WorkflowStep.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using Hotline.Share.Dtos.FlowEngine;
  2. using Hotline.Share.Enums.FlowEngine;
  3. using SqlSugar;
  4. namespace Hotline.FlowEngine.Workflows;
  5. public class WorkflowStep : StepBasicEntity
  6. {
  7. [SugarColumn(ColumnDataType = "json", IsJson = true)]
  8. public List<NextStep> NextSteps { get; set; }
  9. /// <summary>
  10. /// 被指派办理对象(依据不同指派方式可能为:orgCode或userId),该字段subStep才会存在,stepBox不存在
  11. /// 采用list类型,兼容多个办理对象可以办理同一个节点的场景
  12. /// </summary>
  13. [SugarColumn(ColumnDataType = "json", IsJson = true)]
  14. public List<IdName> Handlers { get; set; } = new();
  15. /// <summary>
  16. /// 前一级节点Id(stepBox此字段为上级stepBoxId,step为上级stepId),汇总节点无此字段(因可能有多个上级来源)
  17. /// </summary>
  18. [SugarColumn(IsNullable = true)]
  19. public string? PreviousId { get; set; }
  20. /// <summary>
  21. /// 主办
  22. /// </summary>
  23. public bool IsMain { get; set; }
  24. public EWorkflowStepStatus Status { get; set; } = EWorkflowStepStatus.Assigned;
  25. /// <summary>
  26. /// stepBox此字段无效,记录stepBox与其下subSteps关系
  27. /// </summary>
  28. [SugarColumn(IsNullable = true)]
  29. public string? ParentId { get; set; }
  30. [SugarColumn(IsIgnore = true)]
  31. public List<WorkflowStep> Steps { get; set; } = new();
  32. #region 会签
  33. /// <summary>
  34. /// 发起会签生成会签Id(不发起会签节点无此字段)
  35. /// </summary>
  36. [SugarColumn(IsNullable = true)]
  37. public string? StartCountersignId { get; set; }
  38. /// <summary>
  39. /// 会签id
  40. /// </summary>
  41. [SugarColumn(IsNullable = true)]
  42. public string? CountersignId { get; set; }
  43. /// <summary>
  44. /// 当前节点发起的会签是否已结束,冗余(未发起会签的节点此字段为null)
  45. /// <remarks>
  46. /// 发起的会签结束以后更新,如果有子会签,则所有子会签都结束以后才会更新此字段
  47. /// </remarks>
  48. /// </summary>
  49. public bool? IsStartedCountersignComplete { get; set; }
  50. /// <summary>
  51. /// 节点会签状态
  52. /// </summary>
  53. public EStepCountersignStatus StepCountersignStatus { get; set; }
  54. /// <summary>
  55. /// 发起会签节点code(冗余)
  56. /// </summary>
  57. [SugarColumn(IsNullable = true)]
  58. public string? CountersignStartStepCode { get; set; }
  59. /// <summary>
  60. /// 会签汇总节点code(冗余)
  61. /// </summary>
  62. [SugarColumn(IsNullable = true)]
  63. public string? CountersignEndStepCode { get; set; }
  64. /// <summary>
  65. /// 是否处于会签流程中
  66. /// </summary>
  67. [SugarColumn(IsIgnore = true)]
  68. public bool IsInCountersign => !string.IsNullOrEmpty(CountersignId);
  69. /// <summary>
  70. /// 是否发起过会签
  71. /// </summary>
  72. [SugarColumn(IsIgnore = true)]
  73. public bool HasStartedCountersign => !string.IsNullOrEmpty(StartCountersignId);
  74. #endregion
  75. #region Method
  76. /// <summary>
  77. /// 接办
  78. /// </summary>
  79. /// <param name="userId"></param>
  80. /// <param name="userName"></param>
  81. public void Accept(string userId, string? userName, string orgCode, string? orgName)
  82. {
  83. AcceptUserId = userId;
  84. AcceptUserName = userName;
  85. AcceptTime = DateTime.Now;
  86. AcceptOrgCode = orgCode;
  87. AcceptOrgName = orgName;
  88. Status = EWorkflowStepStatus.Accepted;
  89. }
  90. /// <summary>
  91. /// 节点办理完成
  92. /// </summary>
  93. /// <param name="userId"></param>
  94. /// <param name="userName"></param>
  95. /// <param name="orgCode"></param>
  96. /// <param name="orgName"></param>
  97. public void Complete(string userId, string userName, string orgCode, string orgName, string nextStepCode)
  98. {
  99. UserId = userId;
  100. UserName = userName;
  101. OrgCode = orgCode;
  102. OrgName = orgName;
  103. CompleteTime = DateTime.Now;
  104. Status = EWorkflowStepStatus.Completed;
  105. if (StepType is not EStepType.End or EStepType.Start)
  106. NextSteps.First(d => d.Code == nextStepCode).Selected = true;
  107. }
  108. /// <summary>
  109. /// 检查stepBox状态,如果子节点全都办理,则stepBox办理完成
  110. /// </summary>
  111. public void CheckStepBoxStatusAndUpdate()
  112. {
  113. if (Status is not EWorkflowStepStatus.Completed && Steps.All(d => d.Status is EWorkflowStepStatus.Completed))
  114. {
  115. Status = EWorkflowStepStatus.Completed;
  116. CompleteTime = Steps.Max(d => d.CompleteTime);
  117. }
  118. }
  119. /// <summary>
  120. /// 会签结束
  121. /// </summary>
  122. public void CountersignComplete() => IsStartedCountersignComplete = true;
  123. /// <summary>
  124. /// 开启会签
  125. /// </summary>
  126. public void StartCountersign(string startCountersignId)
  127. {
  128. StartCountersignId = startCountersignId;
  129. IsStartedCountersignComplete = false;
  130. }
  131. /// <summary>
  132. /// step设置为可接办状态
  133. /// </summary>
  134. public void SetAssigned() => Status = EWorkflowStepStatus.Assigned;
  135. /// <summary>
  136. /// 依据当前节点获取下一节点会签状态
  137. /// </summary>
  138. /// <returns></returns>
  139. public EStepCountersignStatus GetNextStepCountersignStatus()
  140. {
  141. if (HasStartedCountersign)
  142. {
  143. return EStepCountersignStatus.InCountersign;
  144. }
  145. return IsInCountersign ? EStepCountersignStatus.OuterCountersign : EStepCountersignStatus.None;
  146. }
  147. /// <summary>
  148. /// 重置节点,只清除办理痕迹(退回场景,将上一级节点重置等待重新办理)
  149. /// </summary>
  150. public void Reset()
  151. {
  152. SetAssigned();
  153. NextHandlers = new();
  154. NextMainHandler = null;
  155. NextStepCode = string.Empty;
  156. AcceptSms = default;
  157. Opinion = string.Empty;
  158. Additions = new();
  159. UserId = null;
  160. UserName = null;
  161. OrgCode = null;
  162. OrgName = null;
  163. CompleteTime = null;
  164. AcceptUserId = null;
  165. AcceptUserName = null;
  166. AcceptOrgCode = null;
  167. AcceptOrgName = null;
  168. AcceptTime = null;
  169. }
  170. //过期:业务调整为由下级节点配置决定当前办理节点能否发起会签
  171. ///// <summary>
  172. ///// 检查该节点是否应该发起会签(办理时确认是否应该作为发起会签节点处理)
  173. ///// </summary>
  174. ///// <returns></returns>
  175. //public bool ShouldStartCountersign(int handlerCount)
  176. //{
  177. // if (StepType is EStepType.End) return false;
  178. // //需求:按角色指派默认不发起会签
  179. // if (HandlerType is EHandlerType.Role) return false;
  180. // return handlerCount > 1;
  181. //}
  182. #endregion
  183. }