流量统计增加域名查询接口,修改活跃IP增加时间查询,app增加appType条件查询,增加主题详情统计

This commit is contained in:
zhanghongqing
2018-12-17 10:12:20 +08:00
parent 630be99456
commit d58b7ae780
10 changed files with 339 additions and 82 deletions

View File

@@ -32,8 +32,19 @@ public class TrafficIpActiveStatistic extends BaseEntity<TrafficIpActiveStatisti
private String time;
private Long count;
public String getTime() {
public Long getCount() {
return count;
}
public void setCount(Long count) {
this.count = count;
}
public String getTime() {
return time;
}

View File

@@ -22,6 +22,7 @@ import com.nis.restful.RestBusinessCode;
import com.nis.restful.RestServiceException;
import com.nis.restful.ServiceRuntimeException;
import com.nis.util.Constants;
import com.nis.util.DateUtils;
import com.nis.util.ExceptionUtil;
import com.nis.util.JsonMapper;
import com.nis.util.StringUtils;
@@ -291,13 +292,26 @@ public class DashboardServiceController extends BaseRestController {
*/
@RequestMapping(value = "trafficIpActive", method = RequestMethod.GET)
@ApiOperation(value = "活跃IP统计", httpMethod = "GET", notes = "对应活跃IP实时统计查询服务。")
public Map<String,?> trafficIpActive(Model model, HttpServletRequest request, HttpServletResponse response) {
public Map<String,?> 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<LinkedHashMap> list = new ArrayList<LinkedHashMap>();
try {
List<LinkedHashMap> 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<LinkedHashMap> 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<String,?> trafficIpActiveOneHour(Model model, HttpServletRequest request, HttpServletResponse response) {
public Map<String,?> 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<HashMap> list = new ArrayList<HashMap>();
try {
List<HashMap> ipActiveChart = dashboardService.ipActiveOneHour();
Date begin = DateUtils.parseDate(beginDate);
Date end = DateUtils.parseDate(endDate);
List<HashMap> 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<String,?> trafficIpActiveFiveMinute(Model model, HttpServletRequest request, HttpServletResponse response) {
public Map<String,?> 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<HashMap> list = new ArrayList<HashMap>();
try {
List<HashMap> 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<HashMap> 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<String,?> trafficAppList(String beginDate,String endDate,Model model, HttpServletRequest request, HttpServletResponse response){
public Map<String,?> 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<HashMap> list = new ArrayList<HashMap>();
try {
List<Map> appList = dashboardService.getAppList(beginDate,endDate);
List<Map> appList = dashboardService.getAppList(beginDate,endDate,appType);
if (appList!=null&&appList.size() > 0) {
String jsonString = JsonMapper.toJsonString(appList);
list = (java.util.List<HashMap>) 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<String,?> trafficWebsiteList(Model model, HttpServletRequest request, HttpServletResponse response) {
public Map<String,?> 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<Map> list = new ArrayList<Map>();
try {
// List<Map> websiteChart = dashboardService.websiteList();
List<Map> 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<Map> websiteChart = dashboardService.getWebsiteDetails(begin,end);
if (websiteChart!=null&&websiteChart.size() > 0) {
list = websiteChart;
}
}else {
// 不带时间默认top10
List<Map> 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<String, ?> trafficWebTypeChart(Integer websiteServiceId,Model model, HttpServletRequest request, HttpServletResponse response) {
public Map<String, ?> 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<Map> list = new ArrayList<Map>();
try {
List<Map> 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<Map> websiteChart = dashboardService.getWebsiteDetailsById(websiteServiceId,begin,end);
if (websiteChart!=null&&websiteChart.size() > 0) {
list = websiteChart;
}
}else {
// 不带时间默认top10
List<Map> 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<String, ?> trafficTopicAndDomainChart(Integer websiteServiceId,Model model, HttpServletRequest request, HttpServletResponse response) {
public Map<String, ?> 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<Map> list = new ArrayList<Map>();
try {
List<Map> 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<Map> websiteChart = dashboardService.getTopicDetails(begin,end);
if (websiteChart!=null&&websiteChart.size() > 0) {
list = websiteChart;
}
}else {
// 不带时间默认top10
List<Map> websiteChart = dashboardService.getTopicTop10();
if (websiteChart!=null&&websiteChart.size() > 0) {
list = websiteChart;
}
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("HTTP网站主题分类分析数据检索失败:"+e.getMessage());

View File

@@ -13,5 +13,5 @@ public interface TrafficAppStatisticDao {
TrafficAppStatistic getMaxStatTime();
List<Map> appChart(@Param("statTime")Date statTime);
List<Map> getAppList(@Param("statTime")Date statTime,@Param("beginTime")String beginTime,@Param("endTime")String endTime);
List<Map> getAppList(@Param("beginTime")String beginTime,@Param("endTime")String endTime,@Param("appType")Integer appType);
}

View File

@@ -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
<if test="beginTime==null or endTime==null">
stat_time > DATE_SUB(#{statTime},INTERVAL 1 HOUR)
</if>
<if test="beginTime!=null and endTime!=null">
stat_time >= #{beginTime} and stat_time &lt;= #{endTime}
</if>
<if test="appType!=null and appType!=''">
and app_type=#{appType}
</if>
GROUP BY app_type ) p
LEFT JOIN ui_code_app_dic c ON p.app_type=c.view_code ORDER BY p.GByte DESC
</select>

View File

@@ -30,4 +30,7 @@ public interface TrafficHttpStatisticDao {
List<Map> getDomainByTopicId(@Param("statTime") Date statTime, @Param("endTime") Date endTime);
List getIdByWebSiteId(@Param("websiteId") Integer websiteId);
List<Map> getDomainList(@Param("beginDate")Date beginDate, @Param("endDate") Date endDate);
}

View File

@@ -60,7 +60,7 @@
<!--获取上个时间段该网站站域名流量的数据量 -->
<select id="preWebsiteListCount" resultType="java.util.HashMap">
select web_id webId, SUM(c2s_byte_len + s2c_byte_len) count from
select web_id webId,SUM(c2s_byte_len + s2c_byte_len) count from
traffic_http_statistic t where
<![CDATA[ stat_time>= #{statTime} and stat_time< #{endTime} group by t.web_id ]]>
@@ -100,9 +100,15 @@ FROM
<!-- 根据主题分组获取子域名 -->
<select id="getDomainByTopicId" resultType="java.util.HashMap">
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
<![CDATA[ stat_time>= #{statTime} and stat_time< #{endTime} group by t.web_id ]]>
<![CDATA[ stat_time>= #{statTime} and stat_time< #{endTime} group by t.web_id]]>
</select>
<!-- 获取域名列表 -->
<select id="getDomainList" resultType="java.util.HashMap">
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
<![CDATA[ stat_time>= #{beginDate} and stat_time< #{endDate} group by t.web_id order by count]]>
</select>

View File

@@ -15,9 +15,9 @@ public interface TrafficIpActiveStatisticDao {
// List<TrafficIpActiveStatistic> getIpList(TrafficIpActiveStatistic trafficIpActiveStatistic);
TrafficIpActiveStatistic getMaxStatTime();
ArrayList<TrafficIpActiveStatistic> ipActiveFiveMinute(@Param("ipAddr") String ipAddr,@Param("statTime")Date statTime);
ArrayList<TrafficIpActiveStatistic> ipActiveFiveMinute( @Param("ipAddr") String ipAddr,@Param("beginDate")Date beginDate,@Param("endDate")Date endDate);
ArrayList<HashMap> ipActiveOneHour(@Param("ipAddr") String ipAddr,@Param("statTime")Date statTime);
ArrayList<HashMap> ipActiveOneHour(@Param("ipAddr") String ipAddr,@Param("beginDate")Date beginDate,@Param("endDate")Date endDate);
ArrayList<LinkedHashMap> ipActiveChart(@Param("statTime")Date statTime);
ArrayList<LinkedHashMap> ipActiveChart(@Param("beginDate")Date beginDate,@Param("endDate")Date endDate);
}

View File

@@ -26,31 +26,37 @@
<select id="getMaxStatTime" resultType="com.nis.domain.restful.dashboard.TrafficIpActiveStatistic">
SELECT stat_time statTime FROM traffic_ip_active_statistic order by stat_time desc limit 1
</select>
<!-- IP流量统计五分钟-->
<!-- IP流量统计五分钟TOp10-->
<select id="ipActiveChart" resultType="java.util.LinkedHashMap">
SELECT ip_addr ipAddr, SUM(c2s_byte_len+s2c_byte_len) linkNum FROM traffic_ip_active_statistic
WHERE stat_time > DATE_SUB(#{statTime},INTERVAL 1 hour)
WHERE
<![CDATA[ stat_time> #{beginDate} and stat_time<=#{endDate}]]>
GROUP BY ip_addr ORDER BY linkNum DESC limit 0,10
</select>
<!-- IP流量统计一小时内每隔五分钟数据-->
<select id="ipActiveFiveMinute" resultMap="BaseResultMap">
<!-- <select id="ipActiveFiveMinute" resultMap="BaseResultMap">
select IFNULL(p.sumNum,0) linkNum, date_format(a.min5,'%Y-%m-%d %H:%i') time from
(select date_sub(#{statTime},interval @mycnt :=@mycnt + 5 MINUTE) min5
from (SELECT @mycnt:=-5) m, traffic_ip_active_statistic limit 12) a
(select date_sub(#{endDate},interval @mycnt :=@mycnt + 5 MINUTE) min5
from (SELECT @mycnt:=-5) m, traffic_ip_active_statistic limit #{inter}) a
LEFT JOIN (
SELECT date_format(stat_time, '%Y-%m-%d %H:%i') timestamp, SUM(c2s_byte_len+s2c_byte_len) sumNum FROM traffic_ip_active_statistic
WHERE ip_addr=#{ipAddr} AND stat_time > DATE_SUB(#{statTime,jdbcType=TIMESTAMP}, INTERVAL 1 HOUR)
WHERE ip_addr=#{ipAddr} AND <![CDATA[ stat_time> #{beginDate} and stat_time<=#{endDate}]]>
GROUP by timestamp
) p
on date_format(p.timestamp,'%Y-%m-%d %H:%i')=date_format(a.min5,'%Y-%m-%d %H:%i')
ORDER by time
</select> -->
<select id="ipActiveFiveMinute" resultMap="BaseResultMap">
select SUM(c2s_byte_len+s2c_byte_len) count ,stat_time time from traffic_ip_active_statistic
WHERE ip_addr=#{ipAddr} and
<![CDATA[ stat_time> #{beginDate} and stat_time<=#{endDate}]]>
</select>
<!-- IP流量统计一小时-->
<select id="ipActiveOneHour" resultType="java.util.HashMap">
SELECT ip_addr ipAddr,area_id areaId,SUM(c2s_byte_len+s2c_byte_len) count, link_num linkNum ,c2s_pkt_num c2sPktNum,s2c_pkt_num s2cPktNum,c2s_byte_len c2sByteLen,s2c_byte_len s2cByteLen,date_format(stat_time, '%Y-%m-%d %H:%i:%s') statTime FROM traffic_ip_active_statistic
WHERE ip_addr=#{ipAddr}
and stat_time > DATE_SUB(#{statTime},INTERVAL 1 HOUR) GROUP BY statTime
and <![CDATA[ stat_time> #{beginDate} and stat_time<=#{endDate}]]> GROUP BY statTime
ORDER BY count DESC LIMIT 1
</select>

View File

@@ -162,7 +162,7 @@ public abstract class BaseService {
* @param set 所有的count
* @param countAndViewMap key是count,val是viewmap
*/
protected List<Map> getTop10Data(Set<Long> set, Map<Long, List<Map>> countAndViewMap) {
protected List<Map> getTop10Data(Set<Long> set, Map<Long, List<Map>> countAndViewMap,int param) {
List<Map> topicList = new ArrayList<Map>();
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;
}

View File

@@ -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<HashMap> ipActiveFiveMinute() {
/* public List<HashMap> ipActiveFiveMinute(Date beginDate,Date endDate) {
TrafficIpActiveStatistic maxStatTime = trafficIpActiveStatisticDao.getMaxStatTime();
ArrayList<HashMap> listMap = new ArrayList<HashMap>();
if (maxStatTime != null && maxStatTime.getStatTime() != null) {
Date statTime = maxStatTime.getStatTime();
// 查询最近五分钟TOP10
ArrayList<LinkedHashMap> list = trafficIpActiveStatisticDao.ipActiveChart(statTime);
if (list != null && list.size() > 0) {
for (LinkedHashMap map : list) {
ArrayList<LinkedHashMap> 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<TrafficIpActiveStatistic> ipList = trafficIpActiveStatisticDao
.ipActiveFiveMinute(ipAddr, statTime);
long beforeTime = beginDate.getTime();
long afterTime = endDate.getTime();
Long inter=(afterTime - beforeTime) / (1000 * 60 * 5);
ArrayList<TrafficIpActiveStatistic> 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<HashMap> ipActiveFiveMinute(Date beginDate,Date endDate) {
ArrayList<HashMap> listMap = new ArrayList<HashMap>();
ArrayList<LinkedHashMap> 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<TrafficIpActiveStatistic> ipList = trafficIpActiveStatisticDao.ipActiveFiveMinute(ipAddr, beginDate,endDate);
List timeList = new ArrayList();
List sumList1 = new ArrayList();
Map<String, Comparable> m= new HashMap<String, Comparable>();
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){
Map rm=new HashMap();
Long sum1=0l;
if(pointTime>=e){
break; //停止
}
for (TrafficIpActiveStatistic e1 : ipList) {
// 实际时间
String time= e1.getTime();
Long t = dateToStamp(time);
if(t>=pointTime&&t<pointTime+inter){
// 范围之内分到此pointTime组
sum1=sum1+ e1.getCount();
}
}
// 在结束时间只有当值大于0时才记录数据防止折线降为0引起误会
if(pointTime>=e-inter&&sum1>0) {
sumList1.add(sum1);
timeList.add(stampToDate(pointTime));
}
if(pointTime<e-inter) {
sumList1.add(sum1);
timeList.add(stampToDate(pointTime));
}
num=num+1;
pointTime =b+inter*num;
}
m1.put("linkNum", sumList1);
m1.put("statTime", timeList);
listMap.add(m1);
}
}
return listMap;
}
/**
* 根据活跃IP最近五分钟TOP10查询近1小时最大值
*
* @return
*/
public List<HashMap> ipActiveOneHour() {
public List<HashMap> ipActiveOneHour(Date beginDate,Date endDate) {
TrafficIpActiveStatistic maxStatTime = trafficIpActiveStatisticDao.getMaxStatTime();
ArrayList<HashMap> listMap = new ArrayList<HashMap>();
if (maxStatTime != null && maxStatTime.getStatTime() != null) {
Date statTime = maxStatTime.getStatTime();
ArrayList<LinkedHashMap> list = trafficIpActiveStatisticDao.ipActiveChart(statTime);
ArrayList<LinkedHashMap> 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<HashMap> iplList = trafficIpActiveStatisticDao.ipActiveOneHour(ipAddr, statTime);
ArrayList<HashMap> 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<LinkedHashMap> ipActiveChart() {
TrafficIpActiveStatistic maxStatTime = trafficIpActiveStatisticDao.getMaxStatTime();
public List<LinkedHashMap> ipActiveChart(Date beginDate, Date endDate) {
// TrafficIpActiveStatistic maxStatTime = trafficIpActiveStatisticDao.getMaxStatTime();
ArrayList<LinkedHashMap> 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<Map> getAppList(String startTime, String endTime) {
TrafficAppStatistic maxStatTime = trafficAppStatisticDao.getMaxStatTime();
public List<Map> getAppList(String startTime, String endTime,Integer appType) {
// TrafficAppStatistic maxStatTime = trafficAppStatisticDao.getMaxStatTime();
List<Map> list = new ArrayList<Map>();
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<Map> getWebsiteDetailsById(Integer websiteServiceId,Date beginDate,Date endDate){
List<Map> list = getDomainByWebsiteServiceId(websiteServiceId,beginDate,endDate,null);
return list;
}
/**
*
* 网站子域名TOP10 默认一小时
* @param beginDate
* @param endDate
* @return
*/
public List<Map> getWebsiteTop10ById(Integer websiteServiceId){
Date startTime = getBeforeByHourTime(1);// 获取上一个小时
List<Map> list = getDomainByWebsiteServiceId(websiteServiceId,startTime,new Date(),"top");
return list;
}
/**
* 根据网站服务查询子域名
*
* @param websiteServiceId
* @return list
*/
public List<Map> getDomainByWebsiteServiceId(Integer websiteServiceId) {
public List<Map> getDomainByWebsiteServiceId(Integer websiteServiceId,Date beginDate,Date endDate,String top) {
Date statTime = getBeforeByHourTime(1);// 获取上一个小时
// Date statTime = getBeforeByHourTime(1);// 获取上一个小时
List idList = trafficHttpStatisticDao.getIdByWebSiteId(websiteServiceId);
List<Map> matchList = trafficHttpStatisticDao.getDomainByWebsiteServiceId(idList, statTime, new Date());// 获取webid和count的对应关系,key是webid,val是count
List<Map> matchList = trafficHttpStatisticDao.getDomainByWebsiteServiceId(idList, beginDate, endDate);// 获取webid和count的对应关系,key是webid,val是count
// 获取webid和count的对应关系,key是webid,val是count
Set<Long> set = new HashSet<>();
Map<Long, List<Map>> countMap = new HashMap();// 存储count和map的对应关系,后面根据count过滤,获取top10的count
@@ -729,7 +815,12 @@ public class DashboardService extends BaseService {
countMap.put(count, listMap);
}
}
List<Map> top10Data = getTop10Data(set, countMap);
List<Map> top10Data =new ArrayList();
if(top!=null) {
top10Data = getTop10Data(set, countMap,1);
}else {
top10Data = getTop10Data(set, countMap,2);
}
List<String> 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<Map> getWebsiteDetails(Date beginDate,Date endDate){
List<Map> list = trafficHttpStatisticDao.getDomainList(beginDate,endDate);
return list;
}
/**
*
* 网站TOP10 默认一小时
* @param beginDate
* @param endDate
* @return
*/
public List<Map> getWebsiteTop10(){
Date startTime = getBeforeByHourTime(1);// 获取上一个小时
List<Map> list = getDomainByWebsiteList(startTime,new Date(),"top");
return list;
}
/**
* 获取网站列表
*
* @return
*/
@SuppressWarnings("unchecked")
public List<Map> getDomainByWebsiteList() {
Date statTime = getBeforeByHourTime(1);// 获取上一个小时
public List<Map> getDomainByWebsiteList(Date beginDate,Date endDate,String top) {
Map<String, List<String>> websiteIdAndIdMap = new HashMap<>();// 存储websiteServiceId和id的对应关系,一个websiteServiceId有多个id
List<Map> websiteIdAndidList = trafficHttpStatisticDao.getDomainByWebsiteList(statTime, new Date());// 获取website_service_id和id的对应关系,group
List<Map> 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<Long> set = new HashSet<>();
Map<Long, List<Map>> countAndViewMap = new HashMap<>();// 存储count和map的对应关系,后面根据count过滤,获取top10的count
List<Map> webIdAndCountList = trafficHttpStatisticDao.preWebsiteListCount(statTime, new Date());// 获取最近一小时的webid和count的关系
List<Map> prevWebIdAndCountList = trafficHttpStatisticDao.preWebsiteListCount(getBeforeByHourTime(2), statTime);// 获取最近一小时的webid和count的关系
List<Map> webIdAndCountList = trafficHttpStatisticDao.preWebsiteListCount(beginDate, endDate);// 获取最近一小时的webid和count的关系
List<Map> 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<String> 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<Map> 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<Map> getTopicDetails(Date beginDate,Date endDate){
List<Map> topicAndDomainList = getTopicAndDomainList(beginDate,endDate,null);
return topicAndDomainList;
}
/**
*
* 主题TOP10 默认一小时
* @param beginDate
* @param endDate
* @return
*/
public List<Map> getTopicTop10(){
Date startTime = getBeforeByHourTime(1);// 获取上一个小时
List<Map> topicAndDomainList = getTopicAndDomainList(startTime,new Date(),"top");
return topicAndDomainList;
}
/**
* 主题网站分类,域名
*
**/
public List<Map> getTopicAndDomainList() {
public List<Map> getTopicAndDomainList(Date beginDate,Date endDate,String top) {
Date startTime = getBeforeByHourTime(1);// 获取上一个小时
Map<String, List<String>> topicIdAndIdMap = new HashMap<>();// 存储topicid和id的对应关系,一个topicid有多个id
List<Map> topicIdAndIdList = trafficHttpStatisticDao.getDomainByTopicList(startTime, new Date());// 获取最近一个小时topicId和id的对应关系,group
List<Map> 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<Long> set = new HashSet<>();
Map<Long, List<Map>> countAndViewMap = new HashMap<>();// 存储count和map的对应关系,后面根据count过滤,获取top10的count
List<Map> webIdAndCountList = trafficHttpStatisticDao.getDomainByTopicId(startTime, new Date());// 获取最近一小时的webid和count的关系
List<Map> webIdAndCountList = trafficHttpStatisticDao.getDomainByTopicId(beginDate, endDate);// 获取最近一小时的webid和count的关系
for (String topicId : topicIdAndIdMap.keySet()) {// 遍历上面获取的topicid和id的对应关系,拼接json
Map viewMap = new HashMap<>();
viewMap.put("topicId", topicId);
List<Map> list = new ArrayList<>();
long count = 0l;// 记录当前topicid所有的count
long linkNum = 0l;
long packets = 0l;
List<String> 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<Map> dataList = new ArrayList();
if(top!=null) {
dataList = getTop10Data(set, countAndViewMap,1);
}else {
dataList = getTop10Data(set, countAndViewMap,2);
}
return dataList;
}
}