Commit 4fbe9fa480b25fde992687399206af5da8ffecc8

Authored by YunaiV
1 parent af842c70

【代码优化】BPM:流程模型->基本信息->谁可以发起,支持指定多个部门

yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/base/dept/DeptSimpleBaseVO.java
@@ -6,8 +6,10 @@ import lombok.Data; @@ -6,8 +6,10 @@ import lombok.Data;
6 @Schema(description = "部门精简信息 VO") 6 @Schema(description = "部门精简信息 VO")
7 @Data 7 @Data
8 public class DeptSimpleBaseVO { 8 public class DeptSimpleBaseVO {
  9 +
9 @Schema(description = "部门编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") 10 @Schema(description = "部门编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
10 private Long id; 11 private Long id;
11 - @Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") 12 + @Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "技术部")
12 private String name; 13 private String name;
  14 +
13 } 15 }
14 \ No newline at end of file 16 \ 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
@@ -83,13 +83,12 @@ public class BpmModelController { @@ -83,13 +83,12 @@ public class BpmModelController {
83 List<ProcessDefinition> processDefinitions = processDefinitionService.getProcessDefinitionListByDeploymentIds( 83 List<ProcessDefinition> processDefinitions = processDefinitionService.getProcessDefinitionListByDeploymentIds(
84 deploymentMap.keySet()); 84 deploymentMap.keySet());
85 Map<String, ProcessDefinition> processDefinitionMap = convertMap(processDefinitions, ProcessDefinition::getDeploymentId); 85 Map<String, ProcessDefinition> processDefinitionMap = convertMap(processDefinitions, ProcessDefinition::getDeploymentId);
86 - // 获得 User Map 86 + // 获得 User Map、Dept Map
87 Set<Long> userIds = convertSetByFlatMap(list, model -> { 87 Set<Long> userIds = convertSetByFlatMap(list, model -> {
88 BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model); 88 BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model);
89 return metaInfo != null ? metaInfo.getStartUserIds().stream() : Stream.empty(); 89 return metaInfo != null ? metaInfo.getStartUserIds().stream() : Stream.empty();
90 }); 90 });
91 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 -> { 92 Set<Long> deptIds = convertSetByFlatMap(list, model -> {
94 BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model); 93 BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model);
95 return metaInfo != null && metaInfo.getStartDeptIds() != null ? metaInfo.getStartDeptIds().stream() : Stream.empty(); 94 return metaInfo != null && metaInfo.getStartDeptIds() != null ? metaInfo.getStartDeptIds().stream() : Stream.empty();
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/BpmModelMetaInfoVO.java
@@ -59,7 +59,7 @@ public class BpmModelMetaInfoVO { @@ -59,7 +59,7 @@ 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 = "可发起部门编号数组") 62 + @Schema(description = "可发起部门编号数组", example = "[2,4,6]")
63 private List<Long> startDeptIds; 63 private List<Long> startDeptIds;
64 64
65 @Schema(description = "可管理用户编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[2,4,6]") 65 @Schema(description = "可管理用户编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[2,4,6]")
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/definition/BpmModelConvert.java
@@ -76,8 +76,7 @@ public interface BpmModelConvert { @@ -76,8 +76,7 @@ public interface BpmModelConvert {
76 default BpmModelRespVO buildModel0(Model model, 76 default BpmModelRespVO buildModel0(Model model,
77 BpmModelMetaInfoVO metaInfo, BpmFormDO form, BpmCategoryDO category, 77 BpmModelMetaInfoVO metaInfo, BpmFormDO form, BpmCategoryDO category,
78 Deployment deployment, ProcessDefinition processDefinition, 78 Deployment deployment, ProcessDefinition processDefinition,
79 - List<AdminUserRespDTO> startUsers,  
80 - List<DeptRespDTO> startDepts) { 79 + List<AdminUserRespDTO> startUsers, List<DeptRespDTO> startDepts) {
81 BpmModelRespVO modelRespVO = new BpmModelRespVO().setId(model.getId()).setName(model.getName()) 80 BpmModelRespVO modelRespVO = new BpmModelRespVO().setId(model.getId()).setName(model.getName())
82 .setKey(model.getKey()).setCategory(model.getCategory()) 81 .setKey(model.getKey()).setCategory(model.getCategory())
83 .setCreateTime(DateUtils.of(model.getCreateTime())); 82 .setCreateTime(DateUtils.of(model.getCreateTime()));
@@ -99,10 +98,9 @@ public interface BpmModelConvert { @@ -99,10 +98,9 @@ public interface BpmModelConvert {
99 modelRespVO.getProcessDefinition().setDeploymentTime(DateUtils.of(deployment.getDeploymentTime())); 98 modelRespVO.getProcessDefinition().setDeploymentTime(DateUtils.of(deployment.getDeploymentTime()));
100 } 99 }
101 } 100 }
102 - // User  
103 - modelRespVO.setStartUsers(BeanUtils.toBean(startUsers, UserSimpleBaseVO.class));  
104 - // Dept  
105 - modelRespVO.setStartDepts(BeanUtils.toBean(startDepts, DeptSimpleBaseVO.class)); 101 + // User、Dept
  102 + modelRespVO.setStartUsers(BeanUtils.toBean(startUsers, UserSimpleBaseVO.class))
  103 + .setStartDepts(BeanUtils.toBean(startDepts, DeptSimpleBaseVO.class));
106 return modelRespVO; 104 return modelRespVO;
107 } 105 }
108 106
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/dataobject/definition/BpmProcessDefinitionInfoDO.java
@@ -154,7 +154,7 @@ public class BpmProcessDefinitionInfoDO extends BaseDO { @@ -154,7 +154,7 @@ public class BpmProcessDefinitionInfoDO extends BaseDO {
154 /** 154 /**
155 * 可发起部门编号数组 155 * 可发起部门编号数组
156 * 156 *
157 - * 关联 {@link AdminUserRespDTO#getId()} 字段的数组 157 + * 关联 {@link AdminUserRespDTO#getDeptId()} 字段的数组
158 */ 158 */
159 @TableField(typeHandler = LongListTypeHandler.class) 159 @TableField(typeHandler = LongListTypeHandler.class)
160 private List<Long> startDeptIds; 160 private List<Long> startDeptIds;
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmProcessDefinitionServiceImpl.java
@@ -51,6 +51,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ @@ -51,6 +51,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
51 51
52 @Resource 52 @Resource
53 private BpmProcessDefinitionInfoMapper processDefinitionMapper; 53 private BpmProcessDefinitionInfoMapper processDefinitionMapper;
  54 +
54 @Resource 55 @Resource
55 private AdminUserApi adminUserApi; 56 private AdminUserApi adminUserApi;
56 57
@@ -93,18 +94,17 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ @@ -93,18 +94,17 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
93 return false; 94 return false;
94 } 95 }
95 96
96 - // 获取用户所在部门  
97 - AdminUserRespDTO user = adminUserApi.getUser(userId);  
98 - Long userDeptId = user != null ? user.getDeptId() : null;  
99 -  
100 // 校验用户是否在允许发起的用户列表中 97 // 校验用户是否在允许发起的用户列表中
101 - if (!CollUtil.isEmpty(processDefinition.getStartUserIds())) { 98 + if (CollUtil.isNotEmpty(processDefinition.getStartUserIds())) {
102 return processDefinition.getStartUserIds().contains(userId); 99 return processDefinition.getStartUserIds().contains(userId);
103 } 100 }
104 101
105 // 校验用户是否在允许发起的部门列表中 102 // 校验用户是否在允许发起的部门列表中
106 - if (!CollUtil.isEmpty(processDefinition.getStartDeptIds()) && userDeptId != null) {  
107 - return processDefinition.getStartDeptIds().contains(userDeptId); 103 + if (CollUtil.isNotEmpty(processDefinition.getStartDeptIds())) {
  104 + AdminUserRespDTO user = adminUserApi.getUser(userId);
  105 + return user != null
  106 + && user.getDeptId() != null
  107 + && processDefinition.getStartDeptIds().contains(user.getDeptId());
108 } 108 }
109 109
110 // 都为空,则所有人都可以发起 110 // 都为空,则所有人都可以发起