AppFlowController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using GxPress.Api.AdminControllers;
  5. using GxPress.Auth;
  6. using GxPress.Entity.WorkFlowDto;
  7. using GxPress.EnumConst;
  8. using GxPress.Repository.Interface;
  9. using GxPress.Repository.Interface.WorkFlow;
  10. using GxPress.Repository.Interface.WorkProcess;
  11. using GxPress.Request.App.Flow;
  12. using GxPress.Result.App;
  13. using GxPress.Result.App.Flow;
  14. using GxPress.Service.Interface;
  15. using GxPress.Service.Interface.Doc;
  16. using Microsoft.AspNetCore.Authorization;
  17. using Microsoft.AspNetCore.Hosting;
  18. using Microsoft.AspNetCore.Mvc;
  19. using Microsoft.Extensions.Logging;
  20. namespace GxPress.Api.AppControllers
  21. {
  22. /// <summary>
  23. /// 通讯录用户信息
  24. /// </summary>
  25. [Route("api/app/flow")]
  26. [ApiController]
  27. [Authorize]
  28. public partial class AppFlowController : ControllerBase
  29. {
  30. private readonly ILogger<AppVersionController> _logger;
  31. private readonly IWebHostEnvironment _environment;
  32. private readonly ILoginContext _loginContext;
  33. private readonly IFlowMessageRepository _flowMessageRepository;
  34. private readonly IFlowTodoRepository _flowTodoRepository;
  35. private readonly IProcessRepository _processRepository;
  36. private readonly IProcessService _processService;
  37. private readonly IFlowService _flowService;
  38. private readonly IUserRepository _userRepository;
  39. private readonly IFlowRepository _flowRepository;
  40. private readonly IDocService docService;
  41. public AppFlowController(
  42. ILogger<AppVersionController> logger,
  43. IWebHostEnvironment environment,
  44. ILoginContext loginContext,
  45. IFlowMessageRepository flowMessageRepository,
  46. IFlowTodoRepository flowTodoRepository,
  47. IProcessRepository processRepository,
  48. IProcessService processService,
  49. IFlowService flowService,
  50. IUserRepository userRepository,
  51. IFlowRepository flowRepository, IDocService docService
  52. )
  53. {
  54. _logger = logger;
  55. _environment = environment;
  56. _loginContext = loginContext;
  57. _flowMessageRepository = flowMessageRepository;
  58. _flowTodoRepository = flowTodoRepository;
  59. _processRepository = processRepository;
  60. _processService = processService;
  61. _flowService = flowService;
  62. _userRepository = userRepository;
  63. _flowRepository = flowRepository;
  64. this.docService = docService;
  65. }
  66. /// <summary>
  67. /// 删除
  68. /// </summary>
  69. /// <param name="id"></param>
  70. /// <returns></returns>
  71. [HttpDelete("{id}")]
  72. public async Task Delete(int id)
  73. {
  74. await _flowService.DeleteAsync(id);
  75. }
  76. /// <summary>
  77. /// 添加工作项
  78. /// </summary>
  79. /// <param name="flow">工作项</param>
  80. /// <returns></returns>
  81. [HttpPost]
  82. [AllowAnonymous]
  83. public async Task<FlowDto> Add([FromBody] FlowDto flow)
  84. {
  85. flow.State = FlowState.Checking;
  86. flow.UserId = _loginContext.AccountId;
  87. if (flow.Id > 0)
  88. await _flowService.DeleteAsync(flow.Id);
  89. flow.Id = await _flowService.AddAsync(flow);
  90. return flow;
  91. }
  92. /// <summary>
  93. /// 获取详情
  94. /// </summary>
  95. /// <param name="id"></param>
  96. /// <returns></returns>
  97. [HttpGet("{id}")]
  98. [AllowAnonymous]
  99. public async Task<FlowResult> Get(int id)
  100. {
  101. await _flowTodoRepository.UpdateCCIsDoneAsync(_loginContext.AccountId, id);
  102. return await _flowService.GetFlowResult(id, _loginContext.AccountId);
  103. }
  104. /// <summary>
  105. /// 获取详情 web专属
  106. /// </summary>
  107. /// <param name="id"></param>
  108. /// <returns></returns>
  109. [HttpGet("web/{id}")]
  110. [AllowAnonymous]
  111. public async Task<FlowResult> GetWeb(int id)
  112. {
  113. //await _flowTodoRepository.UpdateCCIsDoneAsync(_loginContext.AccountId, id);
  114. return await _flowService.GetFlowResult(id, 0);
  115. }
  116. /// <summary>
  117. /// 获取工作项列表
  118. /// </summary>
  119. /// <returns></returns>
  120. [HttpGet]
  121. [AllowAnonymous]
  122. public async Task<ListResult> List([FromQuery] FlowListRequest request)
  123. {
  124. var userId = _loginContext.AccountId;
  125. if (request.Type == nameof(FlowListTypeConst.MyChecking))
  126. {
  127. return await _flowService.ListMyCheckingAsync(userId, request, nameof(FlowListTypeConst.MyChecking));
  128. }
  129. if (request.Type == nameof(FlowListTypeConst.MyChecked))
  130. {
  131. return await _flowService.ListMyCheckedAsync(userId, request, nameof(FlowListTypeConst.MyChecked));
  132. }
  133. if (request.Type == nameof(FlowListTypeConst.CcUnread))
  134. {
  135. return await _flowService.ListCcUnreadAsync(userId, request);
  136. }
  137. if (request.Type == nameof(FlowListTypeConst.CcAll))
  138. {
  139. return await _flowService.ListCcAllAsync(userId, request);
  140. }
  141. if (request.Type == nameof(FlowListTypeConst.SubmittedChecking))
  142. {
  143. return await _flowService.ListSubmittedCheckingAsync(userId, request);
  144. }
  145. if (request.Type == nameof(FlowListTypeConst.SubmittedChecked))
  146. {
  147. return await _flowService.ListSubmittedCheckedAsync(userId, request);
  148. }
  149. return new ListResult();
  150. }
  151. /// <summary>
  152. /// 获取工作项列表
  153. /// </summary>
  154. /// <returns></returns>
  155. [HttpPost("list")]
  156. public async Task<ListResult> PostList(FlowListRequest request)
  157. {
  158. var userId = _loginContext.AccountId;
  159. if (request.Type == nameof(FlowListTypeConst.MyChecking))
  160. {
  161. return await _flowService.ListMyCheckingAsync(userId, request, nameof(FlowListTypeConst.MyChecking));
  162. }
  163. if (request.Type == nameof(FlowListTypeConst.MyChecked))
  164. {
  165. return await _flowService.ListMyCheckedAsync(userId, request, nameof(FlowListTypeConst.MyChecked));
  166. }
  167. if (request.Type == nameof(FlowListTypeConst.CcUnread))
  168. {
  169. return await _flowService.ListCcUnreadAsync(userId, request);
  170. }
  171. if (request.Type == nameof(FlowListTypeConst.CcAll))
  172. {
  173. return await _flowService.ListCcAllAsync(userId, request, nameof(FlowListTypeConst.CcAll));
  174. }
  175. if (request.Type == nameof(FlowListTypeConst.SubmittedChecking))
  176. {
  177. return await _flowService.ListSubmittedCheckingAsync(userId, request, nameof(FlowListTypeConst.SubmittedChecking));
  178. }
  179. if (request.Type == nameof(FlowListTypeConst.SubmittedChecked))
  180. {
  181. return await _flowService.ListSubmittedCheckedAsync(userId, request);
  182. }
  183. return new ListResult();
  184. }
  185. /// <summary>
  186. /// 待办事项
  187. /// </summary>
  188. /// <returns></returns>
  189. [HttpGet("todo")]
  190. [AllowAnonymous]
  191. public async Task<ListResult> TodoList([FromQuery] AdminFlowController.ListRequest request)
  192. {
  193. var userId = _loginContext.AccountId;
  194. var flowListRequest = new FlowListRequest();
  195. flowListRequest.Page = request.Page;
  196. flowListRequest.PerPage = request.PerPage;
  197. var result = await _flowService.ListMyCheckingAsync(userId, flowListRequest, nameof(FlowListTypeConst.MyChecking));
  198. return new ListResult
  199. {
  200. Count = result.Count,
  201. Items = result.Items
  202. };
  203. // var flowTodoList = await _flowService.GetTodoListAsync(userId, request.Page, request.PerPage, request.ProcessId);
  204. // var resultList = new List<FlowTodoResult>();
  205. // foreach (var flowTodo in flowTodoList)
  206. // {
  207. // //新增
  208. // if (flowTodo.IsDone)
  209. // continue;
  210. // var flow = await _flowService.GetAsync(flowTodo.FlowId);
  211. // var user = await _userRepository.GetAsync(flow.UserId);
  212. // if (user == null || flow == null) continue;
  213. // var result = new FlowTodoResult
  214. // {
  215. // Id = flowTodo.Id,
  216. // ProcessId = flowTodo.ProcessId,
  217. // FlowId = flowTodo.FlowId,
  218. // UserId = flowTodo.UserId,
  219. // Type = flowTodo.Type,
  220. // State = flow.State,
  221. // IsDone = false,
  222. // CreatedDate = flowTodo.CreatedDate
  223. // };
  224. // var (title, summaries) = await _flowService.GetFlowTitleAndSummaryAsync(user, flow.ProcessId, flow.Id);
  225. // result.Title = title;
  226. // result.AvatarUrl = _userRepository.GetAvatarUrl(user);
  227. // result.Summaries = summaries;
  228. // resultList.Add(result);
  229. // }
  230. // return new TodoListResult
  231. // {
  232. // Count = await _flowService.GetTodoCountAsync(userId),
  233. // Items = resultList
  234. // };
  235. // //return resultList.ToList();
  236. //}
  237. }
  238. /// <summary>
  239. /// 获取数字
  240. /// </summary>
  241. /// <returns></returns>
  242. [HttpGet("count")]
  243. [AllowAnonymous]
  244. public async Task<GetCountResult> GetCount()
  245. {
  246. var userId = _loginContext.AccountId;
  247. var request = new FlowListRequest();
  248. var result = new GetCountResult
  249. {
  250. MyCheckingCount =
  251. await _flowTodoRepository.GetCountAsync(userId, nameof(TodoTypeConst.ApproverCheck), false,
  252. request),
  253. MyCheckedCount =
  254. await _flowTodoRepository.GetCountAsync(userId, nameof(TodoTypeConst.ApproverCheck), true, request),
  255. SubmittedCheckingCount = await _flowRepository.GetCountByUserIdAsync(userId, true, request),
  256. //SubmittedCheckedCount= await _flowTodoRepository.GetUReadCountAsync(userId, "CarbonCopy",false,request),
  257. SubmittedCheckedCount = await _flowRepository.GetCountByUserIdAsync(userId, false, request),
  258. CcUnreadCount =
  259. await _flowTodoRepository.GetReadCountAsync(userId, nameof(TodoTypeConst.CarbonCopy), request, false),
  260. CcAllCount = await _flowTodoRepository.GetReadCountAsync(userId, nameof(TodoTypeConst.CarbonCopy), request, true)
  261. };
  262. return result;
  263. }
  264. /// <summary>
  265. /// 获取筛选
  266. /// </summary>
  267. /// <returns></returns>
  268. [HttpGet("filter")]
  269. [AllowAnonymous]
  270. public async Task<List<Option>> Filter()
  271. {
  272. var processes = await _processRepository.GetListByDepartmentIdAsync(_loginContext.DepartmentId);
  273. var list = processes.Select(x => new Option
  274. {
  275. Label = x.Name,
  276. Value = x.Id
  277. }).ToList();
  278. list.Insert(0, new Option
  279. {
  280. Label = "全部",
  281. Value = 0
  282. });
  283. return list;
  284. }
  285. }
  286. }