AppProcessController.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. public async Task<List<Process>> GetProcessList()
  36. {
  37. if (_loginContext.DepartmentId == 0)
  38. return new List<Process>();
  39. var result = await _processRepository.GetListByDepartmentIdAsync(_loginContext.DepartmentId);
  40. return result.ToList();
  41. }
  42. /// <summary>
  43. /// 获取工作流程
  44. /// </summary>
  45. /// <returns></returns>
  46. [HttpGet("{id}")]
  47. public async Task<GetProcessResult> GetProcess(int id)
  48. {
  49. var processDto = await _processService.GetAsync(id);
  50. var result = new GetProcessResult
  51. {
  52. Id = processDto.Id,
  53. Name = processDto.Name,
  54. IconUrl = StringUtils.AddDomain(processDto.IconUrl),
  55. Description = processDto.Description,
  56. FormFields = processDto.FormFields,
  57. AllowApproverCheck = processDto.AllowApproverCheck,
  58. AllowCarbonCopy = processDto.AllowCarbonCopy
  59. };
  60. result.ApproverCheckUserIds = new List<int>();
  61. //获取流程接点
  62. foreach (var item in processDto.ProcessNodes)
  63. //添加系统审核人
  64. result.ApproverCheckUserIds.AddRange(item.ApproverChecks.Select(n => n.UserId));
  65. result.ApproverCheckUserIds.Add(_loginContext.AccountId);
  66. return result;
  67. }
  68. /// <summary>
  69. /// 获取流程组与流程列表
  70. /// </summary>
  71. /// <returns></returns>
  72. [HttpGet("groups")]
  73. [AllowAnonymous]
  74. public async Task<IEnumerable<ProcessGroup>> GetProcessGroupList()
  75. {
  76. var groups = await _processGroupRepository.GetListAsync();
  77. foreach (var processGroup in groups)
  78. {
  79. var processes = await _processRepository.GetListByGroupIdAsync(processGroup.Id);
  80. processGroup.Processes = processes;
  81. }
  82. return groups;
  83. }
  84. }
  85. }