统计接口,最下面加 总计 一行时

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;

 

 posted on 2024-08-09 15:39  布鲁布鲁sky  阅读(71)  评论(0编辑  收藏  举报