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; }
public Map<Vacation, Integer> getWorkDays( Map<Vacation, Integer> calDays, List<Holiday> holidays) { Map<Vacation, Integer> workDays = new HashMap<Vacation, Integer>(calDays.size()); for (Map.Entry<Vacation, Integer> entry : calDays.entrySet()) { Vacation vacation = entry.getKey(); Integer calDaysInVacation = entry.getValue(); Region emplRegion = vacation.getEmployee().getRegion(); final int holidaysCount = getHolidaysCount(holidays, emplRegion, vacation.getBeginDate(), vacation.getEndDate()); final int workDaysCount = calDaysInVacation - holidaysCount; workDays.put(vacation, workDaysCount); } return workDays; }
public JsonArrayNodeBuilder createVacationsNode(Employee employee, List<Vacation> vacationList) { JsonArrayNodeBuilder vacationNode = anArrayBuilder(); for (Vacation vacation : vacationList) { if (vacation.getEmployee().equals(employee)) { vacationNode.withElement( anObjectBuilder() .withField( "beginDate", aStringBuilder(dateToString(vacation.getBeginDate(), VIEW_DATE_PATTERN))) .withField( "endDate", aStringBuilder(dateToString(vacation.getEndDate(), VIEW_DATE_PATTERN))) .withField("status", aStringBuilder(vacation.getStatus().getValue())) .withField("type", aStringBuilder(vacation.getType().getId().toString())) .withField("typeName", aStringBuilder(vacation.getType().getValue()))); } } return vacationNode; }
/* определяет по дате началу отпуска принадлежность году */ private Boolean vacationStatusInThisYear(Vacation vacation, int year) { Calendar cal = Calendar.getInstance(); cal.setTime(vacation.getBeginDate()); return cal.get(Calendar.YEAR) == year; }
public void createAndMailVacation( CreateVacationForm createVacationForm, Employee employee, Employee curEmployee, boolean isApprovedVacation) throws VacationApprovalServiceException { final Vacation vacation = new Vacation(); vacation.setCreationDate(new Date()); vacation.setBeginDate(DateTimeUtil.stringToTimestamp(createVacationForm.getCalFromDate())); vacation.setEndDate(DateTimeUtil.stringToTimestamp(createVacationForm.getCalToDate())); vacation.setComment(createVacationForm.getComment().trim()); vacation.setType(dictionaryItemService.find(createVacationForm.getVacationType())); vacation.setAuthor(curEmployee); vacation.setEmployee(employee); vacation.setRemind(false); vacation.setStatus( dictionaryItemService.find( isApprovedVacation ? VacationStatusEnum.APPROVED.getId() : VacationStatusEnum.APPROVEMENT_WITH_PM.getId())); TransactionStatus transactionStatus = null; try { transactionStatus = getNewTransaction(); store(vacation); boolean isPlannedVacation = vacation.getType().getId().equals(VacationTypesEnum.PLANNED.getId()); if (isPlannedVacation) { vacationApprovalProcessService.sendNoticeForPlannedVacaton(vacation); } else { List<Vacation> plannedVacations = vacationDAO.getPlannedVacationsByBeginAndEndDates( employee, vacation.getBeginDate(), vacation.getEndDate()); for (Vacation plannedVacation : plannedVacations) { delete(plannedVacation); } if (needsToBeApproved(vacation)) { vacationApprovalProcessService.sendVacationApproveRequestMessages( vacation); // рассылаем письма о согласовании отпуска } else { vacationApprovalProcessService.sendBackDateVacationApproved(vacation); } } commit(transactionStatus); } catch (VacationApprovalServiceException e) { if (transactionStatus != null) { rollback(transactionStatus); logger.error("Transaction rollbacked. Error saving vacation: {} ", e); } else { logger.error("TransactionStatus is null."); } } sendMailService.performVacationCreateMailing(vacation); }