Kui vaja teha Java mingi class listidega SQL laadne GROUP BY arvutus
InventoryPositionsViewRate on algne klass mis on vaja summeerida tInventorySummaryViewRate listiks
private void calculateSummary(final List<InventoryPositionsViewRate> ipwr) {
// Calculates sum GROUP BY branch, currency
this.listInventorySummaryViewRate = ipwr.parallelStream()
.collect(Collectors.groupingBy(Function.identity(),
() -> new TreeMap<>(Comparator.<InventoryPositionsViewRate, String> comparing(InventoryPositionsViewRate::getBranchDisplayName)
.thenComparing(InventoryPositionsViewRate::getCurrencyCode)
.thenComparing(InventoryPositionsViewRate::getRate)), //getRate is nessesary for localAmount calculating
Collectors.summingDouble(foo -> foo.getAmount().doubleValue())))
.entrySet().stream()
.map(iswr -> new InventoryPositionsSummaryRate(iswr.getKey().getBranchDisplayName(),
iswr.getKey().getCurrencyCode(), BigDecimal.valueOf(iswr.getValue()), iswr.getKey().getRate()))
.collect(Collectors.toList());
}
esmaspäev, 1. juuli 2019
Tellimine:
Postitused (Atom)