From 7da6f394864ba0412c1ac58ba7752862de7d3f3d Mon Sep 17 00:00:00 2001 From: z8018 <1282578289@qq.com> Date: 星期二, 06 五月 2025 10:41:48 +0800 Subject: [PATCH] 1 --- 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineOutJob.cs | 194 ++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 179 insertions(+), 15 deletions(-) diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineOutJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineOutJob.cs" index 9fe9210..2200f2e 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineOutJob.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineOutJob.cs" @@ -22,13 +22,20 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; +using System.Threading.Tasks; using WIDESEA_Common.Log; +using WIDESEAWCS_BasicInfoService; +using WIDESEAWCS_Common; +using WIDESEAWCS_Core.Helper; using WIDESEAWCS_DTO.BasicInfo; +using WIDESEAWCS_IBasicInfoRepository; using WIDESEAWCS_IBasicInfoService; +using WIDESEAWCS_ITaskInfoRepository; using WIDESEAWCS_ITaskInfoService; using WIDESEAWCS_Model.Models; using WIDESEAWCS_Model.Models.System; using WIDESEAWCS_QuartzJob; +using WIDESEAWCS_QuartzJob.DTO; using WIDESEAWCS_QuartzJob.Service; using WIDESEAWCS_Tasks.ConveyorLineJob; @@ -38,31 +45,44 @@ public class CommonConveyorLineOutJob : JobBase, IJob { private readonly ITaskService _taskService; - private readonly ITaskExecuteDetailService _taskExecuteDetailService; - private readonly IRouterService _routerService; - private readonly IOrderDetailsService _OrderDetailsService; private readonly IMapper _mapper; - public CommonConveyorLineOutJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IOrderDetailsService orderDetails, IMapper mapper) + private readonly IOrderDetailsService _orderDetailsService; + private readonly ITaskRepository _taskRepository; + private readonly IContainerRepository _containerRepository; + + private static Dt_Container DischargeContainer; + + private static int dischargeStation = 8; + + public CommonConveyorLineOutJob(ITaskService taskService, IMapper mapper, IOrderDetailsService orderDetailsService, ITaskRepository taskRepository, IContainerRepository containerRepository) { _taskService = taskService; - _taskExecuteDetailService = taskExecuteDetailService; - _routerService = routerService; - _OrderDetailsService = orderDetails; _mapper = mapper; + _orderDetailsService = orderDetailsService; + _taskRepository = taskRepository; + _containerRepository = containerRepository; } - static string barcode = string.Empty; //鏉$爜 + public Task Execute(IJobExecutionContext context) { - try + if (DischargeContainer == null) { - bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value); - if (flag && value != null && value is OtherDevice) + DischargeContainer = _containerRepository.QueryFirst(x => x.ContainerEnable && x.ContainerType == ContainerTypeEnum.DischargeContainer.ObjToInt()); + if (DischargeContainer != null) { - OtherDevice otherDevice = (OtherDevice)value; + dischargeStation = DischargeContainer.ContainerNo; + } + } + bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value); + if (flag && value != null && value is OtherDevice) + { + OtherDevice otherDevice = (OtherDevice)value; + try + { bool request = otherDevice.GetValue<ConveyorLineStationDBName, bool>(ConveyorLineStationDBName.PLCStationRequest); //鐢宠 bool response = otherDevice.GetValue<ConveyorLineStationDBName, bool>(ConveyorLineStationDBName.PLCStationResponse); //搴旂瓟 @@ -70,18 +90,162 @@ if (request && !response && !wcsResponse) { + DeviceProDTO? devicePro = otherDevice.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == ConveyorLineStationDBName.PLCStationBarcode.ToString()); + if (devicePro != null) + { + string barcode = otherDevice.GetValue<ConveyorLineStationDBName, string>(ConveyorLineStationDBName.PLCStationBarcode); + + //List<byte> bytes = otherDevice.Communicator.Read(devicePro.DeviceProAddress, devicePro.DeviceProDataLength).ToList(); + + //byte[] temp = bytes.ToArray().SelectMiddle(2, bytes.IndexOf(0) - 2); + + //barcode = Encoding.Default.GetString(temp); + + if (!string.IsNullOrEmpty(barcode)) + { + OrderInfo orderInfo = _orderDetailsService.GetOrderInfoByBarcode(barcode); + + _orderDetailsService.ToMes(barcode, 3); + + if (orderInfo.Width >= AppSettings.Get("MinWidth").ObjToInt() && orderInfo.Width <= AppSettings.Get("MaxWidth").ObjToInt() && orderInfo.Length >= AppSettings.Get("MinLength").ObjToInt() && orderInfo.Length <= AppSettings.Get("MaxLength").ObjToInt() || orderInfo.Length >= AppSettings.Get("MinWidth").ObjToInt() && orderInfo.Length <= AppSettings.Get("MaxWidth").ObjToInt() && orderInfo.Width >= AppSettings.Get("MinLength").ObjToInt() && orderInfo.Width <= AppSettings.Get("MaxLength").ObjToInt()) + { + Dt_Task task = _taskRepository.QueryFirst(x => x.PalletCode == barcode); + if (task == null) + { + try + { + var (taskFlag, gTask, message) = _taskService.GenerateTask(orderInfo); + if (taskFlag && gTask != null) + { + task = gTask; + if (!string.IsNullOrEmpty(task.ItemInfo)) + { + string[] itemInfos = task.ItemInfo.Split("*"); + if (itemInfos.Length == 3) + { + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(itemInfos[0])); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(itemInfos[1])); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(itemInfos[2])); + } + } + + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(task.TargetAddress)); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, task.TaskNum); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true); + } + else + { + //if (message.Contains("10001")) + //{ + // otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Length)); + // otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Width)); + // otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Thickness)); + // otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, dischargeStation); + // otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, 999); + // otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true); + //} + //else if (message.Contains("10002")) + //{ + // WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}", message); + //} + //else + { + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Length)); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Width)); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Thickness)); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, dischargeStation); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, 998); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true); + + WriteError(nameof(CommonConveyorLineOutJob), message); + } + } + } + catch (Exception ex) + { + if (ex.Message.Contains("10001")) + { + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Length)); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Width)); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Thickness)); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, dischargeStation); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, 999); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true); + } + else if (ex.Message.Contains("10002")) + { + WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}", ex.Message, ex); + } + else + { + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Length)); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Width)); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Thickness)); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, dischargeStation); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, 998); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true); + + WriteError(nameof(CommonConveyorLineOutJob), ex.Message, ex); + } + } + } + else + { + if (!string.IsNullOrEmpty(task.ItemInfo)) + { + string[] itemInfos = task.ItemInfo.Split("*"); + if (itemInfos.Length == 3) + { + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(itemInfos[0])); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(itemInfos[1])); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(itemInfos[2])); + } + } + + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(task.TargetAddress)); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, task.TaskNum); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true); + } + } + else + { + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Length)); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Width)); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Thickness)); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, dischargeStation); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, 999); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true); + } + } + else + { + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, dischargeStation); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, 997); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true); + //otherDevice.SetValue(ConveyorLineStationDBName.WCSStationNoBarcode, true); + } + } } else { - if (wcsResponse) + if (wcsResponse && !request) otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, false); //娓呴櫎鍝嶅簲 } + + } + catch (Exception ex) + { + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, dischargeStation); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, 996); + otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true); + + WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}", ex.Message, ex); } } - catch (Exception ex) + else { - WriteError(nameof(CommonConveyorLineJob), ex.ToString(), ex); + WriteError(nameof(CommonConveyorLineOutJob), "鍙傛暟閿欒,鏈紶閫掕澶囧弬鏁版垨璁惧绫诲瀷閿欒"); } return Task.CompletedTask; } -- Gitblit v1.9.3