Commit d7ae94443824afc1f2476b2b021fdcbda5b30188
1 parent
cd678e99
feat: 【工作流】--减签逻辑优化
Showing
4 changed files
with
47 additions
and
9 deletions
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; | @@ -4,6 +4,9 @@ import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | ||
| 4 | import lombok.AllArgsConstructor; | 4 | import lombok.AllArgsConstructor; |
| 5 | import lombok.Getter; | 5 | import lombok.Getter; |
| 6 | 6 | ||
| 7 | +import java.util.Arrays; | ||
| 8 | +import java.util.List; | ||
| 9 | + | ||
| 7 | /** | 10 | /** |
| 8 | * 流程实例的结果 | 11 | * 流程实例的结果 |
| 9 | * | 12 | * |
| @@ -63,4 +66,9 @@ public enum BpmProcessInstanceResultEnum { | @@ -63,4 +66,9 @@ public enum BpmProcessInstanceResultEnum { | ||
| 63 | ADD_SIGN_AFTER.getResult()); | 66 | ADD_SIGN_AFTER.getResult()); |
| 64 | } | 67 | } |
| 65 | 68 | ||
| 69 | + /** | ||
| 70 | + * 能被减签的状态 | ||
| 71 | + */ | ||
| 72 | + public static final List<Integer> CAN_SUB_SIGN_STATUS = Arrays.asList(PROCESS.result, WAIT_BEFORE_TASK.result); | ||
| 73 | + | ||
| 66 | } | 74 | } |
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.date.LocalDateTimeUtil; | 3 | import cn.hutool.core.date.LocalDateTimeUtil; |
| 4 | +import cn.hutool.core.util.StrUtil; | ||
| 4 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 5 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 5 | import cn.iocoder.yudao.framework.common.util.date.DateUtils; | 6 | import cn.iocoder.yudao.framework.common.util.date.DateUtils; |
| 6 | import cn.iocoder.yudao.framework.common.util.number.NumberUtils; | 7 | import cn.iocoder.yudao.framework.common.util.number.NumberUtils; |
| @@ -160,12 +161,17 @@ public interface BpmTaskConvert { | @@ -160,12 +161,17 @@ public interface BpmTaskConvert { | ||
| 160 | return task; | 161 | return task; |
| 161 | } | 162 | } |
| 162 | 163 | ||
| 163 | - default List<BpmTaskSubSignRespVO> convertList(List<BpmTaskExtDO> bpmTaskExtDOList, Map<Long, AdminUserRespDTO> userMap){ | 164 | + default List<BpmTaskSubSignRespVO> convertList(List<BpmTaskExtDO> bpmTaskExtDOList, |
| 165 | + Map<Long, AdminUserRespDTO> userMap, | ||
| 166 | + Map<String, Task> idTaskMap){ | ||
| 164 | return CollectionUtils.convertList(bpmTaskExtDOList, task->{ | 167 | return CollectionUtils.convertList(bpmTaskExtDOList, task->{ |
| 165 | BpmTaskSubSignRespVO bpmTaskSubSignRespVO = new BpmTaskSubSignRespVO(); | 168 | BpmTaskSubSignRespVO bpmTaskSubSignRespVO = new BpmTaskSubSignRespVO(); |
| 166 | bpmTaskSubSignRespVO.setName(task.getName()); | 169 | bpmTaskSubSignRespVO.setName(task.getName()); |
| 167 | bpmTaskSubSignRespVO.setId(task.getTaskId()); | 170 | bpmTaskSubSignRespVO.setId(task.getTaskId()); |
| 168 | - AdminUserRespDTO assignUser = userMap.get(task.getAssigneeUserId()); | 171 | + Task sourceTask = idTaskMap.get(task.getTaskId()); |
| 172 | + // 后加签任务不会直接设置 assignee ,所以不存在 assignee 的情况,则去取 owner | ||
| 173 | + String assignee = StrUtil.isNotEmpty(sourceTask.getAssignee()) ? sourceTask.getAssignee() : sourceTask.getOwner(); | ||
| 174 | + AdminUserRespDTO assignUser = userMap.get(NumberUtils.parseLong(assignee)); | ||
| 169 | if (assignUser != null) { | 175 | if (assignUser != null) { |
| 170 | bpmTaskSubSignRespVO.setAssigneeUser(convert3(assignUser)); | 176 | bpmTaskSubSignRespVO.setAssigneeUser(convert3(assignUser)); |
| 171 | } | 177 | } |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/mysql/task/BpmTaskExtMapper.java
| 1 | package cn.iocoder.yudao.module.bpm.dal.mysql.task; | 1 | package cn.iocoder.yudao.module.bpm.dal.mysql.task; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||
| 4 | import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO; | 5 | import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO; |
| 6 | +import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum; | ||
| 5 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 7 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| 6 | import org.apache.ibatis.annotations.Mapper; | 8 | import org.apache.ibatis.annotations.Mapper; |
| 7 | 9 | ||
| @@ -19,6 +21,13 @@ public interface BpmTaskExtMapper extends BaseMapperX<BpmTaskExtDO> { | @@ -19,6 +21,13 @@ public interface BpmTaskExtMapper extends BaseMapperX<BpmTaskExtDO> { | ||
| 19 | return selectList(BpmTaskExtDO::getTaskId, taskIds); | 21 | return selectList(BpmTaskExtDO::getTaskId, taskIds); |
| 20 | } | 22 | } |
| 21 | 23 | ||
| 24 | + default List<BpmTaskExtDO> selectProcessListByTaskIds(Collection<String> taskIds) { | ||
| 25 | + return selectList(new LambdaQueryWrapperX<BpmTaskExtDO>() | ||
| 26 | + .in(BpmTaskExtDO::getTaskId, taskIds) | ||
| 27 | + .in(BpmTaskExtDO::getResult, BpmProcessInstanceResultEnum.CAN_SUB_SIGN_STATUS)); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + | ||
| 22 | default BpmTaskExtDO selectByTaskId(String taskId) { | 31 | default BpmTaskExtDO selectByTaskId(String taskId) { |
| 23 | return selectOne(BpmTaskExtDO::getTaskId, taskId); | 32 | return selectOne(BpmTaskExtDO::getTaskId, taskId); |
| 24 | } | 33 | } |
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; | @@ -34,6 +34,7 @@ import org.flowable.engine.history.HistoricProcessInstance; | ||
| 34 | import org.flowable.engine.runtime.ProcessInstance; | 34 | import org.flowable.engine.runtime.ProcessInstance; |
| 35 | import org.flowable.task.api.DelegationState; | 35 | import org.flowable.task.api.DelegationState; |
| 36 | import org.flowable.task.api.Task; | 36 | import org.flowable.task.api.Task; |
| 37 | +import org.flowable.task.api.TaskInfo; | ||
| 37 | import org.flowable.task.api.TaskQuery; | 38 | import org.flowable.task.api.TaskQuery; |
| 38 | import org.flowable.task.api.history.HistoricTaskInstance; | 39 | import org.flowable.task.api.history.HistoricTaskInstance; |
| 39 | import org.flowable.task.api.history.HistoricTaskInstanceQuery; | 40 | import org.flowable.task.api.history.HistoricTaskInstanceQuery; |
| @@ -49,6 +50,8 @@ import javax.annotation.Resource; | @@ -49,6 +50,8 @@ import javax.annotation.Resource; | ||
| 49 | import javax.validation.Valid; | 50 | import javax.validation.Valid; |
| 50 | import java.time.LocalDateTime; | 51 | import java.time.LocalDateTime; |
| 51 | import java.util.*; | 52 | import java.util.*; |
| 53 | +import java.util.stream.Collectors; | ||
| 54 | +import java.util.stream.Stream; | ||
| 52 | 55 | ||
| 53 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 56 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 54 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; | 57 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; |
| @@ -797,12 +800,13 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -797,12 +800,13 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 797 | //3. 修改扩展表状态为取消 | 800 | //3. 修改扩展表状态为取消 |
| 798 | taskExtMapper.updateBatchByTaskIdList(allTaskIdList,new BpmTaskExtDO().setResult(BpmProcessInstanceResultEnum.CANCEL.getResult()) | 801 | taskExtMapper.updateBatchByTaskIdList(allTaskIdList,new BpmTaskExtDO().setResult(BpmProcessInstanceResultEnum.CANCEL.getResult()) |
| 799 | .setReason(StrUtil.format("由于{}操作[减签],任务被取消",user.getNickname()))); | 802 | .setReason(StrUtil.format("由于{}操作[减签],任务被取消",user.getNickname()))); |
| 800 | - //4. 处理当前任务的父任务 | ||
| 801 | - this.handleParentTask(task); | ||
| 802 | - //5.记录日志到父任务中 | 803 | + //4.记录日志到父任务中 先记录日志是因为,通过 handleParentTask 方法之后,任务可能被完成了,并且不存在了,会报异常,所以先记录 |
| 803 | String comment = StrUtil.format("{}操作了【减签】,审批人{}的任务被取消",user.getNickname(),cancelUser.getNickname()); | 804 | String comment = StrUtil.format("{}操作了【减签】,审批人{}的任务被取消",user.getNickname(),cancelUser.getNickname()); |
| 804 | taskService.addComment(task.getParentTaskId(),task.getProcessInstanceId(), | 805 | taskService.addComment(task.getParentTaskId(),task.getProcessInstanceId(), |
| 805 | BpmCommentTypeEnum.SUB_SIGN.getResult().toString(),comment); | 806 | BpmCommentTypeEnum.SUB_SIGN.getResult().toString(),comment); |
| 807 | + //5. 处理当前任务的父任务 | ||
| 808 | + this.handleParentTask(task); | ||
| 809 | + | ||
| 806 | } | 810 | } |
| 807 | 811 | ||
| 808 | /** | 812 | /** |
| @@ -864,9 +868,20 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -864,9 +868,20 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 864 | if(CollUtil.isEmpty(childrenTaskIdList)){ | 868 | if(CollUtil.isEmpty(childrenTaskIdList)){ |
| 865 | return Collections.emptyList(); | 869 | return Collections.emptyList(); |
| 866 | } | 870 | } |
| 867 | - List<BpmTaskExtDO> bpmTaskExtDOList = taskExtMapper.selectListByTaskIds(childrenTaskIdList); | ||
| 868 | - Set<Long> assigneeUserIdSet = convertSet(bpmTaskExtDOList, BpmTaskExtDO::getAssigneeUserId); | ||
| 869 | - Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(assigneeUserIdSet); | ||
| 870 | - return BpmTaskConvert.INSTANCE.convertList(bpmTaskExtDOList,userMap); | 871 | + //1. 只查询进行中的任务 |
| 872 | + List<BpmTaskExtDO> bpmTaskExtDOList = taskExtMapper.selectProcessListByTaskIds(childrenTaskIdList); | ||
| 873 | + //2. 后加签的任务,可能不存在 assignee,所以还需要查询 owner | ||
| 874 | + List<Task> taskList = taskService.createTaskQuery().taskIds(childrenTaskIdList).list(); | ||
| 875 | + Map<String, Task> idTaskMap = convertMap(taskList, TaskInfo::getId); | ||
| 876 | + //3. 将 owner 和 assignee 统一到一个集合中 | ||
| 877 | + List<Long> userIds = taskList.stream() | ||
| 878 | + .flatMap(control -> | ||
| 879 | + Stream.of(control.getAssignee(), control.getOwner()) | ||
| 880 | + .filter(Objects::nonNull)) | ||
| 881 | + .distinct() | ||
| 882 | + .map(NumberUtils::parseLong) | ||
| 883 | + .collect(Collectors.toList()); | ||
| 884 | + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds); | ||
| 885 | + return BpmTaskConvert.INSTANCE.convertList(bpmTaskExtDOList,userMap,idTaskMap); | ||
| 871 | } | 886 | } |
| 872 | } | 887 | } |