活跃IPTOP10及详情增加时间条件,app增加appType条件查询,时间范围做校验开始时间小于结束时间,
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
package com.nis.web.controller.dashboard;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -12,6 +16,7 @@ import java.util.Set;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.http.client.utils.URIBuilder;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
@@ -85,11 +90,13 @@ public class DashboardController extends BaseController{
|
||||
*/
|
||||
@RequestMapping(value="ipActive")
|
||||
@ResponseBody
|
||||
public List ipActive(){
|
||||
public List ipActive(String beginDate,String endDate){
|
||||
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
||||
List list = new ArrayList();
|
||||
try {
|
||||
String string = HttpClientUtil.get(Constants.DASHBOARD_URL+Constants.TRAFFIC_IPACTIVE);
|
||||
String url =Constants.DASHBOARD_URL+Constants.TRAFFIC_IPACTIVE;
|
||||
url = urlAddDate(url, beginDate, endDate);
|
||||
String string = HttpClientUtil.get(url);
|
||||
Gson gson = new GsonBuilder().create();
|
||||
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
|
||||
logger.debug("活跃IP数据"+fromJsonList);
|
||||
@@ -107,11 +114,13 @@ public class DashboardController extends BaseController{
|
||||
*/
|
||||
@RequestMapping(value="ipActiveMinuteList")
|
||||
@ResponseBody
|
||||
public List ipActiveMinuteList(){
|
||||
public List ipActiveMinuteList(String beginDate,String endDate){
|
||||
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
||||
List list = new ArrayList();
|
||||
try {
|
||||
String string = HttpClientUtil.get(Constants.DASHBOARD_URL+Constants.TRAFFIC_IPACTIVE_FIVEMINUTE);
|
||||
String url=Constants.DASHBOARD_URL+Constants.TRAFFIC_IPACTIVE_FIVEMINUTE;
|
||||
url=urlAddDate(url, beginDate, endDate);
|
||||
String string = HttpClientUtil.get(url);
|
||||
Gson gson = new GsonBuilder().create();
|
||||
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
|
||||
logger.debug("活跃IP1小时,间隔5分钟数据"+fromJsonList);
|
||||
@@ -155,26 +164,50 @@ public class DashboardController extends BaseController{
|
||||
return gson;
|
||||
}
|
||||
@RequestMapping(value="ipActiveList")
|
||||
public String ipActiveList( HttpServletRequest request, HttpServletResponse response, Model model, RedirectAttributes redirectAttributes){
|
||||
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
||||
List<TrafficIpActiveStatistic> ipActiveList = new ArrayList<TrafficIpActiveStatistic>();
|
||||
public String ipActiveList(@RequestParam(value="beginDate",required=false)String beginDate,@RequestParam(value="endDate",required=false)String endDate,HttpServletRequest request, HttpServletResponse response, Model model, RedirectAttributes redirectAttributes){
|
||||
try {
|
||||
String string = HttpClientUtil.get(Constants.DASHBOARD_URL+Constants.TRAFFIC_IPACTIVE_ONEHOUR);
|
||||
|
||||
Gson gson = getIntGson();
|
||||
fromJsonList = gson.fromJson(string, new TypeToken<Map<String, Object>>(){}.getType());
|
||||
logger.debug("活跃IP1小时"+fromJsonList);
|
||||
ipActiveList = gson.fromJson(fromJsonList.get("data").toString(), new TypeToken<List<TrafficIpActiveStatistic>>() {}.getType()) ;
|
||||
// 默认当前时间一小时
|
||||
if(StringUtil.isEmpty(beginDate)||StringUtil.isEmpty(endDate)){
|
||||
Calendar cal = Calendar. getInstance ();
|
||||
cal.setTime(new Date());
|
||||
endDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//获取到完整的时间
|
||||
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1);
|
||||
beginDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());
|
||||
}
|
||||
model.addAttribute("beginDate", beginDate);
|
||||
model.addAttribute("endDate", endDate);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("活跃IP统计错误"+e);
|
||||
addMessage(redirectAttributes,"error","request_service_failed");
|
||||
}
|
||||
|
||||
model.addAttribute("ipActiveList", ipActiveList);
|
||||
return "/dashboard/trafficIpActiveList";
|
||||
}
|
||||
|
||||
/**
|
||||
* 活跃IP TOP10 一小时 间隔5分钟数据
|
||||
*/
|
||||
@RequestMapping(value="ajaxIpActiveList")
|
||||
@ResponseBody
|
||||
public List ajaxIpActiveList(String beginDate,String endDate){
|
||||
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
||||
List list = new ArrayList();
|
||||
try {
|
||||
String url=Constants.DASHBOARD_URL+Constants.TRAFFIC_IPACTIVE_ONEHOUR;
|
||||
url=urlAddDate(url, beginDate, endDate);
|
||||
String string = HttpClientUtil.get(url);
|
||||
Gson gson = getIntGson();
|
||||
fromJsonList = gson.fromJson(string, new TypeToken<Map<String, Object>>(){}.getType());
|
||||
logger.debug("活跃IP1小时"+fromJsonList);
|
||||
list = gson.fromJson(fromJsonList.get("data").toString(), new TypeToken<List<TrafficIpActiveStatistic>>() {}.getType()) ;
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("活跃IP数据获取错误"+e);
|
||||
list.add(Maps.newHashMap("error","request_service_failed"));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
//IP活跃导出
|
||||
@RequestMapping(value = "export")
|
||||
public void exportddos(Model model,HttpServletRequest request,HttpServletResponse response,
|
||||
@@ -512,7 +545,7 @@ public class DashboardController extends BaseController{
|
||||
list = (List<Map>) fromJsonList.get("data");
|
||||
//标签集合
|
||||
// List<CodeResult> codeList = CodeDicUtils.getCodeList("webCode");
|
||||
List<SysDataDictionaryItem> codeList = DictUtils.getDictList("WEBSITE_SERVER");
|
||||
List<SysDataDictionaryItem> codeList = DictUtils.getDictList("WEBSITE_SERVER");//网站名
|
||||
//将数字替换为标签文字
|
||||
if(list!=null&&!list.isEmpty()){
|
||||
for (Map map : list) {
|
||||
@@ -557,7 +590,7 @@ public class DashboardController extends BaseController{
|
||||
list = (List<Map>) fromJsonList.get("data");
|
||||
//标签集合
|
||||
// List<CodeResult> codeList2 = CodeDicUtils.getCodeList("webCode");//网站子域名表获取域名domain
|
||||
List<WebsiteDomainTopic> domainList = appCfgService.getDomainDict(new WebsiteDomainTopic());
|
||||
List<WebsiteDomainTopic> domainList = appCfgService.getDomainDict(new WebsiteDomainTopic());// domain 域名
|
||||
if(list!=null&&list.size()>0&&domainList!=null&&domainList.size()>0){
|
||||
for (Map dataMap : list) {
|
||||
for (WebsiteDomainTopic wdt : domainList) {
|
||||
@@ -744,5 +777,27 @@ public class DashboardController extends BaseController{
|
||||
|
||||
System.out.println(map2.get("c"));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* url路径时间参数格式化
|
||||
* @param url
|
||||
* @param beginDate
|
||||
* @param endDate
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
public String urlAddDate(String url,String beginDate,String endDate) throws URISyntaxException{
|
||||
if(StringUtil.isBlank(beginDate)||StringUtil.isBlank(endDate)){
|
||||
Calendar cal = Calendar. getInstance ();
|
||||
cal.setTime(new Date());
|
||||
endDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//获取到完整的时间
|
||||
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1);
|
||||
beginDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());
|
||||
}
|
||||
URIBuilder uriBuilder = new URIBuilder(url);
|
||||
uriBuilder.addParameter("beginDate",beginDate);
|
||||
uriBuilder.addParameter("endDate",endDate);
|
||||
return uriBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
package com.nis.web.controller.dashboard;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -38,13 +35,10 @@ import com.google.gson.JsonParseException;
|
||||
import com.google.gson.LongSerializationPolicy;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.nis.domain.PageLog;
|
||||
import com.nis.domain.SysDataDictionaryItem;
|
||||
import com.nis.domain.configuration.WebsiteDomainTopic;
|
||||
import com.nis.domain.dashboard.TrafficIpActiveStatistic;
|
||||
import com.nis.util.CodeDicUtils;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.DateUtil;
|
||||
import com.nis.util.DictUtils;
|
||||
import com.nis.util.StringUtil;
|
||||
import com.nis.util.httpclient.HttpClientUtil;
|
||||
import com.nis.web.controller.BaseController;
|
||||
@@ -346,12 +340,15 @@ public class TrafficStatisticsInfoController extends BaseController {
|
||||
*/
|
||||
@RequestMapping(value="appList")
|
||||
@ResponseBody
|
||||
public List appList(@RequestParam(value="beginDate",required=false)String beginDate,@RequestParam(value="endDate",required=false)String endDate){
|
||||
public List appList(@RequestParam(value="appType",required=false)Integer appType,@RequestParam(value="beginDate",required=false)String beginDate,@RequestParam(value="endDate",required=false)String endDate){
|
||||
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
||||
List list = new ArrayList();
|
||||
String url = Constants.DASHBOARD_URL+Constants.TRAFFIC_APP_LIST;
|
||||
try {
|
||||
url=urlAddDate(url,beginDate,endDate);
|
||||
if(!StringUtil.isEmpty(appType)){
|
||||
url=url+"&appType="+appType;
|
||||
}
|
||||
String string = HttpClientUtil.get(url);
|
||||
Gson gson = new GsonBuilder().create();
|
||||
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
|
||||
@@ -388,100 +385,4 @@ public class TrafficStatisticsInfoController extends BaseController {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
/**
|
||||
* 网址类型列表
|
||||
*/
|
||||
@RequestMapping("webTypeList")
|
||||
public String webTypeList(Model model){
|
||||
Calendar cal = Calendar. getInstance ();
|
||||
cal.setTime(new Date());
|
||||
String now = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//获取到完整的时间
|
||||
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1);
|
||||
String oneHoursAgo = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());
|
||||
model.addAttribute("beginDate", oneHoursAgo);
|
||||
model.addAttribute("endDate", now);
|
||||
return "/dashboard/trafficWebTypeList";
|
||||
}
|
||||
/**
|
||||
* 网站统计图跟表
|
||||
*/
|
||||
@RequestMapping(value="websiteList")
|
||||
@ResponseBody
|
||||
public List websiteList(Model model,@RequestParam(required=false)String beginDate,@RequestParam(required=false)String endDate){
|
||||
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
||||
List list = new ArrayList();
|
||||
String url = Constants.DASHBOARD_URL+Constants.TRAFFIC_WEBSITELIST;
|
||||
// String url = "http://192.168.11.87:8088/galaxy-service/service/log/v1/"+Constants.TRAFFIC_WEBSITELIST;
|
||||
try {
|
||||
url=urlAddDate(url,beginDate,endDate);
|
||||
String string = HttpClientUtil.get(url);
|
||||
Gson gson = new GsonBuilder().create();
|
||||
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
|
||||
logger.debug("website接口数据"+fromJsonList);
|
||||
list = (ArrayList) fromJsonList.get("data");
|
||||
BigDecimal divisor=new BigDecimal(1024*1024*1024);
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
DecimalFormat dl = new DecimalFormat("0");
|
||||
DecimalFormat pf = new DecimalFormat("0.00%");
|
||||
Double totalLink=0d;
|
||||
Double totalGbyte=0d;
|
||||
Double totalPackets=0d;
|
||||
for (Object object : list) {
|
||||
Map m=(Map)object;
|
||||
Double count=(Double)m.get("count");
|
||||
totalGbyte+=count;
|
||||
totalLink+=(Double)m.get("linkNum");
|
||||
totalPackets+=(Double)m.get("packets");
|
||||
String format = df.format(count/1024/1024/1024);
|
||||
m.put("Gbyte", format);
|
||||
}
|
||||
List<WebsiteDomainTopic> codeList = appCfgService.getDomainDict(new WebsiteDomainTopic());
|
||||
Map<Long, String> map = new HashMap<Long,String>();
|
||||
for (WebsiteDomainTopic websiteDomainTopic : codeList) {
|
||||
if(!map.containsKey(websiteDomainTopic.getWebsiteServiceId())){
|
||||
map.put(websiteDomainTopic.getId(),websiteDomainTopic.getDomain());
|
||||
}
|
||||
}
|
||||
for (Object object : list) {
|
||||
Map m=(Map)object;
|
||||
Double perLink = ((Double)m.get("linkNum"))/totalLink;
|
||||
m.put("perLink",pf.format(perLink));
|
||||
Double perPackets = ((Double)m.get("packets"))/totalPackets;
|
||||
m.put("perPackets", pf.format(perPackets));
|
||||
Double perGbyte = ((Double)m.get("count"))/totalGbyte;
|
||||
m.put("perGbyte", pf.format(perGbyte));
|
||||
if(map.containsKey(Long.parseLong(dl.format(m.get("webId"))))){
|
||||
m.put("website", map.get(Long.parseLong(dl.format(m.get("webId")))));
|
||||
}
|
||||
}
|
||||
Collections.sort(list, new Comparator<Object>() {
|
||||
|
||||
@Override
|
||||
public int compare(Object o1, Object o2) {
|
||||
if(o1==null&&o2!=null){
|
||||
return 1;
|
||||
}
|
||||
if(o1!=null&&o2==null){
|
||||
return -1;
|
||||
}
|
||||
if(o1==null&&o2==null){
|
||||
return 0;
|
||||
}
|
||||
Map m1=(Map)o1;
|
||||
Map m2=(Map)o2;
|
||||
if((Double)m1.get("count")==(Double)m2.get("count")){
|
||||
return 0;
|
||||
}
|
||||
int result=((Double)m1.get("count")-(Double)m2.get("count"))>0?-1:1;
|
||||
return result;
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("网站域名数据获取错误"+e);
|
||||
list.add(Maps.newHashMap("error","request_service_failed"));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user