IWorkflowDomainService.cs 18 KB

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