From a0fdff7103fc0f394ed4c459c35eed3bc842ea07 Mon Sep 17 00:00:00 2001 From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com> Date: 星期三, 11 六月 2025 15:18:34 +0800 Subject: [PATCH] 更新 appsettings.json 配置项 --- Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs | 219 ++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 146 insertions(+), 73 deletions(-) diff --git a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs index 5104d55..22efbda 100644 --- a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs +++ b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs @@ -23,6 +23,7 @@ using WIDESEAWCS_QuartzJob; using WIDESEAWCS_QuartzJob.DeviceBase; using WIDESEAWCS_QuartzJob.DTO; +using WIDESEAWCS_QuartzJob.Models; using WIDESEAWCS_QuartzJob.Repository; using WIDESEAWCS_QuartzJob.Service; using WIDESEAWCS_SignalR; @@ -77,79 +78,115 @@ CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams"); if (conveyorLine != null) { + //ConsoleHelper.WriteColorLine("寮�濮嬶細" + DateTime.Now, ConsoleColor.Cyan); // 鏌ヨ鎵�鏈夊瓙璁惧鐨勪綅缃� List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode); + // 鑾峰彇鎵�鏈夌珯鐐圭鐞嗗櫒 + List<Dt_StationManager> stationManagers = _stationManagerService.GetAllStationByDeviceCode(conveyorLine.DeviceCode); // 骞惰澶勭悊姣忎釜瀛愯澶� var tasks = childDeviceCodes.Select(childDeviceCode => ProcessDeviceAsync(conveyorLine, childDeviceCode)).ToList(); + + // 骞惰澶勭悊姣忎釜绔欑偣绠$悊鍣� + tasks = stationManagers.Select(station => Task.Run(async () => + { + var (command, commandWrite) = ReadCommands(station, conveyorLine); + if (command == null || commandWrite == null) + { + return; + } + + IStationHandler handler = StationHandlerFactory.GetHandler(station.stationType, this); + await handler.HandleStationAsync(conveyorLine, station, command, commandWrite); + })).ToList(); + + #region + //foreach (var station in stationManagers) + //{ + // #region + // //tasks.Add(Task.Run(async () => + // //{ + // // if (station.stationType == 11) + // // { + // // // 璇诲彇浠诲姟鍛戒护鍜岃澶囧懡浠� + // // ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationChildCode); + // // ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(station.stationChildCode, "DeviceCommand"); + // // if (command != null && commandWrite != null) + // // { + // // // 灏嗕氦浜掍俊鍙疯浆鎹负甯冨皵鏁扮粍 + // // var structs = BitConverter.GetBytes(commandWrite.WriteInteractiveSignal).Reverse().ToArray().ToBoolArray(); + // // if (structs[0] == true) + // // { + // // // 杈撳嚭璀﹀憡淇℃伅 + // // var log = $"銆恵conveyorLine.DeviceName}銆戜换鍔″彿锛氥�恵command.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵command.Barcode}銆戝凡鍒拌揪銆恵station.stationChildCode}銆戠┖鎵樼洏璇锋眰鎵爜鍏ュ簱"; + // // ConsoleHelper.WriteWarningLine(log); + + // // await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); + // // WriteInfo(conveyorLine.DeviceName, log); + + // // // 澶勭悊鍏ュ簱璇锋眰 + // // NGRequestTaskInbound(conveyorLine, command, station, 0); + // // } + // // else + // // { + // // // 鍙戦�佸畬鎴愪俊鍙� + // // ConveyorLineSendFinish(conveyorLine, station.stationChildCode, 0, false); + // // } + // // } + // // } + // // else if (station.stationType == 5) + // // { + // // // 璇诲彇浠诲姟鍛戒护鍜岃澶囧懡浠� + // // ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationChildCode); + // // ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(station.stationChildCode, "DeviceCommand"); + // // if (command != null && commandWrite != null) + // // { + // // // 灏嗕氦浜掍俊鍙疯浆鎹负甯冨皵鏁扮粍 + // // var structs = BitConverter.GetBytes(commandWrite.WriteInteractiveSignal).Reverse().ToArray().ToBoolArray(); + // // if (structs[0] == true) + // // { + // // // 妫�鏌ユ槸鍚﹀瓨鍦ㄤ换鍔� + // // if (_taskRepository.QueryData(x => x.SourceAddress == station.stationChildCode).Count() > 0) + // // { + // // return; + // // } + // // // 杈撳嚭璀﹀憡淇℃伅 + // // var log = $"銆恵conveyorLine.DeviceName}銆戜换鍔″彿锛氥�恵command.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵command.Barcode}銆戝凡鍒拌揪銆恵station.stationChildCode}銆戝紓甯稿彛璇锋眰鎵爜鍏ュ簱"; + // // ConsoleHelper.WriteWarningLine(log); + + // // await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); + // // WriteInfo(conveyorLine.DeviceName, log); + + // // // 澶勭悊鏂颁换鍔� + // // await HandleNewTaskAsync(conveyorLine, command, station.stationChildCode, 0); + // // } + // // else + // // { + // // // 鍙戦�佸畬鎴愪俊鍙� + // // ConveyorLineSendFinish(conveyorLine, station.stationChildCode, 0, false); + // // } + // // } + // // } + // //})); + // #endregion + + // tasks.Add(Task.Run(async () => + // { + // var (command, commandWrite) = ReadCommands(station, conveyorLine); + // if (command == null || commandWrite == null) + // { + // return; + // } + + // IStationHandler handler = StationHandlerFactory.GetHandler(station.stationType, this); + // await handler.HandleStationAsync(conveyorLine, station, command, commandWrite); + // })); + //} + #endregion + await Task.WhenAll(tasks); - // 鑾峰彇鎵�鏈夌珯鐐圭鐞嗗櫒 - List<Dt_StationManager> stationManagers = _stationManagerService.GetAllStationByDeviceCode(conveyorLine.DeviceCode); - foreach (var station in stationManagers) - { - if (station.stationType == 11) - { - // 璇诲彇浠诲姟鍛戒护鍜岃澶囧懡浠� - ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationChildCode); - ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(station.stationChildCode, "DeviceCommand"); - if (command != null && commandWrite != null) - { - // 灏嗕氦浜掍俊鍙疯浆鎹负甯冨皵鏁扮粍 - var structs = BitConverter.GetBytes(commandWrite.WriteInteractiveSignal).Reverse().ToArray().ToBoolArray(); - if (structs[0] == true) - { - // 杈撳嚭璀﹀憡淇℃伅 - var log = $"銆恵conveyorLine.DeviceName}銆戜换鍔″彿锛氥�恵command.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵command.Barcode}銆戝凡鍒拌揪銆恵station.stationChildCode}銆戠┖鎵樼洏璇锋眰鎵爜鍏ュ簱"; - ConsoleHelper.WriteWarningLine(log); - - await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); - WriteInfo(conveyorLine.DeviceName, log); - - // 澶勭悊鍏ュ簱璇锋眰 - NGRequestTaskInbound(conveyorLine, command, station, 0); - } - else - { - // 鍙戦�佸畬鎴愪俊鍙� - ConveyorLineSendFinish(conveyorLine, station.stationChildCode, 0, false); - } - } - } - else if (station.stationType == 5) - { - // 璇诲彇浠诲姟鍛戒护鍜岃澶囧懡浠� - ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationChildCode); - ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(station.stationChildCode, "DeviceCommand"); - if (command != null && commandWrite != null) - { - // 灏嗕氦浜掍俊鍙疯浆鎹负甯冨皵鏁扮粍 - var structs = BitConverter.GetBytes(commandWrite.WriteInteractiveSignal).Reverse().ToArray().ToBoolArray(); - if (structs[0] == true) - { - // 妫�鏌ユ槸鍚﹀瓨鍦ㄤ换鍔� - if (_taskRepository.QueryData(x => x.SourceAddress == station.stationChildCode).Count() > 0) - { - return; - } - // 杈撳嚭璀﹀憡淇℃伅 - var log = $"銆恵conveyorLine.DeviceName}銆戜换鍔″彿锛氥�恵command.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵command.Barcode}銆戝凡鍒拌揪銆恵station.stationChildCode}銆戝紓甯稿彛璇锋眰鎵爜鍏ュ簱"; - ConsoleHelper.WriteWarningLine(log); - - await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); - WriteInfo(conveyorLine.DeviceName, log); - - // 澶勭悊鏂颁换鍔� - await HandleNewTaskAsync(conveyorLine, command, station.stationChildCode, 0); - } - else - { - // 鍙戦�佸畬鎴愪俊鍙� - ConveyorLineSendFinish(conveyorLine, station.stationChildCode, 0, false); - } - } - } - } + //ConsoleHelper.WriteColorLine("缁撴潫锛�" + DateTime.Now, ConsoleColor.Cyan); } } catch (Exception ex) @@ -221,7 +258,7 @@ } // 鏌ヨ骞冲彴淇℃伅 - Platform platform = _platFormRepository.QueryFirst(x => x.PLCCode == conveyorLine.DeviceCode && x.PlatCode == childDeviceCode && x.Status == "Active"); + Platform platform = _platFormRepository.QueryFirst(x => x.DeviceCode == conveyorLine.DeviceCode && x.PlatCode == childDeviceCode && x.Status == "Active"); if (platform != null && !string.IsNullOrEmpty(platform.Location)) { var strings = platform.Location.Split(',').ToList(); @@ -345,7 +382,8 @@ _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, log); - Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode); + //Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode); + Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode, command.Barcode); if (task != null) { if (command.Barcode == task.PalletCode) @@ -366,6 +404,7 @@ WriteInfo(conveyorLine.DeviceName, logs); conveyorLine.SendCommand(taskCommand, childDeviceCode); + _taskService.UpdateData(newTask); } } } @@ -390,7 +429,8 @@ _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, log); - var task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode); + //var task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode); + var task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode, command.Barcode); if (task != null && task.TaskState != (int)TaskInStatusEnum.Line_InFinish) { if (command.Barcode == task.PalletCode && childDeviceCode == task.NextAddress) @@ -512,7 +552,8 @@ WriteInfo(conveyorLine.DeviceName, log); // 鏌ヨ姝e湪鎵ц鐨勮緭閫佺嚎浠诲姟锛屾牴鎹换鍔″彿鍜屽瓙璁惧浠g爜鑾峰彇浠诲姟淇℃伅 - Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode); + //Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode); + Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode, command.Barcode); // 濡傛灉浠诲姟瀛樺湪 if (task != null) @@ -547,6 +588,8 @@ // 鏍囪杈撻�佺嚎鍙戦�佷换鍔″畬鎴� ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); + + _taskService.UpdateData(newTask); } } } @@ -570,7 +613,8 @@ WriteInfo(conveyorLine.DeviceName, logs); // 鏌ヨ姝e湪鎵ц鐨勮緭閫佺嚎浠诲姟 - var task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode); + //var task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode); + var task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode, command.Barcode); // 濡傛灉浠诲姟瀛樺湪 if (task != null) @@ -732,13 +776,26 @@ } var wmsIpAddress = wmsBase + requestTrayOutTask; - var device = _deviceInfoRepository.QueryData(x => x.DeviceStatus == "1" && x.DeviceRemark == platform.Id.ToString()); + + List<Dt_DeviceInfo> device; + if (platform.Roadway != null) + { + List<string> strings = platform.Roadway.Split(',').ToList(); + device = _deviceInfoRepository.QueryData(x => x.DeviceStatus == "1" && strings.Contains(x.DeviceCode)); + } + else + { + device = _deviceInfoRepository.QueryData(x => x.DeviceStatus == "1"); + } var deviceCode = device.Select(x => x.DeviceCode).ToList(); // 鍙戦�丠TTP POST璇锋眰鑾峰彇浠诲姟鏁版嵁 var result = await HttpHelper.PostAsync(wmsIpAddress, new { position = childDeviceCode, tag = (int)taskType, areaCdoe = platform.Stacker, AreaCdoes = deviceCode, platform.ProductionLine }.ToJsonString()); // 瑙f瀽杩斿洖鐨凧SON鏁版嵁 WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result); + + + Console.WriteLine($"{JsonConvert.SerializeObject(content)}鍛煎彨鎴愬姛"); // 妫�鏌ヨ繑鍥炵姸鎬侊紝濡傛灉澶辫触鍒欒繑鍥� if (!content.Status) @@ -748,6 +805,7 @@ taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString()); #endregion 璋冪敤WMS鑾峰彇鍑哄簱浠诲姟 + // 鍒涘缓骞跺彂閫佷换鍔� CreateAndSendTask(taskDTO); @@ -762,7 +820,7 @@ var content = _taskService.ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO }); if (content.Status) { - Console.WriteLine($"{taskDTO.TaskType}鍛煎彨鎴愬姛"); + Console.WriteLine($"{taskDTO.TargetAddress}鍛煎彨鎴愬姛"); } return content; } @@ -853,5 +911,20 @@ } #endregion 璁惧NG鍙e叆搴� + + public async Task LogAndWarn(string deviceName, string log, string color = "red") + { + ConsoleHelper.WriteWarningLine(log); + await _noticeService.Logs(userTokenIds, new { deviceName, log = log, time = DateTime.Now.ToString("G"), color = color }); + WriteInfo(deviceName, log); + } + + private (ConveyorLineTaskCommand, ConveyorLineTaskCommandWrite) ReadCommands(Dt_StationManager station, CommonConveyorLine conveyorLine) + { + ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationChildCode); + ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(station.stationChildCode, "DeviceCommand"); + return (command, commandWrite); + } + } } \ No newline at end of file -- Gitblit v1.9.3