<?xml version="1.0" encoding="UTF-8"?> <process key="task" name="task" xmlns="http://jbpm.org/4.4/jpdl"> <!-- EL表达式给assignee属性赋值 --> <task assignee="${user.userId}" g="406,144,92,52" name="任务A"> <transition name="提交到任务B" to="任务B" g="-78,-17"/> </task> <task assignee="${user.userName}" g="412,259,92,52" name="任务B"> <transition name="提交到任务C" to="任务C" g="-93,-12"/> </task> <task assignee="${user.userCode}" g="409,372,92,52" name="任务C"> <transition name="通过" to="end1" g="-35,-8"/> </task> <start g="440,36,48,48" name="start1"> <transition name="提交到任务A" to="任务A" g="-75,-19"/> </start> <end g="425,491,48,48" name="end1"/> </process>
public void getTask() { //通过用户ID得到任务信息,如数量、名称、ID List<Task> tasks=taskService.findPersonalTasks("001"); print("任务数量",tasks.size()); print("任务名称", tasks.get(0).getActivityName()); print("任务ID", tasks.get(0).getId()); }
<?xml version="1.0" encoding="UTF-8"?> <process key="task" name="task" xmlns="http://jbpm.org/4.4/jpdl"> <task g="406,144,92,52" name="任务A"> <!-- 设置监听的类,是哪一个类 --> <assignment-handler class="com.tgb.video.node.task.handler.AssignTask"> </assignment-handler> <transition name="提交到任务B" to="任务B" g="-78,-17"/> </task> <task g="412,259,92,52" name="任务B"> <!-- 设置监听的类,是哪一个类 --> <assignment-handler class="com.tgb.video.node.task.handler.AssignTask1"> </assignment-handler> <transition name="提交到任务C" to="任务C" g="-93,-12"/> </task> <task g="409,372,92,52" name="任务C"> <transition name="通过" to="end1" g="-35,-8"/> </task> <start g="440,36,48,48" name="start1"> <transition name="提交到任务A" to="任务A" g="-75,-19"/> </start> <end g="425,491,48,48" name="end1"/> </process>
这里边设置了一个监听属性,指定了监听类是哪一个,该类实现了一个AssignementHandler监听接口,当到达该任务时它会监听到并将用户信息设置到assignee属性上面,如下:
public class AssignTask implements AssignmentHandler { /** * 设置task的assignee属性 */ private static final long serialVersionUID = 1L; @Override public void assign(Assignable assignable, OpenExecution openExecution) throws Exception { assignable.setAssignee("001"); } }