Commit 6fbcac3c13f5604605b4390c7f17c947abcafced

Authored by 郑威
1 parent e9a99c1e

【Simple设计器】流程模型->基本信息->谁可以发起,支持指定多个部门

指定部门可以在部门新增成员后无需重新修改相关流程
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/base/dept/DeptSimpleBaseVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.bpm.controller.admin.base.dept;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +@Schema(description = "部门精简信息 VO")
  7 +@Data
  8 +public class DeptSimpleBaseVO {
  9 + @Schema(description = "部门编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  10 + private Long id;
  11 + @Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
  12 + private String name;
  13 +}
0 \ No newline at end of file 14 \ No newline at end of file
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/BpmModelController.java
@@ -12,6 +12,8 @@ import cn.iocoder.yudao.module.bpm.service.definition.BpmCategoryService; @@ -12,6 +12,8 @@ import cn.iocoder.yudao.module.bpm.service.definition.BpmCategoryService;
12 import cn.iocoder.yudao.module.bpm.service.definition.BpmFormService; 12 import cn.iocoder.yudao.module.bpm.service.definition.BpmFormService;
13 import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService; 13 import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService;
14 import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService; 14 import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService;
  15 +import cn.iocoder.yudao.module.system.api.dept.DeptApi;
  16 +import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
15 import cn.iocoder.yudao.module.system.api.user.AdminUserApi; 17 import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
16 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; 18 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
17 import io.swagger.v3.oas.annotations.Operation; 19 import io.swagger.v3.oas.annotations.Operation;
@@ -53,6 +55,8 @@ public class BpmModelController { @@ -53,6 +55,8 @@ public class BpmModelController {
53 55
54 @Resource 56 @Resource
55 private AdminUserApi adminUserApi; 57 private AdminUserApi adminUserApi;
  58 + @Resource
  59 + private DeptApi deptApi;
56 60
57 @GetMapping("/list") 61 @GetMapping("/list")
58 @Operation(summary = "获得模型分页") 62 @Operation(summary = "获得模型分页")
@@ -85,8 +89,14 @@ public class BpmModelController { @@ -85,8 +89,14 @@ public class BpmModelController {
85 return metaInfo != null ? metaInfo.getStartUserIds().stream() : Stream.empty(); 89 return metaInfo != null ? metaInfo.getStartUserIds().stream() : Stream.empty();
86 }); 90 });
87 Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds); 91 Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
  92 + // 获得 Dept Map
  93 + Set<Long> deptIds = convertSetByFlatMap(list, model -> {
  94 + BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model);
  95 + return metaInfo != null && metaInfo.getStartDeptIds() != null ? metaInfo.getStartDeptIds().stream() : Stream.empty();
  96 + });
  97 + Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(deptIds);
88 return success(BpmModelConvert.INSTANCE.buildModelList(list, 98 return success(BpmModelConvert.INSTANCE.buildModelList(list,
89 - formMap, categoryMap, deploymentMap, processDefinitionMap, userMap)); 99 + formMap, categoryMap, deploymentMap, processDefinitionMap, userMap, deptMap));
90 } 100 }
91 101
92 @GetMapping("/get") 102 @GetMapping("/get")
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/BpmModelMetaInfoVO.java
@@ -59,6 +59,9 @@ public class BpmModelMetaInfoVO { @@ -59,6 +59,9 @@ public class BpmModelMetaInfoVO {
59 @Schema(description = "可发起用户编号数组", example = "[1,2,3]") 59 @Schema(description = "可发起用户编号数组", example = "[1,2,3]")
60 private List<Long> startUserIds; 60 private List<Long> startUserIds;
61 61
  62 + @Schema(description = "可发起部门编号数组")
  63 + private List<Long> startDeptIds;
  64 +
62 @Schema(description = "可管理用户编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[2,4,6]") 65 @Schema(description = "可管理用户编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[2,4,6]")
63 @NotEmpty(message = "可管理用户编号数组不能为空") 66 @NotEmpty(message = "可管理用户编号数组不能为空")
64 private List<Long> managerUserIds; 67 private List<Long> managerUserIds;
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/BpmModelRespVO.java
1 package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model; 1 package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;
2 2
  3 +import cn.iocoder.yudao.module.bpm.controller.admin.base.dept.DeptSimpleBaseVO;
3 import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO; 4 import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO;
4 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; 5 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
5 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO; 6 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO;
@@ -39,6 +40,9 @@ public class BpmModelRespVO extends BpmModelMetaInfoVO { @@ -39,6 +40,9 @@ public class BpmModelRespVO extends BpmModelMetaInfoVO {
39 @Schema(description = "可发起的用户数组") 40 @Schema(description = "可发起的用户数组")
40 private List<UserSimpleBaseVO> startUsers; 41 private List<UserSimpleBaseVO> startUsers;
41 42
  43 + @Schema(description = "可发起的部门数组")
  44 + private List<DeptSimpleBaseVO> startDepts;
  45 +
42 @Schema(description = "BPMN XML") 46 @Schema(description = "BPMN XML")
43 private String bpmnXml; 47 private String bpmnXml;
44 48
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/definition/BpmModelConvert.java
@@ -4,6 +4,7 @@ import cn.hutool.core.util.ArrayUtil; @@ -4,6 +4,7 @@ import cn.hutool.core.util.ArrayUtil;
4 import cn.iocoder.yudao.framework.common.util.date.DateUtils; 4 import cn.iocoder.yudao.framework.common.util.date.DateUtils;
5 import cn.iocoder.yudao.framework.common.util.json.JsonUtils; 5 import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
6 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 6 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  7 +import cn.iocoder.yudao.module.bpm.controller.admin.base.dept.DeptSimpleBaseVO;
7 import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO; 8 import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO;
8 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO; 9 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
9 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelRespVO; 10 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelRespVO;
@@ -13,6 +14,7 @@ import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmPro @@ -13,6 +14,7 @@ import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmPro
13 import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO; 14 import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
14 import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO; 15 import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
15 import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; 16 import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
  17 +import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
16 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; 18 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
17 import org.flowable.common.engine.impl.db.SuspensionState; 19 import org.flowable.common.engine.impl.db.SuspensionState;
18 import org.flowable.engine.repository.Deployment; 20 import org.flowable.engine.repository.Deployment;
@@ -43,7 +45,8 @@ public interface BpmModelConvert { @@ -43,7 +45,8 @@ public interface BpmModelConvert {
43 Map<String, BpmCategoryDO> categoryMap, 45 Map<String, BpmCategoryDO> categoryMap,
44 Map<String, Deployment> deploymentMap, 46 Map<String, Deployment> deploymentMap,
45 Map<String, ProcessDefinition> processDefinitionMap, 47 Map<String, ProcessDefinition> processDefinitionMap,
46 - Map<Long, AdminUserRespDTO> userMap) { 48 + Map<Long, AdminUserRespDTO> userMap,
  49 + Map<Long, DeptRespDTO> deptMap) {
47 List<BpmModelRespVO> result = convertList(list, model -> { 50 List<BpmModelRespVO> result = convertList(list, model -> {
48 BpmModelMetaInfoVO metaInfo = parseMetaInfo(model); 51 BpmModelMetaInfoVO metaInfo = parseMetaInfo(model);
49 BpmFormDO form = metaInfo != null ? formMap.get(metaInfo.getFormId()) : null; 52 BpmFormDO form = metaInfo != null ? formMap.get(metaInfo.getFormId()) : null;
@@ -52,7 +55,8 @@ public interface BpmModelConvert { @@ -52,7 +55,8 @@ public interface BpmModelConvert {
52 ProcessDefinition processDefinition = model.getDeploymentId() != null ? 55 ProcessDefinition processDefinition = model.getDeploymentId() != null ?
53 processDefinitionMap.get(model.getDeploymentId()) : null; 56 processDefinitionMap.get(model.getDeploymentId()) : null;
54 List<AdminUserRespDTO> startUsers = metaInfo != null ? convertList(metaInfo.getStartUserIds(), userMap::get) : null; 57 List<AdminUserRespDTO> startUsers = metaInfo != null ? convertList(metaInfo.getStartUserIds(), userMap::get) : null;
55 - return buildModel0(model, metaInfo, form, category, deployment, processDefinition, startUsers); 58 + List<DeptRespDTO> startDepts = metaInfo != null ? convertList(metaInfo.getStartDeptIds(), deptMap::get) : null;
  59 + return buildModel0(model, metaInfo, form, category, deployment, processDefinition, startUsers, startDepts);
56 }); 60 });
57 // 排序 61 // 排序
58 result.sort(Comparator.comparing(BpmModelMetaInfoVO::getSort)); 62 result.sort(Comparator.comparing(BpmModelMetaInfoVO::getSort));
@@ -61,7 +65,7 @@ public interface BpmModelConvert { @@ -61,7 +65,7 @@ public interface BpmModelConvert {
61 65
62 default BpmModelRespVO buildModel(Model model, byte[] bpmnBytes, BpmSimpleModelNodeVO simpleModel) { 66 default BpmModelRespVO buildModel(Model model, byte[] bpmnBytes, BpmSimpleModelNodeVO simpleModel) {
63 BpmModelMetaInfoVO metaInfo = parseMetaInfo(model); 67 BpmModelMetaInfoVO metaInfo = parseMetaInfo(model);
64 - BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null, null); 68 + BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null, null, null);
65 if (ArrayUtil.isNotEmpty(bpmnBytes)) { 69 if (ArrayUtil.isNotEmpty(bpmnBytes)) {
66 modelVO.setBpmnXml(BpmnModelUtils.getBpmnXml(bpmnBytes)); 70 modelVO.setBpmnXml(BpmnModelUtils.getBpmnXml(bpmnBytes));
67 } 71 }
@@ -72,7 +76,8 @@ public interface BpmModelConvert { @@ -72,7 +76,8 @@ public interface BpmModelConvert {
72 default BpmModelRespVO buildModel0(Model model, 76 default BpmModelRespVO buildModel0(Model model,
73 BpmModelMetaInfoVO metaInfo, BpmFormDO form, BpmCategoryDO category, 77 BpmModelMetaInfoVO metaInfo, BpmFormDO form, BpmCategoryDO category,
74 Deployment deployment, ProcessDefinition processDefinition, 78 Deployment deployment, ProcessDefinition processDefinition,
75 - List<AdminUserRespDTO> startUsers) { 79 + List<AdminUserRespDTO> startUsers,
  80 + List<DeptRespDTO> startDepts) {
76 BpmModelRespVO modelRespVO = new BpmModelRespVO().setId(model.getId()).setName(model.getName()) 81 BpmModelRespVO modelRespVO = new BpmModelRespVO().setId(model.getId()).setName(model.getName())
77 .setKey(model.getKey()).setCategory(model.getCategory()) 82 .setKey(model.getKey()).setCategory(model.getCategory())
78 .setCreateTime(DateUtils.of(model.getCreateTime())); 83 .setCreateTime(DateUtils.of(model.getCreateTime()));
@@ -96,6 +101,8 @@ public interface BpmModelConvert { @@ -96,6 +101,8 @@ public interface BpmModelConvert {
96 } 101 }
97 // User 102 // User
98 modelRespVO.setStartUsers(BeanUtils.toBean(startUsers, UserSimpleBaseVO.class)); 103 modelRespVO.setStartUsers(BeanUtils.toBean(startUsers, UserSimpleBaseVO.class));
  104 + // Dept
  105 + modelRespVO.setStartDepts(BeanUtils.toBean(startDepts, DeptSimpleBaseVO.class));
99 return modelRespVO; 106 return modelRespVO;
100 } 107 }
101 108
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/dataobject/definition/BpmProcessDefinitionInfoDO.java
@@ -152,6 +152,14 @@ public class BpmProcessDefinitionInfoDO extends BaseDO { @@ -152,6 +152,14 @@ public class BpmProcessDefinitionInfoDO extends BaseDO {
152 private List<Long> startUserIds; 152 private List<Long> startUserIds;
153 153
154 /** 154 /**
  155 + * 可发起部门编号数组
  156 + *
  157 + * 关联 {@link AdminUserRespDTO#getId()} 字段的数组
  158 + */
  159 + @TableField(typeHandler = LongListTypeHandler.class)
  160 + private List<Long> startDeptIds;
  161 +
  162 + /**
155 * 可管理用户编号数组 163 * 可管理用户编号数组
156 * 164 *
157 * 关联 {@link AdminUserRespDTO#getId()} 字段的数组 165 * 关联 {@link AdminUserRespDTO#getId()} 字段的数组
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmProcessDefinitionServiceImpl.java
@@ -12,6 +12,8 @@ import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitio @@ -12,6 +12,8 @@ import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitio
12 import cn.iocoder.yudao.module.bpm.dal.mysql.definition.BpmProcessDefinitionInfoMapper; 12 import cn.iocoder.yudao.module.bpm.dal.mysql.definition.BpmProcessDefinitionInfoMapper;
13 import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants; 13 import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants;
14 import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils; 14 import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
  15 +import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
  16 +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
15 import jakarta.annotation.Resource; 17 import jakarta.annotation.Resource;
16 import lombok.extern.slf4j.Slf4j; 18 import lombok.extern.slf4j.Slf4j;
17 import org.flowable.bpmn.model.BpmnModel; 19 import org.flowable.bpmn.model.BpmnModel;
@@ -49,6 +51,8 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ @@ -49,6 +51,8 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
49 51
50 @Resource 52 @Resource
51 private BpmProcessDefinitionInfoMapper processDefinitionMapper; 53 private BpmProcessDefinitionInfoMapper processDefinitionMapper;
  54 + @Resource
  55 + private AdminUserApi adminUserApi;
52 56
53 @Override 57 @Override
54 public ProcessDefinition getProcessDefinition(String id) { 58 public ProcessDefinition getProcessDefinition(String id) {
@@ -88,12 +92,23 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ @@ -88,12 +92,23 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
88 if (processDefinition == null) { 92 if (processDefinition == null) {
89 return false; 93 return false;
90 } 94 }
91 - // 为空,则所有人都可以发起  
92 - if (CollUtil.isEmpty(processDefinition.getStartUserIds())) {  
93 - return true; 95 +
  96 + // 获取用户所在部门
  97 + AdminUserRespDTO user = adminUserApi.getUser(userId);
  98 + Long userDeptId = user != null ? user.getDeptId() : null;
  99 +
  100 + // 校验用户是否在允许发起的用户列表中
  101 + if (!CollUtil.isEmpty(processDefinition.getStartUserIds())) {
  102 + return processDefinition.getStartUserIds().contains(userId);
  103 + }
  104 +
  105 + // 校验用户是否在允许发起的部门列表中
  106 + if (!CollUtil.isEmpty(processDefinition.getStartDeptIds()) && userDeptId != null) {
  107 + return processDefinition.getStartDeptIds().contains(userDeptId);
94 } 108 }
95 - // 不为空,则需要存在里面  
96 - return processDefinition.getStartUserIds().contains(userId); 109 +
  110 + // 都为空,则所有人都可以发起
  111 + return true;
97 } 112 }
98 113
99 @Override 114 @Override