// 数据源
List<ReportStatisticsAgentInfo> list = reportReceiveTaskMapper.getResourceAgentReportTypequarter(param);
if(null==list || list.size()==0){
return result;
}
// 定义一个map 用于分组
Map<String, List<ReportStatisticsAgentInfo>> mapList = new HashMap<String, List<ReportStatisticsAgentInfo>>();
// 遍历集合以AgentId为键,map.get(key)为值保存到集合中
for (Iterator it = list.iterator(); it.hasNext();) {
// 将循环读取的结果放入对象中
ReportStatisticsAgentInfo rsai = (ReportStatisticsAgentInfo) it.next();
// 如果在这个map中包含有相同的键,这创建一个集合将其存起来
if (mapList.containsKey(rsai.getAgentId())) {
List<ReportStatisticsAgentInfo> syn = mapList.get(rsai.getAgentId());
syn.add(rsai);
// 如果没有包含相同的键,在创建一个集合保存数据
} else {
List<ReportStatisticsAgentInfo> syns = new ArrayList<ReportStatisticsAgentInfo>();
syns.add(rsai);
mapList.put(rsai.getAgentId(), syns);
}
}
/**
* 遍历Map<String, List<ReportStatisticsAgentInfo>> mapList
* 获取每一个List<ReportStatisticsAgentInfo>
* 对List<ReportStatisticsAgentInfo>中的元素按照时间排序
*/
for (Map.Entry<String, List<ReportStatisticsAgentInfo>> m : mapList.entrySet()) {
List<ReportStatisticsAgentInfo> rslist = m.getValue();
int tot = 0;
Collections.sort(rslist, new Comparator<ReportStatisticsAgentInfo>() {
@Override
public int compare(ReportStatisticsAgentInfo o1, ReportStatisticsAgentInfo o2) {
/*Long i = o1.getDayTime().getTime() - o2.getDayTime().getTime();*/
String[] s1 = o1.getStrDayTime().split("-");
int l1 = s1.length;
String[] s2 = o1.getStrDayTime().split("-");
int l2 = s2.length;
int i = Integer.parseInt(s1[l1-1])-Integer.parseInt(s2[l2-1]);
if (i > 0) {
return 1;
} else if (i < 0) {
return -1;
} else {
return 0;
}
}
});
List<ReportStatisticsAgentInfo> list = reportReceiveTaskMapper.getResourceAgentReportTypequarter(param);
if(null==list || list.size()==0){
return result;
}
// 定义一个map 用于分组
Map<String, List<ReportStatisticsAgentInfo>> mapList = new HashMap<String, List<ReportStatisticsAgentInfo>>();
// 遍历集合以AgentId为键,map.get(key)为值保存到集合中
for (Iterator it = list.iterator(); it.hasNext();) {
// 将循环读取的结果放入对象中
ReportStatisticsAgentInfo rsai = (ReportStatisticsAgentInfo) it.next();
// 如果在这个map中包含有相同的键,这创建一个集合将其存起来
if (mapList.containsKey(rsai.getAgentId())) {
List<ReportStatisticsAgentInfo> syn = mapList.get(rsai.getAgentId());
syn.add(rsai);
// 如果没有包含相同的键,在创建一个集合保存数据
} else {
List<ReportStatisticsAgentInfo> syns = new ArrayList<ReportStatisticsAgentInfo>();
syns.add(rsai);
mapList.put(rsai.getAgentId(), syns);
}
}
/**
* 遍历Map<String, List<ReportStatisticsAgentInfo>> mapList
* 获取每一个List<ReportStatisticsAgentInfo>
* 对List<ReportStatisticsAgentInfo>中的元素按照时间排序
*/
for (Map.Entry<String, List<ReportStatisticsAgentInfo>> m : mapList.entrySet()) {
List<ReportStatisticsAgentInfo> rslist = m.getValue();
int tot = 0;
Collections.sort(rslist, new Comparator<ReportStatisticsAgentInfo>() {
@Override
public int compare(ReportStatisticsAgentInfo o1, ReportStatisticsAgentInfo o2) {
/*Long i = o1.getDayTime().getTime() - o2.getDayTime().getTime();*/
String[] s1 = o1.getStrDayTime().split("-");
int l1 = s1.length;
String[] s2 = o1.getStrDayTime().split("-");
int l2 = s2.length;
int i = Integer.parseInt(s1[l1-1])-Integer.parseInt(s2[l2-1]);
if (i > 0) {
return 1;
} else if (i < 0) {
return -1;
} else {
return 0;
}
}
});