mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 17:21:53 +08:00
feat: 【工作流】--减签逻辑优化
This commit is contained in:
parent
cd678e997a
commit
d7ae944438
@ -4,6 +4,9 @@ import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 流程实例的结果
|
* 流程实例的结果
|
||||||
*
|
*
|
||||||
@ -63,4 +66,9 @@ public enum BpmProcessInstanceResultEnum {
|
|||||||
ADD_SIGN_AFTER.getResult());
|
ADD_SIGN_AFTER.getResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 能被减签的状态
|
||||||
|
*/
|
||||||
|
public static final List<Integer> CAN_SUB_SIGN_STATUS = Arrays.asList(PROCESS.result, WAIT_BEFORE_TASK.result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.bpm.convert.task;
|
package cn.iocoder.yudao.module.bpm.convert.task;
|
||||||
|
|
||||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
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.collection.CollectionUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
|
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
|
||||||
@ -160,12 +161,17 @@ public interface BpmTaskConvert {
|
|||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
default List<BpmTaskSubSignRespVO> convertList(List<BpmTaskExtDO> bpmTaskExtDOList, Map<Long, AdminUserRespDTO> userMap){
|
default List<BpmTaskSubSignRespVO> convertList(List<BpmTaskExtDO> bpmTaskExtDOList,
|
||||||
|
Map<Long, AdminUserRespDTO> userMap,
|
||||||
|
Map<String, Task> idTaskMap){
|
||||||
return CollectionUtils.convertList(bpmTaskExtDOList, task->{
|
return CollectionUtils.convertList(bpmTaskExtDOList, task->{
|
||||||
BpmTaskSubSignRespVO bpmTaskSubSignRespVO = new BpmTaskSubSignRespVO();
|
BpmTaskSubSignRespVO bpmTaskSubSignRespVO = new BpmTaskSubSignRespVO();
|
||||||
bpmTaskSubSignRespVO.setName(task.getName());
|
bpmTaskSubSignRespVO.setName(task.getName());
|
||||||
bpmTaskSubSignRespVO.setId(task.getTaskId());
|
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) {
|
if (assignUser != null) {
|
||||||
bpmTaskSubSignRespVO.setAssigneeUser(convert3(assignUser));
|
bpmTaskSubSignRespVO.setAssigneeUser(convert3(assignUser));
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package cn.iocoder.yudao.module.bpm.dal.mysql.task;
|
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.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.dal.dataobject.task.BpmTaskExtDO;
|
||||||
|
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
@ -19,6 +21,13 @@ public interface BpmTaskExtMapper extends BaseMapperX<BpmTaskExtDO> {
|
|||||||
return selectList(BpmTaskExtDO::getTaskId, taskIds);
|
return selectList(BpmTaskExtDO::getTaskId, taskIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default List<BpmTaskExtDO> selectProcessListByTaskIds(Collection<String> taskIds) {
|
||||||
|
return selectList(new LambdaQueryWrapperX<BpmTaskExtDO>()
|
||||||
|
.in(BpmTaskExtDO::getTaskId, taskIds)
|
||||||
|
.in(BpmTaskExtDO::getResult, BpmProcessInstanceResultEnum.CAN_SUB_SIGN_STATUS));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
default BpmTaskExtDO selectByTaskId(String taskId) {
|
default BpmTaskExtDO selectByTaskId(String taskId) {
|
||||||
return selectOne(BpmTaskExtDO::getTaskId, taskId);
|
return selectOne(BpmTaskExtDO::getTaskId, taskId);
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ import org.flowable.engine.history.HistoricProcessInstance;
|
|||||||
import org.flowable.engine.runtime.ProcessInstance;
|
import org.flowable.engine.runtime.ProcessInstance;
|
||||||
import org.flowable.task.api.DelegationState;
|
import org.flowable.task.api.DelegationState;
|
||||||
import org.flowable.task.api.Task;
|
import org.flowable.task.api.Task;
|
||||||
|
import org.flowable.task.api.TaskInfo;
|
||||||
import org.flowable.task.api.TaskQuery;
|
import org.flowable.task.api.TaskQuery;
|
||||||
import org.flowable.task.api.history.HistoricTaskInstance;
|
import org.flowable.task.api.history.HistoricTaskInstance;
|
||||||
import org.flowable.task.api.history.HistoricTaskInstanceQuery;
|
import org.flowable.task.api.history.HistoricTaskInstanceQuery;
|
||||||
@ -49,6 +50,8 @@ import javax.annotation.Resource;
|
|||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
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.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
||||||
@ -797,12 +800,13 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
|||||||
//3. 修改扩展表状态为取消
|
//3. 修改扩展表状态为取消
|
||||||
taskExtMapper.updateBatchByTaskIdList(allTaskIdList,new BpmTaskExtDO().setResult(BpmProcessInstanceResultEnum.CANCEL.getResult())
|
taskExtMapper.updateBatchByTaskIdList(allTaskIdList,new BpmTaskExtDO().setResult(BpmProcessInstanceResultEnum.CANCEL.getResult())
|
||||||
.setReason(StrUtil.format("由于{}操作[减签],任务被取消",user.getNickname())));
|
.setReason(StrUtil.format("由于{}操作[减签],任务被取消",user.getNickname())));
|
||||||
//4. 处理当前任务的父任务
|
//4.记录日志到父任务中 先记录日志是因为,通过 handleParentTask 方法之后,任务可能被完成了,并且不存在了,会报异常,所以先记录
|
||||||
this.handleParentTask(task);
|
|
||||||
//5.记录日志到父任务中
|
|
||||||
String comment = StrUtil.format("{}操作了【减签】,审批人{}的任务被取消",user.getNickname(),cancelUser.getNickname());
|
String comment = StrUtil.format("{}操作了【减签】,审批人{}的任务被取消",user.getNickname(),cancelUser.getNickname());
|
||||||
taskService.addComment(task.getParentTaskId(),task.getProcessInstanceId(),
|
taskService.addComment(task.getParentTaskId(),task.getProcessInstanceId(),
|
||||||
BpmCommentTypeEnum.SUB_SIGN.getResult().toString(),comment);
|
BpmCommentTypeEnum.SUB_SIGN.getResult().toString(),comment);
|
||||||
|
//5. 处理当前任务的父任务
|
||||||
|
this.handleParentTask(task);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -864,9 +868,20 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
|||||||
if(CollUtil.isEmpty(childrenTaskIdList)){
|
if(CollUtil.isEmpty(childrenTaskIdList)){
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
List<BpmTaskExtDO> bpmTaskExtDOList = taskExtMapper.selectListByTaskIds(childrenTaskIdList);
|
//1. 只查询进行中的任务
|
||||||
Set<Long> assigneeUserIdSet = convertSet(bpmTaskExtDOList, BpmTaskExtDO::getAssigneeUserId);
|
List<BpmTaskExtDO> bpmTaskExtDOList = taskExtMapper.selectProcessListByTaskIds(childrenTaskIdList);
|
||||||
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(assigneeUserIdSet);
|
//2. 后加签的任务,可能不存在 assignee,所以还需要查询 owner
|
||||||
return BpmTaskConvert.INSTANCE.convertList(bpmTaskExtDOList,userMap);
|
List<Task> taskList = taskService.createTaskQuery().taskIds(childrenTaskIdList).list();
|
||||||
|
Map<String, Task> idTaskMap = convertMap(taskList, TaskInfo::getId);
|
||||||
|
//3. 将 owner 和 assignee 统一到一个集合中
|
||||||
|
List<Long> userIds = taskList.stream()
|
||||||
|
.flatMap(control ->
|
||||||
|
Stream.of(control.getAssignee(), control.getOwner())
|
||||||
|
.filter(Objects::nonNull))
|
||||||
|
.distinct()
|
||||||
|
.map(NumberUtils::parseLong)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
|
||||||
|
return BpmTaskConvert.INSTANCE.convertList(bpmTaskExtDOList,userMap,idTaskMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user