|
|
|
@ -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
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class FeeBillTaskService : TaskService, IFeeBillTaskService
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 当前用户ID
|
|
|
|
|
/// </summary>
|
|
|
|
|
public readonly long UserId;
|
|
|
|
|
|
|
|
|
|
readonly ILogger<FeeBillTaskService> logger;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化
|
|
|
|
@ -25,6 +31,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
public FeeBillTaskService(IServiceProvider provider) : base(provider)
|
|
|
|
|
{
|
|
|
|
|
logger = provider.GetRequiredService<ILogger<FeeBillTaskService>>();
|
|
|
|
|
UserId = long.Parse(User.UserId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -39,7 +46,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 回调更新
|
|
|
|
|
/// 整票审核回调更新
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="callback"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
@ -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<FeeRecord>()
|
|
|
|
|
.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<FeeRecord>()
|
|
|
|
|
.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<FeeRecord>()
|
|
|
|
|
.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<DataResult> BillLockAudit()
|
|
|
|
|
//{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 锁单审核
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult> BillLockAuditAsync(TaskAuditRequest request)
|
|
|
|
|
{
|
|
|
|
|
request.TaskTypeName = TaskBaseTypeEnum.BILL_LOCK_AUDIT.ToString();
|
|
|
|
|
return await AuditAsync(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置锁定
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="biz">业务费用对象</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 任务审核
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override async Task<DataResult> AuditAsync(TaskAuditRequest request)
|
|
|
|
|
{
|
|
|
|
|
var tasks = await TenantDb.Queryable<BusinessTask>().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<FlowInstance>().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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置任务状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <param name="useTransaction"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override Task<DataResult> 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] //通知任务发起人
|
|
|
|
|
};
|
|
|
|
|
//创建驳回任务以进行通知
|
|
|
|
|