예제 #1
0
 @Transactional(propagation = Propagation.REQUIRED)
 public void updateLeaveReceipt(SLeave leave) {
   this.leaveDao.updateByPrimaryKeySelective(leave);
   // 如果是调休,需减掉对应的加班时数
   if (leave.getTypeId().intValue() == 7) {
     SOvertimeCollection userOtCollection =
         this.overtimeCollectionDao.selectByPrimaryKey(leave.getUserId());
     userOtCollection.setHoursCollection(
         userOtCollection.getHoursCollection().floatValue()
             - leave.getLeaveDays().floatValue() * 8);
     this.overtimeCollectionDao.updateByPrimaryKey(userOtCollection);
   }
   // 如果是年假,需减掉对应的请假时数
   if (leave.getTypeId().intValue() == 3) {
     SAnnualLeave sal = this.leaveDao.getAnnualLeave(leave.getUserId());
     sal.setAnnualHours(sal.getAnnualHours().intValue() - leave.getLeaveDays().intValue());
     this.leaveDao.updateAnnualLeaveHours(sal);
   }
   String instanceId = "leave." + leave.getLeaveId();
   ProcessEngine processEngine = Configuration.getProcessEngine();
   List<Task> myTaskList =
       processEngine.getTaskService().findPersonalTasks(String.valueOf(leave.getUserId()));
   for (Task task : myTaskList) {
     if (task.getExecutionId().equals(instanceId)) {
       processEngine.getTaskService().completeTask(task.getId(), "申请");
       break;
     }
   }
 }
 public void next(String userId, String taskId, Map varis) {
   Task task = processEngine.getTaskService().getTask(taskId);
   if (task.getAssignee() == null) {
     processEngine.getTaskService().takeTask(taskId, userId);
     varis.put("!" + task.getActivityName(), userId);
   }
   processEngine.getTaskService().completeTask(taskId, varis);
 }
예제 #3
0
 public JbpmTemplate(ProcessEngine processEngine) {
   this.processEngine = processEngine;
   repositoryService = processEngine.getRepositoryService();
   executionService = processEngine.getExecutionService();
   taskService = processEngine.getTaskService();
   historyService = processEngine.getHistoryService();
   managementService = processEngine.getManagementService();
 }
예제 #4
0
 public void setProcessEngine(ProcessEngine processEngine) {
   this.processEngine = processEngine;
   System.out.println(processEngine);
   repositoryService = processEngine.getRepositoryService();
   executionService = processEngine.getExecutionService();
   taskService = processEngine.getTaskService();
   historyService = processEngine.getHistoryService();
   managementService = processEngine.getManagementService();
 }
 public String start(String processDefinitonKey, String businessId, Map varis) {
   ProcessInstance processInstance =
       processEngine
           .getExecutionService()
           .startProcessInstanceByKey(processDefinitonKey, varis, businessId);
   return processInstance.getId();
 }
 public List<Map<String, String>> findTaskNodes(String processDefinitionId) {
   List<Map<String, String>> list = new ArrayList<Map<String, String>>();
   RepositoryService repositoryService = processEngine.getRepositoryService();
   ProcessDefinition processDefinition =
       repositoryService
           .createProcessDefinitionQuery()
           .processDefinitionId(processDefinitionId)
           .uniqueResult();
   InputStream input =
       repositoryService.getResourceAsStream(
           processDefinition.getDeploymentId(), processDefinition.getKey() + ".jpdl.xml");
   try {
     Document doc = new SAXReader().read(input);
     for (Iterator i = doc.getRootElement().elementIterator("task"); i.hasNext(); ) {
       Element foo = (Element) i.next();
       String act = foo.attributeValue("name");
       Map<String, String> rec = new HashMap<String, String>();
       TaskUsers taskUsers =
           (TaskUsers)
               sessionFactory
                   .getCurrentSession()
                   .get(TaskUsers.class, processDefinitionId + "_" + act);
       rec.put("name", act);
       if (taskUsers != null) {
         rec.put("type", taskUsers.getType());
         rec.put("value", taskUsers.getEntityId());
         rec.put("text", taskUsers.getEntityName());
       }
       list.add(rec);
     }
   } catch (DocumentException e) {
     e.printStackTrace();
   }
   return list;
 }
 public List<ProcessInstance> findProcessInstances(String processDefinitionId) {
   return processEngine
       .getExecutionService()
       .createProcessInstanceQuery()
       .processDefinitionId(processDefinitionId)
       .list();
 }
  public void delete(String deploymentId) {
    ProcessDefinition processDefinition =
        processEngine
            .getRepositoryService()
            .createProcessDefinitionQuery()
            .deploymentId(deploymentId)
            .uniqueResult();
    processEngine
        .getRepositoryService()
        .deleteDeploymentCascade(processDefinition.getDeploymentId());

    Session session = sessionFactory.getCurrentSession();
    session
        .createQuery("delete from TaskUsers tu where tu.id like :id")
        .setParameter("id", processDefinition.getId() + "%")
        .executeUpdate();
  }
 public String deploy(InputStream input, String remark) {
   String deploymentId =
       processEngine
           .getRepositoryService()
           .createDeployment()
           .addResourcesFromZipInputStream(new ZipInputStream(input))
           .deploy();
   if (log.isDebugEnabled()) {
     log.debug("deploymentId:" + deploymentId + ",remark:" + remark);
   }
   return deploymentId;
 }
예제 #10
0
 // removes any history and process data
 @Transactional
 public String removeAll() {
   try {
     // remove brute force including history and running instances
     processEngine.getRepositoryService().deleteDeploymentCascade(Long.toString(deploymentId));
     hibernateSession.flush();
     return "removedAll";
   } catch (final JbpmException ex) {
     final FacesMessages facesMessages = FacesMessages.instance();
     facesMessages.add(Severity.ERROR, "Error: " + ex.toString());
     ex.printStackTrace();
     return "invalid";
   }
 }
예제 #11
0
 // removes just the process keeping the history data
 @Transactional
 public String remove() {
   try {
     // remove if there are no open executions, history information stays
     processEngine.getRepositoryService().deleteDeployment(Long.toString(deploymentId));
     hibernateSession.flush();
     return "removed";
   } catch (final JbpmException ex) {
     final FacesMessages facesMessages = FacesMessages.instance();
     facesMessages.add(Severity.ERROR, "Error: " + ex.toString());
     ex.printStackTrace();
     return "invalid";
   }
 }
예제 #12
0
  @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;
          }
        }
      }
    }
  }
 public String getBusinessIdByTaskId(String taskId) {
   Task task = processEngine.getTaskService().getTask(taskId);
   Execution execution =
       processEngine.getExecutionService().findExecutionById(task.getExecutionId());
   return execution.getKey();
 }
 public List<ProcessDefinition> findProcessDefinitions() {
   return processEngine.getRepositoryService().createProcessDefinitionQuery().list();
 }
 public void deleteProcessInstance(String processInstanceId) {
   processEngine.getExecutionService().deleteProcessInstanceCascade(processInstanceId);
 }
 public List<Task> findTodos(String userId) {
   TaskService taskService = processEngine.getTaskService();
   List<Task> list = taskService.createTaskQuery().candidate(userId).list();
   list.addAll(taskService.findPersonalTasks(userId));
   return list;
 }