Search in sources :

Example 11 with ErrorMessage

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;
}
Also used : Entity(com.qcadoo.model.api.Entity) ProductionLineResponse(com.qcadoo.mes.productionLines.controller.dataProvider.ProductionLineResponse) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with ErrorMessage

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);
}
Also used : Entity(com.qcadoo.model.api.Entity) ProgressForDaysContainer(com.qcadoo.mes.productionPerShift.domain.ProgressForDaysContainer) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Example 13 with ErrorMessage

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);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) ProgressForDaysContainer(com.qcadoo.mes.productionPerShift.domain.ProgressForDaysContainer) PpsMessage(com.qcadoo.mes.productionPerShift.domain.PpsMessage) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) Date(java.util.Date)

Example 14 with ErrorMessage

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();
}
Also used : Entity(com.qcadoo.model.api.Entity) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) BigDecimal(java.math.BigDecimal)

Example 15 with ErrorMessage

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;
}
Also used : ShiftEfficiencyCalculationHolder(com.qcadoo.mes.productionPerShift.domain.ShiftEfficiencyCalculationHolder) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) BigDecimal(java.math.BigDecimal)

Aggregations

ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)50 Entity (com.qcadoo.model.api.Entity)30 BigDecimal (java.math.BigDecimal)11 Test (org.junit.Test)11 Transactional (org.springframework.transaction.annotation.Transactional)8 Map (java.util.Map)7 DataDefinition (com.qcadoo.model.api.DataDefinition)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 FormComponent (com.qcadoo.view.api.components.FormComponent)5 TranslationService (com.qcadoo.localization.api.TranslationService)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 LocaleContextHolder (org.springframework.context.i18n.LocaleContextHolder)4 Lists (com.google.common.collect.Lists)3 OrderFields (com.qcadoo.mes.orders.constants.OrderFields)3 ProductFlowThruDivisionConstants (com.qcadoo.mes.productFlowThruDivision.constants.ProductFlowThruDivisionConstants)3 WarehouseIssueParameterService (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.WarehouseIssueParameterService)3 ProductsToIssueFields (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.ProductsToIssueFields)3 WarehouseIssueFields (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.WarehouseIssueFields)3 StateChangeContext (com.qcadoo.mes.states.StateChangeContext)3