Search in sources :

Example 16 with OperationProductComponentWithQuantityContainer

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

the class MaterialRequirementCoverageForOrderServiceImpl method estimateProductDemandInTime.

private void estimateProductDemandInTime(final Map<Long, Entity> productAndCoverageProducts, final List<Entity> orders, final Date coverageToDate, final Entity coveredOrder) {
    for (Entity order : orders) {
        String coveredOrdersProductsSql = "select toc.id as tocId, parentToc.id as parentId, inputProd.id as prodId, opic.id as opicId, " + "(select count(*) from #technologies_technology t where t.product = inputProd and t.master = true) " + "as prodTechId from  #technologies_operationProductInComponent opic " + "left join opic.product as inputProd left join opic.operationComponent toc " + "left join toc.operation operation left join toc.operationProductOutComponents opoc " + "left join opoc.product outputProd left join toc.technology tech " + "left join toc.parent as parentToc where tech.id = :technologyID ";
        List<Entity> coveredOrderProducts = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT).find(coveredOrdersProductsSql).setLong("technologyID", order.getBelongsToField(OrderFields.TECHNOLOGY).getId()).list().getEntities();
        StringBuilder coveredOrdersProductsToSql = new StringBuilder("select toc.id as tocId, parentToc.id as parentId, inputProd.id as prodId, opic.id as opicId, " + "(select count(*) from #technologies_technology t where t.product = inputProd and t.master = true) " + "as prodTechId from #technologies_operationProductInComponent opic " + "left join opic.product as inputProd left join opic.operationComponent toc " + "left join toc.operation operation left join toc.operationProductOutComponents opoc " + "left join opoc.product outputProd left join toc.technology tech " + "left join toc.parent as parentToc where tech.id = :technologyID and inputProd.id IN ( ");
        boolean isFirst = true;
        for (Entity entity : coveredOrderProducts) {
            if (isFirst) {
                coveredOrdersProductsToSql.append(entity.getField("prodId"));
                isFirst = false;
            } else {
                coveredOrdersProductsToSql.append(" ,");
                coveredOrdersProductsToSql.append(entity.getField("prodId"));
            }
        }
        coveredOrdersProductsToSql.append(")");
        List<Entity> coveredOrderProductsTo = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT).find(coveredOrdersProductsToSql.toString()).setLong("technologyID", coveredOrder.getBelongsToField(OrderFields.TECHNOLOGY).getId()).list().getEntities();
        if (!coveredOrderProductsTo.isEmpty()) {
            String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING);
            String intputProductsRequiredForType = order.getStringField(OrderFieldsMR.INPUT_PRODUCTS_REQUIRED_FOR_TYPE);
            Map<Long, BigDecimal> productComponentQuantities = Maps.newHashMap();
            OperationProductComponentWithQuantityContainer operationProductComponentWithQuantityContainer = new OperationProductComponentWithQuantityContainer();
            if (InputProductsRequiredForType.START_ORDER.getStringValue().equals(intputProductsRequiredForType)) {
                if (TypeOfProductionRecording.FOR_EACH.getStringValue().equals(typeOfProductionRecording)) {
                    operationProductComponentWithQuantityContainer = productQuantitiesService.getProductComponentQuantitiesWithoutNonComponents(Lists.newArrayList(order));
                } else if (TypeOfProductionRecording.CUMULATED.getStringValue().equals(typeOfProductionRecording) || TypeOfProductionRecording.BASIC.getStringValue().equals(typeOfProductionRecording)) {
                    productComponentQuantities = productQuantitiesService.getNeededProductQuantities(order, materialRequirementService.getDefaultMrpAlgorithm());
                }
            }
            operationProductComponentWithQuantityContainer = operationProductComponentWithQuantityContainer.getAllWithSameEntityType(TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
            for (Entity productE : coveredOrderProductsTo) {
                Entity technologyOperationComponent = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT).get((Long) productE.getField("tocId"));
                Entity operationProductInComponent = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT).get((Long) productE.getField("opicId"));
                estimateProductDemandForOperationInComponent(productAndCoverageProducts, new CoverageProductForOrder(coverageToDate, order, technologyOperationComponent, null, operationProductInComponent, productComponentQuantities, operationProductComponentWithQuantityContainer), coveredOrder);
            }
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) CoverageProductForOrder(com.qcadoo.mes.materialRequirementCoverageForOrder.constans.CoverageProductForOrder) BigDecimal(java.math.BigDecimal)

Example 17 with OperationProductComponentWithQuantityContainer

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

the class OrderRealizationTimeServiceImpl method estimateOperationTimeConsumption.

@Override
@Transactional
public int estimateOperationTimeConsumption(final EntityTreeNode operationComponent, final BigDecimal plannedQuantity, final boolean includeTpz, final boolean includeAdditionalTime, final Entity productionLine) {
    Entity technology = operationComponent.getBelongsToField(TECHNOLOGY);
    Map<Long, BigDecimal> operationRunsFromProductionQuantities = Maps.newHashMap();
    OperationProductComponentWithQuantityContainer productComponentQuantities = productQuantitiesService.getProductComponentQuantities(technology, plannedQuantity, operationRunsFromProductionQuantities);
    return evaluateOperationTime(null, operationComponent, includeTpz, includeAdditionalTime, operationRunsFromProductionQuantities, productionLine, false, productComponentQuantities);
}
Also used : Entity(com.qcadoo.model.api.Entity) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) BigDecimal(java.math.BigDecimal) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with OperationProductComponentWithQuantityContainer

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

the class BasicProductionCountingServiceImpl method updateProductionCountingQuantitiesAndOperationRuns.

@Override
public void updateProductionCountingQuantitiesAndOperationRuns(final Entity order) {
    final Map<Long, BigDecimal> operationRuns = Maps.newHashMap();
    final Set<OperationProductComponentHolder> nonComponents = Sets.newHashSet();
    final OperationProductComponentWithQuantityContainer productComponentQuantities = productQuantitiesService.getProductComponentWithQuantities(Collections.singletonList(order), operationRuns, nonComponents);
    updateProductionCountingOperationRuns(order, operationRuns);
    updateProductionCountingQuantities(order, productComponentQuantities, nonComponents);
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) BigDecimal(java.math.BigDecimal)

Example 19 with OperationProductComponentWithQuantityContainer

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

the class BasicProductionCountingServiceImpl method createProductionCounting.

@Override
public OperationProductComponentWithQuantityContainer createProductionCounting(final Entity order) {
    Map<Long, BigDecimal> operationRuns = Maps.newHashMap();
    Set<OperationProductComponentHolder> nonComponents = Sets.newHashSet();
    final OperationProductComponentWithQuantityContainer productComponentQuantities = productQuantitiesService.getProductComponentWithQuantities(Collections.singletonList(order), operationRuns, nonComponents);
    createProductionCountingOperationRuns(order, operationRuns);
    List<Entity> productionCountingQuantities = prepareProductionCountingQuantities(order, nonComponents, productComponentQuantities);
    List<Entity> basicProductionCounting = Lists.newArrayList();
    prepareBasicProductionCounting(order, productionCountingQuantities, basicProductionCounting);
    saveBasicProductionCounting(order, productionCountingQuantities, basicProductionCounting, order.getBelongsToField(OrderFields.PRODUCT));
    return productComponentQuantities;
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) Entity(com.qcadoo.model.api.Entity) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) BigDecimal(java.math.BigDecimal)

Example 20 with OperationProductComponentWithQuantityContainer

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

the class OrderHooksBPC method onSave.

public void onSave(final DataDefinition orderDD, final Entity order) {
    if (Objects.nonNull(order.getBelongsToField(OrderFields.TECHNOLOGY))) {
        boolean shouldCreateProductionCounting = checkIfShouldCreateProductionCounting(order);
        if (shouldCreateProductionCounting) {
            OperationProductComponentWithQuantityContainer operationProductComponentWithQuantityContainer = basicProductionCountingService.createProductionCounting(order);
            addMessagesIfExists(order, operationProductComponentWithQuantityContainer);
        } else if (checkIfShouldReCreateProductionCounting(order)) {
            for (Entity pcq : order.getHasManyField(OrderFieldsBPC.PRODUCTION_COUNTING_QUANTITIES)) {
                pcq.getDataDefinition().delete(pcq.getId());
            }
            for (Entity bpc : order.getHasManyField(OrderFieldsBPC.BASIC_PRODUCTION_COUNTINGS)) {
                bpc.getDataDefinition().delete(bpc.getId());
            }
            for (Entity pqor : order.getHasManyField(OrderFieldsBPC.PRODUCTION_COUNTING_OPERATION_RUNS)) {
                pqor.getDataDefinition().delete(pqor.getId());
            }
            OperationProductComponentWithQuantityContainer operationProductComponentWithQuantityContainer = basicProductionCountingService.createProductionCounting(order);
            addMessagesIfExists(order, operationProductComponentWithQuantityContainer);
        } else {
            updateProductionCountingQuantitiesAndOperationRuns(order);
            updateProducedQuantity(order);
        }
    } else if (Objects.nonNull(order.getId())) {
        order.setField(OrderFieldsBPC.BASIC_PRODUCTION_COUNTINGS, Lists.newArrayList());
        order.setField(OrderFieldsBPC.PRODUCTION_COUNTING_OPERATION_RUNS, Lists.newArrayList());
        order.setField(OrderFieldsBPC.PRODUCTION_COUNTING_QUANTITIES, Lists.newArrayList());
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer)

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