update - 计算人,需要两种逻辑,一种是跑异常,另一种是不抛异常
This commit is contained in:
parent
25a46cc956
commit
25261e9c9f
@ -1,11 +1,12 @@
|
||||
package cn.axzo.workflow.core.deletage;
|
||||
|
||||
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.flowable.bpmn.model.UserTask;
|
||||
import org.flowable.engine.delegate.DelegateExecution;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 任务节点的审批人查询器接口
|
||||
*
|
||||
@ -22,7 +23,7 @@ public interface BpmnTaskAssigneeSelector {
|
||||
/**
|
||||
* 查询具体审批人
|
||||
*/
|
||||
List<BpmnTaskDelegateAssigner> select(UserTask userTask, DelegateExecution execution);
|
||||
List<BpmnTaskDelegateAssigner> select(UserTask userTask, DelegateExecution execution, Boolean throwException);
|
||||
|
||||
/**
|
||||
* 审批人筛选项获取类型
|
||||
|
||||
@ -40,7 +40,8 @@ public class MockTaskAssigneeSelector implements BpmnTaskAssigneeSelector {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BpmnTaskDelegateAssigner> select(UserTask userTask, DelegateExecution execution) {
|
||||
public List<BpmnTaskDelegateAssigner> select(UserTask userTask, DelegateExecution execution,
|
||||
Boolean throwException) {
|
||||
List<BpmnTaskDelegateAssigner> users = new ArrayList<>();
|
||||
|
||||
// 优先读取 Nacos 配置
|
||||
|
||||
@ -43,7 +43,7 @@ public class CustomForecastUserTaskAssigneeCmd implements Command<List<BpmnTaskD
|
||||
List<BpmnTaskDelegateAssigner> forecastAssigners = new ArrayList<>();
|
||||
getApproverSpecify(userTask).ifPresent(specify -> {
|
||||
forecastAssigners.addAll(engineExecutionStartListener.approverSelect(specify.getType(), userTask,
|
||||
(DelegateExecution) list.get(0)));
|
||||
(DelegateExecution) list.get(0), false));
|
||||
});
|
||||
return forecastAssigners;
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ public class EngineExecutionStartListener implements ExecutionListener {
|
||||
// 这里只会是 human 这一种情况, 因为 nobody 在转 BPMN 协议时,Activity 直接变成了 ReceiveTask 节点了。
|
||||
List<BpmnTaskDelegateAssigner> assigners = new ArrayList<>();
|
||||
getApproverSpecify(userTask).ifPresent(specify -> {
|
||||
assigners.addAll(approverSelect(specify.getType(), userTask, execution));
|
||||
assigners.addAll(approverSelect(specify.getType(), userTask, execution, true));
|
||||
});
|
||||
|
||||
// 审批候选人为空时的兜底
|
||||
@ -139,7 +139,7 @@ public class EngineExecutionStartListener implements ExecutionListener {
|
||||
break;
|
||||
case transferToAdmin:
|
||||
assigners.addAll(approverSelect(ApproverEmptyHandleTypeEnum.transferToAdmin.getType(), userTask,
|
||||
execution));
|
||||
execution, true));
|
||||
break;
|
||||
case specifyAssignee:
|
||||
List<BpmnTaskDelegateAssigner> emptyAssignees =
|
||||
@ -160,7 +160,8 @@ public class EngineExecutionStartListener implements ExecutionListener {
|
||||
* @param userTask 当前节点, 这个对象会包含配置元数据, 可以在该方法中或者基于 BpmnTaskAssigneeSelector 建一个抽象类, 做解析元数据公共方法
|
||||
* @return
|
||||
*/
|
||||
public List<BpmnTaskDelegateAssigner> approverSelect(String type, UserTask userTask, DelegateExecution execution) {
|
||||
public List<BpmnTaskDelegateAssigner> approverSelect(String type, UserTask userTask, DelegateExecution execution,
|
||||
Boolean throwException) {
|
||||
List<BpmnTaskDelegateAssigner> assigners = new ArrayList<>();
|
||||
|
||||
// 如果开启了 mock 模式(workflow.mock=true), 则根据 mock 配置去选择审批人
|
||||
@ -182,11 +183,12 @@ public class EngineExecutionStartListener implements ExecutionListener {
|
||||
*/
|
||||
if ((mock && global) ||
|
||||
(mock && !global && Objects.equals(category, execution.getProcessDefinitionId().split(":")[0]))) {
|
||||
assigners.addAll(new MockTaskAssigneeSelector(assigneeMap, global, category).select(userTask, execution));
|
||||
assigners.addAll(new MockTaskAssigneeSelector(assigneeMap, global, category).select(userTask, execution,
|
||||
throwException));
|
||||
} else {
|
||||
selectors.forEach(select -> {
|
||||
if (select.support(type)) {
|
||||
assigners.addAll(select.select(userTask, execution));
|
||||
assigners.addAll(select.select(userTask, execution, throwException));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -27,10 +27,10 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!--<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
</dependency>-->
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>workflow-engine-core</artifactId>
|
||||
|
||||
@ -37,7 +37,8 @@ public abstract class AbstractBpmnTaskAssigneeSelector implements BpmnTaskAssign
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public List<BpmnTaskDelegateAssigner> select(UserTask userTask, DelegateExecution execution) {
|
||||
public List<BpmnTaskDelegateAssigner> select(UserTask userTask, DelegateExecution execution,
|
||||
Boolean throwException) {
|
||||
return (List<BpmnTaskDelegateAssigner>) BpmnMetaParserHelper.getApproverScope(userTask)
|
||||
.map(approverScopeEnum -> {
|
||||
if (Objects.isNull(approverScopeEnum.getProcessor())) {
|
||||
@ -49,9 +50,12 @@ public abstract class AbstractBpmnTaskAssigneeSelector implements BpmnTaskAssign
|
||||
ApproverScopeDTO scopeDto = processor.select(userTask, execution);
|
||||
try {
|
||||
return invokeService(userTask, execution, scopeDto);
|
||||
} catch (Exception e) {
|
||||
log.warn("Activity 结算审批人出现异常: , 入参: {}", e.getMessage(), JSON.toJSONString(scopeDto));
|
||||
return Collections.emptyList();
|
||||
} catch (Throwable t) {
|
||||
if (throwException) {
|
||||
throw t;
|
||||
} else {
|
||||
return this.invokeService(userTask, execution, scopeDto);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).orElseGet(Collections::emptyList);
|
||||
|
||||
@ -25,7 +25,8 @@ public class FixedPersonTaskAssigneeSelector extends AbstractBpmnTaskAssigneeSel
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BpmnTaskDelegateAssigner> select(UserTask userTask, DelegateExecution execution) {
|
||||
public List<BpmnTaskDelegateAssigner> select(UserTask userTask, DelegateExecution execution,
|
||||
Boolean throwException) {
|
||||
List<BpmnTaskDelegateAssigner> assigners = new ArrayList<>();
|
||||
BpmnMetaParserHelper.getApproverSpecifyValue(userTask)
|
||||
.ifPresent(s -> assigners.addAll(JSON.parseArray(s, BpmnTaskDelegateAssigner.class)));
|
||||
|
||||
@ -24,7 +24,8 @@ public class InitiatorLeaderRecursionTaskAssigneeSelector extends AbstractBpmnTa
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BpmnTaskDelegateAssigner> select(UserTask userTask, DelegateExecution execution) {
|
||||
public List<BpmnTaskDelegateAssigner> select(UserTask userTask, DelegateExecution execution,
|
||||
Boolean throwException) {
|
||||
throw new WorkflowEngineException("暂不支持");
|
||||
}
|
||||
|
||||
|
||||
@ -15,7 +15,6 @@ import org.flowable.engine.delegate.DelegateExecution;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
@ -65,7 +64,7 @@ public class InitiatorLeaderTaskAssigneeSelector extends AbstractBpmnTaskAssigne
|
||||
parseApiResult(() -> organizationalNodeUserApi.listFlowTaskAssigner(req), "通过发起人主管查询审批人", req);
|
||||
|
||||
if (CollUtil.isEmpty(flowTaskAssigners)) {
|
||||
return Collections.emptyList();
|
||||
return super.invokeService(userTask, execution, scopeDto);
|
||||
}
|
||||
return BeanUtil.copyToList(flowTaskAssigners, BpmnTaskDelegateAssigner.class);
|
||||
}
|
||||
|
||||
@ -33,7 +33,8 @@ public class PreNodeSpecifiedTaskAssigneeSelector extends AbstractBpmnTaskAssign
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BpmnTaskDelegateAssigner> select(UserTask userTask, DelegateExecution execution) {
|
||||
public List<BpmnTaskDelegateAssigner> select(UserTask userTask, DelegateExecution execution,
|
||||
Boolean throwException) {
|
||||
BpmnTaskDelegateAssigner assigner = runtimeService.getVariable(execution.getProcessInstanceId(),
|
||||
INTERNAL_SPECIFY_NEXT_APPROVER, BpmnTaskDelegateAssigner.class);
|
||||
return Lists.newArrayList(assigner);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user