package com.yq.job;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class Mount00 {
public static void main(String[] args) {
List<Compeny> compeny=new ArrayList<Compeny>();
compeny.add(new Compeny("粤嵌", "123", 900, 1));
compeny.add(new Compeny("粤嵌", "123", 600, 2));
compeny.add(new Compeny("粤嵌", "123", 1000, 3));
compeny.add(new Compeny("粤嵌", "123", 800, 5));
compeny.add(new Compeny("粤嵌", "123", 300, 7));
compeny.add(new Compeny("粤嵌", "123", 200, 12));
compeny.add(new Compeny("培华", "124", 900, 1));
compeny.add(new Compeny("培华", "124", 1000, 1));
compeny.add(new Compeny("培华", "124", 750, 5));
compeny.add(new Compeny("培华", "124", 741, 9));
compeny.add(new Compeny("培华", "124", 654, 11));
Map<String, List<Compeny>> resultMap=compeny.stream().collect(Collectors.groupingBy(Compeny::getNo));
List<Map<String, Object>> result=new ArrayList<Map<String,Object>>();
resultMap.entrySet().stream().forEach(entry ->{
Map<String, Object> dataMap = new HashMap<>();
String arr[]=entry.getKey().split("-");
List<Compeny> list_one=entry.getValue();
dataMap.put("no", arr[0]);
int total= list_one.stream().collect(Collectors.summingInt(o->Integer.parseInt(String.valueOf(o.getAmount()))));
dataMap.put("total",total);
result.add(dataMap);
});
System.out.println(result);
}
}
//运行结果
[{no=123, total=3800}, {no=124, total=4045}]