Commit 3bb3e4caf6a929b5e53eab74ca43960dbaa5d80d

Authored by YunaiV
1 parent cc67174f

code review:工作流的加减签

yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java
@@ -3,7 +3,6 @@ package cn.iocoder.yudao.framework.common.util.collection; @@ -3,7 +3,6 @@ package cn.iocoder.yudao.framework.common.util.collection;
3 import cn.hutool.core.collection.CollUtil; 3 import cn.hutool.core.collection.CollUtil;
4 import cn.hutool.core.collection.CollectionUtil; 4 import cn.hutool.core.collection.CollectionUtil;
5 import cn.hutool.core.util.ArrayUtil; 5 import cn.hutool.core.util.ArrayUtil;
6 -import cn.iocoder.yudao.framework.common.util.number.NumberUtils;  
7 import com.google.common.collect.ImmutableMap; 6 import com.google.common.collect.ImmutableMap;
8 7
9 import java.util.*; 8 import java.util.*;
@@ -269,7 +268,7 @@ public class CollectionUtils { @@ -269,7 +268,7 @@ public class CollectionUtils {
269 return deptId == null ? Collections.emptyList() : Collections.singleton(deptId); 268 return deptId == null ? Collections.emptyList() : Collections.singleton(deptId);
270 } 269 }
271 270
272 - public static <T, U> List<U> convertListByMultiAttr(Collection<T> from, 271 + public static <T, U> List<U> convertListByFlatMap(Collection<T> from,
273 Function<T, ? extends Stream<? extends U>> func) { 272 Function<T, ? extends Stream<? extends U>> func) {
274 if (CollUtil.isEmpty(from)) { 273 if (CollUtil.isEmpty(from)) {
275 return new ArrayList<>(); 274 return new ArrayList<>();
@@ -277,11 +276,12 @@ public class CollectionUtils { @@ -277,11 +276,12 @@ public class CollectionUtils {
277 return from.stream().flatMap(func).filter(Objects::nonNull).collect(Collectors.toList()); 276 return from.stream().flatMap(func).filter(Objects::nonNull).collect(Collectors.toList());
278 } 277 }
279 278
280 - public static <T, U> Set<U> convertSetByMultiAttr(Collection<T> from,  
281 - Function<T, ? extends Stream<? extends U>> func) { 279 + public static <T, U> Set<U> convertSetByFlatMap(Collection<T> from,
  280 + Function<T, ? extends Stream<? extends U>> func) {
282 if (CollUtil.isEmpty(from)) { 281 if (CollUtil.isEmpty(from)) {
283 return new HashSet<>(); 282 return new HashSet<>();
284 } 283 }
285 return from.stream().flatMap(func).filter(Objects::nonNull).collect(Collectors.toSet()); 284 return from.stream().flatMap(func).filter(Objects::nonNull).collect(Collectors.toSet());
286 } 285 }
  286 +
287 } 287 }
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/BpmTaskController.java
@@ -101,22 +101,22 @@ public class BpmTaskController { @@ -101,22 +101,22 @@ public class BpmTaskController {
101 @PutMapping("/create-sign") 101 @PutMapping("/create-sign")
102 @Operation(summary = "加签", description = "before 前加签,after 后加签") 102 @Operation(summary = "加签", description = "before 前加签,after 后加签")
103 @PreAuthorize("@ss.hasPermission('bpm:task:update')") 103 @PreAuthorize("@ss.hasPermission('bpm:task:update')")
104 - public CommonResult<Boolean> addSignTask(@Valid @RequestBody BpmTaskAddSignReqVO reqVO) {  
105 - taskService.addSignTask(getLoginUserId(), reqVO); 104 + public CommonResult<Boolean> createSignTask(@Valid @RequestBody BpmTaskAddSignReqVO reqVO) {
  105 + taskService.createSignTask(getLoginUserId(), reqVO);
106 return success(true); 106 return success(true);
107 } 107 }
108 108
109 @DeleteMapping("/delete-sign") 109 @DeleteMapping("/delete-sign")
110 @Operation(summary = "减签") 110 @Operation(summary = "减签")
111 @PreAuthorize("@ss.hasPermission('bpm:task:update')") 111 @PreAuthorize("@ss.hasPermission('bpm:task:update')")
112 - public CommonResult<Boolean> subSignTask(@Valid @RequestBody BpmTaskSubSignReqVO reqVO) {  
113 - taskService.subSignTask(getLoginUserId(), reqVO); 112 + public CommonResult<Boolean> deleteSignTask(@Valid @RequestBody BpmTaskSubSignReqVO reqVO) {
  113 + taskService.deleteSignTask(getLoginUserId(), reqVO);
114 return success(true); 114 return success(true);
115 } 115 }
116 116
117 @GetMapping("children-list") 117 @GetMapping("children-list")
118 @Operation(summary = "获取能被减签的任务") 118 @Operation(summary = "获取能被减签的任务")
119 - @Parameter(name = "parentId", description = "父级任务ID", required = true) 119 + @Parameter(name = "parentId", description = "父级任务 ID", required = true)
120 @PreAuthorize("@ss.hasPermission('bpm:task:update')") 120 @PreAuthorize("@ss.hasPermission('bpm:task:update')")
121 public CommonResult<List<BpmTaskSubSignRespVO>> getChildrenTaskList(@RequestParam("parentId") String parentId) { 121 public CommonResult<List<BpmTaskSubSignRespVO>> getChildrenTaskList(@RequestParam("parentId") String parentId) {
122 return success(taskService.getChildrenTaskList(parentId)); 122 return success(taskService.getChildrenTaskList(parentId));
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/task/BpmTaskConvert.java
1 package cn.iocoder.yudao.module.bpm.convert.task; 1 package cn.iocoder.yudao.module.bpm.convert.task;
2 2
3 -import cn.hutool.core.collection.CollUtil;  
4 import cn.hutool.core.date.LocalDateTimeUtil; 3 import cn.hutool.core.date.LocalDateTimeUtil;
5 import cn.hutool.core.util.ObjectUtil; 4 import cn.hutool.core.util.ObjectUtil;
6 import cn.hutool.core.util.StrUtil; 5 import cn.hutool.core.util.StrUtil;
@@ -27,6 +26,9 @@ import java.util.Date; @@ -27,6 +26,9 @@ import java.util.Date;
27 import java.util.List; 26 import java.util.List;
28 import java.util.Map; 27 import java.util.Map;
29 28
  29 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap;
  30 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
  31 +
30 /** 32 /**
31 * Bpm 任务 Convert 33 * Bpm 任务 Convert
32 * 34 *
@@ -171,9 +173,7 @@ public interface BpmTaskConvert { @@ -171,9 +173,7 @@ public interface BpmTaskConvert {
171 Map<String, Task> idTaskMap){ 173 Map<String, Task> idTaskMap){
172 return CollectionUtils.convertList(bpmTaskExtDOList, task -> { 174 return CollectionUtils.convertList(bpmTaskExtDOList, task -> {
173 BpmTaskSubSignRespVO bpmTaskSubSignRespVO = new BpmTaskSubSignRespVO() 175 BpmTaskSubSignRespVO bpmTaskSubSignRespVO = new BpmTaskSubSignRespVO()
174 - .setName(task.getName())  
175 - .setId(task.getTaskId());  
176 - 176 + .setId(task.getTaskId()).setName(task.getName());
177 // 后加签任务不会直接设置 assignee ,所以不存在 assignee 的情况,则去取 owner 177 // 后加签任务不会直接设置 assignee ,所以不存在 assignee 的情况,则去取 owner
178 Task sourceTask = idTaskMap.get(task.getTaskId()); 178 Task sourceTask = idTaskMap.get(task.getTaskId());
179 String assignee = ObjectUtil.defaultIfBlank(sourceTask.getOwner(),sourceTask.getAssignee()); 179 String assignee = ObjectUtil.defaultIfBlank(sourceTask.getOwner(),sourceTask.getAssignee());
@@ -190,12 +190,12 @@ public interface BpmTaskConvert { @@ -190,12 +190,12 @@ public interface BpmTaskConvert {
190 * @return 转换后的父子级数组 190 * @return 转换后的父子级数组
191 */ 191 */
192 default List<BpmTaskRespVO> convertChildrenList(List<BpmTaskRespVO> sourceList) { 192 default List<BpmTaskRespVO> convertChildrenList(List<BpmTaskRespVO> sourceList) {
193 - List<BpmTaskRespVO> childrenTaskList = CollectionUtils.filterList(sourceList, r -> StrUtil.isNotEmpty(r.getParentTaskId()));  
194 - Map<String, List<BpmTaskRespVO>> parentChildrenTaskListMap = CollectionUtils.convertMultiMap(childrenTaskList, BpmTaskRespVO::getParentTaskId); 193 + List<BpmTaskRespVO> childrenTaskList = filterList(sourceList, r -> StrUtil.isNotEmpty(r.getParentTaskId()));
  194 + Map<String, List<BpmTaskRespVO>> parentChildrenTaskListMap = convertMultiMap(childrenTaskList, BpmTaskRespVO::getParentTaskId);
195 for (BpmTaskRespVO bpmTaskRespVO : sourceList) { 195 for (BpmTaskRespVO bpmTaskRespVO : sourceList) {
196 bpmTaskRespVO.setChildren(parentChildrenTaskListMap.get(bpmTaskRespVO.getId())); 196 bpmTaskRespVO.setChildren(parentChildrenTaskListMap.get(bpmTaskRespVO.getId()));
197 } 197 }
198 - return CollectionUtils.filterList(sourceList, r -> StrUtil.isEmpty(r.getParentTaskId())); 198 + return filterList(sourceList, r -> StrUtil.isEmpty(r.getParentTaskId()));
199 } 199 }
200 200
201 } 201 }
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java
@@ -163,7 +163,7 @@ public interface BpmTaskService { @@ -163,7 +163,7 @@ public interface BpmTaskService {
163 * @param userId 被加签的用户和任务 ID,加签类型 163 * @param userId 被加签的用户和任务 ID,加签类型
164 * @param reqVO 当前用户 ID 164 * @param reqVO 当前用户 ID
165 */ 165 */
166 - void addSignTask(Long userId, BpmTaskAddSignReqVO reqVO); 166 + void createSignTask(Long userId, BpmTaskAddSignReqVO reqVO);
167 167
168 /** 168 /**
169 * 任务减签名 169 * 任务减签名
@@ -171,7 +171,7 @@ public interface BpmTaskService { @@ -171,7 +171,7 @@ public interface BpmTaskService {
171 * @param userId 当前用户ID 171 * @param userId 当前用户ID
172 * @param reqVO 被减签的任务 ID,理由 172 * @param reqVO 被减签的任务 ID,理由
173 */ 173 */
174 - void subSignTask(Long userId, BpmTaskSubSignReqVO reqVO); 174 + void deleteSignTask(Long userId, BpmTaskSubSignReqVO reqVO);
175 175
176 /** 176 /**
177 * 获取指定任务的子任务和审批人信息 177 * 获取指定任务的子任务和审批人信息
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
@@ -711,7 +711,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -711,7 +711,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
711 711
712 @Override 712 @Override
713 @Transactional(rollbackFor = Exception.class) 713 @Transactional(rollbackFor = Exception.class)
714 - public void addSignTask(Long userId, BpmTaskAddSignReqVO reqVO) { 714 + public void createSignTask(Long userId, BpmTaskAddSignReqVO reqVO) {
715 // 1. 获取和校验任务 715 // 1. 获取和校验任务
716 TaskEntityImpl taskEntity = validateAddSign(userId, reqVO); 716 TaskEntityImpl taskEntity = validateAddSign(userId, reqVO);
717 List<AdminUserRespDTO> userList = adminUserApi.getUserList(reqVO.getUserIdList()); 717 List<AdminUserRespDTO> userList = adminUserApi.getUserList(reqVO.getUserIdList());
@@ -826,7 +826,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -826,7 +826,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
826 826
827 @Override 827 @Override
828 @Transactional(rollbackFor = Exception.class) 828 @Transactional(rollbackFor = Exception.class)
829 - public void subSignTask(Long userId, BpmTaskSubSignReqVO reqVO) { 829 + public void deleteSignTask(Long userId, BpmTaskSubSignReqVO reqVO) {
830 // 1.1 校验 task 可以被减签 830 // 1.1 校验 task 可以被减签
831 Task task = validateSubSign(reqVO.getId()); 831 Task task = validateSubSign(reqVO.getId());
832 // 1.2 校验取消人存在 832 // 1.2 校验取消人存在
@@ -902,12 +902,14 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -902,12 +902,14 @@ public class BpmTaskServiceImpl implements BpmTaskService {
902 stack.push(parentTaskId); 902 stack.push(parentTaskId);
903 //控制遍历的次数不超过 Byte.MAX_VALUE,避免脏数据造成死循环 903 //控制遍历的次数不超过 Byte.MAX_VALUE,避免脏数据造成死循环
904 int count = 0; 904 int count = 0;
  905 + // TODO @海:< 的前后空格,要注意哈;
905 while (!stack.isEmpty() && count<Byte.MAX_VALUE) { 906 while (!stack.isEmpty() && count<Byte.MAX_VALUE) {
906 // 1.2 弹出栈顶任务ID 907 // 1.2 弹出栈顶任务ID
907 String taskId = stack.pop(); 908 String taskId = stack.pop();
908 // 1.3 将任务ID添加到结果集合中 909 // 1.3 将任务ID添加到结果集合中
909 allChildTaskIds.add(taskId); 910 allChildTaskIds.add(taskId);
910 // 1.4 获取该任务的子任务列表 911 // 1.4 获取该任务的子任务列表
  912 + // TODO @海:有个更高效的写法;一次性去 in 一层;不然每个节点,都去查询一次 db, 太浪费了;每次 in,最终就是 O(h) 查询,而不是 O(n) 查询;
911 List<String> childrenTaskIdList = getChildrenTaskIdList(taskId); 913 List<String> childrenTaskIdList = getChildrenTaskIdList(taskId);
912 if (CollUtil.isNotEmpty(childrenTaskIdList)) { 914 if (CollUtil.isNotEmpty(childrenTaskIdList)) {
913 for (String childTaskId : childrenTaskIdList) { 915 for (String childTaskId : childrenTaskIdList) {
@@ -920,7 +922,6 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -920,7 +922,6 @@ public class BpmTaskServiceImpl implements BpmTaskService {
920 return allChildTaskIds; 922 return allChildTaskIds;
921 } 923 }
922 924
923 -  
924 /** 925 /**
925 * 获取指定父级任务的所有子任务 ID 集合 926 * 获取指定父级任务的所有子任务 ID 集合
926 * 927 *
@@ -954,13 +955,11 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -954,13 +955,11 @@ public class BpmTaskServiceImpl implements BpmTaskService {
954 } 955 }
955 List<String> childrenTaskIdList = convertList(taskList, Task::getId); 956 List<String> childrenTaskIdList = convertList(taskList, Task::getId);
956 957
957 -  
958 - // 2. 将 owner 和 assignee 统一到一个集合中  
959 - List<Long> userIds = convertListByMultiAttr(taskList,control -> 958 + // 2.1 将 owner 和 assignee 统一到一个集合中
  959 + List<Long> userIds = convertListByFlatMap(taskList, control ->
960 Stream.of(NumberUtils.parseLong(control.getAssignee()), NumberUtils.parseLong(control.getOwner())) 960 Stream.of(NumberUtils.parseLong(control.getAssignee()), NumberUtils.parseLong(control.getOwner()))
961 .filter(Objects::nonNull)); 961 .filter(Objects::nonNull));
962 -  
963 - // 3. 组装数据 962 + // 2.2 组装数据
964 Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds); 963 Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
965 List<BpmTaskExtDO> taskExtList = taskExtMapper.selectProcessListByTaskIds(childrenTaskIdList); 964 List<BpmTaskExtDO> taskExtList = taskExtMapper.selectProcessListByTaskIds(childrenTaskIdList);
966 Map<String, Task> idTaskMap = convertMap(taskList, TaskInfo::getId); 965 Map<String, Task> idTaskMap = convertMap(taskList, TaskInfo::getId);