Search in sources :

Example 6 with SearchProjection

use of com.qcadoo.model.api.search.SearchProjection in project mes by qcadoo.

the class StaffTimeCalculator method countTotalLaborTime.

public Long countTotalLaborTime(final Long productionRecordId) {
    SearchCriteriaBuilder scb = getStaffWorkTimeDD().find();
    SearchProjection totalLaborProjection = SearchProjections.alias(SearchProjections.sum(StaffWorkTimeFields.LABOR_TIME), TOTAL_LABOR_PROJECTION_ALIAS);
    SearchProjection rowCntProjection = SearchProjections.rowCount();
    scb.setProjection(SearchProjections.list().add(rowCntProjection).add(totalLaborProjection));
    scb.add(SearchRestrictions.belongsTo(StaffWorkTimeFields.PRODUCTION_RECORD, ProductionCountingConstants.PLUGIN_IDENTIFIER, ProductionCountingConstants.MODEL_PRODUCTION_TRACKING, productionRecordId));
    // Fix for missing id column. Touch on your own risk.
    scb.addOrder(SearchOrders.asc(TOTAL_LABOR_PROJECTION_ALIAS));
    Entity res = scb.setMaxResults(1).uniqueResult();
    if (res == null) {
        return 0L;
    }
    Long totalLabor = (Long) res.getField(TOTAL_LABOR_PROJECTION_ALIAS);
    if (totalLabor == null) {
        return 0L;
    }
    return totalLabor;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchProjection(com.qcadoo.model.api.search.SearchProjection)

Aggregations

SearchProjection (com.qcadoo.model.api.search.SearchProjection)6 Entity (com.qcadoo.model.api.Entity)5 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)4 SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)4 FieldDefinition (com.qcadoo.model.api.FieldDefinition)2 SearchResult (com.qcadoo.model.api.search.SearchResult)2 BigDecimal (java.math.BigDecimal)2 MasterOutputProductCriteria (com.qcadoo.mes.technologies.tree.traversing.MasterOutputProductCriteria)1