FlowService.List.cs 8.3 KB

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