新增 bpm 基于流程实例查询任务列表

This commit is contained in:
YunaiV 2022-01-16 13:47:23 +08:00
parent a4d31f9c45
commit 23eda6b1a9
2 changed files with 31 additions and 40 deletions

View File

@ -29,27 +29,21 @@ public interface BpmTaskConvert {
BpmTaskConvert INSTANCE = Mappers.getMapper(BpmTaskConvert.class); BpmTaskConvert INSTANCE = Mappers.getMapper(BpmTaskConvert.class);
default List<BpmTaskTodoPageItemRespVO> convertList(List<Task> tasks, Map<String, ProcessInstance> processInstanceMap, default List<BpmTaskTodoPageItemRespVO> convertList1(List<Task> tasks, Map<String, ProcessInstance> processInstanceMap,
Map<Long, SysUserDO> userMap) { Map<Long, SysUserDO> userMap) {
return CollectionUtils.convertList(tasks, task -> { return CollectionUtils.convertList(tasks, task -> {
BpmTaskTodoPageItemRespVO respVO = convert1(task);
ProcessInstance processInstance = processInstanceMap.get(task.getProcessInstanceId()); ProcessInstance processInstance = processInstanceMap.get(task.getProcessInstanceId());
return convert(task, processInstance, userMap.get(Long.valueOf(processInstance.getStartUserId()))); if (processInstance != null) {
SysUserDO startUser = userMap.get(NumberUtils.parseLong(processInstance.getStartUserId()));
respVO.setProcessInstance(convert(processInstance, startUser));
}
return respVO;
}); });
} }
@Mappings({ @Mapping(source = "suspended", target = "suspensionState", qualifiedByName = "convertSuspendedToSuspensionState")
@Mapping(source = "task.id", target = "id"), BpmTaskTodoPageItemRespVO convert1(Task bean);
@Mapping(source = "task.name", target = "name"),
@Mapping(source = "task.claimTime", target = "claimTime"),
@Mapping(source = "task.createTime", target = "createTime"),
@Mapping(source = "task.suspended", target = "suspensionState", qualifiedByName = "convertSuspendedToSuspensionState"),
@Mapping(source = "processInstance.id", target = "processInstance.id"),
@Mapping(source = "processInstance.name", target = "processInstance.name"),
@Mapping(source = "processInstance.startUserId", target = "processInstance.startUserId"),
@Mapping(source = "processInstance.processDefinitionId", target = "processInstance.processDefinitionId"),
@Mapping(source = "user.nickname", target = "processInstance.startUserNickname")
})
BpmTaskTodoPageItemRespVO convert(Task task, ProcessInstance processInstance, SysUserDO user);
@Named("convertSuspendedToSuspensionState") @Named("convertSuspendedToSuspensionState")
default Integer convertSuspendedToSuspensionState(boolean suspended) { default Integer convertSuspendedToSuspensionState(boolean suspended) {
@ -61,29 +55,19 @@ public interface BpmTaskConvert {
Map<String, HistoricProcessInstance> historicProcessInstanceMap, Map<String, HistoricProcessInstance> historicProcessInstanceMap,
Map<Long, SysUserDO> userMap) { Map<Long, SysUserDO> userMap) {
return CollectionUtils.convertList(tasks, task -> { return CollectionUtils.convertList(tasks, task -> {
BpmTaskDonePageItemRespVO respVO = convert2(task);
BpmTaskExtDO taskExtDO = bpmTaskExtDOMap.get(task.getId()); BpmTaskExtDO taskExtDO = bpmTaskExtDOMap.get(task.getId());
copyTo(taskExtDO, respVO);
HistoricProcessInstance processInstance = historicProcessInstanceMap.get(task.getProcessInstanceId()); HistoricProcessInstance processInstance = historicProcessInstanceMap.get(task.getProcessInstanceId());
SysUserDO userDO = userMap.get(Long.valueOf(processInstance.getStartUserId())); if (processInstance != null) {
return convert(task, taskExtDO, processInstance, userDO); SysUserDO startUser = userMap.get(NumberUtils.parseLong(processInstance.getStartUserId()));
respVO.setProcessInstance(convert(processInstance, startUser));
}
return respVO;
}); });
} }
@Mappings({ BpmTaskDonePageItemRespVO convert2(HistoricTaskInstance bean);
@Mapping(source = "task.id", target = "id"),
@Mapping(source = "task.name", target = "name"),
@Mapping(source = "task.claimTime", target = "claimTime"),
@Mapping(source = "task.createTime", target = "createTime"),
@Mapping(source = "task.endTime", target = "endTime"),
@Mapping(source = "task.durationInMillis", target = "durationInMillis"),
@Mapping(source = "taskExtDO.result", target = "result"),
@Mapping(source = "taskExtDO.comment", target = "comment"),
@Mapping(source = "processInstance.id", target = "processInstance.id"),
@Mapping(source = "processInstance.name", target = "processInstance.name"),
@Mapping(source = "processInstance.startUserId", target = "processInstance.startUserId"),
@Mapping(source = "processInstance.processDefinitionId", target = "processInstance.processDefinitionId"),
@Mapping(source = "startUser.nickname", target = "processInstance.startUserNickname")
})
BpmTaskDonePageItemRespVO convert(HistoricTaskInstance task, BpmTaskExtDO taskExtDO, HistoricProcessInstance processInstance, SysUserDO startUser);
@Mappings({ @Mappings({
@Mapping(source = "id", target = "taskId"), @Mapping(source = "id", target = "taskId"),
@ -98,7 +82,7 @@ public interface BpmTaskConvert {
return CollectionUtils.convertList(tasks, task -> { return CollectionUtils.convertList(tasks, task -> {
BpmTaskRespVO respVO = convert3(task); BpmTaskRespVO respVO = convert3(task);
BpmTaskExtDO taskExtDO = bpmTaskExtDOMap.get(task.getId()); BpmTaskExtDO taskExtDO = bpmTaskExtDOMap.get(task.getId());
copyTo3(taskExtDO, respVO); copyTo(taskExtDO, respVO);
if (processInstance != null) { if (processInstance != null) {
SysUserDO startUser = userMap.get(NumberUtils.parseLong(processInstance.getStartUserId())); SysUserDO startUser = userMap.get(NumberUtils.parseLong(processInstance.getStartUserId()));
respVO.setProcessInstance(convert(processInstance, startUser)); respVO.setProcessInstance(convert(processInstance, startUser));
@ -117,7 +101,17 @@ public interface BpmTaskConvert {
BpmTaskRespVO convert3(HistoricTaskInstance bean); BpmTaskRespVO convert3(HistoricTaskInstance bean);
BpmTaskRespVO.User convert3(SysUserDO bean); BpmTaskRespVO.User convert3(SysUserDO bean);
void copyTo3(BpmTaskExtDO from, @MappingTarget BpmTaskRespVO to);
void copyTo(BpmTaskExtDO from, @MappingTarget BpmTaskDonePageItemRespVO to);
@Mappings({
@Mapping(source = "processInstance.id", target = "id"),
@Mapping(source = "processInstance.name", target = "name"),
@Mapping(source = "processInstance.startUserId", target = "startUserId"),
@Mapping(source = "processInstance.processDefinitionId", target = "processDefinitionId"),
@Mapping(source = "startUser.nickname", target = "startUserNickname")
})
BpmTaskTodoPageItemRespVO.ProcessInstance convert(ProcessInstance processInstance, SysUserDO startUser);
@Mappings({ @Mappings({
@Mapping(source = "processInstance.id", target = "id"), @Mapping(source = "processInstance.id", target = "id"),

View File

@ -2,7 +2,6 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.task.impl;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task.*; import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task.*;
import cn.iocoder.yudao.adminserver.modules.bpm.convert.task.BpmTaskConvert; import cn.iocoder.yudao.adminserver.modules.bpm.convert.task.BpmTaskConvert;
@ -34,7 +33,6 @@ import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.history.HistoricTaskInstanceQuery; import org.activiti.engine.history.HistoricTaskInstanceQuery;
import org.activiti.engine.repository.ProcessDefinition; import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Comment;
import org.activiti.engine.task.Task; import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery; import org.activiti.engine.task.TaskQuery;
import org.activiti.image.ProcessDiagramGenerator; import org.activiti.image.ProcessDiagramGenerator;
@ -48,7 +46,6 @@ import javax.validation.Valid;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.*; import java.util.*;
import java.util.function.Function;
import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.*; import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.*;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@ -155,7 +152,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
Map<Long, SysUserDO> userMap = userService.getUserMap( Map<Long, SysUserDO> userMap = userService.getUserMap(
convertSet(processInstanceMap.values(), instance -> Long.valueOf(instance.getStartUserId()))); convertSet(processInstanceMap.values(), instance -> Long.valueOf(instance.getStartUserId())));
// 拼接结果 // 拼接结果
return new PageResult<>(BpmTaskConvert.INSTANCE.convertList(tasks, processInstanceMap, userMap), return new PageResult<>(BpmTaskConvert.INSTANCE.convertList1(tasks, processInstanceMap, userMap),
taskQuery.count()); taskQuery.count());
} }