JSONObject json = newJSONObject();
String dataType= request.getParameter("dataType");
String channelId= request.getParameter("channelId");
String order= request.getParameter("type");
setMapTimeRight(dataType,0);
map.put("channelId", channelId);
map.put("order", order);try{
List now = this.service
.unconventionBrandSituation(map);//1、产生组装排序条件字段数据标记
int bigIdOrder=0;int i=-1;int i2=0;
List bigIdOrderArray= newArrayList();for(UnconventionBrandAnalyseByBrand un : now){
i++;//如果当前bigId与前一个bigId相等,则将该id视为一个id(bigIdOrder),对该id所对应的所有频次数进行累加
if(i==0
&&now.get(0).getBigId().equals(now.get(1).getBigId())){//第一次计数后有(非分组条件)
bigIdOrder = bigIdOrder+Integer.parseInt(now.get(i).getPinci());
}else if(i>0
&&i
&&!now.get(i).getBigId().equals(now.get(i-1).getBigId())&&now.get(i).getBigId().equals(now.get(i+1).getBigId())){//前不同后相同(非分组条件)
bigIdOrder = bigIdOrder+Integer.parseInt(now.get(i).getPinci());
}else if(i>0
&&i
&&now.get(i).getBigId().equals(now.get(i+1).getBigId())&&now.get(i).getBigId().equals(now.get(i+1).getBigId())){//前相同后相同(非分组条件)
bigIdOrder = bigIdOrder+Integer.parseInt(now.get(i).getPinci());
}else{//分组条件
bigIdOrder = bigIdOrder+Integer.parseInt(now.get(i).getPinci());
un.setBigIdOrder(bigIdOrder+"");//添加分组标识(int类型bigIdOrder)
bigIdOrderArray.add(i2, bigIdOrder+"");
i2++;
bigIdOrder= 0;
}
}//2、补全产生组装排序条件字段数据标记
int ii = 0;int ng = 0;//非分组条件计数器
for(UnconventionBrandAnalyseByBrand un : now) {//如果当前bigId与前一个bigId相等,则将该id视为一个id(bigIdOrder),对该id所对应的所有频次数进行累加
if (ii == 0
&& !now.get(0).getBigId().equals(now.get(1).getBigId())) {//第一次计数后无(分组条件)
} else if (ii > 0
&& i < now.size() - 1
&&now.get(ii).getBigId().equals(
now.get(ii- 1).getBigId())&& !now.get(ii).getBigId().equals(
now.get(ii+ 1).getBigId())) {//前同后不同(分组条件)
} else if (ii == now.size() - 1
&&now.get(ii).getBigId().equals(
now.get(ii- 1).getBigId())) {//后无前同(分组条件)
} else if (ii == now.size() - 1
&& !now.get(ii).getBigId().equals(
now.get(ii- 1).getBigId())) {//后无前不同(分组条件)
} else{//非分组条件
if (ii == 0) {
un.setBigIdOrder(bigIdOrderArray.get(0).toString());
}else if (!now.get(ii).getBigId().equals(
now.get(ii- 1).getBigId())) {
ng++;
un.setBigIdOrder(bigIdOrderArray.get(ng).toString());
}else{
un.setBigIdOrder(bigIdOrderArray.get(ng).toString());
}
}
ii++;
}//3、开始排序采用对象比较器
Comparator comparator = new Comparator() {public intcompare(UnconventionBrandAnalyseByBrand s1,
UnconventionBrandAnalyseByBrand s2) {//排序标记
int ret = 0;if (s1.getBigIdOrder() !=s2.getBigIdOrder()) {
ret=Integer.parseInt(s1.getBigIdOrder())-Integer.parseInt(s2.getBigIdOrder());
}return ret > 0 ? -1 : 1;//升序或者降序改变-1和1的位置即可
}
};//开始自动排序
Collections.sort(now,comparator);
json.put("data", now);try{
response.setContentType("text/html;charset=UTF-8");
PrintWriter out=response.getWriter();
out.print(json);
out.close();
}catch(Exception e) {
e.printStackTrace();
}
}catch(Exception e) {
e.printStackTrace();
}return null;