mirror of
				https://github.com/YunaiV/ruoyi-vue-pro.git
				synced 2025-10-31 02:28:03 +08:00 
			
		
		
		
	code review:工作流的加减签
This commit is contained in:
		| @ -3,7 +3,6 @@ package cn.iocoder.yudao.framework.common.util.collection; | |||||||
| import cn.hutool.core.collection.CollUtil; | import cn.hutool.core.collection.CollUtil; | ||||||
| import cn.hutool.core.collection.CollectionUtil; | import cn.hutool.core.collection.CollectionUtil; | ||||||
| import cn.hutool.core.util.ArrayUtil; | import cn.hutool.core.util.ArrayUtil; | ||||||
| import cn.iocoder.yudao.framework.common.util.number.NumberUtils; |  | ||||||
| import com.google.common.collect.ImmutableMap; | import com.google.common.collect.ImmutableMap; | ||||||
|  |  | ||||||
| import java.util.*; | import java.util.*; | ||||||
| @ -269,7 +268,7 @@ public class CollectionUtils { | |||||||
|         return deptId == null ? Collections.emptyList() : Collections.singleton(deptId); |         return deptId == null ? Collections.emptyList() : Collections.singleton(deptId); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static <T, U> List<U> convertListByMultiAttr(Collection<T> from, |     public static <T, U> List<U> convertListByFlatMap(Collection<T> from, | ||||||
|                                                       Function<T, ? extends Stream<? extends U>> func) { |                                                       Function<T, ? extends Stream<? extends U>> func) { | ||||||
|         if (CollUtil.isEmpty(from)) { |         if (CollUtil.isEmpty(from)) { | ||||||
|             return new ArrayList<>(); |             return new ArrayList<>(); | ||||||
| @ -277,11 +276,12 @@ public class CollectionUtils { | |||||||
|         return from.stream().flatMap(func).filter(Objects::nonNull).collect(Collectors.toList()); |         return from.stream().flatMap(func).filter(Objects::nonNull).collect(Collectors.toList()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static <T, U> Set<U> convertSetByMultiAttr(Collection<T> from, |     public static <T, U> Set<U> convertSetByFlatMap(Collection<T> from, | ||||||
|                                                     Function<T, ? extends Stream<? extends U>> func) { |                                                     Function<T, ? extends Stream<? extends U>> func) { | ||||||
|         if (CollUtil.isEmpty(from)) { |         if (CollUtil.isEmpty(from)) { | ||||||
|             return new HashSet<>(); |             return new HashSet<>(); | ||||||
|         } |         } | ||||||
|         return from.stream().flatMap(func).filter(Objects::nonNull).collect(Collectors.toSet()); |         return from.stream().flatMap(func).filter(Objects::nonNull).collect(Collectors.toSet()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -101,22 +101,22 @@ public class BpmTaskController { | |||||||
|     @PutMapping("/create-sign") |     @PutMapping("/create-sign") | ||||||
|     @Operation(summary = "加签", description = "before 前加签,after 后加签") |     @Operation(summary = "加签", description = "before 前加签,after 后加签") | ||||||
|     @PreAuthorize("@ss.hasPermission('bpm:task:update')") |     @PreAuthorize("@ss.hasPermission('bpm:task:update')") | ||||||
|     public CommonResult<Boolean> addSignTask(@Valid @RequestBody BpmTaskAddSignReqVO reqVO) { |     public CommonResult<Boolean> createSignTask(@Valid @RequestBody BpmTaskAddSignReqVO reqVO) { | ||||||
|         taskService.addSignTask(getLoginUserId(), reqVO); |         taskService.createSignTask(getLoginUserId(), reqVO); | ||||||
|         return success(true); |         return success(true); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @DeleteMapping("/delete-sign") |     @DeleteMapping("/delete-sign") | ||||||
|     @Operation(summary = "减签") |     @Operation(summary = "减签") | ||||||
|     @PreAuthorize("@ss.hasPermission('bpm:task:update')") |     @PreAuthorize("@ss.hasPermission('bpm:task:update')") | ||||||
|     public CommonResult<Boolean> subSignTask(@Valid @RequestBody BpmTaskSubSignReqVO reqVO) { |     public CommonResult<Boolean> deleteSignTask(@Valid @RequestBody BpmTaskSubSignReqVO reqVO) { | ||||||
|         taskService.subSignTask(getLoginUserId(), reqVO); |         taskService.deleteSignTask(getLoginUserId(), reqVO); | ||||||
|         return success(true); |         return success(true); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @GetMapping("children-list") |     @GetMapping("children-list") | ||||||
|     @Operation(summary = "获取能被减签的任务") |     @Operation(summary = "获取能被减签的任务") | ||||||
|     @Parameter(name = "parentId", description = "父级任务ID", required = true) |     @Parameter(name = "parentId", description = "父级任务 ID", required = true) | ||||||
|     @PreAuthorize("@ss.hasPermission('bpm:task:update')") |     @PreAuthorize("@ss.hasPermission('bpm:task:update')") | ||||||
|     public CommonResult<List<BpmTaskSubSignRespVO>> getChildrenTaskList(@RequestParam("parentId") String parentId) { |     public CommonResult<List<BpmTaskSubSignRespVO>> getChildrenTaskList(@RequestParam("parentId") String parentId) { | ||||||
|         return success(taskService.getChildrenTaskList(parentId)); |         return success(taskService.getChildrenTaskList(parentId)); | ||||||
|  | |||||||
| @ -1,6 +1,5 @@ | |||||||
| package cn.iocoder.yudao.module.bpm.convert.task; | package cn.iocoder.yudao.module.bpm.convert.task; | ||||||
|  |  | ||||||
| import cn.hutool.core.collection.CollUtil; |  | ||||||
| import cn.hutool.core.date.LocalDateTimeUtil; | import cn.hutool.core.date.LocalDateTimeUtil; | ||||||
| import cn.hutool.core.util.ObjectUtil; | import cn.hutool.core.util.ObjectUtil; | ||||||
| import cn.hutool.core.util.StrUtil; | import cn.hutool.core.util.StrUtil; | ||||||
| @ -27,6 +26,9 @@ import java.util.Date; | |||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
|  |  | ||||||
|  | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap; | ||||||
|  | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Bpm 任务 Convert |  * Bpm 任务 Convert | ||||||
|  * |  * | ||||||
| @ -171,9 +173,7 @@ public interface BpmTaskConvert { | |||||||
|                                                    Map<String, Task> idTaskMap){ |                                                    Map<String, Task> idTaskMap){ | ||||||
|         return CollectionUtils.convertList(bpmTaskExtDOList, task -> { |         return CollectionUtils.convertList(bpmTaskExtDOList, task -> { | ||||||
|             BpmTaskSubSignRespVO bpmTaskSubSignRespVO = new BpmTaskSubSignRespVO() |             BpmTaskSubSignRespVO bpmTaskSubSignRespVO = new BpmTaskSubSignRespVO() | ||||||
|                     .setName(task.getName()) |                     .setId(task.getTaskId()).setName(task.getName()); | ||||||
|                     .setId(task.getTaskId()); |  | ||||||
|  |  | ||||||
|             // 后加签任务不会直接设置 assignee ,所以不存在 assignee 的情况,则去取 owner |             // 后加签任务不会直接设置 assignee ,所以不存在 assignee 的情况,则去取 owner | ||||||
|             Task sourceTask = idTaskMap.get(task.getTaskId()); |             Task sourceTask = idTaskMap.get(task.getTaskId()); | ||||||
|             String assignee = ObjectUtil.defaultIfBlank(sourceTask.getOwner(),sourceTask.getAssignee()); |             String assignee = ObjectUtil.defaultIfBlank(sourceTask.getOwner(),sourceTask.getAssignee()); | ||||||
| @ -190,12 +190,12 @@ public interface BpmTaskConvert { | |||||||
|      * @return 转换后的父子级数组 |      * @return 转换后的父子级数组 | ||||||
|      */ |      */ | ||||||
|     default List<BpmTaskRespVO> convertChildrenList(List<BpmTaskRespVO> sourceList) { |     default List<BpmTaskRespVO> convertChildrenList(List<BpmTaskRespVO> sourceList) { | ||||||
|         List<BpmTaskRespVO> childrenTaskList = CollectionUtils.filterList(sourceList, r -> StrUtil.isNotEmpty(r.getParentTaskId())); |         List<BpmTaskRespVO> childrenTaskList = filterList(sourceList, r -> StrUtil.isNotEmpty(r.getParentTaskId())); | ||||||
|         Map<String, List<BpmTaskRespVO>> parentChildrenTaskListMap = CollectionUtils.convertMultiMap(childrenTaskList, BpmTaskRespVO::getParentTaskId); |         Map<String, List<BpmTaskRespVO>> parentChildrenTaskListMap = convertMultiMap(childrenTaskList, BpmTaskRespVO::getParentTaskId); | ||||||
|         for (BpmTaskRespVO bpmTaskRespVO : sourceList) { |         for (BpmTaskRespVO bpmTaskRespVO : sourceList) { | ||||||
|             bpmTaskRespVO.setChildren(parentChildrenTaskListMap.get(bpmTaskRespVO.getId())); |             bpmTaskRespVO.setChildren(parentChildrenTaskListMap.get(bpmTaskRespVO.getId())); | ||||||
|         } |         } | ||||||
|         return CollectionUtils.filterList(sourceList, r -> StrUtil.isEmpty(r.getParentTaskId())); |         return filterList(sourceList, r -> StrUtil.isEmpty(r.getParentTaskId())); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -163,7 +163,7 @@ public interface BpmTaskService { | |||||||
|      * @param userId 被加签的用户和任务 ID,加签类型 |      * @param userId 被加签的用户和任务 ID,加签类型 | ||||||
|      * @param reqVO  当前用户 ID |      * @param reqVO  当前用户 ID | ||||||
|      */ |      */ | ||||||
|     void addSignTask(Long userId, BpmTaskAddSignReqVO reqVO); |     void createSignTask(Long userId, BpmTaskAddSignReqVO reqVO); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 任务减签名 |      * 任务减签名 | ||||||
| @ -171,7 +171,7 @@ public interface BpmTaskService { | |||||||
|      * @param userId 当前用户ID |      * @param userId 当前用户ID | ||||||
|      * @param reqVO  被减签的任务 ID,理由 |      * @param reqVO  被减签的任务 ID,理由 | ||||||
|      */ |      */ | ||||||
|     void subSignTask(Long userId, BpmTaskSubSignReqVO reqVO); |     void deleteSignTask(Long userId, BpmTaskSubSignReqVO reqVO); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 获取指定任务的子任务和审批人信息 |      * 获取指定任务的子任务和审批人信息 | ||||||
|  | |||||||
| @ -711,7 +711,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { | |||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     @Transactional(rollbackFor = Exception.class) |     @Transactional(rollbackFor = Exception.class) | ||||||
|     public void addSignTask(Long userId, BpmTaskAddSignReqVO reqVO) { |     public void createSignTask(Long userId, BpmTaskAddSignReqVO reqVO) { | ||||||
|         // 1. 获取和校验任务 |         // 1. 获取和校验任务 | ||||||
|         TaskEntityImpl taskEntity = validateAddSign(userId, reqVO); |         TaskEntityImpl taskEntity = validateAddSign(userId, reqVO); | ||||||
|         List<AdminUserRespDTO> userList = adminUserApi.getUserList(reqVO.getUserIdList()); |         List<AdminUserRespDTO> userList = adminUserApi.getUserList(reqVO.getUserIdList()); | ||||||
| @ -826,7 +826,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { | |||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     @Transactional(rollbackFor = Exception.class) |     @Transactional(rollbackFor = Exception.class) | ||||||
|     public void subSignTask(Long userId, BpmTaskSubSignReqVO reqVO) { |     public void deleteSignTask(Long userId, BpmTaskSubSignReqVO reqVO) { | ||||||
|         // 1.1 校验 task 可以被减签 |         // 1.1 校验 task 可以被减签 | ||||||
|         Task task = validateSubSign(reqVO.getId()); |         Task task = validateSubSign(reqVO.getId()); | ||||||
|         // 1.2 校验取消人存在 |         // 1.2 校验取消人存在 | ||||||
| @ -902,12 +902,14 @@ public class BpmTaskServiceImpl implements BpmTaskService { | |||||||
|         stack.push(parentTaskId); |         stack.push(parentTaskId); | ||||||
|         //控制遍历的次数不超过 Byte.MAX_VALUE,避免脏数据造成死循环 |         //控制遍历的次数不超过 Byte.MAX_VALUE,避免脏数据造成死循环 | ||||||
|         int count = 0; |         int count = 0; | ||||||
|  |         // TODO @海:< 的前后空格,要注意哈; | ||||||
|         while (!stack.isEmpty() && count<Byte.MAX_VALUE) { |         while (!stack.isEmpty() && count<Byte.MAX_VALUE) { | ||||||
|             // 1.2 弹出栈顶任务ID |             // 1.2 弹出栈顶任务ID | ||||||
|             String taskId = stack.pop(); |             String taskId = stack.pop(); | ||||||
|             // 1.3 将任务ID添加到结果集合中 |             // 1.3 将任务ID添加到结果集合中 | ||||||
|             allChildTaskIds.add(taskId); |             allChildTaskIds.add(taskId); | ||||||
|             // 1.4 获取该任务的子任务列表 |             // 1.4 获取该任务的子任务列表 | ||||||
|  |             // TODO @海:有个更高效的写法;一次性去 in 一层;不然每个节点,都去查询一次 db, 太浪费了;每次 in,最终就是 O(h) 查询,而不是 O(n) 查询; | ||||||
|             List<String> childrenTaskIdList = getChildrenTaskIdList(taskId); |             List<String> childrenTaskIdList = getChildrenTaskIdList(taskId); | ||||||
|             if (CollUtil.isNotEmpty(childrenTaskIdList)) { |             if (CollUtil.isNotEmpty(childrenTaskIdList)) { | ||||||
|                 for (String childTaskId : childrenTaskIdList) { |                 for (String childTaskId : childrenTaskIdList) { | ||||||
| @ -920,7 +922,6 @@ public class BpmTaskServiceImpl implements BpmTaskService { | |||||||
|         return allChildTaskIds; |         return allChildTaskIds; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 获取指定父级任务的所有子任务 ID 集合 |      * 获取指定父级任务的所有子任务 ID 集合 | ||||||
|      * |      * | ||||||
| @ -954,13 +955,11 @@ public class BpmTaskServiceImpl implements BpmTaskService { | |||||||
|         } |         } | ||||||
|         List<String> childrenTaskIdList = convertList(taskList, Task::getId); |         List<String> childrenTaskIdList = convertList(taskList, Task::getId); | ||||||
|  |  | ||||||
|  |         // 2.1 将 owner 和 assignee 统一到一个集合中 | ||||||
|         // 2. 将 owner 和 assignee 统一到一个集合中 |         List<Long> userIds = convertListByFlatMap(taskList, control -> | ||||||
|         List<Long> userIds = convertListByMultiAttr(taskList,control -> |  | ||||||
|                 Stream.of(NumberUtils.parseLong(control.getAssignee()), NumberUtils.parseLong(control.getOwner())) |                 Stream.of(NumberUtils.parseLong(control.getAssignee()), NumberUtils.parseLong(control.getOwner())) | ||||||
|                         .filter(Objects::nonNull)); |                         .filter(Objects::nonNull)); | ||||||
|  |         // 2.2 组装数据 | ||||||
|         // 3. 组装数据 |  | ||||||
|         Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds); |         Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds); | ||||||
|         List<BpmTaskExtDO> taskExtList = taskExtMapper.selectProcessListByTaskIds(childrenTaskIdList); |         List<BpmTaskExtDO> taskExtList = taskExtMapper.selectProcessListByTaskIds(childrenTaskIdList); | ||||||
|         Map<String, Task> idTaskMap = convertMap(taskList, TaskInfo::getId); |         Map<String, Task> idTaskMap = convertMap(taskList, TaskInfo::getId); | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV