From f01369ce6b301c40fc85411d52ac6d66ef0b2d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B5=87=E6=96=87=E9=BE=99?= Date: Fri, 15 Nov 2024 11:29:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E7=94=A8=E8=A7=84=E5=88=99=E5=BA=93?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E9=94=99=E8=AF=AF=E6=97=B6=E5=86=99=E5=85=A5?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Fee/Method/FeeRecordService.cs | 35 ++++++++++++++----- .../TaskInteraction/Entity/BusinessTaskLog.cs | 6 ++++ .../Method/FeeBillTaskService.cs | 2 ++ .../TaskInteraction/Method/TaskService.cs | 22 +++++++++--- 4 files changed, 51 insertions(+), 14 deletions(-) diff --git a/ds-wms-service/DS.WMS.Core/Fee/Method/FeeRecordService.cs b/ds-wms-service/DS.WMS.Core/Fee/Method/FeeRecordService.cs index ac4f0f2c..2a6c190b 100644 --- a/ds-wms-service/DS.WMS.Core/Fee/Method/FeeRecordService.cs +++ b/ds-wms-service/DS.WMS.Core/Fee/Method/FeeRecordService.cs @@ -453,18 +453,28 @@ namespace DS.WMS.Core.Fee.Method /// public async Task DeleteAsync(params long[] ids) { - var model = await TenantDb.Queryable().Where(x => ids.Contains(x.Id)).Select(x => new { x.BusinessId, x.BusinessType }).FirstAsync(); - if (await IsFeeLockedAsync(model.BusinessId, model.BusinessType)) - return DataResult.FailedWithDesc(nameof(MultiLanguageConst.FeeLocked)); - - if (await TenantDb.Queryable().AnyAsync(x => ids.Contains(x.Id) && (x.FeeStatus != FeeStatus.Entering && x.FeeStatus != FeeStatus.RejectSubmission))) - return DataResult.FailedWithDesc(nameof(MultiLanguageConst.FeeRecordDelete)); + await TenantDb.Ado.BeginTranAsync(); + try + { + var model = await TenantDb.Queryable().Where(x => ids.Contains(x.Id)).Select(x => new { x.BusinessId, x.BusinessType }).FirstAsync(); + if (await IsFeeLockedAsync(model.BusinessId, model.BusinessType)) + return DataResult.FailedWithDesc(nameof(MultiLanguageConst.FeeLocked)); - int result = await TenantDb.Deleteable(x => ids.Contains(x.Id)).ExecuteCommandAsync(); + if (await TenantDb.Queryable().AnyAsync(x => ids.Contains(x.Id) && x.FeeStatus != FeeStatus.Entering && x.FeeStatus != FeeStatus.RejectSubmission)) + return DataResult.FailedWithDesc(nameof(MultiLanguageConst.FeeRecordDelete)); - await WriteBackStatusAsync(model.BusinessId, model.BusinessType); + await TenantDb.Deleteable(x => ids.Contains(x.Id)).ExecuteCommandAsync(); + await WriteBackStatusAsync(model.BusinessId, model.BusinessType); - return result > 0 ? DataResult.Success : DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed)); + await TenantDb.Ado.CommitTranAsync(); + return DataResult.Success; + } + catch (Exception ex) + { + await TenantDb.Ado.RollbackTranAsync(); + await ex.LogAsync(Db); + return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed)); + } } #region 审核相关 @@ -534,6 +544,8 @@ namespace DS.WMS.Core.Fee.Method x.SubmitBy, x.SubmitDate }).ExecuteCommandAsync(); + await WriteBackStatusAsync(bid, bType); + await TenantDb.Ado.CommitTranAsync(); return DataResult.Success; } @@ -869,6 +881,7 @@ namespace DS.WMS.Core.Fee.Method } await TenantDb.Updateable(fees).UpdateColumns(x => new { x.FeeStatus, x.SubmitBy, x.SubmitDate }).ExecuteCommandAsync(); + await WriteBackStatusAsync(fees[0].BusinessId, fees[0].BusinessType); await TenantDb.Ado.CommitTranAsync(); return DataResult.Success; } @@ -1002,6 +1015,8 @@ namespace DS.WMS.Core.Fee.Method (x.FeeStatus == FeeStatus.Entering || x.FeeStatus == FeeStatus.Withdraw || x.FeeStatus == FeeStatus.RejectSubmission)) .SetColumns(x => x.FeeStatus == FeeStatus.AuditSubmitted).ExecuteCommandAsync(); + await WriteBackStatusAsync(bid, type); + if (useTransaction) await TenantDb.Ado.CommitTranAsync(); return DataResult.Success; @@ -1092,6 +1107,8 @@ namespace DS.WMS.Core.Fee.Method await TenantDb.Updateable().Where(x => x.BusinessId == bid && x.BusinessType == type && x.FeeStatus == FeeStatus.AuditSubmitted) .SetColumns(x => x.FeeStatus == FeeStatus.Entering).ExecuteCommandAsync(); + await WriteBackStatusAsync(bid, type); + await TenantDb.Ado.CommitTranAsync(); return result; } diff --git a/ds-wms-service/DS.WMS.Core/TaskInteraction/Entity/BusinessTaskLog.cs b/ds-wms-service/DS.WMS.Core/TaskInteraction/Entity/BusinessTaskLog.cs index a757420e..e0d82630 100644 --- a/ds-wms-service/DS.WMS.Core/TaskInteraction/Entity/BusinessTaskLog.cs +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Entity/BusinessTaskLog.cs @@ -114,6 +114,12 @@ namespace DS.WMS.Core.TaskInteraction.Entity [Description("删除")] Delete = 10, + /// + /// 规则验证 + /// + [Description("规则验证")] + Validation = 11, + /// /// 审核 /// diff --git a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/FeeBillTaskService.cs b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/FeeBillTaskService.cs index 99604de3..d61a8954 100644 --- a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/FeeBillTaskService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/FeeBillTaskService.cs @@ -159,6 +159,8 @@ namespace DS.WMS.Core.TaskInteraction.Method await SetLockAsync(biz); } + + await TenantDb.Ado.CommitTranAsync(); } catch (Exception ex) diff --git a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/TaskService.cs b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/TaskService.cs index 9a418b79..4584104e 100644 --- a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/TaskService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/TaskService.cs @@ -25,6 +25,7 @@ using Mapster; using Masuit.Tools; using Masuit.Tools.Systems; using Microsoft.Extensions.DependencyInjection; +using Newtonsoft.Json; using SqlSugar; namespace DS.WMS.Core.TaskInteraction.Method @@ -235,7 +236,7 @@ namespace DS.WMS.Core.TaskInteraction.Method if (request.TaskType == TaskBaseTypeEnum.WAIT_ORDER_AUDIT) { - result = await CheckRulesAsync(request.BusinessId, request.BusinessType.Value, RuleEngineType.COMMON_ORDER_AUDIT); + result = await CheckRulesAsync(request.TaskType, request.BusinessId, request.BusinessType.Value, RuleEngineType.COMMON_ORDER_AUDIT); if (!result.Succeeded) return result; } @@ -754,7 +755,7 @@ namespace DS.WMS.Core.TaskInteraction.Method if (task.TaskType == TaskBaseTypeEnum.WAIT_ORDER_AUDIT) { - result = await CheckRulesAsync(request.BusinessId, request.BusinessType.Value, RuleEngineType.COMMON_ORDER_AUDIT); + result = await CheckRulesAsync(request.TaskType, request.BusinessId, request.BusinessType.Value, RuleEngineType.COMMON_ORDER_AUDIT); if (!result.Succeeded) return result; } @@ -970,7 +971,7 @@ namespace DS.WMS.Core.TaskInteraction.Method //如果当前审批为终审,则调用规则库进行校验 if (request.Result == 1 && request.TaskType == TaskBaseTypeEnum.WAIT_ORDER_AUDIT && instance.GetMarkerList().Length == 1) { - result = await CheckRulesAsync(instance.BusinessId, request.BusinessType.GetValueOrDefault(), RuleEngineType.COMMON_OCEAN_BOOKING); + result = await CheckRulesAsync(request.TaskType, instance.BusinessId, request.BusinessType.GetValueOrDefault(), RuleEngineType.COMMON_OCEAN_BOOKING); if (!result.Succeeded) return result; } @@ -1229,7 +1230,8 @@ namespace DS.WMS.Core.TaskInteraction.Method return info; } - async Task CheckRulesAsync(long bsId, BusinessType businessType, RuleEngineType ruleType) + //调用规则库 + async Task CheckRulesAsync(TaskBaseTypeEnum taskType, long bsId, BusinessType businessType, RuleEngineType ruleType) { var rulesReq = new RuleEngineReq(); var order = await TenantDb.Queryable().Where(x => x.Id == bsId).FirstAsync(); @@ -1239,7 +1241,17 @@ namespace DS.WMS.Core.TaskInteraction.Method var ruleResult = await RuleEngineService.Value.ExecuteSeaExportAuditRulesAsync(rulesReq); if (string.Equals(ruleResult.Succ, bool.FalseString, StringComparison.OrdinalIgnoreCase)) { - return DataResult.Failed(ruleResult.Msg); + string msg = "校验规则API返回了错误:" + ruleResult.Msg; + var taskLog = new BusinessTaskLog + { + BusinessId = bsId, + BusinessType = businessType, + ActionType = ActionType.Validation, + TaskType = taskType, + Remark = msg + ";请求参数:" + JsonConvert.SerializeObject(rulesReq) + }; + await LogService.WriteLogAsync(taskLog); + return DataResult.Failed(msg); } else if (ruleResult.Extra.DetailList?.Count > 0) {