/** Start Process Definition */
  public static ProcessInstance runProcessDefinition(
      String user, long processDefinitionId, String uuid, List<FormElement> variables)
      throws WorkflowException {
    log.debug(
        "runProcessDefinition({}, {}, {}, {})",
        new Object[] {user, processDefinitionId, uuid, variables});
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    ProcessInstance vo = new ProcessInstance();

    if (Config.SYSTEM_READONLY) {
      throw new WorkflowException("System is in read-only mode");
    }

    try {
      jbpmContext.setActorId(user);
      GraphSession graphSession = jbpmContext.getGraphSession();
      Map<String, Object> hm = new HashMap<String, Object>();
      hm.put(Config.WORKFLOW_PROCESS_INSTANCE_VARIABLE_UUID, uuid);

      for (FormElement fe : variables) {
        hm.put(fe.getName(), fe);
      }

      org.jbpm.graph.def.ProcessDefinition pd =
          graphSession.getProcessDefinition(processDefinitionId);
      org.jbpm.graph.exe.ProcessInstance pi = pd.createProcessInstance(hm);

      if (pi != null) {
        org.jbpm.taskmgmt.exe.TaskMgmtInstance tmi = pi.getTaskMgmtInstance();

        // http://community.jboss.org/thread/115182
        if (tmi.getTaskMgmtDefinition().getStartTask() != null) {
          org.jbpm.taskmgmt.exe.TaskInstance ti = tmi.createStartTaskInstance();

          if (Config.WORKFLOW_START_TASK_AUTO_RUN) {
            ti.start();
            ti.end();
          }
        } else {
          pi.getRootToken().signal();
        }

        jbpmContext.save(pi);
        vo = WorkflowUtils.copy(pi);
      }
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("runProcessDefinition: {}", vo);
    return vo;
  }
  public ActionForward insertPayment(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws AppException {
    String forwardPage = "";
    Inform inf = new Inform();

    Workflow workflow = (Workflow) form;

    JbpmContext jbpmContext = JbpmUtil.getJbpmContext();
    try {
      String issueperson = "user1";
      // 设置当前用户为user1
      jbpmContext.setActorId(issueperson);

      ProcessDefinition pd = jbpmContext.getGraphSession().findLatestProcessDefinition("payment");

      ProcessInstance processInstance = pd.createProcessInstance();
      ContextInstance contextInstance = processInstance.getContextInstance();

      //
      contextInstance.setVariable("issueperson", issueperson);

      // 创建开始节点的TaskInstance
      TaskInstance taskInstance = processInstance.getTaskMgmtInstance().createStartTaskInstance();

      // 向任务实例当中写入相关变量
      taskInstance.setVariable("title", workflow.getTitle());
      taskInstance.setVariable("moneyCount", workflow.getMoneyCount());
      taskInstance.setVariable("remark", workflow.getRemark());

      // 结束任务实例,token进入部门经理审批
      taskInstance.end();

      inf.setMessage("报销申请提交成功");
    } catch (Exception e) {
      e.printStackTrace();
      inf.setMessage("异常信息:" + e.getMessage());
    } finally {
      jbpmContext.close();
    }
    return forwardInformPage(inf, mapping, request);
  }