📖 BPM:code review 抄送逻辑

This commit is contained in:
YunaiV 2024-01-23 12:55:13 +08:00
parent 986f953319
commit 7bb171512a
13 changed files with 87 additions and 253 deletions

View File

@ -17,17 +17,15 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.stream.Stream;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@ -41,6 +39,7 @@ public class BpmProcessInstanceCopyController {
private BpmProcessInstanceCopyService processInstanceCopyService; private BpmProcessInstanceCopyService processInstanceCopyService;
@Resource @Resource
private BpmProcessInstanceService bpmProcessInstanceService; private BpmProcessInstanceService bpmProcessInstanceService;
@Resource @Resource
private AdminUserApi adminUserApi; private AdminUserApi adminUserApi;
@ -50,8 +49,9 @@ public class BpmProcessInstanceCopyController {
@PostMapping("/create") @PostMapping("/create")
@Operation(summary = "抄送流程") @Operation(summary = "抄送流程")
@PreAuthorize("@ss.hasPermission('bpm:process-instance-cc:create')") @PreAuthorize("@ss.hasPermission('bpm:process-instance-cc:create')")
public CommonResult<Void> createProcessInstanceCC(@Valid @RequestBody BpmProcessInstanceCopyCreateReqVO createReqVO) { public CommonResult<Boolean> createProcessInstanceCC(@Valid @RequestBody BpmProcessInstanceCopyCreateReqVO createReqVO) {
return success(processInstanceCopyService.createProcessInstanceCopy(getLoginUserId(), createReqVO)); processInstanceCopyService.createProcessInstanceCopy(getLoginUserId(), createReqVO);
return success(true);
} }
@GetMapping("/my-page") @GetMapping("/my-page")
@ -64,20 +64,14 @@ public class BpmProcessInstanceCopyController {
return success(new PageResult<>(pageResult.getTotal())); return success(new PageResult<>(pageResult.getTotal()));
} }
Map<String, String> taskNameByTaskIds = bpmTaskService.getTaskNameByTaskIds(convertSet(pageResult.getList(), BpmProcessInstanceCopyDO::getTaskId)); // 拼接返回
Map<String, String> processInstanceNameByProcessInstanceIds = bpmTaskService.getProcessInstanceNameByProcessInstanceIds(convertSet(pageResult.getList(), BpmProcessInstanceCopyDO::getProcessInstanceId)); Map<String, String> taskNameMap = bpmTaskService.getTaskNameByTaskIds(
convertSet(pageResult.getList(), BpmProcessInstanceCopyDO::getTaskId));
Set<Long/* userId */> userIds = new HashSet<>(); Map<String, String> processNameMap = bpmProcessInstanceService.getProcessInstanceNameMap(
for (BpmProcessInstanceCopyDO doItem : pageResult.getList()) { convertSet(pageResult.getList(), BpmProcessInstanceCopyDO::getProcessInstanceId));
userIds.add(doItem.getStartUserId()); Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(pageResult.getList(),
Long userId = Long.valueOf(doItem.getCreator()); copy -> Stream.of(copy.getStartUserId(), Long.parseLong(copy.getCreator()))));
userIds.add(userId); return success(BpmProcessInstanceCopyConvert.INSTANCE.convertPage(pageResult, taskNameMap, processNameMap, userMap));
}
Map<Long, String> userMap = adminUserApi.getUserList(userIds).stream().collect(Collectors.toMap(
AdminUserRespDTO::getId, AdminUserRespDTO::getNickname));
// 转换返回
return success(BpmProcessInstanceCopyConvert.INSTANCE.convertPage(pageResult, taskNameByTaskIds, processInstanceNameByProcessInstanceIds, userMap));
} }
} }

View File

@ -1,18 +1,13 @@
package cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance; package cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance;
import cn.iocoder.yudao.module.bpm.controller.admin.candidate.vo.BpmTaskCandidateRuleVO;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 流程实例抄送的创建 Request VO") @Schema(description = "管理后台 - 流程实例抄送的创建 Request VO")
@Data @Data
@EqualsAndHashCode(callSuper = true) public class BpmProcessInstanceCopyCreateReqVO {
@ToString(callSuper = true)
public class BpmProcessInstanceCopyCreateReqVO extends BpmTaskCandidateRuleVO {
@Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotEmpty(message = "任务编号不能为空") @NotEmpty(message = "任务编号不能为空")

View File

@ -12,7 +12,7 @@ public class BpmProcessInstanceCopyPageItemRespVO {
@Schema(description = "抄送主键") @Schema(description = "抄送主键")
private Long id; private Long id;
@Schema(description = "发起人Id") @Schema(description = "发起人 ID")
private Long startUserId; private Long startUserId;
@Schema(description = "发起人别名") @Schema(description = "发起人别名")

View File

@ -5,6 +5,7 @@ import lombok.Data;
import java.time.LocalDateTime; import java.time.LocalDateTime;
// TODO @kyle1明确是 Req 还是 Resp2注释可以合并到 swagger 3example 写一下这样一些 mock 接口平台可以读取 example
/** /**
* 流程抄送视图对象 * 流程抄送视图对象
*/ */
@ -60,4 +61,5 @@ public class BpmProcessInstanceCopyVO {
@Schema(description = "抄送时间") @Schema(description = "抄送时间")
private LocalDateTime createTime; private LocalDateTime createTime;
} }

View File

@ -4,8 +4,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceCopyPageItemRespVO; import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceCopyPageItemRespVO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmProcessInstanceCopyVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.cc.BpmProcessInstanceCopyDO; import cn.iocoder.yudao.module.bpm.dal.dataobject.cc.BpmProcessInstanceCopyDO;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
@ -22,22 +22,17 @@ public interface BpmProcessInstanceCopyConvert {
BpmProcessInstanceCopyConvert INSTANCE = Mappers.getMapper(BpmProcessInstanceCopyConvert.class); BpmProcessInstanceCopyConvert INSTANCE = Mappers.getMapper(BpmProcessInstanceCopyConvert.class);
BpmProcessInstanceCopyVO convert(BpmProcessInstanceCopyDO bean); default PageResult<BpmProcessInstanceCopyPageItemRespVO> convertPage(PageResult<BpmProcessInstanceCopyDO> page,
Map<String, String> taskNameMap,
List<BpmProcessInstanceCopyPageItemRespVO> convertList(List<BpmProcessInstanceCopyDO> list); Map<String, String> processInstaneNameMap,
Map<Long, AdminUserRespDTO> userMap) {
default PageResult<BpmProcessInstanceCopyPageItemRespVO> convertPage(PageResult<BpmProcessInstanceCopyDO> page
, Map<String, String/* taskName */> taskMap
, Map<String, String/* processInstaneName */> processInstaneMap
, Map<Long, String/* userName */> userMap
) {
List<BpmProcessInstanceCopyPageItemRespVO> list = BeanUtils.toBean(page.getList(), List<BpmProcessInstanceCopyPageItemRespVO> list = BeanUtils.toBean(page.getList(),
BpmProcessInstanceCopyPageItemRespVO.class, BpmProcessInstanceCopyPageItemRespVO.class,
copy -> { copy -> {
MapUtils.findAndThen(userMap, Long.valueOf(copy.getCreator()), copy::setCreatorNickname); MapUtils.findAndThen(userMap, Long.valueOf(copy.getCreator()), user -> user.setNickname(user.getNickname()));
MapUtils.findAndThen(userMap, copy.getStartUserId(), copy::setStartUserNickname); MapUtils.findAndThen(userMap, copy.getStartUserId(), user -> copy.setStartUserNickname(user.getNickname()));
MapUtils.findAndThen(taskMap, copy.getTaskId(), copy::setTaskName); MapUtils.findAndThen(taskNameMap, copy.getTaskId(), copy::setTaskName);
MapUtils.findAndThen(processInstaneMap, copy.getProcessInstanceId(), copy::setProcessInstanceName); MapUtils.findAndThen(processInstaneNameMap, copy.getProcessInstanceId(), copy::setProcessInstanceName);
}); });
return new PageResult<>(list, page.getTotal()); return new PageResult<>(list, page.getTotal());
} }

View File

@ -28,40 +28,40 @@ public class BpmProcessInstanceCopyDO extends BaseDO {
/** /**
* 发起人 Id * 发起人 Id
* <p> *
* 关联 system_users id 属性 * 关联 system_users id 属性
*/ */
private Long startUserId; private Long startUserId;
/** /**
* 流程名 * 流程名
* <p> *
* 冗余字段 * 冗余 ProcessInstance name 字段
*/ */
private String processInstanceName; private String processInstanceName;
/** /**
* 流程实例的编号 * 流程实例的编号
* <p> *
* 关联 ProcessInstance id 属性 * 关联 ProcessInstance id 属性
*/ */
private String processInstanceId; private String processInstanceId;
/** /**
* 任务主键 * 任务主键
* <p> *
* 关联 task id 属性 * 关联 Task id 属性
*/ */
private String taskId; private String taskId;
/** /**
* 任务名称 * 任务名称
* <p> *
* 冗余字段 * 冗余 Task name 属性
*/ */
private String taskName; private String taskName;
/** /**
* 用户编号 * 用户编号
* <p> *
* 关联 system_users id 属性 * 关联 system_users id 属性
*/ */
private Long userId; private Long userId;
@ -73,8 +73,8 @@ public class BpmProcessInstanceCopyDO extends BaseDO {
/** /**
* 流程分类 * 流程分类
* <p> *
* 冗余字段 * 冗余 ProcessInstance category 字段
*/ */
private String category; private String category;

View File

@ -46,6 +46,17 @@ public interface BpmProcessInstanceService {
return CollectionUtils.convertMap(getProcessInstances(ids), ProcessInstance::getProcessInstanceId); return CollectionUtils.convertMap(getProcessInstances(ids), ProcessInstance::getProcessInstanceId);
} }
/**
* 获得流程实例名字 Map
*
* @param ids 流程实例的编号集合
* @return 对应的映射关系
*/
default Map<String, String> getProcessInstanceNameMap(Set<String> ids) {
return CollectionUtils.convertMap(getProcessInstances(ids),
ProcessInstance::getProcessInstanceId, ProcessInstance::getName);
}
/** /**
* 获得流程实例的分页 * 获得流程实例的分页
* *

View File

@ -10,7 +10,6 @@ import org.flowable.task.api.Task;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
* 流程任务实例 Service 接口 * 流程任务实例 Service 接口
@ -186,18 +185,11 @@ public interface BpmTaskService {
List<BpmTaskSubSignRespVO> getChildrenTaskList(String parentId); List<BpmTaskSubSignRespVO> getChildrenTaskList(String parentId);
/** /**
* 通过任务id查询任务名 * 通过任务 ID查询任务名 Map
* *
* @param taskIds 任务id * @param taskIds 任务 ID
* @return 对应的映射关系 * @return 任务 ID 与名字的 Map
*/ */
Map<String/* taskId */, String/* taskName */> getTaskNameByTaskIds(Collection<String> taskIds); Map<String, String> getTaskNameByTaskIds(Collection<String> taskIds);
/**
* 通过流程实例id获取到流程实例名
*
* @param processInstaneIds 流程实例Id
* @return 对应的映射关系
*/
Map<String/* processInstaneId */, String/* processInstaneName */> getProcessInstanceNameByProcessInstanceIds(Set<String> processInstaneIds);
} }

View File

@ -21,7 +21,6 @@ import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskAddSignTypeEnum; import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskAddSignTypeEnum;
import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService; import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService;
import cn.iocoder.yudao.module.bpm.service.message.BpmMessageService; import cn.iocoder.yudao.module.bpm.service.message.BpmMessageService;
import cn.iocoder.yudao.module.bpm.service.task.cc.BpmProcessInstanceCopyService;
import cn.iocoder.yudao.module.system.api.dept.DeptApi; import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi; import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
@ -95,9 +94,6 @@ public class BpmTaskServiceImpl implements BpmTaskService {
@Resource @Resource
private ManagementService managementService; private ManagementService managementService;
@Resource
private BpmProcessInstanceCopyService processInstanceCopyService;
@Override @Override
public PageResult<BpmTaskTodoPageItemRespVO> getTodoTaskPage(Long userId, BpmTaskTodoPageReqVO pageVO) { public PageResult<BpmTaskTodoPageItemRespVO> getTodoTaskPage(Long userId, BpmTaskTodoPageReqVO pageVO) {
// 查询待办任务 // 查询待办任务
@ -972,28 +968,12 @@ public class BpmTaskServiceImpl implements BpmTaskService {
} }
@Override @Override
public Map<String/* taskId */, String/* taskName */> getTaskNameByTaskIds(Collection<String> taskIds) { public Map<String, String> getTaskNameByTaskIds(Collection<String> taskIds) {
List<Task> tasks = taskService.createTaskQuery().taskIds(taskIds).list(); if (CollUtil.isEmpty(taskIds)) {
if (CollUtil.isNotEmpty(tasks)) {
Map<String/* taskId */, String/* taskName */> taskMap = new HashMap<>(tasks.size());
for (Task task : tasks) {
taskMap.putIfAbsent(task.getId(), task.getName());
}
return taskMap;
}
return Collections.emptyMap(); return Collections.emptyMap();
} }
List<Task> tasks = taskService.createTaskQuery().taskIds(taskIds).list();
return convertMap(tasks, Task::getId, Task::getName);
}
@Override
public Map<String/* processInstaneId */, String/* processInstaneName */> getProcessInstanceNameByProcessInstanceIds(Set<String> processInstanceIds) {
List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().processInstanceIds(processInstanceIds).list();
if (CollUtil.isNotEmpty(processInstances)) {
Map<String/* processInstaneId */, String/* processInstaneName */> processInstaneMap = new HashMap<>(processInstances.size());
for (ProcessInstance processInstance : processInstances) {
processInstaneMap.putIfAbsent(processInstance.getId(), processInstance.getName());
}
return processInstaneMap;
}
return Collections.emptyMap();
}
} }

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.bpm.service.task.cc;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceCopyCreateReqVO; import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceCopyCreateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceCopyMyPageReqVO; import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceCopyMyPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceCopyPageItemRespVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.cc.BpmProcessInstanceCopyDO; import cn.iocoder.yudao.module.bpm.dal.dataobject.cc.BpmProcessInstanceCopyDO;
import cn.iocoder.yudao.module.bpm.service.candidate.BpmCandidateSourceInfo; import cn.iocoder.yudao.module.bpm.service.candidate.BpmCandidateSourceInfo;
@ -28,14 +27,14 @@ public interface BpmProcessInstanceCopyService {
* @param userId 当前登录用户 * @param userId 当前登录用户
* @param createReqVO 创建的抄送请求 * @param createReqVO 创建的抄送请求
*/ */
Void createProcessInstanceCopy(Long userId, BpmProcessInstanceCopyCreateReqVO createReqVO); void createProcessInstanceCopy(Long userId, BpmProcessInstanceCopyCreateReqVO createReqVO);
/** /**
* 抄送的流程的分页 * 抄送的流程的分页
* @param loginUserId 登录用户id * @param userId 当前登录用户
* @param pageReqVO 分页请求 * @param pageReqVO 分页请求
* @return 抄送的分页结果 * @return 抄送的分页结果
*/ */
PageResult<BpmProcessInstanceCopyDO> getMyProcessInstanceCopyPage(Long loginUserId, PageResult<BpmProcessInstanceCopyDO> getMyProcessInstanceCopyPage(Long userId,
BpmProcessInstanceCopyMyPageReqVO pageReqVO); BpmProcessInstanceCopyMyPageReqVO pageReqVO);
} }

View File

@ -7,25 +7,18 @@ import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceCopyCreateReqVO; import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceCopyCreateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceCopyMyPageReqVO; import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceCopyMyPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceCopyPageItemRespVO;
import cn.iocoder.yudao.module.bpm.convert.cc.BpmProcessInstanceCopyConvert;
import cn.iocoder.yudao.module.bpm.dal.dataobject.cc.BpmProcessInstanceCopyDO; import cn.iocoder.yudao.module.bpm.dal.dataobject.cc.BpmProcessInstanceCopyDO;
import cn.iocoder.yudao.module.bpm.dal.mysql.cc.BpmProcessInstanceCopyMapper; import cn.iocoder.yudao.module.bpm.dal.mysql.cc.BpmProcessInstanceCopyMapper;
import cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants; import cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmTaskAssignRuleTypeEnum;
import cn.iocoder.yudao.module.bpm.service.candidate.BpmCandidateSourceInfo; import cn.iocoder.yudao.module.bpm.service.candidate.BpmCandidateSourceInfo;
import cn.iocoder.yudao.module.bpm.service.candidate.BpmCandidateSourceInfoProcessorChain; import cn.iocoder.yudao.module.bpm.service.candidate.BpmCandidateSourceInfoProcessorChain;
import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService; import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService; import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService;
import cn.iocoder.yudao.module.bpm.service.task.cc.dto.BpmDelegateExecutionDTO; import cn.iocoder.yudao.module.bpm.service.task.cc.dto.BpmDelegateExecutionDTO;
import cn.iocoder.yudao.module.bpm.util.FlowableUtils;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.RuntimeService; import org.flowable.engine.RuntimeService;
import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance; import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task; import org.flowable.task.api.Task;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
@ -33,14 +26,14 @@ import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.ArrayList;
import java.util.stream.Collectors; import java.util.List;
import java.util.Set;
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.convertSet;
/** /**
* Flowable流程抄送实现 * 流程抄送 Service 实现
* *
* @author kyle * @author kyle
*/ */
@ -61,6 +54,9 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy
@Resource @Resource
@Lazy @Lazy
private BpmTaskService bpmTaskService; private BpmTaskService bpmTaskService;
@Resource
@Lazy
private BpmProcessInstanceService bpmProcessInstanceService;
@Override @Override
public boolean makeCopy(BpmCandidateSourceInfo sourceInfo) { public boolean makeCopy(BpmCandidateSourceInfo sourceInfo) {
@ -86,7 +82,7 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy
// 调用 // 调用
// 设置任务id // 设置任务id
copyDO.setTaskId(sourceInfo.getTaskId()); copyDO.setTaskId(sourceInfo.getTaskId());
copyDO.setTaskName(FlowableUtils.getTaskNameByTaskId(sourceInfo.getTaskId())); copyDO.setTaskName(task.getName());
copyDO.setProcessInstanceId(processInstanceId); copyDO.setProcessInstanceId(processInstanceId);
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery() ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
.processInstanceId(processInstanceId) .processInstanceId(processInstanceId)
@ -95,10 +91,9 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy
log.warn("相关流程实例不存在 {}", sourceInfo.getTaskId()); log.warn("相关流程实例不存在 {}", sourceInfo.getTaskId());
return false; return false;
} }
copyDO.setStartUserId(FlowableUtils.getStartUserIdFromProcessInstance(processInstance)); copyDO.setStartUserId(Long.parseLong(processInstance.getStartUserId()));
copyDO.setProcessInstanceName(processInstance.getName()); copyDO.setProcessInstanceName(processInstance.getName());
ProcessDefinition processDefinition = FlowableUtils.getProcessDefinition(processInstance.getProcessDefinitionId()); copyDO.setCategory(processInstance.getProcessDefinitionCategory());
copyDO.setCategory(processDefinition.getCategory());
copyDO.setReason(sourceInfo.getReason()); copyDO.setReason(sourceInfo.getReason());
copyDO.setCreator(sourceInfo.getCreator()); copyDO.setCreator(sourceInfo.getCreator());
copyDO.setCreateTime(LocalDateTime.now()); copyDO.setCreateTime(LocalDateTime.now());
@ -113,53 +108,32 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy
} }
@Override @Override
public Void createProcessInstanceCopy(Long userId, BpmProcessInstanceCopyCreateReqVO reqVO) { public void createProcessInstanceCopy(Long userId, BpmProcessInstanceCopyCreateReqVO reqVO) {
if (!ObjectUtil.equal(reqVO.getType(), BpmTaskAssignRuleTypeEnum.USER.getType())) { // 1.1 校验任务存在
throw new IllegalArgumentException("业务仅支持USER");
}
Task task = bpmTaskService.getTask(reqVO.getTaskId()); Task task = bpmTaskService.getTask(reqVO.getTaskId());
if (ObjectUtil.isNull(task)) { if (ObjectUtil.isNull(task)) {
throw exception(ErrorCodeConstants.TASK_NOT_EXISTS); throw exception(ErrorCodeConstants.TASK_NOT_EXISTS);
} }
// 1.2 校验流程存在
String processInstanceId = task.getProcessInstanceId(); String processInstanceId = task.getProcessInstanceId();
if (StrUtil.isBlank(processInstanceId)) { ProcessInstance processInstance = bpmProcessInstanceService.getProcessInstance(processInstanceId);
if (processInstance == null) {
log.warn("[createProcessInstanceCopy][任务({}) 对应的流程不存在]", reqVO.getTaskId());
throw exception(ErrorCodeConstants.PROCESS_INSTANCE_NOT_EXISTS); throw exception(ErrorCodeConstants.PROCESS_INSTANCE_NOT_EXISTS);
} }
// 在能正常审批的情况下抄送流程
BpmProcessInstanceCopyDO copyDO = new BpmProcessInstanceCopyDO(); // 2. 创建抄送流程
// 调用 BpmProcessInstanceCopyDO copy = new BpmProcessInstanceCopyDO()
// 设置任务id .setTaskId(reqVO.getTaskId()).setTaskName(task.getName())
copyDO.setTaskId(reqVO.getTaskId()); .setProcessInstanceId(processInstanceId).setStartUserId(Long.valueOf(processInstance.getStartUserId()))
copyDO.setTaskName(FlowableUtils.getTaskNameByTaskId(reqVO.getTaskId())); .setProcessInstanceName(processInstance.getName()).setCategory(processInstance.getProcessDefinitionCategory())
copyDO.setProcessInstanceId(processInstanceId); .setReason(reqVO.getReason());
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery() processInstanceCopyMapper.insert(copy);
.processInstanceId(processInstanceId)
.singleResult();
if (null == processInstance) {
log.warn("相关流程实例不存在 {}", reqVO.getTaskId());
throw exception(ErrorCodeConstants.PROCESS_INSTANCE_NOT_EXISTS);
}
copyDO.setStartUserId(FlowableUtils.getStartUserIdFromProcessInstance(processInstance));
copyDO.setProcessInstanceName(processInstance.getName());
ProcessDefinition processDefinition = FlowableUtils.getProcessDefinition(processInstance.getProcessDefinitionId());
copyDO.setCategory(processDefinition.getCategory());
copyDO.setReason(reqVO.getReason());
copyDO.setCreator(String.valueOf(userId));
copyDO.setCreateTime(LocalDateTime.now());
List<BpmProcessInstanceCopyDO> copyList = new ArrayList<>(reqVO.getOptions().size());
for (Long copyUserId : reqVO.getOptions()) {
BpmProcessInstanceCopyDO copy = BeanUtil.copyProperties(copyDO, BpmProcessInstanceCopyDO.class);
copy.setUserId(copyUserId);
copyList.add(copy);
}
processInstanceCopyMapper.insertBatch(copyList);
return null;
} }
@Override @Override
public PageResult<BpmProcessInstanceCopyDO> getMyProcessInstanceCopyPage(Long loginUserId, BpmProcessInstanceCopyMyPageReqVO pageReqVO) { public PageResult<BpmProcessInstanceCopyDO> getMyProcessInstanceCopyPage(Long userId, BpmProcessInstanceCopyMyPageReqVO pageReqVO) {
// 通过 BpmProcessInstanceExtDO 先查询到对应的分页 return processInstanceCopyMapper.selectPage(userId, pageReqVO);
return processInstanceCopyMapper.selectPage(loginUserId, pageReqVO);
} }
} }

View File

@ -1,91 +0,0 @@
package cn.iocoder.yudao.module.bpm.util;
import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.ExtensionElement;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.bpmn.model.FlowNode;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import java.util.List;
import java.util.Map;
/**
* 流程引擎工具类封装
*
* @author: linjinp
* @create: 2019-12-24 13:51
**/
public class FlowableUtils {
/**
* 获取流程名称
*
* @param processDefinitionId
* @return
*/
public static String getProcessDefinitionName(String processDefinitionId) {
RepositoryService repositoryService = SpringUtil.getBean(RepositoryService.class);
ProcessDefinition processDefinition = repositoryService.getProcessDefinition(processDefinitionId);
return processDefinition.getName();
}
public static ProcessDefinition getProcessDefinition(String processDefinitionId) {
RepositoryService repositoryService = SpringUtil.getBean(RepositoryService.class);
return repositoryService.getProcessDefinition(processDefinitionId);
}
/**
* 获取节点数据
*
* @param processInstanceId
* @param nodeId
* @return
*/
public static FlowNode getFlowNode(String processInstanceId, String nodeId) {
RuntimeService runtimeService = SpringUtil.getBean(RuntimeService.class);
RepositoryService repositoryService = SpringUtil.getBean(RepositoryService.class);
String definitionld = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult().getProcessDefinitionId(); // 获取bpm模型对象
BpmnModel bpmnModel = repositoryService.getBpmnModel(definitionld);
// 传节点定义key获取当前节点
FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(nodeId);
return flowNode;
}
public static ExtensionElement generateFlowNodeIdExtension(String nodeId) {
ExtensionElement extensionElement = new ExtensionElement();
extensionElement.setElementText(nodeId);
extensionElement.setName("nodeId");
extensionElement.setNamespacePrefix("flowable");
extensionElement.setNamespace("nodeId");
return extensionElement;
}
public static String getNodeIdFromExtension(FlowElement flowElement) {
Map<String, List<ExtensionElement>> extensionElements = flowElement.getExtensionElements();
return extensionElements.get("nodeId").get(0).getElementText();
}
public static Long getStartUserIdFromProcessInstance(ProcessInstance instance) {
if (null == instance) {
return null;
}
return NumberUtils.parseLong(instance.getStartUserId());
}
public static String getTaskNameByTaskId(String taskId) {
TaskService taskService = SpringUtil.getBean(TaskService.class);
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
return task.getName();
}
}

View File

@ -1,17 +0,0 @@
package cn.iocoder.yudao.module.bpm.service.cc;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.bpm.service.task.cc.BpmProcessInstanceCopyServiceImpl;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
@Import({BpmProcessInstanceCopyServiceImpl.class})
class BpmProcessInstanceCopyServiceTest extends BaseDbUnitTest {
@Resource
private BpmProcessInstanceCopyServiceImpl service;
@Test
void queryById() {
}
}