From 5270308151082506e0e6df2c72d278d2976ec860 Mon Sep 17 00:00:00 2001
From: liulijun <liulijun@hnkhzn.com>
Date: 星期三, 29 四月 2026 10:28:58 +0800
Subject: [PATCH] WCS设备监控
---
项目代码/WCS/WCSServices/WIDESEAWCS_Tasks/原料库/ConveyorLineJob_YL1ndFloor.cs | 139 +++++++++++++++++++++++++++++++++++++--------
1 files changed, 113 insertions(+), 26 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\345\216\237\346\226\231\345\272\223/ConveyorLineJob_YL1ndFloor.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\345\216\237\346\226\231\345\272\223/ConveyorLineJob_YL1ndFloor.cs"
index 30ebadb..91f2273 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\345\216\237\346\226\231\345\272\223/ConveyorLineJob_YL1ndFloor.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\345\216\237\346\226\231\345\272\223/ConveyorLineJob_YL1ndFloor.cs"
@@ -1,4 +1,5 @@
-锘縰sing Microsoft.AspNetCore.Components.Routing;
+锘縰sing HslCommunication.WebSocket;
+using Microsoft.AspNetCore.Components.Routing;
using Newtonsoft.Json;
using Quartz;
using System;
@@ -7,11 +8,13 @@
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
+using HslCommunication.WebSocket;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Communicator;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
@@ -37,9 +40,10 @@
private readonly IRouterRepository _routerRepository;
private readonly IRouterService _routerService;
private readonly IRouterExtension _routerExtension;
+ private readonly WebSocketServer _webSocketServer;
private readonly List<Dt_WarehouseDevice> warehouseDevices;
- public ConveyorLineJob_YL1ndFloor(ICacheService cacheService, ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IRouterService routerService, IRouterExtension routerExtension)
+ public ConveyorLineJob_YL1ndFloor(ICacheService cacheService, ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IRouterService routerService, IRouterExtension routerExtension, WebSocketServer webSocketServer)
{
_cacheService = cacheService;
_taskService = taskService;
@@ -49,6 +53,7 @@
_routerRepository = routerRepository;
_routerService = routerService;
_routerExtension = routerExtension;
+ _webSocketServer = webSocketServer;
string? warehouseDevicesStr = _cacheService.Get<string>(nameof(Dt_WarehouseDevice));
if (!string.IsNullOrEmpty(warehouseDevicesStr))
@@ -70,20 +75,40 @@
//鑾峰彇鎵�鏈夊崗璁殑杈撻�佺嚎绔欏彴
List<string> deviceStations = device.DeviceProDTOs.Select(x => x.DeviceChildCode).ToList();
List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode);
+
+ // 鍒涘缓杈撻�佺嚎鏁版嵁瀵硅薄锛岀敤浜嶹ebSocket鍙戦��
+ var conveyorLineCPData = new Dictionary<string, object>();
+ conveyorLineCPData["璁惧缂栧彿"] = device.DeviceCode;
+ conveyorLineCPData["璁惧鍚嶇О"] = "鍘熸枡搴撲竴妤艰緭閫佺嚎";
+ conveyorLineCPData["ConveyorLineInfo"] = new Dictionary<string, Dictionary<string, object>>();
foreach (var item in stationMangers.Where(x => deviceStations.Contains(x.StationCode)))
{
DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(WR_CLineYLDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+ DeviceProDTO? deviceErrRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_ErrorYLDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+ R_ConveyorLineYLInfo conveyorLineInfoRead = new R_ConveyorLineYLInfo();
+ R_ErrorYLDB errorYLDB = new R_ErrorYLDB();
+ var simplifiedInfo = new Dictionary<string, object>();
if (deviceProRead != null)
{
- R_ConveyorLineYLInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineYLInfo>(deviceProRead.DeviceProAddress);
+ conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineYLInfo>(deviceProRead.DeviceProAddress);
+
if (conveyorLineInfoRead != null && item.StationType == StationTypeEnum.StationType_InStartAndOutEnd.ObjToInt() && conveyorLineInfoRead.WR_ToHode <= 0 && conveyorLineInfoRead.WR_Request == 86 && !string.IsNullOrEmpty(conveyorLineInfoRead.WR_TMID)) //涓�妤兼潵鏂欑О閲嶇珯鍙板厑璁稿叆搴撶敵璇�
{
- device.SetValue(WR_CLineYLDB.WR_Reresult, 86, item.StationCode);
- WriteInfo(item.StationCode, $"璇锋眰鍏ュ簱鏉$爜:{conveyorLineInfoRead.WR_TMID}");
+ WebResponseContent content = _taskService.YLPurchaseBoxing(conveyorLineInfoRead.WR_TMID, weight: conveyorLineInfoRead.WR_Weight, thickness: conveyorLineInfoRead.WR_Height, wide: conveyorLineInfoRead.WR_Width);
+ if (content.Status)
+ {
+ device.SetValue(WR_CLineYLDB.WR_Reresult, 86, item.StationCode);
+ WriteInfo(item.StationCode, $"璇锋眰鍏ュ簱鏉$爜:{conveyorLineInfoRead.WR_TMID}");
+ }
+ else
+ {
+ WriteError(item.StationCode, $"璇锋眰鍏ュ簱澶辫触锛歿content.Message}");
+ }
+
}
- else if (conveyorLineInfoRead != null && item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt() && conveyorLineInfoRead.WR_ToHode <= 0 && conveyorLineInfoRead.WR_Request == 86 && conveyorLineInfoRead.WR_Task <= 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.WR_TMID)) //涓�妤煎垎閰嶇珯鍙板叆搴撳垎閰嶇洰鏍囩偣
+ else if (conveyorLineInfoRead != null && item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt() && conveyorLineInfoRead.WR_ToHode <= 0 && conveyorLineInfoRead.WR_Request == 86 && conveyorLineInfoRead.WR_Task <= 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.WR_TMID)) //涓�妤煎垎閰嶇珯鍙板叆搴撳垎閰嶇洰鏍囩偣(骞冲彴)
{
- Dt_Task task = _taskRepository.QueryFirst(x => x.PalletCode == conveyorLineInfoRead.WR_TMID && x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.New.ObjToInt() && x.DeviceCode == device.DeviceCode);
+ Dt_Task task = _taskRepository.QueryFirst(x => x.RfidCode == conveyorLineInfoRead.WR_TMID && x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.New.ObjToInt() && x.DeviceCode == device.DeviceCode);
if (task == null)
{
WebResponseContent content = _taskService.RequestYLWMSTaskSimple(conveyorLineInfoRead.WR_TMID, item.StationCode);
@@ -96,12 +121,13 @@
{
device.SetValue(WR_CLineYLDB.WR_Task, task.TaskNum, item.StationCode);
device.SetValue(WR_CLineYLDB.WR_ToHode, task.NextAddress, item.StationCode);
+ device.SetValue(WR_CLineYLDB.WR_Width, task.TaskLength, item.StationCode);
device.SetValue(WR_CLineYLDB.WR_Reresult, 86, item.StationCode);
_taskService.UpdateTask(task, TaskStatusEnum.Line_Executing);
WriteInfo(item.StationCode, $"{conveyorLineInfoRead.Serialize()}");
}
}
- else if (conveyorLineInfoRead != null && item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt() && conveyorLineInfoRead.WR_ToHode <= 0 && conveyorLineInfoRead.WR_Request == 86 && conveyorLineInfoRead.WR_Task > 0) //涓�妤煎垎閰嶇珯鍙板叆搴撳垎閰嶇洰鏍囩偣
+ else if (conveyorLineInfoRead != null && item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt() && conveyorLineInfoRead.WR_ToHode <= 0 && conveyorLineInfoRead.WR_Request == 86 && conveyorLineInfoRead.WR_Task > 0) //涓�妤煎垎閰嶇珯鍙板叆搴撳垎閰嶇洰鏍囩偣(搴撳唴)
{
Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.WR_Task && x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.AGV_Finish.ObjToInt() && x.DeviceCode == device.DeviceCode);
//鍙戦�佷换鍔�
@@ -109,23 +135,27 @@
{
if (string.IsNullOrEmpty(task.Roadway) && string.IsNullOrEmpty(task.NextAddress))
{
- WebResponseContent content = _taskService.AssignYLRoadwayNo(task.PalletCode);
- if (!content.Status)
+ WebResponseContent content = _taskService.AssignYLRoadwayNo(task.PalletCode,weight: conveyorLineInfoRead.WR_Weight, thickness: conveyorLineInfoRead.WR_Height, wide: conveyorLineInfoRead.WR_Width);
+ if (content.Status)
+ {
+ string roadWay = content.Data.ToString();
+ //鑾峰彇璺敱閰嶇疆
+ List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == task.TaskType && task.CurrentAddress == x.StartPosi && x.ChildPosiDeviceCode == roadWay);
+ Dt_Router router = routers.FirstOrDefault();
+ if (router == null)
+ {
+ WriteError(item.StationName, $"浠诲姟鍙�:{task.TaskNum}鏈壘鍒拌矾鐢遍厤缃俊鎭�");
+ return Task.CompletedTask;
+ }
+ task.Roadway = roadWay;
+ task.NextAddress = router.NextPosi;
+ _taskService.UpdateTask(task, TaskStatusEnum.AGV_Finish);
+ }
+ else
{
WriteError(item.StationCode, $"璇锋眰鍏ュ簱澶辫触锛歿content.Message}");
}
- string roadWay = content.Data.ToString();
- //鑾峰彇璺敱閰嶇疆
- List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == task.TaskType && task.CurrentAddress == x.StartPosi && x.ChildPosiDeviceCode== roadWay);
- Dt_Router router = routers.FirstOrDefault();
- if (router == null)
- {
- WriteError(item.StationName, $"浠诲姟鍙�:{task.TaskNum}鏈壘鍒拌矾鐢遍厤缃俊鎭�");
- return Task.CompletedTask;
- }
- task.Roadway = roadWay;
- task.NextAddress = router.NextPosi;
- _taskService.UpdateTask(task,TaskStatusEnum.AGV_Finish);
+
}
else
{
@@ -163,9 +193,9 @@
}
}
- else if (conveyorLineInfoRead != null && item.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt() && conveyorLineInfoRead.WR_ToHode <= 0 && conveyorLineInfoRead.WR_Request == 99 && conveyorLineInfoRead.WR_Task <= 0) //鍑虹珯鍙板垎閰嶇洰鏍囩偣
+ else if (conveyorLineInfoRead != null && item.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt() && conveyorLineInfoRead.WR_ToHode <= 0 && conveyorLineInfoRead.WR_Request == 99 && conveyorLineInfoRead.WR_Task > 0) //鍑虹珯鍙板垎閰嶇洰鏍囩偣
{
- Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt() && x.DeviceCode == device.DeviceCode);
+ Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && x.TaskNum == conveyorLineInfoRead.WR_Task && _taskService.TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt() && x.DeviceCode == device.DeviceCode);
if (task != null)
{
//鍙戦�佺洰鏍囩偣
@@ -191,9 +221,58 @@
{
//浠诲姟鍥炲
device.SetValue(WR_CLineYLDB.WR_Reresult, 98, item.StationCode);
- _taskService.TaskCompleted(task.TaskNum);
- WriteInfo(item.StationCode, $"浠诲姟鍙�:{task.TaskNum}涓�妤煎嚭搴撹嚦鑰佸巶鎴垮畬鎴�");
+ _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing, deviceCode: "CL3_YL");
+ WriteInfo(item.StationCode, $"浠诲姟鍙�:{task.TaskNum}锛孯IFD{task.RfidCode}涓�妤煎嚭搴撹嚦鑰佸巶鎴垮畬鎴�");
}
+ }
+ else if (conveyorLineInfoRead != null && item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt() && conveyorLineInfoRead.WR_Task <= 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.WR_TMID) && conveyorLineInfoRead.WR_Request == 98) //涓�妤艰�佸巶鍑哄簱鍙e畬鎴�
+ {
+ Dt_Task task = _taskRepository.QueryFirst(x => (x.RfidCode == conveyorLineInfoRead.WR_TMID || x.PalletCode== conveyorLineInfoRead.WR_TMID) && _taskService.TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt() && x.DeviceCode == device.DeviceCode);
+ if (task != null)
+ {
+ //浠诲姟鍥炲
+ device.SetValue(WR_CLineYLDB.WR_Reresult, 98, item.StationCode);
+ _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing, deviceCode: "CL3_YL");
+ WriteInfo(item.StationCode, $"浠诲姟鍙�:{task.TaskNum}锛孯IFD{task.RfidCode}涓�妤煎嚭搴撹嚦鑰佸巶鎴垮畬鎴�");
+ }
+ }
+ // 灏嗗綋鍓嶇珯鍙扮殑杈撻�佺嚎淇℃伅娣诲姞鍒版暟鎹璞★紝鍙寘鍚渶瑕佺殑瀛楁
+ if (conveyorLineInfoRead != null)
+ {
+ simplifiedInfo["LineCode"] = device.DeviceCode;
+ simplifiedInfo["TaskNum"] = conveyorLineInfoRead.WR_Task; // 浠诲姟鍙�
+ simplifiedInfo["RFID"] = conveyorLineInfoRead.WR_TMID;//RFID
+ simplifiedInfo["Width"] = conveyorLineInfoRead.WR_Width;//绾稿嵎骞呭
+ simplifiedInfo["Request"] = conveyorLineInfoRead.WR_Request;//鐢宠
+ simplifiedInfo["Reresult"] = conveyorLineInfoRead.WR_Reresult;//鐢宠鍙嶉
+ simplifiedInfo["HasGoods"] = conveyorLineInfoRead.WR_ToHode > 0; // 鏄惁鏈夎揣
+ ((Dictionary<string, Dictionary<string, object>>)conveyorLineCPData["ConveyorLineInfo"])[item.StationCode] = simplifiedInfo;
+ }
+ }
+ else if (deviceErrRead!=null)
+ {
+
+ errorYLDB = device.Communicator.ReadCustomer<R_ErrorYLDB>(deviceErrRead.DeviceProAddress);
+ if (errorYLDB != null && errorYLDB.R_Error==2)
+ {
+ ErrorDeviceInfo? errorDeviceInfo = RoadwayError.Roadways.FirstOrDefault(x=>x.Code==item.StationCode);
+ if (errorDeviceInfo==null)
+ {
+ RoadwayError.Roadways.Add(new ErrorDeviceInfo() { Code = item.StationCode, Roadway = item.StackerCraneCode });
+ }
+ }
+ else if(errorYLDB != null && errorYLDB.R_Error == 1)
+ {
+ ErrorDeviceInfo? deviceInfo = RoadwayError.Roadways.FirstOrDefault(x => x.Code == item.StationCode);
+ if (deviceInfo != null)
+ {
+ RoadwayError.Roadways.Remove(deviceInfo);
+ }
+ }
+ if (errorYLDB != null)
+ {
+ simplifiedInfo["Error"] = errorYLDB.R_Error;
+ ((Dictionary<string, Dictionary<string, object>>)conveyorLineCPData["ConveyorLineInfo"])[item.StationCode] = simplifiedInfo;
}
}
else
@@ -201,6 +280,14 @@
WriteError(item.StationName, $"鏈壘鍒拌澶囧瓙缂栧彿{item.StationCode}鐨勫崗璁俊鎭�");
}
}
+
+ // 閫氳繃WebSocket鍙戦�佽緭閫佺嚎鏁版嵁鍒板墠绔�
+ // 搴忓垪鍖栨暟鎹�
+ string jsonData = JsonConvert.SerializeObject(conveyorLineCPData);
+ // 鍙戦�佹暟鎹埌鎵�鏈夊鎴风
+ _webSocketServer.PublishAllClientPayload(jsonData);
+ // 璁板綍鍙戦�佹棩蹇�
+ WriteInfo(device.DeviceCode, $"WebSocket鍙戦�佽緭閫佺嚎鏁版嵁锛歿jsonData}");
}
return Task.CompletedTask;
}
--
Gitblit v1.9.3