Search in sources :

Example 1 with DateTimeRange

use of com.qcadoo.mes.basic.util.DateTimeRange in project mes by qcadoo.

the class ShiftExceptionService method getShiftWorkDateTimes.

public List<DateTimeRange> getShiftWorkDateTimes(final Entity productionLine, final Shift shift, DateTime dateOfDay, final boolean removeFreeTimeException) {
    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(), removeFreeTimeException);
    return shiftWorkDateTime;
}
Also used : DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) TimeRange(com.qcadoo.commons.dateTime.TimeRange) DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange)

Example 2 with DateTimeRange

use of com.qcadoo.mes.basic.util.DateTimeRange in project mes by qcadoo.

the class ShiftsServiceImpl method getNearestWorkingDateForShiftWorkTime.

private void getNearestWorkingDateForShiftWorkTime(final TimeRange shiftWorkTime, final DateTime dateFrom, final DateTime currentDate, final List<DateTimeRange> workTimes) {
    LocalTime currentTime = currentDate.toLocalTime();
    LocalTime timeTo = shiftWorkTime.getTo();
    LocalTime timeFrom = shiftWorkTime.getFrom();
    if (!currentDate.equals(dateFrom.minusDays(1)) || timeFrom.isAfter(timeTo)) {
        if (timeFrom.isAfter(timeTo) && currentDate.equals(dateFrom.minusDays(1))) {
            if (currentTime.compareTo(LocalTime.MIDNIGHT) >= 0 && currentTime.compareTo(timeTo) <= 0) {
                Optional<Interval> interval = createInterval(currentDate.plusDays(1), currentTime, timeTo);
                interval.ifPresent(i -> workTimes.add(new DateTimeRange(i)));
            }
        } else {
            if (currentDate.equals(dateFrom)) {
                if (timeFrom.compareTo(currentTime) < 0 && timeTo.compareTo(currentTime) > 0) {
                    Optional<Interval> interval = createInterval(currentDate, currentTime, timeTo);
                    interval.ifPresent(i -> workTimes.add(new DateTimeRange(i)));
                } else if (timeFrom.isAfter(timeTo)) {
                    if (timeFrom.compareTo(currentTime) < 0) {
                        Optional<Interval> interval = createInterval(currentDate, currentTime, timeTo);
                        interval.ifPresent(i -> workTimes.add(new DateTimeRange(i)));
                    } else {
                        Optional<Interval> interval = createInterval(currentDate, timeFrom, timeTo);
                        interval.ifPresent(i -> workTimes.add(new DateTimeRange(i)));
                    }
                } else if (timeFrom.compareTo(currentTime) >= 0) {
                    Optional<Interval> interval = createInterval(currentDate, timeFrom, timeTo);
                    interval.ifPresent(i -> workTimes.add(new DateTimeRange(i)));
                }
            } else {
                Optional<Interval> interval = createInterval(currentDate, timeFrom, timeTo);
                interval.ifPresent(i -> workTimes.add(new DateTimeRange(i)));
            }
        }
    }
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) DateTimeZone(org.joda.time.DateTimeZone) ShiftFields(com.qcadoo.mes.basic.constants.ShiftFields) Date(java.util.Date) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) LocalTime(org.joda.time.LocalTime) Autowired(org.springframework.beans.factory.annotation.Autowired) Shift(com.qcadoo.mes.basic.shift.Shift) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Interval(org.joda.time.Interval) Lists(com.google.common.collect.Lists) Calendar(java.util.Calendar) BasicConstants(com.qcadoo.mes.basic.constants.BasicConstants) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) Map(java.util.Map) Days(org.joda.time.Days) TimetableExceptionType(com.qcadoo.mes.basic.constants.TimetableExceptionType) LinkedList(java.util.LinkedList) Period(org.joda.time.Period) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) DateTime(org.joda.time.DateTime) IllegalFieldValueException(org.joda.time.IllegalFieldValueException) Maps(com.google.common.collect.Maps) DataDefinition(com.qcadoo.model.api.DataDefinition) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Entity(com.qcadoo.model.api.Entity) List(java.util.List) DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) FieldComponent(com.qcadoo.view.api.components.FieldComponent) Optional(java.util.Optional) TimeRange(com.qcadoo.commons.dateTime.TimeRange) Comparator(java.util.Comparator) Collections(java.util.Collections) StringUtils(org.springframework.util.StringUtils) LocalTime(org.joda.time.LocalTime) Optional(java.util.Optional) DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) Interval(org.joda.time.Interval)

Example 3 with DateTimeRange

use of com.qcadoo.mes.basic.util.DateTimeRange in project mes by qcadoo.

the class ShiftsServiceImpl method getWorkedHoursOfWorker.

@Override
public BigDecimal getWorkedHoursOfWorker(final Shift shift, final DateTime dateOfDay) {
    BigDecimal hours = BigDecimal.ZERO;
    List<DateTimeRange> dateTimeRanges = getDateTimeRanges(Collections.singletonList(shift), dateOfDay.toDate(), dateOfDay.plusDays(1).toDate());
    for (DateTimeRange dateTimeRange : dateTimeRanges) {
        Period p = new Period(dateTimeRange.getFrom(), dateTimeRange.getTo());
        hours = hours.add(new BigDecimal(p.getHours()));
    }
    return hours;
}
Also used : Period(org.joda.time.Period) DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) BigDecimal(java.math.BigDecimal)

Example 4 with DateTimeRange

use of com.qcadoo.mes.basic.util.DateTimeRange in project mes by qcadoo.

the class ShiftsServiceImpl method getDateTimeRanges.

@Override
public List<DateTimeRange> getDateTimeRanges(final List<Shift> shifts, final Date dateFrom, final Date dateTo) {
    List<DateTimeRange> ranges = Lists.newArrayList();
    DateTime dateOfDay = new DateTime(dateFrom);
    int loopCount = 0;
    while (!dateOfDay.isAfter(new DateTime(dateTo))) {
        if (loopCount > MAX_LOOPS) {
            return ranges;
        }
        for (Shift shift : shifts) {
            ranges.addAll(shiftExceptionService.getShiftWorkDateTimes(null, shift, dateOfDay, true));
        }
        loopCount++;
        dateOfDay = dateOfDay.plusDays(1);
    }
    return ranges;
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) DateTime(org.joda.time.DateTime)

Example 5 with DateTimeRange

use of com.qcadoo.mes.basic.util.DateTimeRange in project mes by qcadoo.

the class ShiftsServiceImpl method getNearestWorkingDate.

@Override
public Optional<DateTime> getNearestWorkingDate(DateTime dateFrom, Entity productionLine) {
    List<Shift> shifts = findAll(productionLine);
    List<DateTimeRange> finalShiftWorkTimes = Lists.newArrayList();
    DateTime currentDate = dateFrom.minusDays(1);
    if (shifts.stream().noneMatch(shift -> checkShiftWorkingAfterDate(dateFrom, productionLine, shift))) {
        return Optional.empty();
    }
    while (finalShiftWorkTimes.isEmpty()) {
        for (Shift shift : shifts) {
            getNearestWorkingDateForShift(shift, productionLine, dateFrom, currentDate, finalShiftWorkTimes);
        }
        currentDate = currentDate.plusDays(1);
    }
    DateTime result = finalShiftWorkTimes.stream().min(Comparator.comparing(DateTimeRange::getFrom)).get().getFrom();
    if (result.compareTo(dateFrom) <= 0) {
        return Optional.of(dateFrom);
    }
    return Optional.of(result);
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) DateTime(org.joda.time.DateTime)

Aggregations

DateTimeRange (com.qcadoo.mes.basic.util.DateTimeRange)14 Shift (com.qcadoo.mes.basic.shift.Shift)9 DateTime (org.joda.time.DateTime)8 TimeRange (com.qcadoo.commons.dateTime.TimeRange)4 Entity (com.qcadoo.model.api.Entity)3 BigDecimal (java.math.BigDecimal)3 Date (java.util.Date)3 Interval (org.joda.time.Interval)2 Period (org.joda.time.Period)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 BasicConstants (com.qcadoo.mes.basic.constants.BasicConstants)1 ShiftFields (com.qcadoo.mes.basic.constants.ShiftFields)1 TimetableExceptionType (com.qcadoo.mes.basic.constants.TimetableExceptionType)1 DailyProgressContainer (com.qcadoo.mes.productionPerShift.domain.DailyProgressContainer)1 DailyProgressKey (com.qcadoo.mes.productionPerShift.domain.DailyProgressKey)1 ShiftEfficiencyCalculationHolder (com.qcadoo.mes.productionPerShift.domain.ShiftEfficiencyCalculationHolder)1 DataDefinition (com.qcadoo.model.api.DataDefinition)1 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)1 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)1