From 17e5dbd7bd0364e27a33f1a7dab91cf33d5dcabc Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 04 三月 2026 11:52:12 +0800
Subject: [PATCH] 增强Redis缓存服务与设备通信优化
---
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/QuartzNet/QuartzNetExtension.cs | 18 +++++++++++++-----
1 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/QuartzNet/QuartzNetExtension.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/QuartzNet/QuartzNetExtension.cs
index 9991cd6..50b4e4e 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/QuartzNet/QuartzNetExtension.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/QuartzNet/QuartzNetExtension.cs
@@ -1,5 +1,7 @@
锘縰sing System.Reflection;
+using WIDESEAWCS_Common;
using WIDESEAWCS_Core;
+using WIDESEAWCS_Core.Caches;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Service;
@@ -15,19 +17,21 @@
private readonly IDeviceInfoService _deviceInfoService;
private readonly IDispatchInfoService _dispatchInfoService;
private readonly IDeviceProtocolDetailService _deviceProtocolDetailService;
+ private readonly ICacheService _cacheService;
private readonly Storage _storage;
/// <summary>
/// 鍚姩绋嬪簭鑷姩寮�鍚皟搴︽湇鍔�
/// </summary>
/// <returns></returns>
- public QuartzNetExtension(IDeviceInfoService deviceInfoService, IDispatchInfoService dispatchInfoService, ISchedulerCenter schedulerCenter, IDeviceProtocolDetailService deviceProtocolDetailService, Storage storage)
+ public QuartzNetExtension(IDeviceInfoService deviceInfoService, IDispatchInfoService dispatchInfoService, ISchedulerCenter schedulerCenter, IDeviceProtocolDetailService deviceProtocolDetailService, Storage storage, ICacheService cacheService)
{
_deviceInfoService = deviceInfoService;
_dispatchInfoService = dispatchInfoService;
_schedulerCenter = schedulerCenter;
_deviceProtocolDetailService = deviceProtocolDetailService;
_storage = storage;
+ _cacheService = cacheService;
}
/// <summary>
@@ -40,6 +44,7 @@
{
List<DispatchInfoDTO> dispatches = _dispatchInfoService.QueryDispatchInfos();
List<DeviceInfoDTO> deviceInfos = await _deviceInfoService.QueryDeviceProInfos();
+ _cacheService.RemoveByPrefix($"{RedisPrefix.System}");
deviceInfos.ForEach(x =>
{
@@ -47,7 +52,7 @@
{
try
{
- if (!x.DeviceName.Contains("鏈烘鎵�"))
+ if (!x.DevicePlcType.Contains("Socket"))
{
#region 杩炴帴PLC
@@ -93,7 +98,7 @@
}).ToList();
// 鏍规嵁璁惧绫诲瀷鑾峰彇璁惧鍗忚璇︽儏
- List<DeviceProtocolDetailDTO> deviceProtocolDetails = _deviceProtocolDetailService.GetDeviceProtocolDetailsByDeviceType(x.DeviceType);
+ List<DeviceProtocolDetailDTO> deviceProtocolDetails = _deviceProtocolDetailService.GetDeviceProtocolDetailsByDeviceId(x.Id);
// 鍔犺浇璁惧绋嬪簭闆�
Assembly assemblyDevice = Assembly.Load($"WIDESEAWCS_QuartzJob");
@@ -107,6 +112,8 @@
x.Device = (IDevice)deviceInstance;
Storage.Devices.Add((IDevice)deviceInstance);
+
+ _cacheService.AddObject($"{RedisPrefix.System}:{RedisName.IDevice}:{x.DeviceName}", (IDevice)deviceInstance);
}
}
catch (Exception ex)
@@ -121,14 +128,15 @@
});
for (int i = 0; i < dispatches.Count; i++)
{
- var targetDevice = deviceInfos.FirstOrDefault(x => x.Id == dispatches[i].Id);
+ var targetDevice = deviceInfos.FirstOrDefault(x => x.DispatchId == dispatches[i].Id);
if (targetDevice is null) continue;
+
// 浣跨敤妯″紡鍖归厤
dispatches[i].JobParams = targetDevice switch
{
- { DeviceName: var name } when name.Contains("鏈烘鎵�")
+ { DevicePlcType: var type } when type.Contains("Socket")
=> new RobotCraneDevice { DeviceCode = targetDevice.DeviceCode, DeviceName = targetDevice.DeviceName, IPAddress = targetDevice.DeviceIp + ":" + targetDevice.DevicePort },
_ => targetDevice.Device
};
--
Gitblit v1.9.3