FlowService.Actions2.Check.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. SendUserId = user.Id,
  89. SendUserName = user.Name
  90. });
  91. }
  92. }
  93. else
  94. {
  95. flowTodo.IsOperate = true;
  96. await _flowTodoRepository.UpdateAsync(flowTodo);
  97. await _noticeService.AddNoticeFlowAsync(new NoticeInRequest
  98. {
  99. NoticeType = NoticeTypeConst.Send,
  100. Title = $"{user.Name}的{process.Name}流程",
  101. UserId = flow.UserId,
  102. SoureId = flow.Id,
  103. SonId = flowTodo.Id,
  104. TypeValue = AllTypeConst.MyChecked.GetHashCode(),
  105. SendUserId = user.Id,
  106. SendUserName = user.Name
  107. });
  108. }
  109. }
  110. // ProcessNodeDto nextApproverNode = null;
  111. // foreach (var processNodeDto in nodes)
  112. // {
  113. // if (processNodeDto.Id == flow.ProcessNodeId)
  114. // {
  115. // // 当前节点如果是会签需要判断是否为当前节点的最后一个审核人
  116. // if (processNodeDto.Type == nameof(ProcessNodeTypeConst.Approver) &&
  117. // processNodeDto.ApprovalType == nameof(ApprovalTypeConst.And) &&
  118. // processNodeDto.ApproverChecks != null)
  119. // {
  120. // var checkedUserIdList = await _flowTodoRepository.GetAllCheckedUserIdListAsync(flow.Id);
  121. // var allUserIdList = await GetUserIdListAsync(processNodeDto.ApproverChecks);
  122. // if (checkedUserIdList.Count() != allUserIdList.Count)
  123. // {
  124. // return;
  125. // }
  126. // }
  127. // }
  128. // //判断是否进入下一阶段
  129. // if (isCheck && processNodeDto.Id > flow.ProcessNodeId && processNodeDto.Type == nameof(ProcessNodeTypeConst.Approver))
  130. // {
  131. // nextApproverNode = processNodeDto;
  132. // //设置节点
  133. // await _flowRepository.UpdateProcessNodeIdAsync(flow.Id, processNodeDto.Id);
  134. // break;
  135. // }
  136. // }
  137. // if (nextApproverNode == null)
  138. // {
  139. // if (isCheck)
  140. // {
  141. // //修改状态
  142. // await _flowRepository.UpdateStateAsync(flow.Id, nameof(FlowState.Checked));
  143. // }
  144. // //await _flowTodoRepository.DeleteCheckingByFlowIdAsync(flow.Id);
  145. // //await NodeExecuteAsync(flow, nodes.Last());
  146. // }
  147. // else
  148. // {
  149. // //修改状态
  150. // await _flowRepository.UpdateStateAsync(flow.Id, nameof(FlowState.Checking));
  151. // await NodeExecuteAsync(flow, nextApproverNode);
  152. // }
  153. }
  154. else
  155. {
  156. //删除多余的审核人
  157. // await _flowTodoRepository.DeleteCheckingByFlowIdAsync(flow.Id);
  158. //修改工作流程状态
  159. await _flowRepository.UpdateStateAsync(flow.Id, nameof(FlowState.Denied));
  160. //await NodeExecuteAsync(flow, nodes.Last());
  161. }
  162. }
  163. public async Task<bool> RemindAsync(int flowId, int userId)
  164. {
  165. var flow = await GetFlowResult(flowId);
  166. var flowDto = await _flowRepository.GetAsync(flowId);
  167. var todo = await _flowTodoRepository.GetAsync(Q.Where(nameof(FlowTodo.FlowId), flowId).Where(nameof(FlowTodo.IsOperate), true));
  168. if (todo == null)
  169. return false;
  170. if (todo.IsRemind)
  171. return true;
  172. var user = await _userRepository.GetAsync(todo.UserId);
  173. //发送通知
  174. var request = new NoticeInRequest();
  175. request.Title = "工作流催办";
  176. request.UserId = flowDto.UserId;
  177. request.AddresseeUserMiddles = new List<Request.UserMiddle.UserMiddleInRequest>();
  178. request.AddresseeUserMiddles.Add(new Request.UserMiddle.UserMiddleInRequest { MiddleType = 10, SourceType = 0, SourceId = todo.UserId, SourceName = user.Name });
  179. request.NoticeType = NoticeTypeConst.Send;
  180. //构建数据
  181. var resultJson = new List<ContentJsonData>();
  182. // var contentJsonData = JsonConvert.DeserializeObject<List<ContentJsonData>>(result.Content);
  183. // foreach (var item in contentJsonData)
  184. // item.File = StringUtils.AddDomain(item.File);
  185. // result.Data = contentJsonData;
  186. //文字
  187. var resultJsonText = new ContentJsonData();
  188. resultJsonText.Title = "催办工作流程";
  189. resultJsonText.Type = 1;
  190. resultJson.Add(resultJsonText);
  191. //审批
  192. var resultJsonFlow = new ContentJsonData();
  193. resultJsonFlow.Type = 14;
  194. resultJsonFlow.Id = flowId;
  195. resultJsonFlow.Title = flow.Name;
  196. resultJson.Add(resultJsonFlow);
  197. request.Content = JsonConvert.SerializeObject(resultJson);
  198. var boolValue = await _noticeService.InsertAsync(request);
  199. todo.IsRemind = true;
  200. await _flowTodoRepository.UpdateAsync(todo);
  201. return false;
  202. }
  203. public async Task TransferCheckAsync(int todoId, List<int> transferUserIds, string message, List<int> fileIds)
  204. {
  205. var todo = await _flowTodoRepository.GetAsync(todoId);
  206. // await _flowTodoRepository.DeleteAsync(todo.Id);
  207. var flow = await GetAsync(todo.FlowId);
  208. //获取用户
  209. var user = await _userRepository.GetAsync(flow.UserId);
  210. //获取
  211. var process = await _processRepository.GetAsync(flow.ProcessId);
  212. await _flowMessageRepository.InsertAsync(new FlowMessage
  213. {
  214. ProcessId = flow.ProcessId,
  215. FlowId = flow.Id,
  216. UserId = todo.UserId,
  217. Type = nameof(TodoTypeConst.ApproverCheck),
  218. Message = message,
  219. FileIds = fileIds
  220. });
  221. //判断是否存在专审 存在就提示
  222. var flowTodo = await _flowTodoRepository.GetAllAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), todo.FlowId).Where(nameof(Entity.WorkFlow.FlowTodo.Type), nameof(TodoTypeConst.ApproverCheck)));
  223. if (flowTodo.Select(n => n.UserId).Any(n => transferUserIds.Contains(n)))
  224. {
  225. throw new Exception("转审人或者审核人已存在!");
  226. }
  227. if (transferUserIds.Count > 0)
  228. {
  229. //获取其他审核人
  230. var flowTodos = await _flowTodoRepository.GetAllAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), todo.FlowId).Where(nameof(Entity.WorkFlow.FlowTodo.Sort), ">", todo.Sort));
  231. foreach (var item in flowTodos)
  232. {
  233. item.Sort = item.Sort + transferUserIds.Count;
  234. await _flowTodoRepository.UpdateSortAsync(item);
  235. }
  236. }
  237. var sort = 1;
  238. foreach (var transferUserId in transferUserIds)
  239. {
  240. var flowTo = new Entity.WorkFlow.FlowTodo();
  241. flowTo.UserId = transferUserId;
  242. flowTo.IsChecked = false;
  243. flowTo.IsDone = false;
  244. flowTo.IsRead = false;
  245. flowTo.FlowId = flow.Id;
  246. flowTo.ProcessId = flow.ProcessId;
  247. flowTo.Type = nameof(TodoTypeConst.ApproverCheck);
  248. flowTo.IsOperate = sort == 1 ? true : false;
  249. flowTo.Sort = todo.Sort + sort;
  250. var flowToId = await _flowTodoRepository.InsertAsync(flowTo);
  251. sort++;
  252. //专审收件箱
  253. if (flowTo.IsOperate)
  254. await _noticeService.AddNoticeFlowAsync(new NoticeInRequest
  255. {
  256. NoticeType = NoticeTypeConst.Send,
  257. Title = $"{user.Name}的{process.Name}流程",
  258. UserId = flow.UserId,
  259. SoureId = flow.Id,
  260. SonId = flowToId,
  261. TypeValue = AllTypeConst.MyChecked.GetHashCode(),
  262. SendUserId = user.Id,
  263. SendUserName = user.Name
  264. });
  265. }
  266. //修改当前用户状态
  267. todo.Message = message;
  268. todo.IsDone = true;
  269. todo.FileIds = fileIds;
  270. todo.IsChecked = true;
  271. todo.IsOperate = false;
  272. //已转审
  273. todo.IsReferral = true;
  274. await _flowTodoRepository.UpdateAsync(todo);
  275. }
  276. }
  277. }