数据库查询的List数据结构为:
[ QuerySnsInfo (
id = NULL,
snscode = 110931243@qq.com,
times = NULL,
cdate = NULL,
uname = NULL,
num = NULL,
comments = NULL,
STATUS = NULL,
NAME = NULL,
type = NULL,
CODE = NULL,
person = NULL,
phone = NULL,
bdphone = NULL,
province = NULL,
city = NULL,
sort = NULL,
stTime = NULL,
endTime = NULL,
nums = NULL,
dates = NULL,
years = 2017,
months = 11,12,(月份,这里使用,分割)
numss = 11,12(月份对应的num值)
),
QuerySnsInfo (
id = NULL,
snscode = zhanhongjiaoyu,
times = NULL,
cdate = NULL,
uname = NULL,
num = NULL,
comments = NULL,
STATUS = NULL,
NAME = NULL,
type = NULL,
CODE = NULL,
person = NULL,
phone = NULL,
bdphone = NULL,
province = NULL,
city = NULL,
sort = NULL,
stTime = NULL,
endTime = NULL,
nums = NULL,
dates = NULL,
years = 2017,
months = 12,11,
numss = 12,11
) ]
希望导出excel合并一行:实现样式如下:
号码 | 年份 | 1月 | 2月 | 3月 | 4月 | 5月 | 6月 | 7月 | 8月 | 9月 | 10月 | 11月 | 12月 |
zhanhongjiaoyu | 2017 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 11 | 12 |
110931243@qq.com | 2017 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 11 | 12 |
可是自己做出来的结果样式为:
号码 | 年份 | 1月 | 2月 | 3月 | 4月 | 5月 | 6月 | 7月 | 8月 | 9月 | 10月 | 11月 | 12月 | ||||||||||||
zhanhongjiaoyu | 2017 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 12 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 11 | 0 |
110931243@qq.com | 2017 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 11 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 12 |
代码如下:
public List<List<String>> userJoint(List<QuerySnsInfo> snsInfoList) throws NumberFormatException, ParseException {
List<List<String>> list = new ArrayList<List<String>>();
//List<String> info = new ArrayList<String>();
Map<String, List<QuerySnsInfo>> map = snsInfoList.stream().collect(Collectors.groupingBy(QuerySnsInfo::getSnscode));
for (Entry<String, List<QuerySnsInfo>> entry : map.entrySet()) {
List<String> info = new ArrayList<String>();
info.add(entry.getKey());
List<QuerySnsInfo> infoList = entry.getValue();
for(QuerySnsInfo sns : infoList){
info.add(sns.getYears());
String month[] = sns.getMonths().split(",");
String[] num = sns.getNumss().split(",");
for (int k = 0; k <month.length; k++) {
for(int j=1;j<=12;j++){
if(month[k].replace("0", "").equals(String.valueOf(j))){
info.add(num[k]);
}else{
sns.setNumss("0");
info.add(sns.getNumss());
}
}
}
}
list.add(info);
}
return list;
}
求大神指导。谢谢!