From 324edb3561045df05d64c75977a6c7ebc26b9227 Mon Sep 17 00:00:00 2001 From: zhangxiaofeng <1939543722@qq.com> Date: Fri, 30 Aug 2024 14:58:50 +0800 Subject: [PATCH] =?UTF-8?q?BC=E6=B5=81=E7=A8=8B=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Constants/TaskFlowDataNameConst.cs | 7 +- .../TaskPlat/Method/TaskManageBCService.cs | 109 ++++++++++++++---- .../TaskPlat/Method/TaskManageBaseService.cs | 16 +-- .../TaskPlat/Method/TaskManageService.cs | 9 +- .../TaskPlat/Other/TaskFlowRuner.cs | 9 +- 5 files changed, 106 insertions(+), 44 deletions(-) diff --git a/ds-wms-service/DS.Module.Core/Constants/TaskFlowDataNameConst.cs b/ds-wms-service/DS.Module.Core/Constants/TaskFlowDataNameConst.cs index 4b91a49d..cb32dee3 100644 --- a/ds-wms-service/DS.Module.Core/Constants/TaskFlowDataNameConst.cs +++ b/ds-wms-service/DS.Module.Core/Constants/TaskFlowDataNameConst.cs @@ -38,9 +38,14 @@ /// /// BC对比订单后是否存在差异 /// - /// 类型: + /// 类型:CompareResultInfo public const string BcCompareWithSeaExportResult = "BcCompareWithSeaExportResult"; + /// + /// BC是否匹配到了海运出口订单 + /// + public const string BcIsMatchSeaExport = "BcIsMatchSeaExport"; + /// /// BC文件 /// diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs index 6d56ab35..60684f2d 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs @@ -1184,7 +1184,7 @@ namespace DS.WMS.Core.TaskPlat.Method SeaExport = seaExport, OpCtnList = seaExportCtnList }; - var result = await CompareBcWithSeaExport(compareDto); + CompareResultInfo result = await CompareBcWithSeaExport(compareDto); dataContext.Set(TaskFlowDataNameConst.BcCompareWithSeaExportResult, result); @@ -1345,14 +1345,23 @@ namespace DS.WMS.Core.TaskPlat.Method var taskBcInfo = dataContext.Get(TaskFlowDataNameConst.TaskBCInfo) ?? throw new ArgumentException($"缺少参数:{nameof(TaskFlowDataNameConst.TaskBCInfo)}"); var result = await BcMatchSeaExport(taskBcInfo); - if (result.Succeeded && result.Data != null) + if (result.Succeeded && result.Data != null && result.Data.Id != 0) { - dataContext.Set(TaskFlowDataNameConst.BusinessId, result.Data.Id!); + // BC是否匹配到了海运出口订单=>true + dataContext.Set(TaskFlowDataNameConst.BcIsMatchSeaExport, true); + + // 订单Id + dataContext.Set(TaskFlowDataNameConst.BusinessId, result.Data.Id); await tenantDb.Updateable() .SetColumns(x => x.BOOKING_ORDER_ID == result.Data.Id) .Where(x => x.Id == taskBcInfo.Id) .ExecuteCommandAsync(); + + await tenantDb.Updateable() + .SetColumns(x => x.OUT_BS_NO == result.Data.Id) + .Where(x => x.Id == taskBcInfo.TASK_ID) + .ExecuteCommandAsync(); } return result; } @@ -1362,6 +1371,7 @@ namespace DS.WMS.Core.TaskPlat.Method private async Task> BcMatchSeaExport(TaskBCInfo taskBcInfo) { var queryable = tenantDb.Queryable(); + if (taskBcInfo.BOOKING_ORDER_ID is not null or 0) { queryable.Where(x => x.Id == taskBcInfo.BOOKING_ORDER_ID); @@ -1402,7 +1412,7 @@ namespace DS.WMS.Core.TaskPlat.Method { // 更新订单 await tenantDb.Updateable().SetColumns(x => x.MBLNO == taskBcInfo.MBL_NO).Where(x => x.Id == seaExport.Id).ExecuteCommandAsync(); - + // 赋值 seaExport.MBLNO = taskBcInfo.MBL_NO; @@ -2592,6 +2602,10 @@ namespace DS.WMS.Core.TaskPlat.Method { return DataResult.Failed("未执行:当前任务状态为已完成,请重新查询"); } + if (waitBcTask.OUT_BS_NO == null) + { + return DataResult.Failed("未执行:当前任务的业务主键为null"); + } taskBcInfo.BOOKING_ORDER_ID = waitBcTask.OUT_BS_NO; // 获取订单信息 @@ -2738,6 +2752,7 @@ namespace DS.WMS.Core.TaskPlat.Method FILE_CATEGORY_NAME = TaskFileCategoryEnum.BC.EnumDescription() }; + // 存库 try { @@ -2757,6 +2772,20 @@ namespace DS.WMS.Core.TaskPlat.Method throw; } + var taskService = serviceProvider.GetRequiredService(); + var rlt = await taskService.SetTaskStatusAsync(new TaskUpdateRequest() + { + AutoCreateNext = false, + BusinessId = (long)waitBcTask.OUT_BS_NO, + BusinessType = BusinessType.OceanShippingExport, + TaskStatus = TaskStatusEnum.Complete, + TaskTypeName = TaskBaseTypeEnum.WAIT_BC.ToString() + }); + if (!rlt.Succeeded) + { + logger.LogError("手动上传BC:设置收BC任务完成时失败,message:" + rlt.Message); + } + // 触发BC任务,执行自动化操作 TaskManageOrderBCInfo messageBcInfo = taskBcInfo.Adapt(); messageBcInfo.CtnList = ctnList.Adapt>(); @@ -2801,32 +2830,70 @@ namespace DS.WMS.Core.TaskPlat.Method /// 数据上下文 public async Task BCTaskCompleteThenNext(TaskFlowDataContext dataContext) { - var businessId = dataContext.Get(TaskFlowDataNameConst.BusinessId); - if (businessId == null || businessId == 0) + // 这里获取到的是获取BC任务的基础任务 + var taskBaseInfo = dataContext.Get(TaskFlowDataNameConst.TaskBaseInfo); + if (taskBaseInfo == null) { - Logger.Log(NLog.LogLevel.Info, $"执行BCTaskCompleteThenNext时,未获取到businessId:{businessId}"); - return DataResult.Failed("未获取到订单Id"); + return DataResult.Failed("未获取到BC任务对象TaskBaseInfo"); + } + + await SetTaskStatus(taskBaseInfo, TaskStatusEnum.Complete, DateTime.Now); + + if (taskBaseInfo.OUT_BS_NO is null or 0) + { + logger.LogError("BCTaskCompleteThenNext:BC任务对象TaskBaseInfo的OUT_BS_NO为空或0"); + return DataResult.Failed("任务对象的业务主键为空"); } else { - var taskService = serviceProvider.GetRequiredService(); - var rlt = await taskService.SetTaskStatusAsync(new TaskUpdateRequest() + var req = new TaskCreationRequest { - AutoCreateNext = true, - BusinessId = (long)businessId, + BusinessId = (long)taskBaseInfo.OUT_BS_NO, BusinessType = BusinessType.OceanShippingExport, - TaskStatus = TaskStatusEnum.Complete, - TaskTypeName = TaskBaseTypeEnum.WAIT_BC.ToString() - }); - if (rlt.Succeeded) - { - return DataResult.Successed("BC任务已完成,并创建下一步任务"); - } - else + TaskTypeName = TaskBaseTypeEnum.WAIT_SPACE_RELEASE.ToString(), + }; + + CompareResultInfo? compareResult = dataContext.Get(TaskFlowDataNameConst.BcCompareWithSeaExportResult); + if (compareResult != null && compareResult.IsExistsDiff) { - return DataResult.Failed(rlt.Message); + req.TaskDescription = "未放舱原因:BC对比存在差异"; } + + var taskService = serviceProvider.GetRequiredService(); + var result = await taskService.CreateTaskAsync(req, false); + if (!result.Succeeded) + return DataResult.Failed("创建下一任务时返回错误:" + result.Message, result.MultiCode); } + return DataResult.Successed("BC任务已完成,并创建下一步任务"); + + /* + //之前这里结束的待收BC任务,后面改为结束BC任务 + //var businessId = dataContext.Get(TaskFlowDataNameConst.BusinessId); + //if (businessId == null || businessId == 0) + //{ + // Logger.Log(NLog.LogLevel.Info, $"执行BCTaskCompleteThenNext时,未获取到businessId:{businessId}"); + // return DataResult.Failed("未获取到订单Id"); + //} + //else + //{ + //var taskService = serviceProvider.GetRequiredService(); + //var rlt = await taskService.SetTaskStatusAsync(new TaskUpdateRequest() + // { + // AutoCreateNext = false, + // BusinessId = (long)businessId, + // BusinessType = BusinessType.OceanShippingExport, + // TaskStatus = TaskStatusEnum.Complete, + // TaskTypeName = TaskBaseTypeEnum.WAIT_BC.ToString() + // }); + // if (rlt.Succeeded) + // { + // return DataResult.Successed("BC任务已完成,并创建下一步任务"); + // } + // else + // { + // return DataResult.Failed(rlt.Message); + // } + //} */ } } } diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBaseService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBaseService.cs index e50f33f8..6c60ca37 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBaseService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBaseService.cs @@ -520,28 +520,24 @@ namespace DS.WMS.Core.TaskPlat.Method .Where(t => t.Id == taskBaseId) .FirstAsync(); - return await SetTaskStatus(taskInfo, taskBaseTypeEnum, taskStatusEnum, statusTime, bsno); + return await SetTaskStatus(taskInfo, taskStatusEnum, statusTime, bsno); } /// /// 通过任务主表对象设置任务状态() /// /// 任务主表对象 - /// 业务类型 /// 业务状态 /// 状态发生时间 /// 业务主键 - protected async Task SetTaskStatus(TaskBaseInfo taskInfo, TaskBaseTypeEnum taskBaseTypeEnum, TaskStatusEnum taskStatusEnum, DateTime? statusTime, long? bsno = null) + public async Task SetTaskStatus(TaskBaseInfo taskInfo, TaskStatusEnum taskStatusEnum, DateTime? statusTime, long? bsno = null) { - SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); - - if (taskInfo == null) + if (taskInfo is null) { - logger.LogInformation($"根据bsno:【{bsno}】,TaskBaseTypeEnum:【{taskBaseTypeEnum}】未查询到任务"); - return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData))); + throw new ArgumentNullException(nameof(taskInfo)); } - logger.LogInformation("接收到任务状态修改报文 任务主键={id} 状态设置={status}", taskInfo.Id, taskStatusEnum.ToString()); + SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); // 修改任务的状态 taskInfo.STATUS = taskStatusEnum.ToString(); @@ -553,7 +549,7 @@ namespace DS.WMS.Core.TaskPlat.Method // 如果任务状态为已完成,则查询任务完成时任务对应模块的配置中要设置的业务状态,然后进行设置 if (taskStatusEnum == TaskStatusEnum.Complete && bsno != null) { - string? statusCode = await tenantDb.Queryable().Where(x => x.ModuleType == 2 && x.TaskType == taskBaseTypeEnum.ToString()).Select(x => x.BusinessStatusCode).FirstAsync(); + string? statusCode = await tenantDb.Queryable().Where(x => x.ModuleType == 2 && x.TaskType == taskInfo.TASK_TYPE).Select(x => x.BusinessStatusCode).FirstAsync(); if (!string.IsNullOrEmpty(statusCode)) { await seaExportCommonService.Value.SetGoodsStatus(statusCode, (long)bsno, tenantDb); diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs index ee7ff2bd..f4b14458 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs @@ -136,7 +136,7 @@ namespace DS.WMS.Core.TaskPlat.Method return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData))); } - return await SetTaskStatus(taskInfo, taskBaseTypeEnum, taskStatusEnum, statusTime, bsno); + return await SetTaskStatus(taskInfo, taskStatusEnum, statusTime, bsno); } @@ -2112,13 +2112,6 @@ namespace DS.WMS.Core.TaskPlat.Method TASK_USER_STATUS_TIME = a.StatusTime }).Distinct().ToQueryPageAsync(querySearch.PageCondition); - //var sql = queryable.Select((t, a) => new - //{ - // PK_ID = t.Id.SelectAll(), - // TASK_USER_STATUS = a.Status, - // TASK_USER_STATUS_NAME = a.StatusName, - // TASK_USER_STATUS_TIME = a.StatusTime - //}).Distinct().ToSqlString(); return result; } diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs index 3f169dce..5cdc68e7 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs @@ -109,7 +109,7 @@ namespace DS.WMS.Core.TaskPlat } if (targetConfig == null) { - throw new Exception("targetConfig目标流程意外为null"); + throw new Exception("targetConfig目标流程意外为null"); // 不会走到这里,至少会有一条流程匹配到 } // 待执行的流程(节点列表) @@ -192,10 +192,11 @@ namespace DS.WMS.Core.TaskPlat if (executeConfig == null) { - flowLog.IsComplete = false; - flowLog.IsSuccess = false; - flowLog.Note += $"【执行时未找到符合执行条件的节点,经判断条件的节点Id如下:{string.Join(',', waitMatchConfigList.Select(x => x.Id))}】"; + //调整:没有找到待执行的节点,不认为整个流程失败或者未完成 + //flowLog.IsComplete = false; + //flowLog.IsSuccess = false; + flowLog.Note += $"【执行时未找到符合执行条件的节点,经判断条件的节点Id如下:{string.Join(',', waitMatchConfigList.Select(x => x.Id))}】"; break; }