From b6837f097e9cdb2645368aed4ddb03f580c331e4 Mon Sep 17 00:00:00 2001 From: z8018 <1282578289@qq.com> Date: 星期一, 05 五月 2025 17:29:07 +0800 Subject: [PATCH] 1 --- 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs | 132 +++++++++++++++++++++++++------------------ 1 files changed, 76 insertions(+), 56 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 7982e18..61f9a66 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; @@ -32,7 +35,7 @@ namespace WIDESEAWCS_Tasks { [DisallowConcurrentExecution] - public class CommonConveyorLineJob : IJob + public class CommonConveyorLineJob : JobBase, IJob { private readonly ITaskService _taskService; private readonly ITaskExecuteDetailService _taskExecuteDetailService; @@ -49,80 +52,97 @@ _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) { - if (conveyorLine.Communicator.Read<bool>("DB7.3030.0")) //鐢宠 + OtherDevice otherDevice = (OtherDevice)value; + + 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.3116")) - { - conveyorLine.Communicator.Write("DB7.3022", (int)0); //娓呴櫎鍐欏叆鍘诲悜 - conveyorLine.Communicator.Write("DB7.3028.0", (bool)false); //娓呴櫎鍐欏叆鍙嶉 - WriteLog.Write_Log("鎵爜鏋�", "鎵爜绔欏彴", "鎴愬姛", new { 淇℃伅 = $"鏉$爜锛歿barcodeNumber}锛屾竻闄よ緭閫佺嚎鍙嶉鎴愬姛" }); - //璋冨彇鍙嶉MES鎵樼洏鏉$爜 - - 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}锛屽弽棣堝け璐�" }); - } - - - } - else - { - WriteLog.Write_Log("鎵爜鏋�", "鎵爜绔欏彴", "閿欒", new { 淇℃伅 = $"鏉$爜锛歿barcodeNumber}锛屾竻闄よ緭閫佺嚎鍙嶉澶辫触" }); - } - } - else - { - conveyorLine.Communicator.Write("DB7.3028.1", (bool)true); - WriteLog.Write_Log("鎵爜鏋�", "鎵爜绔欏彴", "閿欒", new { 淇℃伅 = $"鏉$爜锛歿barcodeNumber}锛屾湭鎵惧埌鏁版嵁鏄庣粏璇︽儏闀垮害锛屽啓鍏ユ姤璀︿俊鎭�" }); - } + useableStations[i] += 1; } - else + + 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)) { - WriteLog.Write_Log("鎵爜鏋�", "鎵爜绔欏彴", "閿欒", new { 淇℃伅 = $"鏈鍙栧埌鎵樼洏鏉$爜锛屾潯鐮侀敊璇瘂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 { - - 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