From a95c4e748b01da8bea6ba0f8e6af9c281bc582d7 Mon Sep 17 00:00:00 2001 From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com> Date: 星期二, 29 七月 2025 09:22:13 +0800 Subject: [PATCH] 优化日志格式并增强库存查询逻辑在 CommonConveyorLineJob.cs和CommonConveyorLine_GWJob.cs文件中,修改了日志输出格式,添加了时间戳以提高可读性和可追溯性。部分代码中的ToJsonString()方法被替换为 Serialize()方法,以统一序列化方式。与此同时,在 Dt_TaskService.cs文件中增加了库存信息查询逻辑,以确保出库时能够正确处理库存条件,增强系统的健壮性。 --- Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/CommonConveyorLine_GWJob.cs | 150 ++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 116 insertions(+), 34 deletions(-) diff --git a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/CommonConveyorLine_GWJob.cs b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/CommonConveyorLine_GWJob.cs index b4a25b1..cc448ff 100644 --- a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/CommonConveyorLine_GWJob.cs +++ b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/CommonConveyorLine_GWJob.cs @@ -21,10 +21,12 @@ using AutoMapper; using HslCommunication; +using Masuit.Tools; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using Quartz; using SqlSugar; +using System.ComponentModel.Design; using System.Reflection; using WIDESEAWCS_BasicInfoRepository; using WIDESEAWCS_Common; @@ -132,7 +134,7 @@ } } - if (childDeviceCode == "1670"||childDeviceCode=="1666"||childDeviceCode=="1548"||childDeviceCode=="1448") + if (childDeviceCode == "1670" || childDeviceCode == "1666" || childDeviceCode == "1548" || childDeviceCode == "1448") { Platform platform = _platFormRepository.QueryFirst(x => x.DeviceCode == conveyorLine.DeviceCode && x.PlatCode == childDeviceCode && x.Status == "Active"); if (platform != null) @@ -149,7 +151,6 @@ } } } - #region 璋冪敤浜嬩欢鎬荤嚎閫氱煡鍓嶇 var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken"); @@ -169,6 +170,8 @@ _noticeService.LineData(userIds?.FirstOrDefault(), userTokenIds, new { conveyorLine.DeviceName, data = obj }); #endregion 璋冪敤浜嬩欢鎬荤嚎閫氱煡鍓嶇 + + } #endregion 璺敱鏂瑰紡 @@ -198,7 +201,7 @@ try { var task = _taskService.QueryBarCodeConveyorLineTask(command.ConveyorLineBarcode, childDeviceCode); - var log = $"銆恵conveyorLine.DeviceName}銆戞墭鐩樺彿锛氥�恵command.ConveyorLineBarcode}銆戜换鍔″彿锛氥�恵command.ConveyorLineTaskNum}銆戣澶囩紪鐮侊細銆恵childDeviceCode}銆�"; + var log = $"鏃堕棿锛氥�恵DateTime.Now}銆戙�恵conveyorLine.DeviceName}銆戞墭鐩樺彿锛氥�恵command.ConveyorLineBarcode}銆戜换鍔″彿锛氥�恵command.ConveyorLineTaskNum}銆戣澶囩紪鐮侊細銆恵childDeviceCode}銆�"; ConsoleHelper.WriteSuccessLine(log); _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); @@ -211,15 +214,19 @@ else { var GWTask = _taskRepository.QueryData(x => x.Roadway.Contains("GWSC2") && x.SourceAddress == "1039" && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskInStatusEnum.Line_InFinish)).ToList(); - if (GWTask.Count >= 2 && childDeviceCode == "1039"&& task.Roadway.Contains("GWSC2")) + if (GWTask.Count >= 2 && childDeviceCode == "1039" && task.Roadway.Contains("GWSC2")) { - ConsoleHelper.WriteErrorLine($"鎵樼洏鍙凤細銆恵command.ConveyorLineBarcode}銆戦珮娓╀簩宸插瓨鍦ㄣ�恵GWTask.Count}銆戜釜浠诲姟澶т簬2涓换鍔′笉鍙笅鍙�"); + ConsoleHelper.WriteErrorLine($"鏃堕棿锛氥�恵DateTime.Now}銆戞墭鐩樺彿锛氥�恵command.ConveyorLineBarcode}銆戦珮娓╀簩宸插瓨鍦ㄣ�恵GWTask.Count}銆戜釜浠诲姟澶т簬2涓换鍔′笉鍙笅鍙�"); return; } ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task); - conveyorLine.SendCommand(taskCommand, childDeviceCode); - conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); - _taskService.UpdateTaskStatusToNext(task); + + bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); + if (sendFlag) + { + conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); + _taskService.UpdateTaskStatusToNext(task); + } } } catch (Exception ex) @@ -249,11 +256,25 @@ if (newTask != null) { ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(newTask); - conveyorLine.SendCommand(taskCommand, childDeviceCode); - conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); - _taskService.UpdateData(newTask); + //conveyorLine.SendCommand(taskCommand, childDeviceCode); + + bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); + if (sendFlag) + { + conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); + _taskService.UpdateData(newTask); + } } } + //else + //{ + // //褰撳墠鍦板潃璇锋眰 瀵绘壘褰撳墠鍦板潃鐨勬墭鐩樺彿 浠诲姟鍙风殑浠诲姟锛屽瀛樺湪浠诲姟鍒欓噸鏂板啀娆″啓鍏ユ柊鐩爣鍦板潃 + // Dt_Task currentTask = _taskService.QueryExecutingCurrentConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode, command.ConveyorLineBarcode); + // if (currentTask != null) + // { + // conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(currentTask.TargetAddress), childDeviceCode); + // } + //} } /// <summary> @@ -272,7 +293,7 @@ if (content.Status) { - conveyorLine.SetValue(ConveyorLineDBName_After.ResponState,Convert.ToInt16(1), childDeviceCode); + conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); } Console.Out.WriteLine(content.Serialize()); @@ -292,13 +313,18 @@ if (task != null) { ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task); - conveyorLine.SendCommand(taskCommand, childDeviceCode); - conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); + //conveyorLine.SendCommand(taskCommand, childDeviceCode); - _taskService.UpdateTaskStatusToNext(task); - if (task.TaskType == (int)TaskOutboundTypeEnum.OutTray) + bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); + if (sendFlag) { + conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); + _taskService.UpdateTaskStatusToNext(task); + if (task.TaskType == (int)TaskOutboundTypeEnum.OutTray) + { + _taskService.UpdateTaskStatusToNext(task); + } } } } @@ -335,8 +361,8 @@ var MOMIpAddress = wmsBase + ipAddress; - var result = HttpHelper.PostAsync(MOMIpAddress, trayCells.ToJsonString()).Result; - WriteInfo("鍏ョ珯鏍¢獙", $"銆恵childDeviceCode}銆戝叆绔欐牎楠岃姹傚弬鏁般�恵trayCells.ToJsonString()}銆�"); + var result = HttpHelper.PostAsync(MOMIpAddress, trayCells.Serialize()).Result; + WriteInfo("鍏ョ珯鏍¢獙", $"銆恵childDeviceCode}銆戝叆绔欐牎楠岃姹傚弬鏁般�恵trayCells.Serialize()}銆�"); WriteInfo("鍏ョ珯鏍¢獙", ""); WriteInfo("鍏ョ珯鏍¢獙", $"銆恵childDeviceCode}銆戝叆绔欐牎楠岃繑鍥炲弬鏁般�恵result}銆�"); ResultTrayCellsStatus result1 = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(result); @@ -346,18 +372,28 @@ if (newTask != null) { ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(newTask); - conveyorLine.SendCommand(taskCommand, childDeviceCode); - conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); - _taskService.UpdateData(newTask); + //conveyorLine.SendCommand(taskCommand, childDeviceCode); + + bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); + if (sendFlag) + { + conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); + _taskService.UpdateData(newTask); + } } } else { ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task); taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationNGChildCode); - conveyorLine.SendCommand(taskCommand, childDeviceCode); - conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); - _taskService.UpdateTaskStatusToNext(task); + //conveyorLine.SendCommand(taskCommand, childDeviceCode); + + bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); + if (sendFlag) + { + conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); + _taskService.UpdateTaskStatusToNext(task); + } } } } @@ -370,7 +406,7 @@ /// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param> public void ConveyorLineOutFinish(CommonConveyorLine_GW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { - var log = $"銆恵conveyorLine.DeviceName}銆戞墭鐩樺彿锛氥�恵command.ConveyorLineBarcode}銆戜换鍔″彿锛氥�恵command.ConveyorLineTaskNum}銆戣澶囩紪鐮侊細銆恵childDeviceCode}銆�"; + var log = $"鏃堕棿锛氥�恵DateTime.Now}銆戙�恵conveyorLine.DeviceName}銆戞墭鐩樺彿锛氥�恵command.ConveyorLineBarcode}銆戜换鍔″彿锛氥�恵command.ConveyorLineTaskNum}銆戣澶囩紪鐮侊細銆恵childDeviceCode}銆�"; ConsoleHelper.WriteSuccessLine(log); _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); @@ -404,9 +440,13 @@ } } - conveyorLine.SendCommand(taskCommand, childDeviceCode); - conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); - content = _taskService.UpdateTaskStatusToNext(task); + //conveyorLine.SendCommand(taskCommand, childDeviceCode); + bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); + if (sendFlag) + { + conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); + content = _taskService.UpdateTaskStatusToNext(task); + } } else { @@ -437,11 +477,16 @@ } } - conveyorLine.SendCommand(taskCommand, childDeviceCode); - conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); + //conveyorLine.SendCommand(taskCommand, childDeviceCode); - taskNext.ExceptionMessage = log; - content = _taskService.UpdateTaskStatusToNext(taskNext); + bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); + if (sendFlag) + { + conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); + + taskNext.ExceptionMessage = log; + content = _taskService.UpdateTaskStatusToNext(taskNext); + } } } } @@ -495,7 +540,7 @@ //var deviceCode = device.Select(x => x.DeviceCode).ToList(); List<string> strings = platform.Location.Split(',').ToList(); - var result = await HttpHelper.PostAsync(wmsIpAddress, new { Position = childDeviceCode, Tag = (int)taskType, AreaCdoe = platform.Stacker, AreaCdoes = strings, platform.ProductionLine }.ToJsonString()); + var result = await HttpHelper.PostAsync(wmsIpAddress, new { Position = childDeviceCode, Tag = (int)taskType, AreaCdoe = platform.Stacker, AreaCdoes = strings, platform.ProductionLine }.Serialize()); //var result = await HttpHelper.PostAsync("http://localhost:5000/api/Task/RequestTrayOutTaskAsync", dynamic.ToJsonString()); WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result); @@ -524,7 +569,44 @@ } return content; } + + public bool SendCommand(ConveyorLineTaskCommand_After taskCommand, CommonConveyorLine_GW conveyorLine, string childDeviceCode) + { + conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(taskCommand.ConveyorLineTargetAddress), childDeviceCode); + Thread.Sleep(100); + conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineBarcode, taskCommand.ConveyorLineBarcode, childDeviceCode); + Thread.Sleep(100); + conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTaskNum, taskCommand.ConveyorLineTaskNum, childDeviceCode); + for (int i = 0; i < 6; i++) + { + ConveyorLineTaskCommand_After command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(childDeviceCode); + if (command != null) + { + if (command.ConveyorLineBarcode == taskCommand.ConveyorLineBarcode && command.ConveyorLineTaskNum == taskCommand.ConveyorLineTaskNum && command.ConveyorLineTargetAddress == taskCommand.ConveyorLineTargetAddress) + { + WriteInfo(conveyorLine.DeviceName, $"鏃堕棿锛氥�恵DateTime.Now}銆戝啓鍏ヤ换鍔℃垚鍔熷啓鍏ユ鏁皗i}鍐欏叆浠诲姟銆恵JsonConvert.SerializeObject(taskCommand)}銆�"); + return true; + } + if (command.ConveyorLineTargetAddress != taskCommand.ConveyorLineTargetAddress) + { + conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(taskCommand.ConveyorLineTargetAddress), childDeviceCode); + Thread.Sleep(100); + } + if (command.ConveyorLineBarcode != taskCommand.ConveyorLineBarcode) + { + conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineBarcode, taskCommand.ConveyorLineBarcode, childDeviceCode); + Thread.Sleep(100); + } + if (command.ConveyorLineTaskNum != taskCommand.ConveyorLineTaskNum) + { + conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTaskNum, taskCommand.ConveyorLineTaskNum, childDeviceCode); Thread.Sleep(100); + } + + } + } + WriteInfo(conveyorLine.DeviceName, $"鏃堕棿锛氥�恵DateTime.Now}銆戝啓鍏ヤ换鍔″け璐ヤ换鍔″彿銆恵taskCommand.ConveyorLineTaskNum}銆戞墭鐩樺彿銆恵taskCommand.ConveyorLineBarcode}銆戠洰鏍囧湴鍧�銆恵taskCommand.ConveyorLineTargetAddress}銆戝綋鍓嶈妭鐐广�恵childDeviceCode}銆�"); + return false; + } } } - #endregion \ No newline at end of file -- Gitblit v1.9.3