From e46aa927d231af83724683c7286d9db503e24cf7 Mon Sep 17 00:00:00 2001
From: z8018 <1282578289@qq.com>
Date: 星期二, 10 六月 2025 11:46:20 +0800
Subject: [PATCH] 1

---
 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineStationJob.cs |  105 ++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 77 insertions(+), 28 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineStationJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineStationJob.cs"
index a8b0b46..e90bcc2 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineStationJob.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineStationJob.cs"
@@ -23,8 +23,11 @@
 using System.Text;
 using System.Text.RegularExpressions;
 using WIDESEA_Common.Log;
+using WIDESEAWCS_Common;
+using WIDESEAWCS_Core.Helper;
 using WIDESEAWCS_DTO.BasicInfo;
 using WIDESEAWCS_IBasicInfoService;
+using WIDESEAWCS_ITaskInfoRepository;
 using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_Model.Models.System;
@@ -34,54 +37,100 @@
 
 namespace WIDESEAWCS_Tasks
 {
+    /// <summary>
+    /// 閫氱敤杈撻�佺嚎绔欏彴浠诲姟绫伙紝鐢ㄤ簬澶勭悊杈撻�佺嚎绔欏彴鐨凱LC淇″彿浜や簰鍜屼换鍔$鐞�
+    /// </summary>
+    /// <remarks>
+    /// 1. 瀹炵幇IJob鎺ュ彛锛屼綔涓篞uartz.NET鐨勫畾鏃朵换鍔� <br/>
+    /// 2. 閫氳繃DisallowConcurrentExecution鐗规�ч槻姝㈠苟鍙戞墽琛� <br/>
+    /// 3. 涓昏鍔熻兘锛� <br/>
+    ///    - 鐩戞帶PLC绔欏彴璇锋眰淇″彿 <br/>
+    ///    - 澶勭悊浠诲姟閲嶆柊鐢熸垚閫昏緫 <br/>
+    ///    - 鏇存柊浠诲姟鐘舵�� <br/>
+    ///    - 璁剧疆PLC鍝嶅簲淇″彿
+    /// </remarks>
     [DisallowConcurrentExecution]
     public class CommonConveyorLineStationJob : JobBase, IJob
     {
-        private readonly ITaskService _taskService;
-        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
-        private readonly IRouterService _routerService;
-        private readonly IOrderDetailsService _OrderDetailsService;
         private readonly IMapper _mapper;
 
-        public CommonConveyorLineStationJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IOrderDetailsService orderDetails, IMapper mapper)
+        private readonly ITaskRepository _taskRepository;
+
+        private readonly ITaskService _taskService;
+
+        public CommonConveyorLineStationJob(IMapper mapper, ITaskRepository taskRepository, ITaskService taskService)
         {
-            _taskService = taskService;
-            _taskExecuteDetailService = taskExecuteDetailService;
-            _routerService = routerService;
-            _OrderDetailsService = orderDetails;
             _mapper = mapper;
+            _taskRepository = taskRepository;
+            _taskService = taskService;
         }
 
-        static string barcode = string.Empty; //鏉$爜
 
         public Task Execute(IJobExecutionContext context)
         {
-            try
+            bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
+            if (flag && value != null && value is OtherDevice otherDevice)
             {
-                bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
-                if (flag && value != null && value is OtherDevice)
+                try
                 {
-                    OtherDevice otherDevice = (OtherDevice)value;
-
-                    bool request = otherDevice.GetValue<ConveyorLineStationDBName, bool>(ConveyorLineStationDBName.PLCStationRequest);   //鐢宠
-                    bool response = otherDevice.GetValue<ConveyorLineStationDBName, bool>(ConveyorLineStationDBName.PLCStationResponse);    //搴旂瓟
-
-                    bool wcsResponse = otherDevice.GetValue<ConveyorLineStationDBName, bool>(ConveyorLineStationDBName.WCSStationResponse);    //搴旂瓟
-
-                    if (request && !response && !wcsResponse)
+                    List<string> deviceChildCodes = otherDevice.DeviceProDTOs.GroupBy(x => x.DeviceChildCode).Select(x => x.Key).ToList();
+                    for (int i = 0; i < deviceChildCodes.Count; i++)
                     {
+                        bool request = otherDevice.GetValue<ConveyorLineStationDBName, bool>(ConveyorLineStationDBName.PLCStationRequest, deviceChildCodes[i]);   //鐢宠
+                        bool response = otherDevice.GetValue<ConveyorLineStationDBName, bool>(ConveyorLineStationDBName.PLCStationResponse, deviceChildCodes[i]);    //搴旂瓟
+                        bool wcsResponse = otherDevice.GetValue<ConveyorLineStationDBName, bool>(ConveyorLineStationDBName.WCSStationResponse, deviceChildCodes[i]);    //搴旂瓟
 
+                        if (request && !response && !wcsResponse)
+                        {
+                            int taskNum = otherDevice.GetValue<ConveyorLineStationDBName, int>(ConveyorLineStationDBName.PLCStationTaskNum, deviceChildCodes[i]);
+                            if (taskNum > 0)
+                            {
+                                Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == taskNum);
+                                if (task != null)
+                                {
+                                    if (task.TaskState == TaskStatusEnum.Gantry_BeReassign.ObjToInt())
+                                    {
+                                        var (taskFlag, gTask, message) = _taskService.RegenerateTask(task, deviceChildCodes[i]);
+                                        if (!taskFlag || gTask == null)
+                                        {
+                                            otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, 8, deviceChildCodes[i]);
+                                            otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true, deviceChildCodes[i]);
+                                            continue;
+                                        }
+                                    }
+                                    else
+                                    {
+                                        task.TaskState = TaskStatusEnum.Gantry_New.ObjToInt();
+                                        _taskRepository.UpdateData(task);
+                                    }
+
+                                    otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, 0, deviceChildCodes[i]);
+                                    otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true, deviceChildCodes[i]);
+                                }
+                                else
+                                {
+                                    otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, 8, deviceChildCodes[i]);
+                                    otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true, deviceChildCodes[i]);
+                                }
+                            }
+                        }
+                        else
+                        {
+                            if (wcsResponse && !request)
+                                otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, false, deviceChildCodes[i]);  //娓呴櫎鍝嶅簲
+                        }
                     }
-                    else
-                    {
-                        if (wcsResponse)
-                            otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, false);  //娓呴櫎鍝嶅簲
-                    }
+
+
+                }
+                catch (Exception ex)
+                {
+                    WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}", ex.Message, ex);
                 }
             }
-            catch (Exception ex)
+            else
             {
-                WriteError(nameof(CommonConveyorLineJob), ex.ToString(), ex);
+                WriteError(nameof(CommonConveyorLineStationJob), "鍙傛暟閿欒,鏈紶閫掕澶囧弬鏁版垨璁惧绫诲瀷閿欒");
             }
             return Task.CompletedTask;
         }

--
Gitblit v1.9.3