任务审核批量提交与任务

dev
嵇文龙 3 months ago
parent a690f76c47
commit 1697824c66

@ -1504,6 +1504,8 @@ public static class MultiLanguageConst
public const string TaskReceiverNotFound = "Task_Receiver_Not_Found";
[Description("未找到此票订单的订舱任务")]
public const string BookingTaskNotFound = "Booking_Task_NotFound";
[Description("此操作不支持多种业务类型同时提交")]
public const string MultiBusinessType = "Multi_Business_Type";
[Description("任务邮件必须设置收件人")]
public const string TaskMailReceiverNotNull = "Task_Mail_Receiver_Not_Null";

@ -107,24 +107,13 @@ public class ClientInfoService : ServiceBase, IClientInfoService
/// <returns></returns>
public async Task<DataResult> AuditAsync(AuditRequest request)
{
var list = await flowService.Value.GetInstanceByBSIdAsync(TaskBaseTypeEnum.INFO_CLIENT_AUDIT, ids: request.Ids);
if (list.Count != request.Ids.Length)
return DataResult.FailedWithDesc(MultiLanguageConst.NotInAudit);
foreach (var item in list)
return await taskService.Value.AuditAsync(new TaskAuditRequest
{
var result = flowService.Value.AuditFlowInstance(new FlowAuditInfo
{
AuditNote = request.Remark,
Status = request.Result,
Instance = item
});
if (!result.Succeeded)
return result;
}
return DataResult.Success;
Ids = request.Ids,
Remark = request.Remark,
Result = request.Result,
TaskTypeName = INFO_CLIENT_TASK.ToString()
});
}
/// <summary>
@ -134,7 +123,7 @@ public class ClientInfoService : ServiceBase, IClientInfoService
/// <returns></returns>
public async Task<DataResult> AuditCallbackAsync(FlowCallback callback)
{
if (callback.AuditType != TaskBaseTypeEnum.INFO_CLIENT_AUDIT)
if (callback.AuditType != INFO_CLIENT_TASK)
return DataResult.FailedWithDesc(MultiLanguageConst.NoAuditItems);
InfoClient infoClient = new()
@ -163,17 +152,33 @@ public class ClientInfoService : ServiceBase, IClientInfoService
/// <returns></returns>
public async Task<DataResult> WithdrawAsync(IdModel idModel)
{
var list = await flowService.Value.GetInstanceByBSIdAsync(TaskBaseTypeEnum.INFO_CLIENT_AUDIT, ids: idModel.Ids);
if (list.Count != idModel.Ids.Length)
return DataResult.FailedWithDesc(MultiLanguageConst.NotInAudit);
var result = await flowService.Value.WithdrawAsync(idModel.Ids);
if (!result.Succeeded)
return result;
DataResult result;
await TenantDb.Ado.BeginTranAsync();
try
{
for (int i = 0; i < idModel.Ids.Length; i++)
{
result = await taskService.Value.WithdrawAsync(new TaskRequest
{
BusinessId = idModel.Ids[i],
TaskTypeName = INFO_CLIENT_TASK.ToString()
}, false);
if (!result.Succeeded)
{
return result;
}
}
int rows = await TenantDb.Updateable<InfoClient>().Where(x => idModel.Ids.Contains(x.Id))
await TenantDb.Updateable<InfoClient>().Where(x => idModel.Ids.Contains(x.Id))
.SetColumns(x => x.AuditStatus == AuditStatusEnum.NoAudit).ExecuteCommandAsync();
return rows > 0 ? DataResult.Success : DataResult.FailedWithDesc(MultiLanguageConst.Operation_Failed);
await TenantDb.Ado.CommitTranAsync();
return DataResult.Success;
}
catch
{
await TenantDb.Ado.RollbackTranAsync();
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
}
/// <summary>

@ -48,15 +48,17 @@ namespace DS.WMS.Core.Op.Interface.TaskInteraction
/// 发起任务审核
/// </summary>
/// <param name="request"></param>
/// <param name="useTransaction">是否使用事务</param>
/// <returns></returns>
Task<DataResult> SubmitAuditAsync(TaskRequest request);
Task<DataResult> SubmitAuditAsync(TaskRequest request, bool useTransaction = true);
/// <summary>
/// 撤销审核任务
/// </summary>
/// <param name="request"></param>
/// <param name="useTransaction">是否使用事务</param>
/// <returns></returns>
Task<DataResult> WithdrawAsync(TaskRequest request);
Task<DataResult> WithdrawAsync(TaskRequest request, bool useTransaction = true);
/// <summary>
/// 任务审核

@ -489,8 +489,9 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
/// 发起任务审核
/// </summary>
/// <param name="request"></param>
/// <param name="useTransaction">是否使用事务</param>
/// <returns></returns>
public async Task<DataResult> SubmitAuditAsync(TaskRequest request)
public async Task<DataResult> SubmitAuditAsync(TaskRequest request, bool useTransaction = true)
{
var task = await GetQuery(request.BusinessId, request.BusinessType, request.TaskType).FirstAsync();
if (task == null)
@ -510,7 +511,9 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
return result;
}
await TenantDb.Ado.BeginTranAsync();
if (useTransaction)
await TenantDb.Ado.BeginTranAsync();
try
{
var req = new TaskUpdateRequest
@ -537,12 +540,17 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
//记录日志
await LogService.WriteLogAsync(req, "重新审批");
await TenantDb.Ado.CommitTranAsync();
if (useTransaction)
await TenantDb.Ado.CommitTranAsync();
return result2;
}
catch (Exception ex)
{
await TenantDb.Ado.RollbackTranAsync();
if (useTransaction)
await TenantDb.Ado.RollbackTranAsync();
await ex.LogAsync(Db);
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
@ -555,8 +563,9 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
/// 撤销审核任务
/// </summary>
/// <param name="request"></param>
/// <param name="useTransaction">是否使用事务</param>
/// <returns></returns>
public async Task<DataResult> WithdrawAsync(TaskRequest request)
public async Task<DataResult> WithdrawAsync(TaskRequest request, bool useTransaction = true)
{
var task = await GetQuery(request.BusinessId, request.BusinessType, request.TaskType).Select(x => new
{
@ -574,7 +583,10 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.NotInFlows));
DateTime dt = DateTime.Now;
await TenantDb.Ado.BeginTranAsync();
if (useTransaction)
await TenantDb.Ado.BeginTranAsync();
try
{
var result = await ManagerService.SetTaskStatusWithBsno(request.BusinessId, request.TaskType, TaskStatusEnum.Cancel, dt);
@ -599,12 +611,16 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
TaskType = request.TaskType
});
await TenantDb.Ado.CommitTranAsync();
if (useTransaction)
await TenantDb.Ado.CommitTranAsync();
return DataResult.Success;
}
catch (Exception ex)
{
await TenantDb.Ado.RollbackTranAsync();
if (useTransaction)
await TenantDb.Ado.RollbackTranAsync();
await ex.LogAsync(Db);
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
@ -614,56 +630,54 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
/// 任务审核
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<DataResult> AuditAsync(TaskAuditRequest request)
{
long id = request.Ids[0];
var task = await GetQuery(id, request.BusinessType.GetValueOrDefault(), request.TaskType).FirstAsync();
if (task == null)
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.EmptyData));
if (task.TaskStatus == TaskStatusEnum.Complete)
if (tasks.Exists(x => x.TaskStatus == TaskStatusEnum.Complete))
{
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskCompleted));
}
else if (task.TaskStatus != TaskStatusEnum.Create && task.TaskStatus != TaskStatusEnum.Pending)
else if (tasks.Exists(x => x.TaskStatus != TaskStatusEnum.Create && x.TaskStatus != TaskStatusEnum.Pending))
{
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskAuditStatusError));
}
if (task.FlowId == null)
if (tasks.Exists(x => x.FlowId == null))
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.FlowNotFound));
DataResult result;
var flowInstance = await Db.Queryable<FlowInstance>().FirstAsync(x => x.Id == task.FlowId.Value);
//如果当前审批为终审,则调用规则库进行校验
if (task.TaskType == TaskBaseTypeEnum.WAIT_ORDER_AUDIT && flowInstance.GetMarkerList().Length == 1)
DataResult result = DataResult.Success;
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 CheckRulesAsync(id, request.BusinessType.GetValueOrDefault(), RuleEngineType.COMMON_OCEAN_BOOKING);
if (!result.Succeeded)
return result;
}
//如果当前审批为终审,则调用规则库进行校验
if (request.TaskType == TaskBaseTypeEnum.WAIT_ORDER_AUDIT && instance.GetMarkerList().Length == 1)
{
result = await CheckRulesAsync(instance.BusinessId, request.BusinessType.GetValueOrDefault(), RuleEngineType.COMMON_OCEAN_BOOKING);
if (!result.Succeeded)
return result;
}
result = FlowService.Value.AuditFlowInstance(new FlowAuditInfo
{
AuditNote = request.Remark,
Status = request.Result,
Instance = flowInstance
});
result = FlowService.Value.AuditFlowInstance(new FlowAuditInfo
{
AuditNote = request.Remark,
Status = request.Result,
Instance = instance
});
var flow = await Db.Queryable<FlowInstance>().Where(x => x.Id == task.FlowId.Value).Select(x => new FlowInstance
{
FlowStatus = x.FlowStatus,
MakerList = x.MakerList,
}).FirstAsync();
////终审通过且任务类型为审单,则生成费用
//if (request.TaskType == TaskBaseTypeEnum.WAIT_ORDER_AUDIT && flow.FlowStatus == FlowStatusEnum.Approve && flow.IsCompleted)
//{
// FeeTemplateService.Value.GenerateFeesAsync(request.Ids[0], request.BusinessType.GetValueOrDefault());
//}
////终审通过且任务类型为审单,则生成费用
//if (request.TaskType == TaskBaseTypeEnum.WAIT_ORDER_AUDIT && flow.FlowStatus == FlowStatusEnum.Approve && flow.IsCompleted)
//{
// FeeTemplateService.Value.GenerateFeesAsync(request.Ids[0], request.BusinessType.GetValueOrDefault());
//}
result.Data = new { instance.IsCompleted, instance.FlowStatus };
}
result.Data = new { flow.IsCompleted, flow.FlowStatus };
return result;
}
@ -864,11 +878,6 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
return result.Succeeded ? result.Data : [];
}
/// <summary>
/// 填充用户信息
/// </summary>
/// <param name="ids">用户ID</param>
/// <returns></returns>
internal async Task<List<RecvUserInfo>> FillInUserInfoAsync(params long[] ids)
{
return await Db.Queryable<SysUser>().Where(x => ids.Contains(x.Id)).Select(

Loading…
Cancel
Save