【代码评审】Bpm:更多设置-自动去重(审批)
This commit is contained in:
parent
c55f77f001
commit
ca1d9e6896
|
@ -15,6 +15,7 @@ import java.util.Arrays;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum BpmAutoApproveType implements IntArrayValuable {
|
public enum BpmAutoApproveType implements IntArrayValuable {
|
||||||
|
|
||||||
|
// TODO @lesan:0、1、/2 会不会好理解一点哈。
|
||||||
NONE(1, "不自动通过"),
|
NONE(1, "不自动通过"),
|
||||||
APPROVE_ALL(2, "仅审批一次,后续重复的审批节点均自动通过"),
|
APPROVE_ALL(2, "仅审批一次,后续重复的审批节点均自动通过"),
|
||||||
APPROVE_SEQUENT(3, "仅针对连续审批的节点自动通过");
|
APPROVE_SEQUENT(3, "仅针对连续审批的节点自动通过");
|
||||||
|
|
|
@ -164,6 +164,8 @@ public class BpmProcessDefinitionInfoDO extends BaseDO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自动去重类型
|
* 自动去重类型
|
||||||
|
*
|
||||||
|
* 枚举 {@link cn.iocoder.yudao.module.bpm.enums.definition.BpmAutoApproveType}
|
||||||
*/
|
*/
|
||||||
private Integer autoApprovalType;
|
private Integer autoApprovalType;
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,6 @@ public interface RedisKeyConstants {
|
||||||
/**
|
/**
|
||||||
* 流程 ID 的缓存
|
* 流程 ID 的缓存
|
||||||
*/
|
*/
|
||||||
String BPM_PROCESS_ID = "bpm:process_id:seq_no:";
|
String BPM_PROCESS_ID = "bpm:process_id:";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1172,51 +1172,50 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||||
log.error("[processTaskAssigned][taskId({}) 没有找到流程实例]", task.getId());
|
log.error("[processTaskAssigned][taskId({}) 没有找到流程实例]", task.getId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 自动去重 TODO @芋艿 驳回的情况得考虑一下
|
|
||||||
|
// 自动去重,通过自动审批的方式 TODO @芋艿 驳回的情况得考虑一下;@lesan:驳回后,又自动审批么?
|
||||||
BpmProcessDefinitionInfoDO processDefinitionInfo = bpmProcessDefinitionService.getProcessDefinitionInfo(task.getProcessDefinitionId());
|
BpmProcessDefinitionInfoDO processDefinitionInfo = bpmProcessDefinitionService.getProcessDefinitionInfo(task.getProcessDefinitionId());
|
||||||
if (processDefinitionInfo == null) {
|
if (processDefinitionInfo == null) {
|
||||||
log.error("[processTaskAssigned][taskId({}) 没有找到流程定义]", task.getId());
|
log.error("[processTaskAssigned][taskId({}) 没有找到流程定义({})]", task.getId(), task.getProcessDefinitionId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (processDefinitionInfo.getAutoApprovalType() != null) {
|
if (processDefinitionInfo.getAutoApprovalType() != null) {
|
||||||
HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery()
|
HistoricTaskInstanceQuery sameAssigneeQuery = historyService.createHistoricTaskInstanceQuery()
|
||||||
.processInstanceId(task.getProcessInstanceId())
|
.processInstanceId(task.getProcessInstanceId())
|
||||||
.taskAssignee(task.getAssignee())
|
.taskAssignee(task.getAssignee()) // 相同审批人
|
||||||
.taskVariableValueEquals(BpmnVariableConstants.TASK_VARIABLE_STATUS,
|
.taskVariableValueEquals(BpmnVariableConstants.TASK_VARIABLE_STATUS, BpmTaskStatusEnum.APPROVE.getStatus())
|
||||||
BpmTaskStatusEnum.APPROVE.getStatus())
|
|
||||||
.finished();
|
.finished();
|
||||||
if (BpmAutoApproveType.APPROVE_ALL.getType().equals(processDefinitionInfo.getAutoApprovalType())){
|
if (BpmAutoApproveType.APPROVE_ALL.getType().equals(processDefinitionInfo.getAutoApprovalType())
|
||||||
long count = query.count();
|
&& sameAssigneeQuery.count() > 0) {
|
||||||
if (count > 0) {
|
|
||||||
// 自动通过
|
|
||||||
getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId())
|
getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId())
|
||||||
.setReason(BpmAutoApproveType.APPROVE_ALL.getName()));
|
.setReason(BpmAutoApproveType.APPROVE_ALL.getName()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (BpmAutoApproveType.APPROVE_SEQUENT.getType().equals(processDefinitionInfo.getAutoApprovalType())) {
|
if (BpmAutoApproveType.APPROVE_SEQUENT.getType().equals(processDefinitionInfo.getAutoApprovalType())) {
|
||||||
BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(processInstance.getProcessDefinitionId());
|
BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(processInstance.getProcessDefinitionId());
|
||||||
if (bpmnModel == null) {
|
if (bpmnModel == null) {
|
||||||
log.error("[processTaskAssigned][taskId({}) 没有找到流程模型]", task.getId());
|
log.error("[processTaskAssigned][taskId({}) 没有找到流程模型({})]", task.getId(), task.getProcessDefinitionId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// TODO @lesan:这里的逻辑,要不在 BpmnModelUtils 抽个方法???尽量收敛
|
||||||
FlowNode taskElement = (FlowNode) BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey());
|
FlowNode taskElement = (FlowNode) BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey());
|
||||||
List<SequenceFlow> incomingFlows = taskElement.getIncomingFlows();
|
List<SequenceFlow> incomingFlows = taskElement.getIncomingFlows();
|
||||||
List<String> sourceTaskIds = new ArrayList<>();
|
List<String> sourceTaskIds = new ArrayList<>();
|
||||||
|
// TODO @lesan:这种 CollUtil.isnotempty 简化
|
||||||
if (incomingFlows != null && !incomingFlows.isEmpty()) {
|
if (incomingFlows != null && !incomingFlows.isEmpty()) {
|
||||||
|
// TODO @lesan:这种,idea 一般会告警,可以处理掉哈。一切警告,皆是错误
|
||||||
incomingFlows.forEach(flow -> {
|
incomingFlows.forEach(flow -> {
|
||||||
sourceTaskIds.add(flow.getSourceRef());
|
sourceTaskIds.add(flow.getSourceRef());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
long count = query.taskDefinitionKeys(sourceTaskIds).count();
|
if (sameAssigneeQuery.taskDefinitionKeys(sourceTaskIds).count() > 0) {
|
||||||
if (count > 0) {
|
|
||||||
// 自动通过
|
|
||||||
getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId())
|
getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId())
|
||||||
.setReason(BpmAutoApproveType.APPROVE_SEQUENT.getName()));
|
.setReason(BpmAutoApproveType.APPROVE_SEQUENT.getName()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 审批人与提交人为同一人时,根据 BpmUserTaskAssignStartUserHandlerTypeEnum 策略进行处理
|
// 审批人与提交人为同一人时,根据 BpmUserTaskAssignStartUserHandlerTypeEnum 策略进行处理
|
||||||
if (StrUtil.equals(task.getAssignee(), processInstance.getStartUserId())) {
|
if (StrUtil.equals(task.getAssignee(), processInstance.getStartUserId())) {
|
||||||
// 判断是否为退回或者驳回:如果是退回或者驳回不走这个策略
|
// 判断是否为退回或者驳回:如果是退回或者驳回不走这个策略
|
||||||
|
|
Loading…
Reference in New Issue