From bec4a1b386c740ce4fc53a52b8ec8846ffb5f2bd Mon Sep 17 00:00:00 2001 From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com> Date: 星期日, 17 八月 2025 15:53:25 +0800 Subject: [PATCH] 代码优化 --- 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs | 107 ++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 73 insertions(+), 34 deletions(-) diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs" index 860137f..772c2af 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs" @@ -5,10 +5,12 @@ using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; +using WIDESEA_Common.Log; using WIDESEAWCS_Common; using WIDESEAWCS_Common.TaskEnum; using WIDESEAWCS_Core; using WIDESEAWCS_Core.Helper; +using WIDESEAWCS_DTO.StackerHandTask; using WIDESEAWCS_DTO.TaskInfo; using WIDESEAWCS_Model.BasicInfo; using WIDESEAWCS_Model.Models; @@ -54,51 +56,84 @@ private async Task RequestTask(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, Dt_StationManager stationManager) { - var hasTask = await _taskRepository.QueryFirstAsync(x => x.SourceAddress == childDeviceCode && x.TaskState < (int)TaskInStatusEnum.RGV_InExecutingFinish && x.TaskState >= (int)TaskInStatusEnum.InNew); - if (hasTask != null) + try { - var log = $"銆恵conveyorLine._deviceName}銆戜换鍔″彿锛氥�恵hasTask.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵hasTask.PalletCode}銆戝凡鍒拌揪銆恵childDeviceCode}銆戣緭閫佺嚎瀛樺湪浠诲姟"; + var hasTask = await _taskRepository.QueryFirstAsync(x => x.SourceAddress == childDeviceCode && x.TaskState < (int)TaskInStatusEnum.RGV_InExecutingFinish && x.TaskState >= (int)TaskInStatusEnum.InNew); + if (hasTask != null) + { + var log = $"銆恵conveyorLine._deviceName}銆戜换鍔″彿锛氥�恵hasTask.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵hasTask.PalletCode}銆戝凡鍒拌揪銆恵childDeviceCode}銆戣緭閫佺嚎瀛樺湪浠诲姟"; + ConsoleHelper.WriteWarningLine(log); + + await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); + WriteInfo(conveyorLine.DeviceName, log); + return; + } + var RGVName = string.Empty; + if (stationManager.stationFloor == "1F") + { + RGVName = stationManager.RGVName; + } + else + { + RGVName = "RGV03"; + } + int targetStation = 0; + if (childDeviceCode == "1004" || childDeviceCode == "1039" || childDeviceCode == "1040" || childDeviceCode == "1013" || childDeviceCode == "1014") + { + targetStation = 14; + } + else if (childDeviceCode == "1015" || childDeviceCode == "1016" || childDeviceCode == "1027" || childDeviceCode == "1028" || childDeviceCode == "1029" || childDeviceCode == "1030") + { + targetStation = 1; + } + else + { + targetStation = 0; + } + Dt_Task task = new Dt_Task() + { + TaskNum = _taskRepository.GetTaskNo().Result, + TaskType = (int)TaskInboundTypeEnum.Inbound, + TaskState = (int)TaskInStatusEnum.InNew, + SourceAddress = childDeviceCode, + Dispatchertime = DateTime.Now, + Grade = 1, + Creater = "System", + Floor = stationManager.stationFloor, + RGVName = RGVName, + SourceStation = stationManager.remark, + TargetStation = targetStation, + }; + + _taskRepository.AddData(task); + } + catch (Exception ex) + { + var log = $"銆恵conveyorLine._deviceName}銆戣緭閫佺嚎銆恵childDeviceCode}銆戙�恵ex.Message}銆�"; ConsoleHelper.WriteWarningLine(log); await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, log); - return; } - var RGVName = string.Empty; - if (stationManager.stationFloor == "1F") - { - RGVName = stationManager.RGVName; - } - else - { - RGVName = "RGV03"; - } - Dt_Task task = new Dt_Task() - { - TaskNum = _taskRepository.GetTaskNo().Result, - TaskType = (int)TaskInboundTypeEnum.Inbound, - TaskState = (int)TaskInStatusEnum.InNew, - SourceAddress = childDeviceCode, - Dispatchertime = DateTime.Now, - Grade = 1, - Creater = "System", - Floor = stationManager.stationFloor, - RGVName = RGVName, - SourceStation= stationManager.remark, - }; - - _taskRepository.AddData(task); + } private void RequestWMSTask(CommonConveyorLine conveyorLine, Dt_StationManager stationManager) { if (stationManager.stationChildCode == "3002") { + + var newTask = _taskRepository.QueryFirst(x => x.TargetAddress == "3004"); + if (newTask != null) + { + return; + } + DeviceProDTO? devicePro = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == stationManager.stationChildCode && x.DeviceProParamName == "ConveyorLineBarcode").FirstOrDefault(); - var x = conveyorLine.Communicator.Read(devicePro.DeviceProAddress, 5); + var x = conveyorLine.Communicator.Read(devicePro.DeviceProAddress, 10); string Barcode = Encoding.UTF8.GetString(x); - if (Barcode == null) + if (Barcode == null || Barcode==""|| Barcode.Trim().Contains("\0")) { conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(3), stationManager.stationChildCode); } @@ -137,29 +172,32 @@ } var wmsIpAddress = wmsBase + requestTask; var result = WIDESEA_Comm.Http.HttpHelper.PostAsync(wmsIpAddress, taskDTO.ToJsonString()).Result; + WriteLog.GetLog("WMS鎺ュ彛杩斿洖淇℃伅").Write(JsonConvert.SerializeObject(result), "WMS鎺ュ彛杩斿洖淇℃伅"); } } else { DeviceProDTO? devicePro = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == stationManager.stationNextChildCode && x.DeviceProParamName == "ConveyorLineBarcode").FirstOrDefault(); - var x = conveyorLine.Communicator.Read(devicePro.DeviceProAddress, 5); + var x = conveyorLine.Communicator.Read(devicePro.DeviceProAddress, 10); string Barcode = Encoding.UTF8.GetString(x); - if (Barcode == "") + + if (Barcode == null || Barcode == "" || Barcode.Trim().Contains("\0")) { conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(3), stationManager.stationChildCode); } var task = _taskRepository.QueryFirst(x => x.PalletCode == Barcode); if (task != null) { - + var log = $"銆恵conveyorLine._deviceName}銆戠珯鍙般�恵stationManager.stationChildCode}銆戣姹傚彇璐с�佸凡瀛樺湪浠诲姟浠诲姟鍙穥task.TaskNum}"; + LogAndWarn(conveyorLine.DeviceName, log); } else { var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue; var requestTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestTask)?.ConfigValue; - + WMSTaskDTO taskDTO = new WMSTaskDTO() { TPbarcode = Barcode, @@ -172,6 +210,7 @@ } var wmsIpAddress = wmsBase + requestTask; var result = WIDESEA_Comm.Http.HttpHelper.PostAsync(wmsIpAddress, taskDTO.ToJsonString()).Result; + WriteLog.GetLog("WMS鎺ュ彛杩斿洖淇℃伅").Write(JsonConvert.SerializeObject(result), "WMS鎺ュ彛杩斿洖淇℃伅"); } } } -- Gitblit v1.9.3