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); }
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); } }
private Map<String, BigDecimal> estimatePieceworkCostCalculationForSingleOperation( final EntityTreeNode calculationOperationComponent, final BigDecimal productionCostMargin, final BigDecimal operationRuns) { Map<String, BigDecimal> costs = Maps.newHashMap(); BigDecimal pieceworkCost = BigDecimalUtils.convertNullToZero(calculationOperationComponent .getDecimalField(CalculationOperationComponentFields.PIECEWORK_COST)); BigDecimal numberOfOperations = BigDecimalUtils.convertNullToOne(calculationOperationComponent .getField(CalculationOperationComponentFields.NUMBER_OF_OPERATIONS)); BigDecimal pieceworkCostPerOperation = pieceworkCost.divide(numberOfOperations, numberService.getMathContext()); BigDecimal operationCost = operationRuns.multiply(pieceworkCostPerOperation, numberService.getMathContext()); BigDecimal operationMarginCost = operationCost.multiply(productionCostMargin.divide(BigDecimal.valueOf(100), numberService.getMathContext())); BigDecimal totalOperationCost = numberService.setScaleWithDefaultMathContext(operationCost.add(operationMarginCost, numberService.getMathContext())); costs.put(L_OPERATION_COST, numberService.setScaleWithDefaultMathContext(operationCost)); costs.put(L_OPERATION_MARGIN_COST, numberService.setScaleWithDefaultMathContext(operationMarginCost)); costs.put(L_PIECES, numberService.setScaleWithDefaultMathContext(operationRuns)); costs.put(L_TOTAL_OPERATION_COST, totalOperationCost); return costs; }
@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 deleteOperationsTreeIfExists(final Entity costCalculation) { Entity yetAnotherCostCalculation = costCalculation.getDataDefinition().get(costCalculation.getId()); EntityTree existingOperationsTree = yetAnotherCostCalculation.getTreeField(L_CALCULATION_OPERATION_COMPONENTS); if (existingOperationsTree == null || existingOperationsTree.getRoot() == null) { return; } debug("existing calculation operation components tree will be removed.."); EntityTreeNode existingOperationsTreeRoot = existingOperationsTree.getRoot(); existingOperationsTreeRoot.getDataDefinition().delete(existingOperationsTreeRoot.getId()); }
List<EntityTreeNode> children = operationComponents.getRoot().getChildren(); .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS).get(0); BigDecimal outQuantity = productOutComponent.getDecimalField(OperationProductOutComponentFields.QUANTITY);
private Optional<Entity> getSetProductTechnology(final Long productId) { DataDefinition technologyDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY); Entity masterTechnology = technologyDD.find().add(SearchRestrictions.eq(TechnologyFields.PRODUCT + ".id", productId)) .add(SearchRestrictions.eq(TechnologyFields.MASTER, true)).uniqueResult(); if (masterTechnology != null) { EntityTree operationComponents = masterTechnology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); boolean isSet = operationComponents.getRoot() .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS).get(0) .getBooleanField(OperationProductOutComponentFields.SET); if (isSet) { return Optional.of(masterTechnology); } } return Optional.empty(); }
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 Entity createTechnologyInstanceForCalculation(final EntityTree sourceTree, final Entity parentEntity) { checkArgument(sourceTree != null, "source is null"); DataDefinition calculationOperationComponentDD = dataDefinitionService.get(PLUGIN_IDENTIFIER, MODEL_CALCULATION_OPERATION_COMPONENT); // drop old operation components tree EntityTree oldCalculationOperationComponents = parentEntity.getTreeField(L_CALCULATION_OPERATION_COMPONENTS); if (oldCalculationOperationComponents != null && oldCalculationOperationComponents.getRoot() != null) { calculationOperationComponentDD.delete(oldCalculationOperationComponents.getRoot().getId()); } Entity tree = createCalculationOperationComponent(sourceTree.getRoot(), null, calculationOperationComponentDD, parentEntity); parentEntity.setField(L_CALCULATION_OPERATION_COMPONENTS, asList(tree)); return parentEntity; }
@Override @Transactional public int estimateMaxOperationTimeConsumptionForWorkstation(final Entity order, 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(order, operationComponent, includeTpz, includeAdditionalTime, operationRunsFromProductionQuantities, productionLine, true, productComponentQuantities); }
private void appendNodeNumbersToMap(final Map<String, Set<String>> map, final EntityTreeNode parent, final EntityTreeNode child) { final String parentNodeNumber = parent.getStringField(NODE_NUMBER); final String childNodeNumber = child.getStringField(NODE_NUMBER); if (map.containsKey(parentNodeNumber)) { final Set<String> subOpsNodeNums = map.get(parentNodeNumber); subOpsNodeNums.add(childNodeNumber); map.put(parentNodeNumber, subOpsNodeNums); } else { map.put(parentNodeNumber, Sets.newHashSet(childNodeNumber)); } }
EntityTree tree = technologyFromDB.getTreeField(TechnologyFields.PRODUCT_STRUCTURE_TREE); if (tree.getRoot() != null) { Date productStructureCreateDate = tree.getRoot().getDateField(ProductStructureTreeNodeFields.CREATE_DATE); List<Entity> treeEntities = tree.find().list().getEntities(); Entity technologyStateChange = getLastTechnologyStateChange(technologyFromDB);
private void updateTechnology(final Entity technology) { String number = technology.getStringField(TechnologyFields.NUMBER); Entity product = technology.getBelongsToField(TechnologyFields.PRODUCT); technology.setField(TechnologyFields.NAME, makeTechnologyName(number, product)); technology.setField(TechnologyFields.TECHNOLOGY_PROTOTYPE, null); technology.setField(TechnologyFields.TECHNOLOGY_TYPE, TechnologyType.WITH_OWN_TECHNOLOGY.getStringValue()); EntityTree operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); if ((operationComponents != null) && !operationComponents.isEmpty()) { EntityTreeNode root = operationComponents.getRoot(); root.getDataDefinition().delete(root.getId()); } technology.setField(TechnologyFields.OPERATION_COMPONENTS, Lists.newArrayList()); technology.getDataDefinition().save(technology); if (TechnologyStateStringValues.CHECKED.equals(technology.getStringField(TechnologyFields.STATE))) { changeTechnologyState(technology, TechnologyStateStringValues.DRAFT); } }
public boolean checkTopComponentsProducesProductForTechnology(final StateChangeContext stateContext) { Entity technology = stateContext.getOwner(); final Entity savedTechnology = technology.getDataDefinition().get(technology.getId()); final Entity product = savedTechnology.getBelongsToField(TechnologyFields.PRODUCT); final EntityTree operations = savedTechnology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); final EntityTreeNode root = operations.getRoot(); if (root != null) { final EntityList productOutComps = root .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS); for (Entity productOutComp : productOutComps) { if (product.getId().equals(productOutComp.getBelongsToField(OperationProductOutComponentFields.PRODUCT).getId())) { return true; } } } stateContext.addValidationError("technologies.technology.validate.global.error.noFinalProductInTechnologyTree"); return false; }
@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); }
private void appendProductsToMap(final Map<String, Set<Entity>> parentToProductsMap, final EntityTreeNode parent, final Set<Long> commonProds) { DataDefinition dd = dataDefinitionService.get("basic", "product"); String nodeNumber = parent.getStringField("nodeNumber"); Set<Entity> productsSet = parentToProductsMap.get(nodeNumber); if (productsSet == null) { productsSet = Sets.newHashSet(); } for (Long prodId : commonProds) { productsSet.add(dd.get(prodId)); } parentToProductsMap.put(nodeNumber, productsSet); }
if (technology != null) { EntityTree operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); Entity operationProductOutComponent = operationComponents.getRoot().getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS).get(0); boolean isSet = operationProductOutComponent.getBooleanField("set"); if (isSet) { EntityTree operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); Entity operationProductOutComponent = operationComponents.getRoot().getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS).get(0); boolean isSet = operationProductOutComponent.getBooleanField("set"); if (isSet) {