FlowService.Actions2.Check.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Datory;
  6. using GxPress.Entity.WorkFlow;
  7. using GxPress.EnumConst;
  8. using GxPress.Request.Notice;
  9. using GxPress.Result;
  10. using Newtonsoft.Json;
  11. namespace GxPress.Service.Implement
  12. {
  13. public partial class FlowService
  14. {
  15. /// <summary>
  16. /// 审核
  17. /// </summary>
  18. /// <param name="todoId"></param>
  19. /// <param name="isChecked"></param>
  20. /// <param name="message"></param>
  21. /// <returns></returns>
  22. public async Task CheckAsync(int todoId, bool isChecked, string message)
  23. {
  24. var todo = await _flowTodoRepository.GetAsync(todoId);
  25. todo.IsChecked = isChecked;
  26. todo.Message = message;
  27. todo.IsDone = true;
  28. //是否当前操作
  29. todo.IsOperate = false;
  30. todo.DoneType = 0;
  31. var updated = await _flowTodoRepository.UpdateAsync(todo);
  32. var flow = await GetAsync(todo.FlowId);
  33. //获取用户
  34. var user = await _userRepository.GetAsync(flow.UserId);
  35. //获取
  36. var process = await _processRepository.GetAsync(flow.ProcessId);
  37. await _flowMessageRepository.InsertAsync(new FlowMessage
  38. {
  39. ProcessId = flow.ProcessId,
  40. FlowId = flow.Id,
  41. UserId = todo.UserId,
  42. Type = nameof(TodoTypeConst.ApproverCheck),
  43. Message = message
  44. });
  45. //var nodes = await GetNodesAsync(flow, await _processService.GetNodesAsync(flow.ProcessId, 0));
  46. // var isCheck = false;
  47. if (isChecked)
  48. {
  49. //修改状态
  50. if (todo.IsCaseOr && todo.ParentId > 0)
  51. {
  52. var flowDtos = await _flowTodoRepository.GetAllAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.ParentId), todo.ParentId).Where(nameof(Entity.WorkFlow.FlowTodo.IsCaseOr), true));
  53. foreach (var item in flowDtos)
  54. {
  55. item.IsOperate = false;
  56. item.IsDone = true;
  57. item.IsChecked = true;
  58. await _flowTodoRepository.UpdateAsync(item);
  59. }
  60. }
  61. // //修改状态
  62. // // await _flowRepository.UpdateStateAsync(flow.Id, nameof(FlowState.Checked));
  63. // //是否审核通过
  64. var checkedCount = await _flowTodoRepository.CountAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), flow.Id).Where(nameof(Entity.WorkFlow.FlowTodo.IsDone), true).Where(nameof(Entity.WorkFlow.FlowTodo.Type), nameof(TodoTypeConst.ApproverCheck)).Where(nameof(Entity.WorkFlow.FlowTodo.IsChecked), true));
  65. var allCount = await _flowTodoRepository.CountAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), flow.Id).Where(nameof(Entity.WorkFlow.FlowTodo.Type), nameof(TodoTypeConst.ApproverCheck)));
  66. //判断是否最后一个通过
  67. if (checkedCount == allCount)
  68. await _flowRepository.UpdateStateAsync(flow.Id, nameof(FlowState.Checked));
  69. else
  70. {
  71. //修改可操作人
  72. var flowTodo = await _flowTodoRepository.GetAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.IsChecked), false).Where(nameof(Entity.WorkFlow.FlowTodo.IsDone), false).Where(nameof(Entity.WorkFlow.FlowTodo.Type), nameof(TodoTypeConst.ApproverCheck)).Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), todo.FlowId).OrderBy(nameof(Entity.WorkFlow.FlowTodo.Sort)));
  73. if (flowTodo.IsCaseOr && flowTodo.ParentId > 0)
  74. {
  75. var flowDtos = await _flowTodoRepository.GetAllAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.ParentId), flowTodo.ParentId).Where(nameof(Entity.WorkFlow.FlowTodo.IsCaseOr), true).Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), flowTodo.FlowId));
  76. foreach (var item in flowDtos)
  77. {
  78. item.IsOperate = true;
  79. await _flowTodoRepository.UpdateAsync(item);
  80. await _noticeService.AddNoticeFlowAsync(new NoticeInRequest
  81. {
  82. NoticeType = NoticeTypeConst.Send,
  83. Title = $"{user.Name}的{process.Name}",
  84. UserId = flow.UserId,
  85. SoureId = flow.Id,
  86. SonId = item.Id,
  87. TypeValue = AllTypeConst.MyChecked.GetHashCode()
  88. });
  89. }
  90. }
  91. else
  92. {
  93. flowTodo.IsOperate = true;
  94. await _flowTodoRepository.UpdateAsync(flowTodo);
  95. await _noticeService.AddNoticeFlowAsync(new NoticeInRequest
  96. {
  97. NoticeType = NoticeTypeConst.Send,
  98. Title = $"{user.Name}的{process.Name}",
  99. UserId = flow.UserId,
  100. SoureId = flow.Id,
  101. SonId = flowTodo.Id,
  102. TypeValue = AllTypeConst.MyChecked.GetHashCode()
  103. });
  104. }
  105. }
  106. // ProcessNodeDto nextApproverNode = null;
  107. // foreach (var processNodeDto in nodes)
  108. // {
  109. // if (processNodeDto.Id == flow.ProcessNodeId)
  110. // {
  111. // // 当前节点如果是会签需要判断是否为当前节点的最后一个审核人
  112. // if (processNodeDto.Type == nameof(ProcessNodeTypeConst.Approver) &&
  113. // processNodeDto.ApprovalType == nameof(ApprovalTypeConst.And) &&
  114. // processNodeDto.ApproverChecks != null)
  115. // {
  116. // var checkedUserIdList = await _flowTodoRepository.GetAllCheckedUserIdListAsync(flow.Id);
  117. // var allUserIdList = await GetUserIdListAsync(processNodeDto.ApproverChecks);
  118. // if (checkedUserIdList.Count() != allUserIdList.Count)
  119. // {
  120. // return;
  121. // }
  122. // }
  123. // }
  124. // //判断是否进入下一阶段
  125. // if (isCheck && processNodeDto.Id > flow.ProcessNodeId && processNodeDto.Type == nameof(ProcessNodeTypeConst.Approver))
  126. // {
  127. // nextApproverNode = processNodeDto;
  128. // //设置节点
  129. // await _flowRepository.UpdateProcessNodeIdAsync(flow.Id, processNodeDto.Id);
  130. // break;
  131. // }
  132. // }
  133. // if (nextApproverNode == null)
  134. // {
  135. // if (isCheck)
  136. // {
  137. // //修改状态
  138. // await _flowRepository.UpdateStateAsync(flow.Id, nameof(FlowState.Checked));
  139. // }
  140. // //await _flowTodoRepository.DeleteCheckingByFlowIdAsync(flow.Id);
  141. // //await NodeExecuteAsync(flow, nodes.Last());
  142. // }
  143. // else
  144. // {
  145. // //修改状态
  146. // await _flowRepository.UpdateStateAsync(flow.Id, nameof(FlowState.Checking));
  147. // await NodeExecuteAsync(flow, nextApproverNode);
  148. // }
  149. }
  150. else
  151. {
  152. //删除多余的审核人
  153. // await _flowTodoRepository.DeleteCheckingByFlowIdAsync(flow.Id);
  154. //修改工作流程状态
  155. await _flowRepository.UpdateStateAsync(flow.Id, nameof(FlowState.Denied));
  156. //await NodeExecuteAsync(flow, nodes.Last());
  157. }
  158. }
  159. public async Task<bool> RemindAsync(int flowId, int userId)
  160. {
  161. var flow = await GetFlowResult(flowId);
  162. var flowDto = await _flowRepository.GetAsync(flowId);
  163. var todo = await _flowTodoRepository.GetAsync(Q.Where(nameof(FlowTodo.FlowId), flowId).Where(nameof(FlowTodo.IsOperate), true));
  164. if (todo == null)
  165. return false;
  166. if (todo.IsRemind)
  167. return true;
  168. var user = await _userRepository.GetAsync(todo.UserId);
  169. //发送通知
  170. var request = new NoticeInRequest();
  171. request.Title = "工作流催办";
  172. request.UserId = flowDto.UserId;
  173. request.AddresseeUserMiddles = new List<Request.UserMiddle.UserMiddleInRequest>();
  174. request.AddresseeUserMiddles.Add(new Request.UserMiddle.UserMiddleInRequest { MiddleType = 10, SourceType = 0, SourceId = todo.UserId, SourceName = user.Name });
  175. request.NoticeType = NoticeTypeConst.Send;
  176. //构建数据
  177. var resultJson = new List<ContentJsonData>();
  178. // var contentJsonData = JsonConvert.DeserializeObject<List<ContentJsonData>>(result.Content);
  179. // foreach (var item in contentJsonData)
  180. // item.File = StringUtils.AddDomain(item.File);
  181. // result.Data = contentJsonData;
  182. //文字
  183. var resultJsonText = new ContentJsonData();
  184. resultJsonText.Title = "催办工作流程";
  185. resultJsonText.Type = 1;
  186. resultJson.Add(resultJsonText);
  187. //审批
  188. var resultJsonFlow = new ContentJsonData();
  189. resultJsonFlow.Type = 14;
  190. resultJsonFlow.Id = flowId;
  191. resultJsonFlow.Title = flow.Name;
  192. resultJson.Add(resultJsonFlow);
  193. request.Content = JsonConvert.SerializeObject(resultJson);
  194. var boolValue = await _noticeService.InsertAsync(request);
  195. todo.IsRemind = true;
  196. await _flowTodoRepository.UpdateAsync(todo);
  197. return false;
  198. }
  199. public async Task TransferCheckAsync(int todoId, List<int> transferUserIds, string message, List<int> fileIds)
  200. {
  201. var todo = await _flowTodoRepository.GetAsync(todoId);
  202. // await _flowTodoRepository.DeleteAsync(todo.Id);
  203. var flow = await GetAsync(todo.FlowId);
  204. await _flowMessageRepository.InsertAsync(new FlowMessage
  205. {
  206. ProcessId = flow.ProcessId,
  207. FlowId = flow.Id,
  208. UserId = todo.UserId,
  209. Type = nameof(TodoTypeConst.ApproverCheck),
  210. Message = message,
  211. FileIds = fileIds
  212. });
  213. //判断是否存在专审 存在就提示
  214. var flowTodo = await _flowTodoRepository.GetAllAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), todo.FlowId).Where(nameof(Entity.WorkFlow.FlowTodo.Type), nameof(TodoTypeConst.ApproverCheck)));
  215. if (flowTodo.Select(n => n.UserId).Any(n => transferUserIds.Contains(n)))
  216. {
  217. throw new Exception("转审人或者审核人已存在!");
  218. }
  219. if (transferUserIds.Count > 0)
  220. {
  221. //获取其他审核人
  222. var flowTodos = await _flowTodoRepository.GetAllAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), todo.FlowId).Where(nameof(Entity.WorkFlow.FlowTodo.Sort), ">", todo.Sort));
  223. foreach (var item in flowTodos)
  224. {
  225. item.Sort = item.Sort + transferUserIds.Count;
  226. await _flowTodoRepository.UpdateSortAsync(item);
  227. }
  228. }
  229. var sort = 1;
  230. foreach (var transferUserId in transferUserIds)
  231. {
  232. var flowTo = new Entity.WorkFlow.FlowTodo();
  233. flowTo.UserId = transferUserId;
  234. flowTo.IsChecked = false;
  235. flowTo.IsDone = false;
  236. flowTo.IsRead = false;
  237. flowTo.FlowId = flow.Id;
  238. flowTo.ProcessId = flow.ProcessId;
  239. flowTo.Type = nameof(TodoTypeConst.ApproverCheck);
  240. flowTo.IsOperate = sort == 1 ? true : false;
  241. flowTo.Sort = todo.Sort + sort;
  242. await _flowTodoRepository.InsertAsync(flowTo);
  243. sort++;
  244. }
  245. //修改当前用户状态
  246. todo.Message = message;
  247. todo.IsDone = true;
  248. todo.FileIds = fileIds;
  249. todo.IsChecked = true;
  250. todo.IsOperate = false;
  251. //已转审
  252. todo.IsReferral = true;
  253. await _flowTodoRepository.UpdateAsync(todo);
  254. }
  255. }
  256. }