FlowService.Get.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using Datory;
  5. using GxPress.Common.Tools;
  6. using GxPress.Entity;
  7. using GxPress.Entity.WorkFlowDto;
  8. using GxPress.Entity.WorkProcessDto;
  9. using GxPress.EnumConst;
  10. using GxPress.Result.App.Flow;
  11. namespace GxPress.Service.Implement
  12. {
  13. public partial class FlowService
  14. {
  15. public async Task<FlowDto> GetAsync(int flowId)
  16. {
  17. var flow = await _flowRepository.GetAsync(flowId);
  18. if (flow == null) return null;
  19. var fieldValues = await _flowFieldValueRepository.GetListAsync(flowId);
  20. var fields = new List<FlowField>();
  21. foreach (var flowFieldValue in fieldValues)
  22. {
  23. fields.Add(new FlowField
  24. {
  25. Id = flowFieldValue.FieldId,
  26. Type = flowFieldValue.FieldType,
  27. Value = GetFieldValue(flowFieldValue)
  28. });
  29. }
  30. var dto = new FlowDto
  31. {
  32. Id = flowId,
  33. ProcessId = flow.ProcessId,
  34. UserId = flow.UserId,
  35. State = flow.State,
  36. CreatedDate = flow.CreatedDate,
  37. Guid = flow.Guid,
  38. ProcessNodeId = flow.ProcessNodeId,
  39. Fields = fields
  40. };
  41. //获取审核和抄送人
  42. var flowToDos = await _flowTodoRepository.GetAllAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), flowId));
  43. if (flowToDos.Count() > 0)
  44. {
  45. dto.ApproverCheckUserIds = flowToDos.Where(n => n.Type == nameof(TodoTypeConst.ApproverCheck)).Select(n => n.UserId).ToList();
  46. dto.CarbonCopyUserIds = flowToDos.Where(n => n.Type == nameof(TodoTypeConst.CarbonCopy)).Select(n => n.UserId).ToList();
  47. }
  48. return dto;
  49. }
  50. public async Task<(string Title, List<string> Summaries)> GetFlowTitleAndSummaryAsync(User user, int processId, int flowId)
  51. {
  52. var process = await _processRepository.GetAsync(processId);
  53. if (process != null)
  54. {
  55. var fieldList = await _processFieldRepository.GetListAsync(processId);
  56. var valueList = await _flowFieldValueRepository.GetListAsync(flowId);
  57. var summaries = new List<string>();
  58. if (fieldList != null)
  59. {
  60. foreach (var processField in fieldList)
  61. {
  62. var value = valueList?.FirstOrDefault(v => v.FieldId == processField.Id);
  63. if (value != null)
  64. {
  65. summaries.Add($"{processField.Label}:{GetFieldValue(value)}");
  66. }
  67. }
  68. }
  69. return (GetFlowName(user, process), summaries);
  70. }
  71. return (GetFlowName(user, process), new List<string>());
  72. }
  73. public async Task<FlowResult> GetFlowResult(int todoId, int userId = 0)
  74. {
  75. var flowTodoModel = await _flowTodoRepository.GetAsync(todoId);
  76. var flowId = flowTodoModel.FlowId;
  77. var flowDto = await GetAsync(flowId);
  78. var user = await _userRepository.GetAsync(flowDto.UserId);
  79. var avatarUrl = await _userRepository.GetAvatarUrlAsync(flowDto.UserId);
  80. var process = await _processRepository.GetAsync(flowDto.ProcessId);
  81. if (process == null)
  82. throw new GxPress.Common.Exceptions.BusinessException("工作流不存在");
  83. var processFields = await _processFieldRepository.GetListAsync(flowDto.ProcessId);
  84. var valueList = await _flowFieldValueRepository.GetListAsync(flowId);
  85. var formFields = new List<FormField>();
  86. if (processFields != null)
  87. {
  88. foreach (var field in processFields)
  89. {
  90. var flowFieldValue = valueList.FirstOrDefault(x => x.FieldId == field.Id);
  91. formFields.Add(new FormField
  92. {
  93. Id = field.Id,
  94. Label = field.Label,
  95. Placeholder = field.Placeholder,
  96. Required = field.Required,
  97. Sort = field.Sort,
  98. Type = field.Type,
  99. Unit = field.Unit,
  100. Options = StringUtils.StringCollectionToStringList(field.Options),
  101. Value = GetFieldValue(flowFieldValue)
  102. });
  103. }
  104. }
  105. var nodes = new List<NodeResult>
  106. {
  107. new NodeResult
  108. {
  109. AvatarUrl = avatarUrl,
  110. Name = user.Name,
  111. Action = NodeStateConstUtils.GetText(NodeStateConst.Start),
  112. CreatedDate = flowDto.CreatedDate
  113. }
  114. };
  115. var todoList = await _flowTodoRepository.GetListByFlowIdAsync(flowId);
  116. var carbonCopies = new List<string>();
  117. foreach (var flowTodo in todoList)
  118. {
  119. if (flowTodo.Type == nameof(TodoTypeConst.ApproverCheck))
  120. {
  121. nodes.Add(new NodeResult
  122. {
  123. AvatarUrl = await _userRepository.GetAvatarUrlAsync(flowTodo.UserId),
  124. Name = await _userRepository.GetNameAsync(flowTodo.UserId),
  125. Action = GetTodoAction(flowTodo),
  126. CreatedDate = flowTodo.LastModifiedDate,
  127. Message = flowTodo.Message
  128. });
  129. }
  130. else if (flowTodo.Type == nameof(TodoTypeConst.CarbonCopy))
  131. {
  132. var nodeUserName = await _userRepository.GetNameAsync(flowTodo.UserId);
  133. carbonCopies.Add(nodeUserName);
  134. }
  135. }
  136. // var checkMessages = new List<MessageResult>();
  137. // var messages = await _flowMessageRepository.GetListByFlowIdAsync(flowId, nameof(TodoTypeConst.ApproverCheck));
  138. // foreach (var message in messages)
  139. // {
  140. // checkMessages.Add(new MessageResult
  141. // {
  142. // AvatarUrl = await _userRepository.GetAvatarUrlAsync(message.UserId),
  143. // Name = await _userRepository.GetNameAsync(message.UserId),
  144. // Message = message.Message,
  145. // CreatedDate = message.CreatedDate
  146. // });
  147. // }
  148. //获取系统配置抄送人和审核人
  149. var processNodeDtos = await GetNodesAsync(flowDto, await _processService.GetNodesAsync(flowDto.ProcessId, 0));
  150. //系统抄送人
  151. var carbonCopyUserIds = new List<int>();
  152. //系统审核人
  153. var approverCheckUserIds = new List<int>();
  154. foreach (var processNodeDto in processNodeDtos)
  155. {
  156. //抄送人
  157. if (processNodeDto.Type == nameof(ProcessNodeTypeConst.Start))
  158. {
  159. carbonCopyUserIds.AddRange(await GetListUserAsync(processNodeDto));
  160. }
  161. //插入审核人
  162. if (processNodeDto.Type == nameof(ProcessNodeTypeConst.Approver))
  163. {
  164. approverCheckUserIds.AddRange(await GetListUserAsync(processNodeDto));
  165. //break;
  166. }
  167. //抄送人
  168. if (processNodeDto.Type == nameof(ProcessNodeTypeConst.End))
  169. {
  170. carbonCopyUserIds.AddRange(await GetListUserAsync(processNodeDto));
  171. break;
  172. }
  173. }
  174. var flowResult = new FlowResult
  175. {
  176. ProcessId = process.Id,
  177. AvatarUrl = avatarUrl,
  178. UserName = user.Name,
  179. Name = GetFlowName(user, process),
  180. FlowState = flowDto.State,
  181. No = flowDto.No,
  182. DepartmentName = await _departmentRepository.GetNameAsync(user.DepartmentId),
  183. CreatedDate = flowDto.CreatedDate,
  184. FormFields = formFields,
  185. Nodes = nodes,
  186. CarbonCopies = string.Join(",", carbonCopies),
  187. UserId = flowDto.UserId
  188. // CheckMessages = checkMessages
  189. };
  190. //流程名称
  191. flowResult.ProcessName = process.Name;
  192. //抄送人
  193. flowResult.CarbonCopyUsers = await _userRepository.GeFlowUsers(carbonCopyUserIds, flowId, nameof(TodoTypeConst.CarbonCopy));
  194. //审核人
  195. flowResult.ApproverCheckUsers = await _userRepository.GeFlowUsers(approverCheckUserIds, flowId, nameof(TodoTypeConst.ApproverCheck));
  196. if (userId > 0)
  197. {
  198. //获取副流程
  199. var flowToDo = flowTodoModel;
  200. if (flowToDo != null)
  201. {
  202. if (flowToDo.IsDone && flowToDo.IsChecked)
  203. flowResult.State = FlowState.Checked;
  204. else if (flowToDo.IsDone && !flowToDo.IsChecked)
  205. {
  206. if (flowToDo.DoneType == 1)
  207. flowResult.State = FlowState.Meeting;
  208. else if (flowToDo.DoneType == 2)
  209. flowResult.State = FlowState.Wait;
  210. else
  211. flowResult.State = FlowState.Denied;
  212. }
  213. else if (flowToDo.IsDone && !flowToDo.IsChecked)
  214. flowResult.State = FlowState.Denied;
  215. else
  216. {
  217. flowResult.State = FlowState.Checking;
  218. }
  219. }
  220. else
  221. {
  222. flowResult.State = FlowState.Checked;
  223. }
  224. }
  225. //获取会议上传的文件流
  226. var flowAttachments = await flowAttachmentRepository.GetAllAsync(Q.Where(nameof(Entity.WorkFlow.FlowAttachment.TypeId), 1).Where(nameof(Entity.WorkFlow.FlowAttachment.FlowId), flowId).OrderByDesc(nameof(Entity.WorkFlow.FlowAttachment.CreatedDate)));
  227. flowResult.FlowAttachments = flowAttachments.ToList();
  228. return flowResult;
  229. }
  230. }
  231. }