jbpm5.4会签思路和实现
程序员文章站
2022-07-12 10:50:17
...
关于jbpm5的人工任务实现这里提供一个思路
流程图如下:
有一个流程变量会记录会签人员列表,在分支节点会判断会签人员列表是否为空,为空就会签结束,不然就走到会签节点为剩余的会签人员创建任务
而每个会签人员处理完任务后,就会从流程变量中的会签人员列表中将该人员移除,这个是思路。
而每个会签人员处理完任务后,就会从流程变量中的会签人员列表中将该人员移除,这个是思路。
在流程中创建流程变量的方式
这个变量会在发起流程的时候初始化,或在任务处理的时候更新
而在分支节点的判断逻辑是
<!--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(); }
测试结果
上一篇: JBPM4