diff --git a/ds-wms-service/DS.Module.Core/Condition/ConditionHelper.cs b/ds-wms-service/DS.Module.Core/Condition/ConditionHelper.cs index 37f2c3a0..f44a6f2a 100644 --- a/ds-wms-service/DS.Module.Core/Condition/ConditionHelper.cs +++ b/ds-wms-service/DS.Module.Core/Condition/ConditionHelper.cs @@ -44,11 +44,18 @@ namespace DS.Module.Core.Condition { var obj = dataContext.Get(firstKey)!; - var propertyPath = item.Field.Substring(item.Field.IndexOf('.') + 1); - var (_, val, _) = GetPropertyValue(obj, propertyPath); + if (obj == null) + { + valStr = null; + } + else + { + var propertyPath = item.Field.Substring(item.Field.IndexOf('.') + 1); + var (_, val, _) = GetPropertyValue(obj, propertyPath); - if (val != null) - valStr = val.ToString(); + if (val != null) + valStr = val.ToString(); + } } } diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs index 2fe0e9df..1854d1dc 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs @@ -2823,11 +2823,14 @@ namespace DS.WMS.Core.TaskPlat.Method ); TaskFlowRuner runer = new TaskFlowRuner(tenantDb, serviceProvider); - var result1 = await runer.GetWorkFlowNextConfig(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext, null); // 首位 - var result2 = await runer.GetWorkFlowNextConfig(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext, 20001); // 正常 - var result3 = await runer.GetWorkFlowNextConfig(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext, 20002); // 分支判断 - var result4 = await runer.GetWorkFlowNextConfig(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext, 20003); // 分支结尾判断 - var result5 = await runer.GetWorkFlowNextConfig(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext, 20008); // 末位 + //var result1 = await runer.GetWorkFlowNextConfigByTaskType(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext, null); // 首位 + //var result2 = await runer.GetWorkFlowNextConfigByTaskType(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext, 20001); // 正常 + //var result3 = await runer.GetWorkFlowNextConfigByTaskType(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext, 20002); // 分支判断 + //var result4 = await runer.GetWorkFlowNextConfigByTaskType(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext, 20003); // 分支结尾判断 + //var result5 = await runer.GetWorkFlowNextConfigByTaskType(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext, 20008); // 末位 + + var result12 = await runer.GetWorkFlowNextConfigByTaskType(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext, null); // 首位 + var result22 = await runer.GetWorkFlowNextConfigByTaskType(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext, TaskBaseTypeEnum.WAIT_BOOKING); // 正常 break; } } diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs index 7fe7e09d..31f897d0 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs @@ -374,6 +374,111 @@ namespace DS.WMS.Core.TaskPlat return await Run(taskBaseType, taskId, dataContext); } + /// + /// 根据当前节点Id,获取工作流下一个任务类型 + /// + /// 工作流流程类型 + /// + /// 当前执行的任务类型(如果为空,则返回首个任务类型) + /// (下一个任务类型,下一节点Id) + public async Task GetWorkFlowNextConfigByTaskType(TaskBaseTypeEnum workFlowType, TaskFlowDataContext dataContext, TaskBaseTypeEnum? currentTaskType) + { + var allConfigList = await tenantDb.Queryable() + .Where(t => t.MainConfigId == SqlFunc.Subqueryable().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() + .Where(x => allConfigModuleIdList.Contains(x.Id) && x.TaskType == currentTaskType.ToString()) + .Select(x => x.Id) + .FirstAsync(); + configId = allConfigList.First(x => x.ExecuteModuleId == currentModuleId).Id; + } + List 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() + .Where(x => configIdList.Contains(x.ConfigId)) + .ToListAsync(); + + var matchedConfigList = new List(); + 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(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().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; + } + /// /// 根据当前节点Id,获取工作流下一个任务类型 /// diff --git a/ds-wms-service/DS.WMS.Test/SaasTest.cs b/ds-wms-service/DS.WMS.Test/SaasTest.cs index bf3d04d2..77664245 100644 --- a/ds-wms-service/DS.WMS.Test/SaasTest.cs +++ b/ds-wms-service/DS.WMS.Test/SaasTest.cs @@ -265,6 +265,6 @@ public class SaasTest (TaskFlowDataNameConst.Business, order) ); TaskFlowRuner runer = new TaskFlowRuner(tenantDb, _serviceProvider); - var result = await runer.GetWorkFlowNextConfig(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext); + //var result = await runer.GetWorkFlowNextConfigByTaskType(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext); } } \ No newline at end of file