|
|
|
@ -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)
|
|
|
|
|
{
|
|
|
|
|
bool isBizValid = false;
|
|
|
|
|
switch (request.BusinessType.Value)
|
|
|
|
|
if (!await HasAuthorizedAsync())
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.ModuleUnauthorized));
|
|
|
|
|
|
|
|
|
|
if (request.Steps?.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
@ -593,7 +594,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
DataResult result;
|
|
|
|
|
if (!FeeTypes.Contains(request.TaskType))
|
|
|
|
|
{
|
|
|
|
|
result = await ManagerService.SetTaskStatusWithBsno(request.BusinessId, request.TaskType, request.TaskStatus, DateTime.Now, false, request.TaskDesc);
|
|
|
|
|
result = await ManagerService.SetTaskStatusWithBsno(request.BusinessId, request.TaskType, request.TaskStatus, DateTime.Now, request.TaskDesc);
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
return DataResult.Failed(result.Message, result.MultiCode);
|
|
|
|
|
|
|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
@ -954,7 +970,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result = await ManagerService.SetTaskStatusWithBsno(request.BusinessId, request.TaskType, TaskStatusEnum.Cancel, dt, false);
|
|
|
|
|
result = await ManagerService.SetTaskStatusWithBsno(request.BusinessId, request.TaskType, TaskStatusEnum.Cancel, dt);
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
@ -1090,7 +1106,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
if (relativeTasks.All(x => x.TaskStatus == TaskStatusEnum.Complete))
|
|
|
|
|
{
|
|
|
|
|
var userIdList = tasks.Where(x => relativeFeeIds.Contains(x.BusinessId)).SelectMany(x => x.RecvUserIdArray).Distinct().ToList();
|
|
|
|
|
result = await ManagerService.SetTaskStatusWithBsno(biz.Key.BusinessId, request.TaskType, TaskStatusEnum.Complete, DateTime.Now, false, userIdList: userIdList);
|
|
|
|
|
result = await ManagerService.SetTaskStatusWithBsno(biz.Key.BusinessId, request.TaskType, TaskStatusEnum.Complete, DateTime.Now, userIdList: userIdList);
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|