wanshenmean
23 小时以前 d14030746fcd0310d3c9b028fe2c0a5b78984eb6
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Flows/RelocationTaskFlowService.cs
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using Serilog;
using WIDESEAWCS_Common.HttpEnum;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEA_Core;
@@ -8,6 +9,7 @@
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_Tasks;
namespace WIDESEAWCS_TaskInfoService.Flows
{
@@ -18,14 +20,16 @@
    public class RelocationTaskFlowService : IRelocationTaskFlowService
    {
        private readonly HttpClientHelper _httpClientHelper;
        private readonly ILogger _logger;
        /// <summary>
        /// 初始化移库任务流程服务。
        /// </summary>
        /// <param name="httpClientHelper">WMS接口调用帮助类。</param>
        public RelocationTaskFlowService(HttpClientHelper httpClientHelper)
        public RelocationTaskFlowService(HttpClientHelper httpClientHelper, ILogger logger)
        {
            _httpClientHelper = httpClientHelper;
            _logger = logger;
        }
        /// <summary>
@@ -34,9 +38,10 @@
        /// </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)
        {
            // 当前版本移库任务接收时不需要额外设置路由或状态。
            return WebResponseContent.Instance.OK();
        }
        /// <summary>
@@ -100,13 +105,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 }.ToJson());
                configKey,
                requestParam);
            if (!result.IsSuccess || !result.Data.Status)
            {
                QuartzLogHelper.LogError(_logger, $"调用WMS接口失败,接口:【{configKey}】,请求参数:【{requestParam}】,错误信息:【{result.Data?.Message}】", "RelocationTaskFlowService");
                return WebResponseContent.Instance.Error($"调用WMS接口更新任务状态失败,任务号:【{task.TaskNum}】,错误信息:【{result.Data?.Message}】");
            }
            QuartzLogHelper.LogInfo(_logger, $"调用WMS接口成功,接口:【{configKey}】,响应数据:【{result.Data?.Data}】,耗时:{(DateTime.Now - startTime).TotalMilliseconds}ms", "RelocationTaskFlowService");
            return WebResponseContent.Instance.OK();
        }
@@ -117,20 +130,28 @@
        /// <returns>通知结果。</returns>
        private WebResponseContent NotifyWMSRelocationFinish(Dt_Task task)
        {
            string configKey = nameof(ConfigKey.RelocationFinishTask);
            string requestParam = new CreateTaskDto
            {
                PalletCode = task.PalletCode,
                SourceAddress = task.CurrentAddress,
                TargetAddress = task.TargetAddress,
                Roadway = task.Roadway,
                TaskType = task.TaskType
            }.ToJson();
            DateTime startTime = DateTime.Now;
            var result = _httpClientHelper.Post<WebResponseContent>(
                nameof(ConfigKey.RelocationFinishTask),
                new CreateTaskDto
                {
                    PalletCode = task.PalletCode,
                    SourceAddress = task.CurrentAddress,
                    TargetAddress = task.TargetAddress,
                    Roadway = task.Roadway,
                    TaskType = task.TaskType
                }.ToJson());
                configKey,
                requestParam);
            if (!result.IsSuccess || !result.Data.Status)
            {
                QuartzLogHelper.LogError(_logger, $"调用WMS接口失败,接口:【{configKey}】,请求参数:【{requestParam}】,错误信息:【{result.Data?.Message}】", "RelocationTaskFlowService");
                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", "RelocationTaskFlowService");
            return WebResponseContent.Instance.OK();
        }
    }