From c5c3e4e538a11f2a6391e6b2613375b1f92eb20a Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 15 四月 2026 14:39:18 +0800
Subject: [PATCH] feat: 添加Quartz日志助手类并重构任务服务日志记录
---
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Flows/OutboundTaskFlowService.cs | 102 +++++++++++++++++++++++++++------------------------
1 files changed, 54 insertions(+), 48 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Flows/OutboundTaskFlowService.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Flows/OutboundTaskFlowService.cs
index b6d645d..5e1e70b 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Flows/OutboundTaskFlowService.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Flows/OutboundTaskFlowService.cs
@@ -1,18 +1,18 @@
-锘縰sing Newtonsoft.Json;
+锘縰sing Autofac;
+using Newtonsoft.Json;
using System.Diagnostics.CodeAnalysis;
+using WIDESEA_Core;
using WIDESEAWCS_Common.HttpEnum;
using WIDESEAWCS_Common.TaskEnum;
-using WIDESEA_Core;
using WIDESEAWCS_Core;
-using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.Enums;
+using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO;
using WIDESEAWCS_DTO.Stock;
using WIDESEAWCS_DTO.TaskInfo;
-using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
-using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
@@ -27,8 +27,8 @@
private readonly IRouterService _routerService;
private readonly HttpClientHelper _httpClientHelper;
private readonly IRobotTaskService _robotTaskService;
- private readonly ITaskService _taskService;
- private readonly ITaskRepository _taskRepository;
+ private readonly IComponentContext _componentContext;
+ private readonly IUnitOfWorkManage _unitOfWorkManage;
/// <summary>
/// 鍒濆鍖栧嚭搴撲换鍔℃祦绋嬫湇鍔°��
@@ -36,34 +36,40 @@
/// <param name="routerService">璺敱鏈嶅姟銆�</param>
/// <param name="httpClientHelper">WMS鎺ュ彛璋冪敤甯姪绫汇��</param>
/// <param name="robotTaskService">鏈烘鎵嬩换鍔℃湇鍔°��</param>
- /// <param name="taskService">浠诲姟鏈嶅姟锛堢敤浜庢帴鏀跺叆搴撲换鍔★級銆�</param>
- /// <param name="taskRepository">浠诲姟浠撳偍锛堢敤浜庡垹闄ゅ嚭搴撲换鍔★級銆�</param>
- public OutboundTaskFlowService(IRouterService routerService, HttpClientHelper httpClientHelper, IRobotTaskService robotTaskService, ITaskService taskService, ITaskRepository taskRepository)
+ /// <param name="componentContext">Autofac缁勪欢涓婁笅鏂囷紙鐢ㄤ簬寤惰繜瑙f瀽ITaskService浠ラ伩鍏嶅惊鐜緷璧栵級銆�</param>
+ public OutboundTaskFlowService(IRouterService routerService, HttpClientHelper httpClientHelper, IRobotTaskService robotTaskService, IComponentContext componentContext, IUnitOfWorkManage unitOfWorkManage)
{
_routerService = routerService;
_httpClientHelper = httpClientHelper;
_robotTaskService = robotTaskService;
- _taskService = taskService;
- _taskRepository = taskRepository;
+ _componentContext = componentContext;
+ _unitOfWorkManage = unitOfWorkManage;
}
+
+ /// <summary>
+ /// 寤惰繜瑙f瀽ITaskService浠ラ伩鍏嶅惊鐜緷璧�
+ /// </summary>
+ private ITaskService TaskService => _componentContext.Resolve<ITaskService>();
/// <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>
@@ -131,36 +137,7 @@
task.Modifier = "System";
// 閫氱煡WMS鍑哄簱瀹屾垚骞惰幏鍙栬繑鍥炵粨鏋�
- var result = _httpClientHelper.Post<WebResponseContent>(
- nameof(ConfigKey.OutboundFinishTaskAsync),
- new StockInfoDTO { PalletCode = task.PalletCode, TaskNum = task.TaskNum }.ToJson());
-
- if (!result.IsSuccess || !result.Data.Status)
- {
- return content.Error($"閫氱煡WMS绯荤粺鍫嗗灈鏈哄嚭搴撳畬鎴愬け璐�,浠诲姟鍙�:銆恵task.TaskNum}銆�,鎵樼洏鍙�:銆恵task.PalletCode}銆�,閿欒淇℃伅:銆恵result.Data?.Message}銆�");
- }
-
- // 澶勭悊WMS杩斿洖鐨勫叆搴撲换鍔★紙濡傛灉鏈夛級
- if (result.Data?.Data != null)
- {
- var inboundTaskJson = result.Data.Data.ToString();
- var inboundTaskDto = JsonConvert.DeserializeObject<WMSTaskDTO>(inboundTaskJson);
-
- if (inboundTaskDto != null)
- {
- // 鍏堝垹闄ゆ湰鍦板嚭搴撲换鍔★紝閬垮厤鎵樼洏鍙峰敮涓�閿啿绐�
- _taskRepository.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
-
- // 璋冪敤ReceiveWMSTask鍒涘缓鏈湴鍏ュ簱浠诲姟
- var receiveResult = _taskService.ReceiveWMSTask(new List<WMSTaskDTO> { inboundTaskDto });
- if (!receiveResult.Status)
- {
- return content.Error($"鍒涘缓鏈湴鍏ュ簱浠诲姟澶辫触: {receiveResult.Message}");
- }
- }
- }
-
- return content.OK($"閫氱煡WMS绯荤粺鍫嗗灈鏈哄嚭搴撳畬鎴愭垚鍔�,浠诲姟鍙�:銆恵task.TaskNum}銆�,鎵樼洏鍙�:銆恵task.PalletCode}銆�");
+ return NotifyWMSOutboundFinish(task);
}
/// <summary>
@@ -170,14 +147,43 @@
/// <returns>閫氱煡缁撴灉銆�</returns>
private WebResponseContent NotifyWMSOutboundFinish(Dt_Task task)
{
+ WebResponseContent content = new WebResponseContent();
+
+ // 閫氱煡WMS鍑哄簱瀹屾垚骞惰幏鍙栬繑鍥炵粨鏋�
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 content.Error($"閫氱煡WMS绯荤粺鍫嗗灈鏈哄嚭搴撳畬鎴愬け璐�,浠诲姟鍙�:銆恵task.TaskNum}銆�,鎵樼洏鍙�:銆恵task.PalletCode}銆�,閿欒淇℃伅:銆恵result.Data?.Message}銆�");
+ // 澶勭悊WMS杩斿洖鐨勫叆搴撲换鍔★紙濡傛灉鏈夛級
+ if (result.Data?.Data != null)
+ {
+ var inboundTaskJson = result.Data.Data.ToString();
+ var inboundTaskDto = JsonConvert.DeserializeObject<WMSTaskDTO>(inboundTaskJson);
- return WebResponseContent.Instance.OK();
+ if (inboundTaskDto != null)
+ {
+ _unitOfWorkManage.BeginTran(() =>
+ {
+ // 鍏堝垹闄ゆ湰鍦板嚭搴撲换鍔★紝閬垮厤鎵樼洏鍙峰敮涓�閿啿绐�
+ bool isDeleted = TaskService.Repository.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
+ if (!isDeleted)
+ {
+ return content.Error($"鍒犻櫎鏈湴鍑哄簱浠诲姟澶辫触,浠诲姟鍙�:銆恵task.TaskNum}銆�,鎵樼洏鍙�:銆恵task.PalletCode}銆�");
+ }
+
+ // 璋冪敤ReceiveWMSTask鍒涘缓鏈湴鍏ュ簱浠诲姟
+ var receiveResult = TaskService.ReceiveWMSTask(new List<WMSTaskDTO> { inboundTaskDto });
+ if (!receiveResult.Status)
+ {
+ return content.Error($"鍒涘缓鏈湴鍏ュ簱浠诲姟澶辫触: {receiveResult.Message}");
+ }
+ return content.OK("鍒涘缓鏈湴鍏ュ簱浠诲姟鎴愬姛");
+ });
+ }
+ }
+ return content.OK($"閫氱煡WMS绯荤粺鍫嗗灈鏈哄嚭搴撳畬鎴愭垚鍔�,浠诲姟鍙�:銆恵task.TaskNum}銆�,鎵樼洏鍙�:銆恵task.PalletCode}銆�");
}
/// <summary>
@@ -213,7 +219,7 @@
{
var result = _httpClientHelper.Post<WebResponseContent>(
nameof(ConfigKey.UpdateTaskByStatus),
- new UpdateTaskDto { Id = task.TaskNum, NewStatus = task.TaskStatus }.ToJson());
+ new UpdateTaskDto { Id = task.TaskNum, NewStatus = task.TaskStatus, NextAddress = task.NextAddress, CurrentAddress = task.CurrentAddress }.ToJson());
if (!result.IsSuccess || !result.Data.Status)
return WebResponseContent.Instance.Error($"璋冪敤WMS鎺ュ彛鏇存柊浠诲姟鐘舵�佸け璐�,浠诲姟鍙�:銆恵task.TaskNum}銆�,閿欒淇℃伅:銆恵result.Data?.Message}銆�");
@@ -238,4 +244,4 @@
return WebResponseContent.Instance.OK();
}
}
-}
+}
\ No newline at end of file
--
Gitblit v1.9.3