From 4b483d9d06bead231b88ca212fd799196668a057 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期二, 28 四月 2026 22:58:27 +0800
Subject: [PATCH] fix(任务服务): 修复出库任务选择逻辑和货位分配问题
---
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs | 163 +++++++++++++++++++++++++++++++++---------------------
1 files changed, 100 insertions(+), 63 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs
index ac18766..7788251 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs
@@ -6,6 +6,7 @@
using Serilog;
using SqlSugar;
using WIDESEA_Core;
+using WIDESEAWCS_Common.HttpEnum;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
@@ -87,7 +88,7 @@
/// </summary>
/// <remarks>
/// </remarks>
- private static List<string> AddressToDeviceType = new List<string> { "11020", "11028", "2125" };
+ private static List<string> AddressToDeviceType = new List<string> { "11020", "11028", "2125", "11062" };
/// <summary>
/// 鎵樼洏妫�鏌ヤ綅缃殑鏈�杩戞墽琛屾椂闂达紙鐢ㄤ簬30绉掗棿闅旈檺鍒讹級
@@ -148,15 +149,6 @@
return Task.CompletedTask;
}
- // 鍒涘缓骞惰閫夐」锛岄檺鍒舵渶澶у苟鍙戞暟
- //var parallelOptions = new ParallelOptions
- //{
- // // 闄愬埗骞跺彂鏁帮細瀛愯澶囨暟閲忓拰 CPU 鏍稿績鏁�*2 鐨勮緝灏忓��
- // MaxDegreeOfParallelism = Math.Min(childDeviceCodes.Count, Environment.ProcessorCount * 2),
- //};
-
- // 骞惰澶勭悊姣忎釜瀛愯澶�
- //Parallel.For(0, childDeviceCodes.Count, parallelOptions, i =>
foreach (var childDeviceCode in childDeviceCodes)
{
//string childDeviceCode = childDeviceCodes[i];
@@ -176,57 +168,57 @@
// ========== 妫�鏌ョ壒瀹氫綅缃槸鍚︽湁鎵樼洏 ==========
// 浠庨厤缃腑璇诲彇闇�瑕佹鏌ユ墭鐩樼殑浣嶇疆鍒楄〃
- var checkPalletPositions = App.Configuration.GetSection("CheckPalletPositions")
- .Get<List<CheckPalletPosition>>() ?? new List<CheckPalletPosition>();
+ //var checkPalletPositions = App.Configuration.GetSection("CheckPalletPositions")
+ // .Get<List<CheckPalletPosition>>() ?? new List<CheckPalletPosition>();
- // 濡傛灉褰撳墠璁惧鍦ㄦ鏌ュ垪琛ㄤ腑
- if (checkPalletPositions.Any(x => x.Code == childDeviceCode))
- {
- // 30绉掗棿闅旈檺鍒�
- if (_lastPalletCheckTime.TryGetValue(childDeviceCode, out var lastTime) &&
- (DateTime.Now - lastTime).TotalSeconds < 30)
- {
- continue;
- }
+ //// 濡傛灉褰撳墠璁惧鍦ㄦ鏌ュ垪琛ㄤ腑
+ //if (checkPalletPositions.Any(x => x.Code == childDeviceCode))
+ //{
+ // // 30绉掗棿闅旈檺鍒�
+ // if (_lastPalletCheckTime.TryGetValue(childDeviceCode, out var lastTime) &&
+ // (DateTime.Now - lastTime).TotalSeconds < 30)
+ // {
+ // continue;
+ // }
- // 妫�鏌ヨ緭閫佺嚎鐘舵�侊紙鏄惁鏈夋墭鐩橈級
- if (command.CV_State == 2)
- {
- // 妫�鏌ヨ浣嶇疆鏄惁宸叉湁浠诲姟
- var existingTask = _taskService.Db.Queryable<Dt_Task>().First(x => x.TargetAddress == childDeviceCode);
- if (existingTask.IsNullOrEmpty())
- {
- // 娌℃湁浠诲姟锛屽悜 WMS 璇锋眰鍑哄簱鎵樼洏浠诲姟
- var position = checkPalletPositions.FirstOrDefault(x => x.Code == childDeviceCode);
+ // // 妫�鏌ヨ緭閫佺嚎鐘舵�侊紙鏄惁鏈夋墭鐩橈級
+ // if (command.CV_State == 2)
+ // {
+ // // 妫�鏌ヨ浣嶇疆鏄惁宸叉湁浠诲姟
+ // var existingTask = _taskService.Db.Queryable<Dt_Task>().Count(x => x.TargetAddress == childDeviceCode);
+ // if (existingTask < 5)
+ // {
+ // // 娌℃湁浠诲姟锛屽悜 WMS 璇锋眰鍑哄簱鎵樼洏浠诲姟
+ // var position = checkPalletPositions.FirstOrDefault(x => x.Code == childDeviceCode);
- string configKey = "GetOutBoundTrayTaskAsync";
- string requestParam = new CreateTaskDto()
- {
- WarehouseId = position.WarehouseId,
- TargetAddress = childDeviceCode
- }.Serialize();
- DateTime startTime = DateTime.Now;
+ // string configKey = "GetOutBoundTrayTaskAsync";
+ // string requestParam = new CreateTaskDto()
+ // {
+ // WarehouseId = position.WarehouseId,
+ // TargetAddress = childDeviceCode
+ // }.Serialize();
+ // DateTime startTime = DateTime.Now;
- var responseResult = _httpClientHelper.Post<WebResponseContent>(configKey, requestParam);
+ // var responseResult = _httpClientHelper.Post<WebResponseContent>(configKey, requestParam);
- _lastPalletCheckTime[childDeviceCode] = DateTime.Now;
+ // _lastPalletCheckTime[childDeviceCode] = DateTime.Now;
- // 濡傛灉璇锋眰鎴愬姛锛屾帴鏀� WMS 杩斿洖鐨勪换鍔�
- if (responseResult.IsSuccess && responseResult.Data.Status)
- {
- QuartzLogHelper.LogInfo(_logger, $"璋冪敤WMS鎺ュ彛鎴愬姛,鎺ュ彛:銆恵configKey}銆�,璇锋眰鍙傛暟:銆恵requestParam}銆�,鍝嶅簲鏁版嵁:銆恵responseResult.Data?.Data}銆�,鑰楁椂:{(DateTime.Now - startTime).TotalMilliseconds}ms", conveyorLine.DeviceCode);
- var wmsTask = JsonConvert.DeserializeObject<WMSTaskDTO>(responseResult.Data.Data.ToString());
- List<WMSTaskDTO> taskDTOs = new List<WMSTaskDTO> { wmsTask };
- if (wmsTask != null)
- _taskService.ReceiveWMSTask(taskDTOs);
- }
- else
- {
- QuartzLogHelper.LogError(_logger, $"璋冪敤WMS鎺ュ彛澶辫触,鎺ュ彛:銆恵configKey}銆�,璇锋眰鍙傛暟:銆恵requestParam}銆�,閿欒淇℃伅:銆恵responseResult.Data?.Message}銆�", conveyorLine.DeviceCode);
- }
- }
- }
- }
+ // // 濡傛灉璇锋眰鎴愬姛锛屾帴鏀� WMS 杩斿洖鐨勪换鍔�
+ // if (responseResult.IsSuccess && responseResult.Data.Status)
+ // {
+ // QuartzLogHelper.LogInfo(_logger, $"璋冪敤WMS鎺ュ彛鎴愬姛,鎺ュ彛:銆恵configKey}銆�,璇锋眰鍙傛暟:銆恵requestParam}銆�,鍝嶅簲鏁版嵁:銆恵responseResult.Data?.Data}銆�,鑰楁椂:{(DateTime.Now - startTime).TotalMilliseconds}ms", conveyorLine.DeviceCode);
+ // var wmsTask = JsonConvert.DeserializeObject<WMSTaskDTO>(responseResult.Data.Data.ToString());
+ // List<WMSTaskDTO> taskDTOs = new List<WMSTaskDTO> { wmsTask };
+ // if (wmsTask != null)
+ // _taskService.ReceiveWMSTask(taskDTOs);
+ // }
+ // else
+ // {
+ // QuartzLogHelper.LogError(_logger, $"璋冪敤WMS鎺ュ彛澶辫触,鎺ュ彛:銆恵configKey}銆�,璇锋眰鍙傛暟:銆恵requestParam}銆�,閿欒淇℃伅:銆恵responseResult.Data?.Message}銆�", conveyorLine.DeviceCode);
+ // }
+ // }
+ // }
+ //}
#endregion 妫�娴嬫槸鍚﹂渶瑕佺┖鎵樼洏
@@ -244,6 +236,7 @@
var task = _taskService.QueryManualInboundTask(childDeviceCode);
if (task != null)
{
+ QuartzLogHelper.LogInfo(_logger, $"鑾峰彇鍒拌緭閫佺嚎寮�濮嬩换鍔★紝浠诲姟鍙凤細{task.TaskNum}锛岀姸鎬�: {task.TaskStatus},褰撳墠鍦板潃锛歿conveyorLine.DeviceCode}", conveyorLine.DeviceCode);
var handler = new ManualInboundTaskHandler(_taskService, _logger);
handler.WriteTaskToPlc(conveyorLine, childDeviceCode, task);
}
@@ -270,21 +263,22 @@
Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNo, childDeviceCode);
if (!task.IsNullOrEmpty())
{
- QuartzLogHelper.LogInfo(_logger, "Execute锛氬瓙璁惧 {ChildDeviceCode} 澶勭悊浠诲姟 {TaskNum}锛岀姸鎬�: {Status}", $"澶勭悊浠诲姟 {task.TaskNum}锛岀姸鎬�: {task.TaskStatus}", conveyorLine.DeviceCode, childDeviceCode, task.TaskNum, task.TaskStatus);
+ QuartzLogHelper.LogInfo(_logger, $"澶勭悊浠诲姟 {task.TaskNum}锛岀姸鎬�: {task.TaskStatus}", conveyorLine.DeviceCode);
// 澶勭悊浠诲姟鐘舵�侊紙鏍规嵁鐘舵�佸垎鍙戝埌涓嶅悓鏂规硶锛�
ProcessTaskState(conveyorLine, command, task, childDeviceCode);
- return Task.CompletedTask;
+ continue;
}
+ // Todo锛� 涓嬮潰鐨勯�昏緫涓昏澶勭悊娌℃湁鏌ヨ鍒颁换鍔′絾鏈夋潯鐮佺殑鎯呭喌锛屽彲鑳芥槸闇�瑕佺敓鎴愭満姊版墜浠诲姟鎴栬�呰皟鐢� WMS 鍒涘缓鍏ュ簱浠诲姟 锛堜复鏃朵娇鐢級
else if (!command.Barcode.IsNullOrEmpty() && childDeviceCode == "11068")
{
- if (_robotTaskService.Db.Queryable<Dt_RobotTask>().Any(x => x.RobotTargetAddressPalletCode == command.Barcode))
+ var isWcsTask = _taskService.Db.Queryable<Dt_Task>().Any(x => x.PalletCode == command.Barcode && (x.TaskStatus == (int)TaskOutStatusEnum.OutNew || x.TaskStatus == (int)TaskInStatusEnum.InNew));
+ var isRobotTask = _robotTaskService.Db.Queryable<Dt_RobotTask>().Any(x => x.RobotTargetAddressPalletCode == command.Barcode || x.RobotRoadway == "娉ㄦ恫缁勭洏鏈烘鎵�");
+ if (isWcsTask || isRobotTask)
{
- return Task.CompletedTask;
+ continue;
}
- Random rnd = new Random();
- int num = rnd.StrictNext();//浜х敓鐪熼殢鏈烘暟
- // 娌℃湁浠诲姟鍙蜂絾鏈夋潯鐮佸苟涓斿湪11068浣嶇疆锛岀洿鎺ユ坊鍔犳満姊版墜缁勭洏浠诲姟
+ // 鐩存帴娣诲姞鏈烘鎵嬬粍鐩樹换鍔�
Dt_RobotTask robotTask = new Dt_RobotTask
{
RobotTargetAddressPalletCode = command.Barcode,
@@ -296,14 +290,57 @@
RobotGrade = 1,
RobotRoadway = "娉ㄦ恫缁勭洏鏈烘鎵�",
RobotTargetAddressLineCode = childDeviceCode,
- RobotTaskNum = num, // 鐢熸垚浠诲姟鍙�
+ RobotTaskNum = Random.Shared.StrictNext(), // 鐢熸垚浠诲姟鍙�
RobotDispatchertime = DateTime.Now,
};
if (_robotTaskService.AddData(robotTask).Status)
{
+ QuartzLogHelper.LogInfo(_logger, $"鐢熶骇鏈烘鎵嬩换鍔℃垚鍔燂紝 {robotTask.RobotTaskNum}锛岀姸鎬�: {robotTask.RobotTaskState},褰撳墠鍦板潃锛歿conveyorLine.DeviceCode}", conveyorLine.DeviceCode);
conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
}
}
+ //else if (!command.Barcode.IsNullOrEmpty() && (childDeviceCode == "11001" || childDeviceCode == "11010"))
+ //{
+ // var isWcsTask = _taskService.Db.Queryable<Dt_Task>().Any(x => x.PalletCode == command.Barcode && (x.TaskStatus == (int)TaskOutStatusEnum.OutNew || x.TaskStatus == (int)TaskInStatusEnum.InNew));
+ // var isRobotTask = _robotTaskService.Db.Queryable<Dt_RobotTask>().Any(x => x.RobotTargetAddressPalletCode == command.Barcode);
+ // if (isWcsTask || isRobotTask)
+ // {
+ // continue;
+ // }
+
+ // // 璋冪敤 WMS 鍒涘缓绌烘墭鐩樺叆搴撲换鍔�
+ // string configKey = nameof(ConfigKey.CreateTaskInboundAsync);
+ // string requestParam = new CreateTaskDto()
+ // {
+ // PalletCode = command.Barcode,
+ // SourceAddress = childDeviceCode,
+ // TargetAddress = "GWSC1", // 鐩爣鍦板潃
+ // Roadway = "GWSC1", // 宸烽亾
+ // WarehouseId = 1, // 浠撳簱 ID
+ // PalletType = 1, // 鎵樼洏绫诲瀷锛堥粯璁や负1锛�
+ // TaskType = TaskTypeEnum.InEmpty.GetHashCode() // 浠诲姟绫诲瀷锛堝叆搴�/绌烘墭鐩樺叆搴擄級
+ // }.Serialize();
+ // DateTime startTime = DateTime.Now;
+
+ // var responseResult = _httpClientHelper.Post<WebResponseContent>(configKey, requestParam);
+
+ // if (responseResult.IsSuccess && responseResult.Data.Status)
+ // {
+ // QuartzLogHelper.LogInfo(_logger, $"璋冪敤WMS鎺ュ彛鎴愬姛,鎺ュ彛:銆恵configKey}銆�,璇锋眰鍙傛暟:銆恵requestParam}銆�,鍝嶅簲鏁版嵁:銆恵responseResult.Data?.Data}銆�,鑰楁椂:{(DateTime.Now - startTime).TotalMilliseconds}ms", conveyorLine.DeviceCode);
+ // var wmsTask = JsonConvert.DeserializeObject<WMSTaskDTO>(responseResult?.Data?.Data?.ToString());
+ // List<WMSTaskDTO> taskDTOs = new List<WMSTaskDTO> { wmsTask };
+ // if (wmsTask == null) continue;
+
+ // if (_taskService.ReceiveWMSTask(taskDTOs).Status)
+ // {
+ // conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
+ // }
+ // }
+ // else
+ // {
+ // QuartzLogHelper.LogError(_logger, $"璋冪敤WMS鎺ュ彛澶辫触,鎺ュ彛:銆恵configKey}銆�,璇锋眰鍙傛暟:銆恵requestParam}銆�,閿欒淇℃伅:銆恵responseResult.Data?.Message}銆�", conveyorLine.DeviceCode);
+ // }
+ //}
}
}
catch (Exception innerEx)
--
Gitblit v1.9.3