Commit af842c70afbb48f99d7f31bd7c62279e7a29f50c

Authored by 芋道源码
Committed by GitHub
2 parents 39916475 6fbcac3c

Merge pull request #777 from minivv/master-jdk17

【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 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 12 import cn.iocoder.yudao.module.bpm.service.definition.BpmFormService;
13 13 import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService;
14 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 17 import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
16 18 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
17 19 import io.swagger.v3.oas.annotations.Operation;
... ... @@ -53,6 +55,8 @@ public class BpmModelController {
53 55  
54 56 @Resource
55 57 private AdminUserApi adminUserApi;
  58 + @Resource
  59 + private DeptApi deptApi;
56 60  
57 61 @GetMapping("/list")
58 62 @Operation(summary = "获得模型分页")
... ... @@ -85,8 +89,14 @@ public class BpmModelController {
85 89 return metaInfo != null ? metaInfo.getStartUserIds().stream() : Stream.empty();
86 90 });
87 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 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 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 59 @Schema(description = "可发起用户编号数组", example = "[1,2,3]")
60 60 private List<Long> startUserIds;
61 61  
  62 + @Schema(description = "可发起部门编号数组")
  63 + private List<Long> startDeptIds;
  64 +
62 65 @Schema(description = "可管理用户编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[2,4,6]")
63 66 @NotEmpty(message = "可管理用户编号数组不能为空")
64 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 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 4 import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO;
4 5 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
5 6 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO;
... ... @@ -39,6 +40,9 @@ public class BpmModelRespVO extends BpmModelMetaInfoVO {
39 40 @Schema(description = "可发起的用户数组")
40 41 private List<UserSimpleBaseVO> startUsers;
41 42  
  43 + @Schema(description = "可发起的部门数组")
  44 + private List<DeptSimpleBaseVO> startDepts;
  45 +
42 46 @Schema(description = "BPMN XML")
43 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 4 import cn.iocoder.yudao.framework.common.util.date.DateUtils;
5 5 import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
6 6 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  7 +import cn.iocoder.yudao.module.bpm.controller.admin.base.dept.DeptSimpleBaseVO;
7 8 import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO;
8 9 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
9 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 14 import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
14 15 import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
15 16 import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
  17 +import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
16 18 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
17 19 import org.flowable.common.engine.impl.db.SuspensionState;
18 20 import org.flowable.engine.repository.Deployment;
... ... @@ -43,7 +45,8 @@ public interface BpmModelConvert {
43 45 Map<String, BpmCategoryDO> categoryMap,
44 46 Map<String, Deployment> deploymentMap,
45 47 Map<String, ProcessDefinition> processDefinitionMap,
46   - Map<Long, AdminUserRespDTO> userMap) {
  48 + Map<Long, AdminUserRespDTO> userMap,
  49 + Map<Long, DeptRespDTO> deptMap) {
47 50 List<BpmModelRespVO> result = convertList(list, model -> {
48 51 BpmModelMetaInfoVO metaInfo = parseMetaInfo(model);
49 52 BpmFormDO form = metaInfo != null ? formMap.get(metaInfo.getFormId()) : null;
... ... @@ -52,7 +55,8 @@ public interface BpmModelConvert {
52 55 ProcessDefinition processDefinition = model.getDeploymentId() != null ?
53 56 processDefinitionMap.get(model.getDeploymentId()) : null;
54 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 62 result.sort(Comparator.comparing(BpmModelMetaInfoVO::getSort));
... ... @@ -61,7 +65,7 @@ public interface BpmModelConvert {
61 65  
62 66 default BpmModelRespVO buildModel(Model model, byte[] bpmnBytes, BpmSimpleModelNodeVO simpleModel) {
63 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 69 if (ArrayUtil.isNotEmpty(bpmnBytes)) {
66 70 modelVO.setBpmnXml(BpmnModelUtils.getBpmnXml(bpmnBytes));
67 71 }
... ... @@ -72,7 +76,8 @@ public interface BpmModelConvert {
72 76 default BpmModelRespVO buildModel0(Model model,
73 77 BpmModelMetaInfoVO metaInfo, BpmFormDO form, BpmCategoryDO category,
74 78 Deployment deployment, ProcessDefinition processDefinition,
75   - List<AdminUserRespDTO> startUsers) {
  79 + List<AdminUserRespDTO> startUsers,
  80 + List<DeptRespDTO> startDepts) {
76 81 BpmModelRespVO modelRespVO = new BpmModelRespVO().setId(model.getId()).setName(model.getName())
77 82 .setKey(model.getKey()).setCategory(model.getCategory())
78 83 .setCreateTime(DateUtils.of(model.getCreateTime()));
... ... @@ -96,6 +101,8 @@ public interface BpmModelConvert {
96 101 }
97 102 // User
98 103 modelRespVO.setStartUsers(BeanUtils.toBean(startUsers, UserSimpleBaseVO.class));
  104 + // Dept
  105 + modelRespVO.setStartDepts(BeanUtils.toBean(startDepts, DeptSimpleBaseVO.class));
99 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 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 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 12 import cn.iocoder.yudao.module.bpm.dal.mysql.definition.BpmProcessDefinitionInfoMapper;
13 13 import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants;
14 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 17 import jakarta.annotation.Resource;
16 18 import lombok.extern.slf4j.Slf4j;
17 19 import org.flowable.bpmn.model.BpmnModel;
... ... @@ -49,6 +51,8 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
49 51  
50 52 @Resource
51 53 private BpmProcessDefinitionInfoMapper processDefinitionMapper;
  54 + @Resource
  55 + private AdminUserApi adminUserApi;
52 56  
53 57 @Override
54 58 public ProcessDefinition getProcessDefinition(String id) {
... ... @@ -88,12 +92,23 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
88 92 if (processDefinition == null) {
89 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 114 @Override
... ...