Authored by qinchao

恶意ip排序

... ... @@ -59,6 +59,8 @@ public class MaliciousIp {
*/
private String time;
private long ts;
/**/
/*private List<String> reason;
private List<String> duration;*/
... ... @@ -152,6 +154,15 @@ public class MaliciousIp {
this.reasonDur = reasonDur;
}
public long getTs() {
return ts;
}
public void setTs(long ts) {
this.ts = ts;
}
@Override
public String toString() {
return "MaliciousIp [ip=" + ip + ", qps=" + qps + ", allCount=" + allCount + ", impCount=" + impCount + ", ipPrecent="
... ...
... ... @@ -241,6 +241,7 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
//组装数据
List<MaliciousIp> listMaliciousIp = new ArrayList<MaliciousIp>();
long ts=0l;
for(String mipKey : mipKeys){
MaliciousIp mip = new MaliciousIp();
mip.setIp(mipKey);
... ... @@ -253,6 +254,7 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
try{
MaliciousIpModel model=JSON.parseObject(reason,MaliciousIpModel.class);
reason=model.toHtmlString();
ts=model.getTimestamp();
}catch (Exception e){
//
}
... ... @@ -271,6 +273,9 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
try{
MaliciousIpModel model=JSON.parseObject(reason,MaliciousIpModel.class);
reason=model.toHtmlString();
if(ts<model.getTimestamp()){
ts=model.getTimestamp();
}
}catch (Exception e){
//
}
... ... @@ -281,8 +286,21 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
//reasonDur += "qcloud: " + qcloudInfo.get("dur")+ " -- "+ qcloudInfo.get("reason") ;
}
mip.setReasonDur(reasonDur);
mip.setTs(ts);
listMaliciousIp.add(mip);
}
//排序
Collections.sort(listMaliciousIp,new Comparator<MaliciousIp>(){
public int compare(MaliciousIp arg0, MaliciousIp arg1) {
long compare= arg0.getTs() - arg1.getTs();
if(compare<0L){
return -1;
}else{
return 1;
}
}
});
response.setData(listMaliciousIp);
return response;
}
... ...