use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class TechnologyComponentsFlowServiceImpl method getComponentsStock.
@Override
public Map<Long, BigDecimal> getComponentsStock(Entity technology, boolean externalNumberShouldBeNull) {
Preconditions.checkArgument(technology != null, "Technology is required.");
DataDefinition operationProductInComponentDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
SearchCriteriaBuilder scb = operationProductInComponentDD.find().createAlias(OperationProductInComponentFields.OPERATION_COMPONENT, "c", JoinType.INNER).createAlias(OperationProductInComponentFieldsPFTD.COMPONENTS_LOCATION, "w", JoinType.LEFT).createAlias("w." + LocationFieldsMFR.RESOURCES, "r", JoinType.LEFT).add(eqField("r." + ResourceFields.PRODUCT, OperationProductInComponentFields.PRODUCT)).add(belongsTo("c." + TechnologyOperationComponentFields.TECHNOLOGY, technology));
if (externalNumberShouldBeNull) {
scb.add(isNull("w." + LocationFields.EXTERNAL_NUMBER));
}
scb.setProjection(list().add(alias(groupField(OperationProductInComponentFields.PRODUCT), OperationProductInComponentFields.PRODUCT)).add(alias(sum("r." + ResourceFields.QUANTITY), ResourceFields.QUANTITY))).addOrder(SearchOrders.asc(ResourceFields.QUANTITY));
List<Entity> componentsStock = scb.list().getEntities();
Map<Long, BigDecimal> stockMap = Maps.newHashMap();
for (Entity componentStock : componentsStock) {
stockMap.put(componentStock.getBelongsToField(OperationProductInComponentFields.PRODUCT).getId(), componentStock.getDecimalField(ResourceFields.QUANTITY));
}
return stockMap;
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class TechnologyHooksPFTD method findOPOCs.
public List<Entity> findOPOCs(final Long technologyId) {
SearchCriteriaBuilder scb = getOpocDD().find();
scb.createAlias(OperationProductOutComponentFields.OPERATION_COMPONENT, "toc", JoinType.INNER);
scb.createAlias("toc." + TechnologyOperationComponentFields.TECHNOLOGY, "tech", JoinType.INNER);
scb.add(eq("tech.id", technologyId));
return scb.list().getEntities();
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class TechnologyProductionLineModelHooks method setNewMasterProductionLine.
private void setNewMasterProductionLine(final DataDefinition dataDefinition, final Entity entity) {
SearchCriteriaBuilder searchCriteria = dataDefinition.find();
searchCriteria.add(SearchRestrictions.eq(TechnologyProductionLineFields.MASTER, true));
searchCriteria.add(SearchRestrictions.belongsTo(TechnologyProductionLineFields.TECHNOLOGY, entity.getBelongsToField(TechnologyProductionLineFields.TECHNOLOGY)));
Entity masterTechnologyProductionLine = searchCriteria.uniqueResult();
if (masterTechnologyProductionLine != null && masterTechnologyProductionLine.getId().equals(entity.getId()) || masterTechnologyProductionLine == null || !entity.getBooleanField(TechnologyProductionLineFields.MASTER)) {
return;
}
masterTechnologyProductionLine.setField(TechnologyProductionLineFields.MASTER, false);
dataDefinition.save(masterTechnologyProductionLine);
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class ReservationsServiceForProductsToIssue method calculateIssuedQuantityForProduct.
private BigDecimal calculateIssuedQuantityForProduct(Entity productToIssue) {
Entity warehouseIssue = productToIssue.getBelongsToField(ProductsToIssueFields.WAREHOUSE_ISSUE);
Entity product = productToIssue.getBelongsToField(ProductsToIssueFields.PRODUCT);
Entity additionalCode = productToIssue.getBelongsToField(ProductsToIssueFields.ADDITIONAL_CODE);
Entity location = productToIssue.getBelongsToField(ProductsToIssueFields.LOCATION);
BigDecimal conversion = productToIssue.getDecimalField(ProductsToIssueFields.CONVERSION);
SearchCriteriaBuilder findIssue = getIssueDD().find();
findIssue.add(SearchRestrictions.belongsTo(IssueFields.WAREHOUSE_ISSUE, warehouseIssue));
findIssue.add(SearchRestrictions.belongsTo(IssueFields.PRODUCT, product));
findIssue.add(SearchRestrictions.belongsTo(IssueFields.ADDITIONAL_CODE, additionalCode));
findIssue.add(SearchRestrictions.belongsTo(IssueFields.LOCATION, location));
findIssue.add(SearchRestrictions.eq(IssueFields.CONVERSION, conversion));
findIssue.add(SearchRestrictions.eq(IssueFields.ISSUED, Boolean.TRUE));
return findIssue.list().getEntities().stream().map(issue -> issue.getDecimalField(IssueFields.ISSUE_QUANTITY)).reduce(BigDecimal.ZERO, (a, b) -> (a.add(b)));
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class IssueCommonDetailsHelper method findStorageLocationForProduct.
public Optional<Entity> findStorageLocationForProduct(final Entity product, final Entity location) {
SearchCriteriaBuilder scb = getStorageLocationDD().find();
scb.add(SearchRestrictions.belongsTo(StorageLocationFields.PRODUCT, product));
scb.add(SearchRestrictions.belongsTo(StorageLocationFields.LOCATION, location));
scb.add(SearchRestrictions.eq(StorageLocationFields.ACTIVE, true));
return Optional.ofNullable(scb.setMaxResults(1).uniqueResult());
}
Aggregations