use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class ProductionLinesApiController method saveProduct.
@ResponseBody
@RequestMapping(value = "/productionLine", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ProductionLineResponse saveProduct(@RequestBody ProductionLineRequest productionLine) {
Entity productionLineEntity = dataDefinitionService.get(ProductionLinesConstants.PLUGIN_IDENTIFIER, ProductionLinesConstants.MODEL_PRODUCTION_LINE).create();
productionLineEntity.setField(ProductionLineFields.NUMBER, productionLine.getNumber());
productionLineEntity.setField(ProductionLineFields.NAME, productionLine.getName());
productionLineEntity.setField(ProductionLineFields.PRODUCTION, Boolean.TRUE);
productionLineEntity.setField(ProductionLineFields.QUANTITY_FOR_OTHER_WORKSTATION_TYPES, 1);
productionLineEntity.setField(ProductionLineFields.SHIFTS, shiftsService.getShifts());
productionLineEntity = productionLineEntity.getDataDefinition().save(productionLineEntity);
if (productionLineEntity.isValid()) {
ProductionLineResponse productionLineResponse = new ProductionLineResponse(ProductionLineResponse.StatusCode.OK);
productionLineResponse.setId(productionLineEntity.getId());
productionLineResponse.setNumber(productionLine.getNumber());
productionLineResponse.setName(productionLine.getName());
return productionLineResponse;
} else {
//
ErrorMessage numberError = productionLineEntity.getError(ProductionLineFields.NUMBER);
if (Objects.nonNull(numberError) && numberError.getMessage().equals("qcadooView.validate.field.error.duplicated")) {
ProductionLineResponse response = new ProductionLineResponse(ProductionLineResponse.StatusCode.ERROR);
response.setMessage(translationService.translate("basic.dashboard.orderDefinitionWizard.error.validationError.productionLineDuplicated", LocaleContextHolder.getLocale()));
return response;
}
}
ProductionLineResponse response = new ProductionLineResponse(ProductionLineResponse.StatusCode.ERROR);
response.setMessage(translationService.translate("basic.dashboard.orderDefinitionWizard.error.validationError.productionLineErrors", LocaleContextHolder.getLocale()));
return response;
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class OrderHooksPPS method regenerateProductionPerShift.
public void regenerateProductionPerShift(final DataDefinition orderDD, final Entity order) {
if (order.getId() == null) {
return;
}
Entity orderFromDB = orderDD.get(order.getId());
Entity productionPerShift = dataDefinitionService.get(ProductionPerShiftConstants.PLUGIN_IDENTIFIER, ProductionPerShiftConstants.MODEL_PRODUCTION_PER_SHIFT).find().add(SearchRestrictions.belongsTo(ProductionPerShiftFields.ORDER, order)).setMaxResults(1).uniqueResult();
boolean generate = canGenerate(order, orderFromDB, productionPerShift);
if (isOrderFieldsChanged(order, orderFromDB) || generate) {
if (productionPerShift != null && automaticPpsParametersService.isAutomaticPlanForShiftOn()) {
boolean shouldBeCorrected = OrderState.of(order).compareTo(OrderState.PENDING) != 0;
if (!productionPerShift.getHasManyField(ProductionPerShiftFields.PROGRES_FOR_DAYS).isEmpty() || generate) {
BigDecimal plannedQuantity = order.getDecimalField(OrderFields.PLANNED_QUANTITY);
if (order.getBooleanField(OrderFields.FINAL_PRODUCTION_TRACKING)) {
plannedQuantity = basicProductionCountingService.getProducedQuantityFromBasicProductionCountings(order);
}
ProgressForDaysContainer progressForDaysContainer = new ProgressForDaysContainer();
progressForDaysContainer.setShouldBeCorrected(shouldBeCorrected);
progressForDaysContainer.setOrder(order);
try {
automaticPpsExecutorService.generateProgressForDays(progressForDaysContainer, productionPerShift);
} catch (Exception ex) {
for (ErrorMessage errorMessage : progressForDaysContainer.getErrors()) {
order.addGlobalError(errorMessage.getMessage(), false, errorMessage.getVars());
}
return;
}
List<Entity> progressForDays = progressForDaysContainer.getProgressForDays();
if (progressForDaysContainer.isCalculationError()) {
productionPerShift.getGlobalErrors().forEach(error -> order.addGlobalError(error.getMessage(), false, error.getVars()));
return;
}
if (!progressForDaysContainer.isPartCalculation()) {
Date finishDate = ppsTimeHelper.calculateOrderFinishDate(order, progressForDays);
order.setField(OrderFields.FINISH_DATE, finishDate);
if (shouldBeCorrected) {
order.setField(OrderFields.CORRECTED_DATE_TO, finishDate);
} else {
order.setField(OrderFields.DATE_TO, finishDate);
}
}
productionPerShift.setField(ProductionPerShiftFields.PLANNED_PROGRESS_TYPE, "01planned");
if (shouldBeCorrected) {
productionPerShift.setField(ProductionPerShiftFields.PLANNED_PROGRESS_TYPE, "02corrected");
progressForDays.addAll(productionPerShift.getHasManyField(ProductionPerShiftFields.PROGRES_FOR_DAYS).stream().filter(progressForDay -> !progressForDay.getBooleanField(ProgressForDayFields.CORRECTED)).collect(Collectors.toList()));
}
productionPerShift.setField(ProductionPerShiftFields.PROGRES_FOR_DAYS, progressForDays);
productionPerShift.getDataDefinition().save(productionPerShift);
}
}
}
updateOrderData(order);
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class ProductionPerShiftListeners method generateProgressForDays.
public void generateProgressForDays(final ViewDefinitionState view, final ComponentState componentState, final String[] args) {
if (!automaticPpsParametersService.isAutomaticPlanForShiftOn()) {
view.addMessage(new ErrorMessage("productionPerShift.automaticAlgorithm.error.ppsOff", false));
return;
}
FormComponent productionPerShiftForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
AwesomeDynamicListComponent progressForDaysComponent = (AwesomeDynamicListComponent) view.getComponentByReference("progressForDays");
Entity productionPerShift = productionPerShiftForm.getPersistedEntityWithIncludedFormValues();
ProgressForDaysContainer progressForDaysContainer = new ProgressForDaysContainer();
try {
automaticPpsExecutorService.generateProgressForDays(progressForDaysContainer, productionPerShift);
} catch (Exception ex) {
for (ErrorMessage errorMessage : progressForDaysContainer.getErrors()) {
view.addMessage(errorMessage.getMessage(), ComponentState.MessageType.FAILURE, false, errorMessage.getVars());
}
if (progressForDaysContainer.getErrors().isEmpty()) {
LOG.error("PPS generation error ", ex);
throw new IllegalStateException();
}
return;
}
List<Entity> progressForDays = progressForDaysContainer.getProgressForDays();
Entity order = productionPerShift.getBelongsToField(ProductionPerShiftFields.ORDER);
Entity product = order.getBelongsToField(OrderFields.PRODUCT);
if (progressForDaysContainer.isCalculationError()) {
productionPerShift.getGlobalErrors().forEach(error -> view.addMessage(error.getMessage(), ComponentState.MessageType.FAILURE, false, error.getVars()));
} else if (progressForDaysContainer.isPartCalculation()) {
productionPerShiftForm.setEntity(productionPerShift);
String unit = null;
if (product != null) {
unit = product.getStringField(ProductFields.UNIT);
}
progressForDaysComponent.setFieldValue(progressForDays);
fillUnit(progressForDaysComponent, unit);
for (PpsMessage message : progressForDaysContainer.getMessages()) {
view.addMessage(message.getMessage(), message.getType(), false, message.getVars());
}
updateProgressForDays(view, componentState, args);
} else {
Date orderFinishDate = ppsTimeHelper.calculateOrderFinishDate(order, progressForDays);
productionPerShift.setField(ProductionPerShiftFields.ORDER_FINISH_DATE, orderFinishDate);
productionPerShiftForm.setEntity(productionPerShift);
String unit = null;
if (product != null) {
unit = product.getStringField(ProductFields.UNIT);
}
progressForDaysComponent.setFieldValue(progressForDays);
fillUnit(progressForDaysComponent, unit);
updateProgressForDays(view, componentState, args);
}
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class PpsTechNormAndWorkersAlgorithmService method getStandardPerformanceNorm.
protected BigDecimal getStandardPerformanceNorm(ProgressForDaysContainer progressForDaysContainer, Entity order) {
Optional<BigDecimal> norm = Optional.empty();
Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE);
if (productionLine != null) {
Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY).getDataDefinition().get(order.getBelongsToField(OrderFields.TECHNOLOGY).getId());
norm = technologyService.getStandardPerformance(technology, productionLine);
}
if (!norm.isPresent()) {
progressForDaysContainer.addError(new ErrorMessage("productionPerShift.automaticAlgorithm.technology.standardPerformanceTechnologyRequired", false));
throw new IllegalStateException("No standard performance norm in technology");
}
return norm.get();
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class PpsTechNormAndWorkersAlgorithmService method calculateShiftEfficiency.
@Override
protected ShiftEfficiencyCalculationHolder calculateShiftEfficiency(ProgressForDaysContainer progressForDaysContainer, Entity productionPerShift, Shift shift, Entity order, DateTimeRange range, BigDecimal shiftEfficiency, int progressForDayQuantity, boolean allowIncompleteUnits) {
ShiftEfficiencyCalculationHolder calculationHolder = new ShiftEfficiencyCalculationHolder();
int workersOnLine = workersOnLineService.getWorkersOnLine(order.getBelongsToField(OrderFields.PRODUCTION_LINE), shift.getEntity(), range.getFrom());
if (workersOnLine == 0) {
progressForDaysContainer.addError(new ErrorMessage("productionPerShift.automaticAlgorithm.noAssignmentForShift", false, order.getBelongsToField(OrderFields.PRODUCTION_LINE).getStringField(ProductionLineFields.NUMBER)));
throw new IllegalStateException("No assignment for shift");
}
BigDecimal scaledNorm = getStandardPerformanceNorm(progressForDaysContainer, order);
Long minuets = range.durationInMins();
BigDecimal efficiencyForRange = calculateEfficiencyForRange(scaledNorm, workersOnLine, minuets, allowIncompleteUnits);
shiftEfficiency = shiftEfficiency.add(efficiencyForRange, numberService.getMathContext());
calculationHolder.setShiftEfficiency(shiftEfficiency);
if (shiftEfficiency.compareTo(progressForDaysContainer.getPlannedQuantity()) > 0) {
calculateEfficiencyTime(calculationHolder, progressForDaysContainer.getPlannedQuantity(), workersOnLine, scaledNorm);
} else {
calculateEfficiencyTime(calculationHolder, shiftEfficiency, workersOnLine, scaledNorm);
}
return calculationHolder;
}
Aggregations