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;
}

groupBy的更多相关文章

  1. GroupBy(..)的四种声明方式的理解及调用

    这里我们以 List<Student> studs作为 source,但是注意,studs中的学生可以是分别属于不同的班级和年级 先看GroupBy的第一种声明: public stati ...

  2. C# List泛型集合中的GroupBy<>用法

    //根据子项目id得到flowjump实体类 flowJumps = this.FlowJumps; //按工序groupby flowjumps IEnumerable<IGrouping&l ...

  3. entity framework 新手入门篇(3)-entity framework实现orderby,count,groupby,like,in,分页等

    前面我们已经学习了entityframework的基本的增删改查,今天,我们将在EF中实现一些更加贴近于实际功能的SQL方法. 承接上面的部分,我们有一个叫做House的数据库,其中包含house表和 ...

  4. Lambda GroupBy Sum

    DataTable dt = new DataTable(); dt.AsEnumerable().GroupBy(r => r["ShopName"]) .Select(g ...

  5. Atitit  数据存储的分组聚合 groupby的实现attilax总结

    Atitit  数据存储的分组聚合 groupby的实现attilax总结 1. 聚合操作1 1.1. a.标量聚合 流聚合1 1.2. b.哈希聚合2 1.3. 所有的最优计划的选择都是基于现有统计 ...

  6. MongoDB数据库GroupBy查询使用Spring-data-mongondb的实现

    以前用MongoDB数据库都是简单的查询,直接用Query就可以,最近项目中用到了分组查询,完全不一样.第一次遇到,搞了好几天终于有点那意思了. 先上代码: import java.math.BigD ...

  7. HIVE: collect_set(输出未包含在groupby的字段);

    今天帮同事测试,发现代码里有个好用的hive 函数: 1. collect_set 可以输出未包含在groupby里的字段.条件是,这个字段值对应于主键是唯一的. select a, collect_ ...

  8. Groupby - collection processing

    Groupby - collection processing Iterator and Iterable have most of the most useful methods when deal ...

  9. Linq 中按照多个值进行分组(GroupBy)

    Linq 中按照多个值进行分组(GroupBy) .GroupBy(x => new { x.Age, x.Sex }) group emp by new { emp.Age, emp.Sex ...

  10. Linq_Lambda GroupBy使用笔记

    今天看MVC遇到了GroupBY的Lambda表达式..有兴趣详细的看下去..得此笔记..记录之... 不罗嗦..上代码... //得到List<GroupEmail>对象 数据源 var ...

随机推荐

  1. 嵌入式linux中使用 DHCP功能描述

    嵌入式linux中使用 DHCP功能描述 busybox中udhcpc的默认script脚本地址为#define DEFAULT_SCRIPT   CONFIG_UDHCPC_DEFAULT_SCRI ...

  2. HDU-1036 Average is not Fast Enough!

    Average is not Fast Enough! http://acm.hdu.edu.cn/showproblem.php?pid=1036 Problem Description A rel ...

  3. powershell学习

    PowerShell 调试器 在开始运行处,输入powershell ISE回车即可 PowerShell 与操作系统版本 powershell在windows server 2008上自带,但最好在 ...

  4. shell if语句

    方法1: if list :then    #注意,这里是因为放一行了,所以要有";",如果then在下一行就不用“:”了          do something here   ...

  5. 输入n,计算并输出n1+n2+n3+……+n10

    // 方法1:双重循环 #include <stdio.h> void main() { int i,j,n,s,t; scanf("%d",&n); s=0; ...

  6. Linux经久不衰的应用程序

    Linux里面的应用程序一贯以高安全性,高性价比(功能/所占空间),此次记录一下Linux里面比较常用的而且经久不衰的应用程序. Shell:               bash(它结合了 csh ...

  7. HW4.3

    public class Solution { public static void main(String[] args) { final double POUND_PER_KILOGRAM = 2 ...

  8. MSSQL 多个表关联更新

    正确写法2):UPDATE A  SET A.mobilephone = b.mobile FROM tb_contact A,tmp_contact b WHERE A.contact_name = ...

  9. HDU5418.Victor and World(状压DP)

    #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #i ...

  10. js动态删除div元素

    在做用户查找时 由于要把查找的结果动态载入和显示,所以,那些html元素要由Ajax动态生成.用户打开查找界面时,有系统推荐的用户,而当用户按条件查找后,查找的结果动态载入和显示.所以考虑到用js来搞 ...