Search in sources :

Example 6 with OperationProductComponentWithQuantityContainer

use of com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer in project mes by qcadoo.

the class ProductQuantitiesServiceImpl method getProductComponentWithQuantitiesForOrders.

private OperationProductComponentWithQuantityContainer getProductComponentWithQuantitiesForOrders(final List<Entity> orders, final Map<Long, BigDecimal> operationRuns, final Set<OperationProductComponentHolder> nonComponents, final boolean onTheFly) {
    Map<Long, OperationProductComponentWithQuantityContainer> productComponentWithQuantitiesForOrders = Maps.newHashMap();
    for (Entity order : orders) {
        BigDecimal plannedQuantity = order.getDecimalField(L_PLANNED_QUANTITY);
        Entity technology = order.getBelongsToField(L_TECHNOLOGY);
        if (Objects.isNull(technology)) {
            throw new IllegalStateException("Order doesn't contain technology.");
        }
        productComponentWithQuantitiesForOrders.put(order.getId(), getProductComponentWithQuantitiesForTechnology(technology, null, plannedQuantity, operationRuns, nonComponents));
    }
    return groupOperationProductComponentWithQuantities(productComponentWithQuantitiesForOrders);
}
Also used : Entity(com.qcadoo.model.api.Entity) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) BigDecimal(java.math.BigDecimal)

Example 7 with OperationProductComponentWithQuantityContainer

use of com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer in project mes by qcadoo.

the class ProductQuantitiesServiceImpl method getProductComponentQuantities.

@Override
public ProductQuantitiesHolder getProductComponentQuantities(final Entity technology, final BigDecimal givenQuantity) {
    Map<Long, BigDecimal> operationRuns = Maps.newHashMap();
    OperationProductComponentWithQuantityContainer productQuantities = getProductComponentQuantities(technology, givenQuantity, operationRuns);
    return new ProductQuantitiesHolder(productQuantities, operationRuns);
}
Also used : OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) ProductQuantitiesHolder(com.qcadoo.mes.technologies.dto.ProductQuantitiesHolder) BigDecimal(java.math.BigDecimal)

Example 8 with OperationProductComponentWithQuantityContainer

use of com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer in project mes by qcadoo.

the class ProductQuantitiesServiceImpl method groupOperationProductComponentWithQuantities.

@Override
public OperationProductComponentWithQuantityContainer groupOperationProductComponentWithQuantities(final Map<Long, OperationProductComponentWithQuantityContainer> operationProductComponentWithQuantityContainerForOrders) {
    OperationProductComponentWithQuantityContainer operationProductComponentWithQuantityContainer = new OperationProductComponentWithQuantityContainer();
    for (Entry<Long, OperationProductComponentWithQuantityContainer> operationProductComponentWithQuantityContainerForOrder : operationProductComponentWithQuantityContainerForOrders.entrySet()) {
        operationProductComponentWithQuantityContainer.getMessages().addAll(operationProductComponentWithQuantityContainerForOrder.getValue().getMessages());
        for (Entry<OperationProductComponentHolder, BigDecimal> productComponentWithQuantity : operationProductComponentWithQuantityContainerForOrder.getValue().asMap().entrySet()) {
            OperationProductComponentHolder operationProductComponentHolder = productComponentWithQuantity.getKey();
            BigDecimal quantity = productComponentWithQuantity.getValue();
            if (operationProductComponentWithQuantityContainer.containsKey(operationProductComponentHolder)) {
                BigDecimal addedQuantity = operationProductComponentWithQuantityContainer.get(operationProductComponentHolder);
                quantity = quantity.add(addedQuantity, numberService.getMathContext());
            }
            operationProductComponentWithQuantityContainer.put(operationProductComponentHolder, quantity);
        }
    }
    return operationProductComponentWithQuantityContainer;
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) BigDecimal(java.math.BigDecimal)

Example 9 with OperationProductComponentWithQuantityContainer

use of com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer in project mes by qcadoo.

the class ProductQuantitiesServiceImpl method getNeededProductQuantitiesForComponents.

private Map<Long, BigDecimal> getNeededProductQuantitiesForComponents(final List<Entity> components, final MrpAlgorithm mrpAlgorithm, final boolean onTheFly) {
    Map<Long, BigDecimal> operationRuns = Maps.newHashMap();
    Set<OperationProductComponentHolder> nonComponents = Sets.newHashSet();
    OperationProductComponentWithQuantityContainer productComponentWithQuantities = getProductComponentWithQuantitiesForOrders(getOrdersFromComponents(components), operationRuns, nonComponents, onTheFly);
    return getProductWithQuantities(productComponentWithQuantities, nonComponents, mrpAlgorithm, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) BigDecimal(java.math.BigDecimal)

Example 10 with OperationProductComponentWithQuantityContainer

use of com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer in project mes by qcadoo.

the class ProductQuantitiesServiceImpl method preloadOperationProductComponentQuantity.

@Override
public void preloadOperationProductComponentQuantity(final List<Entity> operationProductComponents, final OperationProductComponentWithQuantityContainer operationProductComponentWithQuantityContainer) {
    for (Entity operationProductComponent : operationProductComponents) {
        BigDecimal neededQuantity = operationProductComponent.getDecimalField(L_QUANTITY);
        if (operationProductComponent.getDataDefinition().getName().equals(TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT) && operationProductComponent.getBooleanField(OperationProductInComponentFields.DIFFERENT_PRODUCTS_IN_DIFFERENT_SIZES) && !operationProductComponentWithQuantityContainer.getSizeGroups().isEmpty()) {
            for (Entity sizeGroup : operationProductComponentWithQuantityContainer.getSizeGroups()) {
                List<Entity> productsByGroup = operationProductComponent.getHasManyField(OperationProductInComponentFields.PRODUCT_BY_SIZE_GROUPS).stream().filter(pG -> pG.getBelongsToField(ProductBySizeGroupFields.SIZE_GROUP).getId().equals(sizeGroup.getId())).collect(Collectors.toList());
                for (Entity productByGroup : productsByGroup) {
                    operationProductComponentWithQuantityContainer.put(operationProductComponent, productByGroup.getBelongsToField(ProductBySizeGroupFields.PRODUCT), productByGroup.getDecimalField(ProductBySizeGroupFields.QUANTITY));
                }
            }
        } else if (Objects.nonNull(operationProductComponentWithQuantityContainer.getOrderedProduct()) && operationProductComponent.getDataDefinition().getName().equals(TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT) && Objects.nonNull(getOperationProductProduct(operationProductComponent)) && ProductFamilyElementType.PRODUCTS_FAMILY.getStringValue().equals(getOperationProductProduct(operationProductComponent).getField(ProductFields.ENTITY_TYPE)) && Objects.nonNull(operationProductComponent.getBelongsToField(OperationProductInComponentFields.ATTRIBUTE))) {
            Entity attribute = operationProductComponent.getBelongsToField(OperationProductInComponentFields.ATTRIBUTE);
            List<Entity> attributeValues = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.PRODUCT_ATTRIBUTE_VALUE).find().add(SearchRestrictions.belongsTo(ProductAttributeValueFields.PRODUCT, operationProductComponentWithQuantityContainer.getOrderedProduct())).add(SearchRestrictions.belongsTo(ProductAttributeValueFields.ATTRIBUTE, attribute)).list().getEntities();
            Entity opicProduct = getOperationProductProduct(operationProductComponent);
            if (!attributeValues.isEmpty()) {
                Collection<Long> attributeValuesId = attributeValues.stream().map(av -> av.getBelongsToField(ProductAttributeValueFields.ATTRIBUTE_VALUE).getId()).collect(Collectors.toList());
                List<Entity> allProductAttributeValues = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.PRODUCT_ATTRIBUTE_VALUE).find().createAlias(ProductAttributeValueFields.PRODUCT, "prod", JoinType.LEFT).createAlias("prod.parent", "parentProduct", JoinType.LEFT).add(SearchRestrictions.eq("parentProduct.id", opicProduct.getId())).list().getEntities();
                Map<Long, List<Entity>> attributeValuesByProduct = allProductAttributeValues.stream().collect(groupingBy(e -> e.getBelongsToField(ProductAttributeValueFields.PRODUCT).getId()));
                Long specificProductId = null;
                boolean moreThanOneSpecificProduct = false;
                for (Entry<Long, List<Entity>> entry : attributeValuesByProduct.entrySet()) {
                    Long productId = entry.getKey();
                    List<Entity> attrValues = entry.getValue();
                    Collection<Long> allProductAttributeValuesId = attrValues.stream().filter(av -> Objects.nonNull(av.getBelongsToField(ProductAttributeValueFields.ATTRIBUTE_VALUE))).map(av -> av.getBelongsToField(ProductAttributeValueFields.ATTRIBUTE_VALUE).getId()).collect(Collectors.toList());
                    boolean hasNotCalculatedElements = attrValues.stream().anyMatch(av -> Objects.isNull(av.getBelongsToField(ProductAttributeValueFields.ATTRIBUTE_VALUE)));
                    boolean isSame = attributeValuesId.stream().allMatch(a -> allProductAttributeValuesId.stream().anyMatch(b -> b.equals(a)));
                    if (isSame && !hasNotCalculatedElements && attributeValuesId.size() == allProductAttributeValuesId.size()) {
                        if (Objects.nonNull(specificProductId)) {
                            moreThanOneSpecificProduct = true;
                            break;
                        }
                        specificProductId = productId;
                    }
                }
                if (Objects.isNull(specificProductId)) {
                    Entity toc = operationProductComponent.getBelongsToField(OperationProductInComponentFields.OPERATION_COMPONENT);
                    Entity operation = toc.getBelongsToField(TechnologyOperationComponentFields.OPERATION);
                    OperationProductComponentMessage message = new OperationProductComponentMessage();
                    message.setMessage("basicProductionCounting.productionCountingQuantity.error.couldNotFindSpecificProductWithMatchingAttributeValue");
                    message.setOperationNumber(operation.getStringField(OperationFields.NUMBER));
                    message.setProductNumber(opicProduct.getStringField(ProductFields.NUMBER));
                    message.setNodeNumber(toc.getStringField(TechnologyOperationComponentFields.NODE_NUMBER));
                    message.setAttributeNumber(attribute.getStringField(AttributeFields.NUMBER));
                    message.setAttributeValue(attributeValues.stream().map(a -> a.getStringField(ProductAttributeValueFields.VALUE)).collect(Collectors.joining(", ")));
                    operationProductComponentWithQuantityContainer.addMessage(message);
                } else if (moreThanOneSpecificProduct) {
                    Entity toc = operationProductComponent.getBelongsToField(OperationProductInComponentFields.OPERATION_COMPONENT);
                    Entity operation = toc.getBelongsToField(TechnologyOperationComponentFields.OPERATION);
                    OperationProductComponentMessage message = new OperationProductComponentMessage();
                    message.setMessage("basicProductionCounting.productionCountingQuantity.error.toManyProductsWithMatchingAttributeValue");
                    message.setOperationNumber(operation.getStringField(OperationFields.NUMBER));
                    message.setProductNumber(opicProduct.getStringField(ProductFields.NUMBER));
                    message.setNodeNumber(toc.getStringField(TechnologyOperationComponentFields.NODE_NUMBER));
                    message.setAttributeNumber(attribute.getStringField(AttributeFields.NUMBER));
                    message.setAttributeValue(attributeValues.stream().map(a -> a.getStringField(ProductAttributeValueFields.VALUE)).collect(Collectors.joining(", ")));
                    operationProductComponentWithQuantityContainer.addMessage(message);
                } else {
                    Entity product = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(specificProductId);
                    operationProductComponentWithQuantityContainer.put(operationProductComponent, product, operationProductComponent.getDecimalField(ProductBySizeGroupFields.QUANTITY));
                }
            } else {
                Entity toc = operationProductComponent.getBelongsToField(OperationProductInComponentFields.OPERATION_COMPONENT);
                Entity operation = toc.getBelongsToField(TechnologyOperationComponentFields.OPERATION);
                OperationProductComponentMessage message = new OperationProductComponentMessage();
                message.setMessage("basicProductionCounting.productionCountingQuantity.error.orderedProductDoesNotHaveAttribute");
                message.setOperationNumber(operation.getStringField(OperationFields.NUMBER));
                message.setProductNumber(opicProduct.getStringField(ProductFields.NUMBER));
                message.setNodeNumber(toc.getStringField(TechnologyOperationComponentFields.NODE_NUMBER));
                message.setAttributeNumber(attribute.getStringField(AttributeFields.NUMBER));
                operationProductComponentWithQuantityContainer.addMessage(message);
            }
        } else {
            operationProductComponentWithQuantityContainer.put(operationProductComponent, neededQuantity);
        }
    }
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) java.util(java.util) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) ProductQuantitiesHolder(com.qcadoo.mes.technologies.dto.ProductQuantitiesHolder) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Autowired(org.springframework.beans.factory.annotation.Autowired) Maps(com.google.common.collect.Maps) OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityTree(com.qcadoo.model.api.EntityTree) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) OperationProductComponentMessage(com.qcadoo.mes.technologies.dto.OperationProductComponentMessage) JoinType(com.qcadoo.model.api.search.JoinType) BigDecimal(java.math.BigDecimal) com.qcadoo.mes.technologies.constants(com.qcadoo.mes.technologies.constants) Entity(com.qcadoo.model.api.Entity) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) NumberService(com.qcadoo.model.api.NumberService) com.qcadoo.mes.basic.constants(com.qcadoo.mes.basic.constants) Entry(java.util.Map.Entry) RoundingMode(java.math.RoundingMode) Entity(com.qcadoo.model.api.Entity) Entry(java.util.Map.Entry) OperationProductComponentMessage(com.qcadoo.mes.technologies.dto.OperationProductComponentMessage) BigDecimal(java.math.BigDecimal)

Aggregations

OperationProductComponentWithQuantityContainer (com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer)31 BigDecimal (java.math.BigDecimal)26 Entity (com.qcadoo.model.api.Entity)18 OperationProductComponentHolder (com.qcadoo.mes.technologies.dto.OperationProductComponentHolder)16 EntityTree (com.qcadoo.model.api.EntityTree)5 ProductQuantitiesHolder (com.qcadoo.mes.technologies.dto.ProductQuantitiesHolder)4 Lists (com.google.common.collect.Lists)3 Maps (com.google.common.collect.Maps)3 Sets (com.google.common.collect.Sets)3 DataDefinition (com.qcadoo.model.api.DataDefinition)3 Map (java.util.Map)3 Entry (java.util.Map.Entry)3 Test (org.junit.Test)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Service (org.springframework.stereotype.Service)3 Transactional (org.springframework.transaction.annotation.Transactional)3 com.qcadoo.mes.basic.constants (com.qcadoo.mes.basic.constants)2 com.qcadoo.mes.technologies.constants (com.qcadoo.mes.technologies.constants)2 OperationProductComponentEntityType (com.qcadoo.mes.technologies.dto.OperationProductComponentEntityType)2 OperationProductComponentMessage (com.qcadoo.mes.technologies.dto.OperationProductComponentMessage)2