예제 #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;
     }
   }
 }
예제 #2
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;
          }
        }
      }
    }
  }