IWorkflowDomainService.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. ///// <returns></returns>
  154. //Task RejectAsync(Workflow workflow, BasicWorkflowDto dto, CancellationToken cancellationToken);
  155. Task RejectAsync(RejectDto dto, CancellationToken cancellationToken);
  156. /// <summary>
  157. /// 补充
  158. /// </summary>
  159. /// <returns></returns>
  160. Task SupplementAsync(Workflow workflow, EndWorkflowDto dto, CancellationToken cancellationToken);
  161. /// <summary>
  162. /// 终止流程
  163. /// </summary>
  164. Task TerminateAsync(TerminateDto dto, CancellationToken cancellationToken);
  165. /// <summary>
  166. /// 结束流程(流程直接流转至结束节点)
  167. /// </summary>
  168. Task<(WorkflowStep, WorkflowTrace)> EndAsync(ISessionContext current, Workflow workflow, BasicWorkflowDto dto, StepDefine endStepDefine,
  169. WorkflowStep currentStep, DateTime? expiredTime, CancellationToken cancellationToken);
  170. StepDefine GetStepDefine(WorkflowDefinition workflowDefinition, string stepCode);
  171. /// <summary>
  172. /// 查询当前待办理节点
  173. /// </summary>
  174. WorkflowStep FindCurrentStepWaitForHandle(Workflow workflow, string userId, string orgId, string[] roleIds);
  175. /// <summary>
  176. /// 查询当前节点中最后一个节点
  177. /// </summary>
  178. Task<WorkflowStep?> FindLastStepAsync(string workflowId, CancellationToken cancellationToken);
  179. /// <summary>
  180. /// 查询所有办理部门及实际办理部门
  181. /// </summary>
  182. Task<(Kv, IReadOnlyList<Kv>)> GetHandleOrgsAsync(string workflowId, CancellationToken cancellationToken);
  183. /// <summary>
  184. /// 新增流程流转记录
  185. /// </summary>
  186. Task AddStepsAsync(string workflowId, List<WorkflowStep> steps, CancellationToken cancellationToken);
  187. /// <summary>
  188. /// 创建开始节点
  189. /// </summary>
  190. WorkflowStep CreateStartStep(Workflow workflow, StepDefine startStepDefine, BasicWorkflowDto dto, UserInfo assigner,
  191. StepAssignInfo handler, DateTime? expiredTime, //EFlowAssignType? flowAssignType = EFlowAssignType.User,
  192. Action<Workflow, WorkflowStep, StepDefine, WorkflowStep>? newStepConfig = null);
  193. /// <summary>
  194. /// 查询未完成节点
  195. /// </summary>
  196. /// <param name="steps"></param>
  197. /// <param name="orgId"></param>
  198. /// <param name="userId"></param>
  199. /// <returns></returns>
  200. WorkflowStep GetUnHandleStep(List<WorkflowStep> steps, string orgId, string userId, string[] roleIds);
  201. /// <summary>
  202. /// 检查当前办理节点是否为开始节点
  203. /// </summary>
  204. /// <param name="workflowId"></param>
  205. /// <param name="userId">当前办理人Id</param>
  206. /// <param name="orgId">当前办理人orgId</param>
  207. /// <param name="cancellationToken"></param>
  208. /// <returns></returns>
  209. Task<bool> CheckCurrentIsStartStepAsync(string workflowId, string userId, string orgId,
  210. CancellationToken cancellationToken);
  211. /// <summary>
  212. /// 检查动态节点是否该终止
  213. /// </summary>
  214. bool DynamicShouldTerminal(StepDefine currentStepDefine, int currentOrgLevel);
  215. /// <summary>
  216. /// 终止会签
  217. /// </summary>
  218. /// <param name="countersignId"></param>
  219. /// <param name="cancellationToken"></param>
  220. /// <returns></returns>
  221. Task<Workflow> TerminalCountersignAsync(string countersignId, DateTime expireTime, CancellationToken cancellationToken);
  222. Task<Workflow> TerminalCountersignAsync(WorkflowCountersign countersign, DateTime expireTime, CancellationToken cancellationToken);
  223. /// <summary>
  224. /// 办理节点
  225. /// </summary>
  226. Task HandleStepAsync(WorkflowStep step, Workflow workflow, BasicWorkflowDto dto,
  227. ECounterSignType? counterSignType, DateTime? expiredTime, EHandleMode handleMode,
  228. CancellationToken cancellationToken);
  229. /// <summary>
  230. /// 获取会签类型
  231. /// </summary>
  232. ECounterSignType? GetCounterSignType(bool isStartCountersign, EBusinessType currentStepBusinessType);
  233. /// <summary>
  234. /// 查询退回节点信息
  235. /// </summary>
  236. (WorkflowStep currentStep, WorkflowStep prevStep, WorkflowStep? countersignStartStep) GetPreviousStep(
  237. Workflow workflow, string operaterId, string operaterOrgId, string[] roleIds);
  238. /// <summary>
  239. /// 查询派单池中流程节点id
  240. /// </summary>
  241. Task<IReadOnlyList<string>> GetUnhandleStepIdsFromSendPoolAsync(string sendPoolId, CancellationToken cancellationToken);
  242. /// <summary>
  243. /// 查询归属某用户的所有流程节点
  244. /// </summary>
  245. Task<List<WorkflowStep>> GetStepsBelongsToAsync(string userId, CancellationToken cancellationToken);
  246. /// <summary>
  247. /// 查询归属多个用户的所有流程节点 当天
  248. /// </summary>
  249. /// <returns></returns>
  250. Task<List<WorkflowStep>> GetStepsBelongsDayToAsync(List<string> userIds, DateTime time, CancellationToken cancellationToken);
  251. /// <summary>
  252. /// 批量修改工单办理对象
  253. /// </summary>
  254. Task ChangeHandlerBatchAsync(
  255. IReadOnlyList<(string userId, string username, string orgId, string orgName, string? roleId, string? roleName, ICollection<WorkflowStep>
  256. steps)> handlers,
  257. CancellationToken cancellationToken);
  258. /// <summary>
  259. /// 查询工单办理中的一级部门
  260. /// </summary>
  261. Task<ICollection<Kv>> GetLevelOneOrgsAsync(string workflowId, CancellationToken cancellation);
  262. /// <summary>
  263. /// 更新未办理节点的期满时间
  264. /// </summary>
  265. Task UpdateUnhandleExpiredTimeAsync(string workflowId, DateTime? expiredTime, CancellationToken cancellation);
  266. /// <summary>
  267. /// 查询该部门最后办理节点
  268. /// </summary>
  269. /// <returns></returns>
  270. Task<WorkflowStep> FindLastHandleStepAsync(string workflowId, string orgId, CancellationToken cancellation);
  271. /// <summary>
  272. /// 部门会签工单获取流程最顶级办理节点
  273. /// </summary>
  274. /// <returns></returns>
  275. Task<WorkflowStep> FindTopHandleStepAsync(string workflowId, CancellationToken cancellation);
  276. /// <summary>
  277. /// 查询流转方向
  278. /// </summary>
  279. EFlowDirection GetFlowDirection(EBusinessType sourceStepBusinessType, EBusinessType directionStepBusinessType);
  280. /// <summary>
  281. /// 流程被签收至某个用户(更新流转对象,办理对象,节点办理对象以及stepHandlers)
  282. /// </summary>
  283. Task<Workflow> SignToSomebodyAsync(string workflowId, string userId, string username, string orgId, string orgName,
  284. CancellationToken cancellationToken);
  285. /// <summary>
  286. /// 非节点办理人员查询待办节点
  287. /// </summary>
  288. /// <returns></returns>
  289. Task<ICollection<WorkflowStep>> GetUnhandleStepsByOthersAsync(string workflowId, CancellationToken cancellationToken);
  290. /// <summary>
  291. /// 根据汇总对象id找到被汇总节点,生成指派到用户的办理对象
  292. /// </summary>
  293. StepAssignInfo GetSummaryTargetFlowStepHandler(Workflow workflow, string summaryTargetStepCode);
  294. /// <summary>
  295. /// 追加归档信息(接收ds推送12315归档信息)
  296. /// </summary>
  297. Task AppendFileOpinionAsync(string workflowId, string opinion, List<FileDto> files, CancellationToken cancellationToken);
  298. /// <summary>
  299. /// 跳转至结束节点(无视流程模板配置以及当前办理对象,直接跳至结束节点)
  300. /// </summary>
  301. Task JumpToEndAsync(ISessionContext current, string workflowId, string opinion, List<FileDto> files, DateTime? expiredTime,
  302. EReviewResult reviewResult = EReviewResult.Unknown, CancellationToken cancellationToken = default);
  303. Task JumpToEndAsync(ISessionContext current, Workflow workflow, string opinion, List<FileDto> files, DateTime? expiredTime,
  304. EReviewResult reviewResult = EReviewResult.Unknown, CancellationToken cancellationToken = default);
  305. /// <summary>
  306. /// 查找会签循环的初始会签发起节点
  307. /// </summary>
  308. WorkflowStep GetCsLoopStartStep(List<WorkflowStep> steps, WorkflowStep currentStep);
  309. Task HandlePublishTraceAsync(string workflowId, string orderPublishId, UserInfo acceptor, UserInfo handler, DateTime handleTime,
  310. UserInfo visitAcceptor, string orderVisitId, CancellationToken cancellation);
  311. Task HandleVisitTraceAsync(string orderVisitId, UserInfo visitor, DateTime visitTime, CancellationToken cancellation);
  312. Task<FlowAssignInfo> GetNextStepFlowAssignInfoByDefineAsync(StepDefine nextStepDefine,
  313. EHandlerType handlerType, bool isStartCountersign, List<Kv> handlers, CancellationToken cancellationToken);
  314. }
  315. }