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 |   48 ++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 44 insertions(+), 4 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 41be831..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,6 +8,7 @@
 using System.Reflection.Metadata;
 using System.Text;
 using System.Threading.Tasks;
+using HslCommunication.WebSocket;
 using WIDESEAWCS_Common;
 using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_Communicator;
@@ -38,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;
@@ -50,6 +53,7 @@
             _routerRepository = routerRepository;
             _routerService = routerService;
             _routerExtension = routerExtension;
+            _webSocketServer = webSocketServer;
 
             string? warehouseDevicesStr = _cacheService.Get<string>(nameof(Dt_WarehouseDevice));
             if (!string.IsNullOrEmpty(warehouseDevicesStr))
@@ -71,13 +75,23 @@
                 //鑾峰彇鎵�鏈夊崗璁殑杈撻�佺嚎绔欏彴
                 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)) //涓�妤兼潵鏂欑О閲嶇珯鍙板厑璁稿叆搴撶敵璇�
                         {
                             WebResponseContent content = _taskService.YLPurchaseBoxing(conveyorLineInfoRead.WR_TMID, weight: conveyorLineInfoRead.WR_Weight, thickness: conveyorLineInfoRead.WR_Height, wide: conveyorLineInfoRead.WR_Width);
@@ -222,10 +236,23 @@
                                 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)
                     {
-                        R_ErrorYLDB errorYLDB = device.Communicator.ReadCustomer<R_ErrorYLDB>(deviceErrRead.DeviceProAddress);
+
+                        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);
@@ -242,12 +269,25 @@
                                 RoadwayError.Roadways.Remove(deviceInfo);
                             }
                         }
+                        if (errorYLDB != null)
+                        {
+                            simplifiedInfo["Error"] = errorYLDB.R_Error;
+                            ((Dictionary<string, Dictionary<string, object>>)conveyorLineCPData["ConveyorLineInfo"])[item.StationCode] = simplifiedInfo;
+                        }
                     }
                     else
                     {
                         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