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;
}
Aggregations