|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using DS.Module.Core.Data;
|
|
|
|
|
using DS.Module.Core.Helpers;
|
|
|
|
@ -245,6 +244,9 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long userId = long.Parse(User.UserId);
|
|
|
|
|
DateTime dtNow = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
if (useTransaction)
|
|
|
|
|
await TenantDb.Ado.BeginTranAsync();
|
|
|
|
|
try
|
|
|
|
@ -355,20 +357,40 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
|
|
|
|
|
task = new BusinessTask
|
|
|
|
|
{
|
|
|
|
|
ParentId = request.ParentId,
|
|
|
|
|
BusinessId = request.BusinessId,
|
|
|
|
|
BusinessType = request.BusinessType,
|
|
|
|
|
ParentBusinessId = request.ParentBusinessId,
|
|
|
|
|
TaskType = request.TaskType,
|
|
|
|
|
TaskStatus = TaskStatusEnum.Create,
|
|
|
|
|
RecvUsers = string.Join(',', info.Main.RecvUserInfoList.Select(x => x.RecvUserId)) ?? string.Empty,
|
|
|
|
|
NextType = request.NextType,
|
|
|
|
|
CreateBy = long.Parse(User.UserId),
|
|
|
|
|
CreateTime = DateTime.Now
|
|
|
|
|
CreateBy = userId,
|
|
|
|
|
CreateTime = dtNow
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (IsOrderType(request.TaskType) && !task.NextType.HasValue)
|
|
|
|
|
task.NextType = await GetNextTypeAsync(task);
|
|
|
|
|
|
|
|
|
|
await TenantDb.Insertable(task).ExecuteCommandAsync();
|
|
|
|
|
if (request.Steps?.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
if (request.Steps.Where(x => x.Type != StepType.NotSpecified).GroupBy(x => x.Type).Select(x => x.Key).Count() > 1)
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.DuplicateStepType));
|
|
|
|
|
|
|
|
|
|
var steps = request.Steps.Select(x => new TaskStep
|
|
|
|
|
{
|
|
|
|
|
TaskId = task.Id,
|
|
|
|
|
IsCompleted = x.IsCompleted,
|
|
|
|
|
Name = x.Name,
|
|
|
|
|
Type = x.Type,
|
|
|
|
|
SortOrder = request.Steps.IndexOf(x),
|
|
|
|
|
CreateBy = userId,
|
|
|
|
|
CreateTime = dtNow
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
await TenantDb.Insertable(request.Steps).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = await OnTaskCreated(task);
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
@ -542,8 +564,14 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskNotExists));
|
|
|
|
|
if (task.TaskStatus == TaskStatusEnum.Complete)
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskCompleted));
|
|
|
|
|
//if (task.TaskStatus == TaskStatusEnum.Cancel)
|
|
|
|
|
// return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskCancelled));
|
|
|
|
|
|
|
|
|
|
//检查是否有未完成的任务步骤
|
|
|
|
|
var steps = await TenantDb.Queryable<TaskStep>().Where(x => x.TaskId == task.Id && !x.IsCompleted)
|
|
|
|
|
.Select(x => new { x.Type, x.Name }).ToListAsync();
|
|
|
|
|
if (steps.Count > 0)
|
|
|
|
|
return DataResult.Failed(
|
|
|
|
|
MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.UnfinishedItems)) + ":" + string.Join("|", steps.Select(x => x.Type == StepType.NotSpecified ? x.Name : x.Type.GetDescription())),
|
|
|
|
|
nameof(MultiLanguageConst.UnfinishedItems));
|
|
|
|
|
|
|
|
|
|
//触发任务状态变更通知
|
|
|
|
|
if (task.TaskStatus != request.TaskStatus)
|
|
|
|
@ -616,6 +644,102 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置任务步骤状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <param name="useTransaction">是否使用事务</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult> SetStepsAsync(TaskRequest request, bool useTransaction = true)
|
|
|
|
|
{
|
|
|
|
|
if (!await HasAuthorizedAsync())
|
|
|
|
|
return DataResult.FailedWithDesc(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ModuleUnauthorized)));
|
|
|
|
|
|
|
|
|
|
if (request.Steps == null || request.Steps.Count == 0)
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.SubTaskCannotNull));
|
|
|
|
|
|
|
|
|
|
if (useTransaction)
|
|
|
|
|
await TenantDb.Ado.BeginTranAsync();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
BusinessTask task = await GetQuery(request.BusinessId, request.BusinessType, request.TaskType).FirstAsync();
|
|
|
|
|
if (task == null)
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskNotExists));
|
|
|
|
|
if (task.TaskStatus == TaskStatusEnum.Complete)
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskCompleted));
|
|
|
|
|
|
|
|
|
|
var stepTypes = request.Steps.Select(x => x.Type);
|
|
|
|
|
var steps = await TenantDb.Queryable<TaskStep>().Where(x => x.TaskId == task.Id && stepTypes.Contains(x.Type))
|
|
|
|
|
.Select(x => new TaskStep
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
Type = x.Type,
|
|
|
|
|
Name = x.Name,
|
|
|
|
|
SortOrder = x.SortOrder
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
long userId = long.Parse(User.UserId);
|
|
|
|
|
DateTime dtNow = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
foreach (var item in steps)
|
|
|
|
|
{
|
|
|
|
|
var reqStep = request.Steps.Find(x => x.Type == item.Type);
|
|
|
|
|
if (reqStep == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
item.SetValue(reqStep.Value);
|
|
|
|
|
item.IsCompleted = reqStep.IsCompleted;
|
|
|
|
|
item.UpdateBy = userId;
|
|
|
|
|
item.UpdateTime = dtNow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await TenantDb.Updateable(steps).UpdateColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
x.Value,
|
|
|
|
|
x.IsCompleted,
|
|
|
|
|
x.UpdateBy,
|
|
|
|
|
x.UpdateTime
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
if (request.AutoSync)
|
|
|
|
|
{
|
|
|
|
|
var allSteps = await TenantDb.Queryable<TaskStep>().Where(x => x.TaskId == task.Id)
|
|
|
|
|
.Select(x => new
|
|
|
|
|
{
|
|
|
|
|
x.Id,
|
|
|
|
|
x.IsCompleted
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
if (allSteps.Count > 0 && allSteps.Count == allSteps.Count(x => x.IsCompleted))
|
|
|
|
|
{
|
|
|
|
|
var result = await SetTaskStatusAsync(new TaskUpdateRequest
|
|
|
|
|
{
|
|
|
|
|
BusinessId = task.BusinessId,
|
|
|
|
|
BusinessType = task.BusinessType,
|
|
|
|
|
TaskTypeName = request.TaskTypeName,
|
|
|
|
|
TaskStatus = TaskStatusEnum.Complete
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (useTransaction)
|
|
|
|
|
await TenantDb.Ado.CommitTranAsync();
|
|
|
|
|
|
|
|
|
|
return DataResult.Success;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
if (useTransaction)
|
|
|
|
|
await TenantDb.Ado.RollbackTranAsync();
|
|
|
|
|
|
|
|
|
|
await ex.LogAsync(Db);
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 当任务状态发生变化时调用
|
|
|
|
|
/// </summary>
|
|
|
|
|