Пример #1
0
  public List<Vacation> getVacationList(VacationsForm vacationsForm) {
    Integer divisionId = vacationsForm.getDivisionId();
    Integer employeeId = vacationsForm.getEmployeeId();
    Date dateFrom = DateTimeUtil.parseStringToDateForDB(vacationsForm.getCalFromDate());
    Date dateTo = DateTimeUtil.parseStringToDateForDB(vacationsForm.getCalToDate());
    Integer projectId = vacationsForm.getProjectId();
    Integer managerId = vacationsForm.getManagerId();
    List<Integer> regions = vacationsForm.getRegions();
    DictionaryItem vacationType =
        vacationsForm.getVacationType() != 0
            ? dictionaryItemService.find(vacationsForm.getVacationType())
            : null;

    List<Vacation> vacations = new ArrayList<Vacation>();
    if (employeeId != null && employeeId != ALL_VALUE) {
      vacations.addAll(findVacations(employeeId, dateFrom, dateTo, vacationType));
    } else {
      List<Employee> employees =
          employeeService.getEmployees(
              employeeService.createDivisionList(divisionId),
              employeeService.createManagerList(managerId),
              employeeService.createRegionsList(regions),
              employeeService.createProjectList(projectId),
              dateFrom,
              dateTo,
              true);
      vacations.addAll(findVacations(employees, dateFrom, dateTo, vacationType));
    }
    sortVacations(vacations);
    return vacations;
  }
Пример #2
0
  private void addEmployeePlans(
      List<EmployeePlan> employeePlans,
      Integer year,
      Integer month,
      Employee employee,
      JsonNode jsonNode) {
    final Map<JsonStringNode, JsonNode> fields = jsonNode.getFields();

    JsonStringNode field;

    for (Map.Entry<JsonStringNode, TSEnum> entry : PLAN_TYPE_MAP.entrySet()) {
      field = entry.getKey();

      final EmployeePlan employeePlan =
          createEmployeePlanIfNeed(
              year, month, employee, dictionaryItemService.find(entry.getValue().getId()));

      if (fields.containsKey(field)) {
        employeePlan.setValue(JsonUtil.getFloatNumberValue(jsonNode, field.getText()));

        employeePlans.add(employeePlan);
      }
    }

    // KSS APLANATS-850 Удалять будем только существующие записи с value=0.
    // Удаление будет вызвано в методе
    // com.aplana.timesheet.service.EmployeePlanService.mergeProjectPlans

  }
Пример #3
0
 public Map<Vacation, Integer> getCalDays(List<Vacation> vacations) {
   Map<Vacation, Integer> calDays = new HashMap<Vacation, Integer>(vacations.size());
   for (Vacation vacation : vacations) {
     Integer diffInDays =
         DateTimeUtil.getDiffInDays(vacation.getBeginDate(), vacation.getEndDate());
     calDays.put(vacation, diffInDays);
   }
   return calDays;
 }
Пример #4
0
 public List<DictionaryItem> getVacationTypes(List<Vacation> vacations) {
   List<DictionaryItem> result = new ArrayList<DictionaryItem>();
   for (Vacation vacation : vacations) {
     if (!result.contains(vacation.getType())) {
       result.add(vacation.getType());
     }
   }
   // отсортируем
   Collections.sort(
       result,
       new Comparator() {
         @Override
         public int compare(Object type1, Object type2) {
           Integer typeId1 = ((DictionaryItem) type1).getId();
           Integer typeId2 = ((DictionaryItem) type2).getId();
           return typeId1.compareTo(typeId2);
         }
       });
   return result;
 }
Пример #5
0
 public List<VacationInYear> getSummaryDaysCountByYearAndType(
     List<DictionaryItem> vacationTypes,
     int firstYear,
     int lastYear,
     Map<Vacation, Integer> calDays,
     Map<Vacation, Integer> workDays) {
   List<VacationInYear> result = new ArrayList<VacationInYear>();
   for (DictionaryItem vacationType : vacationTypes) {
     for (int year = firstYear; year <= lastYear; year++) {
       Map<Vacation, Integer> calDaysForYearByType =
           getDaysForYearByType(calDays, year, vacationType);
       Map<Vacation, Integer> workDaysForYearByType =
           getDaysForYearByType(workDays, year, vacationType);
       int summaryCalDays = getSummaryDaysCount(calDaysForYearByType);
       int summaryWorkDays = getSummaryDaysCount(workDaysForYearByType);
       result.add(
           new VacationInYear(vacationType.getValue(), year, summaryCalDays, summaryWorkDays));
     }
   }
   return result;
 }
Пример #6
0
 public String getVacationListByRegionJSON(
     Date dateFrom, Date dateTo, List<Vacation> vacationList) {
   List<Region> regionList = regionService.getRegions();
   List<Employee> employeeList = new ArrayList<Employee>();
   for (Vacation vacation : vacationList) {
     Employee employee = vacation.getEmployee();
     if (!(employeeList.contains(employee))) {
       employeeList.add(employee);
     }
   }
   final JsonArrayNodeBuilder result = anArrayBuilder();
   // для каждого проекта смотрим сотрудников у которых есть отпуск
   for (Region region : regionList) {
     JsonArrayNodeBuilder employeeNode = anArrayBuilder();
     boolean hasEmployees = false;
     for (Employee employee : employeeList) {
       if (employee.getRegion().getId().equals(region.getId())) {
         JsonArrayNodeBuilder vacationNode = createVacationsNode(employee, vacationList);
         hasEmployees = true;
         employeeNode.withElement(
             anObjectBuilder()
                 .withField("employee", aStringBuilder(employee.getName()))
                 .withField("vacations", vacationNode));
       }
     }
     if (hasEmployees) {
       result.withElement(
           anObjectBuilder()
               .withField("region_id", aStringBuilder(region.getId().toString()))
               .withField("region_name", aStringBuilder(region.getName()))
               .withField("employeeList", employeeNode)
               .withField("holidays", getHolidayInRegion(dateFrom, dateTo, region)));
     }
   }
   return JsonUtil.format(result);
 }
Пример #7
0
  private void addEmployeeProjectPlans(
      List<EmployeeProjectPlan> employeeProjectPlans,
      Integer year,
      Integer month,
      Employee employee,
      JsonNode jsonNode) {
    // employeeProjectPlanService.remove(employee, year, month); KSS APLANATS-850 Удалять будем
    // только существующие записи с value=0. Удаление будет вызвано в методе
    // com.aplana.timesheet.service.EmployeeProjectPlanService.mergeEmployeeProjectPlans

    if (jsonNode.getFields().containsKey(PROJECTS_PLANS_FIELD)) {
      for (JsonNode node : jsonNode.getArrayNode(PROJECTS_PLANS)) {
        employeeProjectPlans.add(createEmployeeProjectPlanIfNeed(year, month, employee, node));
      }
    }
  }