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/原料库/StackerCraneJob_YLSC2.cs |   99 +++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 90 insertions(+), 9 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/StackerCraneJob_YLSC2.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/StackerCraneJob_YLSC2.cs"
index 4926ef0..76f7d93 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/StackerCraneJob_YLSC2.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/StackerCraneJob_YLSC2.cs"
@@ -1,4 +1,6 @@
-锘縰sing Microsoft.AspNetCore.Components.Routing;
+锘縰sing HslCommunication.WebSocket;
+using Microsoft.AspNetCore.Components.Routing;
+using Newtonsoft.Json;
 using Quartz;
 using System;
 using System.Collections.Generic;
@@ -7,24 +9,30 @@
 using System.Text;
 using System.Threading.Tasks;
 using WIDESEAWCS_Common.TaskEnum;
+using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.Enums;
+using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_DTO.Equipment;
 using WIDESEAWCS_IBasicInfoRepository;
 using WIDESEAWCS_ITaskInfoRepository;
 using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
 using WIDESEAWCS_QuartzJob.DeviceBase;
+using WIDESEAWCS_QuartzJob.DTO;
 using WIDESEAWCS_QuartzJob.Models;
+using WIDESEAWCS_QuartzJob.Repository;
 using WIDESEAWCS_QuartzJob.Service;
+using WIDESEAWCS_QuartzJob.StackerCrane;
 using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
-using WIDESEAWCS_Tasks.StackerCraneJob;
 using WIDESEAWCS_Tasks;
-using WIDESEAWCS_Core;
-using SqlSugar.Extensions;
 using WIDESEAWCS_Tasks.ConveyorLineJob;
 using WIDESEAWCS_QuartzJob.Repository;
 using WIDESEAWCS_QuartzJob.DTO;
 using WIDESEAWCS_QuartzJob.StackerCrane;
+using WIDESEAWCS_Tasks.StackerCraneJob;
+using WIDESEAWCS_DTO.TaskInfo;
+using WIDESEAWCS_Tasks.鍘熸枡搴�;
 
 namespace WIDESEAWCS_Tasks
 {
@@ -37,8 +45,9 @@
         private readonly IRouterService _routerService;
         private readonly IRouterRepository _routerRepository;
         private readonly IStationMangerRepository _stationMangerRepository;
+        private WebSocketServer _webSocketServer;
 
-        public StackerCraneJob_YLSC2(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository)
+        public StackerCraneJob_YLSC2(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, WebSocketServer webSocketServer)
         {
             _taskService = taskService;
             _taskExecuteDetailService = taskExecuteDetailService;
@@ -46,6 +55,7 @@
             _routerService = routerService;
             _stationMangerRepository = stationMangerRepository;
             _routerRepository = routerRepository;
+            _webSocketServer = webSocketServer;
         }
 
         public Task Execute(IJobExecutionContext context)
@@ -90,8 +100,78 @@
                                     }
                                 }
                             }
+                            ErrorDeviceInfo? deviceInfo = RoadwayError.Roadways.FirstOrDefault(x => x.Code == commonStackerCrane.DeviceCode);
+                            if (deviceInfo != null)
+                            {
+                                RoadwayError.Roadways.Remove(deviceInfo);
+                            }
+                        }
+                        else
+                        {
+                            ErrorDeviceInfo? deviceInfo = RoadwayError.Roadways.FirstOrDefault(x => x.Code == commonStackerCrane.DeviceCode);
+                            if (deviceInfo==null)
+                            {
+                                RoadwayError.Roadways.Add(new ErrorDeviceInfo() { Code = commonStackerCrane.DeviceCode, Roadway = commonStackerCrane.DeviceCode });
+                            }
                         }
                     }
+                    // 璁剧疆璁惧缂栧彿锛屽墠绔敤浜庤瘑鍒爢鍨涙満
+                    YL_DB yL_DB = new YL_DB();
+                    yL_DB.R_PP_Status = commonStackerCrane.DeviceCode;
+                    // 璁剧疆鍫嗗灈鏈虹姸鎬�
+                    yL_DB.YL_Status = commonStackerCrane.StackerCraneStatusValue switch
+                    {
+                        StackerCraneStatus.Fault => 0,
+                        StackerCraneStatus.Normal => 1,
+                        StackerCraneStatus.EmergencyStop => 2,
+                        StackerCraneStatus.Unkonw => 3,
+                    };
+                    yL_DB.YL_AutoStatus = commonStackerCrane.StackerCraneAutoStatusValue switch
+                    {
+                        StackerCraneAutoStatus.SemiAutomatic => 1,
+                        StackerCraneAutoStatus.Maintenance => 2,
+                        StackerCraneAutoStatus.Automatic => 3,
+                        StackerCraneAutoStatus.Manual => 4,
+                        StackerCraneAutoStatus.Unkonw => 5,
+                    };
+                    yL_DB.YL_WorkStatus = commonStackerCrane.StackerCraneWorkStatusValue switch
+                    {
+                        StackerCraneWorkStatus.Standby => 1,
+                        StackerCraneWorkStatus.PickUpCompleted => 2,
+                        StackerCraneWorkStatus.PickUp => 3,
+                        StackerCraneWorkStatus.Putting => 5,
+                        StackerCraneWorkStatus.WorkCompleted => 9,
+                    };
+                    yL_DB.YL_TaskNum = commonStackerCrane.CurrentTaskNum;
+                    yL_DB.YL_WorkType = commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType);
+                    yL_DB.YL_Row = commonStackerCrane.Communicator.Read<short>("DB1000.46");
+                    yL_DB.YL_Column = commonStackerCrane.Communicator.Read<short>("DB1000.48.0");
+                    yL_DB.YL_Layer = commonStackerCrane.Communicator.Read<short>("DB1000.50.0");
+                    // 璇诲彇鎶ヨ淇℃伅
+                    short stackerError2 = commonStackerCrane.Communicator.Read<short>("DB1000.54.0");
+                    yL_DB.StackerAlarm = stackerError2 == 0 ? "鏃�" : $"鎶ヨ浠g爜: {stackerError2}";
+                    // 搴忓垪鍖栧苟鍙戦�佹暟鎹�
+                    string ylDB = JsonConvert.SerializeObject(yL_DB);
+                    _webSocketServer.PublishAllClientPayload(ylDB);
+
+                    #region 璋冪敤浜嬩欢鎬荤嚎閫氱煡鍓嶇
+
+                    EquipmentDTO equipmentDTO = new EquipmentDTO();
+                    object obj = new
+                    {
+                        commonStackerCrane.DeviceName,
+                        commonStackerCrane.DeviceCode,
+                        StackerCraneAutoStatus.Automatic,
+                        StackerCraneStatus.Normal,
+                        StackerCraneWorkStatus.Standby,
+                        TaskNum = commonStackerCrane.CurrentTaskNum,
+                        WorkType = commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType),
+                        StackerAlarm = commonStackerCrane.Communicator.Read<short>("DB1000.54.0"),
+                    };
+                    equipmentDTO.StackerDataJson = obj.Serialize();
+                    _webSocketServer.PublishAllClientPayload(equipmentDTO.Serialize());
+
+                    #endregion
                 }
             }
             catch (Exception ex)
@@ -137,7 +217,7 @@
                             return WebResponseContent.Instance.Error($"杈撻�佺嚎鍑哄簱绔欑偣鏈厤缃�,{task.NextAddress}");
                         }
                         bool depth = false;
-                        if (task.Grade>0 && task.TaskType==TaskTypeEnum.PrintYLOutbound.ObjToInt())
+                        if (task.Grade > 0 && task.TaskType==TaskTypeEnum.PrintYLOutbound.ObjToInt())
                         {
                             depth = true;
                         }
@@ -215,7 +295,7 @@
             Dt_Task? task;
             if (commonStackerCrane.LastTaskType == null)
             {
-                task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode);
+                task = _taskService.QueryStackerYLTask(commonStackerCrane.DeviceCode);
             }
             else
             {
@@ -225,13 +305,13 @@
                     task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
                     if (task == null)
                     {
-                        task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
+                        task = _taskService.QueryStackerYLTask(commonStackerCrane.DeviceCode, TaskTypeGroup.OutbondGroup);
                     }
                 }
                 else
                 {
                     //涓婁竴涓负鍏ュ簱鍒欐煡鏄惁瀛樺湪鍑哄簱浠诲姟 浜ゆ浛鎵ц
-                    task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
+                    task = _taskService.QueryStackerYLTask(commonStackerCrane.DeviceCode, TaskTypeGroup.OutbondGroup);
                     if (task == null)
                     {
                         task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
@@ -293,6 +373,7 @@
                     {
                         task.ExceptionMessage = "鍑哄簱绔欏彴鏃犳硶涓嬪彂";
                         _taskRepository.UpdateData(task);
+                        WriteInfo(task.DeviceCode, $"鍑哄簱绔欏彴鏃犳硶涓嬪彂");
                     }
                 }
                 else

--
Gitblit v1.9.3