Search in sources :

Example 1 with CoverageProductForOrder

use of com.qcadoo.mes.materialRequirementCoverageForOrder.constans.CoverageProductForOrder 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)

Aggregations

CoverageProductForOrder (com.qcadoo.mes.materialRequirementCoverageForOrder.constans.CoverageProductForOrder)1 OperationProductComponentWithQuantityContainer (com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer)1 Entity (com.qcadoo.model.api.Entity)1 BigDecimal (java.math.BigDecimal)1