IWorkflowDomainService.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. using Hotline.FlowEngine.Definitions;
  2. using Hotline.FlowEngine.WorkflowModules;
  3. using Hotline.Settings;
  4. using Hotline.Share.Dtos;
  5. using Hotline.Share.Dtos.File;
  6. using Hotline.Share.Dtos.FlowEngine;
  7. using Hotline.Share.Dtos.FlowEngine.Workflow;
  8. using Hotline.Share.Enums.FlowEngine;
  9. using Hotline.Share.Enums.Settings;
  10. using Hotline.Users;
  11. using XF.Domain.Authentications;
  12. using XF.Domain.Entities;
  13. namespace Hotline.FlowEngine.Workflows
  14. {
  15. public interface IWorkflowDomainService
  16. {
  17. /// <summary>
  18. /// 创建流程
  19. /// </summary>
  20. Task<Workflow> CreateWorkflowAsync(WorkflowModule wfModule, string title, string userId, string orgId,
  21. string? externalId = null, CancellationToken cancellationToken = default);
  22. // /// <summary>
  23. // /// 进行流程的开始节点
  24. // /// </summary>
  25. // Task StartAsync(Workflow workflow, WorkflowStep startStep, BasicWorkflowDto dto, StepDefine firstStepDefine,
  26. // bool isNextDynamic, FlowAssignInfo flowAssignInfo, ECounterSignType? counterSignType, DateTime? expiredTime,
  27. // CancellationToken cancellationToken);
  28. /// <summary>
  29. /// new
  30. /// </summary>
  31. Task<(Workflow, WorkflowStep)> StartAsync(StartWorkflowDto dto, string externalId, DateTime? expiredTime = null,
  32. Action<Workflow, StepDefine, WorkflowStep, WorkflowStep>? stepConfig = null,
  33. CancellationToken cancellationToken = default);
  34. /// <summary>
  35. /// new
  36. /// </summary>
  37. Task<List<WorkflowStep>> NextAsync(ISessionContext current, NextWorkflowDto dto,
  38. DateTime? expiredTime = null, bool isAutoFillSummaryOpinion = false,
  39. Action<Workflow, StepDefine, WorkflowStep, WorkflowStep>? stepConfig = null,
  40. CancellationToken cancellationToken = default);
  41. /// <summary>
  42. /// 查询工作流
  43. /// </summary>
  44. Task<Workflow> GetWorkflowAsync(string workflowId, bool withDefine = false, bool withSteps = false,
  45. bool withTraces = false, bool withTracesTree = false, bool withSupplements = false,
  46. bool withCountersigns = false, CancellationToken cancellationToken = default);
  47. /// <summary>
  48. /// 查询工作流包含当前用户办理权限(是否可办理)
  49. /// </summary>
  50. Task<(Workflow Workflow, string? CountersignId, bool CanHandle, bool CanPrevious, WorkflowTrace? Trace)> GetWorkflowHandlePermissionAsync(
  51. string workflowId, string userId, string orgId, string[] roleIds, CancellationToken cancellationToken = default);
  52. /// <summary>
  53. /// 受理,接办
  54. /// </summary>
  55. Task<DateTime?> AcceptAsync(Workflow workflow, string userId, string? userName, string orgId, string? orgName,
  56. string? orgAreaCode, string? orgAreaName, CancellationToken cancellationToken);
  57. ///// <summary>
  58. ///// 办理(流转至下一节点)
  59. ///// </summary>
  60. //Task NextAsync(Workflow workflow, WorkflowStep currentStep, NextWorkflowDto dto, StepDefine nextStepDefine,
  61. // bool isNextDynamic, FlowAssignInfo flowAssignInfo, DateTime? expiredTime, CancellationToken cancellationToken);
  62. // /// <summary>
  63. // /// 退回(返回前一节点)
  64. // /// </summary>
  65. // /// <returns></returns>
  66. // Task<EFlowDirection> PreviousAsync(Workflow workflow, PreviousWorkflowDto dto,
  67. // string applicantId, string applicantName,
  68. // string applicantOrgId, string applicantOrgName,
  69. // string applicantOrgAreaCode, string applicantOrgAreaName,
  70. // bool applicantIsCenter, string[] applicantRoleIds,
  71. // CancellationToken cancellationToken);
  72. /// <summary>
  73. /// 退回(new)
  74. /// </summary>
  75. Task<EFlowDirection> PreviousAsync(Workflow workflow, PreviousWorkflowDto dto, OperatorInfo operatorInfo,
  76. Action<Workflow, StepDefine, WorkflowStep, WorkflowStep>? stepConfig = null,
  77. CancellationToken cancellationToken = default);
  78. /// <summary>
  79. /// 撤回(返回到之前任意节点)
  80. /// </summary>
  81. Task<bool> RecallAsync(RecallDto dto, StepAssignInfo stepAssignInfo,
  82. EWorkflowTraceType traceType, DateTime? expiredTime, bool isOrderFiled, EHandleMode handleMode,
  83. Action<Workflow, StepDefine, WorkflowStep, WorkflowStep>? stepConfig = null,
  84. CancellationToken cancellationToken = default);
  85. Task<bool> RecallAsync(Workflow workflow, RecallDto dto, StepAssignInfo stepAssignInfo, StepDefine targetStepDefine,
  86. EWorkflowTraceType traceType, DateTime? expiredTime, bool isOrderFiled, EHandleMode handleMode,
  87. Action<Workflow, StepDefine, WorkflowStep, WorkflowStep>? stepConfig = null,
  88. CancellationToken cancellationToken = default);
  89. Task<bool> RecallAsync(Workflow workflow, RecallDto dto, StepAssignInfo stepAssignInfo,
  90. StepDefine targetStepDefine, WorkflowStep targetStep, EWorkflowTraceType traceType,
  91. DateTime? expiredTime, bool isOrderFiled, EHandleMode handleMode,
  92. Action<Workflow, StepDefine, WorkflowStep, WorkflowStep>? stepConfig = null,
  93. CancellationToken cancellationToken = default);
  94. Task<bool> RecallAsync(Workflow workflow, RecallDto dto, StepAssignInfo stepAssignInfo,
  95. WorkflowStep targetStep, EWorkflowTraceType traceType,
  96. DateTime? expiredTime, bool isOrderFiled, EHandleMode handleMode,
  97. Action<Workflow, StepDefine, WorkflowStep, WorkflowStep>? stepConfig = null,
  98. CancellationToken cancellationToken = default);
  99. /// <summary>
  100. /// 撤回至开始节点
  101. /// </summary>
  102. Task RecallToStartStepAsync(Workflow workflow, string opinion, ReverseFlowStepAssignInfo reverseFlowStepAssignInfo,
  103. DateTime? expiredTime, bool isOrderFiled, EHandleMode handleMode, CancellationToken cancellationToken);
  104. /// <summary>
  105. /// 特提至派单节点(无派单节点会抛异常)
  106. /// </summary>
  107. Task RecallToSendStepAsync(Workflow workflow, string opinion, ReverseFlowStepAssignInfo reverseFlowStepAssignInfo,
  108. DateTime? expiredTime, bool isOrderFiled, EHandleMode handleMode, CancellationToken cancellationToken);
  109. /// <summary>
  110. /// 特提至中心(优先派单组其次坐席)
  111. /// </summary>
  112. /// <returns></returns>
  113. Task<(bool, Workflow workflow)> RecallToCenterFirstToSendAsync(string workflowId, string opinion,
  114. ReverseFlowStepAssignInfo reverseFlowStepAssignInfo,
  115. bool isOrderFiled, DateTime? expiredTime, EHandleMode handleMode, CancellationToken cancellationToken);
  116. ///// <summary>
  117. ///// 跳转(直接将流程跳转至任意节点)
  118. ///// </summary>
  119. //Task JumpAsync(Workflow workflow, RecallDto dto, StepDefine targetStepDefine, FlowAssignInfo flowAssignInfo,
  120. // CancellationToken cancellationToken);
  121. ///// <summary>
  122. ///// 重办
  123. ///// </summary>
  124. //Task RedoAsync(Workflow workflow, RecallDto dto, StepDefine targetStepDefine, FlowAssignInfo flowAssignInfo,
  125. // CancellationToken cancellationToken);
  126. ///// <summary>
  127. ///// 否决(审批流程不通过)
  128. ///// </summary>
  129. ///// <returns></returns>
  130. //Task RejectAsync(Workflow workflow, BasicWorkflowDto dto, CancellationToken cancellationToken);
  131. /// <summary>
  132. /// 补充
  133. /// </summary>
  134. /// <returns></returns>
  135. Task SupplementAsync(Workflow workflow, EndWorkflowDto dto, CancellationToken cancellationToken);
  136. /// <summary>
  137. /// 终止流程
  138. /// </summary>
  139. Task TerminateAsync(TerminateDto dto, CancellationToken cancellationToken);
  140. /// <summary>
  141. /// 结束流程(流程直接流转至结束节点)
  142. /// </summary>
  143. Task<WorkflowTrace> EndAsync(ISessionContext current, Workflow workflow, BasicWorkflowDto dto, StepDefine endStepDefine,
  144. WorkflowStep currentStep, DateTime? expiredTime, CancellationToken cancellationToken);
  145. StepDefine GetStepDefine(WorkflowDefinition workflowDefinition, string stepCode);
  146. /// <summary>
  147. /// 查询当前待办理节点
  148. /// </summary>
  149. WorkflowStep FindCurrentStepWaitForHandle(Workflow workflow, string userId, string orgId, string[] roleIds);
  150. /// <summary>
  151. /// 查询当前节点中最后一个节点
  152. /// </summary>
  153. Task<WorkflowStep?> FindLastStepAsync(string workflowId, CancellationToken cancellationToken);
  154. /// <summary>
  155. /// 查询所有办理部门及实际办理部门
  156. /// </summary>
  157. Task<(Kv, IReadOnlyList<Kv>)> GetHandleOrgsAsync(string workflowId, CancellationToken cancellationToken);
  158. /// <summary>
  159. /// 新增流程流转记录
  160. /// </summary>
  161. Task AddStepsAsync(string workflowId, List<WorkflowStep> steps, CancellationToken cancellationToken);
  162. /// <summary>
  163. /// 创建开始节点
  164. /// </summary>
  165. WorkflowStep CreateStartStep(Workflow workflow, StepDefine startStepDefine, BasicWorkflowDto dto, UserInfo assigner,
  166. StepAssignInfo handler, DateTime? expiredTime, //EFlowAssignType? flowAssignType = EFlowAssignType.User,
  167. Action<Workflow, StepDefine, WorkflowStep, WorkflowStep>? stepConfig = null);
  168. /// <summary>
  169. /// 查询未完成节点
  170. /// </summary>
  171. /// <param name="steps"></param>
  172. /// <param name="orgId"></param>
  173. /// <param name="userId"></param>
  174. /// <returns></returns>
  175. WorkflowStep GetUnHandleStep(List<WorkflowStep> steps, string orgId, string userId, string[] roleIds);
  176. /// <summary>
  177. /// 检查当前办理节点是否为开始节点
  178. /// </summary>
  179. /// <param name="workflowId"></param>
  180. /// <param name="userId">当前办理人Id</param>
  181. /// <param name="orgId">当前办理人orgId</param>
  182. /// <param name="cancellationToken"></param>
  183. /// <returns></returns>
  184. Task<bool> CheckCurrentIsStartStepAsync(string workflowId, string userId, string orgId,
  185. CancellationToken cancellationToken);
  186. /// <summary>
  187. /// 检查动态节点是否该终止
  188. /// </summary>
  189. bool DynamicShouldTerminal(StepDefine currentStepDefine, int currentOrgLevel);
  190. /// <summary>
  191. /// 终止会签
  192. /// </summary>
  193. /// <param name="countersignId"></param>
  194. /// <param name="cancellationToken"></param>
  195. /// <returns></returns>
  196. Task<Workflow> TerminalCountersignAsync(string countersignId, DateTime expireTime, CancellationToken cancellationToken);
  197. Task<Workflow> TerminalCountersignAsync(WorkflowCountersign countersign, DateTime expireTime, CancellationToken cancellationToken);
  198. /// <summary>
  199. /// 办理节点
  200. /// </summary>
  201. Task HandleStepAsync(WorkflowStep step, Workflow workflow, BasicWorkflowDto dto,
  202. ECounterSignType? counterSignType, DateTime? expiredTime, EHandleMode handleMode,
  203. CancellationToken cancellationToken);
  204. /// <summary>
  205. /// 获取会签类型
  206. /// </summary>
  207. ECounterSignType? GetCounterSignType(bool isStartCountersign, EBusinessType currentStepBusinessType);
  208. /// <summary>
  209. /// 查询退回节点信息
  210. /// </summary>
  211. (WorkflowStep currentStep, WorkflowStep prevStep, WorkflowStep? countersignStartStep) GetPreviousStep(
  212. Workflow workflow, string operaterId, string operaterOrgId, string[] roleIds);
  213. /// <summary>
  214. /// 查询派单池中流程节点id
  215. /// </summary>
  216. Task<IReadOnlyList<string>> GetUnhandleStepIdsFromSendPoolAsync(string sendPoolId, CancellationToken cancellationToken);
  217. /// <summary>
  218. /// 查询归属某用户的所有流程节点
  219. /// </summary>
  220. Task<List<WorkflowStep>> GetStepsBelongsToAsync(string userId, CancellationToken cancellationToken);
  221. /// <summary>
  222. /// 开启流程直接归档
  223. /// </summary>
  224. Task StartToEndAsync(StartWorkflowDto dto, string externalId, DateTime? expiredTime = null,
  225. CancellationToken cancellationToken = default);
  226. /// <summary>
  227. /// 批量修改工单办理对象
  228. /// </summary>
  229. Task ChangeHandlerBatchAsync(
  230. IReadOnlyList<(string userId, string username, string orgId, string orgName, string? roleId, string? roleName, ICollection<WorkflowStep>
  231. steps)> handlers,
  232. CancellationToken cancellationToken);
  233. /// <summary>
  234. /// 查询工单办理中的一级部门
  235. /// </summary>
  236. Task<ICollection<Kv>> GetLevelOneOrgsAsync(string workflowId, CancellationToken cancellation);
  237. /// <summary>
  238. /// 更新未办理节点的期满时间
  239. /// </summary>
  240. Task UpdateUnhandleExpiredTimeAsync(string workflowId, DateTime expiredTime, CancellationToken cancellation);
  241. /// <summary>
  242. /// 查询该部门最后办理节点
  243. /// </summary>
  244. /// <returns></returns>
  245. Task<WorkflowStep> FindLastHandleStepAsync(string workflowId, string orgId, CancellationToken cancellation);
  246. /// <summary>
  247. /// 部门会签工单获取流程最顶级办理节点
  248. /// </summary>
  249. /// <returns></returns>
  250. Task<WorkflowStep> FindTopHandleStepAsync(string workflowId, CancellationToken cancellation);
  251. /// <summary>
  252. /// 查询流转方向
  253. /// </summary>
  254. EFlowDirection GetFlowDirection(EBusinessType sourceStepBusinessType, EBusinessType directionStepBusinessType);
  255. /// <summary>
  256. /// 流程被签收至某个用户(更新流转对象,办理对象,节点办理对象以及stepHandlers)
  257. /// </summary>
  258. Task<Workflow> SignToSomebodyAsync(string workflowId, string userId, string username, string orgId, string orgName,
  259. CancellationToken cancellationToken);
  260. /// <summary>
  261. /// 非节点办理人员查询待办节点
  262. /// </summary>
  263. /// <returns></returns>
  264. Task<ICollection<WorkflowStep>> GetUnhandleStepsByOthersAsync(string workflowId, CancellationToken cancellationToken);
  265. /// <summary>
  266. /// 根据汇总对象id找到被汇总节点,生成指派到用户的办理对象
  267. /// </summary>
  268. FlowStepHandler GetSummaryTargetFlowStepHandler(Workflow workflow, string summaryTargetStepCode);
  269. /// <summary>
  270. /// 追加归档信息(接收ds推送12315归档信息)
  271. /// </summary>
  272. Task AppendFileOpinionAsync(string workflowId, string opinion, List<FileDto> files, CancellationToken cancellationToken);
  273. /// <summary>
  274. /// 跳转至结束节点(无视流程模板配置以及当前办理对象,直接跳至结束节点)
  275. /// </summary>
  276. Task JumpToEndAsync(ISessionContext current, string workflowId, string opinion, List<FileDto> files, DateTime? expiredTime,
  277. EReviewResult reviewResult = EReviewResult.Unknown, CancellationToken cancellationToken = default);
  278. Task JumpToEndAsync(ISessionContext current, Workflow workflow, string opinion, List<FileDto> files, DateTime? expiredTime,
  279. EReviewResult reviewResult = EReviewResult.Unknown, CancellationToken cancellationToken = default);
  280. /// <summary>
  281. /// 查找会签循环的初始会签发起节点
  282. /// </summary>
  283. WorkflowStep GetCsLoopStartStep(List<WorkflowStep> steps, WorkflowStep currentStep);
  284. Task HandlePublishTraceAsync(string workflowId, string orderPublishId, UserInfo acceptor, UserInfo handler, DateTime handleTime,
  285. UserInfo visitAcceptor, string orderVisitId, CancellationToken cancellation);
  286. Task HandleVisitTraceAsync(string orderVisitId, UserInfo visitor, DateTime visitTime, CancellationToken cancellation);
  287. Task<FlowAssignInfo> GetNextStepFlowAssignInfoByDefineAsync(StepDefine nextStepDefine,
  288. EHandlerType handlerType, bool isStartCountersign, List<Kv> handlers, CancellationToken cancellationToken);
  289. }
  290. }