public String start(String processDefinitonKey, String businessId, Map varis) {
   ProcessInstance processInstance =
       processEngine
           .getExecutionService()
           .startProcessInstanceByKey(processDefinitonKey, varis, businessId);
   return processInstance.getId();
 }
 @Override // 默认销售负责人负责的工单列表
 public String execute() throws Exception {
   List<Issue> dbIssues = new ArrayList<Issue>();
   HttpSession session = request.getSession();
   // 获取当前登录用户
   User sessionUser = (User) session.getAttribute(LicenseWorkFlowConstants.SESSION_USER);
   // 获取流程定义列表
   List<ProcessDefinition> pdList =
       issueService.getRepositoryService().createProcessDefinitionQuery().list();
   // 获取流程实例列表
   List<ProcessInstance> piList =
       issueService.getExecutionService().createProcessInstanceQuery().list();
   // 获取该用户组内的任务
   List<Task> taskList = issueService.getTaskService().findGroupTasks(sessionUser.getName());
   // 查询库中所有的工单
   dbIssues = issueService.getAllIssues();
   // 获取流程寮例历史记录列表
   List<HistoryProcessInstance> hplist =
       issueService.getHistoryService().createHistoryProcessInstanceQuery().list();
   String processDefinitionId = ""; // 流程定义标识
   if (pdList != null && pdList.size() > 0) {
     processDefinitionId = ((ProcessDefinition) (pdList.get(0))).getId();
   }
   // 遍历系统中的工单
   for (Issue issue : dbIssues) {
     // 设置工单的流程节点
     String activeName = issueService.getActiveName(issue.getProcessInstanceId());
     IssueVO issueVO = new IssueVO();
     issueVO.setWorkFlowNodeName(activeName);
     // 遍历当前登录用户的task列表
     for (Task task : taskList) {
       // 获取执行
       Execution execution =
           issueService.getExecutionService().findExecutionById(task.getExecutionId());
       ExecutionImpl execImpl = (ExecutionImpl) execution;
       // 获取执行的流程实例
       ProcessInstance processInstance = execImpl.getProcessInstance();
       if (issue.getProcessInstanceId().equals(processInstance.getId())) {
         // 显示审核链接
         issueVO.setShowAudit(true);
         // 当前工单要审核的task
         issueVO.setIssueTask(task);
         break;
       } else {
         issueVO.setShowAudit(false);
       }
     }
     LicenseWorkFlowConstants.issuePOTOVOCopier.copy(issue, issueVO, null);
     issues.add(issueVO);
   }
   return "index";
 }
  protected void triggerCompleted(String type, boolean remove) {
    if (remove) {

      processInstance.getNodeContainer().removeNodeInstance(this);
    }
    Node node = getNode();
    List<SequenceFlow> flows = null;
    if (node != null) {
      flows = node.getOutgoingFlows(type);
    }
    if (flows == null || flows.isEmpty()) {
      processInstance.getNodeContainer().nodeInstanceCompleted(this, type);
    } else {
      for (SequenceFlow flow : flows) {
        triggerConnection(flow);
      }
    }
  }
  @Transactional(propagation = Propagation.REQUIRED)
  public void addLeaveReceipt(SLeave leave, SUser loginUser) {
    if (leave.getLeaveId() == null) {
      if (leave.getStatus().intValue() == 2) {
        leave.setUserId(loginUser.getUserId());
        Integer leaveId = this.leaveDao.insert(leave);
      } else {
        leave.setUserId(loginUser.getUserId());
        leave.setLeaveTime(new Date());
        //				leave.setStatus(0);
        leave.setLeaveCode(NormalFun.getNextCode(Constants.LEAVE_PREFIX, leaveDao.getMaxCode()));
        Integer leaveId = this.leaveDao.insert(leave);
        // 如果是调休,需减掉对应的加班时数
        if (leave.getTypeId().intValue() == 7) {
          SOvertimeCollection userOtCollection =
              this.overtimeCollectionDao.selectByPrimaryKey(loginUser.getUserId());
          userOtCollection.setHoursCollection(
              userOtCollection.getHoursCollection().floatValue()
                  - leave.getLeaveDays().floatValue());
          this.overtimeCollectionDao.updateByPrimaryKey(userOtCollection);
        }
        // 如果是年假,需减掉对应的请假时数
        if (leave.getTypeId().intValue() == 3) {
          SAnnualLeave sal = this.leaveDao.getAnnualLeave(loginUser.getUserId());
          sal.setAnnualHours(sal.getAnnualHours().intValue() - leave.getLeaveDays().intValue());
          this.leaveDao.updateAnnualLeaveHours(sal);
        }

        SDepartment dept = this.departmentDao.getSDepartmentById(loginUser.getDepartmentId());
        ProcessEngine processEngine = Configuration.getProcessEngine();
        Map<String, Object> instanceVariables = new HashMap<String, Object>();
        instanceVariables.put("userName", loginUser.getUserName());
        instanceVariables.put("userId", String.valueOf(loginUser.getUserId()));
        instanceVariables.put("typeName", "休假单");
        instanceVariables.put("deptName", dept.getName());

        instanceVariables.put("leaveDays", leave.getLeaveDays());
        SPosition sp = positionDao.selectByPrimaryKey(loginUser.getPositionOrgId());
        instanceVariables.put("orgPosition", sp.getName());

        // 启动流程实例
        ProcessInstance processInstance =
            processEngine
                .getExecutionService()
                .startProcessInstanceByKey("leave", instanceVariables, String.valueOf(leaveId));
        //				processEngine.getExecutionService().setVariables(processInstance.getId(),
        // instanceVariables);

        List<Task> myTaskList =
            processEngine.getTaskService().findPersonalTasks(String.valueOf(loginUser.getUserId()));
        for (Task task : myTaskList) {
          if (task.getExecutionId().equals(processInstance.getId())) {
            // processEngine.getTaskService().setVariables(task.getId(), instanceVariables);
            processEngine.getTaskService().completeTask(task.getId(), "申请");
            break;
          }
        }
      }
    } else {
      if (leave.getStatus().intValue() == 2) {
        this.leaveDao.updateByPrimaryKeySelective(leave);
      } else {
        leave.setLeaveTime(new Date());
        leave.setLeaveCode(NormalFun.getNextCode(Constants.LEAVE_PREFIX, leaveDao.getMaxCode()));
        this.leaveDao.updateByPrimaryKeySelective(leave);
        // 如果是调休,需减掉对应的加班时数
        if (leave.getTypeId().intValue() == 7) {
          SOvertimeCollection userOtCollection =
              this.overtimeCollectionDao.selectByPrimaryKey(loginUser.getUserId());
          userOtCollection.setHoursCollection(
              userOtCollection.getHoursCollection().floatValue()
                  - leave.getLeaveDays().floatValue());
          this.overtimeCollectionDao.updateByPrimaryKey(userOtCollection);
        }
        // 如果是年假,需减掉对应的请假时数
        if (leave.getTypeId().intValue() == 3) {
          SAnnualLeave sal = this.leaveDao.getAnnualLeave(loginUser.getUserId());
          sal.setAnnualHours(sal.getAnnualHours().intValue() - leave.getLeaveDays().intValue());
          this.leaveDao.updateAnnualLeaveHours(sal);
        }

        SDepartment dept = this.departmentDao.getSDepartmentById(loginUser.getDepartmentId());
        ProcessEngine processEngine = Configuration.getProcessEngine();
        Map<String, Object> instanceVariables = new HashMap<String, Object>();
        instanceVariables.put("userName", loginUser.getUserName());
        instanceVariables.put("userId", String.valueOf(loginUser.getUserId()));
        instanceVariables.put("typeName", "休假单");
        instanceVariables.put("deptName", dept.getName());

        instanceVariables.put("leaveDays", leave.getLeaveDays());
        SPosition sp = positionDao.selectByPrimaryKey(loginUser.getPositionOrgId());
        instanceVariables.put("orgPosition", sp.getName());

        // 启动流程实例
        ProcessInstance processInstance =
            processEngine
                .getExecutionService()
                .startProcessInstanceByKey(
                    "leave", instanceVariables, String.valueOf(leave.getLeaveId()));
        //				processEngine.getExecutionService().setVariables(processInstance.getId(),
        // instanceVariables);

        List<Task> myTaskList =
            processEngine.getTaskService().findPersonalTasks(String.valueOf(loginUser.getUserId()));
        for (Task task : myTaskList) {
          if (task.getExecutionId().equals(processInstance.getId())) {
            // processEngine.getTaskService().setVariables(task.getId(), instanceVariables);
            processEngine.getTaskService().completeTask(task.getId(), "申请");
            break;
          }
        }
      }
    }
  }