private void collectChildrenProducingTheSameParentInputs(final Map<String, Set<Entity>> parentToProductsMap, final EntityTreeNode parentOperation) { final Set<Long> parentInProdIds = getProductIdsFromOperationComponent(parentOperation, OPERATION_PRODUCT_IN_COMPONENTS); Map<Long, Set<Long>> intersections = Maps.newHashMap(); for (EntityTreeNode subOperation : parentOperation.getChildren()) { final Set<Long> childOutProdIds = getProductIdsFromOperationComponent(subOperation, OPERATION_PRODUCT_OUT_COMPONENTS); Set<Long> intersection = Sets.intersection(parentInProdIds, childOutProdIds); intersections.put(subOperation.getId(), intersection); } for (Entry<Long, Set<Long>> entry : intersections.entrySet()) { for (Entry<Long, Set<Long>> entry1 : intersections.entrySet()) { if (entry.getKey().equals(entry1.getKey())) { continue; } Set<Long> commonProds = Sets.intersection(entry.getValue(), entry1.getValue()); if (!commonProds.isEmpty()) { appendProductsToMap(parentToProductsMap, parentOperation, commonProds); } } } for (EntityTreeNode subOperation : parentOperation.getChildren()) { collectChildrenProducingTheSameParentInputs(parentToProductsMap, subOperation); } }
@Override public Map<String, BigDecimal> estimateCostCalculationForHourly(final EntityTreeNode calculationOperationComponent, final BigDecimal productionCostMargin, final BigDecimal plannedQuantity, final OperationTimesContainer realizationTimes, final boolean hourlyCostFromOperation) { checkArgument(calculationOperationComponent != null, "given operationComponent is empty"); Map<String, BigDecimal> costs = Maps.newHashMapWithExpectedSize(L_COST_KEYS.size()); MathContext mathContext = numberService.getMathContext(); for (String costKey : L_COST_KEYS) { costs.put(costKey, BigDecimal.ZERO); } for (EntityTreeNode child : calculationOperationComponent.getChildren()) { Map<String, BigDecimal> unitCosts = estimateCostCalculationForHourly(child, productionCostMargin, plannedQuantity, realizationTimes, hourlyCostFromOperation); for (String costKey : L_COST_KEYS) { BigDecimal unitCost = costs.get(costKey).add(unitCosts.get(costKey), mathContext); costs.put(costKey, numberService.setScaleWithDefaultMathContext(unitCost)); } } OperationTimes operationTimes = realizationTimes.get(calculationOperationComponent.getBelongsToField( "technologyOperationComponent").getId()); Map<String, BigDecimal> costsForSingleOperation = estimateHourlyCostCalculationForSingleOperation(operationTimes, productionCostMargin, hourlyCostFromOperation); saveGeneratedValues(costsForSingleOperation, calculationOperationComponent, true, operationTimes.getTimes(), null); costs.put(L_MACHINE_HOURLY_COST, costs.get(L_MACHINE_HOURLY_COST).add(costsForSingleOperation.get(L_OPERATION_MACHINE_COST), mathContext)); costs.put(L_LABOR_HOURLY_COST, costs.get(L_LABOR_HOURLY_COST).add(costsForSingleOperation.get(L_OPERATION_LABOR_COST), mathContext)); return costs; }
private void collectChildrenProducingManyParentInputs(final Map<String, Set<String>> parentToChildsMap, final EntityTreeNode parentOperation) { final Set<Long> parentInProdIds = getProductIdsFromOperationComponent(parentOperation, OPERATION_PRODUCT_IN_COMPONENTS); for (EntityTreeNode subOperation : parentOperation.getChildren()) { final Set<Long> childOutProdIds = getProductIdsFromOperationComponent(subOperation, OPERATION_PRODUCT_OUT_COMPONENTS); if (hasMoreThanOneCommonProduct(parentInProdIds, childOutProdIds)) { appendNodeNumbersToMap(parentToChildsMap, parentOperation, subOperation); } collectChildrenProducingManyParentInputs(parentToChildsMap, subOperation); } }
private void createOrCopyCalculationOperationComponent(final EntityTreeNode operationComponent, final Entity calculationOperationComponent, final Entity costCalculation) { DataDefinition sourceDD = operationComponent.getDataDefinition(); for (String fieldName : Arrays.asList("priority", "nodeNumber", L_PRODUCTION_IN_ONE_CYCLE, "nextOperationAfterProducedQuantity", "operationOffSet", "effectiveOperationRealizationTime", "effectiveDateFrom", "effectiveDateTo", "pieceworkCost", "numberOfOperations")) { calculationOperationComponent.setField(fieldName, operationComponent.getField(fieldName)); } calculationOperationComponent.setField(L_OPERATION, operationComponent.getBelongsToField(L_OPERATION)); calculationOperationComponent.setField( "nextOperationAfterProducedType", operationComponent.getField("nextOperationAfterProducedType") == null ? "01all" : operationComponent .getField("nextOperationAfterProducedType")); if (!TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT.equals(sourceDD.getName())) { LOG.error("incorrect model!"); } calculationOperationComponent.setField(L_TECHNOLOGY_OPERATION_COMPONENT, operationComponent); calculationOperationComponent.setField(L_ENTITY_TYPE, L_OPERATION); List<Entity> newTechnologyInstanceOperationComponents = new ArrayList<>(); for (EntityTreeNode child : operationComponent.getChildren()) { newTechnologyInstanceOperationComponents.add(createCalculationOperationComponent(child, calculationOperationComponent, calculationOperationComponent.getDataDefinition(), costCalculation)); } calculationOperationComponent.setField("children", newTechnologyInstanceOperationComponents); }
List<EntityTreeNode> children = operationComponents.getRoot().getChildren();