CirculateUtil.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package jnpf.flowable.util;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import jnpf.exception.WorkFlowException;
  4. import jnpf.flowable.entity.CirculateEntity;
  5. import jnpf.flowable.entity.OperatorEntity;
  6. import jnpf.flowable.entity.TaskEntity;
  7. import jnpf.flowable.entity.TemplateNodeEntity;
  8. import jnpf.flowable.enums.RecordEnum;
  9. import jnpf.flowable.model.task.FlowMethod;
  10. import jnpf.flowable.model.task.FlowModel;
  11. import jnpf.flowable.model.templatenode.nodejson.NodeModel;
  12. import jnpf.flowable.model.util.FlowNature;
  13. import jnpf.flowable.service.CirculateService;
  14. import jnpf.permission.entity.UserEntity;
  15. import jnpf.permission.entity.UserRelationEntity;
  16. import jnpf.util.JsonUtil;
  17. import jnpf.util.RandomUtil;
  18. import jnpf.util.StringUtil;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.stereotype.Component;
  21. import java.util.*;
  22. import java.util.stream.Collectors;
  23. /**
  24. * @author :JNPF开发平台组
  25. * @version: V3.1.0
  26. * @copyright 引迈信息技术有限公司
  27. * @date :2024/4/29 下午3:12
  28. */
  29. @Component
  30. public class CirculateUtil {
  31. @Autowired
  32. private ServiceUtil serviceUtil;
  33. @Autowired
  34. private TaskUtil taskUtil;
  35. @Autowired
  36. private CirculateService circulateService;
  37. public List<CirculateEntity> circulateList(FlowMethod flowMethod) throws WorkFlowException {
  38. FlowModel flowModel = flowMethod.getFlowModel();
  39. List<CirculateEntity> circulateList = new ArrayList<>();
  40. TaskEntity task = flowMethod.getTaskEntity();
  41. OperatorEntity operator = flowMethod.getOperatorEntity();
  42. TemplateNodeEntity nodeEntity = flowMethod.getNodeEntity();
  43. NodeModel nodeModel = JsonUtil.getJsonToBean(nodeEntity.getNodeJson(), NodeModel.class);
  44. List<String> userIdAll = new ArrayList<>();
  45. //附加规则
  46. if (!ObjectUtil.equals(flowMethod.getType(), RecordEnum.reject.getCode())) {
  47. userIdAll = serviceUtil.getUserListAll(nodeModel.getCirculateUser());
  48. taskUtil.rule(userIdAll, task.getId(), nodeModel.getExtraCopyRule());
  49. }
  50. //指定传阅人
  51. userIdAll.addAll(Arrays.asList(StringUtil.isNotEmpty(flowModel.getCopyIds()) ? flowModel.getCopyIds().split(",") : new String[]{}));
  52. //抄送自己
  53. if (nodeModel.getIsInitiatorCopy()) {
  54. userIdAll.add(task.getCreatorUserId());
  55. }
  56. //抄送表单变量
  57. if (nodeModel.getIsFormFieldCopy()) {
  58. flowMethod.setIsAssign(false);
  59. Map<String, Object> dataAll = taskUtil.createOrUpdate(flowMethod);
  60. Object data = dataAll.get(nodeModel.getCopyFormField() + FlowNature.FORM_FIELD_SUFFIX);
  61. if (data != null) {
  62. List<String> list = new ArrayList<>();
  63. try {
  64. list.addAll(JsonUtil.getJsonToList(String.valueOf(data), String.class));
  65. } catch (Exception e) {}
  66. if (data instanceof List) {
  67. list.addAll((List) data);
  68. } else {
  69. list.addAll(Arrays.asList(String.valueOf(data).split(",")));
  70. }
  71. List<String> id = new ArrayList<>();
  72. for (String s : list) {
  73. id.add(s.split("--")[0]);
  74. }
  75. List<UserRelationEntity> listByObjectIdAll = serviceUtil.getListByObjectIdAll(id);
  76. List<String> userList = serviceUtil.getUserListAll(list);
  77. List<String> userPosition = listByObjectIdAll.stream().map(UserRelationEntity::getUserId).collect(Collectors.toList());
  78. List<String> handleIdAll = new ArrayList<>();
  79. handleIdAll.addAll(userPosition);
  80. handleIdAll.addAll(id);
  81. handleIdAll.addAll(userList);
  82. userIdAll.addAll(handleIdAll);
  83. }
  84. }
  85. //获取最新用户
  86. List<UserEntity> userList = serviceUtil.getUserName(userIdAll, true);
  87. for (UserEntity userEntity : userList) {
  88. CirculateEntity circulate = new CirculateEntity();
  89. circulate.setId(RandomUtil.uuId());
  90. circulate.setUserId(userEntity.getId());
  91. circulate.setNodeCode(nodeModel.getNodeId());
  92. circulate.setNodeName(nodeModel.getNodeName());
  93. circulate.setTaskId(task.getId());
  94. circulate.setCirculateRead(0);
  95. circulate.setOperatorId(operator.getId());
  96. circulate.setNodeId(operator.getNodeId());
  97. circulate.setCreatorTime(new Date());
  98. circulateList.add(circulate);
  99. }
  100. circulateService.saveBatch(circulateList);
  101. return circulateList;
  102. }
  103. }