use of com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer in project mes by qcadoo.
the class ProductQuantitiesServiceImpl method getProductComponentWithQuantitiesForOrders.
private OperationProductComponentWithQuantityContainer getProductComponentWithQuantitiesForOrders(final List<Entity> orders, final Map<Long, BigDecimal> operationRuns, final Set<OperationProductComponentHolder> nonComponents, final boolean onTheFly) {
Map<Long, OperationProductComponentWithQuantityContainer> productComponentWithQuantitiesForOrders = Maps.newHashMap();
for (Entity order : orders) {
BigDecimal plannedQuantity = order.getDecimalField(L_PLANNED_QUANTITY);
Entity technology = order.getBelongsToField(L_TECHNOLOGY);
if (Objects.isNull(technology)) {
throw new IllegalStateException("Order doesn't contain technology.");
}
productComponentWithQuantitiesForOrders.put(order.getId(), getProductComponentWithQuantitiesForTechnology(technology, null, plannedQuantity, operationRuns, nonComponents));
}
return groupOperationProductComponentWithQuantities(productComponentWithQuantitiesForOrders);
}
use of com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer in project mes by qcadoo.
the class ProductQuantitiesServiceImpl method getProductComponentQuantities.
@Override
public ProductQuantitiesHolder getProductComponentQuantities(final Entity technology, final BigDecimal givenQuantity) {
Map<Long, BigDecimal> operationRuns = Maps.newHashMap();
OperationProductComponentWithQuantityContainer productQuantities = getProductComponentQuantities(technology, givenQuantity, operationRuns);
return new ProductQuantitiesHolder(productQuantities, operationRuns);
}
use of com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer in project mes by qcadoo.
the class ProductQuantitiesServiceImpl method groupOperationProductComponentWithQuantities.
@Override
public OperationProductComponentWithQuantityContainer groupOperationProductComponentWithQuantities(final Map<Long, OperationProductComponentWithQuantityContainer> operationProductComponentWithQuantityContainerForOrders) {
OperationProductComponentWithQuantityContainer operationProductComponentWithQuantityContainer = new OperationProductComponentWithQuantityContainer();
for (Entry<Long, OperationProductComponentWithQuantityContainer> operationProductComponentWithQuantityContainerForOrder : operationProductComponentWithQuantityContainerForOrders.entrySet()) {
operationProductComponentWithQuantityContainer.getMessages().addAll(operationProductComponentWithQuantityContainerForOrder.getValue().getMessages());
for (Entry<OperationProductComponentHolder, BigDecimal> productComponentWithQuantity : operationProductComponentWithQuantityContainerForOrder.getValue().asMap().entrySet()) {
OperationProductComponentHolder operationProductComponentHolder = productComponentWithQuantity.getKey();
BigDecimal quantity = productComponentWithQuantity.getValue();
if (operationProductComponentWithQuantityContainer.containsKey(operationProductComponentHolder)) {
BigDecimal addedQuantity = operationProductComponentWithQuantityContainer.get(operationProductComponentHolder);
quantity = quantity.add(addedQuantity, numberService.getMathContext());
}
operationProductComponentWithQuantityContainer.put(operationProductComponentHolder, quantity);
}
}
return operationProductComponentWithQuantityContainer;
}
use of com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer in project mes by qcadoo.
the class ProductQuantitiesServiceImpl method getNeededProductQuantitiesForComponents.
private Map<Long, BigDecimal> getNeededProductQuantitiesForComponents(final List<Entity> components, final MrpAlgorithm mrpAlgorithm, final boolean onTheFly) {
Map<Long, BigDecimal> operationRuns = Maps.newHashMap();
Set<OperationProductComponentHolder> nonComponents = Sets.newHashSet();
OperationProductComponentWithQuantityContainer productComponentWithQuantities = getProductComponentWithQuantitiesForOrders(getOrdersFromComponents(components), operationRuns, nonComponents, onTheFly);
return getProductWithQuantities(productComponentWithQuantities, nonComponents, mrpAlgorithm, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
}
use of com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer in project mes by qcadoo.
the class ProductQuantitiesServiceImpl method preloadOperationProductComponentQuantity.
@Override
public void preloadOperationProductComponentQuantity(final List<Entity> operationProductComponents, final OperationProductComponentWithQuantityContainer operationProductComponentWithQuantityContainer) {
for (Entity operationProductComponent : operationProductComponents) {
BigDecimal neededQuantity = operationProductComponent.getDecimalField(L_QUANTITY);
if (operationProductComponent.getDataDefinition().getName().equals(TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT) && operationProductComponent.getBooleanField(OperationProductInComponentFields.DIFFERENT_PRODUCTS_IN_DIFFERENT_SIZES) && !operationProductComponentWithQuantityContainer.getSizeGroups().isEmpty()) {
for (Entity sizeGroup : operationProductComponentWithQuantityContainer.getSizeGroups()) {
List<Entity> productsByGroup = operationProductComponent.getHasManyField(OperationProductInComponentFields.PRODUCT_BY_SIZE_GROUPS).stream().filter(pG -> pG.getBelongsToField(ProductBySizeGroupFields.SIZE_GROUP).getId().equals(sizeGroup.getId())).collect(Collectors.toList());
for (Entity productByGroup : productsByGroup) {
operationProductComponentWithQuantityContainer.put(operationProductComponent, productByGroup.getBelongsToField(ProductBySizeGroupFields.PRODUCT), productByGroup.getDecimalField(ProductBySizeGroupFields.QUANTITY));
}
}
} else if (Objects.nonNull(operationProductComponentWithQuantityContainer.getOrderedProduct()) && operationProductComponent.getDataDefinition().getName().equals(TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT) && Objects.nonNull(getOperationProductProduct(operationProductComponent)) && ProductFamilyElementType.PRODUCTS_FAMILY.getStringValue().equals(getOperationProductProduct(operationProductComponent).getField(ProductFields.ENTITY_TYPE)) && Objects.nonNull(operationProductComponent.getBelongsToField(OperationProductInComponentFields.ATTRIBUTE))) {
Entity attribute = operationProductComponent.getBelongsToField(OperationProductInComponentFields.ATTRIBUTE);
List<Entity> attributeValues = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.PRODUCT_ATTRIBUTE_VALUE).find().add(SearchRestrictions.belongsTo(ProductAttributeValueFields.PRODUCT, operationProductComponentWithQuantityContainer.getOrderedProduct())).add(SearchRestrictions.belongsTo(ProductAttributeValueFields.ATTRIBUTE, attribute)).list().getEntities();
Entity opicProduct = getOperationProductProduct(operationProductComponent);
if (!attributeValues.isEmpty()) {
Collection<Long> attributeValuesId = attributeValues.stream().map(av -> av.getBelongsToField(ProductAttributeValueFields.ATTRIBUTE_VALUE).getId()).collect(Collectors.toList());
List<Entity> allProductAttributeValues = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.PRODUCT_ATTRIBUTE_VALUE).find().createAlias(ProductAttributeValueFields.PRODUCT, "prod", JoinType.LEFT).createAlias("prod.parent", "parentProduct", JoinType.LEFT).add(SearchRestrictions.eq("parentProduct.id", opicProduct.getId())).list().getEntities();
Map<Long, List<Entity>> attributeValuesByProduct = allProductAttributeValues.stream().collect(groupingBy(e -> e.getBelongsToField(ProductAttributeValueFields.PRODUCT).getId()));
Long specificProductId = null;
boolean moreThanOneSpecificProduct = false;
for (Entry<Long, List<Entity>> entry : attributeValuesByProduct.entrySet()) {
Long productId = entry.getKey();
List<Entity> attrValues = entry.getValue();
Collection<Long> allProductAttributeValuesId = attrValues.stream().filter(av -> Objects.nonNull(av.getBelongsToField(ProductAttributeValueFields.ATTRIBUTE_VALUE))).map(av -> av.getBelongsToField(ProductAttributeValueFields.ATTRIBUTE_VALUE).getId()).collect(Collectors.toList());
boolean hasNotCalculatedElements = attrValues.stream().anyMatch(av -> Objects.isNull(av.getBelongsToField(ProductAttributeValueFields.ATTRIBUTE_VALUE)));
boolean isSame = attributeValuesId.stream().allMatch(a -> allProductAttributeValuesId.stream().anyMatch(b -> b.equals(a)));
if (isSame && !hasNotCalculatedElements && attributeValuesId.size() == allProductAttributeValuesId.size()) {
if (Objects.nonNull(specificProductId)) {
moreThanOneSpecificProduct = true;
break;
}
specificProductId = productId;
}
}
if (Objects.isNull(specificProductId)) {
Entity toc = operationProductComponent.getBelongsToField(OperationProductInComponentFields.OPERATION_COMPONENT);
Entity operation = toc.getBelongsToField(TechnologyOperationComponentFields.OPERATION);
OperationProductComponentMessage message = new OperationProductComponentMessage();
message.setMessage("basicProductionCounting.productionCountingQuantity.error.couldNotFindSpecificProductWithMatchingAttributeValue");
message.setOperationNumber(operation.getStringField(OperationFields.NUMBER));
message.setProductNumber(opicProduct.getStringField(ProductFields.NUMBER));
message.setNodeNumber(toc.getStringField(TechnologyOperationComponentFields.NODE_NUMBER));
message.setAttributeNumber(attribute.getStringField(AttributeFields.NUMBER));
message.setAttributeValue(attributeValues.stream().map(a -> a.getStringField(ProductAttributeValueFields.VALUE)).collect(Collectors.joining(", ")));
operationProductComponentWithQuantityContainer.addMessage(message);
} else if (moreThanOneSpecificProduct) {
Entity toc = operationProductComponent.getBelongsToField(OperationProductInComponentFields.OPERATION_COMPONENT);
Entity operation = toc.getBelongsToField(TechnologyOperationComponentFields.OPERATION);
OperationProductComponentMessage message = new OperationProductComponentMessage();
message.setMessage("basicProductionCounting.productionCountingQuantity.error.toManyProductsWithMatchingAttributeValue");
message.setOperationNumber(operation.getStringField(OperationFields.NUMBER));
message.setProductNumber(opicProduct.getStringField(ProductFields.NUMBER));
message.setNodeNumber(toc.getStringField(TechnologyOperationComponentFields.NODE_NUMBER));
message.setAttributeNumber(attribute.getStringField(AttributeFields.NUMBER));
message.setAttributeValue(attributeValues.stream().map(a -> a.getStringField(ProductAttributeValueFields.VALUE)).collect(Collectors.joining(", ")));
operationProductComponentWithQuantityContainer.addMessage(message);
} else {
Entity product = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(specificProductId);
operationProductComponentWithQuantityContainer.put(operationProductComponent, product, operationProductComponent.getDecimalField(ProductBySizeGroupFields.QUANTITY));
}
} else {
Entity toc = operationProductComponent.getBelongsToField(OperationProductInComponentFields.OPERATION_COMPONENT);
Entity operation = toc.getBelongsToField(TechnologyOperationComponentFields.OPERATION);
OperationProductComponentMessage message = new OperationProductComponentMessage();
message.setMessage("basicProductionCounting.productionCountingQuantity.error.orderedProductDoesNotHaveAttribute");
message.setOperationNumber(operation.getStringField(OperationFields.NUMBER));
message.setProductNumber(opicProduct.getStringField(ProductFields.NUMBER));
message.setNodeNumber(toc.getStringField(TechnologyOperationComponentFields.NODE_NUMBER));
message.setAttributeNumber(attribute.getStringField(AttributeFields.NUMBER));
operationProductComponentWithQuantityContainer.addMessage(message);
}
} else {
operationProductComponentWithQuantityContainer.put(operationProductComponent, neededQuantity);
}
}
}
Aggregations