You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
5.8 KiB
C#
132 lines
5.8 KiB
C#
using DS.Module.Core;
|
|
using DS.Module.Core.Enums;
|
|
using DS.WMS.Core.Application.Entity;
|
|
using DS.WMS.Core.Flow.Dtos;
|
|
using DS.WMS.Core.Flow.Entity;
|
|
using DS.WMS.Core.TaskInteraction.Dtos;
|
|
using DS.WMS.Core.TaskInteraction.Entity;
|
|
using DS.WMS.Core.TaskInteraction.Interface;
|
|
|
|
namespace DS.WMS.Core.TaskInteraction.Method
|
|
{
|
|
/// <summary>
|
|
/// 申请类审核任务
|
|
/// </summary>
|
|
public class ApplicationTaskService : TaskService, IApplicationTaskService
|
|
{
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
/// <param name="provider"></param>
|
|
public ApplicationTaskService(IServiceProvider provider) : base(provider)
|
|
{
|
|
}
|
|
|
|
public async override Task<DataResult> AuditAsync(TaskAuditRequest request)
|
|
{
|
|
var tasksList = 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 (tasksList.Count == 0)
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskNotExists));
|
|
if (tasksList.Count != request.Ids.Length)
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskCountNotMatch));
|
|
|
|
if (tasksList.Exists(x => x.TaskStatus != TaskStatusEnum.Create && x.TaskStatus != TaskStatusEnum.Pending && x.TaskStatus != TaskStatusEnum.Complete))
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskAuditStatusError));
|
|
|
|
DataResult result = DataResult.Success;
|
|
var tasks = tasksList.FindAll(x => x.TaskStatus == TaskStatusEnum.Create);
|
|
var task2 = tasksList.FindAll(x => x.TaskStatus == TaskStatusEnum.Complete);
|
|
await TenantDb.Ado.BeginTranAsync();
|
|
try
|
|
{
|
|
//状态待审核的任务
|
|
if (tasks.Count > 0)
|
|
{
|
|
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 = request.Remark!;
|
|
}
|
|
}
|
|
|
|
//已完成审核的任务
|
|
if (task2.Count > 0)
|
|
{
|
|
foreach (var task in task2)
|
|
{
|
|
result = await SetTaskStatusAsync(new TaskUpdateRequest
|
|
{
|
|
BusinessId = task.BusinessId,
|
|
BusinessType = task.BusinessType,
|
|
TaskTypeName = task.TaskType.ToString(),
|
|
RejectReason = request.Remark,
|
|
TaskStatus = TaskStatusEnum.Pending,
|
|
TaskDesc = request.Remark,
|
|
IgnoreStatusCheck = true
|
|
}, false);
|
|
|
|
if (!result.Succeeded)
|
|
return result;
|
|
}
|
|
|
|
var ids = task2.Select(x => x.BusinessId);
|
|
switch (request.TaskType)
|
|
{
|
|
case TaskBaseTypeEnum.APPLICATION_PAYMENT_AUDIT:
|
|
await TenantDb.Updateable<PaymentApplication>().Where(x => ids.Contains(x.Id))
|
|
.SetColumns(x => x.Status == PaymentApplicationStatus.AuditRejected)
|
|
.SetColumns(x => x.Reason == request.Remark)
|
|
.ExecuteCommandAsync();
|
|
break;
|
|
|
|
case TaskBaseTypeEnum.APPLICATION_INVOICE_AUDIT:
|
|
await TenantDb.Updateable<InvoiceApplication>().Where(x => ids.Contains(x.Id))
|
|
.SetColumns(x => x.Status == InvoiceApplicationStatus.AuditRejected)
|
|
.SetColumns(x => x.Reason == request.Remark)
|
|
.ExecuteCommandAsync();
|
|
break;
|
|
|
|
default:
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.BusinessNotSupported));
|
|
}
|
|
|
|
}
|
|
|
|
await TenantDb.Ado.CommitTranAsync();
|
|
return result;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await TenantDb.Ado.RollbackTranAsync();
|
|
await ex.LogAsync(Db);
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
|
|
}
|
|
}
|
|
}
|
|
}
|