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_TaskInfoService/Flows/OutboundTaskFlowService.cs | 139 +++++++++++++++++++++++++++++++---------------
1 files changed, 93 insertions(+), 46 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Flows/OutboundTaskFlowService.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Flows/OutboundTaskFlowService.cs
index 6082140..c34af94 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Flows/OutboundTaskFlowService.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Flows/OutboundTaskFlowService.cs
@@ -1,5 +1,5 @@
-锘縰sing Autofac;
-using Newtonsoft.Json;
+锘縰sing Newtonsoft.Json;
+using Serilog;
using System.Diagnostics.CodeAnalysis;
using WIDESEA_Core;
using WIDESEAWCS_Common.HttpEnum;
@@ -11,10 +11,12 @@
using WIDESEAWCS_DTO;
using WIDESEAWCS_DTO.Stock;
using WIDESEAWCS_DTO.TaskInfo;
+using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
+using WIDESEAWCS_Tasks;
namespace WIDESEAWCS_TaskInfoService.Flows
{
@@ -27,8 +29,10 @@
private readonly IRouterService _routerService;
private readonly HttpClientHelper _httpClientHelper;
private readonly IRobotTaskService _robotTaskService;
- private readonly IComponentContext _componentContext;
+ private readonly ITaskRepository _taskRepository;
private readonly IUnitOfWorkManage _unitOfWorkManage;
+ private readonly ILogger _logger;
+ private Func<List<WMSTaskDTO>, WebResponseContent> _receiveWMSTaskFunc;
/// <summary>
/// 鍒濆鍖栧嚭搴撲换鍔℃祦绋嬫湇鍔°��
@@ -36,38 +40,53 @@
/// <param name="routerService">璺敱鏈嶅姟銆�</param>
/// <param name="httpClientHelper">WMS鎺ュ彛璋冪敤甯姪绫汇��</param>
/// <param name="robotTaskService">鏈烘鎵嬩换鍔℃湇鍔°��</param>
- /// <param name="componentContext">Autofac缁勪欢涓婁笅鏂囷紙鐢ㄤ簬寤惰繜瑙f瀽ITaskService浠ラ伩鍏嶅惊鐜緷璧栵級銆�</param>
- public OutboundTaskFlowService(IRouterService routerService, HttpClientHelper httpClientHelper, IRobotTaskService robotTaskService, IComponentContext componentContext, IUnitOfWorkManage unitOfWorkManage)
+ /// <param name="taskRepository">浠诲姟浠撳偍锛堢敤浜庡垹闄�/褰掓。浠诲姟锛夈��</param>
+ /// <param name="unitOfWorkManage">宸ヤ綔鍗曞厓绠$悊鍣ㄣ��</param>
+ /// <param name="logger">鏃ュ織璁板綍鍣ㄣ��</param>
+ public OutboundTaskFlowService(
+ IRouterService routerService,
+ HttpClientHelper httpClientHelper,
+ IRobotTaskService robotTaskService,
+ ITaskRepository taskRepository,
+ IUnitOfWorkManage unitOfWorkManage,
+ ILogger logger)
{
_routerService = routerService;
_httpClientHelper = httpClientHelper;
_robotTaskService = robotTaskService;
- _componentContext = componentContext;
+ _taskRepository = taskRepository;
_unitOfWorkManage = unitOfWorkManage;
+ _logger = logger;
}
/// <summary>
- /// 寤惰繜瑙f瀽ITaskService浠ラ伩鍏嶅惊鐜緷璧�
+ /// 璁剧疆鎺ユ敹WMS浠诲姟鐨勫鎵橈紙鐢盩askService鍦ㄦ瀯閫犲悗璋冪敤锛岄伩鍏嶅惊鐜緷璧栵級銆�
/// </summary>
- private ITaskService TaskService => _componentContext.Resolve<ITaskService>();
+ /// <param name="receiveWMSTaskFunc">鎺ユ敹WMS浠诲姟鐨勬柟娉曞鎵樸��</param>
+ public void SetReceiveWMSTaskDelegate(Func<List<WMSTaskDTO>, WebResponseContent> receiveWMSTaskFunc)
+ {
+ _receiveWMSTaskFunc = receiveWMSTaskFunc;
+ }
/// <summary>
/// 鎺ユ敹WMS浠诲姟鏃跺垵濮嬪寲鍑哄簱浠诲姟銆�
/// </summary>
/// <param name="task">浠诲姟瀹炰綋銆�</param>
/// <param name="source">WMS浠诲姟鍘熷鏁版嵁銆�</param>
- public void InitializeOnReceive([NotNull] Dt_Task task, [NotNull] WMSTaskDTO source)
+ public WebResponseContent InitializeOnReceive([NotNull] Dt_Task task, [NotNull] WMSTaskDTO source)
{
+ WebResponseContent content = new WebResponseContent();
int taskType = task.TaskType == (int)TaskOutboundTypeEnum.OutEmpty ? 100 : task.TaskType;
Dt_Router router = _routerService.QueryNextRoute(source.Roadway, source.TargetAddress, taskType);
if (router == null)
{
- return;
+ return content.Error("鏈壘鍒拌澶囪矾鐢变俊鎭�");
}
task.TaskStatus = (int)TaskOutStatusEnum.OutNew;
task.CurrentAddress = source.SourceAddress;
task.NextAddress = router.ChildPosi;
+ return content.OK();
}
/// <summary>
@@ -77,6 +96,7 @@
/// <returns>鎺ㄨ繘缁撴灉銆�</returns>
public WebResponseContent MoveToNextStatus([NotNull] Dt_Task task)
{
+ WebResponseContent content = new WebResponseContent();
if (task.TaskStatus >= (int)TaskOutStatusEnum.OutFinish)
return WebResponseContent.Instance.Error($"璇ヤ换鍔$姸鎬佷笉鍙烦杞埌涓嬩竴姝�,浠诲姟鍙�:銆恵task.TaskNum}銆�,浠诲姟鐘舵��:銆恵task.TaskStatus}銆�");
@@ -86,17 +106,18 @@
if (task.TaskStatus == (int)TaskOutStatusEnum.Line_OutFinish && task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
{
+ return WebResponseContent.Instance.OK();
return GetWMSOutboundTrayTask(task);
}
if (task.TaskStatus == (int)TaskOutStatusEnum.Line_OutFinish && task.TaskType == (int)TaskOutboundTypeEnum.OutEmpty)
{
- WebResponseContent content = _robotTaskService.GetWMSRobotTask(task);
- if (!content.Status)
- {
- return content;
- }
- return OutboundFinishTaskTray(task);
+ return _robotTaskService.CreateLocalRobotTask(task);
+ //if (!content.Status)
+ //{
+ // return content;
+ //}
+ //return OutboundFinishTaskTray(task);
}
if (task.TaskStatus == (int)TaskOutStatusEnum.Line_OutExecuting)
@@ -135,15 +156,32 @@
task.Modifier = "System";
// 閫氱煡WMS鍑哄簱瀹屾垚骞惰幏鍙栬繑鍥炵粨鏋�
+ return NotifyWMSOutboundFinish(task);
+ }
+
+ /// <summary>
+ /// 閫氱煡WMS鍑哄簱瀹屾垚銆�
+ /// </summary>
+ /// <param name="task">浠诲姟瀹炰綋銆�</param>
+ /// <returns>閫氱煡缁撴灉銆�</returns>
+ private WebResponseContent NotifyWMSOutboundFinish(Dt_Task task)
+ {
+ WebResponseContent content = new WebResponseContent();
+ string configKey = nameof(ConfigKey.OutboundFinishTaskAsync);
+ string requestParam = new StockInfoDTO { PalletCode = task.PalletCode, TaskNum = task.TaskNum }.ToJson();
+ DateTime startTime = DateTime.Now;
+
var result = _httpClientHelper.Post<WebResponseContent>(
- nameof(ConfigKey.OutboundFinishTaskAsync),
- new StockInfoDTO { PalletCode = task.PalletCode, TaskNum = task.TaskNum }.ToJson());
+ configKey,
+ requestParam);
if (!result.IsSuccess || !result.Data.Status)
{
+ QuartzLogHelper.LogError(_logger, $"璋冪敤WMS鎺ュ彛澶辫触,鎺ュ彛:銆恵configKey}銆�,璇锋眰鍙傛暟:銆恵requestParam}銆�,閿欒淇℃伅:銆恵result.Data?.Message}銆�", "OutboundTaskFlowService");
return content.Error($"閫氱煡WMS绯荤粺鍫嗗灈鏈哄嚭搴撳畬鎴愬け璐�,浠诲姟鍙�:銆恵task.TaskNum}銆�,鎵樼洏鍙�:銆恵task.PalletCode}銆�,閿欒淇℃伅:銆恵result.Data?.Message}銆�");
}
+ QuartzLogHelper.LogInfo(_logger, $"璋冪敤WMS鎺ュ彛鎴愬姛,鎺ュ彛:銆恵configKey}銆�,鍝嶅簲鏁版嵁:銆恵result.Data?.Data}銆�,鑰楁椂:{(DateTime.Now - startTime).TotalMilliseconds}ms", "OutboundTaskFlowService");
// 澶勭悊WMS杩斿洖鐨勫叆搴撲换鍔★紙濡傛灉鏈夛級
if (result.Data?.Data != null)
{
@@ -155,14 +193,14 @@
_unitOfWorkManage.BeginTran(() =>
{
// 鍏堝垹闄ゆ湰鍦板嚭搴撲换鍔★紝閬垮厤鎵樼洏鍙峰敮涓�閿啿绐�
- bool isDeleted = TaskService.Repository.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
+ bool isDeleted = _taskRepository.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
if (!isDeleted)
{
return content.Error($"鍒犻櫎鏈湴鍑哄簱浠诲姟澶辫触,浠诲姟鍙�:銆恵task.TaskNum}銆�,鎵樼洏鍙�:銆恵task.PalletCode}銆�");
}
- // 璋冪敤ReceiveWMSTask鍒涘缓鏈湴鍏ュ簱浠诲姟
- var receiveResult = TaskService.ReceiveWMSTask(new List<WMSTaskDTO> { inboundTaskDto });
+ // 璋冪敤ReceiveWMSTask濮旀墭鍒涘缓鏈湴鍏ュ簱浠诲姟
+ var receiveResult = _receiveWMSTaskFunc(new List<WMSTaskDTO> { inboundTaskDto });
if (!receiveResult.Status)
{
return content.Error($"鍒涘缓鏈湴鍏ュ簱浠诲姟澶辫触: {receiveResult.Message}");
@@ -171,25 +209,7 @@
});
}
}
-
return content.OK($"閫氱煡WMS绯荤粺鍫嗗灈鏈哄嚭搴撳畬鎴愭垚鍔�,浠诲姟鍙�:銆恵task.TaskNum}銆�,鎵樼洏鍙�:銆恵task.PalletCode}銆�");
- }
-
- /// <summary>
- /// 閫氱煡WMS鍑哄簱瀹屾垚銆�
- /// </summary>
- /// <param name="task">浠诲姟瀹炰綋銆�</param>
- /// <returns>閫氱煡缁撴灉銆�</returns>
- private WebResponseContent NotifyWMSOutboundFinish(Dt_Task task)
- {
- var result = _httpClientHelper.Post<WebResponseContent>(
- nameof(ConfigKey.OutboundFinishTaskAsync),
- new StockInfoDTO { PalletCode = task.PalletCode, TaskNum = task.TaskNum }.ToJson());
-
- if (!result.IsSuccess || !result.Data.Status)
- return WebResponseContent.Instance.Error($"閫氱煡WMS绯荤粺鍫嗗灈鏈哄嚭搴撳畬鎴愬け璐�,浠诲姟鍙�:銆恵task.TaskNum}銆�,鎵樼洏鍙�:銆恵task.PalletCode}銆�,閿欒淇℃伅:銆恵result.Data?.Message}銆�");
-
- return WebResponseContent.Instance.OK();
}
/// <summary>
@@ -201,19 +221,30 @@
{
int warehouseId = _robotTaskService.MapWarehouseIdConfigKey(task.TargetAddress);
string sourceLineNo = _robotTaskService.ResolveRobotRuleValue(task.TargetAddress, "AddressSourceLineNoMap", task.TargetAddress);
+ string configKey = nameof(ConfigKey.GetOutBoundTrayTaskAsync);
+ string requestParam = new CreateTaskDto { WarehouseId = warehouseId, TargetAddress = sourceLineNo }.ToJson();
+ DateTime startTime = DateTime.Now;
var result = _httpClientHelper.Post<WebResponseContent>(
- nameof(ConfigKey.GetOutBoundTrayTaskAsync),
- new CreateTaskDto { WarehouseId = warehouseId, TargetAddress = sourceLineNo }.ToJson());
+ configKey,
+ requestParam);
if (!result.IsSuccess || !result.Data.Status)
+ {
+ QuartzLogHelper.LogError(_logger, $"璋冪敤WMS鎺ュ彛澶辫触,鎺ュ彛:銆恵configKey}銆�,璇锋眰鍙傛暟:銆恵requestParam}銆�,閿欒淇℃伅:銆恵result.Data?.Message}銆�", "OutboundTaskFlowService");
return WebResponseContent.Instance.Error($"鑾峰彇WMS绯荤粺绌烘墭鐩樺嚭搴撲换鍔″け璐�,浠诲姟鍙�:銆恵task.TaskNum}銆�,鎵樼洏鍙�:銆恵task.PalletCode}銆�,閿欒淇℃伅:銆恵result.Data?.Message}銆�");
+ }
+
+ QuartzLogHelper.LogInfo(_logger, $"璋冪敤WMS鎺ュ彛鎴愬姛,鎺ュ彛:銆恵configKey}銆�,鍝嶅簲鏁版嵁:銆恵result.Data?.Data}銆�,鑰楁椂:{(DateTime.Now - startTime).TotalMilliseconds}ms", "OutboundTaskFlowService");
WMSTaskDTO? wMSTask = JsonConvert.DeserializeObject<WMSTaskDTO>(result.Data.Data?.ToString() ?? string.Empty);
if (wMSTask == null)
return WebResponseContent.Instance.Error($"鑾峰彇WMS绯荤粺绌烘墭鐩樺嚭搴撲换鍔″け璐�,浠诲姟鍙�:銆恵task.TaskNum}銆�,鎵樼洏鍙�:銆恵task.PalletCode}銆�,閿欒淇℃伅:銆怶MS鏈繑鍥炴湁鏁堜换鍔℃暟鎹��");
- return WebResponseContent.Instance.OK("鎴愬姛", new List<WMSTaskDTO> { wMSTask });
+ if (_receiveWMSTaskFunc(new List<WMSTaskDTO> { wMSTask }).Status)
+ return WebResponseContent.Instance.OK("鎴愬姛");
+
+ return WebResponseContent.Instance.Error("鎺ユ敹WMS浠诲姟澶辫触");
}
/// <summary>
@@ -223,13 +254,21 @@
/// <returns>鍚屾缁撴灉銆�</returns>
private WebResponseContent UpdateWMSTaskStatus(Dt_Task task)
{
+ string configKey = nameof(ConfigKey.UpdateTaskByStatus);
+ string requestParam = new UpdateTaskDto { Id = task.TaskNum, NewStatus = task.TaskStatus, NextAddress = task.NextAddress, CurrentAddress = task.CurrentAddress }.ToJson();
+ DateTime startTime = DateTime.Now;
+
var result = _httpClientHelper.Post<WebResponseContent>(
- nameof(ConfigKey.UpdateTaskByStatus),
- new UpdateTaskDto { Id = task.TaskNum, NewStatus = task.TaskStatus, NextAddress = task.NextAddress, CurrentAddress = task.CurrentAddress }.ToJson());
+ configKey,
+ requestParam);
if (!result.IsSuccess || !result.Data.Status)
+ {
+ QuartzLogHelper.LogError(_logger, $"璋冪敤WMS鎺ュ彛澶辫触,鎺ュ彛:銆恵configKey}銆�,璇锋眰鍙傛暟:銆恵requestParam}銆�,閿欒淇℃伅:銆恵result.Data?.Message}銆�", "OutboundTaskFlowService");
return WebResponseContent.Instance.Error($"璋冪敤WMS鎺ュ彛鏇存柊浠诲姟鐘舵�佸け璐�,浠诲姟鍙�:銆恵task.TaskNum}銆�,閿欒淇℃伅:銆恵result.Data?.Message}銆�");
+ }
+ QuartzLogHelper.LogInfo(_logger, $"璋冪敤WMS鎺ュ彛鎴愬姛,鎺ュ彛:銆恵configKey}銆�,鍝嶅簲鏁版嵁:銆恵result.Data?.Data}銆�,鑰楁椂:{(DateTime.Now - startTime).TotalMilliseconds}ms", "OutboundTaskFlowService");
return WebResponseContent.Instance.OK();
}
@@ -240,13 +279,21 @@
/// <returns>鍚屾缁撴灉銆�</returns>
private WebResponseContent OutboundFinishTaskTray(Dt_Task task)
{
+ string configKey = nameof(ConfigKey.OutboundFinishTaskTray);
+ string requestParam = new CreateTaskDto { PalletCode = task.PalletCode, SourceAddress = task.SourceAddress }.ToJson();
+ DateTime startTime = DateTime.Now;
+
var result = _httpClientHelper.Post<WebResponseContent>(
- nameof(ConfigKey.OutboundFinishTaskTray),
- new CreateTaskDto { PalletCode = task.PalletCode, SourceAddress = task.SourceAddress }.ToJson());
+ configKey,
+ requestParam);
if (!result.IsSuccess || !result.Data.Status)
+ {
+ QuartzLogHelper.LogError(_logger, $"璋冪敤WMS鎺ュ彛澶辫触,鎺ュ彛:銆恵configKey}銆�,璇锋眰鍙傛暟:銆恵requestParam}銆�,閿欒淇℃伅:銆恵result.Data?.Message}銆�", "OutboundTaskFlowService");
return WebResponseContent.Instance.Error($"璋冪敤WMS鎺ュ彛鏇存柊浠诲姟鐘舵�佸け璐�,浠诲姟鍙�:銆恵task.TaskNum}銆�,閿欒淇℃伅:銆恵result.Data?.Message}銆�");
+ }
+ QuartzLogHelper.LogInfo(_logger, $"璋冪敤WMS鎺ュ彛鎴愬姛,鎺ュ彛:銆恵configKey}銆�,鍝嶅簲鏁版嵁:銆恵result.Data?.Data}銆�,鑰楁椂:{(DateTime.Now - startTime).TotalMilliseconds}ms", "OutboundTaskFlowService");
return WebResponseContent.Instance.OK();
}
}
--
Gitblit v1.9.3