From d7ae94443824afc1f2476b2b021fdcbda5b30188 Mon Sep 17 00:00:00 2001 From: kehaiyou Date: Sat, 30 Sep 2023 15:35:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=80=90=E5=B7=A5=E4=BD=9C=E6=B5=81?= =?UTF-8?q?=E3=80=91--=E5=87=8F=E7=AD=BE=E9=80=BB=E8=BE=91=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../task/BpmProcessInstanceResultEnum.java | 8 +++++ .../bpm/convert/task/BpmTaskConvert.java | 10 +++++-- .../bpm/dal/mysql/task/BpmTaskExtMapper.java | 9 ++++++ .../bpm/service/task/BpmTaskServiceImpl.java | 29 ++++++++++++++----- 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/task/BpmProcessInstanceResultEnum.java b/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/task/BpmProcessInstanceResultEnum.java index 62b18f54a..0fbb5d58f 100644 --- a/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/task/BpmProcessInstanceResultEnum.java +++ b/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/task/BpmProcessInstanceResultEnum.java @@ -4,6 +4,9 @@ import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import lombok.AllArgsConstructor; import lombok.Getter; +import java.util.Arrays; +import java.util.List; + /** * 流程实例的结果 * @@ -63,4 +66,9 @@ public enum BpmProcessInstanceResultEnum { ADD_SIGN_AFTER.getResult()); } + /** + * 能被减签的状态 + */ + public static final List CAN_SUB_SIGN_STATUS = Arrays.asList(PROCESS.result, WAIT_BEFORE_TASK.result); + } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/task/BpmTaskConvert.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/task/BpmTaskConvert.java index e61061c61..eff2d0a25 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/task/BpmTaskConvert.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/task/BpmTaskConvert.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.bpm.convert.task; import cn.hutool.core.date.LocalDateTimeUtil; +import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.framework.common.util.number.NumberUtils; @@ -160,12 +161,17 @@ public interface BpmTaskConvert { return task; } - default List convertList(List bpmTaskExtDOList, Map userMap){ + default List convertList(List bpmTaskExtDOList, + Map userMap, + Map idTaskMap){ return CollectionUtils.convertList(bpmTaskExtDOList, task->{ BpmTaskSubSignRespVO bpmTaskSubSignRespVO = new BpmTaskSubSignRespVO(); bpmTaskSubSignRespVO.setName(task.getName()); bpmTaskSubSignRespVO.setId(task.getTaskId()); - AdminUserRespDTO assignUser = userMap.get(task.getAssigneeUserId()); + Task sourceTask = idTaskMap.get(task.getTaskId()); + // 后加签任务不会直接设置 assignee ,所以不存在 assignee 的情况,则去取 owner + String assignee = StrUtil.isNotEmpty(sourceTask.getAssignee()) ? sourceTask.getAssignee() : sourceTask.getOwner(); + AdminUserRespDTO assignUser = userMap.get(NumberUtils.parseLong(assignee)); if (assignUser != null) { bpmTaskSubSignRespVO.setAssigneeUser(convert3(assignUser)); } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/mysql/task/BpmTaskExtMapper.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/mysql/task/BpmTaskExtMapper.java index 7d4d18d8f..9b0fe8bb1 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/mysql/task/BpmTaskExtMapper.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/mysql/task/BpmTaskExtMapper.java @@ -1,7 +1,9 @@ package cn.iocoder.yudao.module.bpm.dal.mysql.task; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO; +import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; @@ -19,6 +21,13 @@ public interface BpmTaskExtMapper extends BaseMapperX { return selectList(BpmTaskExtDO::getTaskId, taskIds); } + default List selectProcessListByTaskIds(Collection taskIds) { + return selectList(new LambdaQueryWrapperX() + .in(BpmTaskExtDO::getTaskId, taskIds) + .in(BpmTaskExtDO::getResult, BpmProcessInstanceResultEnum.CAN_SUB_SIGN_STATUS)); + } + + default BpmTaskExtDO selectByTaskId(String taskId) { return selectOne(BpmTaskExtDO::getTaskId, taskId); } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java index c5021ba08..ecad585ea 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java @@ -34,6 +34,7 @@ import org.flowable.engine.history.HistoricProcessInstance; import org.flowable.engine.runtime.ProcessInstance; import org.flowable.task.api.DelegationState; import org.flowable.task.api.Task; +import org.flowable.task.api.TaskInfo; import org.flowable.task.api.TaskQuery; import org.flowable.task.api.history.HistoricTaskInstance; import org.flowable.task.api.history.HistoricTaskInstanceQuery; @@ -49,6 +50,8 @@ import javax.annotation.Resource; import javax.validation.Valid; import java.time.LocalDateTime; import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; @@ -797,12 +800,13 @@ public class BpmTaskServiceImpl implements BpmTaskService { //3. 修改扩展表状态为取消 taskExtMapper.updateBatchByTaskIdList(allTaskIdList,new BpmTaskExtDO().setResult(BpmProcessInstanceResultEnum.CANCEL.getResult()) .setReason(StrUtil.format("由于{}操作[减签],任务被取消",user.getNickname()))); - //4. 处理当前任务的父任务 - this.handleParentTask(task); - //5.记录日志到父任务中 + //4.记录日志到父任务中 先记录日志是因为,通过 handleParentTask 方法之后,任务可能被完成了,并且不存在了,会报异常,所以先记录 String comment = StrUtil.format("{}操作了【减签】,审批人{}的任务被取消",user.getNickname(),cancelUser.getNickname()); taskService.addComment(task.getParentTaskId(),task.getProcessInstanceId(), BpmCommentTypeEnum.SUB_SIGN.getResult().toString(),comment); + //5. 处理当前任务的父任务 + this.handleParentTask(task); + } /** @@ -864,9 +868,20 @@ public class BpmTaskServiceImpl implements BpmTaskService { if(CollUtil.isEmpty(childrenTaskIdList)){ return Collections.emptyList(); } - List bpmTaskExtDOList = taskExtMapper.selectListByTaskIds(childrenTaskIdList); - Set assigneeUserIdSet = convertSet(bpmTaskExtDOList, BpmTaskExtDO::getAssigneeUserId); - Map userMap = adminUserApi.getUserMap(assigneeUserIdSet); - return BpmTaskConvert.INSTANCE.convertList(bpmTaskExtDOList,userMap); + //1. 只查询进行中的任务 + List bpmTaskExtDOList = taskExtMapper.selectProcessListByTaskIds(childrenTaskIdList); + //2. 后加签的任务,可能不存在 assignee,所以还需要查询 owner + List taskList = taskService.createTaskQuery().taskIds(childrenTaskIdList).list(); + Map idTaskMap = convertMap(taskList, TaskInfo::getId); + //3. 将 owner 和 assignee 统一到一个集合中 + List userIds = taskList.stream() + .flatMap(control -> + Stream.of(control.getAssignee(), control.getOwner()) + .filter(Objects::nonNull)) + .distinct() + .map(NumberUtils::parseLong) + .collect(Collectors.toList()); + Map userMap = adminUserApi.getUserMap(userIds); + return BpmTaskConvert.INSTANCE.convertList(bpmTaskExtDOList,userMap,idTaskMap); } }