AppProcessController.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using GxPress.Auth;
  4. using GxPress.Repository.Interface.WorkProcess;
  5. using Microsoft.AspNetCore.Authorization;
  6. using Microsoft.AspNetCore.Mvc;
  7. using GxPress.Entity.WorkProcess;
  8. using GxPress.Result.App.Process;
  9. using GxPress.Service.Interface;
  10. using System.Linq;
  11. using GxPress.Common.Tools;
  12. namespace GxPress.Api.AppControllers
  13. {
  14. [Route("api/app/process")]
  15. [ApiController]
  16. [Authorize]
  17. public class AppProcessController : ControllerBase
  18. {
  19. private readonly IProcessGroupRepository _processGroupRepository;
  20. private readonly IProcessRepository _processRepository;
  21. private readonly IProcessService _processService;
  22. private readonly ILoginContext _loginContext;
  23. public AppProcessController(IProcessGroupRepository processGroupRepository, IProcessRepository processRepository, IProcessService processService, ILoginContext loginContext)
  24. {
  25. _processGroupRepository = processGroupRepository;
  26. _processRepository = processRepository;
  27. _processService = processService;
  28. _loginContext = loginContext;
  29. }
  30. /// <summary>
  31. /// 获取工作流程列表
  32. /// </summary>
  33. /// <returns></returns>
  34. [HttpGet]
  35. [AllowAnonymous]
  36. public async Task<IEnumerable<Process>> GetProcessList()
  37. {
  38. return await _processRepository.GetListByDepartmentIdAsync(_loginContext.DepartmentId);
  39. }
  40. /// <summary>
  41. /// 获取工作流程
  42. /// </summary>
  43. /// <returns></returns>
  44. [HttpGet("{id}")]
  45. public async Task<GetProcessResult> GetProcess(int id)
  46. {
  47. var processDto = await _processService.GetAsync(id);
  48. var result = new GetProcessResult
  49. {
  50. Id = processDto.Id,
  51. Name = processDto.Name,
  52. IconUrl =StringUtils.AddDomain(processDto.IconUrl),
  53. Description = processDto.Description,
  54. FormFields = processDto.FormFields,
  55. AllowApproverCheck = processDto.AllowApproverCheck,
  56. AllowCarbonCopy = processDto.AllowCarbonCopy
  57. };
  58. result.ApproverCheckUserIds = new List<int>();
  59. //获取流程接点
  60. foreach (var item in processDto.ProcessNodes)
  61. //添加系统审核人
  62. result.ApproverCheckUserIds.AddRange(item.ApproverChecks.Select(n => n.UserId));
  63. result.ApproverCheckUserIds.Add(_loginContext.AccountId);
  64. return result;
  65. }
  66. /// <summary>
  67. /// 获取流程组与流程列表
  68. /// </summary>
  69. /// <returns></returns>
  70. [HttpGet("groups")]
  71. [AllowAnonymous]
  72. public async Task<IEnumerable<ProcessGroup>> GetProcessGroupList()
  73. {
  74. var groups = await _processGroupRepository.GetListAsync();
  75. foreach (var processGroup in groups)
  76. {
  77. var processes = await _processRepository.GetListByGroupIdAsync(processGroup.Id);
  78. processGroup.Processes = processes;
  79. }
  80. return groups;
  81. }
  82. }
  83. }