Browse Source

temp to NextAsync.isStartCountersign

xfe 6 tháng trước cách đây
mục cha
commit
673012b81c

+ 6 - 6
src/Hotline.Application/FlowEngine/WorkflowApplication.cs

@@ -156,7 +156,7 @@ public class WorkflowApplication : IWorkflowApplication, IScopeDependency
         var flowAssignInfo =
             await GetNextStepFlowAssignInfoAsync(workflow, startStep, dto, firstStepDefine, isNextDynamic, cancellationToken);
 
-        var counterSignType = _workflowDomainService.GetCounterSignType(dto.IsStartCountersign);
+        var counterSignType = _workflowDomainService.GetCounterSignType(dto.IsStartCountersign, startStep.BusinessType);
 
         //办理开始节点
         await _workflowDomainService.HandleStepAsync(startStep, workflow, dto, counterSignType, expiredTime, cancellationToken);
@@ -1544,7 +1544,7 @@ public class WorkflowApplication : IWorkflowApplication, IScopeDependency
     /// </summary>
     /// <returns></returns>
     private async Task<NextStepOption> GetDynamicStepAsync(
-        EDynamicPolicyCountersign policy, EStepType stepType,
+        ECountersignPolicy policy, EStepType stepType,
         EBusinessType currentBusinessType, CancellationToken cancellationToken)
     {
         int orgLevel;
@@ -1554,7 +1554,7 @@ public class WorkflowApplication : IWorkflowApplication, IScopeDependency
         EFlowDirection? flowDirection = null;
         switch (policy)
         {
-            case EDynamicPolicyCountersign.OrgUpCenterTop:
+            case ECountersignPolicy.OrgUpCenterTop:
                 orgLevel = _sessionContextProvider.SessionContext.OrgLevel - 1;
                 if (orgLevel < 0) orgLevel = 0;
 
@@ -1594,7 +1594,7 @@ public class WorkflowApplication : IWorkflowApplication, IScopeDependency
                 }
 
                 break;
-            case EDynamicPolicyCountersign.OrgUp:
+            case ECountersignPolicy.OrgUp:
                 businessType = _sessionContextProvider.SessionContext.OrgIsCenter
                     ? EBusinessType.Send
                     : _sessionContextProvider.SessionContext.RequiredOrgId.CalcOrgLevel() == 1
@@ -1615,7 +1615,7 @@ public class WorkflowApplication : IWorkflowApplication, IScopeDependency
                     })
                     .ToListAsync(cancellationToken);
                 break;
-            case EDynamicPolicyCountersign.OrgDownCenterTop:
+            case ECountersignPolicy.OrgDownCenterTop:
                 businessType = EBusinessType.Department;
                 if (_sessionContextProvider.SessionContext.OrgIsCenter)
                 {
@@ -1648,7 +1648,7 @@ public class WorkflowApplication : IWorkflowApplication, IScopeDependency
                 }
 
                 break;
-            case EDynamicPolicyCountersign.OrgDown:
+            case ECountersignPolicy.OrgDown:
                 businessType = EBusinessType.Department;
                 orgLevel = _sessionContextProvider.SessionContext.OrgLevel + 1;
                 items = await _organizeRepository.Queryable()

+ 1 - 1
src/Hotline.Share/Dtos/FlowEngine/Definition/StepDefineBasic.cs

@@ -63,7 +63,7 @@ namespace Hotline.Share.Dtos.FlowEngine.Definition
         /// <summary>
         /// 会签策略
         /// </summary>
-        public EDynamicPolicyCountersign? CountersignPolicy { get; set; }
+        public ECountersignPolicy? CountersignPolicy { get; set; }
 
         #endregion
         

+ 1 - 1
src/Hotline.Share/Dtos/FlowEngine/Workflow/StepBasicDto.cs

@@ -136,7 +136,7 @@ namespace Hotline.Share.Dtos.FlowEngine.Workflow
         /// <summary>
         /// 会签策略
         /// </summary>
-        public EDynamicPolicyCountersign? CountersignPolicy { get; set; }
+        public ECountersignPolicy? CountersignPolicy { get; set; }
 
         #endregion
 

+ 68 - 0
src/Hotline.Share/Enums/FlowEngine/ECountersignPolicy.cs

@@ -0,0 +1,68 @@
+using System.ComponentModel;
+
+namespace Hotline.Share.Enums.FlowEngine;
+
+/// <summary>
+/// 动态实例化策略
+/// </summary>
+public enum ECountersignPolicy
+{
+    /// <summary>
+    /// 直属上级部门(中心作为顶级部门)
+    /// </summary>
+    [Description("直属上级(中心作为顶级部门)")]
+    OrgUpCenterTop = 0,
+
+    /// <summary>
+    /// 直属上级(中心作为一级部门)
+    /// </summary>
+    [Description("直属上级(中心作为一级部门)")]
+    OrgUp = 1,
+
+    /// <summary>
+    /// 直属下级部门(中心作为顶级部门)
+    /// </summary>
+    [Description("直属下级(中心作为顶级部门)")]
+    OrgDownCenterTop = 2,
+
+    /// <summary>
+    /// 直属下级(中心作为一级部门)
+    /// </summary>
+    [Description("直属下级(中心作为一级部门)")]
+    OrgDown = 3,
+    // /// <summary>
+    // /// 直属上级部门(中心作为顶级部门)经办人
+    // /// </summary>
+    // [Description("直属上级(中心作为顶级部门) 经办人")]
+    // OrgUpHandleCenterTop = 4,
+    //
+    // /// <summary>
+    // /// 直属上级(中心作为一级部门)
+    // /// </summary>
+    // [Description("直属上级(中心作为一级部门)经办人")]
+    // OrgUpHandle = 5,
+    //
+    // /// <summary>
+    // /// 直属上级部门(中心作为顶级部门) 经办人与领导
+    // /// </summary>
+    // [Description("直属上级(中心作为顶级部门)经办人与领导")]
+    // OrgUpLeadCenterTop = 6,
+    //
+    // /// <summary>
+    // /// 直属上级(中心作为一级部门)经办人与领导
+    // /// </summary>
+    // [Description("直属上级(中心作为一级部门)经办人与领导")]
+    // OrgUpLead = 7,
+    //
+    // /// <summary>
+    // /// 直达中心
+    // /// </summary>
+    // [Description("直达中心")]
+    // ArriveCenter = 8,
+    //
+    // /// <summary>
+    // /// 直达一级部门
+    // /// </summary>
+    // [Description("直达一级部门")]
+    // ArriveOneOrg = 9,
+}

+ 0 - 68
src/Hotline.Share/Enums/FlowEngine/EDynamicPolicyCountersign.cs

@@ -1,68 +0,0 @@
-using System.ComponentModel;
-
-namespace Hotline.Share.Enums.FlowEngine;
-
-/// <summary>
-/// 动态实例化策略
-/// </summary>
-public enum EDynamicPolicyCountersign
-{
-    /// <summary>
-    /// 直属上级部门(中心作为顶级部门)
-    /// </summary>
-    [Description("直属上级(中心作为顶级部门)")]
-    OrgUpCenterTop = 0,
-
-    /// <summary>
-    /// 直属上级(中心作为一级部门)
-    /// </summary>
-    [Description("直属上级(中心作为一级部门)")]
-    OrgUp = 1,
-
-    /// <summary>
-    /// 直属下级部门(中心作为顶级部门)
-    /// </summary>
-    [Description("直属下级(中心作为顶级部门)")]
-    OrgDownCenterTop = 2,
-
-    /// <summary>
-    /// 直属下级(中心作为一级部门)
-    /// </summary>
-    [Description("直属下级(中心作为一级部门)")]
-    OrgDown = 3,
-    /// <summary>
-    /// 直属上级部门(中心作为顶级部门)经办人
-    /// </summary>
-    [Description("直属上级(中心作为顶级部门) 经办人")]
-    OrgUpHandleCenterTop = 4,
-
-    /// <summary>
-    /// 直属上级(中心作为一级部门)
-    /// </summary>
-    [Description("直属上级(中心作为一级部门)经办人")]
-    OrgUpHandle = 5,
-
-    /// <summary>
-    /// 直属上级部门(中心作为顶级部门) 经办人与领导
-    /// </summary>
-    [Description("直属上级(中心作为顶级部门)经办人与领导")]
-    OrgUpLeadCenterTop = 6,
-
-    /// <summary>
-    /// 直属上级(中心作为一级部门)经办人与领导
-    /// </summary>
-    [Description("直属上级(中心作为一级部门)经办人与领导")]
-    OrgUpLead = 7,
-
-    /// <summary>
-    /// 直达中心
-    /// </summary>
-    [Description("直达中心")]
-    ArriveCenter = 8,
-
-    /// <summary>
-    /// 直达一级部门
-    /// </summary>
-    [Description("直达一级部门")]
-    ArriveOneOrg = 9,
-}

+ 1 - 2
src/Hotline/FlowEngine/Workflows/IWorkflowDomainService.cs

@@ -220,8 +220,7 @@ namespace Hotline.FlowEngine.Workflows
         /// <summary>
         /// 获取会签类型
         /// </summary>
-        //ECounterSignType? GetCounterSignType(EBusinessType businessType);
-        ECounterSignType? GetCounterSignType(bool isStartCountersign);
+        ECounterSignType? GetCounterSignType(bool isStartCountersign, EBusinessType currentStepBusinessType);
 
         /// <summary>
         /// 查询退回节点信息

+ 1 - 1
src/Hotline/FlowEngine/Workflows/StepBasicEntity.cs

@@ -272,7 +272,7 @@ public abstract class StepBasicEntity : CreationEntity
     /// <summary>
     /// 会签策略
     /// </summary>
-    public EDynamicPolicyCountersign? CountersignPolicy { get; set; }
+    public ECountersignPolicy? CountersignPolicy { get; set; }
 
     #endregion
 

+ 40 - 30
src/Hotline/FlowEngine/Workflows/WorkflowDomainService.cs

@@ -109,9 +109,11 @@ namespace Hotline.FlowEngine.Workflows
                     PublishStrategy.ParallelWhenAll, cancellationToken);
 
                 //firstStep是否为end,t: 实际办理节点为startStep, 并且handlerId赋值 f: 实际办理节点为firstStep, handlerId未赋值
-                workflow.UpdateActualStepWhenHandle(startStep, _sessionContextProvider.SessionContext.OrgAreaCode, _sessionContextProvider.SessionContext.OrgAreaName, _sessionContextProvider.SessionContext.OrgLevel);
+                workflow.UpdateActualStepWhenHandle(startStep, _sessionContextProvider.SessionContext.OrgAreaCode,
+                    _sessionContextProvider.SessionContext.OrgAreaName, _sessionContextProvider.SessionContext.OrgLevel);
 
-                workflow.UpdateCurrentStepWhenHandle(startStep, _sessionContextProvider.SessionContext.OrgAreaCode, _sessionContextProvider.SessionContext.OrgAreaName, _sessionContextProvider.SessionContext.OrgLevel);
+                workflow.UpdateCurrentStepWhenHandle(startStep, _sessionContextProvider.SessionContext.OrgAreaCode,
+                    _sessionContextProvider.SessionContext.OrgAreaName, _sessionContextProvider.SessionContext.OrgLevel);
 
                 var endTrace = await EndAsync(workflow, dto, firstStepDefine, startStep, expiredTime, cancellationToken);
                 return;
@@ -235,16 +237,16 @@ namespace Hotline.FlowEngine.Workflows
                 _sessionContext.RequiredOrgId,
                 _sessionContext.OrgName);
 
-            //发起会签时记录顶层会签节点(必须在update currentStep之后)
-            var counterSignType = GetCounterSignType(dto.IsStartCountersign);
-            if (dto.IsStartCountersign && !workflow.IsInCountersign)
-                workflow.StartCountersign(startStep.Id, counterSignType);
+            // //发起会签时记录顶层会签节点(必须在update currentStep之后)
+            // var counterSignType = GetCounterSignType(dto.IsStartCountersign);
+            // if (dto.IsStartCountersign && !workflow.IsInCountersign)
+            //     workflow.StartCountersign(startStep.Id, counterSignType);
 
             await _workflowRepository.UpdateAsync(workflow, cancellationToken);
 
             var flowAssignInfo =
                 await GetNextStepFlowAssignInfoAsync(workflow, startStep, dto, firstStepDefine, isNextDynamic, cancellationToken);
-            
+
             //publish
             await _publisher.PublishAsync(new StartWorkflowNotify(workflow, dto, flowAssignInfo.FlowAssignType, startTrace),
                 PublishStrategy.ParallelWhenAll, cancellationToken);
@@ -259,17 +261,16 @@ namespace Hotline.FlowEngine.Workflows
             DateTime? expiredTime = null, CancellationToken cancellationToken = default)
         {
             var workflow = await GetWorkflowAsync(dto.WorkflowId, withDefine: true, withSteps: true,
-            withTraces: true, withCountersigns: true, cancellationToken: cancellationToken);
+                withTraces: true, withCountersigns: true, cancellationToken: cancellationToken);
             CheckWhetherRunnable(workflow.Status);
 
-            //var currentStep = _workflowDomainService.FindCurrentStepWaitForHandle(workflow,
-            //    current.RequiredUserId, current.RequiredOrgId, current.Roles);
             var currentStep = workflow.Steps.FirstOrDefault(d => d.Id == dto.StepId);
             if (currentStep == null)
                 throw new UserFriendlyException(
                     $"未找到对应节点, workflowId: {dto.WorkflowId}, stepId: {dto.StepId}", "未找到对应节点");
             if (currentStep.Status is EWorkflowStepStatus.Handled)
                 throw new UserFriendlyException("该状态不支持继续办理");
+            //todo 校验currentStep 能否由 current 办理
 
             var currentStepDefine = GetStepDefine(workflow.WorkflowDefinition, currentStep.Code);
 
@@ -291,7 +292,7 @@ namespace Hotline.FlowEngine.Workflows
                 nextStepDefine = GetStepDefine(workflow.WorkflowDefinition, dto.NextStepCode);
             }
 
-            //普通节点往汇总节点办理时可以不选,不选的场景主动去查之前的办理对象
+            //普通节点往汇总节点办理时可以不选,不选的场景主动去查之前的办理对象 //todo 按照指派策略生成办理对象
             if (nextStepDefine.StepType is EStepType.Summary && !dto.NextHandlers.Any())
             {
                 var handler = GetSummaryTargetFlowStepHandler(workflow, nextStepDefine.SummaryTargetCode);
@@ -305,15 +306,13 @@ namespace Hotline.FlowEngine.Workflows
             if (dto.IsStartCountersign)
             {
                 if (!currentStepDefine.CanStartCountersign)
-                    throw new UserFriendlyException("当前节点不支持发起会签");
-                //if (currentStepDefine.HandlerType is EHandlerType.Role)
-                //    throw new UserFriendlyException("当前节点不支持发起会签");
+                    throw UserFriendlyException.SameMessage("当前节点不支持发起会签");
                 //即使当前节点支持发起会签,但下一节点为信息汇总节点、结束节点时也不可发起会签
                 if (nextStepDefine.StepType is EStepType.Summary or EStepType.End)
-                    throw new UserFriendlyException("下一节点不允许发起会签");
+                    throw UserFriendlyException.SameMessage("下一汇总节点不允许发起会签");
                 //下一节点是会签汇总节点也不允许发起会签
                 if (dto.BackToCountersignEnd)
-                    throw new UserFriendlyException("下一节点不允许发起会签");
+                    throw UserFriendlyException.SameMessage("下一会签汇总节点不允许发起会签");
             }
 
             var flowAssignInfo =
@@ -323,8 +322,8 @@ namespace Hotline.FlowEngine.Workflows
             #region 办理当前节点
 
             if (dto.Files != null && dto.Files.Any())
-                currentStep.FileJson = await _fileRepository.AddFileAsync(dto.Files, workflow.ExternalId,
-                    currentStep.Id, cancellationToken);
+                currentStep.FileJson = await _fileRepository.AddFileAsync(
+                    dto.Files, workflow.ExternalId, currentStep.Id, cancellationToken);
 
             //(currentStep.IsInCountersign() && !dto.BackToCountersignEnd) || dto.IsStartCountersign;
             var isStartCountersign = currentStep.CountersignPosition switch
@@ -336,7 +335,7 @@ namespace Hotline.FlowEngine.Workflows
                 _ => throw new ArgumentOutOfRangeException()
             };
 
-            var counterSignType = GetCounterSignType(dto.IsStartCountersign);
+            var counterSignType = GetCounterSignType(dto.IsStartCountersign, currentStep.BusinessType);
 
             var updateSteps = new List<WorkflowStep> { currentStep };
 
@@ -584,7 +583,7 @@ namespace Hotline.FlowEngine.Workflows
             }
 
             var unhandlePreviousTrace = workflow.Traces.FirstOrDefault(d =>
-                    d.Status is not EWorkflowStepStatus.Handled
+                d.Status is not EWorkflowStepStatus.Handled
             );
 
             var unCompletedCountersign = workflow.Countersigns
@@ -667,7 +666,7 @@ namespace Hotline.FlowEngine.Workflows
                 _ => throw new ArgumentOutOfRangeException()
             };
 
-            var counterSignType = GetCounterSignType(dto.IsStartCountersign);
+            var counterSignType = GetCounterSignType(dto.IsStartCountersign, currentStep.BusinessType);
 
             var updateSteps = new List<WorkflowStep> { currentStep };
 
@@ -755,7 +754,8 @@ namespace Hotline.FlowEngine.Workflows
                         //throw new UserFriendlyException(
                         //    $"会签数据异常, workflowId: {currentStep.WorkflowId}, countersignId: {currentStep.CountersignId}",
                         //    "会签数据异常");
-                        countersign.MemberHandled(_sessionContextProvider.SessionContext.RequiredUserId, _sessionContextProvider.SessionContext.RequiredOrgId);
+                        countersign.MemberHandled(_sessionContextProvider.SessionContext.RequiredUserId,
+                            _sessionContextProvider.SessionContext.RequiredOrgId);
                         //update cs
                         await _workflowCountersignRepository.UpdateNav(countersign)
                             .Include(d => d.Members)
@@ -798,12 +798,14 @@ namespace Hotline.FlowEngine.Workflows
             if (workflow.ActualHandleStepId == currentStep.Id)
             {
                 //更新实际办理节点信息
-                workflow.UpdateActualStepWhenHandle(currentStep, _sessionContextProvider.SessionContext.OrgAreaCode, _sessionContextProvider.SessionContext.OrgAreaName, _sessionContextProvider.SessionContext.OrgLevel);
+                workflow.UpdateActualStepWhenHandle(currentStep, _sessionContextProvider.SessionContext.OrgAreaCode,
+                    _sessionContextProvider.SessionContext.OrgAreaName, _sessionContextProvider.SessionContext.OrgLevel);
             }
 
             if (workflow.CurrentStepId == currentStep.Id)
             {
-                workflow.UpdateCurrentStepWhenHandle(currentStep, _sessionContextProvider.SessionContext.OrgAreaCode, _sessionContextProvider.SessionContext.OrgAreaName, _sessionContextProvider.SessionContext.OrgLevel);
+                workflow.UpdateCurrentStepWhenHandle(currentStep, _sessionContextProvider.SessionContext.OrgAreaCode,
+                    _sessionContextProvider.SessionContext.OrgAreaName, _sessionContextProvider.SessionContext.OrgLevel);
             }
 
             //检查是否流转到流程终点
@@ -849,7 +851,8 @@ namespace Hotline.FlowEngine.Workflows
 
             //更新会签实际办理对象信息
             if (currentStep.IsActualHandled)
-                workflow.AddCsActualHandler(_sessionContextProvider.SessionContext.RequiredUserId, _sessionContextProvider.SessionContext.RequiredOrgId);
+                workflow.AddCsActualHandler(_sessionContextProvider.SessionContext.RequiredUserId,
+                    _sessionContextProvider.SessionContext.RequiredOrgId);
 
             await _workflowRepository.UpdateAsync(workflow, cancellationToken);
 
@@ -1145,7 +1148,8 @@ namespace Hotline.FlowEngine.Workflows
         /// 批量修改工单办理对象
         /// </summary>
         public async Task ChangeHandlerBatchAsync(
-            IReadOnlyList<(string userId, string username, string orgId, string orgName, string? roleId, string? roleName, ICollection<WorkflowStep> steps)> handlers,
+            IReadOnlyList<(string userId, string username, string orgId, string orgName, string? roleId, string? roleName, ICollection<WorkflowStep>
+                steps)> handlers,
             CancellationToken cancellationToken)
         {
             foreach (var handler in handlers)
@@ -1615,6 +1619,7 @@ namespace Hotline.FlowEngine.Workflows
                     cancellationToken);
                 isPaiDan = false;
             }
+
             return isPaiDan;
         }
 
@@ -1871,7 +1876,8 @@ namespace Hotline.FlowEngine.Workflows
             workflow.Complete(endStep, dto.ReviewResult);
 
             //需求调整:归档时当前节点显示为归档节点
-            workflow.UpdateCurrentStepWhenHandle(endStep, _sessionContextProvider.SessionContext.OrgAreaCode, _sessionContextProvider.SessionContext.OrgAreaName, _sessionContextProvider.SessionContext.OrgLevel);
+            workflow.UpdateCurrentStepWhenHandle(endStep, _sessionContextProvider.SessionContext.OrgAreaCode,
+                _sessionContextProvider.SessionContext.OrgAreaName, _sessionContextProvider.SessionContext.OrgLevel);
             workflow.UpdateCurrentStepAcceptTime(endStep.AcceptTime.Value);
 
             //workflow.UpdateActualStepWhenHandle(endStep, current.OrgAreaCode, current.OrgAreaName, current.OrgLevel);
@@ -1904,10 +1910,14 @@ namespace Hotline.FlowEngine.Workflows
         //        _ => throw new ArgumentOutOfRangeException(nameof(businessType), businessType, null)
         //    };
 
-        public ECounterSignType? GetCounterSignType(bool isStartCountersign)
+        public ECounterSignType? GetCounterSignType(bool isStartCountersign, EBusinessType currentStepBusinessType)
         {
             if (!isStartCountersign) return null;
-            return _sessionContextProvider.SessionContext.OrgIsCenter ? ECounterSignType.Center : ECounterSignType.Department;
+            return currentStepBusinessType is EBusinessType.Seat or EBusinessType.Send
+                ? ECounterSignType.Center
+                : ECounterSignType.Department;
+
+            // return _sessionContextProvider.SessionContext.OrgIsCenter ? ECounterSignType.Center : ECounterSignType.Department;
         }
 
         /// <summary>
@@ -1984,7 +1994,7 @@ namespace Hotline.FlowEngine.Workflows
                         new FlowStepHandler
                         {
                             Key = OrgSeedData.CenterId,
-                            Value = OrgSeedData.CenterName, 
+                            Value = OrgSeedData.CenterName,
                             OrgId = OrgSeedData.CenterId,
                             OrgName = OrgSeedData.CenterName
                         });