code review:工作流的加减签

This commit is contained in:
YunaiV 2023-10-21 21:04:20 +08:00
parent cc67174f87
commit 3bb3e4caf6
5 changed files with 25 additions and 26 deletions

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.framework.common.util.collection;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
import com.google.common.collect.ImmutableMap;
import java.util.*;
@ -269,7 +268,7 @@ public class CollectionUtils {
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) {
if (CollUtil.isEmpty(from)) {
return new ArrayList<>();
@ -277,11 +276,12 @@ public class CollectionUtils {
return from.stream().flatMap(func).filter(Objects::nonNull).collect(Collectors.toList());
}
public static <T, U> Set<U> convertSetByMultiAttr(Collection<T> from,
Function<T, ? extends Stream<? extends U>> func) {
public static <T, U> Set<U> convertSetByFlatMap(Collection<T> from,
Function<T, ? extends Stream<? extends U>> func) {
if (CollUtil.isEmpty(from)) {
return new HashSet<>();
}
return from.stream().flatMap(func).filter(Objects::nonNull).collect(Collectors.toSet());
}
}

View File

@ -101,22 +101,22 @@ public class BpmTaskController {
@PutMapping("/create-sign")
@Operation(summary = "加签", description = "before 前加签after 后加签")
@PreAuthorize("@ss.hasPermission('bpm:task:update')")
public CommonResult<Boolean> addSignTask(@Valid @RequestBody BpmTaskAddSignReqVO reqVO) {
taskService.addSignTask(getLoginUserId(), reqVO);
public CommonResult<Boolean> createSignTask(@Valid @RequestBody BpmTaskAddSignReqVO reqVO) {
taskService.createSignTask(getLoginUserId(), reqVO);
return success(true);
}
@DeleteMapping("/delete-sign")
@Operation(summary = "减签")
@PreAuthorize("@ss.hasPermission('bpm:task:update')")
public CommonResult<Boolean> subSignTask(@Valid @RequestBody BpmTaskSubSignReqVO reqVO) {
taskService.subSignTask(getLoginUserId(), reqVO);
public CommonResult<Boolean> deleteSignTask(@Valid @RequestBody BpmTaskSubSignReqVO reqVO) {
taskService.deleteSignTask(getLoginUserId(), reqVO);
return success(true);
}
@GetMapping("children-list")
@Operation(summary = "获取能被减签的任务")
@Parameter(name = "parentId", description = "父级任务ID", required = true)
@Parameter(name = "parentId", description = "父级任务 ID", required = true)
@PreAuthorize("@ss.hasPermission('bpm:task:update')")
public CommonResult<List<BpmTaskSubSignRespVO>> getChildrenTaskList(@RequestParam("parentId") String parentId) {
return success(taskService.getChildrenTaskList(parentId));

View File

@ -1,6 +1,5 @@
package cn.iocoder.yudao.module.bpm.convert.task;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
@ -27,6 +26,9 @@ import java.util.Date;
import java.util.List;
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
*
@ -171,9 +173,7 @@ public interface BpmTaskConvert {
Map<String, Task> idTaskMap){
return CollectionUtils.convertList(bpmTaskExtDOList, task -> {
BpmTaskSubSignRespVO bpmTaskSubSignRespVO = new BpmTaskSubSignRespVO()
.setName(task.getName())
.setId(task.getTaskId());
.setId(task.getTaskId()).setName(task.getName());
// 后加签任务不会直接设置 assignee ,所以不存在 assignee 的情况则去取 owner
Task sourceTask = idTaskMap.get(task.getTaskId());
String assignee = ObjectUtil.defaultIfBlank(sourceTask.getOwner(),sourceTask.getAssignee());
@ -190,12 +190,12 @@ public interface BpmTaskConvert {
* @return 转换后的父子级数组
*/
default List<BpmTaskRespVO> convertChildrenList(List<BpmTaskRespVO> sourceList) {
List<BpmTaskRespVO> childrenTaskList = CollectionUtils.filterList(sourceList, r -> StrUtil.isNotEmpty(r.getParentTaskId()));
Map<String, List<BpmTaskRespVO>> parentChildrenTaskListMap = CollectionUtils.convertMultiMap(childrenTaskList, BpmTaskRespVO::getParentTaskId);
List<BpmTaskRespVO> childrenTaskList = filterList(sourceList, r -> StrUtil.isNotEmpty(r.getParentTaskId()));
Map<String, List<BpmTaskRespVO>> parentChildrenTaskListMap = convertMultiMap(childrenTaskList, BpmTaskRespVO::getParentTaskId);
for (BpmTaskRespVO bpmTaskRespVO : sourceList) {
bpmTaskRespVO.setChildren(parentChildrenTaskListMap.get(bpmTaskRespVO.getId()));
}
return CollectionUtils.filterList(sourceList, r -> StrUtil.isEmpty(r.getParentTaskId()));
return filterList(sourceList, r -> StrUtil.isEmpty(r.getParentTaskId()));
}
}

View File

@ -163,7 +163,7 @@ public interface BpmTaskService {
* @param userId 被加签的用户和任务 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 reqVO 被减签的任务 ID理由
*/
void subSignTask(Long userId, BpmTaskSubSignReqVO reqVO);
void deleteSignTask(Long userId, BpmTaskSubSignReqVO reqVO);
/**
* 获取指定任务的子任务和审批人信息

View File

@ -711,7 +711,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
@Override
@Transactional(rollbackFor = Exception.class)
public void addSignTask(Long userId, BpmTaskAddSignReqVO reqVO) {
public void createSignTask(Long userId, BpmTaskAddSignReqVO reqVO) {
// 1. 获取和校验任务
TaskEntityImpl taskEntity = validateAddSign(userId, reqVO);
List<AdminUserRespDTO> userList = adminUserApi.getUserList(reqVO.getUserIdList());
@ -826,7 +826,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
@Override
@Transactional(rollbackFor = Exception.class)
public void subSignTask(Long userId, BpmTaskSubSignReqVO reqVO) {
public void deleteSignTask(Long userId, BpmTaskSubSignReqVO reqVO) {
// 1.1 校验 task 可以被减签
Task task = validateSubSign(reqVO.getId());
// 1.2 校验取消人存在
@ -902,12 +902,14 @@ public class BpmTaskServiceImpl implements BpmTaskService {
stack.push(parentTaskId);
//控制遍历的次数不超过 Byte.MAX_VALUE避免脏数据造成死循环
int count = 0;
// TODO @海< 的前后空格要注意哈
while (!stack.isEmpty() && count<Byte.MAX_VALUE) {
// 1.2 弹出栈顶任务ID
String taskId = stack.pop();
// 1.3 将任务ID添加到结果集合中
allChildTaskIds.add(taskId);
// 1.4 获取该任务的子任务列表
// TODO @海有个更高效的写法一次性去 in 一层不然每个节点都去查询一次 db 太浪费了每次 in最终就是 O(h) 查询而不是 O(n) 查询
List<String> childrenTaskIdList = getChildrenTaskIdList(taskId);
if (CollUtil.isNotEmpty(childrenTaskIdList)) {
for (String childTaskId : childrenTaskIdList) {
@ -920,7 +922,6 @@ public class BpmTaskServiceImpl implements BpmTaskService {
return allChildTaskIds;
}
/**
* 获取指定父级任务的所有子任务 ID 集合
*
@ -954,13 +955,11 @@ public class BpmTaskServiceImpl implements BpmTaskService {
}
List<String> childrenTaskIdList = convertList(taskList, Task::getId);
// 2. owner assignee 统一到一个集合中
List<Long> userIds = convertListByMultiAttr(taskList,control ->
// 2.1 owner assignee 统一到一个集合中
List<Long> userIds = convertListByFlatMap(taskList, control ->
Stream.of(NumberUtils.parseLong(control.getAssignee()), NumberUtils.parseLong(control.getOwner()))
.filter(Objects::nonNull));
// 3. 组装数据
// 2.2 组装数据
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
List<BpmTaskExtDO> taskExtList = taskExtMapper.selectProcessListByTaskIds(childrenTaskIdList);
Map<String, Task> idTaskMap = convertMap(taskList, TaskInfo::getId);