|
|
|
@ -22,7 +22,6 @@ using DS.WMS.Core.TaskPlat.Interface;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Masuit.Tools;
|
|
|
|
|
using Masuit.Tools.Systems;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
|
@ -123,8 +122,6 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected Lazy<IRuleEngineService> RuleEngineService { get; private set; }
|
|
|
|
|
|
|
|
|
|
readonly IConfiguration configuration;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化
|
|
|
|
|
/// </summary>
|
|
|
|
@ -135,7 +132,6 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
LogService = provider.GetRequiredService<ITaskLogService>();
|
|
|
|
|
TaskAllocationService = provider.GetRequiredService<ITaskAllocationService>();
|
|
|
|
|
ActionService = provider.GetRequiredService<IActionManagerService>();
|
|
|
|
|
configuration = provider.GetRequiredService<IConfiguration>();
|
|
|
|
|
|
|
|
|
|
ClientParamService = new Lazy<IClientParamService>(provider.GetRequiredService<IClientParamService>());
|
|
|
|
|
FlowService = new Lazy<IClientFlowInstanceService>(provider.GetRequiredService<IClientFlowInstanceService>());
|
|
|
|
@ -185,23 +181,31 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult> CreateTaskAsync(TaskCreationRequest request, bool useTransaction = true)
|
|
|
|
|
{
|
|
|
|
|
if (request.BusinessType.HasValue)
|
|
|
|
|
if (!await HasAuthorizedAsync())
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.ModuleUnauthorized));
|
|
|
|
|
|
|
|
|
|
if (request.Steps?.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
bool isBizValid = false;
|
|
|
|
|
switch (request.BusinessType.Value)
|
|
|
|
|
{
|
|
|
|
|
case BusinessType.OceanShippingExport:
|
|
|
|
|
isBizValid = await TenantDb.Queryable<SeaExport>().AnyAsync(x => x.Id == request.BusinessId);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
if (!isBizValid)
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Biz_Not_Valid));
|
|
|
|
|
if (request.Steps.Any(x => x.Type == StepType.NotSpecified && string.IsNullOrEmpty(x.Name)))
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TypeOrName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//if (request.BusinessType.HasValue)
|
|
|
|
|
//{
|
|
|
|
|
// bool isBizValid = false;
|
|
|
|
|
// switch (request.BusinessType.Value)
|
|
|
|
|
// {
|
|
|
|
|
// case BusinessType.OceanShippingExport:
|
|
|
|
|
// isBizValid = await TenantDb.Queryable<SeaExport>().AnyAsync(x => x.Id == request.BusinessId);
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if (!await HasAuthorizedAsync())
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.ModuleUnauthorized));
|
|
|
|
|
// if (!isBizValid)
|
|
|
|
|
// return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Biz_Not_Valid));
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
if (request.HasCabin.GetValueOrDefault() && request.BusinessType.HasValue)
|
|
|
|
|
{
|
|
|
|
@ -254,8 +258,6 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
TaskManageOrderMessageInfo? info = null;
|
|
|
|
|
if (task == null)
|
|
|
|
|
{
|
|
|
|
|
long tenatId = long.Parse(User.TenantId);
|
|
|
|
|
string tenatName = Db.Queryable<SysTenant>().Where(x => x.Id == tenatId).Select(x => x.Name).First();
|
|
|
|
|
info = new TaskManageOrderMessageInfo
|
|
|
|
|
{
|
|
|
|
|
Head = new TaskManageOrderMessageHeadInfo
|
|
|
|
@ -279,8 +281,8 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
TaskDesp = request.TaskDescription,
|
|
|
|
|
TaskUserId = User.UserId,
|
|
|
|
|
TaskUserName = User.UserName,
|
|
|
|
|
TaskTenatId = tenatId,
|
|
|
|
|
TaskTenatName = tenatName,
|
|
|
|
|
TaskTenatId = long.Parse(User.TenantId),
|
|
|
|
|
TaskTenatName = User.TenantName,
|
|
|
|
|
IsCheckExistsByTaskType = true
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
@ -375,16 +377,13 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
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),
|
|
|
|
|
SortOrder = x.Priority ?? request.Steps.IndexOf(x),
|
|
|
|
|
CreateBy = userId,
|
|
|
|
|
CreateTime = dtNow
|
|
|
|
|
}).ToList();
|
|
|
|
@ -564,6 +563,8 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskNotExists));
|
|
|
|
|
if (task.TaskStatus == TaskStatusEnum.Complete)
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskCompleted));
|
|
|
|
|
if (request.TaskStatus == TaskStatusEnum.Complete && await TenantDb.Queryable<BusinessTask>().AnyAsync(x => x.ParentId == task.Id && x.TaskStatus != request.TaskStatus))
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.UnfinishedItems));
|
|
|
|
|
|
|
|
|
|
//检查是否有未完成的任务步骤
|
|
|
|
|
var steps = await TenantDb.Queryable<TaskStep>().Where(x => x.TaskId == task.Id && !x.IsCompleted)
|
|
|
|
@ -669,29 +670,39 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
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))
|
|
|
|
|
var allSteps = await TenantDb.Queryable<TaskStep>().Where(x => x.TaskId == task.Id).OrderBy(x => x.SortOrder)
|
|
|
|
|
.Select(x => new TaskStep
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
Type = x.Type,
|
|
|
|
|
Name = x.Name,
|
|
|
|
|
IsCompleted = x.IsCompleted,
|
|
|
|
|
SortOrder = x.SortOrder
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
//获取未完成的优先级最高的步骤
|
|
|
|
|
var topSteps = allSteps.Where(x => !x.IsCompleted).GroupBy(x => x.SortOrder).OrderBy(x => x.Key).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
var stepTypes = request.Steps.Select(x => x.Type);
|
|
|
|
|
List<TaskStep> steps = [];
|
|
|
|
|
long userId = long.Parse(User.UserId);
|
|
|
|
|
DateTime dtNow = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
foreach (var item in steps)
|
|
|
|
|
foreach (var item in allSteps)
|
|
|
|
|
{
|
|
|
|
|
var reqStep = request.Steps.Find(x => x.Type == item.Type);
|
|
|
|
|
var reqStep = request.Steps.Find(x => x.Type == item.Type || (x.Type == StepType.NotSpecified && x.Name == item.Name));
|
|
|
|
|
if (reqStep == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (topSteps.Any(x => x.SortOrder > item.SortOrder))
|
|
|
|
|
return DataResult.Failed(
|
|
|
|
|
MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.HigherUnfinishedItems)) + ":" + string.Join("|", topSteps.Select(x => x.Type == StepType.NotSpecified ? x.Name : x.Type.GetDescription())),
|
|
|
|
|
nameof(MultiLanguageConst.HigherUnfinishedItems));
|
|
|
|
|
|
|
|
|
|
item.SetValue(reqStep.Value);
|
|
|
|
|
item.IsCompleted = reqStep.IsCompleted;
|
|
|
|
|
item.UpdateBy = userId;
|
|
|
|
|
item.UpdateTime = dtNow;
|
|
|
|
|
steps.Add(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await TenantDb.Updateable(steps).UpdateColumns(x => new
|
|
|
|
@ -704,12 +715,6 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
@ -751,20 +756,31 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取业务的任务信息
|
|
|
|
|
/// 获取任务信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bsId">业务ID</param>
|
|
|
|
|
/// <param name="businessType">业务类型</param>
|
|
|
|
|
/// <param name="withSubTask">是否获取子任务</param>
|
|
|
|
|
/// <param name="types">任务类型</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<List<BusinessTaskDto>>> GetTasks(long bsId, BusinessType? businessType, params TaskBaseTypeEnum[] types)
|
|
|
|
|
public async Task<DataResult<List<BusinessTask>>> GetTasks(long bsId, BusinessType? businessType, bool withSubTask, params TaskBaseTypeEnum[] types)
|
|
|
|
|
{
|
|
|
|
|
var list = await TenantDb.Queryable<BusinessTask>().Where(x => x.BusinessId == bsId)
|
|
|
|
|
var list = await TenantDb.Queryable<BusinessTask>().Includes(x => x.Steps).Where(x => x.BusinessId == bsId)
|
|
|
|
|
.WhereIF(businessType.HasValue, x => x.BusinessType == businessType)
|
|
|
|
|
.WhereIF(types != null && types.Length > 0, x => types.Contains(x.TaskType))
|
|
|
|
|
.Select<BusinessTaskDto>().ToListAsync();
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
if (list.Count > 0 && withSubTask)
|
|
|
|
|
{
|
|
|
|
|
var ids = list.Select(x => x.Id);
|
|
|
|
|
var list2 = await TenantDb.Queryable<BusinessTask>().Includes(x => x.Steps)
|
|
|
|
|
.Where(x => x.ParentId.HasValue && ids.Contains(x.ParentId.Value)).ToListAsync();
|
|
|
|
|
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
item.SubTasks = list2.FindAll(x => x.ParentId == item.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = DataResult<List<BusinessTaskDto>>.Success(list);
|
|
|
|
|
var result = DataResult<List<BusinessTask>>.Success(list);
|
|
|
|
|
result.Count = list.Count;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|