List重复合并

  • Post author:
  • Post category:其他


List根据两个属性判重,将值累加合并。

List<FmsVoucherSub> list = voucherVo.getSubList();

List<FmsVoucherSub> hebingList = new ArrayList<>();
list.parallelStream().collect(Collectors.groupingBy(o -> (o.getAccountType() + o.getAccountName()), Collectors.toList())).forEach((id, transfer) -> {
                    transfer.stream().reduce((a, b) -> new FmsVoucherSub(
                            a.getId(),
                            a.getEntryId(),
                            a.getAccountType(),
                            a.getAccountCode(),
                            a.getAccountName(),
                            a.getNaturalDebitCurrency()+b.getNaturalDebitCurrency(),
                            a.getNaturalCreditCurrency()+b.getNaturalCreditCurrency(),
                            a.getAbstracts(),
                            a.getCstmName(),
                            a.getSettlement(),
                            a.getDocCode(),
                            a.getCustId(),
                            a.getSupplierName(),
                            a.getSupplierId(),
                            a.getDeptUcode(),
                            a.getDeptUname(),
                            a.getVtype())).ifPresent(hebingList::add);
                });
voucherVo.setSubList(hebingList);



版权声明:本文为u010772100原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。