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);
}
}
}
}
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);
}
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);
}
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;
}
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());
}
}
Aggregations