Commit 24f1ce16c714dbebc8bd9958f7d05889bfd0226a

Authored by YunaiV
1 parent b496ec3f

【代码评审】BPM:优化流程发起预测节点审批人是否配置在后端逻辑中实现

yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/BpmProcessInstanceController.java
@@ -6,7 +6,6 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; @@ -6,7 +6,6 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
6 import cn.iocoder.yudao.framework.common.pojo.PageResult; 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
7 import cn.iocoder.yudao.framework.common.util.json.JsonUtils; 7 import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
8 import cn.iocoder.yudao.framework.common.util.number.NumberUtils; 8 import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
9 -import cn.iocoder.yudao.framework.common.util.string.StrUtils;  
10 import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.*; 9 import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.*;
11 import cn.iocoder.yudao.module.bpm.convert.task.BpmProcessInstanceConvert; 10 import cn.iocoder.yudao.module.bpm.convert.task.BpmProcessInstanceConvert;
12 import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO; 11 import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
@@ -165,9 +164,10 @@ public class BpmProcessInstanceController { @@ -165,9 +164,10 @@ public class BpmProcessInstanceController {
165 @Operation(summary = "获得审批详情") 164 @Operation(summary = "获得审批详情")
166 @Parameter(name = "id", description = "流程实例的编号", required = true) 165 @Parameter(name = "id", description = "流程实例的编号", required = true)
167 @PreAuthorize("@ss.hasPermission('bpm:process-instance:query')") 166 @PreAuthorize("@ss.hasPermission('bpm:process-instance:query')")
  167 + @SuppressWarnings("unchecked")
168 public CommonResult<BpmApprovalDetailRespVO> getApprovalDetail(@Valid BpmApprovalDetailReqVO reqVO) { 168 public CommonResult<BpmApprovalDetailRespVO> getApprovalDetail(@Valid BpmApprovalDetailReqVO reqVO) {
169 - if (StrUtil.isNotEmpty(reqVO.getProcessVariablesStr())){  
170 - reqVO.setProcessVariables(JsonUtils.parseObject(reqVO.getProcessVariablesStr(),Map.class)); 169 + if (StrUtil.isNotEmpty(reqVO.getProcessVariablesStr())) {
  170 + reqVO.setProcessVariables(JsonUtils.parseObject(reqVO.getProcessVariablesStr(), Map.class));
171 } 171 }
172 return success(processInstanceService.getApprovalDetail(getLoginUserId(), reqVO)); 172 return success(processInstanceService.getApprovalDetail(getLoginUserId(), reqVO));
173 } 173 }
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java
@@ -799,8 +799,8 @@ public class BpmnModelUtils { @@ -799,8 +799,8 @@ public class BpmnModelUtils {
799 // 查找满足条件的 SequenceFlow 路径 799 // 查找满足条件的 SequenceFlow 路径
800 Gateway gateway = (Gateway) currentElement; 800 Gateway gateway = (Gateway) currentElement;
801 SequenceFlow matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(), 801 SequenceFlow matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(),
802 - flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId())  
803 - && (evalConditionExpress(variables, flow.getConditionExpression()))); 802 + flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId())
  803 + && (evalConditionExpress(variables, flow.getConditionExpression())));
804 if (matchSequenceFlow == null) { 804 if (matchSequenceFlow == null) {
805 matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(), 805 matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(),
806 flow -> ObjUtil.equal(gateway.getDefaultFlow(), flow.getId())); 806 flow -> ObjUtil.equal(gateway.getDefaultFlow(), flow.getId()));
@@ -857,9 +857,12 @@ public class BpmnModelUtils { @@ -857,9 +857,12 @@ public class BpmnModelUtils {
857 if (express == null) { 857 if (express == null) {
858 return Boolean.FALSE; 858 return Boolean.FALSE;
859 } 859 }
  860 + // 如果 variables 为空,则创建一个的原因?可能 expression 的计算,不依赖于 variables
860 if (variables == null) { 861 if (variables == null) {
861 - return Boolean.FALSE; 862 + variables = new HashMap<>();
862 } 863 }
  864 +
  865 + // 执行计算
863 try { 866 try {
864 Object result = FlowableUtils.getExpressionValue(variables, express); 867 Object result = FlowableUtils.getExpressionValue(variables, express);
865 return Boolean.TRUE.equals(result); 868 return Boolean.TRUE.equals(result);
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
@@ -696,8 +696,9 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService @@ -696,8 +696,9 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
696 } 696 }
697 697
698 private void validateStartUserSelectAssignees(Long userId, ProcessDefinition definition, 698 private void validateStartUserSelectAssignees(Long userId, ProcessDefinition definition,
699 - Map<String, List<Long>> startUserSelectAssignees, Map<String,Object> variables) {  
700 - // 1.获取预测的节点信息 699 + Map<String, List<Long>> startUserSelectAssignees,
  700 + Map<String,Object> variables) {
  701 + // 1. 获取预测的节点信息
701 BpmApprovalDetailRespVO detailRespVO = getApprovalDetail(userId, new BpmApprovalDetailReqVO() 702 BpmApprovalDetailRespVO detailRespVO = getApprovalDetail(userId, new BpmApprovalDetailReqVO()
702 .setProcessDefinitionId(definition.getId()) 703 .setProcessDefinitionId(definition.getId())
703 .setProcessVariables(variables)); 704 .setProcessVariables(variables));
@@ -705,9 +706,11 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService @@ -705,9 +706,11 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
705 if (CollUtil.isEmpty(activityNodes)){ 706 if (CollUtil.isEmpty(activityNodes)){
706 return; 707 return;
707 } 708 }
708 - // 2.移除掉不是发起人自选审批人节点  
709 - activityNodes.removeIf(task -> !Objects.equals(BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy(), task.getCandidateStrategy()));  
710 - // 3.流程发起时要先获取当前流程的预测走向节点,发起时只校验预测的节点发起人自选审批人的审批人和抄送人是否都配置了 709 +
  710 + // 2.1 移除掉不是发起人自选审批人节点
  711 + activityNodes.removeIf(task ->
  712 + ObjectUtil.notEqual(BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy(), task.getCandidateStrategy()));
  713 + // 2.2 流程发起时要先获取当前流程的预测走向节点,发起时只校验预测的节点发起人自选审批人的审批人和抄送人是否都配置了
711 activityNodes.forEach(task -> { 714 activityNodes.forEach(task -> {
712 List<Long> assignees = startUserSelectAssignees != null ? startUserSelectAssignees.get(task.getId()) : null; 715 List<Long> assignees = startUserSelectAssignees != null ? startUserSelectAssignees.get(task.getId()) : null;
713 if (CollUtil.isEmpty(assignees)) { 716 if (CollUtil.isEmpty(assignees)) {