Search in sources :

Example 11 with TimeRange

use of com.qcadoo.commons.dateTime.TimeRange in project mes by qcadoo.

the class ShiftsServiceImpl method getNearestWorkingDateForShift.

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(), true);
    workTimes = workTimes.stream().filter(workTime -> workTime.contains(dateFrom) || workTime.isAfter(dateFrom)).collect(Collectors.toList());
    finalShiftWorkTimes.addAll(workTimes);
}
Also used : DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) TimeRange(com.qcadoo.commons.dateTime.TimeRange) DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange)

Example 12 with TimeRange

use of com.qcadoo.commons.dateTime.TimeRange in project mes by qcadoo.

the class WorkingHours method parseIntervals.

private Set<TimeRange> parseIntervals(final String hoursRanges) {
    if (StringUtils.isBlank(hoursRanges)) {
        return Collections.emptySet();
    }
    String trimmedHoursRanges = StringUtils.remove(hoursRanges, ' ');
    if (!WORKING_HOURS_PATTERN.matcher(trimmedHoursRanges).matches()) {
        throw new IllegalArgumentException(String.format("Invalid shift's work time definition format: %s", hoursRanges));
    }
    final Set<TimeRange> intervals = Sets.newHashSet();
    for (String hoursRange : StringUtils.split(trimmedHoursRanges, ',')) {
        TimeRange interval = stringToInterval(hoursRange);
        if (interval != null) {
            intervals.add(interval);
        }
    }
    return intervals;
}
Also used : TimeRange(com.qcadoo.commons.dateTime.TimeRange)

Example 13 with TimeRange

use of com.qcadoo.commons.dateTime.TimeRange in project mes by qcadoo.

the class Shift method getShiftDates.

private void getShiftDates(DateTime day) {
    DateTime dateTime = day.withTimeAtStartOfDay();
    Optional<TimeRange> orange = findWorkTimeAt(dateTime.getDayOfWeek());
    if (orange.isPresent()) {
        TimeRange range = orange.get();
        shiftStartDate = dateTime;
        shiftStartDate = shiftStartDate.withHourOfDay(range.getFrom().getHourOfDay());
        shiftStartDate = shiftStartDate.withMinuteOfHour(range.getFrom().getMinuteOfHour());
        shiftEndDate = dateTime;
        shiftEndDate = shiftEndDate.withHourOfDay(range.getTo().getHourOfDay());
        shiftEndDate = shiftEndDate.withMinuteOfHour(range.getTo().getMinuteOfHour());
        if (shiftStartDate.isAfter(shiftEndDate)) {
            shiftEndDate = shiftEndDate.plusDays(1);
        }
    } else {
        shiftStartDate = null;
        shiftEndDate = null;
    }
}
Also used : TimeRange(com.qcadoo.commons.dateTime.TimeRange) DateTime(org.joda.time.DateTime)

Example 14 with TimeRange

use of com.qcadoo.commons.dateTime.TimeRange in project mes by qcadoo.

the class OrderRealizationDaysResolverTest method shouldNotResultInAnInfiniteCycleIfShiftsNeverWorks.

@Test
public final void shouldNotResultInAnInfiniteCycleIfShiftsNeverWorks() {
    // given
    DateTime startDate = new DateTime(2014, 8, 14, 3, 0, 0);
    Shift lazyShift = mockShift(new TimeRange(SH_1_START, SH_1_END), ImmutableSet.<Integer>of());
    List<Shift> shifts = ImmutableList.of(lazyShift);
    // when
    OrderRealizationDay realizationDay = orderRealizationDaysResolver.find(startDate, 1, true, shifts);
    // then
    assertRealizationDayState(realizationDay, 1, startDate.toLocalDate(), ImmutableList.<Shift>of());
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) TimeRange(com.qcadoo.commons.dateTime.TimeRange) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 15 with TimeRange

use of com.qcadoo.commons.dateTime.TimeRange in project mes by qcadoo.

the class PPSReportXlsHelper method getProductionPerShiftForReport.

public List<Entity> getProductionPerShiftForReport(final Entity goodFoodReport) {
    List<Entity> shifts = shiftsService.getShifts();
    DateTime dateFrom = new DateTime(goodFoodReport.getDateField(PPSReportFields.DATE_FROM));
    Shift shiftFirst = new Shift(shifts.get(0), dateFrom, false);
    List<TimeRange> ranges = shiftFirst.findWorkTimeAt(dateFrom.toLocalDate());
    LocalTime startTime = ranges.get(0).getFrom();
    DateTime firstStartShitTime = dateFrom;
    firstStartShitTime = firstStartShitTime.withHourOfDay(startTime.getHourOfDay());
    firstStartShitTime = firstStartShitTime.withMinuteOfHour(startTime.getMinuteOfHour());
    long dateToInMills = getDateToInMills(goodFoodReport, shifts);
    String sql = "select pps from #productionPerShift_productionPerShift as pps where (" + "(" + "('" + firstStartShitTime.toDate().toString() + "' <= pps.order.finishDate and '" + firstStartShitTime.toDate().toString() + "' >= pps.order.startDate) or " + "('" + new Date(dateToInMills).toString().toString() + "' < pps.order.finishDate and '" + new Date(dateToInMills).toString().toString() + "' > pps.order.startDate)" + ") or " + "(" + "(pps.order.startDate >= '" + firstStartShitTime.toDate().toString() + "' and pps.order.startDate <'" + new Date(dateToInMills).toString().toString() + "') or " + "(pps.order.finishDate >= '" + firstStartShitTime.toDate().toString() + "' and pps.order.finishDate < '" + new Date(dateToInMills).toString().toString() + "') " + ")" + ") and pps.order.state <> '05declined' and pps.order.state <> '07abandoned'  " + "and pps.order.state <> '04completed' and pps.order.active = true";
    return dataDefinitionService.get(ProductionPerShiftConstants.PLUGIN_IDENTIFIER, ProductionPerShiftConstants.MODEL_PRODUCTION_PER_SHIFT).find(sql).list().getEntities();
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) Entity(com.qcadoo.model.api.Entity) TimeRange(com.qcadoo.commons.dateTime.TimeRange) LocalTime(org.joda.time.LocalTime) DateTime(org.joda.time.DateTime) Date(java.util.Date)

Aggregations

TimeRange (com.qcadoo.commons.dateTime.TimeRange)19 DateTime (org.joda.time.DateTime)12 LocalTime (org.joda.time.LocalTime)12 Shift (com.qcadoo.mes.basic.shift.Shift)10 Entity (com.qcadoo.model.api.Entity)6 LocalDate (org.joda.time.LocalDate)5 DateTimeRange (com.qcadoo.mes.basic.util.DateTimeRange)4 Date (java.util.Date)4 Test (org.junit.Test)4 Lists (com.google.common.collect.Lists)2 Calendar (java.util.Calendar)2 Collections (java.util.Collections)2 List (java.util.List)2 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)2 Service (org.springframework.stereotype.Service)2 Function (com.google.common.base.Function)1 Optional (com.google.common.base.Optional)1 FluentIterable (com.google.common.collect.FluentIterable)1 Maps (com.google.common.collect.Maps)1 FluentOptional (com.qcadoo.commons.functional.FluentOptional)1