統計介面,最下面加 總計 一行時
public List<GateBaseBResultStatis> gateBaseBResultStatisTotal(List<GateBaseBResultStatis> list){ GateBaseBResultStatis model = new GateBaseBResultStatis(); model.setAddvcd("總計"); model.setTotalCount(list.stream().map(GateBaseBResultStatis :: getTotalCount).reduce(BigDecimal.ZERO, BigDecimal :: add).setScale(2, BigDecimal.ROUND_HALF_UP)); model.setGateNumberCount(list.stream().map(GateBaseBResultStatis :: getGateNumberCount).reduce(BigDecimal.ZERO, BigDecimal :: add).setScale(2, BigDecimal.ROUND_HALF_UP)); model.setGateNumberRate(model.getGateNumberCount().divide(model.getTotalCount(), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100")) + "%"); list.add(model); return list; }
需要注意,屬性也要用BigDecimal 修飾,否則 BigDecimal :: add 不能用
//總計 private BigDecimal totalCount;