作者:mobiledu2502897083 | 来源:互联网 | 2024-09-28 13:14
在实际的工作流业务开发中,当用户完成当前用户任务时,需要指定下一个用户任务的审核人。此时我们需要获取下一个节点的一些信息,来确定下一个用户任务的审核人有哪些。在实际工
在实际的工作流业务开发中, 当用户完成当前用户任务时, 需要指定下一个用户任务的审核人。此时我们需要获取下一个节点的一些信息, 来确定下一个用户任务的审核人有哪些。
在实际工作流程中, 当前用户任务后的节点可能为用户任务, 也可能为网关。如果下一个节点为网关我们需要判断流程线路。
Java代码
-
-
-
-
-
-
- public Set getNextTaskGroup(String taskId) throws Exception {
-
- ProcessDefinitionEntity processDefinitionEntity = null;
-
- String id = null;
-
- TaskDefinition task = null;
-
-
- String processInstanceId = taskService.createTaskQuery().taskId(taskId).singleResult().getProcessInstanceId();
-
-
- String definitionId = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult().getProcessDefinitionId();
-
- processDefinitionEntity = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
- .getDeployedProcessDefinition(definitionId);
-
- ExecutionEntity execution = (ExecutionEntity) runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
-
-
- String activitiId = execution.getActivityId();
-
-
- List activitiList = processDefinitionEntity.getActivities();
-
-
- for(ActivityImpl activityImpl : activitiList){
- id = activityImpl.getId();
-
-
- if (activitiId.equals(id)) {
-
-
- task = nextTaskDefinition(activityImpl, activityImpl.getId(), null, processInstanceId);
-
- break;
- }
- }
-
- return task.getCandidateGroupIdExpressions();
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- private TaskDefinition nextTaskDefinition(ActivityImpl activityImpl, String activityId, String elString, String processInstanceId){
-
- PvmActivity ac = null;
-
- Object s = null;
-
-
- if("userTask".equals(activityImpl.getProperty("type")) && !activityId.equals(activityImpl.getId())){
-
- TaskDefinition taskDefinition = ((UserTaskActivityBehavior)activityImpl.getActivityBehavior()).getTaskDefinition();
- return taskDefinition;
- }else{
-
- List outTransitions = activityImpl.getOutgoingTransitions();
- List outTransitionsTemp = null;
- for(PvmTransition tr : outTransitions){
- ac = tr.getDestination();
-
- if("exclusiveGateway".equals(ac.getProperty("type"))){
- outTransitionsTemp = ac.getOutgoingTransitions();
-
-
- if(StrUtils.isEmpty(elString)) {
-
- elString = getGatewayCondition(ac.getId(), processInstanceId);
- }
-
-
- if(outTransitionsTemp.size() == 1){
- return nextTaskDefinition((ActivityImpl)outTransitionsTemp.get(0).getDestination(), activityId, elString, processInstanceId);
- }else if(outTransitionsTemp.size() > 1){
- for(PvmTransition tr1 : outTransitionsTemp){
- s = tr1.getProperty("conditionText");
-
- if(isCondition(ac.getId(), StrUtils.trim(s.toString()), elString)){
- return nextTaskDefinition((ActivityImpl)tr1.getDestination(), activityId, elString, processInstanceId);
- }
- }
- }
- }else if("userTask".equals(ac.getProperty("type"))){
- return ((UserTaskActivityBehavior)((ActivityImpl)ac).getActivityBehavior()).getTaskDefinition();
- }else{
- }
- }
- return null;
- }
- }
-
-
-
-
-
-
-
- public String getGatewayCondition(String gatewayId, String processInstanceId) {
- Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstanceId).singleResult();
- return runtimeService.getVariable(execution.getId(), gatewayId).toString();
- }
-
-
-
-
-
-
-
-
- public boolean isCondition(String key, String el, String value) {
- ExpressionFactory factory = new ExpressionFactoryImpl();
- SimpleContext context = new SimpleContext();
- context.setVariable(key, factory.createValueExpression(value, String.class));
- ValueExpression e = factory.createValueExpression(context, el, boolean.class);
- return (Boolean) e.getValue(context);
- }