日期:2014-05-17 浏览次数:20719 次
public ProcessInstance approvalProcess(final long id, final Map attrs) throws Exception { return (ProcessInstance) jbpmTemplate.execute(new JbpmCallback() { public Object doInJbpm(JbpmContext context) throws JbpmException { ProcessInstance pi = context.getGraphSession() .loadProcessInstance(id);//得到流程实例 String nodeName = ""; String trans = ""; try { Node node = pi.getRootToken().getNode(); nodeName = node.getName(); //得到当前节点名称 Transition transition = (Transition) node .getLeavingTransitions().get(0); trans = transition.getName();//得到当前节点对应的发送描述 } catch (Exception e) { } //判断流程实例是否结束 if (!pi.hasEnded()) { //得到当前实例所有任务 Iterator<TaskInstance> it = pi.getTaskMgmtInstance() .getTaskInstances().iterator(); for (; it.hasNext();) { TaskInstance ti = it.next(); //遍历所有任务,如果有和当前节点名称相同的任务 if (nodeName.equals(ti.getName())) { //设置任务完成时间 ti.setEnd(new Date()); //设置任务完成意见 ti.addComment(attrs.get("comment").toString()); //将发送描述放到description备用 ti.setDescription(trans); //得到任务处理人集合 Set se = ti.getPooledActors(); Iterator iterator = se.iterator(); while(iterator.hasNext()){ PooledActor pl = (PooledActor)iterator.next(); //attrs.get("author")是当前用户, //如果匹配到任务处理人集合里有当前人,则把任务完成者设为当前用户 if(pl.getActorId().equals(attrs.get("author"))){ ti.setActorId(pl.getActorId()); break; } } break; } } //发送流程实例 pi.signal(); //保存流程实例 context.save(pi); } else { throw new JbpmException("ProcessInstance " + id + " is end"); } return pi; } }); }