Skip to content

Instantly share code, notes, and snippets.

@GayanM
Created September 25, 2022 10:21
Show Gist options
  • Save GayanM/92121a44d96b9c92bb9cb4dfdcd69c77 to your computer and use it in GitHub Desktop.
Save GayanM/92121a44d96b9c92bb9cb4dfdcd69c77 to your computer and use it in GitHub Desktop.
Calculate total lump sum of all orders placed in Feb 2021:Answ=11995.36
@RequestMapping("/lump-sum")
public Double lumpSumOfOrders (@RequestParam("month") final int month) {
return orderRepo.findAll()
.stream()
.filter(o -> o.getOrderDate().compareTo(LocalDate.of(2021, month, 1)) >= 0)
.filter(o -> o.getOrderDate().compareTo(LocalDate.of(2021, month + 1, 1)) < 0)
.flatMap(o -> o.getProducts().stream())
.mapToDouble(p -> p.getPrice())
.sum();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment