BPM:抄送任务的 code review

This commit is contained in:
YunaiV 2024-01-18 19:07:01 +08:00
parent a5dc4e7876
commit ee1870802f
16 changed files with 84 additions and 74 deletions

View File

@ -2,20 +2,18 @@ package cn.iocoder.yudao.module.bpm.controller.admin.task;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.*;
import cn.iocoder.yudao.module.bpm.service.cc.BpmProcessInstanceCopyService;
import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@ -62,19 +60,21 @@ public class BpmProcessInstanceController {
return success(true);
}
// TODO @kyle抄送要不单独 controller
@PostMapping("/cc/create")
@Operation(summary = "抄送流程")
@PreAuthorize("@ss.hasPermission('bpm:process-instance-cc:create')")
public CommonResult<Boolean> createProcessInstanceCC(@Valid @RequestBody BpmProcessInstanceCCReqVO createReqVO) {
return success(processInstanceCopyService.ccProcessInstance(SecurityFrameworkUtils.getLoginUserId(), createReqVO));
return success(processInstanceCopyService.ccProcessInstance(getLoginUserId(), createReqVO));
}
@GetMapping("/cc/my-page")
@Operation(summary = "获得抄送流程分页列表")
@PreAuthorize("@ss.hasPermission('bpm:process-instance-cc:query')")
public CommonResult<PageResult<BpmProcessInstanceCCPageItemRespVO>> getProcessInstanceCCPage(@Valid BpmProcessInstanceCCMyPageReqVO pageReqVO) {
return success(processInstanceCopyService.getMyProcessInstanceCCPage(SecurityFrameworkUtils.getLoginUserId(), pageReqVO));
public CommonResult<PageResult<BpmProcessInstanceCCPageItemRespVO>> getProcessInstanceCCPage(
@Valid BpmProcessInstanceCCMyPageReqVO pageReqVO) {
return success(processInstanceCopyService.getMyProcessInstanceCCPage(getLoginUserId(), pageReqVO));
}
}

View File

@ -11,7 +11,8 @@ import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 流程实例抄送的分页 Item Response VO")
// TODO @kyle建议改成 BpmProcessInstanceCopyMyPageReqVOcc 缩写不容易理解所以改成 copy虽然会长一点但是可读性更重要
@Schema(description = "管理后台 - 流程实例抄送的分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)

View File

@ -9,6 +9,7 @@ import java.time.LocalDateTime;
@Data
public class BpmProcessInstanceCCPageItemRespVO {
// TODO @kyle如果已经写了 swagger 注解可以不用写 java 注释哈
/**
* 编号
*/
@ -52,4 +53,5 @@ public class BpmProcessInstanceCCPageItemRespVO {
@Schema(description = "抄送时间")
private LocalDateTime createTime;
}

View File

@ -9,8 +9,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.Set;
// TODO @kyle这个 VO 可以改成 BpmProcessInstanceCopyCreateReqVO
@Schema(description = "管理后台 - 流程实例的抄送 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ -33,7 +32,6 @@ public class BpmProcessInstanceCCReqVO extends BpmTaskCandidateRuleVO {
@NotNull(message = "发起流程的用户的编号不能为空")
private Long startUserId;
@Schema(description = "任务实例名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotEmpty(message = "任务实例名称不能为空")
private String processInstanceName;
@ -41,4 +39,9 @@ public class BpmProcessInstanceCCReqVO extends BpmTaskCandidateRuleVO {
@Schema(description = "抄送原因", requiredMode = Schema.RequiredMode.REQUIRED, example = "请帮忙审查下!")
@NotBlank(message = "抄送原因不能为空")
private String reason;
// TODO @kyle看了下字段有点多尽量不传递可推导的字段
// 需要传递taskId任务编号reasonuserIds被抄送的人
// 不需要传递taskKeytaskNameprocessInstanceKeystartUserIdprocessInstanceName 因为这些可以后端查询到
}

View File

@ -11,6 +11,7 @@ import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.Map;
// TODO kyle类注释不太对
/**
* 动态表单 Convert
*
@ -21,14 +22,14 @@ public interface BpmProcessInstanceCopyConvert {
BpmProcessInstanceCopyConvert INSTANCE = Mappers.getMapper(BpmProcessInstanceCopyConvert.class);
// TODO @kyle可以使用 BeanUtils copy 替代这些简单的哈
BpmProcessInstanceCopyDO copy(BpmProcessInstanceCopyDO bean);
BpmProcessInstanceCopyVO convert(BpmProcessInstanceCopyDO bean);
List<BpmProcessInstanceCopyVO> convertList2(List<BpmProcessInstanceCopyDO> list);
List<BpmProcessInstanceCCPageItemRespVO> convertList(List<BpmProcessInstanceCopyDO> list);
// TODO @kyle/* taskId */ 这种注释一般不用写可以一眼看明白的避免变量看着略微不清晰哈
default PageResult<BpmProcessInstanceCCPageItemRespVO> convertPage(PageResult<BpmProcessInstanceCopyDO> page
, Map<String/* taskId */, String/* taskName */> taskMap
, Map<String/* processInstaneId */, String/* processInstaneName */> processInstaneMap
@ -45,6 +46,15 @@ public interface BpmProcessInstanceCopyConvert {
MapUtils.findAndThen(processInstaneMap, vo.getProcessInstanceId(),
vo::setProcessInstanceName);
}
// TODO @kyle可以精简成下面的哈
// List<BpmProcessInstanceCCPageItemRespVO> list2 = BeanUtils.toBean(page.getList(),
// BpmProcessInstanceCCPageItemRespVO.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);
// });
return new PageResult<>(list, page.getTotal());
}

View File

@ -6,10 +6,10 @@ import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
/**
* 流程抄送对象
* 流程抄送 DO
*
* @author kyle
* @date 2022-05-19
* @date 2022-05-19 TODO @kyle@date 不是标准 java doc可以使用 @since 替代然后日期是不是不对
*/
@TableName(value = "bpm_process_instance_copy", autoResultMap = true)
@Data
@ -26,6 +26,7 @@ public class BpmProcessInstanceCopyDO extends BaseDO {
@TableId
private Long id;
// TODO @kyle字段如果是关联或者冗余要写下注释 processInstanceId 举例子
/**
* 发起人 Id
*/
@ -35,7 +36,9 @@ public class BpmProcessInstanceCopyDO extends BaseDO {
*/
private String processInstanceName;
/**
* 流程主键
* 流程实例的编号
*
* 关联 ProcessInstance id 属性
*/
private String processInstanceId;
@ -50,7 +53,7 @@ public class BpmProcessInstanceCopyDO extends BaseDO {
private String taskName;
/**
* 用户主键
* 用户编号
*/
private Long userId;
@ -59,6 +62,7 @@ public class BpmProcessInstanceCopyDO extends BaseDO {
*/
private String reason;
// TODO @kyle这个字段可以用 category 简化点
/**
* 流程分类
*/

View File

@ -8,7 +8,7 @@ import cn.iocoder.yudao.module.bpm.dal.dataobject.cc.BpmProcessInstanceCopyDO;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface BpmProcessInstanceCopyMapper extends BaseMapperX<BpmProcessInstanceCopyDO> {
public interface BpmProcessInstanceCopyMapper extends BaseMapperX<BpmProcessInstanceCopyDO> { // TODO @kyle方法和类之间要空行下
default PageResult<BpmProcessInstanceCopyDO> selectPage(Long loginUserId, BpmProcessInstanceCCMyPageReqVO reqVO){
return selectPage(reqVO, new LambdaQueryWrapperX<BpmProcessInstanceCopyDO>()
.eqIfPresent(BpmProcessInstanceCopyDO::getUserId, loginUserId)

View File

@ -6,8 +6,7 @@ import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.List;
// TODO @芋艿Candidate 相关还在完善中用户可以暂时忽略 yudao 开发的同学需要关注~计划是把 Candidate Assign 融合成一套
/**
* BPM 通用的 Configuration 配置类提供给 Activiti Flowable
* @author kyle

View File

@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessI
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceCCReqVO;
import cn.iocoder.yudao.module.bpm.service.candidate.BpmCandidateSourceInfo;
// TODO @kyle这个 Service 要不挪到 task 包下保持统一task 下有流程任务抄送等
// TODO @kyle中文和英文之间有个空格会更清晰点例如说流程抄送 Service 接口中文写作习惯~
/**
* 流程抄送Service接口
*
@ -13,6 +15,7 @@ import cn.iocoder.yudao.module.bpm.service.candidate.BpmCandidateSourceInfo;
*/
public interface BpmProcessInstanceCopyService {
// TODO @kyle无用的方法可以去掉哈另外考虑到避免过多的 VO这里就可以返回 BpmProcessInstanceCopyDO
/**
* 查询流程抄送
*
@ -21,6 +24,7 @@ public interface BpmProcessInstanceCopyService {
*/
BpmProcessInstanceCopyVO queryById(Long copyId);
// TODO 芋艿这块要 review 思考下~~
/**
* 抄送
* @param sourceInfo 抄送源信息方便抄送处理
@ -28,13 +32,15 @@ public interface BpmProcessInstanceCopyService {
*/
boolean makeCopy(BpmCandidateSourceInfo sourceInfo);
// TODO @kyle可以方法名改成 createProcessInstanceCopy现在项目一般新增都用 create 为主
/**
* 流程实例的抄送
* @param loginUserId 当前登录用户
*
* @param userId 当前登录用户
* @param createReqVO 创建的抄送请求
* @return 是否抄送成功抄送成功则返回true
* @return 是否抄送成功抄送成功则返回true TODO @kyle这里可以不用返回哈目前一般是失败就抛出业务异常
*/
boolean ccProcessInstance(Long loginUserId, BpmProcessInstanceCCReqVO createReqVO);
boolean ccProcessInstance(Long userId, BpmProcessInstanceCCReqVO createReqVO);
/**
* 抄送的流程
@ -42,5 +48,6 @@ public interface BpmProcessInstanceCopyService {
* @param pageReqVO 分页请求
* @return 抄送的分页结果
*/
PageResult<BpmProcessInstanceCCPageItemRespVO> getMyProcessInstanceCCPage(Long loginUserId, BpmProcessInstanceCCMyPageReqVO pageReqVO);
PageResult<BpmProcessInstanceCCPageItemRespVO> getMyProcessInstanceCCPage(Long loginUserId,
BpmProcessInstanceCCMyPageReqVO pageReqVO);
}

View File

@ -11,10 +11,12 @@ import cn.iocoder.yudao.module.bpm.dal.mysql.cc.BpmProcessInstanceCopyMapper;
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.cc.dto.BpmDelegateExecutionDTO;
import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService;
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;
@ -24,33 +26,37 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
// TODO @kyle类注释要写下
@Slf4j // TODO @kyle按照 @Service@Validated@Slf4j从重要到不重要的顺序
@Service
@Validated
public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopyService {
@Resource
@Resource // TODO @kyle第一个变量和类之间要有空行
private BpmProcessInstanceCopyMapper processInstanceCopyMapper;
/**
* 和flowable有关的查询流程名用的
* 和flowable有关的查询流程名用的 TODO @kyle可以不写哈注释
*/
@Resource
private RuntimeService runtimeService;
/**
* 找抄送人用的
* 找抄送人用的 TODO @kyle可以不写哈注释
*/
@Resource
private BpmCandidateSourceInfoProcessorChain processorChain;
// TODO @kyle多余的变量可以去掉哈
@Resource
@Lazy // 解决循环依赖
private BpmTaskService taskService;
private BpmTaskService bpmTaskService;
@Resource
@Lazy // 解决循环依赖
private BpmProcessInstanceService bpmProcessInstanceService;
@Resource
private AdminUserApi adminUserApi;
@ -60,6 +66,10 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy
return BpmProcessInstanceCopyConvert.INSTANCE.convert(bpmProcessInstanceCopyDO);
}
// TODO @kylemakeCopy ccProcessInstance 的调用关系感受上反了
// makeCopy 有点像基于规则查找抄送人然后创建
// ccProcessInstance 是已经有了抄送人然后创建
// 建议的改造独立基于 processInstanceCopyMapper insert
@Override
public boolean makeCopy(BpmCandidateSourceInfo sourceInfo) {
if (null == sourceInfo) {
@ -103,13 +113,13 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy
}
@Override
public boolean ccProcessInstance(Long loginUserId, BpmProcessInstanceCCReqVO reqVO) {
public boolean ccProcessInstance(Long userId, BpmProcessInstanceCCReqVO reqVO) {
// 在能正常审批的情况下抄送流程
BpmCandidateSourceInfo sourceInfo = new BpmCandidateSourceInfo();
sourceInfo.setTaskId(reqVO.getTaskKey());
sourceInfo.setProcessInstanceId(reqVO.getProcessInstanceKey());
sourceInfo.addRule(reqVO);
sourceInfo.setCreator(String.valueOf(loginUserId));
sourceInfo.setCreator(String.valueOf(userId));
sourceInfo.setReason(reqVO.getReason());
if (!makeCopy(sourceInfo)) {
throw new RuntimeException("抄送任务失败");
@ -117,15 +127,20 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy
return false;
}
//获取流程抄送分页
//获取流程抄送分页 TODO @kyle接口已经注释这里不用注释了哈
@Override
public PageResult<BpmProcessInstanceCCPageItemRespVO> getMyProcessInstanceCCPage(Long loginUserId, BpmProcessInstanceCCMyPageReqVO pageReqVO) {
// 通过 BpmProcessInstanceExtDO 先查询到对应的分页
// TODO @kyle一般读逻辑Service 返回 PageResult<BpmProcessInstanceCopyDO> 即可关联数据的查询和拼接交给 Controller目的是保证 Service 聚焦写逻辑清晰简洁
PageResult<BpmProcessInstanceCopyDO> pageResult = processInstanceCopyMapper.selectPage(loginUserId, pageReqVO);
if (CollUtil.isEmpty(pageResult.getList())) {
return new PageResult<>(pageResult.getTotal());
}
// TODO @kyle这种可以简洁点参考如下
// Map<String, ProcessInstance> processInstanceMap = bpmProcessInstanceService.getProcessInstanceMap(
// convertSet(pageResult.getList(), BpmProcessInstanceCopyDO::getProcessInstanceId));
Set<String/* taskId */> taskIds = new HashSet<>();
Set<String/* processInstaneId */> processInstaneIds = new HashSet<>();
Set<Long/* userId */> userIds = new HashSet<>();

View File

@ -1,13 +1,11 @@
package cn.iocoder.yudao.module.bpm.service.cc;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.Date;
// TODO @kyle看看是不是要删除
/**
* 流程抄送视图对象 wf_copy
*

View File

@ -88,6 +88,7 @@ public class FlowableUtils {
return task.getName();
}
// TODO @kyleUtils 里不做查询可以封装到 bpmTaskService
public static Map<String/* taskId */, String/* taskName */> getTaskNameByTaskIds(Collection<String> taskIds) {
TaskService taskService = SpringUtil.getBean(TaskService.class);
List<Task> tasks = taskService.createTaskQuery().taskIds(taskIds).list();
@ -109,6 +110,7 @@ public class FlowableUtils {
return processInstance.getName();
}
// TODO @kyleUtils 里不做查询可以封装到 bpmTaskService
public static Map<String/* processInstaneId */, String/* processInstaneName */> getProcessInstanceNameByTaskIds(Set<String> taskIds) {
RuntimeService runtimeService = SpringUtil.getBean(RuntimeService.class);
List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().processInstanceIds(taskIds).list();

View File

@ -2,11 +2,11 @@ package cn.iocoder.yudao.module.system.controller.admin.ip;
import cn.hutool.core.lang.Assert;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.ip.core.Area;
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
import cn.iocoder.yudao.framework.ip.core.utils.IPUtils;
import cn.iocoder.yudao.module.system.controller.admin.ip.vo.AreaNodeRespVO;
import cn.iocoder.yudao.module.system.convert.ip.AreaConvert;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -31,7 +31,7 @@ public class AreaController {
public CommonResult<List<AreaNodeRespVO>> getAreaTree() {
Area area = AreaUtils.getArea(Area.ID_CHINA);
Assert.notNull(area, "获取不到中国");
return success(AreaConvert.INSTANCE.convertList(area.getChildren()));
return success(BeanUtils.toBean(area.getChildren(), AreaNodeRespVO.class));
}
@GetMapping("/get-by-ip")

View File

@ -31,7 +31,4 @@ public class SocialUserBindReqVO {
@NotEmpty(message = "state 不能为空")
private String state;
public Integer getType() {
return type;
}
}

View File

@ -2,10 +2,10 @@ package cn.iocoder.yudao.module.system.controller.app.ip;
import cn.hutool.core.lang.Assert;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.ip.core.Area;
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
import cn.iocoder.yudao.module.system.controller.app.ip.vo.AppAreaNodeRespVO;
import cn.iocoder.yudao.module.system.convert.ip.AreaConvert;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
@ -28,7 +28,7 @@ public class AppAreaController {
public CommonResult<List<AppAreaNodeRespVO>> getAreaTree() {
Area area = AreaUtils.getArea(Area.ID_CHINA);
Assert.notNull(area, "获取不到中国");
return success(AreaConvert.INSTANCE.convertList3(area.getChildren()));
return success(BeanUtils.toBean(area.getChildren(), AppAreaNodeRespVO.class));
}
}

View File

@ -1,28 +0,0 @@
package cn.iocoder.yudao.module.system.convert.ip;
import cn.iocoder.yudao.framework.ip.core.Area;
import cn.iocoder.yudao.module.system.controller.admin.ip.vo.AreaNodeRespVO;
import cn.iocoder.yudao.module.system.controller.app.ip.vo.AppAreaNodeRespVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface AreaConvert {
AreaConvert INSTANCE = Mappers.getMapper(AreaConvert.class);
List<AreaNodeRespVO> convertList(List<Area> list);
List<AppAreaNodeRespVO> convertList3(List<Area> list);
/**
* 缺少单个转换
* @param value
* @return
*/
AreaNodeRespVO map(Area value);
AppAreaNodeRespVO map3(Area value);
}