diff --git a/src/main/java/com/nis/domain/restful/dashboard/TrafficIpActiveStatistic.java b/src/main/java/com/nis/domain/restful/dashboard/TrafficIpActiveStatistic.java index 94c081d..c6aed49 100644 --- a/src/main/java/com/nis/domain/restful/dashboard/TrafficIpActiveStatistic.java +++ b/src/main/java/com/nis/domain/restful/dashboard/TrafficIpActiveStatistic.java @@ -32,8 +32,19 @@ public class TrafficIpActiveStatistic extends BaseEntity trafficIpActive(Model model, HttpServletRequest request, HttpServletResponse response) { + public Map trafficIpActive(String beginDate, String endDate ,Model model, HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); List list = new ArrayList(); try { - List ipActiveChart = dashboardService.ipActiveChart(); + Date begin=null; + Date end=null; + if(StringUtils.isEmpty(beginDate)||StringUtils.isEmpty(endDate)) { + Calendar cal = Calendar. getInstance (); + cal.setTime(new Date()); + begin = cal.getTime();//获取到完整的时间 + cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1); + end = cal.getTime(); + }else { + begin = DateUtils.parseDate(beginDate); + end = DateUtils.parseDate(endDate); + } + + List ipActiveChart = dashboardService.ipActiveChart(begin,end); if (ipActiveChart!=null&&ipActiveChart.size() > 0) { list = ipActiveChart; } @@ -322,13 +336,15 @@ public class DashboardServiceController extends BaseRestController { */ @RequestMapping(value = "trafficIpActiveOneHour", method = RequestMethod.GET) @ApiOperation(value = "活跃IP统计一个小时的活跃IP", httpMethod = "GET", notes = "对应活跃IP实时统计查询服务。") - public Map trafficIpActiveOneHour(Model model, HttpServletRequest request, HttpServletResponse response) { + public Map trafficIpActiveOneHour(String beginDate, String endDate ,Model model, HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); List list = new ArrayList(); try { - List ipActiveChart = dashboardService.ipActiveOneHour(); + Date begin = DateUtils.parseDate(beginDate); + Date end = DateUtils.parseDate(endDate); + List ipActiveChart = dashboardService.ipActiveOneHour(begin,end); if (ipActiveChart!=null&&ipActiveChart.size() > 0) { list = ipActiveChart; } @@ -353,13 +369,19 @@ public class DashboardServiceController extends BaseRestController { */ @RequestMapping(value = "trafficIpActiveFiveMinute", method = RequestMethod.GET) @ApiOperation(value = "活跃IP最近一个小时的变化趋势统计", httpMethod = "GET", notes = "对最新TOP10的活跃IP,在近一个小时的变化情况进行统计") - public Map trafficIpActiveFiveMinute(Model model, HttpServletRequest request, HttpServletResponse response) { + public Map trafficIpActiveFiveMinute(String beginDate, String endDate ,Model model, HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); List list = new ArrayList(); try { - List ipActiveChart = dashboardService.ipActiveFiveMinute(); + Date begin=null; + Date end=null; + if(!StringUtils.isEmpty(beginDate)&&!StringUtils.isEmpty(endDate)) { + begin=DateUtils.parseDate(beginDate); + end=DateUtils.parseDate(endDate); + } + List ipActiveChart = dashboardService.ipActiveFiveMinute(begin,end); if (ipActiveChart!=null&&ipActiveChart.size() > 0) { list = ipActiveChart; } @@ -415,12 +437,12 @@ public class DashboardServiceController extends BaseRestController { */ @RequestMapping(value="trafficAppList", method = RequestMethod.GET) @ApiOperation(value = "App统计占比与报表", httpMethod = "GET", notes = "对应App统计详情占比与报表") - public Map trafficAppList(String beginDate,String endDate,Model model, HttpServletRequest request, HttpServletResponse response){ + public Map trafficAppList(Integer appType,String beginDate,String endDate,Model model, HttpServletRequest request, HttpServletResponse response){ long start = System.currentTimeMillis(); AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); List list = new ArrayList(); try { - List appList = dashboardService.getAppList(beginDate,endDate); + List appList = dashboardService.getAppList(beginDate,endDate,appType); if (appList!=null&&appList.size() > 0) { String jsonString = JsonMapper.toJsonString(appList); list = (java.util.List) JsonMapper.fromJsonList(jsonString,HashMap.class); @@ -554,17 +576,28 @@ public class DashboardServiceController extends BaseRestController { } @RequestMapping(value = "trafficWebsiteList", method = RequestMethod.GET) @ApiOperation(value = "网站流量分析统计", httpMethod = "GET", notes = "对应网站http分类显示") - public Map trafficWebsiteList(Model model, HttpServletRequest request, HttpServletResponse response) { + public Map trafficWebsiteList(String beginDate,String endDate,Model model, HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); List list = new ArrayList(); try { -// List websiteChart = dashboardService.websiteList(); - List websiteChart = dashboardService.getDomainByWebsiteList(); - if (websiteChart!=null&&websiteChart.size() > 0) { - list = websiteChart; + if(!StringUtils.isEmpty(beginDate)&&!StringUtils.isEmpty(endDate)) { + Date begin = DateUtils.parseDate(beginDate); + Date end = DateUtils.parseDate(endDate); + // 带查询时间查询所有 + List websiteChart = dashboardService.getWebsiteDetails(begin,end); + if (websiteChart!=null&&websiteChart.size() > 0) { + list = websiteChart; + } + }else { + // 不带时间默认top10 + List websiteChart = dashboardService.getWebsiteTop10(); + if (websiteChart!=null&&websiteChart.size() > 0) { + list = websiteChart; + } } + } catch (Exception e) { auditLogThread.setExceptionInfo("网站流量分析统计数据检索失败:"+e.getMessage()); logger.error("网站流量分析统计数据检索失败:"+ExceptionUtil.getExceptionMsg(e)); @@ -583,16 +616,28 @@ public class DashboardServiceController extends BaseRestController { } @RequestMapping(value = "trafficWebTypeChart", method = RequestMethod.GET) @ApiOperation(value = "HTTP网站分类分析统计", httpMethod = "GET", notes = "对应某个网站类型分类统计图") - public Map trafficWebTypeChart(Integer websiteServiceId,Model model, HttpServletRequest request, HttpServletResponse response) { + public Map trafficWebTypeChart(String beginDate,String endDate,Integer websiteServiceId,Model model, HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); List list = new ArrayList(); try { - List websiteChart = dashboardService.getDomainByWebsiteServiceId(websiteServiceId); - if (websiteChart!=null&&websiteChart.size() > 0) { - list = websiteChart; + if(!StringUtils.isEmpty(beginDate)&&!StringUtils.isEmpty(endDate)) { + Date begin = DateUtils.parseDate(beginDate); + Date end = DateUtils.parseDate(endDate); + // 带查询时间查询所有 + List websiteChart = dashboardService.getWebsiteDetailsById(websiteServiceId,begin,end); + if (websiteChart!=null&&websiteChart.size() > 0) { + list = websiteChart; + } + }else { + // 不带时间默认top10 + List websiteChart = dashboardService.getWebsiteTop10ById(websiteServiceId); + if (websiteChart!=null&&websiteChart.size() > 0) { + list = websiteChart; + } } + } catch (Exception e) { auditLogThread.setExceptionInfo("HTTP网站分类分析统计失败:"+e.getMessage()); logger.error("HTTP网站分类分析统计失败:"+ExceptionUtil.getExceptionMsg(e)); @@ -611,15 +656,26 @@ public class DashboardServiceController extends BaseRestController { } @RequestMapping(value = "trafficTopicAndDomainChart", method = RequestMethod.GET) @ApiOperation(value = "HTTP网站主题分类分析统计", httpMethod = "GET", notes = "对应某个网站主题类型分类统计图") - public Map trafficTopicAndDomainChart(Integer websiteServiceId,Model model, HttpServletRequest request, HttpServletResponse response) { + public Map trafficTopicAndDomainChart(String beginDate,String endDate,Model model, HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); List list = new ArrayList(); try { - List websiteChart = dashboardService.getTopicAndDomainList(); - if (websiteChart!=null&&websiteChart.size() > 0) { - list = websiteChart; + if(!StringUtils.isEmpty(beginDate)&&!StringUtils.isEmpty(endDate)) { + Date begin = DateUtils.parseDate(beginDate); + Date end = DateUtils.parseDate(endDate); + // 带查询时间查询所有 + List websiteChart = dashboardService.getTopicDetails(begin,end); + if (websiteChart!=null&&websiteChart.size() > 0) { + list = websiteChart; + } + }else { + // 不带时间默认top10 + List websiteChart = dashboardService.getTopicTop10(); + if (websiteChart!=null&&websiteChart.size() > 0) { + list = websiteChart; + } } } catch (Exception e) { auditLogThread.setExceptionInfo("HTTP网站主题分类分析数据检索失败:"+e.getMessage()); diff --git a/src/main/java/com/nis/web/dao/dashboard/TrafficAppStatisticDao.java b/src/main/java/com/nis/web/dao/dashboard/TrafficAppStatisticDao.java index 00e60ab..a7d9225 100644 --- a/src/main/java/com/nis/web/dao/dashboard/TrafficAppStatisticDao.java +++ b/src/main/java/com/nis/web/dao/dashboard/TrafficAppStatisticDao.java @@ -13,5 +13,5 @@ public interface TrafficAppStatisticDao { TrafficAppStatistic getMaxStatTime(); List appChart(@Param("statTime")Date statTime); - List getAppList(@Param("statTime")Date statTime,@Param("beginTime")String beginTime,@Param("endTime")String endTime); + List getAppList(@Param("beginTime")String beginTime,@Param("endTime")String endTime,@Param("appType")Integer appType); } \ No newline at end of file diff --git a/src/main/java/com/nis/web/dao/dashboard/TrafficAppStatisticDao.xml b/src/main/java/com/nis/web/dao/dashboard/TrafficAppStatisticDao.xml index 58031d3..ed55e53 100644 --- a/src/main/java/com/nis/web/dao/dashboard/TrafficAppStatisticDao.xml +++ b/src/main/java/com/nis/web/dao/dashboard/TrafficAppStatisticDao.xml @@ -32,12 +32,12 @@ SELECT app_type,SUM(link_num) AS link_num,SUM(c2s_pkt_num+s2c_pkt_num) AS packets, ((SUM(c2s_byte_len+s2c_byte_len)*8)/300/1024/1024/1024) AS GByte FROM traffic_app_statistic WHERE - - stat_time > DATE_SUB(#{statTime},INTERVAL 1 HOUR) - stat_time >= #{beginTime} and stat_time <= #{endTime} + + and app_type=#{appType} + GROUP BY app_type ) p LEFT JOIN ui_code_app_dic c ON p.app_type=c.view_code ORDER BY p.GByte DESC diff --git a/src/main/java/com/nis/web/dao/dashboard/TrafficHttpStatisticDao.java b/src/main/java/com/nis/web/dao/dashboard/TrafficHttpStatisticDao.java index 28b4f80..1e516a9 100644 --- a/src/main/java/com/nis/web/dao/dashboard/TrafficHttpStatisticDao.java +++ b/src/main/java/com/nis/web/dao/dashboard/TrafficHttpStatisticDao.java @@ -30,4 +30,7 @@ public interface TrafficHttpStatisticDao { List getDomainByTopicId(@Param("statTime") Date statTime, @Param("endTime") Date endTime); List getIdByWebSiteId(@Param("websiteId") Integer websiteId); + + List getDomainList(@Param("beginDate")Date beginDate, @Param("endDate") Date endDate); + } \ No newline at end of file diff --git a/src/main/java/com/nis/web/dao/dashboard/TrafficHttpStatisticDao.xml b/src/main/java/com/nis/web/dao/dashboard/TrafficHttpStatisticDao.xml index 978b373..e38be50 100644 --- a/src/main/java/com/nis/web/dao/dashboard/TrafficHttpStatisticDao.xml +++ b/src/main/java/com/nis/web/dao/dashboard/TrafficHttpStatisticDao.xml @@ -60,7 +60,7 @@ - select web_id webId,sum(c2s_byte_len + s2c_byte_len) count from + select web_id webId,link_num linkNum,SUM(c2s_pkt_num+s2c_pkt_num) packets,sum(c2s_byte_len + s2c_byte_len) count from traffic_http_statistic t where - = #{statTime} and stat_time< #{endTime} group by t.web_id ]]> + = #{statTime} and stat_time< #{endTime} group by t.web_id]]> + + + diff --git a/src/main/java/com/nis/web/dao/dashboard/TrafficIpActiveStatisticDao.java b/src/main/java/com/nis/web/dao/dashboard/TrafficIpActiveStatisticDao.java index 6031f24..ca586c7 100644 --- a/src/main/java/com/nis/web/dao/dashboard/TrafficIpActiveStatisticDao.java +++ b/src/main/java/com/nis/web/dao/dashboard/TrafficIpActiveStatisticDao.java @@ -15,9 +15,9 @@ public interface TrafficIpActiveStatisticDao { // List getIpList(TrafficIpActiveStatistic trafficIpActiveStatistic); TrafficIpActiveStatistic getMaxStatTime(); - ArrayList ipActiveFiveMinute(@Param("ipAddr") String ipAddr,@Param("statTime")Date statTime); + ArrayList ipActiveFiveMinute( @Param("ipAddr") String ipAddr,@Param("beginDate")Date beginDate,@Param("endDate")Date endDate); - ArrayList ipActiveOneHour(@Param("ipAddr") String ipAddr,@Param("statTime")Date statTime); + ArrayList ipActiveOneHour(@Param("ipAddr") String ipAddr,@Param("beginDate")Date beginDate,@Param("endDate")Date endDate); - ArrayList ipActiveChart(@Param("statTime")Date statTime); + ArrayList ipActiveChart(@Param("beginDate")Date beginDate,@Param("endDate")Date endDate); } \ No newline at end of file diff --git a/src/main/java/com/nis/web/dao/dashboard/TrafficIpActiveStatisticDao.xml b/src/main/java/com/nis/web/dao/dashboard/TrafficIpActiveStatisticDao.xml index 3673b62..3146156 100644 --- a/src/main/java/com/nis/web/dao/dashboard/TrafficIpActiveStatisticDao.xml +++ b/src/main/java/com/nis/web/dao/dashboard/TrafficIpActiveStatisticDao.xml @@ -26,31 +26,37 @@ - + - + select SUM(c2s_byte_len+s2c_byte_len) count ,stat_time time from traffic_ip_active_statistic + WHERE ip_addr=#{ipAddr} and + #{beginDate} and stat_time<=#{endDate}]]> diff --git a/src/main/java/com/nis/web/service/BaseService.java b/src/main/java/com/nis/web/service/BaseService.java index 34daa20..a68d205 100644 --- a/src/main/java/com/nis/web/service/BaseService.java +++ b/src/main/java/com/nis/web/service/BaseService.java @@ -162,7 +162,7 @@ public abstract class BaseService { * @param set 所有的count * @param countAndViewMap key是count,val是viewmap */ - protected List getTop10Data(Set set, Map> countAndViewMap) { + protected List getTop10Data(Set set, Map> countAndViewMap,int param) { List topicList = new ArrayList(); Long[] countArr = new Long[set.size()]; set.toArray(countArr); @@ -172,7 +172,7 @@ public abstract class BaseService { boolean exit = false; for (Map map : list) { topicList.add(map); - if (topicList.size() == 10) { + if (param==1&&topicList.size() == 10) { exit = true; break; } diff --git a/src/main/java/com/nis/web/service/restful/DashboardService.java b/src/main/java/com/nis/web/service/restful/DashboardService.java index 302bd66..3283514 100644 --- a/src/main/java/com/nis/web/service/restful/DashboardService.java +++ b/src/main/java/com/nis/web/service/restful/DashboardService.java @@ -3,6 +3,7 @@ package com.nis.web.service.restful; import com.beust.jcommander.internal.Maps; import com.nis.domain.restful.NtcEntranceReport; import com.nis.domain.restful.dashboard.*; +import com.nis.util.DateUtils; import com.nis.util.StringUtils; import com.nis.web.dao.dashboard.*; import com.nis.web.service.BaseService; @@ -416,22 +417,24 @@ public class DashboardService extends BaseService { * * @return */ - public List ipActiveFiveMinute() { +/* public List ipActiveFiveMinute(Date beginDate,Date endDate) { TrafficIpActiveStatistic maxStatTime = trafficIpActiveStatisticDao.getMaxStatTime(); ArrayList listMap = new ArrayList(); if (maxStatTime != null && maxStatTime.getStatTime() != null) { Date statTime = maxStatTime.getStatTime(); // 查询最近五分钟TOP10 - ArrayList list = trafficIpActiveStatisticDao.ipActiveChart(statTime); - if (list != null && list.size() > 0) { - for (LinkedHashMap map : list) { + ArrayList ipListTop10 = trafficIpActiveStatisticDao.ipActiveChart(beginDate,endDate); + if (ipListTop10 != null && ipListTop10.size() > 0) { + for (LinkedHashMap map : ipListTop10) { HashMap m = new HashMap(); if (map.get("ipAddr") != null) { String ipAddr = (String) map.get("ipAddr"); m.put("ipAddr", ipAddr); // 根据五分钟TOP10IP,查询TOP10中每个IP最近一小时的变化 - ArrayList ipList = trafficIpActiveStatisticDao - .ipActiveFiveMinute(ipAddr, statTime); + long beforeTime = beginDate.getTime(); + long afterTime = endDate.getTime(); + Long inter=(afterTime - beforeTime) / (1000 * 60 * 5); + ArrayList ipList = trafficIpActiveStatisticDao.ipActiveFiveMinute(inter,ipAddr, beginDate,endDate); List linkList = new ArrayList(); List timeList = new ArrayList(); if (ipList != null && ipList.size() > 0) { @@ -451,24 +454,79 @@ public class DashboardService extends BaseService { } return listMap; + }*/ + /** + * 获取活跃IPtop10 的趋势图 + */ + public List ipActiveFiveMinute(Date beginDate,Date endDate) { + ArrayList listMap = new ArrayList(); + ArrayList ipListTop10 = trafficIpActiveStatisticDao.ipActiveChart(beginDate,endDate); + if (ipListTop10 != null && ipListTop10.size() > 0) { + for (LinkedHashMap map : ipListTop10) { + HashMap m1 = new HashMap(); + String ipAddr = (String) map.get("ipAddr"); + m1.put("ipAddr", ipAddr); + ArrayList ipList = trafficIpActiveStatisticDao.ipActiveFiveMinute(ipAddr, beginDate,endDate); + List timeList = new ArrayList(); + List sumList1 = new ArrayList(); + + Map m= new HashMap(); + int inter=1000*60*5;// 间隔时间为五分钟 + // 开始时间,结束时间 时间戳 + Long b = dateToStamp(DateUtils.formatDateTime(beginDate)); + Long e = dateToStamp(DateUtils.formatDateTime(endDate)); + int num=0; + Long pointTime=b; + while(pointTime=e){ + break; //停止 + } + for (TrafficIpActiveStatistic e1 : ipList) { + // 实际时间 + String time= e1.getTime(); + Long t = dateToStamp(time); + if(t>=pointTime&&t=e-inter&&sum1>0) { + sumList1.add(sum1); + timeList.add(stampToDate(pointTime)); + } + if(pointTime ipActiveOneHour() { + public List ipActiveOneHour(Date beginDate,Date endDate) { TrafficIpActiveStatistic maxStatTime = trafficIpActiveStatisticDao.getMaxStatTime(); ArrayList listMap = new ArrayList(); if (maxStatTime != null && maxStatTime.getStatTime() != null) { Date statTime = maxStatTime.getStatTime(); - ArrayList list = trafficIpActiveStatisticDao.ipActiveChart(statTime); + ArrayList list = trafficIpActiveStatisticDao.ipActiveChart(beginDate,endDate); if (list != null && list.size() > 0) { for (LinkedHashMap map : list) { if (map.get("ipAddr") != null) { String ipAddr = (String) map.get("ipAddr"); - ArrayList iplList = trafficIpActiveStatisticDao.ipActiveOneHour(ipAddr, statTime); + ArrayList iplList = trafficIpActiveStatisticDao.ipActiveOneHour(ipAddr, beginDate,endDate); listMap.add(iplList.get(0)); } } @@ -478,13 +536,19 @@ public class DashboardService extends BaseService { return listMap; } + /** + * 活跃IP首页top10 + * @param beginDate + * @param endDate + * @return + */ @SuppressWarnings("rawtypes") - public List ipActiveChart() { - TrafficIpActiveStatistic maxStatTime = trafficIpActiveStatisticDao.getMaxStatTime(); + public List ipActiveChart(Date beginDate, Date endDate) { +// TrafficIpActiveStatistic maxStatTime = trafficIpActiveStatisticDao.getMaxStatTime(); ArrayList list = new ArrayList<>(); - if (maxStatTime != null && maxStatTime.getStatTime() != null) { - Date statTime = maxStatTime.getStatTime(); - list = trafficIpActiveStatisticDao.ipActiveChart(statTime); +// if (maxStatTime != null && maxStatTime.getStatTime() != null) { +// Date statTime = maxStatTime.getStatTime(); + list = trafficIpActiveStatisticDao.ipActiveChart(beginDate,endDate); if (list != null && list.size() > 0) { for (LinkedHashMap map : list) { if (map.get("ipAddr") != null) { @@ -494,7 +558,7 @@ public class DashboardService extends BaseService { } } } - } +// } return list; } @@ -560,13 +624,13 @@ public class DashboardService extends BaseService { * * @return */ - public List getAppList(String startTime, String endTime) { - TrafficAppStatistic maxStatTime = trafficAppStatisticDao.getMaxStatTime(); + public List getAppList(String startTime, String endTime,Integer appType) { +// TrafficAppStatistic maxStatTime = trafficAppStatisticDao.getMaxStatTime(); List list = new ArrayList(); - if (maxStatTime != null && maxStatTime.getStatTime() != null) { - Date statTime = maxStatTime.getStatTime(); - list = trafficAppStatisticDao.getAppList(statTime, startTime, endTime); - } +// if (maxStatTime != null && maxStatTime.getStatTime() != null) { +// Date statTime = maxStatTime.getStatTime(); + list = trafficAppStatisticDao.getAppList(startTime, endTime,appType); +// } return list; } @@ -700,20 +764,42 @@ public class DashboardService extends BaseService { // } // return result; // } - + /** + * + * 网站子域名详情 + * @param beginDate + * @param endDate + * @return + */ + public List getWebsiteDetailsById(Integer websiteServiceId,Date beginDate,Date endDate){ + List list = getDomainByWebsiteServiceId(websiteServiceId,beginDate,endDate,null); + return list; + } +/** + * + * 网站子域名TOP10 默认一小时 + * @param beginDate + * @param endDate + * @return + */ +public List getWebsiteTop10ById(Integer websiteServiceId){ + Date startTime = getBeforeByHourTime(1);// 获取上一个小时 + List list = getDomainByWebsiteServiceId(websiteServiceId,startTime,new Date(),"top"); + return list; +} /** * 根据网站服务查询子域名 * * @param websiteServiceId * @return list */ - public List getDomainByWebsiteServiceId(Integer websiteServiceId) { + public List getDomainByWebsiteServiceId(Integer websiteServiceId,Date beginDate,Date endDate,String top) { - Date statTime = getBeforeByHourTime(1);// 获取上一个小时 +// Date statTime = getBeforeByHourTime(1);// 获取上一个小时 List idList = trafficHttpStatisticDao.getIdByWebSiteId(websiteServiceId); - List matchList = trafficHttpStatisticDao.getDomainByWebsiteServiceId(idList, statTime, new Date());// 获取webid和count的对应关系,key是webid,val是count + List matchList = trafficHttpStatisticDao.getDomainByWebsiteServiceId(idList, beginDate, endDate);// 获取webid和count的对应关系,key是webid,val是count // 获取webid和count的对应关系,key是webid,val是count Set set = new HashSet<>(); Map> countMap = new HashMap();// 存储count和map的对应关系,后面根据count过滤,获取top10的count @@ -729,7 +815,12 @@ public class DashboardService extends BaseService { countMap.put(count, listMap); } } - List top10Data = getTop10Data(set, countMap); + List top10Data =new ArrayList(); + if(top!=null) { + top10Data = getTop10Data(set, countMap,1); + }else { + top10Data = getTop10Data(set, countMap,2); + } List notTop10List = new ArrayList<>();// 获取不在top10中的webid,用来查询标记为orther for (Map map : matchList) { String webIdStr = String.valueOf(map.get("webId")); @@ -747,7 +838,7 @@ public class DashboardService extends BaseService { // 查询固定网站下的域名除了TOP10以外的others域名 if (matchList != null && matchList.size() > 10) { - Map others = trafficHttpStatisticDao.websiteDomainOthers(notTop10List, statTime, new Date()); + Map others = trafficHttpStatisticDao.websiteDomainOthers(notTop10List, beginDate, endDate); if (others != null && others.size() > 0) { others.put("webId", "-1"); top10Data.add(others); @@ -756,17 +847,39 @@ public class DashboardService extends BaseService { return top10Data; } - + + /** + * + * 网站详情 + * @param beginDate + * @param endDate + * @return + */ + public List getWebsiteDetails(Date beginDate,Date endDate){ + List list = trafficHttpStatisticDao.getDomainList(beginDate,endDate); + return list; + } +/** + * + * 网站TOP10 默认一小时 + * @param beginDate + * @param endDate + * @return + */ +public List getWebsiteTop10(){ + Date startTime = getBeforeByHourTime(1);// 获取上一个小时 + List list = getDomainByWebsiteList(startTime,new Date(),"top"); + return list; +} /** * 获取网站列表 * * @return */ @SuppressWarnings("unchecked") - public List getDomainByWebsiteList() { - Date statTime = getBeforeByHourTime(1);// 获取上一个小时 + public List getDomainByWebsiteList(Date beginDate,Date endDate,String top) { Map> websiteIdAndIdMap = new HashMap<>();// 存储websiteServiceId和id的对应关系,一个websiteServiceId有多个id - List websiteIdAndidList = trafficHttpStatisticDao.getDomainByWebsiteList(statTime, new Date());// 获取website_service_id和id的对应关系,group + List websiteIdAndidList = trafficHttpStatisticDao.getDomainByWebsiteList(beginDate, endDate);// 获取website_service_id和id的对应关系,group // by // website_service_id,id for (Map map : websiteIdAndidList) { @@ -785,11 +898,13 @@ public class DashboardService extends BaseService { Set set = new HashSet<>(); Map> countAndViewMap = new HashMap<>();// 存储count和map的对应关系,后面根据count过滤,获取top10的count - List webIdAndCountList = trafficHttpStatisticDao.preWebsiteListCount(statTime, new Date());// 获取最近一小时的webid和count的关系 - List prevWebIdAndCountList = trafficHttpStatisticDao.preWebsiteListCount(getBeforeByHourTime(2), statTime);// 获取最近一小时的webid和count的关系 + List webIdAndCountList = trafficHttpStatisticDao.preWebsiteListCount(beginDate, endDate);// 获取最近一小时的webid和count的关系 + List prevWebIdAndCountList = trafficHttpStatisticDao.preWebsiteListCount(getBeforeByHourTime(2), beginDate);// 获取最近一小时的webid和count的关系 for (String websiteServiceId : websiteIdAndIdMap.keySet()) {// 遍历上面获取的websiteServiceId和id的对应关系,拼接json Map viewMap = new HashMap<>(); long count = 0l;// 记录当前websiteServiceId所有的count +// long linkNum = 0l;// +// long packets = 0l;// long prevCount = 0l;// 记录当前websiteServiceId所有的count List idList = websiteIdAndIdMap.get(websiteServiceId);// 根据websiteServiceId获取对应的id for (String id : idList) { @@ -797,9 +912,17 @@ public class DashboardService extends BaseService { String webId = String.valueOf(webIdAndCountMap.get("webId")); if (webId != null && webId.equals(id)) {// 如果webid和id相等则获取count数据并统计 String countStr = String.valueOf(webIdAndCountMap.get("count")); +// String linkNumStr = String.valueOf(webIdAndCountMap.get("linkNum")); +// String packetsStr = String.valueOf(webIdAndCountMap.get("packets")); if (countStr != null) { count += Long.parseLong(countStr);// 将count累加 } +// if (linkNumStr != null) { +// linkNum += Long.parseLong(linkNumStr);// 将count累加 +// } +// if (packetsStr != null) { +// packets += Long.parseLong(packetsStr);// 将count累加 +// } } } for (Map webIdAndCountMap : prevWebIdAndCountList) {// 遍历webid和count @@ -815,6 +938,8 @@ public class DashboardService extends BaseService { } viewMap.put("websiteServiceId", websiteServiceId); viewMap.put("count", count); +// viewMap.put("linkNum", linkNum); +// viewMap.put("packets", packets); viewMap.put("pktNum", 0); viewMap.put("byteLen", 0); viewMap.put("preCount", prevCount); @@ -828,18 +953,48 @@ public class DashboardService extends BaseService { } set.add(count); } - return getTop10Data(set, countAndViewMap); + List dataList = new ArrayList(); + if(top!=null) { + dataList = getTop10Data(set, countAndViewMap,1);// 取top10 + }else { + dataList = getTop10Data(set, countAndViewMap,2); + } + return dataList; } - + + + /** + * + * 主题详情 + * @param beginDate + * @param endDate + * @return + */ + public List getTopicDetails(Date beginDate,Date endDate){ + List topicAndDomainList = getTopicAndDomainList(beginDate,endDate,null); + return topicAndDomainList; + } +/** + * + * 主题TOP10 默认一小时 + * @param beginDate + * @param endDate + * @return + */ +public List getTopicTop10(){ + Date startTime = getBeforeByHourTime(1);// 获取上一个小时 + List topicAndDomainList = getTopicAndDomainList(startTime,new Date(),"top"); + return topicAndDomainList; +} /** * 主题网站分类,域名 * **/ - public List getTopicAndDomainList() { + public List getTopicAndDomainList(Date beginDate,Date endDate,String top) { - Date startTime = getBeforeByHourTime(1);// 获取上一个小时 + Map> topicIdAndIdMap = new HashMap<>();// 存储topicid和id的对应关系,一个topicid有多个id - List topicIdAndIdList = trafficHttpStatisticDao.getDomainByTopicList(startTime, new Date());// 获取最近一个小时topicId和id的对应关系,group + List topicIdAndIdList = trafficHttpStatisticDao.getDomainByTopicList(beginDate,endDate );// 获取最近一个小时topicId和id的对应关系,group for (Map map : topicIdAndIdList) { Object topicIdObj = map.get("topicId"); Object idObj = map.get("id"); @@ -856,26 +1011,40 @@ public class DashboardService extends BaseService { Set set = new HashSet<>(); Map> countAndViewMap = new HashMap<>();// 存储count和map的对应关系,后面根据count过滤,获取top10的count - List webIdAndCountList = trafficHttpStatisticDao.getDomainByTopicId(startTime, new Date());// 获取最近一小时的webid和count的关系 + List webIdAndCountList = trafficHttpStatisticDao.getDomainByTopicId(beginDate, endDate);// 获取最近一小时的webid和count的关系 for (String topicId : topicIdAndIdMap.keySet()) {// 遍历上面获取的topicid和id的对应关系,拼接json Map viewMap = new HashMap<>(); viewMap.put("topicId", topicId); List list = new ArrayList<>(); long count = 0l;// 记录当前topicid所有的count + long linkNum = 0l; + long packets = 0l; List idList = topicIdAndIdMap.get(topicId);// 根据topicid获取对应的id for (String id : idList) { for (Map webIdAndCountMap : webIdAndCountList) {// 遍历webid和count String webId = String.valueOf(webIdAndCountMap.get("webId")); if (webId != null && webId.equals(id)) {// 如果webid和id相等则获取count数据并统计 String countStr = String.valueOf(webIdAndCountMap.get("count")); + String linkNumStr = String.valueOf(webIdAndCountMap.get("linkNum")); + String packetsStr = String.valueOf(webIdAndCountMap.get("packets")); if (countStr != null) { count += Long.parseLong(countStr);// 将count累加 list.add(webIdAndCountMap); } + if (linkNumStr != null) { + linkNum += Long.parseLong(linkNumStr);// 将count累加 + list.add(webIdAndCountMap); + } + if (packetsStr != null) { + packets += Long.parseLong(packetsStr);// 将count累加 + list.add(webIdAndCountMap); + } } } } viewMap.put("count", count); + viewMap.put("linkNum", linkNum); + viewMap.put("packets", packets); viewMap.put("domainData", list); if (countAndViewMap.containsKey(count)) {// 将每个count和对应的viewmap放到map中,count可能相同所以value是list countAndViewMap.get(count).add(viewMap); @@ -886,7 +1055,13 @@ public class DashboardService extends BaseService { } set.add(count); } - return getTop10Data(set, countAndViewMap); + List dataList = new ArrayList(); + if(top!=null) { + dataList = getTop10Data(set, countAndViewMap,1); + }else { + dataList = getTop10Data(set, countAndViewMap,2); + } + return dataList; } }