From 7bb171512a35522ae060e4b0a313a55ca2be8cef Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 23 Jan 2024 12:55:13 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=96=20BPM=EF=BC=9Acode=20review=20?= =?UTF-8?q?=E6=8A=84=E9=80=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BpmProcessInstanceCopyController.java | 34 +++---- .../BpmProcessInstanceCopyCreateReqVO.java | 7 +- .../BpmProcessInstanceCopyPageItemRespVO.java | 2 +- .../vo/task/BpmProcessInstanceCopyVO.java | 2 + .../cc/BpmProcessInstanceCopyConvert.java | 23 ++--- .../cc/BpmProcessInstanceCopyDO.java | 22 ++--- .../task/BpmProcessInstanceService.java | 11 +++ .../bpm/service/task/BpmTaskService.java | 16 +--- .../bpm/service/task/BpmTaskServiceImpl.java | 30 +----- .../cc/BpmProcessInstanceCopyService.java | 7 +- .../cc/BpmProcessInstanceCopyServiceImpl.java | 78 ++++++---------- .../yudao/module/bpm/util/FlowableUtils.java | 91 ------------------- .../cc/BpmProcessInstanceCopyServiceTest.java | 17 ---- 13 files changed, 87 insertions(+), 253 deletions(-) delete mode 100644 yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/util/FlowableUtils.java delete mode 100644 yudao-module-bpm/yudao-module-bpm-biz/src/test/java/cn/iocoder/yudao/module/bpm/service/cc/BpmProcessInstanceCopyServiceTest.java diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/BpmProcessInstanceCopyController.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/BpmProcessInstanceCopyController.java index 98e04dd0a..fe3511af7 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/BpmProcessInstanceCopyController.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/BpmProcessInstanceCopyController.java @@ -17,17 +17,15 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import jakarta.validation.Valid; -import org.springframework.context.annotation.Lazy; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import java.util.HashSet; import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; +import java.util.stream.Stream; 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.security.core.util.SecurityFrameworkUtils.getLoginUserId; @@ -41,6 +39,7 @@ public class BpmProcessInstanceCopyController { private BpmProcessInstanceCopyService processInstanceCopyService; @Resource private BpmProcessInstanceService bpmProcessInstanceService; + @Resource private AdminUserApi adminUserApi; @@ -50,8 +49,9 @@ public class BpmProcessInstanceCopyController { @PostMapping("/create") @Operation(summary = "抄送流程") @PreAuthorize("@ss.hasPermission('bpm:process-instance-cc:create')") - public CommonResult createProcessInstanceCC(@Valid @RequestBody BpmProcessInstanceCopyCreateReqVO createReqVO) { - return success(processInstanceCopyService.createProcessInstanceCopy(getLoginUserId(), createReqVO)); + public CommonResult createProcessInstanceCC(@Valid @RequestBody BpmProcessInstanceCopyCreateReqVO createReqVO) { + processInstanceCopyService.createProcessInstanceCopy(getLoginUserId(), createReqVO); + return success(true); } @GetMapping("/my-page") @@ -64,20 +64,14 @@ public class BpmProcessInstanceCopyController { return success(new PageResult<>(pageResult.getTotal())); } - Map taskNameByTaskIds = bpmTaskService.getTaskNameByTaskIds(convertSet(pageResult.getList(), BpmProcessInstanceCopyDO::getTaskId)); - Map processInstanceNameByProcessInstanceIds = bpmTaskService.getProcessInstanceNameByProcessInstanceIds(convertSet(pageResult.getList(), BpmProcessInstanceCopyDO::getProcessInstanceId)); - - Set userIds = new HashSet<>(); - for (BpmProcessInstanceCopyDO doItem : pageResult.getList()) { - userIds.add(doItem.getStartUserId()); - Long userId = Long.valueOf(doItem.getCreator()); - userIds.add(userId); - } - Map userMap = adminUserApi.getUserList(userIds).stream().collect(Collectors.toMap( - AdminUserRespDTO::getId, AdminUserRespDTO::getNickname)); - - // 转换返回 - return success(BpmProcessInstanceCopyConvert.INSTANCE.convertPage(pageResult, taskNameByTaskIds, processInstanceNameByProcessInstanceIds, userMap)); + // 拼接返回 + Map taskNameMap = bpmTaskService.getTaskNameByTaskIds( + convertSet(pageResult.getList(), BpmProcessInstanceCopyDO::getTaskId)); + Map processNameMap = bpmProcessInstanceService.getProcessInstanceNameMap( + convertSet(pageResult.getList(), BpmProcessInstanceCopyDO::getProcessInstanceId)); + Map userMap = adminUserApi.getUserMap(convertListByFlatMap(pageResult.getList(), + copy -> Stream.of(copy.getStartUserId(), Long.parseLong(copy.getCreator())))); + return success(BpmProcessInstanceCopyConvert.INSTANCE.convertPage(pageResult, taskNameMap, processNameMap, userMap)); } } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/instance/BpmProcessInstanceCopyCreateReqVO.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/instance/BpmProcessInstanceCopyCreateReqVO.java index 5847d2a1c..3a1b1d45c 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/instance/BpmProcessInstanceCopyCreateReqVO.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/instance/BpmProcessInstanceCopyCreateReqVO.java @@ -1,18 +1,13 @@ 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 jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotEmpty; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; @Schema(description = "管理后台 - 流程实例抄送的创建 Request VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class BpmProcessInstanceCopyCreateReqVO extends BpmTaskCandidateRuleVO { +public class BpmProcessInstanceCopyCreateReqVO { @Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @NotEmpty(message = "任务编号不能为空") diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/instance/BpmProcessInstanceCopyPageItemRespVO.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/instance/BpmProcessInstanceCopyPageItemRespVO.java index ee23e4c0b..4b149a65e 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/instance/BpmProcessInstanceCopyPageItemRespVO.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/instance/BpmProcessInstanceCopyPageItemRespVO.java @@ -12,7 +12,7 @@ public class BpmProcessInstanceCopyPageItemRespVO { @Schema(description = "抄送主键") private Long id; - @Schema(description = "发起人Id") + @Schema(description = "发起人 ID") private Long startUserId; @Schema(description = "发起人别名") diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmProcessInstanceCopyVO.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmProcessInstanceCopyVO.java index 4be3d0bbe..977ec41d8 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmProcessInstanceCopyVO.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmProcessInstanceCopyVO.java @@ -5,6 +5,7 @@ import lombok.Data; import java.time.LocalDateTime; +// TODO @kyle:1)明确是 Req 还是 Resp;2)注释可以合并到 swagger 里;3)example 写一下,这样一些 mock 接口平台可以读取 example /** * 流程抄送视图对象 */ @@ -60,4 +61,5 @@ public class BpmProcessInstanceCopyVO { @Schema(description = "抄送时间") private LocalDateTime createTime; + } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/cc/BpmProcessInstanceCopyConvert.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/cc/BpmProcessInstanceCopyConvert.java index 1b949dff3..f482c71e6 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/cc/BpmProcessInstanceCopyConvert.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/cc/BpmProcessInstanceCopyConvert.java @@ -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.object.BeanUtils; 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.system.api.user.dto.AdminUserRespDTO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -22,22 +22,17 @@ public interface BpmProcessInstanceCopyConvert { BpmProcessInstanceCopyConvert INSTANCE = Mappers.getMapper(BpmProcessInstanceCopyConvert.class); - BpmProcessInstanceCopyVO convert(BpmProcessInstanceCopyDO bean); - - List convertList(List list); - - default PageResult convertPage(PageResult page - , Map taskMap - , Map processInstaneMap - , Map userMap - ) { + default PageResult convertPage(PageResult page, + Map taskNameMap, + Map processInstaneNameMap, + Map userMap) { List list = BeanUtils.toBean(page.getList(), BpmProcessInstanceCopyPageItemRespVO.class, copy -> { - MapUtils.findAndThen(userMap, Long.valueOf(copy.getCreator()), copy::setCreatorNickname); - MapUtils.findAndThen(userMap, copy.getStartUserId(), copy::setStartUserNickname); - MapUtils.findAndThen(taskMap, copy.getTaskId(), copy::setTaskName); - MapUtils.findAndThen(processInstaneMap, copy.getProcessInstanceId(), copy::setProcessInstanceName); + MapUtils.findAndThen(userMap, Long.valueOf(copy.getCreator()), user -> user.setNickname(user.getNickname())); + MapUtils.findAndThen(userMap, copy.getStartUserId(), user -> copy.setStartUserNickname(user.getNickname())); + MapUtils.findAndThen(taskNameMap, copy.getTaskId(), copy::setTaskName); + MapUtils.findAndThen(processInstaneNameMap, copy.getProcessInstanceId(), copy::setProcessInstanceName); }); return new PageResult<>(list, page.getTotal()); } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/dataobject/cc/BpmProcessInstanceCopyDO.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/dataobject/cc/BpmProcessInstanceCopyDO.java index c9192e103..7ca65f3db 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/dataobject/cc/BpmProcessInstanceCopyDO.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/dataobject/cc/BpmProcessInstanceCopyDO.java @@ -28,40 +28,40 @@ public class BpmProcessInstanceCopyDO extends BaseDO { /** * 发起人 Id - *

+ * * 关联 system_users 的 id 属性 */ private Long startUserId; /** * 流程名 - *

- * 冗余字段 + * + * 冗余 ProcessInstance 的 name 字段 */ private String processInstanceName; /** * 流程实例的编号 - *

+ * * 关联 ProcessInstance 的 id 属性 */ private String processInstanceId; /** * 任务主键 - *

- * 关联 task 的 id 属性 + * + * 关联 Task 的 id 属性 */ private String taskId; /** * 任务名称 - *

- * 冗余字段 + * + * 冗余 Task 的 name 属性 */ private String taskName; /** * 用户编号 - *

+ * * 关联 system_users 的 id 属性 */ private Long userId; @@ -73,8 +73,8 @@ public class BpmProcessInstanceCopyDO extends BaseDO { /** * 流程分类 - *

- * 冗余字段 + * + * 冗余 ProcessInstance 的 category 字段 */ private String category; diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceService.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceService.java index a0cc1c71b..01a29c559 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceService.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceService.java @@ -46,6 +46,17 @@ public interface BpmProcessInstanceService { return CollectionUtils.convertMap(getProcessInstances(ids), ProcessInstance::getProcessInstanceId); } + /** + * 获得流程实例名字 Map + * + * @param ids 流程实例的编号集合 + * @return 对应的映射关系 + */ + default Map getProcessInstanceNameMap(Set ids) { + return CollectionUtils.convertMap(getProcessInstances(ids), + ProcessInstance::getProcessInstanceId, ProcessInstance::getName); + } + /** * 获得流程实例的分页 * diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java index 05925a858..97018451d 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java @@ -10,7 +10,6 @@ import org.flowable.task.api.Task; import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.Set; /** * 流程任务实例 Service 接口 @@ -186,18 +185,11 @@ public interface BpmTaskService { List getChildrenTaskList(String parentId); /** - * 通过任务id查询任务名 + * 通过任务 ID,查询任务名 Map * - * @param taskIds 任务id - * @return 对应的映射关系 + * @param taskIds 任务 ID + * @return 任务 ID 与名字的 Map */ - Map getTaskNameByTaskIds(Collection taskIds); + Map getTaskNameByTaskIds(Collection taskIds); - /** - * 通过流程实例id获取到流程实例名 - * - * @param processInstaneIds 流程实例Id - * @return 对应的映射关系 - */ - Map getProcessInstanceNameByProcessInstanceIds(Set processInstaneIds); } 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 eaebccb93..6e9929d37 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 @@ -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.service.definition.BpmModelService; 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.dto.DeptRespDTO; import cn.iocoder.yudao.module.system.api.user.AdminUserApi; @@ -95,9 +94,6 @@ public class BpmTaskServiceImpl implements BpmTaskService { @Resource private ManagementService managementService; - @Resource - private BpmProcessInstanceCopyService processInstanceCopyService; - @Override public PageResult getTodoTaskPage(Long userId, BpmTaskTodoPageReqVO pageVO) { // 查询待办任务 @@ -972,28 +968,12 @@ public class BpmTaskServiceImpl implements BpmTaskService { } @Override - public Map getTaskNameByTaskIds(Collection taskIds) { - List tasks = taskService.createTaskQuery().taskIds(taskIds).list(); - if (CollUtil.isNotEmpty(tasks)) { - Map taskMap = new HashMap<>(tasks.size()); - for (Task task : tasks) { - taskMap.putIfAbsent(task.getId(), task.getName()); - } - return taskMap; + public Map getTaskNameByTaskIds(Collection taskIds) { + if (CollUtil.isEmpty(taskIds)) { + return Collections.emptyMap(); } - return Collections.emptyMap(); + List tasks = taskService.createTaskQuery().taskIds(taskIds).list(); + return convertMap(tasks, Task::getId, Task::getName); } - @Override - public Map getProcessInstanceNameByProcessInstanceIds(Set processInstanceIds) { - List processInstances = runtimeService.createProcessInstanceQuery().processInstanceIds(processInstanceIds).list(); - if (CollUtil.isNotEmpty(processInstances)) { - Map processInstaneMap = new HashMap<>(processInstances.size()); - for (ProcessInstance processInstance : processInstances) { - processInstaneMap.putIfAbsent(processInstance.getId(), processInstance.getName()); - } - return processInstaneMap; - } - return Collections.emptyMap(); - } } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/cc/BpmProcessInstanceCopyService.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/cc/BpmProcessInstanceCopyService.java index 93ab42492..208749a57 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/cc/BpmProcessInstanceCopyService.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/cc/BpmProcessInstanceCopyService.java @@ -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.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.BpmProcessInstanceCopyPageItemRespVO; import cn.iocoder.yudao.module.bpm.dal.dataobject.cc.BpmProcessInstanceCopyDO; import cn.iocoder.yudao.module.bpm.service.candidate.BpmCandidateSourceInfo; @@ -28,14 +27,14 @@ public interface BpmProcessInstanceCopyService { * @param userId 当前登录用户 * @param createReqVO 创建的抄送请求 */ - Void createProcessInstanceCopy(Long userId, BpmProcessInstanceCopyCreateReqVO createReqVO); + void createProcessInstanceCopy(Long userId, BpmProcessInstanceCopyCreateReqVO createReqVO); /** * 抄送的流程的分页 - * @param loginUserId 登录用户id + * @param userId 当前登录用户 * @param pageReqVO 分页请求 * @return 抄送的分页结果 */ - PageResult getMyProcessInstanceCopyPage(Long loginUserId, + PageResult getMyProcessInstanceCopyPage(Long userId, BpmProcessInstanceCopyMyPageReqVO pageReqVO); } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/cc/BpmProcessInstanceCopyServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/cc/BpmProcessInstanceCopyServiceImpl.java index aad9815f4..50d042cdc 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/cc/BpmProcessInstanceCopyServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/cc/BpmProcessInstanceCopyServiceImpl.java @@ -7,25 +7,18 @@ import cn.hutool.core.util.StrUtil; 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.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.mysql.cc.BpmProcessInstanceCopyMapper; 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.BpmCandidateSourceInfoProcessorChain; 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.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 lombok.extern.slf4j.Slf4j; import org.flowable.engine.RuntimeService; import org.flowable.engine.delegate.DelegateExecution; -import org.flowable.engine.repository.ProcessDefinition; import org.flowable.engine.runtime.ProcessInstance; import org.flowable.task.api.Task; import org.springframework.context.annotation.Lazy; @@ -33,14 +26,14 @@ import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import java.time.LocalDateTime; -import java.util.*; -import java.util.stream.Collectors; +import java.util.ArrayList; +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.util.collection.CollectionUtils.convertSet; /** - * Flowable流程抄送实现 + * 流程抄送 Service 实现类 * * @author kyle */ @@ -61,6 +54,9 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy @Resource @Lazy private BpmTaskService bpmTaskService; + @Resource + @Lazy + private BpmProcessInstanceService bpmProcessInstanceService; @Override public boolean makeCopy(BpmCandidateSourceInfo sourceInfo) { @@ -86,7 +82,7 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy // 调用 // 设置任务id copyDO.setTaskId(sourceInfo.getTaskId()); - copyDO.setTaskName(FlowableUtils.getTaskNameByTaskId(sourceInfo.getTaskId())); + copyDO.setTaskName(task.getName()); copyDO.setProcessInstanceId(processInstanceId); ProcessInstance processInstance = runtimeService.createProcessInstanceQuery() .processInstanceId(processInstanceId) @@ -95,10 +91,9 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy log.warn("相关流程实例不存在 {}", sourceInfo.getTaskId()); return false; } - copyDO.setStartUserId(FlowableUtils.getStartUserIdFromProcessInstance(processInstance)); + copyDO.setStartUserId(Long.parseLong(processInstance.getStartUserId())); copyDO.setProcessInstanceName(processInstance.getName()); - ProcessDefinition processDefinition = FlowableUtils.getProcessDefinition(processInstance.getProcessDefinitionId()); - copyDO.setCategory(processDefinition.getCategory()); + copyDO.setCategory(processInstance.getProcessDefinitionCategory()); copyDO.setReason(sourceInfo.getReason()); copyDO.setCreator(sourceInfo.getCreator()); copyDO.setCreateTime(LocalDateTime.now()); @@ -113,53 +108,32 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy } @Override - public Void createProcessInstanceCopy(Long userId, BpmProcessInstanceCopyCreateReqVO reqVO) { - if (!ObjectUtil.equal(reqVO.getType(), BpmTaskAssignRuleTypeEnum.USER.getType())) { - throw new IllegalArgumentException("业务仅支持USER"); - } + public void createProcessInstanceCopy(Long userId, BpmProcessInstanceCopyCreateReqVO reqVO) { + // 1.1 校验任务存在 Task task = bpmTaskService.getTask(reqVO.getTaskId()); if (ObjectUtil.isNull(task)) { throw exception(ErrorCodeConstants.TASK_NOT_EXISTS); } + // 1.2 校验流程存在 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); } - // 在能正常审批的情况下抄送流程 - BpmProcessInstanceCopyDO copyDO = new BpmProcessInstanceCopyDO(); - // 调用 - // 设置任务id - copyDO.setTaskId(reqVO.getTaskId()); - copyDO.setTaskName(FlowableUtils.getTaskNameByTaskId(reqVO.getTaskId())); - copyDO.setProcessInstanceId(processInstanceId); - ProcessInstance processInstance = runtimeService.createProcessInstanceQuery() - .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 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; + + // 2. 创建抄送流程 + BpmProcessInstanceCopyDO copy = new BpmProcessInstanceCopyDO() + .setTaskId(reqVO.getTaskId()).setTaskName(task.getName()) + .setProcessInstanceId(processInstanceId).setStartUserId(Long.valueOf(processInstance.getStartUserId())) + .setProcessInstanceName(processInstance.getName()).setCategory(processInstance.getProcessDefinitionCategory()) + .setReason(reqVO.getReason()); + processInstanceCopyMapper.insert(copy); } @Override - public PageResult getMyProcessInstanceCopyPage(Long loginUserId, BpmProcessInstanceCopyMyPageReqVO pageReqVO) { - // 通过 BpmProcessInstanceExtDO 表,先查询到对应的分页 - return processInstanceCopyMapper.selectPage(loginUserId, pageReqVO); + public PageResult getMyProcessInstanceCopyPage(Long userId, BpmProcessInstanceCopyMyPageReqVO pageReqVO) { + return processInstanceCopyMapper.selectPage(userId, pageReqVO); } } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/util/FlowableUtils.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/util/FlowableUtils.java deleted file mode 100644 index c877c2a4a..000000000 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/util/FlowableUtils.java +++ /dev/null @@ -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> 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(); - } - -} diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/test/java/cn/iocoder/yudao/module/bpm/service/cc/BpmProcessInstanceCopyServiceTest.java b/yudao-module-bpm/yudao-module-bpm-biz/src/test/java/cn/iocoder/yudao/module/bpm/service/cc/BpmProcessInstanceCopyServiceTest.java deleted file mode 100644 index 8434399e0..000000000 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/test/java/cn/iocoder/yudao/module/bpm/service/cc/BpmProcessInstanceCopyServiceTest.java +++ /dev/null @@ -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() { - } -} \ No newline at end of file