huangxiaoqiang
3 天以前 4b43452bbdcae2dadc4543d0a4c836c2b89440fd
增强日志记录和简化代码实现

在 `TaskService.cs` 中添加了日志记录功能,记录包装出库的请求和返回参数,并在异常处理时增加了错误日志。
在 `LocationStatusChangeRecordRepository.cs` 中简化了 `AddLocationStatusChangeRecord` 方法,去掉了多余的变量声明。
在 `Dt_TaskService.cs` 中添加了请求和返回参数的日志记录,修改了获取任务号的方式为同步调用,并增强了异常处理的日志记录。
在 `TaskController.cs` 中调整了节流过滤器的参数,从 5 秒更改为 11 秒。
已修改4个文件
37 ■■■■ 文件已修改
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Partial/TaskService.cs 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicRepository/Location/LocationStatusChangeRecordRepository.cs 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/TaskController.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Partial/TaskService.cs
@@ -399,23 +399,28 @@
                var wmsIpAddrss = wmsBase + requestTask;
                var result = await HttpHelper.PostAsync(wmsIpAddrss, new { Position = stationManager.stationChildCode }.ToJsonString());
                QuartzLogger.WriteLogToFile($"包装出库", $"返回参数【{JsonConvert.SerializeObject(result)}】{Environment.NewLine}{Environment.NewLine}");
                content = JsonConvert.DeserializeObject<WebResponseContent>(result);
                if (!content.Status)
                {
                    //无满足条件可出库至包装的库存
                    ConsoleHelper.WriteErrorLine(JsonConvert.SerializeObject(content));
                    QuartzLogger.WriteLogToFile($"包装出库", $"返回参数【{JsonConvert.SerializeObject(content)}】{Environment.NewLine}{Environment.NewLine}");
                    return content;
                }
                var task = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
                ConsoleHelper.WriteSuccessLine(content.Data.ToString());
                QuartzLogger.WriteLogToFile($"包装出库", $"返回参数【{JsonConvert.SerializeObject(task)}】{Environment.NewLine}{Environment.NewLine}");
                //_taskService.ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO })‘
                content = ReceiveWMSTask(new List<WMSTaskDTO> { task });
                //content = ReceiveByBZOtuTask(task);
                //if (content.Status)
                //{
                //    //相应的在途数据+1
                //   // _taskNeedBarcodeRepository.UpdateData();
                //}
                QuartzLogger.WriteLogToFile($"包装出库", $"返回参数【{JsonConvert.SerializeObject(content)}】{Environment.NewLine}{Environment.NewLine}");
                ConsoleHelper.WriteErrorLine(JsonConvert.SerializeObject(content));
                return content;
            }
            catch (Exception ex)
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicRepository/Location/LocationStatusChangeRecordRepository.cs
@@ -39,8 +39,6 @@
        /// <exception cref="Exception"></exception>
        public void AddLocationStatusChangeRecord(DtLocationInfo locationInfo, int lastStatus, int changeType, int? taskNum)
        {
            try
            {
                DtLocationStatusChangeRecord locationStatusChangeRecord = new DtLocationStatusChangeRecord()
                {
                    AfterStatus = locationInfo.LocationStatus,
@@ -52,13 +50,8 @@
                    Creater = "System",
                    CreateDate = DateTime.Now,
                };
                base.AddData(locationStatusChangeRecord);
            }
            catch (Exception ex)
            {
                throw new Exception($"{ex.Message}");
            }
        }
        public void AddLocationStatusChangeRecord(List<DtLocationInfo> locationInfos, int newStatus, int changeType, List<int>? taskNums)
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs
@@ -1,5 +1,6 @@
using Mapster;
using Masuit.Tools;
using SixLabors.Fonts.Tables.AdvancedTypographic;
using SqlSugar;
using WIDESEA_Common.CustomModels;
using WIDESEA_Core.Const;
@@ -1076,6 +1077,7 @@
        WebResponseContent content = new WebResponseContent();
        try
        {
            LogFactory.GetLog($"包装请求出库任务").Info(true, $"【请求参数】:【{JsonConvert.SerializeObject(json)}】{Environment.NewLine}{Environment.NewLine}");
            Dt_StationManager station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == json.Position && x.stationType == 12 && x.stationArea == "Call");
            if (station == null) { throw new Exception($"未找到包装站台信息,请检查传入参数{json.Position}"); }
@@ -1148,12 +1150,11 @@
                SourceAddress = stockInfo.LocationCode,
                TaskState = (int)TaskOutStatusEnum.OutNew,
                TaskType = (int)TaskOutboundTypeEnum.Outbound,
                TaskNum = await BaseDal.GetTaskNo(),
                TaskNum = BaseDal.GetTaskNo().Result,
                Creater = "System",
                ProductionLine = stockInfo.ProductionLine,
                ProcessCode = stockInfo.ProcessCode,
            };
            WMSTaskDTO taskDTO = CreateTaskDTO(task);
            int lastStatus = locationInfo.LocationStatus;
@@ -1166,11 +1167,15 @@
            _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(stockInfo.LocationInfo, lastStatus, (int)StatusChangeTypeEnum.AutomaticDelivery, task.TaskNum);
            LogFactory.GetLog($"包装请求出库任务").Info(true, $"【返回参数】:【{JsonConvert.SerializeObject(taskDTO)}】{Environment.NewLine}{Environment.NewLine}");
            return content.OK(data: taskDTO);
        }
        catch (Exception ex)
        {
            Console.WriteLine($"CW3至包装出库异常:{ex.ToString()}");
            LogFactory.GetLog($"包装请求出库任务").Info(true, $"【异常】:【{ex.Message}】{Environment.NewLine}【{ex.StackTrace}】{Environment.NewLine}{Environment.NewLine}");
            return content.Error($"失败:{ex.Message}");
        }
    }
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/TaskController.cs
@@ -185,7 +185,7 @@
    /// <param name="input">请求数据</param>
    /// <returns></returns>
    [HttpPost, AllowAnonymous, Route("RequestOutTaskToBZAsync")]
    [TypeFilter(typeof(ThrottleFilter), Arguments = new object[] { 5 })] // 5秒节流
    [TypeFilter(typeof(ThrottleFilter), Arguments = new object[] { 11 })] // 5秒节流
    public async Task<WebResponseContent> RequestOutTaskToBZAsync([FromBody] RequestTaskDto input)
    {
        return await Service.RequestOutTaskToBZAsync(input);