xfe 1 жил өмнө
parent
commit
aec1ec2016

+ 33 - 17
src/Hotline/FlowEngine/Workflows/WorkflowDomainService.cs

@@ -121,7 +121,7 @@ namespace Hotline.FlowEngine.Workflows
 
 
             //firststeps
             //firststeps
             var firstSteps = await CreateNextStepsAsync(workflow, startStep, dto, firstStepDefine,
             var firstSteps = await CreateNextStepsAsync(workflow, startStep, dto, firstStepDefine,
-                isNextDynamic, flowAssignInfo, expiredTime, stepHandlers, cancellationToken);
+                isNextDynamic, flowAssignInfo, expiredTime, stepHandlers, dto.IsStartCountersign, cancellationToken);
             if (firstSteps.Any())
             if (firstSteps.Any())
                 workflow.Steps.AddRange(firstSteps);
                 workflow.Steps.AddRange(firstSteps);
 
 
@@ -324,6 +324,8 @@ namespace Hotline.FlowEngine.Workflows
                 currentStep.FileJson = await _fileRepository.AddFileAsync(dto.Files, workflow.ExternalId,
                 currentStep.FileJson = await _fileRepository.AddFileAsync(dto.Files, workflow.ExternalId,
                     currentStep.Id, cancellationToken);
                     currentStep.Id, cancellationToken);
 
 
+            var isStartCountersign = currentStep.IsInCountersign() || dto.IsStartCountersign;
+
             var counterSignType = GetCounterSignType(currentStep.BusinessType);
             var counterSignType = GetCounterSignType(currentStep.BusinessType);
 
 
             var updateSteps = new List<WorkflowStep> { currentStep };
             var updateSteps = new List<WorkflowStep> { currentStep };
@@ -443,9 +445,21 @@ namespace Hotline.FlowEngine.Workflows
                 return;
                 return;
             }
             }
 
 
+            //创建会签数据
+            if (isStartCountersign)
+            {
+                var exists = workflow.Countersigns.Any(d =>
+                    !d.IsCompleted() && d.StarterId == _sessionContext.RequiredUserId);
+                if (exists)
+                    throw new UserFriendlyException("该用户在当前流程存在未结束会签");
+                await StartCountersignAsync(workflow, currentStep, dto, flowAssignInfo.FlowAssignType,
+                    counterSignType, expiredTime, cancellationToken);
+            }
+
             //创建下一/N个节点(会签汇总节点:会签未全部办理时不创建,最后一个会签办理节点创建会签汇总节点)
             //创建下一/N个节点(会签汇总节点:会签未全部办理时不创建,最后一个会签办理节点创建会签汇总节点)
-            var nextSteps = await CreateNextStepsAsync(workflow, currentStep, dto, nextStepDefine, isNextDynamic,
-                flowAssignInfo, expiredTime, stepHandlers, cancellationToken);
+            var nextSteps = await CreateNextStepsAsync(workflow, currentStep, dto, 
+                nextStepDefine, isNextDynamic, flowAssignInfo, expiredTime, stepHandlers, isStartCountersign, 
+                cancellationToken);
 
 
             ////赋值当前节点的下级办理节点
             ////赋值当前节点的下级办理节点
             //if (dto.IsStartCountersign
             //if (dto.IsStartCountersign
@@ -1165,15 +1179,15 @@ namespace Hotline.FlowEngine.Workflows
             if (dto.IsStartCountersign && !counterSignType.HasValue)
             if (dto.IsStartCountersign && !counterSignType.HasValue)
                 throw new UserFriendlyException("缺少会签类型参数");
                 throw new UserFriendlyException("缺少会签类型参数");
 
 
-            //创建会签数据
-            if (dto.IsStartCountersign)
-            {
-                var exists = workflow.Countersigns.Any(d =>
-                    !d.IsCompleted() && d.StarterId == _sessionContext.RequiredUserId);
-                if (exists)
-                    throw new UserFriendlyException("该用户在当前流程存在未结束会签");
-                await StartCountersignAsync(workflow, step, dto, flowAssignType, counterSignType, expiredTime, cancellationToken);
-            }
+            ////创建会签数据
+            //if (dto.IsStartCountersign)
+            //{
+            //    var exists = workflow.Countersigns.Any(d =>
+            //        !d.IsCompleted() && d.StarterId == _sessionContext.RequiredUserId);
+            //    if (exists)
+            //        throw new UserFriendlyException("该用户在当前流程存在未结束会签");
+            //    await StartCountersignAsync(workflow, step, dto, flowAssignType, counterSignType, expiredTime, cancellationToken);
+            //}
 
 
             //办理参数
             //办理参数
             _mapper.Map(dto, step);
             _mapper.Map(dto, step);
@@ -1255,7 +1269,8 @@ namespace Hotline.FlowEngine.Workflows
         /// </summary>
         /// </summary>
         private async Task<List<WorkflowStep>> CreateNextStepsAsync(Workflow workflow, WorkflowStep currentStep,
         private async Task<List<WorkflowStep>> CreateNextStepsAsync(Workflow workflow, WorkflowStep currentStep,
             BasicWorkflowDto dto, StepDefine nextStepDefine, bool isNextDynamic, FlowAssignInfo flowAssignInfo,
             BasicWorkflowDto dto, StepDefine nextStepDefine, bool isNextDynamic, FlowAssignInfo flowAssignInfo,
-            DateTime? expiredTime, List<WorkflowStepHandler> stepHandlers, CancellationToken cancellationToken)
+            DateTime? expiredTime, List<WorkflowStepHandler> stepHandlers, bool isStartCountersign,
+            CancellationToken cancellationToken)
         {
         {
             List<WorkflowStep> nextSteps = new();
             List<WorkflowStep> nextSteps = new();
             if (currentStep.IsInCountersign())
             if (currentStep.IsInCountersign())
@@ -1266,7 +1281,7 @@ namespace Hotline.FlowEngine.Workflows
                     // t: check if dto.StartCs t: csconfig f: config
                     // t: check if dto.StartCs t: csconfig f: config
                     if (currentStep.IsTopCountersignEndStep(workflow.TopCountersignStepId))
                     if (currentStep.IsTopCountersignEndStep(workflow.TopCountersignStepId))
                     {
                     {
-                        if (dto.IsStartCountersign)
+                        if (isStartCountersign)
                         {
                         {
                             //依据会签策略创建会签下一级节点
                             //依据会签策略创建会签下一级节点
                             nextSteps = await CreateCountersignStepsAsync(workflow, nextStepDefine, currentStep, dto,
                             nextSteps = await CreateCountersignStepsAsync(workflow, nextStepDefine, currentStep, dto,
@@ -1306,7 +1321,7 @@ namespace Hotline.FlowEngine.Workflows
                     }
                     }
                 }
                 }
             }
             }
-            else if (dto.IsStartCountersign) //top
+            else if (isStartCountersign) //top
             {
             {
                 //依据会签策略创建会签下一级节点
                 //依据会签策略创建会签下一级节点
                 nextSteps = await CreateCountersignStepsAsync(workflow, nextStepDefine, currentStep, dto,
                 nextSteps = await CreateCountersignStepsAsync(workflow, nextStepDefine, currentStep, dto,
@@ -1365,7 +1380,8 @@ namespace Hotline.FlowEngine.Workflows
             CancellationToken cancellationToken = default
             CancellationToken cancellationToken = default
         )
         )
         {
         {
-            var countersignId = dto.IsStartCountersign ? prevStep.StartCountersignId : prevStep.CountersignId;
+            //var countersignId = dto.IsStartCountersign ? prevStep.StartCountersignId : prevStep.CountersignId;
+            var countersignId = prevStep.StartCountersignId;
 
 
             var handlerType = stepDefine.CountersignPolicy switch
             var handlerType = stepDefine.CountersignPolicy switch
             {
             {
@@ -1884,7 +1900,7 @@ namespace Hotline.FlowEngine.Workflows
             }
             }
 
 
             return await CreateStepsAsync(workflow, stepDefine, prevStep, dto, dto.IsStartCountersign,
             return await CreateStepsAsync(workflow, stepDefine, prevStep, dto, dto.IsStartCountersign,
-                flowAssignInfo.FlowAssignType, handlers, stepHandlers, null, 
+                flowAssignInfo.FlowAssignType, handlers, stepHandlers, null,
                 EWorkflowStepStatus.WaitForAccept, ECountersignPosition.None,
                 EWorkflowStepStatus.WaitForAccept, ECountersignPosition.None,
                 true, traceStatus, null, expiredTime, cancellationToken);
                 true, traceStatus, null, expiredTime, cancellationToken);
         }
         }