FlowService.List.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using GxPress.Entity.WorkFlow;
  5. using GxPress.EnumConst;
  6. using GxPress.Request.App.Flow;
  7. using GxPress.Result.App.Flow;
  8. namespace GxPress.Service.Implement
  9. {
  10. public partial class FlowService
  11. {
  12. public async Task<ListResult> ListAllAsync(int page, int perPage, int processId, string state, string startDate, string endDate)
  13. {
  14. var flowList = await _flowRepository.GetListAllAsync(page, perPage, processId, state, startDate, endDate);
  15. var items = await GetFlowListResultListAsync(flowList);
  16. return new ListResult
  17. {
  18. Count = await _flowRepository.GetCountAsync(processId, state, startDate, endDate),
  19. Items = items
  20. };
  21. }
  22. public async Task<ListResult> ListMyCheckingAsync(int userId, FlowListRequest request, string source = "")
  23. {
  24. var todoIdFlowIdList = await _flowTodoRepository.GetTodoIdFlowIdListAsync(userId, nameof(TodoTypeConst.ApproverCheck), false, request);
  25. var items = new List<FlowListResult>();
  26. foreach (var todoIdFlowId in todoIdFlowIdList)
  27. {
  28. var flow = await _flowRepository.GetAsync(todoIdFlowId.FlowId);
  29. if (flow != null)
  30. {
  31. items.Add(await GetFlowListResultAsync(flow, todoIdFlowId.TodoId, source));
  32. }
  33. }
  34. //var flowList = await _flowRepository.GetListByIdListAsync(flowIdList, request.Page, request.PerPage);
  35. //var items = await GetFlowListResultListAsync(flowList);
  36. return new ListResult
  37. {
  38. Count = await _flowTodoRepository.GetCountAsync(userId, nameof(TodoTypeConst.ApproverCheck), false,
  39. request),
  40. Items = items
  41. };
  42. }
  43. public async Task<ListResult> ListMyCheckedAsync(int userId, FlowListRequest request, string source = "")
  44. {
  45. var todoIdFlowIdList = await _flowTodoRepository.GetTodoIdFlowIdListAsync(userId, nameof(TodoTypeConst.ApproverCheck), true, request);
  46. var items = new List<FlowListResult>();
  47. foreach (var todoIdFlowId in todoIdFlowIdList)
  48. {
  49. var flow = await _flowRepository.GetAsync(todoIdFlowId.FlowId);
  50. if (flow != null)
  51. {
  52. items.Add(await GetFlowListResultAsync(flow, todoIdFlowId.TodoId, source));
  53. }
  54. }
  55. return new ListResult
  56. {
  57. Count = await _flowTodoRepository.GetCountAsync(userId, nameof(TodoTypeConst.ApproverCheck), true, request),
  58. Items = items
  59. };
  60. }
  61. public async Task<ListResult> ListSubmittedCheckingAsync(int userId, FlowListRequest request, string source = "")
  62. {
  63. var flowList = await _flowRepository.GetListByUserIdAsync(userId, true, request);
  64. var items = await GetFlowListResultListAsync(flowList, source);
  65. return new ListResult
  66. {
  67. Count = await _flowRepository.GetCountByUserIdAsync(userId, true, request),
  68. //Count = items.Count(),
  69. Items = items
  70. };
  71. }
  72. public async Task<ListResult> ListSubmittedCheckedAsync(int userId, FlowListRequest request)
  73. {
  74. var flowList = await _flowRepository.GetListByUserIdAsync(userId, false, request);
  75. var items = await GetFlowListResultListAsync(flowList);
  76. return new ListResult
  77. {
  78. Count = await _flowRepository.GetCountByUserIdAsync(userId, false, request),
  79. Items = items
  80. };
  81. }
  82. public async Task<ListResult> ListCcUnreadAsync(int userId, FlowListRequest request)
  83. {
  84. var todoIdFlowIdList = await _flowTodoRepository.GetTodoIdFlowIdListAsync(userId, nameof(TodoTypeConst.CarbonCopy), request,false);
  85. var items = new List<FlowListResult>();
  86. foreach (var todoIdFlowId in todoIdFlowIdList)
  87. {
  88. var flow = await _flowRepository.GetAsync(todoIdFlowId.FlowId);
  89. if (flow != null)
  90. {
  91. items.Add(await GetFlowListResultAsync(flow, todoIdFlowId.TodoId));
  92. }
  93. }
  94. return new ListResult
  95. {
  96. Count = await _flowTodoRepository.GetReadCountAsync(userId, nameof(TodoTypeConst.CarbonCopy), request,false),
  97. Items = items
  98. };
  99. }
  100. public async Task<ListResult> ListCcAllAsync(int userId, FlowListRequest request, string source = "")
  101. {
  102. var todoIdFlowIdList = await _flowTodoRepository.GetTodoIdFlowIdListAsync(userId, nameof(TodoTypeConst.CarbonCopy), request,true);
  103. var items = new List<FlowListResult>();
  104. foreach (var todoIdFlowId in todoIdFlowIdList)
  105. {
  106. var flow = await _flowRepository.GetAsync(todoIdFlowId.FlowId);
  107. if (flow != null)
  108. {
  109. items.Add(await GetFlowListResultAsync(flow, todoIdFlowId.TodoId, source));
  110. }
  111. }
  112. return new ListResult
  113. {
  114. Count = await _flowTodoRepository.GetReadCountAsync(userId, nameof(TodoTypeConst.CarbonCopy), request,true),
  115. Items = items
  116. };
  117. }
  118. private async Task<IEnumerable<FlowListResult>> GetFlowListResultListAsync(IEnumerable<Entity.WorkFlow.Flow> flowList, string source = "")
  119. {
  120. var resultList = flowList.Select(async x =>
  121. {
  122. var user = await _userRepository.GetAsync(x.UserId);
  123. var result = new FlowListResult
  124. {
  125. Id = x.Id,
  126. ProcessId = x.ProcessId,
  127. UserId = x.UserId,
  128. State = x.State,
  129. ProcessNodeId = x.ProcessNodeId,
  130. CreatedDate = x.CreatedDate,
  131. Guid = x.Guid
  132. };
  133. var (title, summaries) = await GetFlowTitleAndSummaryAsync(user, x.ProcessId, x.Id);
  134. result.Title = title;
  135. result.AvatarUrl = _userRepository.GetAvatarUrl(user);
  136. result.Summaries = summaries;
  137. if (source == nameof(FlowListTypeConst.SubmittedChecking))
  138. result.IsRead = true;
  139. else
  140. result.IsRead = x.IsRead;
  141. return result;
  142. });
  143. return await Task.WhenAll(resultList);
  144. }
  145. private async Task<FlowListResult> GetFlowListResultAsync(Entity.WorkFlow.Flow flow, int todoId, string source = "")
  146. {
  147. var user = await _userRepository.GetAsync(flow.UserId);
  148. //获取todo
  149. var tode = await _flowTodoRepository.GetAsync(todoId);
  150. var result = new FlowListResult
  151. {
  152. Id = flow.Id,
  153. TodoId = todoId,
  154. ProcessId = flow.ProcessId,
  155. UserId = flow.UserId,
  156. State = flow.State,
  157. ProcessNodeId = flow.ProcessNodeId,
  158. CreatedDate = flow.CreatedDate,
  159. Guid = flow.Guid
  160. };
  161. // if (tode != null)
  162. // {
  163. // if (tode.IsDone && tode.IsChecked)
  164. // result.State = FlowState.Checked;
  165. // else if (tode.IsDone && !tode.IsChecked)
  166. // result.State = FlowState.Denied;
  167. // else
  168. // result.State = FlowState.Checking;
  169. // }
  170. var (title, summaries) = await GetFlowTitleAndSummaryAsync(user, flow.ProcessId, flow.Id);
  171. result.Title = title;
  172. result.AvatarUrl = _userRepository.GetAvatarUrl(user);
  173. result.Summaries = summaries;
  174. if (source == nameof(FlowListTypeConst.MyChecking) || source == nameof(FlowListTypeConst.MyChecked))
  175. result.IsRead = tode.IsDone;
  176. else if (source == nameof(FlowListTypeConst.CcAll) || source == nameof(FlowListTypeConst.SubmittedChecking))
  177. result.IsRead = true;
  178. else
  179. result.IsRead = tode.IsRead;
  180. return result;
  181. }
  182. }
  183. }