use of com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer in project mes by qcadoo.
the class OperationProductsExtractor method getOperationProductComponents.
private List<Entity> getOperationProductComponents(final Entity order, final Entity technologyOperationComponent) {
List<Entity> trackingOperationProductComponents = Lists.newArrayList();
Map<OperationProductComponentEntityType, Set<Entity>> entityTypeWithAlreadyAddedProducts = Maps.newHashMap();
String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING);
OperationProductComponentWithQuantityContainer productComponentQuantities = productQuantitiesService.getProductComponentQuantities(order);
for (Entry<OperationProductComponentHolder, BigDecimal> productComponentQuantity : productComponentQuantities.asMap().entrySet()) {
OperationProductComponentHolder operationProductComponentHolder = productComponentQuantity.getKey();
if (forEach(typeOfProductionRecording)) {
Entity operationComponent = operationProductComponentHolder.getTechnologyOperationComponent();
if (technologyOperationComponent == null) {
if (operationComponent != null) {
continue;
}
} else {
if ((operationComponent == null) || !technologyOperationComponent.getId().equals(operationComponent.getId())) {
continue;
}
}
} else if (cumulated(typeOfProductionRecording)) {
OperationProductComponentEntityType entityType = operationProductComponentHolder.getEntityType();
Entity product = operationProductComponentHolder.getProduct();
if ((product != null) && (entityType != null)) {
if (shouldSkipAddingProduct(operationProductComponentHolder, entityTypeWithAlreadyAddedProducts, typeOfProductionRecording)) {
if (entityTypeWithAlreadyAddedProducts.containsKey(entityType)) {
continue;
} else {
entityTypeWithAlreadyAddedProducts.put(entityType, Sets.newHashSet());
continue;
}
} else {
if (entityTypeWithAlreadyAddedProducts.containsKey(entityType)) {
Set<Entity> alreadAddedProducts = entityTypeWithAlreadyAddedProducts.get(entityType);
alreadAddedProducts.add(product);
entityTypeWithAlreadyAddedProducts.put(entityType, alreadAddedProducts);
} else {
entityTypeWithAlreadyAddedProducts.put(entityType, Sets.newHashSet(product));
}
}
}
}
Entity trackingOperationProductComponent = trackingOperationComponentBuilder.fromOperationProductComponentHolder(operationProductComponentHolder);
if (forEach(typeOfProductionRecording)) {
Optional<Entity> mabyExist = trackingOperationProductComponents.stream().filter(toc -> toc.getBelongsToField(L_PRODUCT).getId().equals(trackingOperationProductComponent.getBelongsToField(L_PRODUCT).getId())).findAny();
if (!mabyExist.isPresent()) {
trackingOperationProductComponents.add(trackingOperationProductComponent);
}
} else {
trackingOperationProductComponents.add(trackingOperationProductComponent);
}
}
return trackingOperationProductComponents;
}
use of com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer in project mes by qcadoo.
the class ScheduleDetailsListenersPS method getOperations.
@Transactional
public void getOperations(final ViewDefinitionState view, final ComponentState state, final String[] args) {
GridComponent ordersGrid = (GridComponent) view.getComponentByReference(ScheduleFields.ORDERS);
List<Entity> orders = ordersGrid.getEntities();
FormComponent formComponent = (FormComponent) state;
Entity schedule = formComponent.getEntity();
boolean includeTpz = schedule.getBooleanField(ScheduleFields.INCLUDE_TPZ);
DataDefinition schedulePositionDD = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_SCHEDULE_POSITION);
List<Entity> positions = Lists.newArrayList();
for (Entity order : orders) {
Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
if (technology == null) {
continue;
}
final Map<Long, BigDecimal> operationRuns = Maps.newHashMap();
OperationProductComponentWithQuantityContainer operationProductComponentWithQuantityContainer = productQuantitiesService.getProductComponentQuantities(technology, order.getDecimalField(OrderFields.PLANNED_QUANTITY), operationRuns);
List<Entity> operationComponents = technology.getHasManyField(TechnologyFields.OPERATION_COMPONENTS);
for (Entity operationComponent : operationComponents) {
BigDecimal operationComponentRuns = BigDecimalUtils.convertNullToZero(operationRuns.get(operationComponent.getId()));
BigDecimal staffFactor = getStaffFactor(operationComponent);
OperationWorkTime operationWorkTime = operationWorkTimeService.estimateTechOperationWorkTime(operationComponent, operationComponentRuns, includeTpz, false, false, staffFactor);
Entity schedulePosition = createSchedulePosition(schedule, schedulePositionDD, order, operationComponent, operationWorkTime, operationProductComponentWithQuantityContainer, operationComponentRuns);
positions.add(schedulePosition);
}
}
schedule.setField(ScheduleFields.POSITIONS, positions);
schedule = schedule.getDataDefinition().save(schedule);
formComponent.setEntity(schedule);
view.addMessage("productionScheduling.info.schedulePositionsGenerated", ComponentState.MessageType.SUCCESS);
}
use of com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer in project mes by qcadoo.
the class ProductQuantitiesServiceImpl method getProductComponentWithQuantitiesForTechnology.
@Override
public OperationProductComponentWithQuantityContainer getProductComponentWithQuantitiesForTechnology(final Entity technology, final Entity orderedProduct, final BigDecimal givenQuantity, final Map<Long, BigDecimal> operationRuns, final Set<OperationProductComponentHolder> nonComponents) {
OperationProductComponentWithQuantityContainer operationProductComponentWithQuantityContainer = new OperationProductComponentWithQuantityContainer();
operationProductComponentWithQuantityContainer.setOrderedProduct(orderedProduct);
if (Objects.nonNull(orderedProduct)) {
Entity size = orderedProduct.getBelongsToField(ProductFields.SIZE);
if (Objects.nonNull(size)) {
List<Entity> sizeGroups = size.getHasManyField(SizeFields.SIZE_GROUPS);
if (!sizeGroups.isEmpty()) {
operationProductComponentWithQuantityContainer.setSizeGroups(sizeGroups);
}
}
}
EntityTree operationComponents = getOperationComponentsFromTechnology(technology);
Entity root = operationComponents.getRoot();
if (Objects.nonNull(root)) {
preloadProductQuantitiesAndOperationRuns(operationComponents, operationProductComponentWithQuantityContainer, operationRuns);
traverseProductQuantitiesAndOperationRuns(technology, givenQuantity, root, null, operationProductComponentWithQuantityContainer, nonComponents, operationRuns);
}
return operationProductComponentWithQuantityContainer;
}
use of com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer in project mes by qcadoo.
the class ProductQuantitiesServiceImpl method getNeededProductQuantities.
private Map<Long, BigDecimal> getNeededProductQuantities(final List<Entity> orders, final MrpAlgorithm mrpAlgorithm, final Map<Long, BigDecimal> operationRuns, final boolean onTheFly) {
Set<OperationProductComponentHolder> nonComponents = Sets.newHashSet();
OperationProductComponentWithQuantityContainer productComponentWithQuantities = getProductComponentWithQuantitiesForOrders(orders, 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 multiplyOperationProductComponentQuantities.
private void multiplyOperationProductComponentQuantities(final List<Entity> operationProductComponents, final BigDecimal multiplier, final OperationProductComponentWithQuantityContainer operationProductComponentWithQuantityContainer) {
List<Entity> sizeGroups = operationProductComponentWithQuantityContainer.getSizeGroups();
Entity orderedProduct = operationProductComponentWithQuantityContainer.getOrderedProduct();
for (Entity operationProductComponent : operationProductComponents) {
if (operationProductComponent.getDataDefinition().getName().equals(TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT) && operationProductComponent.getBooleanField(OperationProductInComponentFields.DIFFERENT_PRODUCTS_IN_DIFFERENT_SIZES)) {
if (!sizeGroups.isEmpty()) {
for (Entity sizeGroup : sizeGroups) {
List<Entity> productBySizeGroups = operationProductComponent.getHasManyField(OperationProductInComponentFields.PRODUCT_BY_SIZE_GROUPS).stream().filter(pG -> pG.getBelongsToField(ProductBySizeGroupFields.SIZE_GROUP).getId().equals(sizeGroup.getId())).collect(Collectors.toList());
for (Entity productBySizeGroup : productBySizeGroups) {
BigDecimal addedQuantity = operationProductComponentWithQuantityContainer.get(operationProductComponent, productBySizeGroup.getBelongsToField(ProductBySizeGroupFields.PRODUCT));
BigDecimal quantity = addedQuantity.multiply(multiplier, numberService.getMathContext());
operationProductComponentWithQuantityContainer.put(operationProductComponent, productBySizeGroup.getBelongsToField(ProductBySizeGroupFields.PRODUCT), quantity.setScale(5, RoundingMode.CEILING));
}
}
} else {
operationProductComponentWithQuantityContainer.put(operationProductComponent, null);
}
} else if (Objects.nonNull(orderedProduct) && operationProductComponent.getDataDefinition().getName().equals(TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT) && 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 (!moreThanOneSpecificProduct && Objects.nonNull(specificProductId)) {
Entity product = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(specificProductId);
BigDecimal addedQuantity = operationProductComponentWithQuantityContainer.get(operationProductComponent, product);
BigDecimal quantity = addedQuantity.multiply(multiplier, numberService.getMathContext());
operationProductComponentWithQuantityContainer.put(operationProductComponent, product, quantity.setScale(5, RoundingMode.CEILING));
}
}
} else {
BigDecimal addedQuantity = operationProductComponentWithQuantityContainer.get(operationProductComponent);
BigDecimal quantity = addedQuantity.multiply(multiplier, numberService.getMathContext());
operationProductComponentWithQuantityContainer.put(operationProductComponent, quantity.setScale(5, RoundingMode.CEILING));
}
}
}
Aggregations