ProcessService.Edit.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using GxPress.Common.Exceptions;
  4. using GxPress.Common.Tools;
  5. using GxPress.Entity.WorkProcess;
  6. using GxPress.Entity.WorkProcessDto;
  7. using GxPress.EnumConst;
  8. namespace GxPress.Service.Implement
  9. {
  10. public partial class ProcessService
  11. {
  12. public async Task<Process> EditAsync(ProcessDto request)
  13. {
  14. request.IconUrl = StringUtils.RemoveDomain(request.IconUrl);
  15. //1.保存基本信息
  16. var group = await _processGroupRepository.GetAsync(request.GroupId);
  17. if (group == null) throw new BusinessException("流程分组不存在");
  18. var process = _mapper.Map<Process>(request);
  19. await _processRepository.UpdateAsync(process);
  20. await _processRequestLimitRepository.DeleteByProcessIdAsync(process.Id);
  21. //2.保存发起限制
  22. if (process.LimitType != nameof(LimitTypeConst.NoLimit))
  23. {
  24. //TODO 批量插入优化
  25. foreach (var limit in request.RequestLimits)
  26. {
  27. await _processRequestLimitRepository.InsertAsync(new ProcessRequestLimit
  28. {
  29. ProcessId = process.Id,
  30. DepartmentId = limit.DepartmentId,
  31. RoleId = limit.RoleId,
  32. UserId = limit.UserId
  33. });
  34. }
  35. }
  36. await _processFieldRepository.DeleteByProcessIdAsync(process.Id, request.FormFields);
  37. var fieldDict = new Dictionary<int, int>();
  38. //3.保存表单定义
  39. if (request.FormFields != null)
  40. {
  41. foreach (var field in request.FormFields)
  42. {
  43. //获取
  44. var formField = await _processFieldRepository.GetFieldAsync(field.Id);
  45. if (formField == null)
  46. {
  47. //保存字段
  48. var fieldId = await _processFieldRepository.InsertAsync(new ProcessField
  49. {
  50. ProcessId = process.Id,
  51. Label = field.Label,
  52. Placeholder = field.Placeholder,
  53. Required = field.Required,
  54. Sort = field.Sort,
  55. Type = field.Type,
  56. Unit = field.Unit,
  57. Options = StringUtils.ObjectCollectionToString(field.Options)
  58. });
  59. fieldDict.Add(field.Id, fieldId);
  60. }
  61. else
  62. {
  63. //保存字段
  64. var fieldId = await _processFieldRepository.UpdateAsync(new ProcessField
  65. {
  66. Id = field.Id,
  67. ProcessId = process.Id,
  68. Label = field.Label,
  69. Placeholder = field.Placeholder,
  70. Required = field.Required,
  71. Sort = field.Sort,
  72. Type = field.Type,
  73. Unit = field.Unit,
  74. Options = StringUtils.ObjectCollectionToString(field.Options)
  75. });
  76. fieldDict.Add(field.Id, field.Id);
  77. }
  78. }
  79. }
  80. //4.保存节点定义
  81. await _processNodeRepository.DeleteByProcessIdAsync(process.Id);
  82. if (request.ProcessNodes != null)
  83. {
  84. foreach (var node in request.ProcessNodes)
  85. {
  86. await AddNodeAsync(node, 0, process.Id, fieldDict);
  87. }
  88. }
  89. return process;
  90. }
  91. }
  92. }