1:更改首页流量统计的sql

2:更改topic数据的获取方式
3:修改sql中where错误
4:修改表结构sql
This commit is contained in:
renkaige
2018-12-10 10:23:48 +06:00
parent 599554ee0d
commit 6553fd92ee
7 changed files with 547 additions and 421 deletions

View File

@@ -161,8 +161,10 @@ CREATE TABLE `ui_code_protocol_type_dic` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`protocol_type` varchar(255) DEFAULT '', `protocol_type` varchar(255) DEFAULT '',
`view_code` varchar(255) DEFAULT NULL, `view_code` varchar(255) DEFAULT NULL,
`service_id` int(11) DEFAULT NULL,
`remarks` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=FEDERATED AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 CONNECTION='mysql://root:111111@192.168.10.204:3306/gwall/code_protocol_type_dic'; ) ENGINE=FEDERATED AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 CONNECTION='mysql://root:111111@10.0.4.6:3306/ntc_db/code_protocol_type_dic';
CREATE TABLE `ui_code_service_type_dic` ( CREATE TABLE `ui_code_service_type_dic` (

View File

@@ -32,8 +32,17 @@
</select> </select>
<!-- 根据最近时间条获取带宽,进出口流量 --> <!-- 根据最近时间条获取带宽,进出口流量 -->
<select id="getNetFlowPortInfoNew" resultType="java.util.HashMap"> <select id="getNetFlowPortInfoNew" resultType="java.util.HashMap">
SELECT IFNULL(SUM(c2s_byte_len),0) AS inoctets ,IFNULL(SUM(s2c_byte_len),0) AS outoctets FROM traffic_trans_statistic SELECT SUM(total_traffic.inoctets) AS inoctets ,SUM(total_traffic.outoctets) AS outoctets FROM (
WHERE stat_time > DATE_SUB(#{statTime}, INTERVAL 1 HOUR) SELECT IFNULL(SUM(c2s_byte_len),0) inoctets ,IFNULL(SUM(s2c_byte_len),0) outoctets FROM traffic_trans_statistic
where stat_time = (SELECT stat_time FROM traffic_trans_statistic WHERE entrance_id=1 ORDER BY stat_time DESC LIMIT 0,1) and entrance_id=1
UNION ALL
SELECT IFNULL(SUM(c2s_byte_len),0) inoctets ,IFNULL(SUM(s2c_byte_len),0) outoctets FROM traffic_trans_statistic
where stat_time = (SELECT stat_time FROM traffic_trans_statistic WHERE entrance_id=2 ORDER BY stat_time DESC LIMIT 0,1) and entrance_id=2
) total_traffic
</select> </select>
<!-- 获取近五分钟的带宽根据ip46协议 tcp,udp变化 --> <!-- 获取近五分钟的带宽根据ip46协议 tcp,udp变化 -->
<select id="getBandwidthTrans" resultMap="BandwidthResultMap"> <select id="getBandwidthTrans" resultMap="BandwidthResultMap">

View File

@@ -19,7 +19,9 @@ public interface TrafficHttpStatisticDao {
List<Map> getDomainByWebsiteServiceId(@Param("websiteServiceId") Integer websiteServiceId,@Param("statTime") Date statTime); List<Map> getDomainByWebsiteServiceId(@Param("websiteServiceId") Integer websiteServiceId,@Param("statTime") Date statTime);
Map websiteDomainOthers(@Param("webIdList") List webIdList,@Param("websiteServiceId") Integer websiteServiceId,@Param("statTime") Date statTime); Map websiteDomainOthers(@Param("webIdList") List webIdList,@Param("websiteServiceId") Integer websiteServiceId,@Param("statTime") Date statTime);
List<Map> getDomainByTopicList(@Param("statTime") Date statTime); List<Map> getDomainByTopicList(@Param("statTime") Date statTime,@Param("endTime")Date endTime);
List<Map> getDomainByTopicId(@Param("topicId")Object TopicId,@Param("statTime")Date statTime); List<Map> getUiWebsiteDomainTopicList( );
List<Map> getDomainByTopicId( @Param("statTime")Date statTime ,@Param("endTime")Date endTime);
} }

View File

@@ -1,41 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nis.web.dao.dashboard.TrafficHttpStatisticDao"> <mapper
<resultMap id="BaseResultMap" type="com.nis.domain.restful.dashboard.TrafficHttpStatistic"> namespace="com.nis.web.dao.dashboard.TrafficHttpStatisticDao">
<resultMap id="BaseResultMap"
type="com.nis.domain.restful.dashboard.TrafficHttpStatistic">
<id column="stat_id" jdbcType="INTEGER" property="statId" /> <id column="stat_id" jdbcType="INTEGER" property="statId" />
<result column="link_num" jdbcType="INTEGER" property="linkNum" /> <result column="link_num" jdbcType="INTEGER" property="linkNum" />
<result column="web_id" jdbcType="INTEGER" property="webId" /> <result column="web_id" jdbcType="INTEGER" property="webId" />
<result column="c2s_pkt_num" jdbcType="BIGINT" property="c2sPktNum" /> <result column="c2s_pkt_num" jdbcType="BIGINT"
<result column="s2c_pkt_num" jdbcType="BIGINT" property="s2cPktNum" /> property="c2sPktNum" />
<result column="c2s_byte_len" jdbcType="BIGINT" property="c2sByteLen" /> <result column="s2c_pkt_num" jdbcType="BIGINT"
<result column="s2c_byte_len" jdbcType="BIGINT" property="s2cByteLen" /> property="s2cPktNum" />
<result column="stat_time" jdbcType="TIMESTAMP" property="statTime" /> <result column="c2s_byte_len" jdbcType="BIGINT"
property="c2sByteLen" />
<result column="s2c_byte_len" jdbcType="BIGINT"
property="s2cByteLen" />
<result column="stat_time" jdbcType="TIMESTAMP"
property="statTime" />
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
stat_id, web_type, web_id, c2s_pkt_num, s2c_pkt_num, c2s_byte_len, s2c_byte_len, stat_id, web_type, web_id, c2s_pkt_num, s2c_pkt_num, c2s_byte_len,
s2c_byte_len,
stat_time stat_time
</sql> </sql>
<!-- 获取最近时间并且有效 --> <!-- 获取最近时间并且有效 -->
<select id="getMaxStatTime" resultType="com.nis.domain.restful.dashboard.TrafficHttpStatistic"> <select id="getMaxStatTime"
SELECT stat_time statTime FROM traffic_http_statistic order by stat_time desc limit 1 resultType="com.nis.domain.restful.dashboard.TrafficHttpStatistic">
SELECT stat_time statTime FROM traffic_http_statistic order by stat_time
desc limit 1
</select> </select>
<!-- 根据服务网站将域名分类 网站列表 --> <!-- 根据服务网站将域名分类 网站列表 -->
<select id="getDomainByWebsiteList" resultType="com.nis.domain.restful.dashboard.TrafficHttpStatistic"> <select id="getDomainByWebsiteList"
SELECT SUM(c2s_byte_len+s2c_byte_len) count, IFNULL( website_service_id, 268435455 ) websiteServiceId resultType="com.nis.domain.restful.dashboard.TrafficHttpStatistic">
SELECT SUM(c2s_byte_len+s2c_byte_len) count, IFNULL( website_service_id,
268435455 ) websiteServiceId
FROM TRAFFIC_HTTP_STATISTIC t FROM TRAFFIC_HTTP_STATISTIC t
LEFT JOIN ui_website_domain_topic u ON t.web_id = u.id LEFT JOIN ui_website_domain_topic u ON t.web_id = u.id
where t.stat_time > DATE_SUB(#{statTime},INTERVAL 1 hour) where t.stat_time > DATE_SUB(#{statTime},INTERVAL 1 hour)
GROUP BY u.website_service_id ORDER BY count desc limit 0,10 GROUP BY u.website_service_id ORDER BY count desc limit 0,10
</select> </select>
<!-- 根据主题将域名分类 主题列表 最近五分钟top10 --> <!-- 根据主题将域名分类 主题列表 最近五分钟top10 -->
<select id="getDomainByTopicList" resultType="java.util.HashMap"> <select id="getDomainByTopicList" resultType="java.util.HashMap">
SELECT SUM(c2s_byte_len+s2c_byte_len) count, IFNULL( topic_id, 268435455 ) topicId SELECT
FROM TRAFFIC_HTTP_STATISTIC t IFNULL(topic_id, 268435455) topicId,
LEFT JOIN ui_website_domain_topic u ON t.web_id = u.id id
and t.stat_time > DATE_SUB(#{statTime},INTERVAL 1 hour) FROM
GROUP BY u.topic_id ORDER BY count desc limit 0,10 ui_website_domain_topic u
GROUP BY
u.topic_id,
id
</select> </select>
<!--获取上个时间段该网站站域名流量的数据量 --> <!--获取上个时间段该网站站域名流量的数据量 -->
<select id="preWebsiteListCount" resultType="java.lang.Long"> <select id="preWebsiteListCount" resultType="java.lang.Long">
SELECT SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_http_statistic t SELECT SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_http_statistic t
@@ -46,13 +62,14 @@
</select> </select>
<!--获取网站列表列表 --> <!--获取网站列表列表 -->
<!-- <select id="websiteList" resultMap="BaseResultMap"> <!-- <select id="websiteList" resultMap="BaseResultMap"> SELECT web_id webId,
SELECT web_id webId, (SUM(c2s_pkt_num)+SUM(s2c_pkt_num)+SUM(c2s_byte_len)+SUM(s2c_byte_len)) count FROM traffic_http_statistic (SUM(c2s_pkt_num)+SUM(s2c_pkt_num)+SUM(c2s_byte_len)+SUM(s2c_byte_len)) count
WHERE web_id !=0 and stat_time >= DATE_SUB((SELECT MAX(stat_time) FROM traffic_http_statistic),INTERVAL 5 MINUTE) FROM traffic_http_statistic WHERE web_id !=0 and stat_time >= DATE_SUB((SELECT
GROUP BY web_id ORDER BY count DESC limit 0,10 MAX(stat_time) FROM traffic_http_statistic),INTERVAL 5 MINUTE) GROUP BY web_id
</select> --> ORDER BY count DESC limit 0,10 </select> -->
<!-- 根据网站分组获取子域名 --> <!-- 根据网站分组获取子域名 -->
<select id="getDomainByWebsiteServiceId" resultType="java.util.HashMap"> <select id="getDomainByWebsiteServiceId"
resultType="java.util.HashMap">
SELECT web_id webId,SUM(c2s_byte_len+s2c_byte_len) count SELECT web_id webId,SUM(c2s_byte_len+s2c_byte_len) count
FROM traffic_http_statistic t FROM traffic_http_statistic t
LEFT JOIN ui_website_domain_topic u ON t.web_id=u.id LEFT JOIN ui_website_domain_topic u ON t.web_id=u.id
@@ -62,23 +79,25 @@
</select> </select>
<!-- 根据主题分组获取子域名 --> <!-- 根据主题分组获取子域名 -->
<select id="getDomainByTopicId" resultType="java.util.HashMap"> <select id="getDomainByTopicId" resultType="java.util.HashMap">
SELECT web_id webId,SUM(c2s_byte_len+s2c_byte_len) count select web_id webId,sum(c2s_byte_len + s2c_byte_len) count from
FROM traffic_http_statistic t traffic_http_statistic t where
LEFT JOIN ui_website_domain_topic u ON t.web_id=u.id <![CDATA[ stat_time>= #{statTime} and stat_time< #{endTime} group by t.web_id ]]>
where u.topic_id=#{topicId}
and t.stat_time > DATE_SUB(#{statTime},INTERVAL 1 hour)
GROUP BY t.web_id ORDER BY count desc limit 0,10
</select> </select>
<!-- 指定网站下的TOP10之外为others --> <!-- 指定网站下的TOP10之外为others -->
<select id="websiteDomainOthers" resultType="java.util.HashMap"> <select id="websiteDomainOthers" resultType="java.util.HashMap">
SELECT SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_http_statistic t SELECT SUM(c2s_byte_len+s2c_byte_len) count FROM
traffic_http_statistic t
LEFT JOIN ui_website_domain_topic u ON t.web_id=u.id LEFT JOIN ui_website_domain_topic u ON t.web_id=u.id
where u.website_service_id=#{websiteServiceId} where u.website_service_id=#{websiteServiceId}
<if test="webIdList!=null and webIdList.size()>0"> <if test="webIdList!=null and webIdList.size()>0">
and t.web_id not in and t.web_id not in
<foreach collection="webIdList" item="singleType" index="index" open="(" close=")" separator=","> <foreach collection="webIdList" item="singleType"
index="index" open="(" close=")" separator=",">
#{singleType} #{singleType}
</foreach> </foreach>
</if> </if>

View File

@@ -17,7 +17,7 @@
</sql> </sql>
<!-- 获取最近时间 --> <!-- 获取最近时间 -->
<select id="getMaxStatTime" resultType="com.nis.domain.restful.dashboard.TrafficProtocolStatistic"> <select id="getMaxStatTime" resultType="com.nis.domain.restful.dashboard.TrafficProtocolStatistic">
SELECT stat_time statTime FROM traffic_protocol_statistic WHERE order by stat_time desc limit 1 SELECT stat_time statTime FROM traffic_protocol_statistic order by stat_time desc limit 1
</select> </select>
<select id="protocolChart" resultType="java.util.HashMap"> <select id="protocolChart" resultType="java.util.HashMap">
SELECT proto_type protoType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_protocol_statistic WHERE SELECT proto_type protoType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_protocol_statistic WHERE

View File

@@ -1,6 +1,12 @@
package com.nis.web.service; package com.nis.web.service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -12,22 +18,20 @@ import com.nis.util.StringUtils;
/** /**
* Service基类 * Service基类
*
* @author ThinkGem * @author ThinkGem
* @version 2014-05-16 * @version 2014-05-16
*/ */
public abstract class BaseService { public abstract class BaseService {
/** /**
* 日志对象 * 日志对象
*/ */
protected Logger logger = LoggerFactory.getLogger(getClass()); protected Logger logger = LoggerFactory.getLogger(getClass());
/** /**
* 数据范围过滤 * 数据范围过滤
*
* @param user 当前用户对象通过“entity.getCurrentUser()”获取 * @param user 当前用户对象通过“entity.getCurrentUser()”获取
* @param officeAlias 机构表别名,多个用“,”逗号隔开。 * @param officeAlias 机构表别名,多个用“,”逗号隔开。
* @param userAlias 用户表别名,多个用“,”逗号隔开,传递空,忽略此参数 * @param userAlias 用户表别名,多个用“,”逗号隔开,传递空,忽略此参数
@@ -35,7 +39,6 @@ public abstract class BaseService {
*/ */
public static String dataScopeFilter(SysUser user, String officeAlias, String userAlias) { public static String dataScopeFilter(SysUser user, String officeAlias, String userAlias) {
StringBuilder sqlString = new StringBuilder(); StringBuilder sqlString = new StringBuilder();
// 进行权限过滤,多个角色权限范围之间为或者关系。 // 进行权限过滤,多个角色权限范围之间为或者关系。
@@ -49,8 +52,6 @@ public abstract class BaseService {
if (user.isAdmin()) { if (user.isAdmin()) {
boolean isDataScopeAll = isContainsDataScopeAll(user.getUserRoleList()); boolean isDataScopeAll = isContainsDataScopeAll(user.getUserRoleList());
for (SysRole r : user.getUserRoleList()) { for (SysRole r : user.getUserRoleList()) {
for (String oa : StringUtils.split(officeAlias, ",")) { for (String oa : StringUtils.split(officeAlias, ",")) {
if (!dataScope.contains(r.getDataScope()) && StringUtils.isNotBlank(oa)) { if (!dataScope.contains(r.getDataScope()) && StringUtils.isNotBlank(oa)) {
@@ -83,11 +84,9 @@ public abstract class BaseService {
return ""; return "";
} }
/** /**
* 测试数据是否包含全集 * 测试数据是否包含全集
*
* @return * @return
*/ */
private static boolean isContainsDataScopeAll(List<SysRole> roleList) { private static boolean isContainsDataScopeAll(List<SysRole> roleList) {
@@ -104,9 +103,9 @@ public abstract class BaseService {
} }
/** /**
* 过滤机构信息 * 过滤机构信息
*
* @param dataScope 数据范围1所有数据2所在公司及以下数据3所在公司数据4所在部门及以下数据5所在部门数据6所在单位及以下数据7所在单位数据 * @param dataScope 数据范围1所有数据2所在公司及以下数据3所在公司数据4所在部门及以下数据5所在部门数据6所在单位及以下数据7所在单位数据
* @return * @return
*/ */
@@ -115,39 +114,74 @@ public abstract class BaseService {
if (SysRole.DATA_SCOPE_COMPANY_AND_CHILD.equals(dataScope)) { if (SysRole.DATA_SCOPE_COMPANY_AND_CHILD.equals(dataScope)) {
scopeSql.append(" OR " + officeAlias + ".id = " + user.getCompany().getId()); scopeSql.append(" OR " + officeAlias + ".id = " + user.getCompany().getId());
scopeSql.append(" OR " + officeAlias + ".parent_ids LIKE '" + user.getCompany().getParentIds() + user.getCompany().getId() + ",%'"); scopeSql.append(" OR " + officeAlias + ".parent_ids LIKE '" + user.getCompany().getParentIds()
} + user.getCompany().getId() + ",%'");
else if (SysRole.DATA_SCOPE_COMPANY.equals(dataScope)){ } else if (SysRole.DATA_SCOPE_COMPANY.equals(dataScope)) {
scopeSql.append(" OR " + officeAlias + ".id = " + user.getCompany().getId()); scopeSql.append(" OR " + officeAlias + ".id = " + user.getCompany().getId());
// 包括本公司下的部门 type=1:公司type=2单位 3.部门) // 包括本公司下的部门 type=1:公司type=2单位 3.部门)
scopeSql.append(" OR (" + officeAlias + ".parent_id = '" + user.getCompany().getId() + "' AND " + officeAlias + ".type>1)"); scopeSql.append(" OR (" + officeAlias + ".parent_id = '" + user.getCompany().getId() + "' AND "
} + officeAlias + ".type>1)");
else if (SysRole.DATA_SCOPE_OFFICE_AND_CHILD.equals(dataScope)){ } else if (SysRole.DATA_SCOPE_OFFICE_AND_CHILD.equals(dataScope)) {
scopeSql.append(" OR " + officeAlias + ".id = " + user.getOffice().getId()); scopeSql.append(" OR " + officeAlias + ".id = " + user.getOffice().getId());
scopeSql.append(" OR " + officeAlias + ".parent_ids LIKE '" + user.getOffice().getParentIds() + user.getOffice().getId() + ",%'"); scopeSql.append(" OR " + officeAlias + ".parent_ids LIKE '" + user.getOffice().getParentIds()
} + user.getOffice().getId() + ",%'");
else if (SysRole.DATA_SCOPE_OFFICE.equals(dataScope)){ } else if (SysRole.DATA_SCOPE_OFFICE.equals(dataScope)) {
scopeSql.append(" OR " + officeAlias + ".id = " + user.getOffice().getId()); scopeSql.append(" OR " + officeAlias + ".id = " + user.getOffice().getId());
} } else if (SysRole.DATA_SCOPE_ENTITY_AND_CHILD.equals(dataScope)) {
else if (SysRole.DATA_SCOPE_ENTITY_AND_CHILD.equals(dataScope)){
scopeSql.append(" OR " + officeAlias + ".id = " + user.getEntity().getId()); scopeSql.append(" OR " + officeAlias + ".id = " + user.getEntity().getId());
scopeSql.append(" OR " + officeAlias + ".parent_ids LIKE '" + user.getEntity().getParentIds() + user.getEntity().getId() + ",%'"); scopeSql.append(" OR " + officeAlias + ".parent_ids LIKE '" + user.getEntity().getParentIds()
+ user.getEntity().getId() + ",%'");
} else if (SysRole.DATA_SCOPE_ENTITY.equals(dataScope)) { } else if (SysRole.DATA_SCOPE_ENTITY.equals(dataScope)) {
scopeSql.append(" OR " + officeAlias + ".id = " + user.getEntity().getId()); scopeSql.append(" OR " + officeAlias + ".id = " + user.getEntity().getId());
// 包括本公司下的部门 type=1:公司type=2单位 3.部门) // 包括本公司下的部门 type=1:公司type=2单位 3.部门)
scopeSql.append(" OR (" + officeAlias + ".parent_id = '" + user.getEntity().getId() + "' AND " + officeAlias + ".type>1)"); scopeSql.append(" OR (" + officeAlias + ".parent_id = '" + user.getEntity().getId() + "' AND " + officeAlias
+ ".type>1)");
} }
return scopeSql.toString(); return scopeSql.toString();
} }
/**
* 获取前几个小时的数据
*
* @param ihour
* @return
*/
protected Date getBeforeByHourTime(int ihour) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - ihour);
return calendar.getTime();
}
/**
* 根据count降序排列获取top10的count对应的view
*
* @param set 所有的count
* @param countAndViewMap key是count,val是viewmap
*/
protected List<Map> getTop10Data(Set<Long> set, Map<Long, List<Map>> countAndViewMap) {
List<Map> topicList = new ArrayList<Map>();
Long[] countArr = new Long[set.size()];
set.toArray(countArr);
Arrays.sort(countArr);
for (int i = countArr.length - 1; i >= 0; i--) {
List<Map> list = countAndViewMap.get(countArr[i]);
boolean exit = false;
for (Map map : list) {
topicList.add(map);
if (topicList.size() == 10) {
exit = true;
break;
}
}
if (exit) {
break;
}
}
return topicList;
}
} }

View File

@@ -10,6 +10,7 @@ import com.zdjizhi.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
@Service @Service
@@ -31,8 +32,7 @@ public class DashboardService extends BaseService{
public TrafficPortActiveStatisticDao trafficPortActiveStatisticDao; public TrafficPortActiveStatisticDao trafficPortActiveStatisticDao;
/** /**
* 流量统计 数据显示 * 流量统计 数据显示 info先查询最近时间根据时间条件查询数据 效率提高
* info先查询最近时间根据时间条件查询数据 效率提高
*/ */
public List<Map> getTotalReportList() { public List<Map> getTotalReportList() {
List<Map> totalReportList = new ArrayList<Map>(); List<Map> totalReportList = new ArrayList<Map>();
@@ -65,8 +65,10 @@ public class DashboardService extends BaseService{
} }
return totalReportList; return totalReportList;
} }
/** /**
* 根据ip46,协议tcpudp查询带宽 * 根据ip46,协议tcpudp查询带宽
*
* @param addrType * @param addrType
* @param transType * @param transType
* @return * @return
@@ -107,9 +109,9 @@ public class DashboardService extends BaseService{
} }
return listMap; return listMap;
} }
/** /**
* 根据service 动作查询近五分钟变化趋势 * 根据service 动作查询近五分钟变化趋势 entrance 默认为1,2
* entrance 默认为1,2
*/ */
public List<HashMap> getActionTrans(String serviceType) { public List<HashMap> getActionTrans(String serviceType) {
String sql = ""; String sql = "";
@@ -170,6 +172,7 @@ public class DashboardService extends BaseService{
/** /**
* 最近活跃端口时间五分钟数据 * 最近活跃端口时间五分钟数据
*
* @return List * @return List
*/ */
public List<Map> getPortActiveList() { public List<Map> getPortActiveList() {
@@ -185,7 +188,8 @@ public class DashboardService extends BaseService{
Map map = new HashMap(); Map map = new HashMap();
map.put("port", port.getPort()); map.put("port", port.getPort());
map.put("sum", port.getSum()); map.put("sum", port.getSum());
TrafficPortActiveStatistic portActiveOld = trafficPortActiveStatisticDao.getPortActiveOld(port.getPort(),statTime); TrafficPortActiveStatistic portActiveOld = trafficPortActiveStatisticDao
.getPortActiveOld(port.getPort(), statTime);
if (portActiveOld != null && portActiveOld.getSum() != null) { if (portActiveOld != null && portActiveOld.getSum() != null) {
map.put("preSum", portActiveOld.getSum()); map.put("preSum", portActiveOld.getSum());
} else { } else {
@@ -199,9 +203,9 @@ public class DashboardService extends BaseService{
return list; return list;
} }
/** /**
* 活跃IP最近五分钟数据TOP10 * 活跃IP最近五分钟数据TOP10
*
* @return * @return
*/ */
public List<HashMap> ipActiveFiveMinute() { public List<HashMap> ipActiveFiveMinute() {
@@ -218,7 +222,8 @@ public class DashboardService extends BaseService{
String ipAddr = (String) map.get("ipAddr"); String ipAddr = (String) map.get("ipAddr");
m.put("ipAddr", ipAddr); m.put("ipAddr", ipAddr);
// 根据五分钟TOP10IP查询TOP10中每个IP最近一小时的变化 // 根据五分钟TOP10IP查询TOP10中每个IP最近一小时的变化
ArrayList<TrafficIpActiveStatistic> ipList = trafficIpActiveStatisticDao.ipActiveFiveMinute(ipAddr,statTime); ArrayList<TrafficIpActiveStatistic> ipList = trafficIpActiveStatisticDao
.ipActiveFiveMinute(ipAddr, statTime);
List linkList = new ArrayList(); List linkList = new ArrayList();
List timeList = new ArrayList(); List timeList = new ArrayList();
if (ipList != null && ipList.size() > 0) { if (ipList != null && ipList.size() > 0) {
@@ -239,8 +244,10 @@ public class DashboardService extends BaseService{
return listMap; return listMap;
} }
/** /**
* 根据活跃IP最近五分钟TOP10查询近1小时最大值 * 根据活跃IP最近五分钟TOP10查询近1小时最大值
*
* @return * @return
*/ */
public List<HashMap> ipActiveOneHour() { public List<HashMap> ipActiveOneHour() {
@@ -262,6 +269,7 @@ public class DashboardService extends BaseService{
return listMap; return listMap;
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public List<LinkedHashMap> ipActiveChart() { public List<LinkedHashMap> ipActiveChart() {
TrafficIpActiveStatistic maxStatTime = trafficIpActiveStatisticDao.getMaxStatTime(); TrafficIpActiveStatistic maxStatTime = trafficIpActiveStatisticDao.getMaxStatTime();
@@ -284,6 +292,7 @@ public class DashboardService extends BaseService{
/** /**
* 协议统计 * 协议统计
*
* @return * @return
*/ */
public List<Map> protocolChart() { public List<Map> protocolChart() {
@@ -304,6 +313,7 @@ public class DashboardService extends BaseService{
/** /**
* 协议统计报表 * 协议统计报表
*
* @return * @return
*/ */
public List<Map> getProtocolList(String startTime, String endTime) { public List<Map> getProtocolList(String startTime, String endTime) {
@@ -318,6 +328,7 @@ public class DashboardService extends BaseService{
/** /**
* app应用top10 图 * app应用top10 图
*
* @return * @return
*/ */
public List<Map> appChart() { public List<Map> appChart() {
@@ -335,8 +346,10 @@ public class DashboardService extends BaseService{
} }
return list; return list;
} }
/** /**
* App统计报表 * App统计报表
*
* @return * @return
*/ */
public List<Map> getAppList(String startTime, String endTime) { public List<Map> getAppList(String startTime, String endTime) {
@@ -348,6 +361,7 @@ public class DashboardService extends BaseService{
} }
return list; return list;
} }
// 操作系统列表 排名TOP10 // 操作系统列表 排名TOP10
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
public List<Map> systemList() { public List<Map> systemList() {
@@ -374,6 +388,7 @@ public class DashboardService extends BaseService{
} }
return result; return result;
} }
public List<Map> getBrowserBySystem(Integer osType) { public List<Map> getBrowserBySystem(Integer osType) {
List<Map> list = new ArrayList<Map>(); List<Map> list = new ArrayList<Map>();
TrafficUaStatistic maxStatTime = trafficUaStatisticDao.getMaxStatTime(); TrafficUaStatistic maxStatTime = trafficUaStatisticDao.getMaxStatTime();
@@ -425,6 +440,7 @@ public class DashboardService extends BaseService{
} }
return result; return result;
} }
public List<Map> getSystemBybrowser(Integer bsType) { public List<Map> getSystemBybrowser(Integer bsType) {
List<Map> list = new ArrayList<Map>(); List<Map> list = new ArrayList<Map>();
TrafficUaStatistic maxStatTime = trafficUaStatisticDao.getMaxStatTime(); TrafficUaStatistic maxStatTime = trafficUaStatisticDao.getMaxStatTime();
@@ -449,6 +465,7 @@ public class DashboardService extends BaseService{
} }
return list; return list;
} }
public List<Map> websiteList() { public List<Map> websiteList() {
List<Map> result = new ArrayList<Map>(); List<Map> result = new ArrayList<Map>();
TrafficHttpStatistic maxStatTime = trafficHttpStatisticDao.getMaxStatTime(); TrafficHttpStatistic maxStatTime = trafficHttpStatisticDao.getMaxStatTime();
@@ -462,7 +479,8 @@ public class DashboardService extends BaseService{
map.put("count", website.getCount()); map.put("count", website.getCount());
map.put("pktNum", 0); map.put("pktNum", 0);
map.put("byteLen", 0); map.put("byteLen", 0);
preCount = trafficHttpStatisticDao.preWebsiteListCount(website.getWebId(),maxStatTime.getStatTime());//上个时段的量 用于与现在对比 preCount = trafficHttpStatisticDao.preWebsiteListCount(website.getWebId(),
maxStatTime.getStatTime());// 上个时段的量 用于与现在对比
if (preCount != null) { if (preCount != null) {
map.put("preCount", preCount); map.put("preCount", preCount);
} else { } else {
@@ -474,8 +492,10 @@ public class DashboardService extends BaseService{
} }
return result; return result;
} }
/** /**
* 根据网站服务查询子域名 * 根据网站服务查询子域名
*
* @param websiteServiceId * @param websiteServiceId
* @return list * @return list
*/ */
@@ -505,7 +525,8 @@ public class DashboardService extends BaseService{
} }
/** /**
获取网站列表 * 获取网站列表
*
* @return * @return
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@@ -523,7 +544,8 @@ public class DashboardService extends BaseService{
map.put("count", website.getCount()); map.put("count", website.getCount());
map.put("pktNum", 0); map.put("pktNum", 0);
map.put("byteLen", 0); map.put("byteLen", 0);
preCount = trafficHttpStatisticDao.preWebsiteListCount(website.getWesiteServiceId(),statTime);//上个时段的量 用于与现在对比 preCount = trafficHttpStatisticDao.preWebsiteListCount(website.getWesiteServiceId(), statTime);// 上个时段的量
// 用于与现在对比
if (preCount != null) { if (preCount != null) {
map.put("preCount", preCount); map.put("preCount", preCount);
} else { } else {
@@ -535,27 +557,65 @@ public class DashboardService extends BaseService{
} }
return result; return result;
} }
/** /**
* 主题网站分类,域名 * 主题网站分类,域名
* *
* **/ **/
public List<Map> getTopicAndDomainList() { public List<Map> getTopicAndDomainList() {
List<Map> topicList = new ArrayList<Map>();
TrafficHttpStatistic maxStatTime = trafficHttpStatisticDao.getMaxStatTime(); Date startTime = getBeforeByHourTime(1);// 获取上一个小时
if(maxStatTime!=null) { Map<String, List<String>> topicIdAndIdMap = new HashMap<>();// 存储topicid和id的对应关系,一个topicid有多个id
Date statTime = maxStatTime.getStatTime(); List<Map> topicIdAndIdList = trafficHttpStatisticDao.getDomainByTopicList(startTime, new Date());// 获取最近一个小时topicId和id的对应关系,group
//按照主题分类 获得主题 for (Map map : topicIdAndIdList) {
topicList = trafficHttpStatisticDao.getDomainByTopicList(statTime); Object topicIdObj = map.get("topicId");
if(topicList!=null&&topicList.size()>0){ Object idObj = map.get("id");
for (Map m : topicList) { if (topicIdObj != null && idObj != null) {
List<Map> domainList= new ArrayList<Map>(); if (topicIdAndIdMap.containsKey(String.valueOf(topicIdObj))) {
if(m!=null&&m.get("topicId")!=null){ topicIdAndIdMap.get(String.valueOf(topicIdObj)).add(String.valueOf(idObj));
domainList = trafficHttpStatisticDao.getDomainByTopicId(m.get("topicId"),statTime); } else {
m.put("domainData", domainList); List<String> list = new ArrayList<>();
list.add(String.valueOf(idObj));
topicIdAndIdMap.put(String.valueOf(topicIdObj), list);
}
}
}
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的关系
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
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"));
if (countStr != null) {
count += Long.parseLong(countStr);// 将count累加
list.add(webIdAndCountMap);
} }
} }
} }
} }
return topicList; viewMap.put("count", count);
viewMap.put("domainData", list);
if (countAndViewMap.containsKey(count)) {// 将每个count和对应的viewmap放到map中,count可能相同所以value是list
countAndViewMap.get(count).add(viewMap);
} else {
List<Map> listMap = new ArrayList<>();
listMap.add(viewMap);
countAndViewMap.put(count, listMap);
} }
set.add(count);
}
return getTop10Data(set, countAndViewMap);
}
} }