【代码评审】Bpm:更多设置-自动去重(审批)

This commit is contained in:
YunaiV 2025-01-21 09:37:38 +08:00
parent c55f77f001
commit ca1d9e6896
4 changed files with 21 additions and 19 deletions

View File

@ -15,6 +15,7 @@ import java.util.Arrays;
@AllArgsConstructor
public enum BpmAutoApproveType implements IntArrayValuable {
// TODO @lesan01/2 会不会好理解一点哈
NONE(1, "不自动通过"),
APPROVE_ALL(2, "仅审批一次,后续重复的审批节点均自动通过"),
APPROVE_SEQUENT(3, "仅针对连续审批的节点自动通过");

View File

@ -164,6 +164,8 @@ public class BpmProcessDefinitionInfoDO extends BaseDO {
/**
* 自动去重类型
*
* 枚举 {@link cn.iocoder.yudao.module.bpm.enums.definition.BpmAutoApproveType}
*/
private Integer autoApprovalType;

View File

@ -10,6 +10,6 @@ public interface RedisKeyConstants {
/**
* 流程 ID 的缓存
*/
String BPM_PROCESS_ID = "bpm:process_id:seq_no:";
String BPM_PROCESS_ID = "bpm:process_id:";
}

View File

@ -1172,51 +1172,50 @@ public class BpmTaskServiceImpl implements BpmTaskService {
log.error("[processTaskAssigned][taskId({}) 没有找到流程实例]", task.getId());
return;
}
// 自动去重 TODO @芋艿 驳回的情况得考虑一下
// 自动去重通过自动审批的方式 TODO @芋艿 驳回的情况得考虑一下@lesan驳回后又自动审批么
BpmProcessDefinitionInfoDO processDefinitionInfo = bpmProcessDefinitionService.getProcessDefinitionInfo(task.getProcessDefinitionId());
if (processDefinitionInfo == null) {
log.error("[processTaskAssigned][taskId({}) 没有找到流程定义]", task.getId());
log.error("[processTaskAssigned][taskId({}) 没有找到流程定义({})]", task.getId(), task.getProcessDefinitionId());
return;
}
if (processDefinitionInfo.getAutoApprovalType() != null) {
HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery()
HistoricTaskInstanceQuery sameAssigneeQuery = historyService.createHistoricTaskInstanceQuery()
.processInstanceId(task.getProcessInstanceId())
.taskAssignee(task.getAssignee())
.taskVariableValueEquals(BpmnVariableConstants.TASK_VARIABLE_STATUS,
BpmTaskStatusEnum.APPROVE.getStatus())
.taskAssignee(task.getAssignee()) // 相同审批人
.taskVariableValueEquals(BpmnVariableConstants.TASK_VARIABLE_STATUS, BpmTaskStatusEnum.APPROVE.getStatus())
.finished();
if (BpmAutoApproveType.APPROVE_ALL.getType().equals(processDefinitionInfo.getAutoApprovalType())){
long count = query.count();
if (count > 0) {
// 自动通过
getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId())
.setReason(BpmAutoApproveType.APPROVE_ALL.getName()));
return;
}
if (BpmAutoApproveType.APPROVE_ALL.getType().equals(processDefinitionInfo.getAutoApprovalType())
&& sameAssigneeQuery.count() > 0) {
getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId())
.setReason(BpmAutoApproveType.APPROVE_ALL.getName()));
return;
}
if (BpmAutoApproveType.APPROVE_SEQUENT.getType().equals(processDefinitionInfo.getAutoApprovalType())) {
BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(processInstance.getProcessDefinitionId());
if (bpmnModel == null) {
log.error("[processTaskAssigned][taskId({}) 没有找到流程模型]", task.getId());
log.error("[processTaskAssigned][taskId({}) 没有找到流程模型({})]", task.getId(), task.getProcessDefinitionId());
return;
}
// TODO @lesan这里的逻辑要不在 BpmnModelUtils 抽个方法尽量收敛
FlowNode taskElement = (FlowNode) BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey());
List<SequenceFlow> incomingFlows = taskElement.getIncomingFlows();
List<String> sourceTaskIds = new ArrayList<>();
// TODO @lesan这种 CollUtil.isnotempty 简化
if (incomingFlows != null && !incomingFlows.isEmpty()) {
// TODO @lesan这种idea 一般会告警可以处理掉哈一切警告皆是错误
incomingFlows.forEach(flow -> {
sourceTaskIds.add(flow.getSourceRef());
});
}
long count = query.taskDefinitionKeys(sourceTaskIds).count();
if (count > 0) {
// 自动通过
if (sameAssigneeQuery.taskDefinitionKeys(sourceTaskIds).count() > 0) {
getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId())
.setReason(BpmAutoApproveType.APPROVE_SEQUENT.getName()));
return;
}
}
}
// 审批人与提交人为同一人时根据 BpmUserTaskAssignStartUserHandlerTypeEnum 策略进行处理
if (StrUtil.equals(task.getAssignee(), processInstance.getStartUserId())) {
// 判断是否为退回或者驳回如果是退回或者驳回不走这个策略