jbpm5.4会签思路和实现

阅读更多

关于jbpm5的人工任务实现这里提供一个思路

 

流程图如下:


jbpm5.4会签思路和实现_第1张图片
 

有一个流程变量会记录会签人员列表,在分支节点会判断会签人员列表是否为空,为空就会签结束,不然就走到会签节点为剩余的会签人员创建任务
而每个会签人员处理完任务后,就会从流程变量中的会签人员列表中将该人员移除,这个是思路。

在流程中创建流程变量的方式


jbpm5.4会签思路和实现_第2张图片
 

这个变量会在发起流程的时候初始化,或在任务处理的时候更新
而在分支节点的判断逻辑是


jbpm5.4会签思路和实现_第3张图片
 

 

最后是测试代码
private void test_05_多任务审批(StatefulKnowledgeSession session) {
		org.jbpm.task.service.TaskService internalTaskService = knowledgeSessionTemplate.getInternalTaskService();
		TaskServiceSession taskServiceSession = internalTaskService.createSession();
		taskServiceSession.addUser(new User("Administrator"));
		taskServiceSession.addUser(new User("zhangsan"));
		taskServiceSession.addUser(new User("lisi"));
		taskServiceSession.addUser(new User("wangwu"));
		taskServiceSession.dispose();
		
		Map variableMap = new HashMap();
		variableMap.put("actors", "zhangsan,lisi,wangwu");
		ProcessInstance pi = session.startProcess("defaultPackage.New_Process", variableMap);
		WorkflowProcessInstance wfpi = (WorkflowProcessInstance)pi;
		String actors = (String)wfpi.getVariable("actors");
		
		TaskService taskService = knowledgeSessionTemplate.getTaskService();
		printTasks(taskService);
		
		long taskid = taskService.getTasksAssignedAsPotentialOwner("zhangsan", "en-UK").get(0).getId();
		actors = handleTask(session, taskService, actors, "zhangsan", taskid, pi.getId());
		printTasks(taskService);
		
		taskid = taskService.getTasksAssignedAsPotentialOwner("wangwu", "en-UK").get(0).getId();
		actors = handleTask(session, taskService, actors, "wangwu", taskid, pi.getId());
		printTasks(taskService);
		
		taskid = taskService.getTasksAssignedAsPotentialOwner("lisi", "en-UK").get(0).getId();
		actors = handleTask(session, taskService, actors, "lisi", taskid, pi.getId());
		printTasks(taskService);
	}
	
	private void printTasks(TaskService taskService) {
		List tasks1 = taskService.getTasksAssignedAsPotentialOwner("zhangsan", "en-UK");
		List tasks2 = taskService.getTasksAssignedAsPotentialOwner("lisi", "en-UK");
		List tasks3 = taskService.getTasksAssignedAsPotentialOwner("wangwu", "en-UK");
		System.err.println("张三 :" + tasks1);
		System.err.println("李四 :" + tasks2);
		System.err.println("王五 :" + tasks3);
	}
	
	private String handleTask(StatefulKnowledgeSession session, TaskService taskService, String actors, 
			String actor, long taskid, long piid) {
		String newActors = resetActors(actors, actor);
		((WorkflowProcessInstance)session.getProcessInstance(piid)).setVariable("actors", newActors);
//		taskService.claim(taskid, actor);
		taskService.start(taskid, actor);
		taskService.complete(taskid, actor, null);
		
		ProcessInstance pi = session.getProcessInstance(piid);
		if(pi != null) {
			return ((WorkflowProcessInstance)pi).getVariable("actors").toString();
		}
		return "";
	}
	
	private String resetActors(String actors, String actor) {
		String[] actorArr = actors.split(",");
		StringBuffer sb = new StringBuffer();
		for (String a : actorArr) {
			if (!a.equals(actor)) {
				sb.append(a).append(",");
			}
		}
		int i = sb.lastIndexOf(",");
		if(i!=-1){
			sb.deleteCharAt(i);
		}
		return sb.toString();
	}

 

 

测试结果



jbpm5.4会签思路和实现_第4张图片
 
 

 

 

  • jbpm5.4会签思路和实现_第5张图片
  • 大小: 28.8 KB
  • jbpm5.4会签思路和实现_第6张图片
  • 大小: 62.4 KB
  • jbpm5.4会签思路和实现_第7张图片
  • 大小: 64.8 KB
  • jbpm5.4会签思路和实现_第8张图片
  • 大小: 237.8 KB
  • 查看图片附件

你可能感兴趣的:(jbpm5,workflow,工作流,jbpm,bpmn)