Search in sources :

Example 1 with OperationProductComponentWithQuantityContainer

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

the class OperationProductsExtractor method getOperationProductComponents.

private List<Entity> getOperationProductComponents(final Entity order, final Entity technologyOperationComponent) {
    List<Entity> trackingOperationProductComponents = Lists.newArrayList();
    Map<OperationProductComponentEntityType, Set<Entity>> entityTypeWithAlreadyAddedProducts = Maps.newHashMap();
    String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING);
    OperationProductComponentWithQuantityContainer productComponentQuantities = productQuantitiesService.getProductComponentQuantities(order);
    for (Entry<OperationProductComponentHolder, BigDecimal> productComponentQuantity : productComponentQuantities.asMap().entrySet()) {
        OperationProductComponentHolder operationProductComponentHolder = productComponentQuantity.getKey();
        if (forEach(typeOfProductionRecording)) {
            Entity operationComponent = operationProductComponentHolder.getTechnologyOperationComponent();
            if (technologyOperationComponent == null) {
                if (operationComponent != null) {
                    continue;
                }
            } else {
                if ((operationComponent == null) || !technologyOperationComponent.getId().equals(operationComponent.getId())) {
                    continue;
                }
            }
        } else if (cumulated(typeOfProductionRecording)) {
            OperationProductComponentEntityType entityType = operationProductComponentHolder.getEntityType();
            Entity product = operationProductComponentHolder.getProduct();
            if ((product != null) && (entityType != null)) {
                if (shouldSkipAddingProduct(operationProductComponentHolder, entityTypeWithAlreadyAddedProducts, typeOfProductionRecording)) {
                    if (entityTypeWithAlreadyAddedProducts.containsKey(entityType)) {
                        continue;
                    } else {
                        entityTypeWithAlreadyAddedProducts.put(entityType, Sets.newHashSet());
                        continue;
                    }
                } else {
                    if (entityTypeWithAlreadyAddedProducts.containsKey(entityType)) {
                        Set<Entity> alreadAddedProducts = entityTypeWithAlreadyAddedProducts.get(entityType);
                        alreadAddedProducts.add(product);
                        entityTypeWithAlreadyAddedProducts.put(entityType, alreadAddedProducts);
                    } else {
                        entityTypeWithAlreadyAddedProducts.put(entityType, Sets.newHashSet(product));
                    }
                }
            }
        }
        Entity trackingOperationProductComponent = trackingOperationComponentBuilder.fromOperationProductComponentHolder(operationProductComponentHolder);
        if (forEach(typeOfProductionRecording)) {
            Optional<Entity> mabyExist = trackingOperationProductComponents.stream().filter(toc -> toc.getBelongsToField(L_PRODUCT).getId().equals(trackingOperationProductComponent.getBelongsToField(L_PRODUCT).getId())).findAny();
            if (!mabyExist.isPresent()) {
                trackingOperationProductComponents.add(trackingOperationProductComponent);
            }
        } else {
            trackingOperationProductComponents.add(trackingOperationProductComponent);
        }
    }
    return trackingOperationProductComponents;
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) Function(com.google.common.base.Function) OperationProductComponentEntityType(com.qcadoo.mes.technologies.dto.OperationProductComponentEntityType) ProductionTrackingFields(com.qcadoo.mes.productionCounting.constants.ProductionTrackingFields) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) OrderFieldsPC(com.qcadoo.mes.productionCounting.constants.OrderFieldsPC) Multimap(com.google.common.collect.Multimap) TechnologyService(com.qcadoo.mes.technologies.TechnologyService) Maps(com.google.common.collect.Maps) OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) Sets(com.google.common.collect.Sets) Multimaps(com.google.common.collect.Multimaps) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) BigDecimal(java.math.BigDecimal) Entity(com.qcadoo.model.api.Entity) List(java.util.List) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Map(java.util.Map) Entry(java.util.Map.Entry) ProductionCountingConstants(com.qcadoo.mes.productionCounting.constants.ProductionCountingConstants) ProductQuantitiesService(com.qcadoo.mes.technologies.ProductQuantitiesService) Optional(java.util.Optional) TypeOfProductionRecording(com.qcadoo.mes.productionCounting.constants.TypeOfProductionRecording) Entity(com.qcadoo.model.api.Entity) Set(java.util.Set) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) OperationProductComponentEntityType(com.qcadoo.mes.technologies.dto.OperationProductComponentEntityType) BigDecimal(java.math.BigDecimal)

Example 2 with OperationProductComponentWithQuantityContainer

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

the class ScheduleDetailsListenersPS method getOperations.

@Transactional
public void getOperations(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    GridComponent ordersGrid = (GridComponent) view.getComponentByReference(ScheduleFields.ORDERS);
    List<Entity> orders = ordersGrid.getEntities();
    FormComponent formComponent = (FormComponent) state;
    Entity schedule = formComponent.getEntity();
    boolean includeTpz = schedule.getBooleanField(ScheduleFields.INCLUDE_TPZ);
    DataDefinition schedulePositionDD = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_SCHEDULE_POSITION);
    List<Entity> positions = Lists.newArrayList();
    for (Entity order : orders) {
        Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
        if (technology == null) {
            continue;
        }
        final Map<Long, BigDecimal> operationRuns = Maps.newHashMap();
        OperationProductComponentWithQuantityContainer operationProductComponentWithQuantityContainer = productQuantitiesService.getProductComponentQuantities(technology, order.getDecimalField(OrderFields.PLANNED_QUANTITY), operationRuns);
        List<Entity> operationComponents = technology.getHasManyField(TechnologyFields.OPERATION_COMPONENTS);
        for (Entity operationComponent : operationComponents) {
            BigDecimal operationComponentRuns = BigDecimalUtils.convertNullToZero(operationRuns.get(operationComponent.getId()));
            BigDecimal staffFactor = getStaffFactor(operationComponent);
            OperationWorkTime operationWorkTime = operationWorkTimeService.estimateTechOperationWorkTime(operationComponent, operationComponentRuns, includeTpz, false, false, staffFactor);
            Entity schedulePosition = createSchedulePosition(schedule, schedulePositionDD, order, operationComponent, operationWorkTime, operationProductComponentWithQuantityContainer, operationComponentRuns);
            positions.add(schedulePosition);
        }
    }
    schedule.setField(ScheduleFields.POSITIONS, positions);
    schedule = schedule.getDataDefinition().save(schedule);
    formComponent.setEntity(schedule);
    view.addMessage("productionScheduling.info.schedulePositionsGenerated", ComponentState.MessageType.SUCCESS);
}
Also used : Entity(com.qcadoo.model.api.Entity) FormComponent(com.qcadoo.view.api.components.FormComponent) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) OperationWorkTime(com.qcadoo.mes.operationTimeCalculations.OperationWorkTime) GridComponent(com.qcadoo.view.api.components.GridComponent) DataDefinition(com.qcadoo.model.api.DataDefinition) BigDecimal(java.math.BigDecimal) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with OperationProductComponentWithQuantityContainer

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

the class ProductQuantitiesServiceImpl method getProductComponentWithQuantitiesForTechnology.

@Override
public OperationProductComponentWithQuantityContainer getProductComponentWithQuantitiesForTechnology(final Entity technology, final Entity orderedProduct, final BigDecimal givenQuantity, final Map<Long, BigDecimal> operationRuns, final Set<OperationProductComponentHolder> nonComponents) {
    OperationProductComponentWithQuantityContainer operationProductComponentWithQuantityContainer = new OperationProductComponentWithQuantityContainer();
    operationProductComponentWithQuantityContainer.setOrderedProduct(orderedProduct);
    if (Objects.nonNull(orderedProduct)) {
        Entity size = orderedProduct.getBelongsToField(ProductFields.SIZE);
        if (Objects.nonNull(size)) {
            List<Entity> sizeGroups = size.getHasManyField(SizeFields.SIZE_GROUPS);
            if (!sizeGroups.isEmpty()) {
                operationProductComponentWithQuantityContainer.setSizeGroups(sizeGroups);
            }
        }
    }
    EntityTree operationComponents = getOperationComponentsFromTechnology(technology);
    Entity root = operationComponents.getRoot();
    if (Objects.nonNull(root)) {
        preloadProductQuantitiesAndOperationRuns(operationComponents, operationProductComponentWithQuantityContainer, operationRuns);
        traverseProductQuantitiesAndOperationRuns(technology, givenQuantity, root, null, operationProductComponentWithQuantityContainer, nonComponents, operationRuns);
    }
    return operationProductComponentWithQuantityContainer;
}
Also used : Entity(com.qcadoo.model.api.Entity) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) EntityTree(com.qcadoo.model.api.EntityTree)

Example 4 with OperationProductComponentWithQuantityContainer

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

the class ProductQuantitiesServiceImpl method getNeededProductQuantities.

private Map<Long, BigDecimal> getNeededProductQuantities(final List<Entity> orders, final MrpAlgorithm mrpAlgorithm, final Map<Long, BigDecimal> operationRuns, final boolean onTheFly) {
    Set<OperationProductComponentHolder> nonComponents = Sets.newHashSet();
    OperationProductComponentWithQuantityContainer productComponentWithQuantities = getProductComponentWithQuantitiesForOrders(orders, 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)

Example 5 with OperationProductComponentWithQuantityContainer

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

the class ProductQuantitiesServiceImpl method multiplyOperationProductComponentQuantities.

private void multiplyOperationProductComponentQuantities(final List<Entity> operationProductComponents, final BigDecimal multiplier, final OperationProductComponentWithQuantityContainer operationProductComponentWithQuantityContainer) {
    List<Entity> sizeGroups = operationProductComponentWithQuantityContainer.getSizeGroups();
    Entity orderedProduct = operationProductComponentWithQuantityContainer.getOrderedProduct();
    for (Entity operationProductComponent : operationProductComponents) {
        if (operationProductComponent.getDataDefinition().getName().equals(TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT) && operationProductComponent.getBooleanField(OperationProductInComponentFields.DIFFERENT_PRODUCTS_IN_DIFFERENT_SIZES)) {
            if (!sizeGroups.isEmpty()) {
                for (Entity sizeGroup : sizeGroups) {
                    List<Entity> productBySizeGroups = operationProductComponent.getHasManyField(OperationProductInComponentFields.PRODUCT_BY_SIZE_GROUPS).stream().filter(pG -> pG.getBelongsToField(ProductBySizeGroupFields.SIZE_GROUP).getId().equals(sizeGroup.getId())).collect(Collectors.toList());
                    for (Entity productBySizeGroup : productBySizeGroups) {
                        BigDecimal addedQuantity = operationProductComponentWithQuantityContainer.get(operationProductComponent, productBySizeGroup.getBelongsToField(ProductBySizeGroupFields.PRODUCT));
                        BigDecimal quantity = addedQuantity.multiply(multiplier, numberService.getMathContext());
                        operationProductComponentWithQuantityContainer.put(operationProductComponent, productBySizeGroup.getBelongsToField(ProductBySizeGroupFields.PRODUCT), quantity.setScale(5, RoundingMode.CEILING));
                    }
                }
            } else {
                operationProductComponentWithQuantityContainer.put(operationProductComponent, null);
            }
        } else if (Objects.nonNull(orderedProduct) && operationProductComponent.getDataDefinition().getName().equals(TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT) && 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 (!moreThanOneSpecificProduct && Objects.nonNull(specificProductId)) {
                    Entity product = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(specificProductId);
                    BigDecimal addedQuantity = operationProductComponentWithQuantityContainer.get(operationProductComponent, product);
                    BigDecimal quantity = addedQuantity.multiply(multiplier, numberService.getMathContext());
                    operationProductComponentWithQuantityContainer.put(operationProductComponent, product, quantity.setScale(5, RoundingMode.CEILING));
                }
            }
        } else {
            BigDecimal addedQuantity = operationProductComponentWithQuantityContainer.get(operationProductComponent);
            BigDecimal quantity = addedQuantity.multiply(multiplier, numberService.getMathContext());
            operationProductComponentWithQuantityContainer.put(operationProductComponent, quantity.setScale(5, RoundingMode.CEILING));
        }
    }
}
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) 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