FlowService.Actions2.Check.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. //拼接
  25. var query = Q.NewQuery();
  26. var todo = await _flowTodoRepository.GetAsync(todoId);
  27. todo.IsChecked = isChecked;
  28. todo.Message = message;
  29. todo.IsDone = true;
  30. //是否当前操作
  31. todo.IsOperate = false;
  32. todo.DoneType = 0;
  33. var updated = await _flowTodoRepository.UpdateAsync(todo);
  34. var flow = await GetAsync(todo.FlowId);
  35. await _flowMessageRepository.InsertAsync(new FlowMessage
  36. {
  37. ProcessId = flow.ProcessId,
  38. FlowId = flow.Id,
  39. UserId = todo.UserId,
  40. Type = nameof(TodoTypeConst.ApproverCheck),
  41. Message = message
  42. });
  43. if (isChecked)
  44. {
  45. //修改状态
  46. if (todo.IsCaseOr && todo.ParentId > 0)
  47. {
  48. query = Q.NewQuery();
  49. query.Where(nameof(Entity.WorkFlow.FlowTodo.ParentId), todo.ParentId);
  50. query.Where(nameof(Entity.WorkFlow.FlowTodo.IsCaseOr), true);
  51. query.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), todo.FlowId);
  52. var flowDtos = await _flowTodoRepository.GetAllAsync(query);
  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. var checkedCount = await _flowTodoRepository.CheckedCountAsync(flow.Id);
  63. var allCount = await _flowTodoRepository.AllCountAsync(flow.Id);
  64. //判断是否最后一个通过
  65. if (checkedCount == allCount)
  66. {
  67. await _flowRepository.UpdateStateAsync(flow.Id, nameof(FlowState.Checked));
  68. //发送短信
  69. var user = await _userRepository.GetAsync(flow.UserId);
  70. //Common.Sms.AliySms.FolwStatusSendSms(user.Phone);
  71. // Common.Sms.MasSms.SendSmsTemplate(new List<string>() { user.Phone }, "3c70cbdbcd1e45449b2830871387bdfe");
  72. await smsService.SendSmsTemplate(new List<string>() { user.Phone }, "3c70cbdbcd1e45449b2830871387bdfe", flow.Id, AllTypeConst.Flow.GetHashCode());
  73. }
  74. else
  75. {
  76. //修改可操作人
  77. var flowTodo = await _flowTodoRepository.GetUCheckedAsync(todo.FlowId);
  78. //或签
  79. if (flowTodo.IsCaseOr && flowTodo.ParentId > 0)
  80. {
  81. query = Q.NewQuery();
  82. query.Where(nameof(Entity.WorkFlow.FlowTodo.ParentId), flowTodo.ParentId);
  83. query.Where(nameof(Entity.WorkFlow.FlowTodo.IsCaseOr), flowTodo.IsCaseOr);
  84. query.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), flowTodo.FlowId);
  85. var flowDtos = await _flowTodoRepository.GetAllAsync(query);
  86. foreach (var item in flowDtos)
  87. {
  88. item.IsOperate = true;
  89. await _flowTodoRepository.UpdateAsync(item);
  90. //发送短信
  91. var user = await _userRepository.GetAsync(item.UserId);
  92. // Common.Sms.AliySms.FolwCheckSendSms(user.Phone);
  93. //Common.Sms.MasSms.SendSmsTemplate(new List<string>() { user.Phone }, "c9bdae1685514a9b821299720e2c5fe8");
  94. await smsService.SendSmsTemplate(new List<string>() { user.Phone }, "c9bdae1685514a9b821299720e2c5fe8", flow.Id, AllTypeConst.Flow.GetHashCode());
  95. }
  96. }
  97. //会签
  98. else if (!flowTodo.IsCaseOr && flowTodo.ParentId > 0)
  99. {
  100. if (flowTodo.IsOperate == false)
  101. {
  102. query = Q.NewQuery();
  103. query.Where(nameof(Entity.WorkFlow.FlowTodo.ParentId), flowTodo.ParentId);
  104. query.Where(nameof(Entity.WorkFlow.FlowTodo.IsCaseOr), flowTodo.IsCaseOr);
  105. query.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), flowTodo.FlowId);
  106. var flowDtos = await _flowTodoRepository.GetAllAsync(query);
  107. foreach (var item in flowDtos)
  108. {
  109. item.IsOperate = true;
  110. await _flowTodoRepository.UpdateAsync(item);
  111. //发送短信
  112. var user = await _userRepository.GetAsync(item.UserId);
  113. // Common.Sms.AliySms.FolwCheckSendSms(user.Phone);
  114. //Common.Sms.MasSms.SendSmsTemplate(new List<string>() { user.Phone }, "c9bdae1685514a9b821299720e2c5fe8");
  115. await smsService.SendSmsTemplate(new List<string>() { user.Phone }, "c9bdae1685514a9b821299720e2c5fe8", flow.Id, AllTypeConst.Flow.GetHashCode());
  116. }
  117. }
  118. }
  119. else
  120. {
  121. flowTodo.IsOperate = true;
  122. await _flowTodoRepository.UpdateAsync(flowTodo);
  123. //发送短信
  124. var user = await _userRepository.GetAsync(flowTodo.UserId);
  125. //Common.Sms.AliySms.FolwCheckSendSms(user.Phone);
  126. //Common.Sms.MasSms.SendSmsTemplate(new List<string>() { user.Phone }, "c9bdae1685514a9b821299720e2c5fe8");
  127. await smsService.SendSmsTemplate(new List<string>() { user.Phone }, "c9bdae1685514a9b821299720e2c5fe8", flow.Id, AllTypeConst.Flow.GetHashCode());
  128. }
  129. }
  130. }
  131. else
  132. {
  133. //修改工作流程状态
  134. await _flowRepository.UpdateStateAsync(flow.Id, nameof(FlowState.Denied));
  135. //发送短信
  136. var user = await _userRepository.GetAsync(flow.UserId);
  137. //Common.Sms.AliySms.FolwStatusSendSms(user.Phone);
  138. //Common.Sms.MasSms.SendSmsTemplate(new List<string>() { user.Phone }, "c9bdae1685514a9b821299720e2c5fe8");
  139. await smsService.SendSmsTemplate(new List<string>() { user.Phone }, "c9bdae1685514a9b821299720e2c5fe8", flow.Id, AllTypeConst.Flow.GetHashCode());
  140. }
  141. }
  142. public async Task<bool> RemindAsync(int flowId, int userId)
  143. {
  144. var flow = await GetFlowResult(flowId);
  145. var flowDto = await _flowRepository.GetAsync(flowId);
  146. var todo = await _flowTodoRepository.GetAsync(Q.Where(nameof(FlowTodo.FlowId), flowId).Where(nameof(FlowTodo.IsOperate), true));
  147. if (todo == null)
  148. return false;
  149. if (todo.IsRemind)
  150. return true;
  151. var user = await _userRepository.GetAsync(todo.UserId);
  152. //发送通知
  153. var request = new NoticeInRequest();
  154. request.Title = "工作流催办";
  155. request.UserId = flowDto.UserId;
  156. request.AddresseeUserMiddles = new List<Request.UserMiddle.UserMiddleInRequest>();
  157. request.AddresseeUserMiddles.Add(new Request.UserMiddle.UserMiddleInRequest { MiddleType = 10, SourceType = 0, SourceId = todo.UserId, SourceName = user.Name });
  158. request.NoticeType = NoticeTypeConst.Send;
  159. //构建数据
  160. var resultJson = new List<ContentJsonData>();
  161. // var contentJsonData = JsonConvert.DeserializeObject<List<ContentJsonData>>(result.Content);
  162. // foreach (var item in contentJsonData)
  163. // item.File = StringUtils.AddDomain(item.File);
  164. // result.Data = contentJsonData;
  165. //文字
  166. var resultJsonText = new ContentJsonData();
  167. resultJsonText.Title = "催办工作流程";
  168. resultJsonText.Type = 1;
  169. resultJson.Add(resultJsonText);
  170. //审批
  171. var resultJsonFlow = new ContentJsonData();
  172. resultJsonFlow.Type = 14;
  173. resultJsonFlow.Id = flowId;
  174. resultJsonFlow.Title = flow.Name;
  175. resultJson.Add(resultJsonFlow);
  176. request.Content = JsonConvert.SerializeObject(resultJson);
  177. var boolValue = await _noticeService.InsertAsync(request);
  178. todo.IsRemind = true;
  179. await _flowTodoRepository.UpdateAsync(todo);
  180. return false;
  181. }
  182. public async Task TransferCheckAsync(int todoId, List<int> transferUserIds, string message, List<int> fileIds)
  183. {
  184. var todo = await _flowTodoRepository.GetAsync(todoId);
  185. // await _flowTodoRepository.DeleteAsync(todo.Id);
  186. var flow = await GetAsync(todo.FlowId);
  187. await _flowMessageRepository.InsertAsync(new FlowMessage
  188. {
  189. ProcessId = flow.ProcessId,
  190. FlowId = flow.Id,
  191. UserId = todo.UserId,
  192. Type = nameof(TodoTypeConst.ApproverCheck),
  193. Message = message,
  194. FileIds = fileIds
  195. });
  196. //修改或签状态
  197. if (todo.IsCaseOr && todo.ParentId > 0)
  198. {
  199. var query = Q.NewQuery();
  200. query.Where(nameof(Entity.WorkFlow.FlowTodo.ParentId), todo.ParentId);
  201. query.Where(nameof(Entity.WorkFlow.FlowTodo.IsCaseOr), true);
  202. query.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), todo.FlowId);
  203. var flowDtos = await _flowTodoRepository.GetAllAsync(query);
  204. foreach (var item in flowDtos)
  205. {
  206. item.IsOperate = item.UserId == todo.UserId ? true : false;
  207. item.IsDone = true;
  208. item.IsChecked = true;
  209. await _flowTodoRepository.UpdateAsync(item);
  210. }
  211. }
  212. //判断是否存在专审 存在就提示
  213. // var flowTodo = await _flowTodoRepository.GetAllAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), todo.FlowId).Where(nameof(Entity.WorkFlow.FlowTodo.Type), nameof(TodoTypeConst.ApproverCheck)));
  214. // if (flowTodo.Select(n => n.UserId).Any(n => transferUserIds.Contains(n)))
  215. // {
  216. // throw new Exception("转审人或者审核人已存在!");
  217. // }
  218. if (transferUserIds.Count > 0)
  219. {
  220. //获取其他审核人
  221. var flowTodos = await _flowTodoRepository.GetAllAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), todo.FlowId).Where(nameof(Entity.WorkFlow.FlowTodo.Sort), ">", todo.Sort));
  222. foreach (var item in flowTodos)
  223. {
  224. item.Sort = item.Sort + transferUserIds.Count;
  225. await _flowTodoRepository.UpdateSortAsync(item);
  226. }
  227. }
  228. var sort = 1;
  229. foreach (var transferUserId in transferUserIds)
  230. {
  231. var flowTo = new Entity.WorkFlow.FlowTodo();
  232. flowTo.UserId = transferUserId;
  233. flowTo.IsChecked = false;
  234. flowTo.IsDone = false;
  235. flowTo.IsRead = false;
  236. flowTo.FlowId = flow.Id;
  237. flowTo.ProcessId = flow.ProcessId;
  238. flowTo.Type = nameof(TodoTypeConst.ApproverCheck);
  239. flowTo.IsOperate = sort == 1 ? true : false;
  240. flowTo.Sort = todo.Sort + sort;
  241. await _flowTodoRepository.InsertAsync(flowTo);
  242. sort++;
  243. if (flowTo.IsOperate)
  244. {
  245. //发送短信
  246. var user = await _userRepository.GetAsync(transferUserId);
  247. await smsService.SendSmsTemplate(new List<string>() { user.Phone }, "c9bdae1685514a9b821299720e2c5fe8", flow.Id, AllTypeConst.Flow.GetHashCode());
  248. }
  249. }
  250. //修改当前用户状态
  251. todo.Message = message;
  252. todo.IsDone = true;
  253. todo.FileIds = fileIds;
  254. todo.IsChecked = true;
  255. todo.IsOperate = false;
  256. //已转审
  257. todo.IsReferral = true;
  258. await _flowTodoRepository.UpdateAsync(todo);
  259. }
  260. }
  261. }