1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
List<DtoCompte> tmpLst = new ArrayList<DtoCompte>();
billingSummary.stream().collect(Collectors
.groupingBy(p -> List.of(
p.getNumeroFacture(),
p.getNumeroCompte(),
p.getDate())
, toList()
)
).entrySet().stream()
.collect(Collectors.toMap(x -> {
BigDecimal qte = x.getValue().stream().map(DtoCompte::getQuantite).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal total = x.getValue().stream().map(DtoCompte::getTotal).reduce(BigDecimal.ZERO, BigDecimal::add);
return tmpLst.add(new DtoCompte(x.getValue().get(0).getNumeroCompte(), x.getValue().get(0).getPayeur(), x.getValue().get(0).getDate(), x.getValue().get(0).getNumeroFacture(), qte, total));
}, Map.Entry::getValue)).values().stream().collect(Collectors.toList());
billingSummary = tmpLst;
_________________________________________________________________________________
public class DtoCompte {
private final String numeroCompte;
private final String payeur;
private final LocalDate date;
private final String numeroFacture;
private final BigDecimal quantite;
private final BigDecimal total;
@Setter
private boolean alreadyMatched;
public DtoCompte(String numeroCompte, String payeur, LocalDate date, String numeroFacture,
BigDecimal quantite, BigDecimal total) {
this.numeroCompte = numeroCompte;
this.payeur = payeur;
this.date = date;
this.numeroFacture = numeroFacture;
this.quantite = quantite;
this.total = total;
}
public DtoCompte(VueItemCommandeForEtatDeCompte vueItemCommandeForEtatDeCompte) {
this.numeroCompte = vueItemCommandeForEtatDeCompte.getNumeroCompte();
this.payeur = vueItemCommandeForEtatDeCompte.getPayeur();
this.date = vueItemCommandeForEtatDeCompte.getDateFacture();
this.numeroFacture = vueItemCommandeForEtatDeCompte.getNumeroFacture();
this.quantite = vueItemCommandeForEtatDeCompte.getQuantite();
this.total = vueItemCommandeForEtatDeCompte.getTotal();
}
public LocalDate getDate() {
return date;
}
public String getPayeur() {
return payeur;
}
public String getNumeroFacture() {
return numeroFacture;
}
public BigDecimal getQuantite() {
return quantite;
}
public BigDecimal getTotal() {
return total;
}
public String getNumeroCompte() {
return numeroCompte;
}
public boolean hasSameFacture(DtoCompte other) {
return other != null && equalsIgnoreCase(numeroFacture, other.numeroFacture) && Objects
.equals(date, other.date);
}
public boolean hasSameBillingInfo(DtoCompte other) {
return other != null && quantite.compareTo(other.quantite) == 0 && total.compareTo(other.total) == 0
&& equalsIgnoreCase(stripAccents(payeur), stripAccents(other.payeur));
}
} |
Partager