From e69f814f50fd59739dbedd88518dc8cb8d2ed3ee Mon Sep 17 00:00:00 2001
From: z8018 <1282578289@qq.com>
Date: 星期二, 08 四月 2025 21:18:47 +0800
Subject: [PATCH] 1

---
 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs |  256 +++++++++++++++++++++++++++-----------------------
 1 files changed, 138 insertions(+), 118 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 8860533..173377b 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"
@@ -1,128 +1,148 @@
-锘�//#region << 鐗� 鏈� 娉� 閲� >>
-///*----------------------------------------------------------------
-// * 鍛藉悕绌洪棿锛歐IDESEAWCS_Tasks.ConveyorLineJob
-// * 鍒涘缓鑰咃細鑳$搴�
-// * 鍒涘缓鏃堕棿锛�2024/8/2 16:13:36
-// * 鐗堟湰锛歏1.0.0
-// * 鎻忚堪锛�
-// *
-// * ----------------------------------------------------------------
-// * 淇敼浜猴細
-// * 淇敼鏃堕棿锛�
-// * 鐗堟湰锛歏1.0.1
-// * 淇敼璇存槑锛�
-// * 
-// *----------------------------------------------------------------*/
-//#endregion << 鐗� 鏈� 娉� 閲� >>
+锘�#region << 鐗� 鏈� 娉� 閲� >>
+/*----------------------------------------------------------------
+ * 鍛藉悕绌洪棿锛歐IDESEAWCS_Tasks.ConveyorLineJob
+ * 鍒涘缓鑰咃細鑳$搴�
+ * 鍒涘缓鏃堕棿锛�2024/8/2 16:13:36
+ * 鐗堟湰锛歏1.0.0
+ * 鎻忚堪锛�
+ *
+ * ----------------------------------------------------------------
+ * 淇敼浜猴細
+ * 淇敼鏃堕棿锛�
+ * 鐗堟湰锛歏1.0.1
+ * 淇敼璇存槑锛�
+ * 
+ *----------------------------------------------------------------*/
+#endregion << 鐗� 鏈� 娉� 閲� >>
 
-//using AutoMapper;
-//using Quartz;
-//using System.Text.RegularExpressions;
-//using WIDESEA_Common.Log;
-//using WIDESEAWCS_Common.TaskEnum;
-//using WIDESEAWCS_DTO.Enum;
-//using WIDESEAWCS_ISystemServices;
-//using WIDESEAWCS_ITaskInfoService;
-//using WIDESEAWCS_Model.Models;
-//using WIDESEAWCS_Model.Models.System;
-//using WIDESEAWCS_QuartzJob;
-//using WIDESEAWCS_QuartzJob.Service;
-//using WIDESEAWCS_Tasks.ConveyorLineJob;
+using AutoMapper;
+using HslCommunication;
+using Quartz;
+using System;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using WIDESEA_Common.Log;
+using WIDESEAWCS_DTO.BasicInfo;
+using WIDESEAWCS_IBasicInfoService;
+using WIDESEAWCS_ITaskInfoService;
+using WIDESEAWCS_Model.Models;
+using WIDESEAWCS_Model.Models.System;
+using WIDESEAWCS_QuartzJob;
+using WIDESEAWCS_QuartzJob.Service;
+using WIDESEAWCS_Tasks.ConveyorLineJob;
 
-//namespace WIDESEAWCS_Tasks
-//{
-//    [DisallowConcurrentExecution]
-//    public class CommonConveyorLineJob : IJob
-//    {
-//        private readonly ITaskService _taskService;
-//        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
-//        private readonly IRouterService _routerService;
-//        private readonly IOrderDetailsService _OrderDetailsService;
-//        private readonly IMapper _mapper;
+namespace WIDESEAWCS_Tasks
+{
+    [DisallowConcurrentExecution]
+    public class CommonConveyorLineJob : JobBase, IJob
+    {
+        private readonly ITaskService _taskService;
+        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
+        private readonly IRouterService _routerService;
+        private readonly IOrderDetailsService _OrderDetailsService;
+        private readonly IMapper _mapper;
 
-//        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IOrderDetailsService orderDetails, IMapper mapper)
-//        {
-//            _taskService = taskService;
-//            _taskExecuteDetailService = taskExecuteDetailService;
-//            _routerService = routerService;
-//            _OrderDetailsService = orderDetails;
-//            _mapper = mapper;
-//        }
+        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IOrderDetailsService orderDetails, IMapper mapper)
+        {
+            _taskService = taskService;
+            _taskExecuteDetailService = taskExecuteDetailService;
+            _routerService = routerService;
+            _OrderDetailsService = orderDetails;
+            _mapper = mapper;
+        }
 
-//        public Task Execute(IJobExecutionContext context)
-//        {
-//            try
-//            {
-               
-//                CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
-                
-//                if (conveyorLine != null)
-//                {
-//                    if (conveyorLine.Communicator.Read<bool>("DB7.3030.0"))   //鐢宠
-//                    {
+        static string barcode = string.Empty; //鏉$爜
 
-//                        string Barcodes = conveyorLine.Communicator.Read<string>("DB7.3032");   //璇绘潯鐮�
-//                        string pattern = @"\d+";  // 鍖归厤鏁板瓧
-//                        Match match = Regex.Match(Barcodes, pattern);
-//                        string barcodeNumber = match.Value;
-//                        if (barcodeNumber != "")
-//                        {
-//                            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.3116"))
-//                                {
-//                                    conveyorLine.Communicator.Write("DB7.3022", (int)0);   //娓呴櫎鍐欏叆鍘诲悜
-//                                    conveyorLine.Communicator.Write("DB7.3028.0", (bool)false);   //娓呴櫎鍐欏叆鍙嶉
-//                                    WriteLog.Write_Log("鎵爜鏋�", "鎵爜绔欏彴", "鎴愬姛", new { 淇℃伅 = $"鏉$爜锛歿barcodeNumber}锛屾竻闄よ緭閫佺嚎鍙嶉鎴愬姛" });
-//                                    //璋冨彇鍙嶉MES鎵樼洏鏉$爜
+        public Task Execute(IJobExecutionContext context)
+        {
+            try
+            {
+                bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
+                if (flag && value != null && value is OtherDevice)
+                {
+                    OtherDevice otherDevice = (OtherDevice)value;
 
-//                                   var datast= _OrderDetailsService.ToMesBarc(int.Parse(barcodeNumber));
-//                                    if (datast.code==1)
-//                                    {
-//                                        WriteLog.Write_Log("ToMes", "鏉$爜鍙嶉Mes", "鎴愬姛", new { 淇℃伅 = $"鏉$爜锛歿barcodeNumber}锛屽弽棣堟垚鍔�" });
-//                                    }
-//                                    else
-//                                    {
-//                                        WriteLog.Write_Log("ToMes", "鏉$爜鍙嶉Mes", "澶辫触", new { 淇℃伅 = $"鏉$爜锛歿barcodeNumber}锛屽弽棣堝け璐�" });
-//                                    }
+                    bool request = otherDevice.Communicator.Read<bool>("DB15.22.0");   //鐢宠
+                    bool response = otherDevice.Communicator.Read<bool>("DB15.22.1");   //搴旂瓟
 
-                                    
-//                                }
-//                                else
-//                                {
-//                                    WriteLog.Write_Log("鎵爜鏋�", "鎵爜绔欏彴", "閿欒", new { 淇℃伅 = $"鏉$爜锛歿barcodeNumber}锛屾竻闄よ緭閫佺嚎鍙嶉澶辫触" });
-//                                }
-//                            }
-//                            else
-//                            {
-//                                conveyorLine.Communicator.Write("DB7.3028.1", (bool)true);
-//                                WriteLog.Write_Log("鎵爜鏋�", "鎵爜绔欏彴", "閿欒", new { 淇℃伅 = $"鏉$爜锛歿barcodeNumber}锛屾湭鎵惧埌鏁版嵁鏄庣粏璇︽儏闀垮害锛屽啓鍏ユ姤璀︿俊鎭�" });
-//                            }
-//                        }
-//                        else
-//                        {
-//                            WriteLog.Write_Log("鎵爜鏋�", "鎵爜绔欏彴", "閿欒", new { 淇℃伅 = $"鏈鍙栧埌鎵樼洏鏉$爜锛屾潯鐮侀敊璇瘂barcodeNumber}" });
-//                        }
-//                    }
-//                    else
-//                    {
+                    bool wcsResponse = otherDevice.Communicator.Read<bool>("DB15.0.0");   //搴旂瓟
 
-//                        WriteLog.Write_Log("鎵爜鏋�", "鎵爜绔欏彴", "閿欒", new { 淇℃伅 = "鏈鍙栧埌鎵爜鏋敵璇�" });
-//                    }
-//                }
+                    if (request && !response && !wcsResponse)
+                    {
+                        bool[] useables = otherDevice.Communicator.Read<bool>("DB15.22.3", 3);
 
-//            }
-//            catch (Exception ex)
-//            {
-//                //Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
-//            }
-//            return Task.CompletedTask;
-//        }
+                        int[] useableArray = GetIndexArray(useables, false);
 
-        
-//    }
-//}
+                        List<int> useableStations = useableArray.ToList();
+                        for (int i = 0; i < useableStations.Count; i++)
+                        {
+                            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)//鑾峰彇鍒版湁鏁堝幓鍚�
+                            {
+                                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 if (toplc == -1)//鏉挎潗鏃犳潯鐮�
+                            {
+                                otherDevice.Communicator.Write("DB15.0.3", true);
+                            }
+                            else if (toplc == -2) //鏉挎潗澶у皬涓嶅湪鍖洪棿
+                            {
+                                otherDevice.Communicator.Write("DB15.0.2", true);
+                            }
+                        }
+                    }
+                    else
+                    {
+                        if (wcsResponse)
+                            otherDevice.Communicator.Write("DB15.0", false);  //娓呴櫎鍝嶅簲
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                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]))
+                {
+                    result.Add(i);
+                }
+            }
+            return result.ToArray();
+        }
+    }
+}

--
Gitblit v1.9.3