任务编排配置修改

usertest
zhangxiaofeng 3 months ago
parent 71042087c0
commit a16ff28a3f

@ -40,17 +40,17 @@ namespace DS.WMS.Core.TaskPlat.Entity
[SugarColumn(ColumnDescription = "所属主入口流程主键", IsNullable = true)]
public long? MainConfigId { get; set; }
///// <summary>
///// 下一流程主键
///// </summary>
//[SugarColumn(ColumnDescription = "下一流程主键", IsNullable = true)]
//public long? NextConfigId { get; set; }
/// <summary>
/// 父项流程主键
/// 下一流程主键列表(使用,分隔)
/// </summary>
[SugarColumn(ColumnDescription = "父项流程主键", IsNullable = true)]
public long? ParentConfigId { get; set; }
[SugarColumn(ColumnDescription = "下一流程主键", IsNullable = true, Length = 255)]
public string? NextConfigId { get; set; }
///// <summary>
///// 父项流程主键
///// </summary>
//[SugarColumn(ColumnDescription = "父项流程主键", IsNullable = true)]
//public long? ParentConfigId { get; set; }
/// <summary>
/// 当执行过程中发生异常时是否继续执行下一个节点

@ -212,7 +212,12 @@ namespace DS.WMS.Core.TaskPlat
flowLogDetail.ConfigId = executeConfig.Id;
// 如果当前节点要执行(或者配置了默认执行节点)取出下一批要进行条件判断的节点列表
waitMatchConfigList = configList.Where(x => x.ParentConfigId == executeConfig.Id).ToList();
waitMatchConfigList.Clear();
if (!string.IsNullOrEmpty(executeConfig.NextConfigId))
{
var ids = executeConfig.NextConfigId.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => Convert.ToInt64(x));
waitMatchConfigList = configList.Where(x => ids.Contains(x.Id)).ToList();
}
// 注入参数
var paramItemList = paramList.Where(x => x.ConfigId == executeConfig.Id).ToList();
@ -373,66 +378,89 @@ namespace DS.WMS.Core.TaskPlat
if (allConfigList.Count == 0) return null;
List<TaskFlowConfig> waitMatchConfigList = new();
long configId;
if (currentConfigId == null)
{
waitMatchConfigList.Add(allConfigList.First(x => x.IsMain));
configId = allConfigList.First(x => x.IsMain).Id;
}
else
{
var currentConfig = allConfigList.FirstOrDefault(x => x.Id == currentConfigId);
if (currentConfig == null) return null;
waitMatchConfigList.AddRange(allConfigList.Where(x => x.ParentConfigId == currentConfig.Id));
configId = currentConfigId.Value;
}
if (waitMatchConfigList.Count == 0) return null;
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 configIdList = waitMatchConfigList.Select(x => x.Id);
var conditionList = await tenantDb.Queryable<TaskFlowCondition>()
.Where(x => configIdList.Contains(x.ConfigId))
.ToListAsync();
var nextIds = currentConfig.NextConfigId.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => Convert.ToInt64(x));
waitMatchConfigList = allConfigList.Where(x => nextIds.Contains(x.Id)).ToList();
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
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 contitionContent = JsonConvert.DeserializeObject<ConditionContent>(condition.Content)!;
if (ConditionHelper.IsPass(contitionContent, dataContext))
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);
}
TaskFlowConfig? executeConfig = null;
if (matchedConfigList.Count == 1)
{
executeConfig = matchedConfigList[0];
}
else if (matchedConfigList.Count > 1)
{
executeConfig = matchedConfigList.FirstOrDefault(x => x.IsMoreMatchDefault);
}
if (executeConfig == null) return null;
if (executeConfig == null)
{
executeConfig = waitMatchConfigList.FirstOrDefault(x => x.IsUnMatchDefault);
}
var taskType = await tenantDb.Queryable<TaskFlowModule>().Where(x => x.Id == executeConfig.ExecuteModuleId).Select(x => x.TaskType).FirstAsync();
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).Select(x => x.TaskType).FirstAsync();
if (taskType != null && Enum.TryParse(typeof(TaskBaseTypeEnum), taskType, out object? temp))
{
return ((TaskBaseTypeEnum)temp, executeConfig.Id);
if (taskType != null && Enum.TryParse(typeof(TaskBaseTypeEnum), taskType, out object? temp))
{
return ((TaskBaseTypeEnum)temp, executeConfig.Id);
}
}
}
return null;
}

@ -3,6 +3,7 @@ using DS.Module.Core.Data;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.TaskPlat;
using DS.WMS.Core.TaskPlat.Dtos;
using DS.WMS.Core.TaskPlat.Entity;
using DS.WMS.Core.TaskPlat.Interface;
@ -70,10 +71,19 @@ public class TaskAllocationController : ApiController
(TaskFlowDataNameConst.Business, order)
);
var result = taskAllocationService.GetAllotUserBySeaExportId(new List<TaskBaseTypeEnum>() {
TaskBaseTypeEnum.INVOICE_BILL_MAIL,
TaskBaseTypeEnum.NOT_LOADED,
TaskBaseTypeEnum.NOT_SHIPMENG,
}, 1816649497120477184, dataContext);
// 分配测试
//var result = taskAllocationService.GetAllotUserBySeaExportId(new List<TaskBaseTypeEnum>() {
// TaskBaseTypeEnum.INVOICE_BILL_MAIL,
// TaskBaseTypeEnum.NOT_LOADED,
// TaskBaseTypeEnum.NOT_SHIPMENG,
//}, 1816649497120477184, dataContext);
// 工作流节点测试
TaskFlowRuner runer = new TaskFlowRuner(tenantDb, serviceProvider);
//var result1 = await runer.GetWorkFlowNextConfig(dataContext, null); // 首位
//var result2 = await runer.GetWorkFlowNextConfig(dataContext, 20001); // 正常
//var result3 = await runer.GetWorkFlowNextConfig(dataContext, 20002); // 分支判断
//var result4 = await runer.GetWorkFlowNextConfig(dataContext, 20003); // 分支结尾判断
//var result5 = await runer.GetWorkFlowNextConfig(dataContext, 20007); // 末位
}
}
Loading…
Cancel
Save