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/CommonConveyorLineJob.cs |  136 +++++++++++++++++++++++++++++----------------
 1 files changed, 88 insertions(+), 48 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs"
index dc71f27..8358d6a 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs"
@@ -16,12 +16,15 @@
 #endregion << 鐗� 鏈� 娉� 閲� >>
 
 using AutoMapper;
+using HslCommunication;
 using Quartz;
+using System;
+using System.Linq;
+using System.Text;
 using System.Text.RegularExpressions;
 using WIDESEA_Common.Log;
-using WIDESEAWCS_Common.TaskEnum;
-using WIDESEAWCS_DTO.Enum;
-using WIDESEAWCS_ISystemServices;
+using WIDESEAWCS_DTO.BasicInfo;
+using WIDESEAWCS_IBasicInfoService;
 using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_Model.Models.System;
@@ -31,8 +34,18 @@
 
 namespace WIDESEAWCS_Tasks
 {
+    /// <summary>
+    /// 閫氱敤杈撻�佺嚎浠诲姟锛岃礋璐e鐞嗚緭閫佺嚎璁惧鐨勯�氫俊涓庝换鍔℃墽琛�
+    /// </summary>
+    /// <remarks>
+    /// 1. 閫氳繃PLC閫氫俊璇诲彇璁惧鐘舵�佸拰鏉$爜淇℃伅 <br/>
+    /// 2. 鏍规嵁鏉$爜鏌ヨ浜у搧淇℃伅鍜屽幓鍚戝伐浣� <br/>
+    /// 3. 灏嗕骇鍝佸昂瀵稿拰鍘诲悜淇℃伅鍐欏叆PLC <br/>
+    /// 4. 澶勭悊寮傚父鎯呭喌骞惰褰曢敊璇棩蹇�
+    /// </remarks>
+    /// <attribute>[DisallowConcurrentExecution]</attribute>
     [DisallowConcurrentExecution]
-    public class CommonConveyorLineJob : IJob
+    public class CommonConveyorLineJob : JobBase, IJob
     {
         private readonly ITaskService _taskService;
         private readonly ITaskExecuteDetailService _taskExecuteDetailService;
@@ -49,78 +62,105 @@
             _mapper = mapper;
         }
 
+        static string barcode = string.Empty; //鏉$爜
+
         public Task Execute(IJobExecutionContext context)
         {
             try
             {
-               
-                CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
-                
-                if (conveyorLine != null)
+                bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
+                if (flag && value != null && value is OtherDevice otherDevice)
                 {
-                    if (conveyorLine.Communicator.Read<bool>("DB7.3030.0"))   //鐢宠
+                    bool request = otherDevice.Communicator.Read<bool>("DB15.22.0");   //鐢宠
+                    bool response = otherDevice.Communicator.Read<bool>("DB15.22.1");   //搴旂瓟
+
+                    bool wcsResponse = otherDevice.Communicator.Read<bool>("DB15.0.0");   //搴旂瓟
+
+                    if (request && !response && !wcsResponse)
                     {
+                        bool[] useables = otherDevice.Communicator.Read<bool>("DB15.22.3", 3);
 
-                        string Barcodes = conveyorLine.Communicator.Read<string>("DB7.3032");   //璇绘潯鐮�
-                        string pattern = @"\d+";  // 鍖归厤鏁板瓧
-                        Match match = Regex.Match(Barcodes, pattern);
-                        string barcodeNumber = match.Value;
-                        if (barcodeNumber != "")
+                        int[] useableArray = GetIndexArray(useables, false);
+
+                        List<int> useableStations = useableArray.ToList();
+                        for (int i = 0; i < useableStations.Count; i++)
                         {
-                            int toplc = _OrderDetailsService.GetOrderDetails(barcodeNumber);
-                            if (toplc != -1)
-                            {
-                                conveyorLine.Communicator.Write("DB7.3022", (int)toplc);   //鍐欏叆鍘诲悜
-                                conveyorLine.Communicator.Write("DB7.3028.0", (bool)true);    //鍐欏叆鍙嶉
-                                WriteLog.Write_Log("鎵爜鏋�", "鎵爜绔欏彴", "鎴愬姛", new { 淇℃伅 = $"鏉$爜锛歿barcodeNumber}锛屽啓鍏ュ幓鍚憑toplc}" });
-                                if (conveyorLine.Communicator.Read<bool>("DB7.2986"))
-                                {
-                                    conveyorLine.Communicator.Write("DB7.3022", (int)0);   //娓呴櫎鍐欏叆鍘诲悜
-                                    conveyorLine.Communicator.Write("DB7.3028.0", (bool)false);   //娓呴櫎鍐欏叆鍙嶉
-                                    WriteLog.Write_Log("鎵爜鏋�", "鎵爜绔欏彴", "鎴愬姛", new { 淇℃伅 = $"鏉$爜锛歿barcodeNumber}锛屾竻闄よ緭閫佺嚎鍙嶉鎴愬姛" });
-                                    //璋冨彇鍙嶉MES鎵樼洏鏉$爜
-                                    if (_OrderDetailsService.ToMesBarc(int.Parse(barcodeNumber)))
-                                    {
-                                        WriteLog.Write_Log("ToMes", "鏉$爜鍙嶉Mes", "鎴愬姛", new { 淇℃伅 = $"鏉$爜锛歿barcodeNumber}锛屽弽棣堟垚鍔�" });
-                                    }
-                                    else
-                                    {
-                                        WriteLog.Write_Log("ToMes", "鏉$爜鍙嶉Mes", "澶辫触", new { 淇℃伅 = $"鏉$爜锛歿barcodeNumber}锛屽弽棣堝け璐�" });
-                                    }
+                            useableStations[i] += 1;
+                        }
 
-                                    
+                        barcode = otherDevice.Communicator.Read<string>("DB15.32");   //鏉$爜
+
+                        List<byte> bytes = otherDevice.Communicator.Read("DB15.34", 40).ToList();
+
+                        byte[] temp = bytes.ToArray().SelectMiddle(0, bytes.IndexOf(0));
+
+                        barcode = Encoding.Default.GetString(temp);
+
+                        string pattern = @"\d+";  // 鍖归厤鏁板瓧
+                        Match match = Regex.Match(barcode, pattern);
+                        string barcodeNumber = match.Value;
+
+                        if (!string.IsNullOrEmpty(barcodeNumber))
+                        {
+                            // 1. 鑾峰彇鍘诲悜
+                            int toplc = _OrderDetailsService.GetOrderDetails(barcodeNumber, useableStations, out ProductInfoDTO productInfo);
+
+                            if (toplc > 0)//鑾峰彇鍒版湁鏁堝幓鍚�
+                            {
+                                if (toplc == 1 && productInfo.Length < productInfo.Width)
+                                {
+                                    otherDevice.Communicator.Write("DB15.10", productInfo.Width);
+                                    otherDevice.Communicator.Write("DB15.14", productInfo.Length);
+                                    otherDevice.Communicator.Write("DB15.18", productInfo.Height);
                                 }
                                 else
                                 {
-                                    WriteLog.Write_Log("鎵爜鏋�", "鎵爜绔欏彴", "閿欒", new { 淇℃伅 = $"鏉$爜锛歿barcodeNumber}锛屾竻闄よ緭閫佺嚎鍙嶉澶辫触" });
+                                    otherDevice.Communicator.Write("DB15.10", productInfo.Length);
+                                    otherDevice.Communicator.Write("DB15.14", productInfo.Width);
+                                    otherDevice.Communicator.Write("DB15.18", productInfo.Height);
                                 }
+
+
+                                otherDevice.Communicator.Write("DB15.6", toplc);   //鍐欏叆鍘诲悜
+                                otherDevice.Communicator.Write("DB15.0", true);
+
+                                //var datast = _OrderDetailsService.ToMesBarc(int.Parse(barcode));
                             }
-                            else
+                            else if (toplc == -1)//鏉挎潗鏃犳潯鐮�
                             {
-                                conveyorLine.Communicator.Write("DB7.3028.1", (bool)true);
-                                WriteLog.Write_Log("鎵爜鏋�", "鎵爜绔欏彴", "閿欒", new { 淇℃伅 = $"鏉$爜锛歿barcodeNumber}锛屾湭鎵惧埌鏁版嵁鏄庣粏璇︽儏闀垮害锛屽啓鍏ユ姤璀︿俊鎭�" });
+                                otherDevice.Communicator.Write("DB15.0.3", true);
                             }
-                        }
-                        else
-                        {
-                            WriteLog.Write_Log("鎵爜鏋�", "鎵爜绔欏彴", "閿欒", new { 淇℃伅 = $"鏈鍙栧埌鎵樼洏鏉$爜锛屾潯鐮侀敊璇瘂barcodeNumber}" });
+                            else if (toplc == -2) //鏉挎潗澶у皬涓嶅湪鍖洪棿
+                            {
+                                otherDevice.Communicator.Write("DB15.0.2", true);
+                            }
                         }
                     }
                     else
                     {
-
-                        WriteLog.Write_Log("鎵爜鏋�", "鎵爜绔欏彴", "閿欒", new { 淇℃伅 = "鏈鍙栧埌鎵爜鏋敵璇�" });
+                        if (wcsResponse && !request)
+                            otherDevice.Communicator.Write("DB15.0", false);  //娓呴櫎鍝嶅簲
                     }
                 }
-
             }
             catch (Exception ex)
             {
-                //Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
+                WriteError(nameof(CommonConveyorLineJob), ex.ToString(), ex);
             }
             return Task.CompletedTask;
         }
 
-        
+        public int[] GetIndexArray<T>(T[] values, T value)
+        {
+            List<int> result = new List<int>();
+            for (int i = 0; i < values.Length; i++)
+            {
+                if (value?.Equals(values[i]) ?? false)
+                {
+                    result.Add(i);
+                }
+            }
+            return result.ToArray();
+        }
     }
 }

--
Gitblit v1.9.3