use of org.finos.waltz.model.cost.EntityCost in project waltz by khartec.
the class CostService method summariseByCostKindAndSelector.
public EntityCostsSummary summariseByCostKindAndSelector(Long costKindId, IdSelectionOptions selectionOptions, EntityKind targetKind, int limit) {
GenericSelector genericSelector = genericSelectorFactory.applyForKind(targetKind, selectionOptions);
Set<EntityCost> topCosts = time("topCosts: " + selectionOptions.entityReference(), () -> costDao.findTopCostsForCostKindAndSelector(costKindId, genericSelector, limit));
Integer year = maybeFirst(topCosts).map(EntityCost::year).orElse(LocalDate.now().getYear());
BigDecimal totalCost = time("totalCosts: " + selectionOptions.entityReference(), () -> costDao.getTotalForKindAndYearBySelector(costKindId, year, genericSelector));
Tuple2<Integer, Integer> mappedAndMissingCounts = time("missingCosts: " + selectionOptions.entityReference(), () -> costDao.getMappedAndMissingCountsForKindAndYearBySelector(costKindId, year, genericSelector));
return ImmutableEntityCostsSummary.builder().costKind(costKindDao.getById(costKindId)).year(year).total(ofNullable(totalCost).orElse(BigDecimal.ZERO)).topCosts(topCosts).mappedCount(mappedAndMissingCounts.v1).missingCount(mappedAndMissingCounts.v2).build();
}
Aggregations