|
|
|
@ -374,6 +374,111 @@ namespace DS.WMS.Core.TaskPlat
|
|
|
|
|
return await Run(taskBaseType, taskId, dataContext);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据当前节点Id,获取工作流下一个任务类型
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="workFlowType">工作流流程类型</param>
|
|
|
|
|
/// <param name="dataContext"></param>
|
|
|
|
|
/// <param name="currentTaskType">当前执行的任务类型(如果为空,则返回首个任务类型)</param>
|
|
|
|
|
/// <returns>(下一个任务类型,下一节点Id)</returns>
|
|
|
|
|
public async Task<TaskBaseTypeEnum?> GetWorkFlowNextConfigByTaskType(TaskBaseTypeEnum workFlowType, TaskFlowDataContext dataContext, TaskBaseTypeEnum? currentTaskType)
|
|
|
|
|
{
|
|
|
|
|
var allConfigList = await tenantDb.Queryable<TaskFlowConfig>()
|
|
|
|
|
.Where(t => t.MainConfigId == SqlFunc.Subqueryable<TaskFlowConfig>().Where(x => x.IsMain && x.TaskType == workFlowType.ToString()).Select(x => x.Id))
|
|
|
|
|
.OrderBy(t => t.Id)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
long configId;
|
|
|
|
|
if (currentTaskType == null)
|
|
|
|
|
{
|
|
|
|
|
configId = allConfigList.First(x => x.IsMain).Id;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var allConfigModuleIdList = allConfigList.Select(x => x.ExecuteModuleId).ToList();
|
|
|
|
|
var currentModuleId = await tenantDb.Queryable<TaskFlowModule>()
|
|
|
|
|
.Where(x => allConfigModuleIdList.Contains(x.Id) && x.TaskType == currentTaskType.ToString())
|
|
|
|
|
.Select(x => x.Id)
|
|
|
|
|
.FirstAsync();
|
|
|
|
|
configId = allConfigList.First(x => x.ExecuteModuleId == currentModuleId).Id;
|
|
|
|
|
}
|
|
|
|
|
List<TaskFlowConfig> waitMatchConfigList = new();
|
|
|
|
|
for (int i = 0; i < allConfigList.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var currentConfig = allConfigList.FirstOrDefault(x => x.Id == configId);
|
|
|
|
|
if (currentConfig == null || string.IsNullOrEmpty(currentConfig.NextConfigId))
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
var nextIds = currentConfig.NextConfigId.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => Convert.ToInt64(x));
|
|
|
|
|
waitMatchConfigList = allConfigList.Where(x => nextIds.Contains(x.Id)).ToList();
|
|
|
|
|
|
|
|
|
|
if (waitMatchConfigList.Count == 0) return null; // 如果走了这一步的return,说明配置有问题:配置了下一节点的id,但是却查不到
|
|
|
|
|
|
|
|
|
|
var configIdList = waitMatchConfigList.Select(x => x.Id);
|
|
|
|
|
var conditionList = await tenantDb.Queryable<TaskFlowCondition>()
|
|
|
|
|
.Where(x => configIdList.Contains(x.ConfigId))
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
var matchedConfigList = new List<TaskFlowConfig>();
|
|
|
|
|
foreach (var item in waitMatchConfigList)
|
|
|
|
|
{
|
|
|
|
|
var condition = conditionList.FirstOrDefault(x => x.ConfigId == item.Id);
|
|
|
|
|
if (condition == null || string.IsNullOrEmpty(condition.Content))
|
|
|
|
|
{
|
|
|
|
|
matchedConfigList.Add(item);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var contitionContent = JsonConvert.DeserializeObject<ConditionContent>(condition.Content)!;
|
|
|
|
|
if (ConditionHelper.IsPass(contitionContent, dataContext))
|
|
|
|
|
{
|
|
|
|
|
matchedConfigList.Add(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TaskFlowConfig? executeConfig = null;
|
|
|
|
|
if (matchedConfigList.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
executeConfig = matchedConfigList[0];
|
|
|
|
|
}
|
|
|
|
|
else if (matchedConfigList.Count > 1)
|
|
|
|
|
{
|
|
|
|
|
executeConfig = matchedConfigList.FirstOrDefault(x => x.IsMoreMatchDefault);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (executeConfig == null)
|
|
|
|
|
{
|
|
|
|
|
executeConfig = waitMatchConfigList.FirstOrDefault(x => x.IsUnMatchDefault);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (executeConfig == null)
|
|
|
|
|
{
|
|
|
|
|
// 如果最终还是没有匹配到,则需要判断情况
|
|
|
|
|
// 如果待匹配的分支只有1个,则继续循环判断下一节点;否则如果待匹配的分支有多个,则无法判断下一节点
|
|
|
|
|
if (waitMatchConfigList.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
configId = waitMatchConfigList[0].Id;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var taskType = await tenantDb.Queryable<TaskFlowModule>().Where(x => x.Id == executeConfig.ExecuteModuleId && x.ModuleType == 2).Select(x => x.TaskType).FirstAsync();
|
|
|
|
|
|
|
|
|
|
if (taskType != null && Enum.TryParse(typeof(TaskBaseTypeEnum), taskType, out object? temp))
|
|
|
|
|
{
|
|
|
|
|
return (TaskBaseTypeEnum)temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据当前节点Id,获取工作流下一个任务类型
|
|
|
|
|
/// </summary>
|
|
|
|
|