复杂表格 非固定格式表格显示

 

 

public class TestReport {
    public static void main(String[] args) {
        Set<Integer> months = new HashSet<>();
        Set<String> names = new HashSet<>();
        List<Map<String, Object>> list = Lists.newArrayList(
                new HashMap<String, Object>() {{
                    put("money", BigDecimal.valueOf(34593L));
                    put("name", "刘助理");
                    put("monthStr", 6);
                }},
                new HashMap<String, Object>() {{
                    put("money", BigDecimal.valueOf(34593L));
                    put("name", "刘助理");
                    put("monthStr", 7);
                }},
                new HashMap<String, Object>() {{
                    put("money", BigDecimal.valueOf(34593L));
                    put("name", "陈助理");
                    put("monthStr", 7);
                }}
        );
        System.out.println(list);
        List<Integer> month = new ArrayList<>();
        Map<String, Object> result = new HashMap<>();
        list.forEach(stringObjectMap -> {
            // get month
            months.add((Integer) stringObjectMap.get("monthStr"));
            names.add((String) stringObjectMap.get("name"));
        });
        List<Dto> listDto = new ArrayList<>();
        months.iterator().forEachRemaining(m -> {
            Dto dto = new Dto();
            dto.setMonth(m);
            Map map = new HashMap<>();
            list.forEach(stringObjectMap -> {
                Integer mm = (Integer) stringObjectMap.get("monthStr");
                if (m.intValue() == mm.intValue()) {
                    BigDecimal bg = dto.getAllMoney()==null?BigDecimal.ZERO:dto.getAllMoney();
                    dto.setAllMoney(bg.add((BigDecimal) stringObjectMap.get("money")));
                    map.put(stringObjectMap.get("name"), stringObjectMap.get("money"));
                }
            });
            dto.setMap(map);
            listDto.add(dto);
        });
        System.out.println(listDto.toString());
        System.out.println("=======================================");
        System.out.print("月份\t");
        names.forEach(n->{
            System.out.print(n+"\t");
        });
        System.out.print("工计\t");
        System.out.println();

        listDto.forEach(dto -> {
            System.out.print(dto.getMonth()+"\t");
            names.forEach(n->{
                System.out.print(dto.getMap().get(n)+"\t");
            });
            System.out.print(dto.getAllMoney()+"\t");
            System.out.println();
        });
    }
}


class Dto {
    private Integer month;
    private BigDecimal allMoney;
    private Map map;

    @Override
    public String toString() {
        return "Dto{" +
                "month=" + month +
                ", allMoney=" + allMoney +
                ", map=" + map +
                '}';
    }

    public Integer getMonth() {
        return month;
    }

    public void setMonth(Integer month) {
        this.month = month;
    }

    public BigDecimal getAllMoney() {
        return allMoney;
    }

    public void setAllMoney(BigDecimal allMoney) {
        this.allMoney = allMoney;
    }

    public Map getMap() {
        return map;
    }

    public void setMap(Map map) {
        this.map = map;
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值