FlowService.Actions2.Check.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. await _flowMessageRepository.InsertAsync(new FlowMessage
  34. {
  35. ProcessId = flow.ProcessId,
  36. FlowId = flow.Id,
  37. UserId = todo.UserId,
  38. Type = nameof(TodoTypeConst.ApproverCheck),
  39. Message = message
  40. });
  41. if (isChecked)
  42. {
  43. //修改状态
  44. if (todo.IsCaseOr && todo.ParentId > 0)
  45. {
  46. var flowDtos = await _flowTodoRepository.GetAllAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.ParentId), todo.ParentId).Where(nameof(Entity.WorkFlow.FlowTodo.IsCaseOr), true));
  47. foreach (var item in flowDtos)
  48. {
  49. item.IsOperate = false;
  50. item.IsDone = true;
  51. item.IsChecked = true;
  52. await _flowTodoRepository.UpdateAsync(item);
  53. }
  54. }
  55. //是否审核通过
  56. 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));
  57. var allCount = await _flowTodoRepository.CountAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), flow.Id).Where(nameof(Entity.WorkFlow.FlowTodo.Type), nameof(TodoTypeConst.ApproverCheck)));
  58. //判断是否最后一个通过
  59. if (checkedCount == allCount)
  60. {
  61. await _flowRepository.UpdateStateAsync(flow.Id, nameof(FlowState.Checked));
  62. //发送短信
  63. var user = await _userRepository.GetAsync(flow.UserId);
  64. //Common.Sms.AliySms.FolwStatusSendSms(user.Phone);
  65. Common.Sms.MasSms.SendSmsTemplate(new List<string>() { user.Phone }, "3c70cbdbcd1e45449b2830871387bdfe");
  66. }
  67. else
  68. {
  69. //修改可操作人
  70. 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)));
  71. if (flowTodo.IsCaseOr && flowTodo.ParentId > 0)
  72. {
  73. 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));
  74. foreach (var item in flowDtos)
  75. {
  76. item.IsOperate = true;
  77. await _flowTodoRepository.UpdateAsync(item);
  78. //发送短信
  79. var user = await _userRepository.GetAsync(item.UserId);
  80. // Common.Sms.AliySms.FolwCheckSendSms(user.Phone);
  81. Common.Sms.MasSms.SendSmsTemplate(new List<string>() { user.Phone }, "c9bdae1685514a9b821299720e2c5fe8");
  82. }
  83. }
  84. else
  85. {
  86. flowTodo.IsOperate = true;
  87. await _flowTodoRepository.UpdateAsync(flowTodo);
  88. //发送短信
  89. var user = await _userRepository.GetAsync(flowTodo.UserId);
  90. //Common.Sms.AliySms.FolwCheckSendSms(user.Phone);
  91. Common.Sms.MasSms.SendSmsTemplate(new List<string>() { user.Phone }, "c9bdae1685514a9b821299720e2c5fe8");
  92. }
  93. }
  94. }
  95. else
  96. {
  97. //修改工作流程状态
  98. await _flowRepository.UpdateStateAsync(flow.Id, nameof(FlowState.Denied));
  99. //发送短信
  100. var user = await _userRepository.GetAsync(flow.UserId);
  101. //Common.Sms.AliySms.FolwStatusSendSms(user.Phone);
  102. Common.Sms.MasSms.SendSmsTemplate(new List<string>() { user.Phone }, "c9bdae1685514a9b821299720e2c5fe8");
  103. }
  104. }
  105. public async Task<bool> RemindAsync(int flowId, int userId)
  106. {
  107. var flow = await GetFlowResult(flowId);
  108. var flowDto = await _flowRepository.GetAsync(flowId);
  109. var todo = await _flowTodoRepository.GetAsync(Q.Where(nameof(FlowTodo.FlowId), flowId).Where(nameof(FlowTodo.IsOperate), true));
  110. if (todo == null)
  111. return false;
  112. if (todo.IsRemind)
  113. return true;
  114. var user = await _userRepository.GetAsync(todo.UserId);
  115. //发送通知
  116. var request = new NoticeInRequest();
  117. request.Title = "工作流催办";
  118. request.UserId = flowDto.UserId;
  119. request.AddresseeUserMiddles = new List<Request.UserMiddle.UserMiddleInRequest>();
  120. request.AddresseeUserMiddles.Add(new Request.UserMiddle.UserMiddleInRequest { MiddleType = 10, SourceType = 0, SourceId = todo.UserId, SourceName = user.Name });
  121. request.NoticeType = NoticeTypeConst.Send;
  122. //构建数据
  123. var resultJson = new List<ContentJsonData>();
  124. // var contentJsonData = JsonConvert.DeserializeObject<List<ContentJsonData>>(result.Content);
  125. // foreach (var item in contentJsonData)
  126. // item.File = StringUtils.AddDomain(item.File);
  127. // result.Data = contentJsonData;
  128. //文字
  129. var resultJsonText = new ContentJsonData();
  130. resultJsonText.Title = "催办工作流程";
  131. resultJsonText.Type = 1;
  132. resultJson.Add(resultJsonText);
  133. //审批
  134. var resultJsonFlow = new ContentJsonData();
  135. resultJsonFlow.Type = 14;
  136. resultJsonFlow.Id = flowId;
  137. resultJsonFlow.Title = flow.Name;
  138. resultJson.Add(resultJsonFlow);
  139. request.Content = JsonConvert.SerializeObject(resultJson);
  140. var boolValue = await _noticeService.InsertAsync(request);
  141. todo.IsRemind = true;
  142. await _flowTodoRepository.UpdateAsync(todo);
  143. return false;
  144. }
  145. public async Task TransferCheckAsync(int todoId, List<int> transferUserIds, string message, List<int> fileIds)
  146. {
  147. var todo = await _flowTodoRepository.GetAsync(todoId);
  148. // await _flowTodoRepository.DeleteAsync(todo.Id);
  149. var flow = await GetAsync(todo.FlowId);
  150. await _flowMessageRepository.InsertAsync(new FlowMessage
  151. {
  152. ProcessId = flow.ProcessId,
  153. FlowId = flow.Id,
  154. UserId = todo.UserId,
  155. Type = nameof(TodoTypeConst.ApproverCheck),
  156. Message = message,
  157. FileIds = fileIds
  158. });
  159. //判断是否存在专审 存在就提示
  160. var flowTodo = await _flowTodoRepository.GetAllAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), todo.FlowId).Where(nameof(Entity.WorkFlow.FlowTodo.Type), nameof(TodoTypeConst.ApproverCheck)));
  161. if (flowTodo.Select(n => n.UserId).Any(n => transferUserIds.Contains(n)))
  162. {
  163. throw new Exception("转审人或者审核人已存在!");
  164. }
  165. if (transferUserIds.Count > 0)
  166. {
  167. //获取其他审核人
  168. var flowTodos = await _flowTodoRepository.GetAllAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), todo.FlowId).Where(nameof(Entity.WorkFlow.FlowTodo.Sort), ">", todo.Sort));
  169. foreach (var item in flowTodos)
  170. {
  171. item.Sort = item.Sort + transferUserIds.Count;
  172. await _flowTodoRepository.UpdateSortAsync(item);
  173. }
  174. }
  175. var sort = 1;
  176. foreach (var transferUserId in transferUserIds)
  177. {
  178. var flowTo = new Entity.WorkFlow.FlowTodo();
  179. flowTo.UserId = transferUserId;
  180. flowTo.IsChecked = false;
  181. flowTo.IsDone = false;
  182. flowTo.IsRead = false;
  183. flowTo.FlowId = flow.Id;
  184. flowTo.ProcessId = flow.ProcessId;
  185. flowTo.Type = nameof(TodoTypeConst.ApproverCheck);
  186. flowTo.IsOperate = sort == 1 ? true : false;
  187. flowTo.Sort = todo.Sort + sort;
  188. await _flowTodoRepository.InsertAsync(flowTo);
  189. sort++;
  190. }
  191. //修改当前用户状态
  192. todo.Message = message;
  193. todo.IsDone = true;
  194. todo.FileIds = fileIds;
  195. todo.IsChecked = true;
  196. todo.IsOperate = false;
  197. //已转审
  198. todo.IsReferral = true;
  199. await _flowTodoRepository.UpdateAsync(todo);
  200. }
  201. }
  202. }