WorkflowStep.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using Hotline.Share.Enums.FlowEngine;
  2. using SqlSugar;
  3. namespace Hotline.FlowEngine.Workflows;
  4. public class WorkflowStep : StepBasicEntity
  5. {
  6. [SugarColumn(ColumnDataType = "varchar(2000)", IsJson = true)]
  7. public List<NextStep> NextSteps { get; set; }
  8. /// <summary>
  9. /// 被指派办理对象(依据不同指派方式可能为:depCode或userId),该字段subStep才会存在,stepBox不存在
  10. /// 改为list,兼容多个办理对象可以办理同一个节点的场景
  11. /// </summary>
  12. [SugarColumn(ColumnDataType = "varchar(1000)", IsJson = true)]
  13. public List<string> HandlerIds { get; set; } = new();
  14. /// <summary>
  15. /// 前一级节点Id(stepBox此字段为上级stepBoxId,step为上级stepId),汇总节点无此字段(可能有多个上级来源)
  16. /// </summary>
  17. [SugarColumn(IsNullable = true)]
  18. public string? PreviousId { get; set; }
  19. /// <summary>
  20. /// 主办
  21. /// </summary>
  22. public bool IsMain { get; set; }
  23. public EWorkflowStepStatus Status { get; set; } = EWorkflowStepStatus.Assigned;
  24. /// <summary>
  25. /// stepBox此字段无效,记录stepBox与其下subSteps关系
  26. /// </summary>
  27. [SugarColumn(IsNullable = true)]
  28. public string? ParentId { get; set; }
  29. [SugarColumn(IsIgnore = true)]
  30. public List<WorkflowStep> Steps { get; set; } = new();
  31. #region 会签
  32. /// <summary>
  33. /// 发起会签生成会签Id(不发起会签节点无此字段)
  34. /// </summary>
  35. [SugarColumn(IsNullable = true)]
  36. public string? StartCountersignId { get; set; }
  37. /// <summary>
  38. /// 会签id
  39. /// </summary>
  40. [SugarColumn(IsNullable = true)]
  41. public string? CountersignId { get; set; }
  42. /// <summary>
  43. /// 当前节点发起的会签是否已结束,冗余(未发起会签的节点此字段为null)
  44. /// <remarks>
  45. /// 发起的会签结束以后更新,如果有子会签,则所有子会签都结束以后才会更新此字段
  46. /// </remarks>
  47. /// </summary>
  48. public bool? IsStartedCountersignComplete { get; set; }
  49. /// <summary>
  50. /// 节点会签状态
  51. /// </summary>
  52. public EStepCountersignStatus StepCountersignStatus { get; set; }
  53. /// <summary>
  54. /// 发起会签节点code,冗余(不支持发起会签节点无此字段)
  55. /// </summary>
  56. public string? CountersignStartCode { get; set; }
  57. /// <summary>
  58. /// 会签汇总节点code,冗余(不支持发起会签节点无此字段)
  59. /// </summary>
  60. public string? CountersignEndCode { get; set; }
  61. /// <summary>
  62. /// 是否处于会签流程中
  63. /// </summary>
  64. [SugarColumn(IsIgnore = true)]
  65. public bool IsInCountersign => !string.IsNullOrEmpty(CountersignId);
  66. /// <summary>
  67. /// 是否发起过会签
  68. /// </summary>
  69. [SugarColumn(IsIgnore = true)]
  70. public bool HasStartCountersign => !string.IsNullOrEmpty(StartCountersignId);
  71. #endregion
  72. #region Method
  73. /// <summary>
  74. /// 接办
  75. /// </summary>
  76. /// <param name="userId"></param>
  77. /// <param name="userName"></param>
  78. public void Accept(string userId, string userName, string orgCode, string orgName)
  79. {
  80. AcceptUserId = userId;
  81. AcceptUserName = userName;
  82. AcceptTime = DateTime.Now;
  83. AcceptOrgCode = orgCode;
  84. AcceptOrgName = orgName;
  85. Status = EWorkflowStepStatus.Accepted;
  86. }
  87. /// <summary>
  88. /// 节点办理完成
  89. /// </summary>
  90. /// <param name="userId"></param>
  91. /// <param name="userName"></param>
  92. /// <param name="orgCode"></param>
  93. /// <param name="orgName"></param>
  94. public void StepComplete(string userId, string userName, string orgCode, string orgName, string nextStepCode)
  95. {
  96. UserId = userId;
  97. UserName = userName;
  98. OrgCode = orgCode;
  99. OrgName = orgName;
  100. CompleteTime = DateTime.Now;
  101. Status = EWorkflowStepStatus.Completed;
  102. NextSteps.First(d => d.Code == nextStepCode).Selected = true;
  103. }
  104. /// <summary>
  105. /// 检查stepBox状态,如果子节点全都办理,则stepBox办理完成
  106. /// </summary>
  107. public void CheckStepBoxStatusAndUpdate()
  108. {
  109. if (Status is not EWorkflowStepStatus.Completed && Steps.All(d => d.Status is EWorkflowStepStatus.Completed))
  110. {
  111. Status = EWorkflowStepStatus.Completed;
  112. CompleteTime = Steps.Max(d => d.CompleteTime);
  113. }
  114. }
  115. /// <summary>
  116. /// 会签结束
  117. /// </summary>
  118. public void CountersignComplete() => IsStartedCountersignComplete = true;
  119. /// <summary>
  120. /// 开启会签
  121. /// </summary>
  122. public void StartCountersign(string startCountersignId)
  123. {
  124. StartCountersignId = startCountersignId;
  125. IsStartedCountersignComplete = false;
  126. }
  127. /// <summary>
  128. /// step设置为可接办状态
  129. /// </summary>
  130. public void SetAssigned() => Status = EWorkflowStepStatus.Assigned;
  131. /// <summary>
  132. /// 依据当前节点获取下一节点会签状态
  133. /// </summary>
  134. /// <returns></returns>
  135. public EStepCountersignStatus GetNextStepCountersignStatus()
  136. {
  137. if (HasStartCountersign)
  138. {
  139. return EStepCountersignStatus.InCountersign;
  140. }
  141. return IsInCountersign ? EStepCountersignStatus.OuterCountersign : EStepCountersignStatus.None;
  142. }
  143. #endregion
  144. }