using DS.Module.Core; using DS.WMS.Core.Fee.Entity; using DS.WMS.Core.Flow.Dtos; using DS.WMS.Core.Op.Entity; using DS.WMS.Core.TaskInteraction.Dtos; using DS.WMS.Core.TaskInteraction.Interface; namespace DS.WMS.Core.TaskInteraction.Method { /// /// 费用整票审核任务 /// public class FeeBillTaskService : TaskService, IFeeBillTaskService { /// /// 初始化 /// /// public FeeBillTaskService(IServiceProvider provider) : base(provider) { } /// /// 批量创建 /// /// /// /// public override Task CreateMultipleTaskAsync(TaskCreationRequest request, bool useTransaction = true) { return Task.FromResult(DataResult.Failed("不支持批量提交整票审核任务")); } /// /// 回调更新 /// /// /// public override async Task UpdateBusinessAsync(FlowCallback callback) { var auditType = callback.AuditType; if (auditType != TaskBaseTypeEnum.BILL_RECV_AUDIT && auditType != TaskBaseTypeEnum.BILL_PAY_AUDIT) return; var biz = await TenantDb.Queryable().Where(x => x.BusinessId == callback.BusinessId && x.BusinessType == callback.BusinessType) .Select(x => new BusinessFeeStatus { Id = x.Id, BusinessId = x.BusinessId, BusinessType = x.BusinessType, BillAuditStatus = x.BillAuditStatus, BillFeeStatusTime = x.BillFeeStatusTime, ARFeeStatus = x.ARFeeStatus, APFeeStatus = x.APFeeStatus }).FirstAsync(); if (biz == null) return; long userId = long.Parse(User.UserId); DateTime dtNow = DateTime.Now; await TenantDb.Ado.BeginTranAsync(); try { if (auditType == TaskBaseTypeEnum.BILL_RECV_AUDIT) { FeeStatus status = FeeStatus.RejectSubmission; if (callback.FlowStatus == FlowStatusEnum.Approve) { biz.BillAuditStatus = BillAuditStatus.RecvPassed; biz.ARFeeStatus = BillFeeStatus.AuditPassed; status = FeeStatus.AuditPassed; } else if (callback.FlowStatus == FlowStatusEnum.Reject) { biz.BillAuditStatus = BillAuditStatus.RecvRejected; biz.ARFeeStatus = BillFeeStatus.RejectSubmission; } biz.BillFeeStatusTime = dtNow; await TenantDb.Updateable(biz).UpdateColumns(x => new { x.BillAuditStatus, x.BillFeeStatusTime, x.ARFeeStatus }).ExecuteCommandAsync(); await TenantDb.Updateable() .SetColumns(x => x.FeeStatus == status) .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.FeeType == FeeType.Receivable && x.FeeStatus == FeeStatus.AuditSubmitted) .ExecuteCommandAsync(); } else if (auditType == TaskBaseTypeEnum.BILL_PAY_AUDIT) { FeeStatus status = FeeStatus.RejectSubmission; if (callback.FlowStatus == FlowStatusEnum.Approve) { biz.BillAuditStatus = BillAuditStatus.PayPassed; biz.APFeeStatus = BillFeeStatus.AuditPassed; status = FeeStatus.AuditPassed; } else if (callback.FlowStatus == FlowStatusEnum.Reject) { biz.BillAuditStatus = BillAuditStatus.PayRejected; biz.APFeeStatus = BillFeeStatus.RejectSubmission; } biz.BillFeeStatusTime = dtNow; await TenantDb.Updateable(biz).UpdateColumns(x => new { x.BillAuditStatus, x.BillFeeStatusTime, x.APFeeStatus }).ExecuteCommandAsync(); await TenantDb.Updateable() .SetColumns(x => x.FeeStatus == status) .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.FeeType == FeeType.Payable && x.FeeStatus == FeeStatus.AuditSubmitted) .ExecuteCommandAsync(); } await base.UpdateBusinessAsync(callback); await TenantDb.Ado.CommitTranAsync(); } catch (Exception ex) { await TenantDb.Ado.RollbackTranAsync(); await ex.LogAsync(Db); throw; } } } }