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);
}
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;
}
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;
}
}
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());
}
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();
}
Aggregations