Search in sources :

Example 6 with SearchCriteriaBuilder

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;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) DataDefinition(com.qcadoo.model.api.DataDefinition) BigDecimal(java.math.BigDecimal)

Example 7 with SearchCriteriaBuilder

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();
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 8 with SearchCriteriaBuilder

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);
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 9 with SearchCriteriaBuilder

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)));
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) ProductsToIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.ProductsToIssueFields) IssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.IssueFields) Autowired(org.springframework.beans.factory.annotation.Autowired) ReservationFields(com.qcadoo.mes.materialFlowResources.constants.ReservationFields) BigDecimalUtils(com.qcadoo.model.api.BigDecimalUtils) DataDefinition(com.qcadoo.model.api.DataDefinition) BigDecimal(java.math.BigDecimal) MaterialFlowResourcesConstants(com.qcadoo.mes.materialFlowResources.constants.MaterialFlowResourcesConstants) Entity(com.qcadoo.model.api.Entity) Lists(com.google.common.collect.Lists) ParameterService(com.qcadoo.mes.basic.ParameterService) Service(org.springframework.stereotype.Service) WarehouseIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.WarehouseIssueFields) Optional(java.util.Optional) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) ProductFlowThruDivisionConstants(com.qcadoo.mes.productFlowThruDivision.constants.ProductFlowThruDivisionConstants) Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) BigDecimal(java.math.BigDecimal)

Example 10 with SearchCriteriaBuilder

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());
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Aggregations

SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)176 Entity (com.qcadoo.model.api.Entity)82 DataDefinition (com.qcadoo.model.api.DataDefinition)26 Autowired (org.springframework.beans.factory.annotation.Autowired)19 Service (org.springframework.stereotype.Service)19 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)18 EntityList (com.qcadoo.model.api.EntityList)17 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)17 Collectors (java.util.stream.Collectors)17 SearchResult (com.qcadoo.model.api.search.SearchResult)16 SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)14 Objects (java.util.Objects)14 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)11 BigDecimal (java.math.BigDecimal)11 Set (java.util.Set)11 UserFieldsMF (com.qcadoo.mes.materialFlow.constants.UserFieldsMF)10 UserLocationFields (com.qcadoo.mes.materialFlow.constants.UserLocationFields)10 SecurityService (com.qcadoo.security.api.SecurityService)10 QcadooSecurityConstants (com.qcadoo.security.constants.QcadooSecurityConstants)10 CustomRestriction (com.qcadoo.model.api.search.CustomRestriction)8