refactor: 调整代码分装层次

This commit is contained in:
kyle 2024-01-22 13:59:37 +08:00
parent 97d6aab41c
commit b4150cafa7
3 changed files with 48 additions and 30 deletions

View File

@ -1,20 +1,34 @@
package cn.iocoder.yudao.module.bpm.controller.admin.task; package cn.iocoder.yudao.module.bpm.controller.admin.task;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
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.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.service.task.BpmProcessInstanceService;
import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService;
import cn.iocoder.yudao.module.bpm.service.task.cc.BpmProcessInstanceCopyService; import cn.iocoder.yudao.module.bpm.service.task.cc.BpmProcessInstanceCopyService;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import io.swagger.v3.oas.annotations.Operation; 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.Set;
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.convertSet;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@Tag(name = "管理后台 - 流程实例抄送") @Tag(name = "管理后台 - 流程实例抄送")
@ -25,6 +39,13 @@ public class BpmProcessInstanceCopyController {
@Resource @Resource
private BpmProcessInstanceCopyService processInstanceCopyService; private BpmProcessInstanceCopyService processInstanceCopyService;
@Resource
private BpmProcessInstanceService bpmProcessInstanceService;
@Resource
private AdminUserApi adminUserApi;
@Resource
private BpmTaskService bpmTaskService;
@PostMapping("/create") @PostMapping("/create")
@Operation(summary = "抄送流程") @Operation(summary = "抄送流程")
@ -38,7 +59,28 @@ public class BpmProcessInstanceCopyController {
@PreAuthorize("@ss.hasPermission('bpm:process-instance-cc:query')") @PreAuthorize("@ss.hasPermission('bpm:process-instance-cc:query')")
public CommonResult<PageResult<BpmProcessInstanceCopyPageItemRespVO>> getProcessInstanceCCPage( public CommonResult<PageResult<BpmProcessInstanceCopyPageItemRespVO>> getProcessInstanceCCPage(
@Valid BpmProcessInstanceCopyMyPageReqVO pageReqVO) { @Valid BpmProcessInstanceCopyMyPageReqVO pageReqVO) {
return success(processInstanceCopyService.getMyProcessInstanceCopyPage(getLoginUserId(), pageReqVO)); return success(getMyProcessInstanceCopyPage(getLoginUserId(), pageReqVO));
} }
public PageResult<BpmProcessInstanceCopyPageItemRespVO> getMyProcessInstanceCopyPage(Long loginUserId, BpmProcessInstanceCopyMyPageReqVO pageReqVO) {
PageResult<BpmProcessInstanceCopyDO> pageResult = processInstanceCopyService.getMyProcessInstanceCopyPage(loginUserId, pageReqVO);
if (CollUtil.isEmpty(pageResult.getList())) {
return 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));
Set<Long/* userId */> userIds = new HashSet<>();
for (BpmProcessInstanceCopyDO doItem : pageResult.getList()) {
userIds.add(doItem.getStartUserId());
Long userId = Long.valueOf(doItem.getCreator());
userIds.add(userId);
}
Map<Long, String> userMap = adminUserApi.getUserList(userIds).stream().collect(Collectors.toMap(
AdminUserRespDTO::getId, AdminUserRespDTO::getNickname));
// 转换返回
return BpmProcessInstanceCopyConvert.INSTANCE.convertPage(pageResult, taskNameByTaskIds, processInstanceNameByProcessInstanceIds, userMap);
}
} }

View File

@ -4,6 +4,7 @@ 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.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; import cn.iocoder.yudao.module.bpm.service.candidate.BpmCandidateSourceInfo;
/** /**
@ -35,6 +36,6 @@ public interface BpmProcessInstanceCopyService {
* @param pageReqVO 分页请求 * @param pageReqVO 分页请求
* @return 抄送的分页结果 * @return 抄送的分页结果
*/ */
PageResult<BpmProcessInstanceCopyPageItemRespVO> getMyProcessInstanceCopyPage(Long loginUserId, PageResult<BpmProcessInstanceCopyDO> getMyProcessInstanceCopyPage(Long loginUserId,
BpmProcessInstanceCopyMyPageReqVO pageReqVO); BpmProcessInstanceCopyMyPageReqVO pageReqVO);
} }

View File

@ -62,12 +62,6 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy
@Lazy @Lazy
private BpmTaskService bpmTaskService; private BpmTaskService bpmTaskService;
@Resource
@Lazy // 解决循环依赖
private BpmProcessInstanceService bpmProcessInstanceService;
@Resource
private AdminUserApi adminUserApi;
@Override @Override
public boolean makeCopy(BpmCandidateSourceInfo sourceInfo) { public boolean makeCopy(BpmCandidateSourceInfo sourceInfo) {
if (null == sourceInfo) { if (null == sourceInfo) {
@ -163,28 +157,9 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy
} }
@Override @Override
public PageResult<BpmProcessInstanceCopyPageItemRespVO> getMyProcessInstanceCopyPage(Long loginUserId, BpmProcessInstanceCopyMyPageReqVO pageReqVO) { public PageResult<BpmProcessInstanceCopyDO> getMyProcessInstanceCopyPage(Long loginUserId, BpmProcessInstanceCopyMyPageReqVO pageReqVO) {
// 通过 BpmProcessInstanceExtDO 先查询到对应的分页 // 通过 BpmProcessInstanceExtDO 先查询到对应的分页
// TODO @kyle一般读逻辑Service 返回 PageResult<BpmProcessInstanceCopyDO> 即可关联数据的查询和拼接交给 Controller目的是保证 Service 聚焦写逻辑清晰简洁 return processInstanceCopyMapper.selectPage(loginUserId, pageReqVO);
PageResult<BpmProcessInstanceCopyDO> pageResult = processInstanceCopyMapper.selectPage(loginUserId, pageReqVO);
if (CollUtil.isEmpty(pageResult.getList())) {
return 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));
Set<Long/* userId */> userIds = new HashSet<>();
for (BpmProcessInstanceCopyDO doItem : pageResult.getList()) {
userIds.add(doItem.getStartUserId());
Long userId = Long.valueOf(doItem.getCreator());
userIds.add(userId);
}
Map<Long, String> userMap = adminUserApi.getUserList(userIds).stream().collect(Collectors.toMap(
AdminUserRespDTO::getId, AdminUserRespDTO::getNickname));
// 转换返回
return BpmProcessInstanceCopyConvert.INSTANCE.convertPage(pageResult, taskNameByTaskIds, processInstanceNameByProcessInstanceIds, userMap);
} }
} }