From 645aef6b681b1a764ef11ef06f371da9794bfb01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B5=87=E6=96=87=E9=BE=99?= Date: Tue, 5 Nov 2024 10:53:14 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=81=E5=8D=95=E5=AE=A1=E6=A0=B8=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Fee/Method/FeeRecordService.cs | 2 +- .../Method/FeeBillTaskService.cs | 190 +++++++++++++++--- .../TaskInteraction/Method/TaskService.cs | 5 +- 3 files changed, 162 insertions(+), 35 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 615154cc..298af6f7 100644 --- a/ds-wms-service/DS.WMS.Core/Fee/Method/FeeRecordService.cs +++ b/ds-wms-service/DS.WMS.Core/Fee/Method/FeeRecordService.cs @@ -289,7 +289,7 @@ namespace DS.WMS.Core.Fee.Method StringBuilder sb = new StringBuilder(); foreach (var fe in fees) { - if (fe.FeeStatus != FeeStatus.Entering && fe.FeeStatus != FeeStatus.RejectSubmission) + if (fe.FeeStatus != FeeStatus.Entering && fe.FeeStatus != FeeStatus.RejectSubmission && fe.FeeStatus != FeeStatus.AuditSubmitted) { sb.AppendFormat(MultiLanguageConst.GetDescription(MultiLanguageConst.FeeRecordStatus), fe.FeeName); continue; 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 e0f67f0c..7e807f3e 100644 --- a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/FeeBillTaskService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/FeeBillTaskService.cs @@ -1,6 +1,7 @@ using DS.Module.Core; using DS.WMS.Core.Fee.Entity; using DS.WMS.Core.Flow.Dtos; +using DS.WMS.Core.Flow.Entity; using DS.WMS.Core.Op.Entity; using DS.WMS.Core.TaskInteraction.Dtos; using DS.WMS.Core.TaskInteraction.Entity; @@ -17,6 +18,11 @@ namespace DS.WMS.Core.TaskInteraction.Method /// public class FeeBillTaskService : TaskService, IFeeBillTaskService { + /// + /// 当前用户ID + /// + public readonly long UserId; + readonly ILogger logger; /// /// 初始化 @@ -25,6 +31,7 @@ namespace DS.WMS.Core.TaskInteraction.Method public FeeBillTaskService(IServiceProvider provider) : base(provider) { logger = provider.GetRequiredService>(); + UserId = long.Parse(User.UserId); } /// @@ -39,7 +46,7 @@ namespace DS.WMS.Core.TaskInteraction.Method } /// - /// 回调更新 + /// 整票审核回调更新 /// /// /// @@ -66,17 +73,18 @@ namespace DS.WMS.Core.TaskInteraction.Method return; DataResult result; - long userId = long.Parse(User.UserId); + DateTime dtNow = DateTime.Now; await TenantDb.Ado.BeginTranAsync(); try { await UpdateTaskStatus(callback, biz); - + FeeStatus feeStatus = default; if (auditType == TaskBaseTypeEnum.BILL_RECV_AUDIT) { if (callback.FlowStatus == FlowStatusEnum.Approve) { + feeStatus = FeeStatus.AuditPassed; biz.BillAuditStatus = BillAuditStatus.PaySubmitted; //生成应付确认任务 result = await CreateTaskAsync(new TaskCreationRequest @@ -91,16 +99,20 @@ namespace DS.WMS.Core.TaskInteraction.Method } else if (callback.FlowStatus == FlowStatusEnum.Reject) { + feeStatus = FeeStatus.RejectSubmission; biz.BillAuditStatus = BillAuditStatus.RecvRejected; - await TenantDb.Updateable() - .SetColumns(x => x.FeeStatus == FeeStatus.RejectSubmission) - .SetColumns(x => x.AuditBy == userId) - .SetColumns(x => x.AuditOperator == User.UserName) - .SetColumns(x => x.AuditDate == dtNow) - .Where(x => x.BusinessId == biz.BusinessId && x.BusinessType == biz.BusinessType && x.FeeStatus == FeeStatus.AuditSubmitted) - .ExecuteCommandAsync(); } + //更新应收费用状态 + await TenantDb.Updateable() + .SetColumns(x => x.FeeStatus == feeStatus) + .SetColumns(x => x.AuditBy == UserId) + .SetColumns(x => x.AuditOperator == User.UserName) + .SetColumns(x => x.AuditDate == dtNow) + .Where(x => x.BusinessId == biz.BusinessId && x.BusinessType == biz.BusinessType && x.FeeStatus == FeeStatus.AuditSubmitted) + .WhereIF(callback.FlowStatus == FlowStatusEnum.Approve, x => x.FeeType == FeeType.Receivable) + .ExecuteCommandAsync(); + biz.BillFeeStatusTime = dtNow; await TenantDb.Updateable(biz).UpdateColumns(x => new { @@ -110,18 +122,17 @@ namespace DS.WMS.Core.TaskInteraction.Method } else if (auditType == TaskBaseTypeEnum.BILL_PAY_AUDIT) { - FeeStatus status = FeeStatus.RejectSubmission; if (callback.FlowStatus == FlowStatusEnum.Approve) { biz.BillAuditStatus = BillAuditStatus.PayPassed; biz.ARFeeStatus = biz.APFeeStatus = BillFeeStatus.AuditPassed; - status = FeeStatus.AuditPassed; + feeStatus = FeeStatus.AuditPassed; } else if (callback.FlowStatus == FlowStatusEnum.Reject) { biz.BillAuditStatus = BillAuditStatus.PayRejected; biz.ARFeeStatus = biz.APFeeStatus = BillFeeStatus.RejectSubmission; - status = FeeStatus.RejectSubmission; + feeStatus = FeeStatus.RejectSubmission; } biz.BillFeeStatusTime = dtNow; @@ -134,13 +145,19 @@ namespace DS.WMS.Core.TaskInteraction.Method }).ExecuteCommandAsync(); await TenantDb.Updateable() - .SetColumns(x => x.FeeStatus == status) - .SetColumns(x => x.AuditBy == userId) + .SetColumns(x => x.FeeStatus == feeStatus) + .SetColumns(x => x.AuditBy == UserId) .SetColumns(x => x.AuditOperator == User.UserName) .SetColumns(x => x.AuditDate == dtNow) .Where(x => x.BusinessId == biz.BusinessId && x.BusinessType == biz.BusinessType && x.FeeStatus == FeeStatus.AuditSubmitted) .ExecuteCommandAsync(); } + //锁单审核 + else if (auditType == TaskBaseTypeEnum.BILL_LOCK_AUDIT && callback.FlowStatus == FlowStatusEnum.Approve) + { + biz.IsBusinessLocking = true; + await SetLockAsync(biz); + } await TenantDb.Ado.CommitTranAsync(); } @@ -151,22 +168,13 @@ namespace DS.WMS.Core.TaskInteraction.Method throw; } + if (auditType == TaskBaseTypeEnum.BILL_PAY_AUDIT && callback.FlowStatus == FlowStatusEnum.Approve) { if (biz.ProfitMargin > 0) { - biz.IsFeeLocking = true; - biz.FeeLockingTime = dtNow; - biz.FeeLockingUserId = userId; - biz.FeeLockingUserName = User.UserName; - - await TenantDb.Updateable(biz).UpdateColumns(x => new - { - x.IsFeeLocking, - x.FeeLockingTime, - x.FeeLockingUserId, - x.FeeLockingUserName - }).ExecuteCommandAsync(); + biz.IsBusinessLocking = true; + await SetLockAsync(biz); } else //如果为非正利润则生成锁单任务 { @@ -181,14 +189,134 @@ namespace DS.WMS.Core.TaskInteraction.Method logger.LogError($"生成【{TaskBaseTypeEnum.BILL_LOCK_AUDIT.GetDescription()}】任务失败:" + result.Message); } + //生成账单任务 } } - //public async Task BillLockAudit() - //{ + /// + /// 锁单审核 + /// + /// + /// + public async Task BillLockAuditAsync(TaskAuditRequest request) + { + request.TaskTypeName = TaskBaseTypeEnum.BILL_LOCK_AUDIT.ToString(); + return await AuditAsync(request); + } + + /// + /// 设置锁定 + /// + /// 业务费用对象 + /// + public async Task SetLockAsync(BusinessFeeStatus biz) + { + if (biz.IsFeeLocking.GetValueOrDefault()) + { + biz.FeeLockingTime = DateTime.Now; + biz.FeeLockingUserId = UserId; + biz.FeeLockingUserName = User.UserName; + } + else + { + biz.FeeUnLockingTime = DateTime.Now; + biz.FeeUnLockingUserId = UserId; + biz.FeeUnLockingUserName = User.UserName; + } + + await TenantDb.Updateable(biz).UpdateColumns(x => new + { + x.IsFeeLocking, + x.FeeLockingTime, + x.FeeLockingUserId, + x.FeeLockingUserName, + x.FeeUnLockingTime, + x.FeeUnLockingUserId, + x.FeeUnLockingUserName + }).ExecuteCommandAsync(); + } - //} + /// + /// 任务审核 + /// + /// + /// + public override async Task AuditAsync(TaskAuditRequest request) + { + var tasks = await TenantDb.Queryable().Where(x => x.TaskType == request.TaskType && request.Ids.Contains(x.BusinessId)) + .WhereIF(request.BusinessType.HasValue, x => x.BusinessType == request.BusinessType.Value).ToListAsync(); + if (tasks.Count == 0) + return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskNotExists)); + if (tasks.Count != request.Ids.Length) + return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskCountNotMatch)); + + if (tasks.Exists(x => x.TaskStatus == TaskStatusEnum.Complete)) + { + return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskCompleted)); + } + else if (tasks.Exists(x => x.TaskStatus != TaskStatusEnum.Create && x.TaskStatus != TaskStatusEnum.Pending)) + { + return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskAuditStatusError)); + } + + DataResult result = DataResult.Success; + await TenantDb.Ado.BeginTranAsync(); + try + { + var flowIds = tasks.Select(x => x.FlowId.Value); + var flowInstances = await Db.Queryable().Where(x => flowIds.Contains(x.Id)).ToListAsync(); + foreach (var instance in flowInstances) + { + result = await FlowService.Value.AuditAsync(new FlowAuditInfo + { + AuditNote = request.Remark, + Status = request.Result, + Instance = instance + }); + + if (!result.Succeeded) + return result; + + var req = new TaskUpdateRequest + { + BusinessId = instance.BusinessId, + BusinessType = instance.BusinessType, + RejectReason = request.Remark, + TaskTypeName = request.TaskType.ToString(), + TaskStatus = request.Result == 1 ? TaskStatusEnum.Complete : TaskStatusEnum.Pending, + AutoCreateNext = true + }; + //根据审批结果更新任务状态 + await SetTaskStatusAsync(req, false); + + if (instance.FlowStatus == FlowStatusEnum.Reject) + result.Message = MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskRejected)); + } + + await TenantDb.Ado.CommitTranAsync(); + return result; + } + catch (Exception ex) + { + await TenantDb.Ado.RollbackTranAsync(); + await ex.LogAsync(Db); + return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed)); + } + } + + /// + /// 设置任务状态 + /// + /// + /// + /// + public override Task SetTaskStatusAsync(TaskUpdateRequest request, bool useTransaction = true) + { + + + return base.SetTaskStatusAsync(request, useTransaction); + } //更新当前任务状态 private async Task UpdateTaskStatus(FlowCallback callback, BusinessFeeStatus business) @@ -212,7 +340,7 @@ namespace DS.WMS.Core.TaskInteraction.Method BusinessId = callback.BusinessId, BusinessType = callback.BusinessType, TaskTypeName = GetRejectedType(callback.AuditType.Value).ToString()!, - TaskTitle = $"【{TaskBaseTypeEnum.BILL_PAY_AUDIT.GetDescription()}】【{callback.BusinessType.GetDescription()}】{business.CustomerNo}", + TaskTitle = $"【{callback.AuditType.GetDescription()}】【{callback.BusinessType.GetDescription()}】{business.CustomerNo}", RecvUserIdList = [task.CreateBy] //通知任务发起人 }; //创建驳回任务以进行通知 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 5d6aaac7..015532db 100644 --- a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/TaskService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/TaskService.cs @@ -585,9 +585,8 @@ namespace DS.WMS.Core.TaskInteraction.Method return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskCompleted)); //获取未完成的优先级最高的步骤 - var topSteps = allSteps.Where(x => !x.IsCompleted).GroupBy(x => x.Priority).OrderBy(x => x.Key).FirstOrDefault(); + var topSteps = allSteps.GroupBy(x => x.Priority).OrderBy(x => x.Key).FirstOrDefault(); - var stepTypes = request.Steps.Select(x => x.Type); List steps = []; long userId = long.Parse(User.UserId); DateTime dtNow = DateTime.Now; @@ -619,7 +618,7 @@ namespace DS.WMS.Core.TaskInteraction.Method x.UpdateTime }).ExecuteCommandAsync(); - if (request.AutoSync && allSteps.Count > 0 && allSteps.Count == allSteps.Count(x => x.IsCompleted)) + if (request.AutoSync && allSteps.Count == allSteps.Count(x => x.IsCompleted)) { DataResult result = await SetTaskStatusAsync(new TaskUpdateRequest {