Authored by qinchao

恶意ip排序

@@ -59,6 +59,8 @@ public class MaliciousIp { @@ -59,6 +59,8 @@ public class MaliciousIp {
59 */ 59 */
60 private String time; 60 private String time;
61 61
  62 + private long ts;
  63 +
62 /**/ 64 /**/
63 /*private List<String> reason; 65 /*private List<String> reason;
64 private List<String> duration;*/ 66 private List<String> duration;*/
@@ -152,6 +154,15 @@ public class MaliciousIp { @@ -152,6 +154,15 @@ public class MaliciousIp {
152 this.reasonDur = reasonDur; 154 this.reasonDur = reasonDur;
153 } 155 }
154 156
  157 + public long getTs() {
  158 + return ts;
  159 + }
  160 +
  161 + public void setTs(long ts) {
  162 + this.ts = ts;
  163 + }
  164 +
  165 +
155 @Override 166 @Override
156 public String toString() { 167 public String toString() {
157 return "MaliciousIp [ip=" + ip + ", qps=" + qps + ", allCount=" + allCount + ", impCount=" + impCount + ", ipPrecent=" 168 return "MaliciousIp [ip=" + ip + ", qps=" + qps + ", allCount=" + allCount + ", impCount=" + impCount + ", ipPrecent="
@@ -241,6 +241,7 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { @@ -241,6 +241,7 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
241 241
242 //组装数据 242 //组装数据
243 List<MaliciousIp> listMaliciousIp = new ArrayList<MaliciousIp>(); 243 List<MaliciousIp> listMaliciousIp = new ArrayList<MaliciousIp>();
  244 + long ts=0l;
244 for(String mipKey : mipKeys){ 245 for(String mipKey : mipKeys){
245 MaliciousIp mip = new MaliciousIp(); 246 MaliciousIp mip = new MaliciousIp();
246 mip.setIp(mipKey); 247 mip.setIp(mipKey);
@@ -253,6 +254,7 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { @@ -253,6 +254,7 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
253 try{ 254 try{
254 MaliciousIpModel model=JSON.parseObject(reason,MaliciousIpModel.class); 255 MaliciousIpModel model=JSON.parseObject(reason,MaliciousIpModel.class);
255 reason=model.toHtmlString(); 256 reason=model.toHtmlString();
  257 + ts=model.getTimestamp();
256 }catch (Exception e){ 258 }catch (Exception e){
257 // 259 //
258 } 260 }
@@ -271,6 +273,9 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { @@ -271,6 +273,9 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
271 try{ 273 try{
272 MaliciousIpModel model=JSON.parseObject(reason,MaliciousIpModel.class); 274 MaliciousIpModel model=JSON.parseObject(reason,MaliciousIpModel.class);
273 reason=model.toHtmlString(); 275 reason=model.toHtmlString();
  276 + if(ts<model.getTimestamp()){
  277 + ts=model.getTimestamp();
  278 + }
274 }catch (Exception e){ 279 }catch (Exception e){
275 // 280 //
276 } 281 }
@@ -281,8 +286,21 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { @@ -281,8 +286,21 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
281 //reasonDur += "qcloud: " + qcloudInfo.get("dur")+ " -- "+ qcloudInfo.get("reason") ; 286 //reasonDur += "qcloud: " + qcloudInfo.get("dur")+ " -- "+ qcloudInfo.get("reason") ;
282 } 287 }
283 mip.setReasonDur(reasonDur); 288 mip.setReasonDur(reasonDur);
  289 + mip.setTs(ts);
284 listMaliciousIp.add(mip); 290 listMaliciousIp.add(mip);
285 } 291 }
  292 + //排序
  293 + Collections.sort(listMaliciousIp,new Comparator<MaliciousIp>(){
  294 + public int compare(MaliciousIp arg0, MaliciousIp arg1) {
  295 + long compare= arg0.getTs() - arg1.getTs();
  296 + if(compare<0L){
  297 + return -1;
  298 + }else{
  299 + return 1;
  300 + }
  301 +
  302 + }
  303 + });
286 response.setData(listMaliciousIp); 304 response.setData(listMaliciousIp);
287 return response; 305 return response;
288 } 306 }