private void getNearestWorkingDateForShift(final Shift shift, final Entity productionLine, final DateTime dateFrom, final DateTime currentDate, final List<DateTimeRange> finalShiftWorkTimes) { List<DateTimeRange> workTimes = Lists.newArrayList(); List<TimeRange> shiftWorkTimes = shift.findWorkTimeAt(currentDate.toLocalDate()); for (TimeRange shiftWorkTime : shiftWorkTimes) { getNearestWorkingDateForShiftWorkTime(shiftWorkTime, dateFrom, currentDate, workTimes); } workTimes = shiftExceptionService.manageExceptions(workTimes, productionLine, shift, currentDate.toDate()); workTimes = workTimes.stream().filter(workTime -> workTime.contains(dateFrom) || workTime.isAfter(dateFrom)) .collect(Collectors.toList()); finalShiftWorkTimes.addAll(workTimes); }
private List<DateTimeRange> removeFreeTimeException(final List<DateTimeRange> shiftWorkDateTime, final Entity exception, final Shift shift) { Optional<DateTimeRange> exceptionRange = getExceptionRange(exception, shift, false); if (exceptionRange.isPresent()) { List<DateTimeRange> result = Lists.newArrayList(); for (DateTimeRange range : shiftWorkDateTime) { result.addAll(range.remove(exceptionRange.get())); } return result; } else { return shiftWorkDateTime; } }
private Optional<DateTime> findFirstWorkingDate(Entity order, Date orderStartDate) { DateTime orderStartDateDT = new DateTime(orderStartDate, DateTimeZone.getDefault()); List<Shift> shifts = shiftsDataProvider.findAll(); DateTime dateOfDay = new DateTime(orderStartDate); dateOfDay = dateOfDay.minusDays(ONE_DAY); dateOfDay = dateOfDay.toLocalDate().toDateTimeAtStartOfDay(); boolean notFound = true; int loopCount = 0; while (notFound) { if (loopCount > MAX_LOOPS) { return Optional.empty(); } for (Shift shift : shifts) { for (DateTimeRange range : shiftExceptionService .getShiftWorkDateTimes(order.getBelongsToField(OrderFields.PRODUCTION_LINE), shift, dateOfDay)) { if (orderStartDate.after(dateOfDay.toDate())) { range = range.trimBefore(orderStartDateDT); } if (range != null && range.durationInMins() > 0l) { return Optional.of(range.getFrom()); } } } loopCount++; dateOfDay = dateOfDay.plusDays(1); } return Optional.empty(); }
public List<DateTimeRange> manageExceptions(List<DateTimeRange> shiftWorkDateTime, final Entity productionLine, final Shift shift, final Date dateOfDay) { List<Entity> exceptions; Entity shiftEntity = shift.getEntity(); if (Objects.isNull(productionLine)) { exceptions = shiftEntity.getHasManyField(ShiftFields.TIMETABLE_EXCEPTIONS); } else { exceptions = timetableExceptionService.findFor(productionLine, shiftEntity, dateOfDay); } Shift shiftForDay = new Shift(shiftEntity, new DateTime(dateOfDay), false); for (Entity exception : exceptions) { if (TimetableExceptionType.FREE_TIME.getStringValue() .equals(exception.getStringField(ShiftTimetableExceptionFields.TYPE))) { shiftWorkDateTime = removeFreeTimeException(shiftWorkDateTime, exception, shiftForDay); } if (TimetableExceptionType.WORK_TIME.getStringValue() .equals(exception.getStringField(ShiftTimetableExceptionFields.TYPE))) { shiftWorkDateTime = addWorkTimeException(shiftWorkDateTime, exception, shiftForDay); } } return shiftWorkDateTime; }
.getShiftWorkDateTimes(order.getBelongsToField(OrderFields.PRODUCTION_LINE), shift, dateOfDay)) { if (orderStartDate.after(dateOfDay.toDate())) { range = range.trimBefore(orderStartDateDT);
public List<DateTimeRange> getShiftWorkDateTimes(final Entity productionLine, final Shift shift, DateTime dateOfDay) { List<TimeRange> shiftWorkTime = Lists.newArrayList(); List<DateTimeRange> shiftWorkDateTime = Lists.newArrayList(); if (shift.worksAt(dateOfDay.dayOfWeek().get())) { shiftWorkTime = shift.findWorkTimeAt(dateOfDay.toLocalDate()); } for (TimeRange range : shiftWorkTime) { shiftWorkDateTime.add(new DateTimeRange(dateOfDay, range)); } shiftWorkDateTime = manageExceptions(shiftWorkDateTime, productionLine, shift, dateOfDay.toDate()); return shiftWorkDateTime; }
int time = 0; for (DateTimeRange range : shiftExceptionService .getShiftWorkDateTimes(order.getBelongsToField(OrderFields.PRODUCTION_LINE), shift, dateOfDay)) { if (orderStartDate.after(dateOfDay.toDate())) { range = range.trimBefore(orderStartDateDT);
private List<DateTimeRange> addWorkTimeException(final List<DateTimeRange> shiftWorkDateTime, final Entity exception, final Shift shift) { Optional<DateTimeRange> exceptionRange = getExceptionRange(exception, shift, true); if (exceptionRange.isPresent()) { if (shiftWorkDateTime.isEmpty()) { return Lists.newArrayList(exceptionRange.get()); } List<DateTimeRange> result = Lists.newArrayList(); for (DateTimeRange range : shiftWorkDateTime) { result.addAll(range.add(exceptionRange.get())); } return result; } else { return shiftWorkDateTime; } }
shiftWorkDateTime = shiftExceptionService.manageExceptions(shiftWorkDateTime, order.getBelongsToField(OrderFields.PRODUCTION_LINE), shift, dateOfDay);