use of com.qcadoo.mes.basic.shift.Shift in project mes by qcadoo.
the class ShiftsServiceImpl method getShiftForNearestWorkingDate.
@Override
public Optional<Shift> getShiftForNearestWorkingDate(DateTime nearestWorkingDate, Entity productionLine) {
List<Shift> shifts = findAll(productionLine);
List<DateTimeRange> finalShiftWorkTimes = Lists.newArrayList();
DateTime currentDate = nearestWorkingDate.minusDays(1);
if (shifts.stream().noneMatch(shift -> checkShiftWorkingAfterDate(nearestWorkingDate, productionLine, shift))) {
return Optional.empty();
}
while (finalShiftWorkTimes.isEmpty()) {
for (Shift shift : shifts) {
getNearestWorkingDateForShift(shift, productionLine, nearestWorkingDate, currentDate, finalShiftWorkTimes);
if (!finalShiftWorkTimes.isEmpty()) {
shift.setShiftStartDate(nearestWorkingDate);
DateTime endDate = finalShiftWorkTimes.stream().max(Comparator.comparing(DateTimeRange::getTo)).get().getTo();
shift.setShiftEndDate(endDate);
return Optional.of(shift);
}
}
currentDate = currentDate.plusDays(1);
}
return Optional.empty();
}
use of com.qcadoo.mes.basic.shift.Shift in project mes by qcadoo.
the class ShiftsServiceImpl method getTotalAvailableTimeForProductionLine.
@Override
public long getTotalAvailableTimeForProductionLine(final Date dateFrom, final Date dateTo, final Entity productionLine) {
if (getShiftDataDefinition().find().list().getTotalNumberOfEntities() == 0) {
return (dateTo.getTime() - dateFrom.getTime()) / 1000;
}
long totalAvailableTime = 0;
List<Shift> shifts = findAll(productionLine);
DateTime dateOfDay = new DateTime(dateFrom);
int loopCount = 0;
while (!dateOfDay.isAfter(new DateTime(dateTo))) {
if (loopCount > MAX_LOOPS) {
return (dateTo.getTime() - dateFrom.getTime()) / 1000;
}
for (Shift shift : shifts) {
for (DateTimeRange range : shiftExceptionService.getShiftWorkDateTimes(productionLine, shift, dateOfDay, false)) {
totalAvailableTime += range.durationMillis();
}
}
loopCount++;
dateOfDay = dateOfDay.plusDays(1);
}
return totalAvailableTime / 1000;
}
use of com.qcadoo.mes.basic.shift.Shift in project mes by qcadoo.
the class ShiftsServiceImpl method findDateToForProductionLine.
@Override
public Date findDateToForProductionLine(final Date dateFrom, final long seconds, final Entity productionLine) {
if (getShiftDataDefinition().find().list().getTotalNumberOfEntities() == 0) {
return Date.from(dateFrom.toInstant().plusSeconds(seconds));
}
DateTime dateFromDT = new DateTime(dateFrom, DateTimeZone.getDefault());
List<Shift> shifts = findAll(productionLine);
DateTime dateOfDay = new DateTime(dateFrom);
dateOfDay = dateOfDay.minusDays(1);
dateOfDay = dateOfDay.toLocalDate().toDateTimeAtStartOfDay();
long leftMilliseconds = seconds * MILLS;
int loopCount = 0;
while (leftMilliseconds > 0L) {
if (loopCount > MAX_LOOPS) {
return Date.from(dateFrom.toInstant().plusSeconds(seconds));
}
for (Shift shift : shifts) {
for (DateTimeRange range : shiftExceptionService.getShiftWorkDateTimes(productionLine, shift, dateOfDay, true)) {
if (dateFrom.after(dateOfDay.toDate())) {
range = range.trimBefore(dateFromDT);
}
if (range != null) {
if (leftMilliseconds > range.durationMillis()) {
leftMilliseconds = leftMilliseconds - range.durationMillis();
} else {
return range.getFrom().plusMillis((int) leftMilliseconds).toDate();
}
}
}
}
loopCount++;
dateOfDay = dateOfDay.plusDays(1);
}
return Date.from(dateFrom.toInstant().plusSeconds(seconds));
}
use of com.qcadoo.mes.basic.shift.Shift in project mes by qcadoo.
the class OrderRealizationDaysResolverTest method shouldProduceStreamOfRealizationDays2.
@Test
public final void shouldProduceStreamOfRealizationDays2() {
// given
DateTime startDate = new DateTime(2014, 8, 14, 14, 0, 0);
List<Shift> shifts = ImmutableList.of(shift1, shift2, shift3);
// when
LazyStream<OrderRealizationDay> stream = orderRealizationDaysResolver.asStreamFrom(startDate, shifts);
// then
OrderRealizationDay[] streamVals = FluentIterable.from(stream).limit(5).toArray(OrderRealizationDay.class);
assertRealizationDayState(streamVals[0], 1, startDate.toLocalDate(), shifts);
assertRealizationDayState(streamVals[1], 2, startDate.toLocalDate().plusDays(1), shifts);
assertRealizationDayState(streamVals[2], 5, startDate.toLocalDate().plusDays(4), shifts);
assertRealizationDayState(streamVals[3], 6, startDate.toLocalDate().plusDays(5), shifts);
assertRealizationDayState(streamVals[4], 7, startDate.toLocalDate().plusDays(6), shifts);
}
use of com.qcadoo.mes.basic.shift.Shift in project mes by qcadoo.
the class OrderRealizationDaysResolverTest method shouldResolveRealizationDay3.
@Test
public final void shouldResolveRealizationDay3() {
// given
DateTime startDate = new DateTime(2014, 8, 14, 3, 0, 0);
List<Shift> shifts = ImmutableList.of(shift1, shift2, shift3);
// when
// - 1st order realization day is Thursday,
// - shift working at given time doesn't work at this date but it's not a first day of order realization,
OrderRealizationDay realizationDay = orderRealizationDaysResolver.find(startDate, 1, false, shifts);
// then
assertRealizationDayState(realizationDay, 1, startDate.toLocalDate(), shifts);
}
Aggregations