• groupBy


    public List groupBy(List list,String flag,String... sortName) throws Exception{
    Map<String,List<Object>> tMap = new HashMap<String,List<Object>>();
    for(Object t : list){
    String filedKey ="";
    for(String filedName : sortName){
    Field field = t.getClass().getDeclaredField(filedName);
    filedKey = field.get(t)+","+filedKey;
    System.out.println("filedName======"+filedKey);
    }

    if(tMap.containsKey(filedKey)){
    tMap.get(filedKey).add(t);
    }else{
    List tList1 = new ArrayList();
    tList1.add(t);
    tMap.put(filedKey,tList1);
    }
    }

    Field fields[]=list.get(0).getClass().getDeclaredFields();//获得对象所有属性
    Field field=null;
    for (int i = 0; i < fields.length; i++) {
    field=fields[i];
    field.setAccessible(true);
    }
    List<CoastClaimResult> claimList = new ArrayList<CoastClaimResult>();
    for(Map.Entry<String,List<Object>> entry : tMap.entrySet()){
    BigDecimal billedAmt=new BigDecimal(0);
    List<String> distinctCountList = new ArrayList<String>();
    CoastClaimResult result = new CoastClaimResult();
    System.out.println("Key = " + entry.getKey());
    for(Object t : entry.getValue()){
    System.out.println(t.toString());

    String bill = (String) t.getClass().getDeclaredField("amount"+flag).get(t);
    billedAmt.add(new BigDecimal(bill));

    String claimNo = (String) t.getClass().getDeclaredField("claimNo").get(t);
    if(!distinctCountList.contains(claimNo)){
    distinctCountList.add(claimNo);
    }

    /*String paid = (String) t.getClass().getDeclaredField("amountpaid").get(t);
    paidAmt.add(new BigDecimal(paid));*/
    }
    for(String filedName : sortName){
    Field f = CoastClaimResult.class.getClass().getDeclaredField("filedName");
    f.setAccessible(true);
    f.set(CoastClaimResult.class, (String) list.get(0).getClass().getDeclaredField("filedName").get(list.get(0)));
    }
    result.setExt1(new BigDecimal(distinctCountList.size()));
    if(flag.equals("billed")){
    result.setBilledAmt(billedAmt);
    result.setTitleCategory("BILLED");
    }else{
    result.setPaidAmt(billedAmt);
    result.setTitleCategory("PAID");
    }

    // result.setPaidAmt(paidAmt);
    claimList.add(result);


    // System.out.println(polNo.toString());
    }

    return claimList;
    }

  • 相关阅读:
    多测师讲解接口测试 _linux中搭建环境cms_高级讲师肖sir
    多测师讲解自动化测试 _RF数据库操作(上)_高级讲师肖sir
    多测师讲解自动化测试 _RF自定义关键字_高级讲师肖sir
    多测师讲解自动化--rf断言(下)--_高级讲师肖sir
    多测师讲解自动化测试 _RFalert弹框._高级讲师肖sir
    Tomcat 自定义默认网站目录
    .tomcat 管理 给tomcat设置用户名和密码登录
    tomcat访问管理页面出现:403 Access Denied 解决方法
    tomcat 日志目录 介绍
    部署 jdk
  • 原文地址:https://www.cnblogs.com/jingRegina/p/6230460.html
Copyright © 2020-2023  润新知