jbpm5.4会签思路和实现

标签: jbpm5 | 发表时间:2015-01-08 22:07 | 作者:felix_alone2012
出处:http://www.iteye.com

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

 

流程图如下:



 

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

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



 

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



 

 

<!--StartFragment -->
最后是测试代码
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<String, Object> variableMap = new HashMap<String, Object>();
		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<TaskSummary> tasks1 = taskService.getTasksAssignedAsPotentialOwner("zhangsan", "en-UK");
		List<TaskSummary> tasks2 = taskService.getTasksAssignedAsPotentialOwner("lisi", "en-UK");
		List<TaskSummary> 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();
	}

 

 

测试结果




 
 

 

 



已有 0 人发表留言,猛击->> 这里<<-参与讨论


ITeye推荐



相关 [jbpm5] 推荐:

轻松对比Activiti5与jBPM5技术组成

- - 企业架构 - ITeye博客
jBPM是目前市场上主流开源工作引擎之一,在创建者Tom Baeyens离开JBoss后,jBPM的下一个版本jBPM5完全放弃了jBPM4的基础代码,基于Drools Flow重头来过,目前官网已经推出了jBPM6的beta版本;Tom Baeyens加入Alfresco后很快推出了新的基于jBPM4的开源工作流系统Activiti.