Authored by Xu

恶意ip管理优化

... ... @@ -21,6 +21,11 @@ public class MaliciousDetailIp {
* QPS
*/
private int count;
/**
* 百分比
*/
private double percent;
public String getUserIP() {
return userIP;
... ... @@ -46,8 +51,17 @@ public class MaliciousDetailIp {
this.count = count;
}
public double getPercent() {
return percent;
}
public void setPercent(double percent) {
this.percent = percent;
}
@Override
public String toString() {
return "MaliciousDetailIp [userIP=" + userIP + ", method=" + method + ", count=" + count + "]";
return "MaliciousDetailIp [userIP=" + userIP + ", method=" + method + ", count=" + count + ", percent="
+ percent + "]";
}
}
\ No newline at end of file
... ...
... ... @@ -44,8 +44,8 @@ public class MaliciousIpController {
*/
@RequestMapping("/getDetail")
@ResponseBody
public BaseResponse<List<MaliciousDetailIp>> getDetail(String ip) {
return ipImpl.getDetail(ip);
public BaseResponse<List<MaliciousDetailIp>> getDetail(String ip, String count) {
return ipImpl.getDetail(ip, count);
}
/**
... ...
... ... @@ -25,7 +25,7 @@ public interface MaliciousIpService {
* @param ip
* @return
*/
BaseResponse<List<MaliciousDetailIp>> getDetail(String ip);
BaseResponse<List<MaliciousDetailIp>> getDetail(String ip, String count);
/**
* 上报恶意ip
... ...
... ... @@ -4,6 +4,8 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -67,7 +69,7 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
* 从Redis中获取恶意ip的内容
*/
@Override
public BaseResponse<List<MaliciousDetailIp>> getDetail(String ip) {
public BaseResponse<List<MaliciousDetailIp>> getDetail(String ip, String count) {
BaseResponse<List<MaliciousDetailIp>> response = new BaseResponse<>();
List<MaliciousDetailIp> listMaliciousDetailIp;
try{
... ... @@ -76,6 +78,11 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
return response;
}
listMaliciousDetailIp = (List<MaliciousDetailIp>) JSON.parseArray(detail_json, MaliciousDetailIp.class);
if(NumberUtils.isNumber(count) && CollectionUtils.isNotEmpty(listMaliciousDetailIp)){
for (MaliciousDetailIp maliciousDetailIp : listMaliciousDetailIp) {
maliciousDetailIp.setPercent(maliciousDetailIp.getCount() * 100 / Integer.parseInt(count));
}
}
Comparator comp = new ComparatorDetailIp();
Collections.sort(listMaliciousDetailIp, comp);
response.setData(listMaliciousDetailIp);
... ... @@ -108,9 +115,9 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
public int compare(MaliciousIp e1, MaliciousIp e2) {
int count1 = e1.getCount();
int count2 = e2.getCount();
if (count1 > count2) {
if (count1 < count2) {
return 1;
} else if (count1 < count2) {
} else if (count1 > count2) {
return -1;
} else {
return 0;
... ... @@ -122,9 +129,9 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
public int compare(MaliciousDetailIp e1, MaliciousDetailIp e2) {
int count1 = e1.getCount();
int count2 = e2.getCount();
if (count1 > count2) {
if (count1 < count2) {
return 1;
} else if (count1 < count2) {
} else if (count1 > count2) {
return -1;
} else {
return 0;
... ...