Commit ca1d9e6896ef18ea6351df5707b017997031d4b1
1 parent
c55f77f0
【代码评审】Bpm:更多设置-自动去重(审批)
Showing
4 changed files
with
21 additions
and
19 deletions
yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/definition/BpmAutoApproveType.java
| ... | ... | @@ -15,6 +15,7 @@ import java.util.Arrays; |
| 15 | 15 | @AllArgsConstructor |
| 16 | 16 | public enum BpmAutoApproveType implements IntArrayValuable { |
| 17 | 17 | |
| 18 | + // TODO @lesan:0、1、/2 会不会好理解一点哈。 | |
| 18 | 19 | NONE(1, "不自动通过"), |
| 19 | 20 | APPROVE_ALL(2, "仅审批一次,后续重复的审批节点均自动通过"), |
| 20 | 21 | APPROVE_SEQUENT(3, "仅针对连续审批的节点自动通过"); | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/dataobject/definition/BpmProcessDefinitionInfoDO.java
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/redis/RedisKeyConstants.java
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
| ... | ... | @@ -1172,51 +1172,50 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 1172 | 1172 | log.error("[processTaskAssigned][taskId({}) 没有找到流程实例]", task.getId()); |
| 1173 | 1173 | return; |
| 1174 | 1174 | } |
| 1175 | - // 自动去重 TODO @芋艿 驳回的情况得考虑一下 | |
| 1175 | + | |
| 1176 | + // 自动去重,通过自动审批的方式 TODO @芋艿 驳回的情况得考虑一下;@lesan:驳回后,又自动审批么? | |
| 1176 | 1177 | BpmProcessDefinitionInfoDO processDefinitionInfo = bpmProcessDefinitionService.getProcessDefinitionInfo(task.getProcessDefinitionId()); |
| 1177 | 1178 | if (processDefinitionInfo == null) { |
| 1178 | - log.error("[processTaskAssigned][taskId({}) 没有找到流程定义]", task.getId()); | |
| 1179 | + log.error("[processTaskAssigned][taskId({}) 没有找到流程定义({})]", task.getId(), task.getProcessDefinitionId()); | |
| 1179 | 1180 | return; |
| 1180 | 1181 | } |
| 1181 | 1182 | if (processDefinitionInfo.getAutoApprovalType() != null) { |
| 1182 | - HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery() | |
| 1183 | + HistoricTaskInstanceQuery sameAssigneeQuery = historyService.createHistoricTaskInstanceQuery() | |
| 1183 | 1184 | .processInstanceId(task.getProcessInstanceId()) |
| 1184 | - .taskAssignee(task.getAssignee()) | |
| 1185 | - .taskVariableValueEquals(BpmnVariableConstants.TASK_VARIABLE_STATUS, | |
| 1186 | - BpmTaskStatusEnum.APPROVE.getStatus()) | |
| 1185 | + .taskAssignee(task.getAssignee()) // 相同审批人 | |
| 1186 | + .taskVariableValueEquals(BpmnVariableConstants.TASK_VARIABLE_STATUS, BpmTaskStatusEnum.APPROVE.getStatus()) | |
| 1187 | 1187 | .finished(); |
| 1188 | - if (BpmAutoApproveType.APPROVE_ALL.getType().equals(processDefinitionInfo.getAutoApprovalType())){ | |
| 1189 | - long count = query.count(); | |
| 1190 | - if (count > 0) { | |
| 1191 | - // 自动通过 | |
| 1192 | - getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId()) | |
| 1193 | - .setReason(BpmAutoApproveType.APPROVE_ALL.getName())); | |
| 1194 | - return; | |
| 1195 | - } | |
| 1188 | + if (BpmAutoApproveType.APPROVE_ALL.getType().equals(processDefinitionInfo.getAutoApprovalType()) | |
| 1189 | + && sameAssigneeQuery.count() > 0) { | |
| 1190 | + getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId()) | |
| 1191 | + .setReason(BpmAutoApproveType.APPROVE_ALL.getName())); | |
| 1192 | + return; | |
| 1196 | 1193 | } |
| 1197 | 1194 | if (BpmAutoApproveType.APPROVE_SEQUENT.getType().equals(processDefinitionInfo.getAutoApprovalType())) { |
| 1198 | 1195 | BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(processInstance.getProcessDefinitionId()); |
| 1199 | 1196 | if (bpmnModel == null) { |
| 1200 | - log.error("[processTaskAssigned][taskId({}) 没有找到流程模型]", task.getId()); | |
| 1197 | + log.error("[processTaskAssigned][taskId({}) 没有找到流程模型({})]", task.getId(), task.getProcessDefinitionId()); | |
| 1201 | 1198 | return; |
| 1202 | 1199 | } |
| 1200 | + // TODO @lesan:这里的逻辑,要不在 BpmnModelUtils 抽个方法???尽量收敛 | |
| 1203 | 1201 | FlowNode taskElement = (FlowNode) BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey()); |
| 1204 | 1202 | List<SequenceFlow> incomingFlows = taskElement.getIncomingFlows(); |
| 1205 | 1203 | List<String> sourceTaskIds = new ArrayList<>(); |
| 1204 | + // TODO @lesan:这种 CollUtil.isnotempty 简化 | |
| 1206 | 1205 | if (incomingFlows != null && !incomingFlows.isEmpty()) { |
| 1206 | + // TODO @lesan:这种,idea 一般会告警,可以处理掉哈。一切警告,皆是错误 | |
| 1207 | 1207 | incomingFlows.forEach(flow -> { |
| 1208 | 1208 | sourceTaskIds.add(flow.getSourceRef()); |
| 1209 | 1209 | }); |
| 1210 | 1210 | } |
| 1211 | - long count = query.taskDefinitionKeys(sourceTaskIds).count(); | |
| 1212 | - if (count > 0) { | |
| 1213 | - // 自动通过 | |
| 1211 | + if (sameAssigneeQuery.taskDefinitionKeys(sourceTaskIds).count() > 0) { | |
| 1214 | 1212 | getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId()) |
| 1215 | 1213 | .setReason(BpmAutoApproveType.APPROVE_SEQUENT.getName())); |
| 1216 | 1214 | return; |
| 1217 | 1215 | } |
| 1218 | 1216 | } |
| 1219 | 1217 | } |
| 1218 | + | |
| 1220 | 1219 | // 审批人与提交人为同一人时,根据 BpmUserTaskAssignStartUserHandlerTypeEnum 策略进行处理 |
| 1221 | 1220 | if (StrUtil.equals(task.getAssignee(), processInstance.getStartUserId())) { |
| 1222 | 1221 | // 判断是否为退回或者驳回:如果是退回或者驳回不走这个策略 | ... | ... |