2018-07-13 19:39:04 +08:00
package com.nis.web.service.restful ;
2018-12-01 13:19:30 +06:00
import com.beust.jcommander.internal.Maps ;
2018-12-06 17:19:33 +08:00
import com.nis.domain.restful.NtcEntranceReport ;
2018-12-01 13:19:30 +06:00
import com.nis.domain.restful.dashboard.* ;
2018-12-06 17:19:33 +08:00
import com.nis.util.StringUtils ;
2018-12-01 13:19:30 +06:00
import com.nis.web.dao.dashboard.* ;
import com.nis.web.service.BaseService ;
import com.zdjizhi.utils.StringUtil ;
2018-07-13 19:39:04 +08:00
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
2018-12-10 10:23:48 +06:00
import java.text.SimpleDateFormat ;
2018-12-01 13:19:30 +06:00
import java.util.* ;
2018-07-13 19:39:04 +08:00
@Service
2018-12-10 10:23:48 +06:00
public class DashboardService extends BaseService {
2018-07-13 19:39:04 +08:00
@Autowired
public TrafficIpActiveStatisticDao trafficIpActiveStatisticDao ;
@Autowired
public TrafficProtocolStatisticDao trafficProtocolStatisticDao ;
@Autowired
public TrafficAppStatisticDao trafficAppStatisticDao ;
@Autowired
public TrafficUaStatisticDao trafficUaStatisticDao ;
@Autowired
public TrafficHttpStatisticDao trafficHttpStatisticDao ;
2018-09-21 20:56:01 +08:00
@Autowired
public NtcTotalReportDao ntcTotalReportDao ;
@Autowired
public TrafficPortActiveStatisticDao trafficPortActiveStatisticDao ;
2018-12-10 10:23:48 +06:00
2018-09-21 20:56:01 +08:00
/ * *
2018-12-10 10:23:48 +06:00
* 流量统计 数据显示 info : 先查询最近时间 , 根据时间条件查询数据 效率提高
2018-09-21 20:56:01 +08:00
* /
2018-12-10 10:23:48 +06:00
public List < Map > getTotalReportList ( ) {
List < Map > totalReportList = new ArrayList < Map > ( ) ;
2018-12-04 11:59:01 +08:00
List < Map > newData = new ArrayList < Map > ( ) ;
// 流量统计阻断丢弃回流等数据显示最近时间
2018-10-26 14:41:27 +08:00
NtcTotalReport maxReportTime = ntcTotalReportDao . getMaxReportTime ( ) ;
2018-12-10 10:23:48 +06:00
if ( maxReportTime ! = null & & maxReportTime . getReportTime ( ) ! = null ) {
2018-10-26 14:41:27 +08:00
Date reportTime = maxReportTime . getReportTime ( ) ;
2018-12-04 11:59:01 +08:00
totalReportList = ntcTotalReportDao . getTotalReportList ( reportTime ) ; // 返回阻断,监测等結果
2018-10-26 14:41:27 +08:00
}
2018-12-04 11:59:01 +08:00
Map maxRecvtTime = ntcTotalReportDao . getMaxStatTime ( ) ;
2018-12-10 10:23:48 +06:00
if ( maxRecvtTime ! = null & & maxRecvtTime . get ( " statTime " ) ! = null ) {
2018-11-16 11:08:50 +08:00
Date recvTime = ( Date ) maxRecvtTime . get ( " statTime " ) ;
2018-10-26 14:41:27 +08:00
newData = ntcTotalReportDao . getNetFlowPortInfoNew ( recvTime ) ;
}
2018-12-04 11:59:01 +08:00
// 统计带宽的流入流出 单位 五分钟 的 byte
2018-12-10 10:23:48 +06:00
if ( StringUtil . isNotEmpty ( newData ) ) {
Double inoctets = Double . parseDouble ( newData . get ( 0 ) . get ( " inoctets " ) . toString ( ) ) ;
Double outoctets = Double . parseDouble ( newData . get ( 0 ) . get ( " outoctets " ) . toString ( ) ) ;
2018-12-01 13:19:30 +06:00
if ( StringUtil . isEmpty ( totalReportList ) ) {
Map valueMap = Maps . newHashMap ( ) ;
valueMap . put ( " inoctets " , inoctets ) ;
valueMap . put ( " outoctets " , outoctets ) ;
totalReportList . add ( valueMap ) ;
} else {
totalReportList . get ( 0 ) . put ( " inoctets " , inoctets ) ;
totalReportList . get ( 0 ) . put ( " outoctets " , outoctets ) ;
2018-09-26 16:29:53 +08:00
}
}
2018-09-21 20:56:01 +08:00
return totalReportList ;
}
2018-12-10 10:23:48 +06:00
2018-10-23 11:05:35 +08:00
/ * *
2018-12-04 11:59:01 +08:00
* 根据ip46 , 协议tcp , udp查询带宽
2018-12-10 10:23:48 +06:00
*
2018-12-04 11:59:01 +08:00
* @param addrType
* @param transType
2018-10-23 11:05:35 +08:00
* @return
* /
2018-12-12 10:43:47 +08:00
/ * public List < HashMap > getBandwidthTrans ( String addrType , Integer transType , String beginDate , String endDate ) {
2018-12-10 10:23:48 +06:00
ArrayList < HashMap > listMap = new ArrayList < HashMap > ( ) ;
2018-12-04 11:59:01 +08:00
List < TrafficTransStatistic > bandwidthList = new ArrayList < TrafficTransStatistic > ( ) ;
Map maxStatTime = ntcTotalReportDao . getMaxStatTime ( ) ;
2018-12-10 10:23:48 +06:00
if ( maxStatTime ! = null & & maxStatTime . get ( " statTime " ) ! = null ) {
2018-12-04 11:59:01 +08:00
Date stat = ( Date ) maxStatTime . get ( " statTime " ) ;
HashMap m = new HashMap ( ) ;
2018-12-10 10:23:48 +06:00
bandwidthList = ntcTotalReportDao . getBandwidthTrans ( stat , addrType , transType ) ;
2018-12-04 11:59:01 +08:00
List timeList = new ArrayList ( ) ;
List linkList = new ArrayList ( ) ;
List gbpsList = new ArrayList ( ) ;
List ppsList = new ArrayList ( ) ;
2018-12-10 10:23:48 +06:00
if ( bandwidthList ! = null & & bandwidthList . size ( ) > 0 ) {
2018-12-04 11:59:01 +08:00
for ( TrafficTransStatistic tt : bandwidthList ) {
2018-12-10 10:23:48 +06:00
if ( tt . getTime ( ) ! = null ) {
2018-12-04 11:59:01 +08:00
timeList . add ( tt . getTime ( ) ) ;
2018-12-10 10:23:48 +06:00
if ( tt . getLinkNum ( ) ! = null ) {
2018-12-04 11:59:01 +08:00
linkList . add ( tt . getLinkNum ( ) ) ;
}
2018-12-10 10:23:48 +06:00
if ( tt . getPps ( ) ! = null ) {
2018-12-04 11:59:01 +08:00
ppsList . add ( tt . getPps ( ) ) ;
}
2018-12-10 10:23:48 +06:00
if ( tt . getGbps ( ) ! = null ) {
2018-12-04 11:59:01 +08:00
gbpsList . add ( tt . getGbps ( ) ) ;
}
}
}
}
2018-12-10 10:23:48 +06:00
m . put ( " linkNum " , linkList ) ;
m . put ( " gbps " , gbpsList ) ;
m . put ( " pps " , ppsList ) ;
m . put ( " statTime " , timeList ) ;
2018-12-04 11:59:01 +08:00
listMap . add ( m ) ;
}
return listMap ;
2018-12-12 10:43:47 +08:00
} * /
/ * *
* 根据ip46 , 协议tcp , udp查询带宽
*
* @param addrType
* @param transType
* @return
* /
public List < HashMap > getBandwidthTrans ( String addrType , Integer transType , String beginDate , String endDate ) {
ArrayList < HashMap > listMap = new ArrayList < HashMap > ( ) ;
HashMap m1 = getBandwidthTransEntrance ( addrType , transType , beginDate , endDate , 1 ) ;
if ( m1 ! = null & & m1 . size ( ) > 0 ) {
m1 . put ( " entranceId " , 1 ) ; // 局点1.2 不同来源
listMap . add ( m1 ) ;
}
return listMap ;
}
/ * *
* 根据ip46 , 协议tcp , udp查询带宽
*
* @param addrType
* @param transType
* @return
* /
public List < HashMap > getBandwidthTrans2 ( String addrType , Integer transType , String beginDate , String endDate ) {
ArrayList < HashMap > listMap = new ArrayList < HashMap > ( ) ;
HashMap m2 = getBandwidthTransEntrance ( addrType , transType , beginDate , endDate , 2 ) ;
if ( m2 ! = null & & m2 . size ( ) > 0 ) {
m2 . put ( " entranceId " , 2 ) ;
listMap . add ( m2 ) ;
}
return listMap ;
}
/ * *
* 查询单个局点流量的数据信息
* @param addrType
* @param transType
* @param beginDate
* @param endDate
* @param entranceId
* @return
* /
public HashMap getBandwidthTransEntrance ( String addrType , Integer transType , String beginDate , String endDate , Integer entranceId ) {
long start = System . currentTimeMillis ( ) ;
ArrayList < HashMap > listMap = new ArrayList < HashMap > ( ) ;
List < TrafficTransStatistic > bandwidthList = new ArrayList < TrafficTransStatistic > ( ) ;
HashMap resulMap = new HashMap ( ) ;
bandwidthList = ntcTotalReportDao . getBandwidthTrans ( entranceId , beginDate , endDate , addrType , transType ) ;
List timeList = new ArrayList ( ) ;
List linkList = new ArrayList ( ) ;
List gbpsList = new ArrayList ( ) ;
List ppsList = new ArrayList ( ) ;
if ( bandwidthList ! = null & & bandwidthList . size ( ) > 0 ) {
Map < String , Comparable > m = new HashMap < String , Comparable > ( ) ;
int inter = 1000 * 60 * 5 ; // 间隔时间为五分钟
// 开始时间,结束时间 时间戳
2018-12-13 19:17:52 +08:00
Long b = dateToStamp ( beginDate ) ;
Long e = dateToStamp ( endDate ) ;
2018-12-12 10:43:47 +08:00
int num = 0 ;
Long pointTime = b ;
2018-12-13 19:17:52 +08:00
while ( pointTime < e ) {
2018-12-12 10:43:47 +08:00
Map rm = new HashMap ( ) ;
Long sumL = 0l ;
Long sumP = 0l ;
Long sumG = 0l ;
2018-12-13 19:17:52 +08:00
if ( pointTime > = e ) {
2018-12-12 10:43:47 +08:00
break ; //停止
}
for ( TrafficTransStatistic tt : bandwidthList ) {
// 实际时间
String time = tt . getTime ( ) ;
Long t = dateToStamp ( time ) ;
if ( t > = pointTime & & t < pointTime + inter ) {
// 范围之内分到此pointTime组
sumL = sumL + tt . getLinkNum ( ) ;
sumP = sumP + tt . getPps ( ) ;
sumG = sumG + tt . getGbps ( ) ;
}
}
2018-12-13 19:17:52 +08:00
// 在结束时间只有当值大于0时才记录数据, 防止折线降为0引起误会
if ( pointTime > = e - inter & & sumL > 0 ) {
linkList . add ( sumL ) ;
}
if ( pointTime > = e - inter & & sumP > 0 ) {
ppsList . add ( sumP ) ;
}
if ( pointTime > = e - inter & & sumG > 0 ) {
gbpsList . add ( sumG ) ;
}
if ( pointTime > = e - inter & & ( sumL > 0 | | sumG > 0 | | sumP > 0 ) ) {
timeList . add ( stampToDate ( pointTime ) ) ;
}
if ( pointTime < e - inter ) {
timeList . add ( stampToDate ( pointTime ) ) ;
linkList . add ( sumL ) ;
gbpsList . add ( sumG ) ;
ppsList . add ( sumP ) ;
}
2018-12-12 10:43:47 +08:00
num = num + 1 ;
2018-12-13 19:17:52 +08:00
pointTime = b + inter * num ;
2018-12-12 10:43:47 +08:00
}
resulMap . put ( " linkNum " , linkList ) ;
resulMap . put ( " gbps " , gbpsList ) ;
resulMap . put ( " pps " , ppsList ) ;
resulMap . put ( " statTime " , timeList ) ;
}
return resulMap ;
2018-12-04 11:59:01 +08:00
}
2018-12-10 10:23:48 +06:00
2018-12-12 10:43:47 +08:00
/ * *
* 将结果格式为时间间隔相同 , 数量补0数据
* @param begin
* @param end
* @param li
* @return
* /
public static List < Map > formatDateData ( String begin , String end , List < Map > li ) {
List < Map > resList = new ArrayList < Map > ( ) ;
Map < String , Comparable > m = new HashMap < String , Comparable > ( ) ;
int inter = 1000 * 60 * 60 ; // 间隔时间为一小时
// 开始时间,结束时间 时间戳
Long b = dateToStamp ( begin ) ;
Long e = dateToStamp ( end ) ;
int num = 0 ;
Long pointTime = b ;
2018-12-13 19:17:52 +08:00
while ( pointTime < e ) {
2018-12-12 10:43:47 +08:00
Map rm = new HashMap ( ) ;
Long sum = 0l ;
2018-12-13 19:17:52 +08:00
if ( pointTime > = e ) {
2018-12-12 10:43:47 +08:00
break ; //停止
}
for ( Map < ? , ? > map : li ) {
// 实际时间
String time = ( String ) map . get ( " time " ) ;
Long t = dateToStamp ( time ) ;
if ( t > = pointTime & & t < pointTime + inter ) {
// 范围之内分到此pointTime组
sum = sum + ( Long ) map . get ( " count " ) ;
}
}
rm . put ( " time " , stampToDate ( pointTime ) ) ;
rm . put ( " sum " , sum ) ;
num = num + 1 ;
2018-12-13 19:17:52 +08:00
pointTime = b + inter * num ;
2018-12-12 10:43:47 +08:00
resList . add ( rm ) ;
}
return resList ;
}
/ * *
* 日期格式字符串转换成时间戳
* @param date 字符串日期
* @param format 如 : yyyy - MM - dd HH : mm : ss
* @return
* /
public static Long dateToStamp ( String date_str ) {
try {
SimpleDateFormat sdf = new SimpleDateFormat ( " yyyy-MM-dd HH:mm:ss " ) ;
return sdf . parse ( date_str ) . getTime ( ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
return 0l ;
}
/ * *
* 时间戳 换成日期格式字符串转
* @param 时间 1544602212000
* @param format 如 : yyyy - MM - dd HH : mm : ss
* @return
* /
public static String stampToDate ( long timeStamp ) {
2018-12-12 17:17:41 +08:00
SimpleDateFormat sdf = new SimpleDateFormat ( " MM-dd HH:mm " ) ; //这个是你要转成后的时间的格式
2018-12-12 10:43:47 +08:00
String sd = sdf . format ( new Date ( timeStamp ) ) ; // 时间戳转换成时间
return sd ;
}
2018-12-06 17:19:33 +08:00
/ * *
2018-12-10 10:23:48 +06:00
* 根据service 动作查询近五分钟变化趋势 entrance 默认为1 , 2
2018-12-06 17:19:33 +08:00
* /
2018-12-13 19:17:52 +08:00
public List < HashMap > getActionTrans ( String begin , String end , String serviceType ) {
2018-12-10 10:23:48 +06:00
String sql = " " ;
String sqlBlock = " ((service>=16 and service<=40) or (service>=258 and service<=273) or (service=576)) " ; // 阻断
String sqlMonitor = " ((service>=128 and service<=152) or (service>=384 and service<=513) or (service=592) or (service>=848 and service<=1030) or (service=1152)) " ; // 监测
2018-12-06 17:19:33 +08:00
// 区分动作
2018-12-10 10:23:48 +06:00
if ( StringUtils . isNotBlank ( serviceType ) ) {
if ( serviceType . equalsIgnoreCase ( " block " ) ) {
sql = sqlBlock ;
2018-12-06 17:19:33 +08:00
}
2018-12-10 10:23:48 +06:00
if ( serviceType . equalsIgnoreCase ( " monitor " ) ) {
sql = sqlMonitor ;
2018-12-06 17:19:33 +08:00
}
}
2018-12-10 10:23:48 +06:00
ArrayList < HashMap > listMap = new ArrayList < HashMap > ( ) ;
2018-12-06 17:19:33 +08:00
List < NtcEntranceReport > entrance1 = new ArrayList < NtcEntranceReport > ( ) ;
List < NtcEntranceReport > entrance2 = new ArrayList < NtcEntranceReport > ( ) ;
HashMap m1 = new HashMap ( ) ;
HashMap m2 = new HashMap ( ) ;
2018-12-13 19:17:52 +08:00
entrance1 = ntcTotalReportDao . getActionTrans ( begin , end , 1 , sql ) ;
entrance2 = ntcTotalReportDao . getActionTrans ( begin , end , 2 , sql ) ;
2018-12-06 17:19:33 +08:00
List timeList = new ArrayList ( ) ;
List sumList1 = new ArrayList ( ) ;
List sumList2 = new ArrayList ( ) ;
2018-12-13 19:17:52 +08:00
Map < String , Comparable > m = new HashMap < String , Comparable > ( ) ;
int inter = 1000 * 60 * 5 ; // 间隔时间为五分钟
// 开始时间,结束时间 时间戳
Long b = dateToStamp ( begin ) ;
Long e = dateToStamp ( end ) ;
int num = 0 ;
Long pointTime = b ;
while ( pointTime < e ) {
Map rm = new HashMap ( ) ;
Long sum1 = 0l ;
Long sum2 = 0l ;
if ( pointTime > = e ) {
break ; //停止
}
for ( NtcEntranceReport e1 : entrance1 ) {
// 实际时间
String time = e1 . getTime ( ) ;
Long t = dateToStamp ( time ) ;
if ( t > = pointTime & & t < pointTime + inter ) {
// 范围之内分到此pointTime组
sum1 = sum1 + e1 . getSum ( ) ;
2018-12-06 17:19:33 +08:00
}
}
2018-12-13 19:17:52 +08:00
for ( NtcEntranceReport e2 : entrance2 ) {
// 实际时间
String time = e2 . getTime ( ) ;
Long t = dateToStamp ( time ) ;
if ( t > = pointTime & & t < pointTime + inter ) {
// 范围之内分到此pointTime组
sum2 = sum2 + e2 . getSum ( ) ;
2018-12-06 17:19:33 +08:00
}
}
2018-12-13 19:17:52 +08:00
// 在结束时间只有当值大于0时才记录数据, 防止折线降为0引起误会
if ( pointTime > = e - inter & & sum1 > 0 ) {
sumList1 . add ( sum1 ) ;
}
if ( pointTime > = e - inter & & sum2 > 0 ) {
sumList2 . add ( sum2 ) ;
}
if ( pointTime > = e - inter & & ( sum1 > 0 | | sum2 > 0 ) ) {
timeList . add ( stampToDate ( pointTime ) ) ;
}
if ( pointTime < e - inter ) {
sumList1 . add ( sum1 ) ;
sumList2 . add ( sum2 ) ;
timeList . add ( stampToDate ( pointTime ) ) ;
}
num = num + 1 ;
pointTime = b + inter * num ;
2018-12-06 17:19:33 +08:00
}
2018-12-13 19:17:52 +08:00
m1 . put ( " count " , sumList1 ) ;
2018-12-10 10:23:48 +06:00
m1 . put ( " statTime " , timeList ) ;
m1 . put ( " entranceId " , 1 ) ;
m2 . put ( " count " , sumList2 ) ; // [{link1:[],time:[],entrance:"1"},]
m2 . put ( " statTime " , timeList ) ;
m2 . put ( " entranceId " , 2 ) ;
2018-12-06 17:19:33 +08:00
listMap . add ( m1 ) ;
listMap . add ( m2 ) ;
return listMap ;
}
2018-12-10 10:23:48 +06:00
2018-12-04 11:59:01 +08:00
/ * *
* 最近活跃端口时间五分钟数据
2018-12-10 10:23:48 +06:00
*
2018-12-04 11:59:01 +08:00
* @return List
* /
2018-12-10 10:23:48 +06:00
public List < Map > getPortActiveList ( ) {
2018-10-23 11:05:35 +08:00
List < Map > list = new ArrayList < Map > ( ) ;
2018-10-26 14:41:27 +08:00
TrafficPortActiveStatistic maxStatTime = trafficPortActiveStatisticDao . getMaxStatTime ( ) ;
2018-12-10 10:23:48 +06:00
if ( maxStatTime ! = null & & maxStatTime . getStatTime ( ) ! = null ) {
2018-10-26 14:41:27 +08:00
Date statTime = maxStatTime . getStatTime ( ) ;
List < TrafficPortActiveStatistic > portActiveList = trafficPortActiveStatisticDao . getPortActiveList ( statTime ) ;
2018-12-10 10:23:48 +06:00
// 上个时间五分钟数据
if ( portActiveList ! = null & & portActiveList . size ( ) > 0 ) {
2018-10-26 14:41:27 +08:00
for ( TrafficPortActiveStatistic port : portActiveList ) {
2018-12-10 10:23:48 +06:00
if ( port . getPort ( ) ! = null ) {
2018-10-26 14:41:27 +08:00
Map map = new HashMap ( ) ;
map . put ( " port " , port . getPort ( ) ) ;
map . put ( " sum " , port . getSum ( ) ) ;
2018-12-10 10:23:48 +06:00
TrafficPortActiveStatistic portActiveOld = trafficPortActiveStatisticDao
. getPortActiveOld ( port . getPort ( ) , statTime ) ;
if ( portActiveOld ! = null & & portActiveOld . getSum ( ) ! = null ) {
map . put ( " preSum " , portActiveOld . getSum ( ) ) ;
} else {
map . put ( " preSum " , 0 ) ;
2018-10-26 14:41:27 +08:00
}
list . add ( map ) ;
2018-10-23 11:05:35 +08:00
}
}
}
}
return list ;
2018-09-21 20:56:01 +08:00
}
2018-12-04 11:59:01 +08:00
2018-07-13 19:39:04 +08:00
/ * *
2018-12-04 11:59:01 +08:00
* 活跃IP最近五分钟数据TOP10
2018-12-10 10:23:48 +06:00
*
2018-07-13 19:39:04 +08:00
* @return
* /
2018-12-10 10:23:48 +06:00
public List < HashMap > ipActiveFiveMinute ( ) {
2018-10-26 14:41:27 +08:00
TrafficIpActiveStatistic maxStatTime = trafficIpActiveStatisticDao . getMaxStatTime ( ) ;
2018-12-10 10:23:48 +06:00
ArrayList < HashMap > listMap = new ArrayList < HashMap > ( ) ;
if ( maxStatTime ! = null & & maxStatTime . getStatTime ( ) ! = null ) {
2018-10-26 14:41:27 +08:00
Date statTime = maxStatTime . getStatTime ( ) ;
2018-12-04 11:59:01 +08:00
// 查询最近五分钟TOP10
2018-10-26 14:41:27 +08:00
ArrayList < LinkedHashMap > list = trafficIpActiveStatisticDao . ipActiveChart ( statTime ) ;
2018-12-10 10:23:48 +06:00
if ( list ! = null & & list . size ( ) > 0 ) {
2018-10-26 14:41:27 +08:00
for ( LinkedHashMap map : list ) {
HashMap m = new HashMap ( ) ;
2018-12-10 10:23:48 +06:00
if ( map . get ( " ipAddr " ) ! = null ) {
2018-10-26 14:41:27 +08:00
String ipAddr = ( String ) map . get ( " ipAddr " ) ;
m . put ( " ipAddr " , ipAddr ) ;
2018-12-04 11:59:01 +08:00
// 根据五分钟TOP10IP, 查询TOP10中每个IP最近一小时的变化
2018-12-10 10:23:48 +06:00
ArrayList < TrafficIpActiveStatistic > ipList = trafficIpActiveStatisticDao
. ipActiveFiveMinute ( ipAddr , statTime ) ;
2018-10-26 14:41:27 +08:00
List linkList = new ArrayList ( ) ;
List timeList = new ArrayList ( ) ;
2018-12-10 10:23:48 +06:00
if ( ipList ! = null & & ipList . size ( ) > 0 ) {
2018-10-26 14:41:27 +08:00
for ( TrafficIpActiveStatistic ip : ipList ) {
2018-12-10 10:23:48 +06:00
if ( ip . getLinkNum ( ) ! = null & & ip . getTime ( ) ! = null ) {
2018-10-26 14:41:27 +08:00
linkList . add ( ip . getLinkNum ( ) ) ;
timeList . add ( ip . getTime ( ) ) ;
}
2018-10-12 17:45:45 +08:00
}
}
2018-12-10 10:23:48 +06:00
m . put ( " linkNum " , linkList ) ;
m . put ( " statTime " , timeList ) ;
2018-10-26 14:41:27 +08:00
listMap . add ( m ) ;
2018-10-12 17:45:45 +08:00
}
}
}
}
2018-12-10 10:23:48 +06:00
2018-10-12 17:45:45 +08:00
return listMap ;
}
2018-12-10 10:23:48 +06:00
2018-12-04 11:59:01 +08:00
/ * *
* 根据活跃IP最近五分钟TOP10 , 查询近1小时最大值
2018-12-10 10:23:48 +06:00
*
2018-12-04 11:59:01 +08:00
* @return
* /
2018-12-10 10:23:48 +06:00
public List < HashMap > ipActiveOneHour ( ) {
2018-10-26 14:41:27 +08:00
TrafficIpActiveStatistic maxStatTime = trafficIpActiveStatisticDao . getMaxStatTime ( ) ;
2018-12-10 10:23:48 +06:00
ArrayList < HashMap > listMap = new ArrayList < HashMap > ( ) ;
if ( maxStatTime ! = null & & maxStatTime . getStatTime ( ) ! = null ) {
2018-10-26 14:41:27 +08:00
Date statTime = maxStatTime . getStatTime ( ) ;
ArrayList < LinkedHashMap > list = trafficIpActiveStatisticDao . ipActiveChart ( statTime ) ;
2018-12-10 10:23:48 +06:00
if ( list ! = null & & list . size ( ) > 0 ) {
2018-10-26 14:41:27 +08:00
for ( LinkedHashMap map : list ) {
2018-12-10 10:23:48 +06:00
if ( map . get ( " ipAddr " ) ! = null ) {
2018-10-26 14:41:27 +08:00
String ipAddr = ( String ) map . get ( " ipAddr " ) ;
2018-12-10 10:23:48 +06:00
ArrayList < HashMap > iplList = trafficIpActiveStatisticDao . ipActiveOneHour ( ipAddr , statTime ) ;
2018-10-26 14:41:27 +08:00
listMap . add ( iplList . get ( 0 ) ) ;
}
2018-10-12 17:45:45 +08:00
}
}
}
2018-12-10 10:23:48 +06:00
2018-10-12 17:45:45 +08:00
return listMap ;
}
2018-12-10 10:23:48 +06:00
2018-10-26 14:41:27 +08:00
@SuppressWarnings ( " rawtypes " )
2018-12-10 10:23:48 +06:00
public List < LinkedHashMap > ipActiveChart ( ) {
2018-10-26 14:41:27 +08:00
TrafficIpActiveStatistic maxStatTime = trafficIpActiveStatisticDao . getMaxStatTime ( ) ;
ArrayList < LinkedHashMap > list = new ArrayList < > ( ) ;
2018-12-10 10:23:48 +06:00
if ( maxStatTime ! = null & & maxStatTime . getStatTime ( ) ! = null ) {
2018-10-26 14:41:27 +08:00
Date statTime = maxStatTime . getStatTime ( ) ;
list = trafficIpActiveStatisticDao . ipActiveChart ( statTime ) ;
2018-12-10 10:23:48 +06:00
if ( list ! = null & & list . size ( ) > 0 ) {
2018-10-26 14:41:27 +08:00
for ( LinkedHashMap map : list ) {
2018-12-10 10:23:48 +06:00
if ( map . get ( " ipAddr " ) ! = null ) {
2018-10-26 14:41:27 +08:00
Map m = new LinkedHashMap ( ) ;
2018-12-10 10:23:48 +06:00
map . put ( " pktNum " , 0 ) ;
map . put ( " byteLen " , 0 ) ;
2018-10-26 14:41:27 +08:00
}
}
}
}
2018-07-13 19:39:04 +08:00
return list ;
}
2018-12-05 16:44:52 +08:00
/ * *
* 协议统计
2018-12-10 10:23:48 +06:00
*
2018-12-05 16:44:52 +08:00
* @return
* /
2018-07-13 19:39:04 +08:00
public List < Map > protocolChart ( ) {
2018-10-26 14:41:27 +08:00
TrafficProtocolStatistic maxStatTime = trafficProtocolStatisticDao . getMaxStatTime ( ) ;
2018-12-10 10:23:48 +06:00
List < Map > list = new ArrayList < Map > ( ) ;
if ( maxStatTime ! = null & & maxStatTime . getStatTime ( ) ! = null ) {
2018-10-26 14:41:27 +08:00
Date statTime = maxStatTime . getStatTime ( ) ;
list = trafficProtocolStatisticDao . protocolChart ( statTime ) ;
2018-12-10 10:23:48 +06:00
// 当不查询包,字节时 设为0
if ( list ! = null & & list . size ( ) > 0 ) {
2018-10-26 14:41:27 +08:00
Map map = new HashMap ( ) ;
2018-12-10 10:23:48 +06:00
map . put ( " pktNum " , 0 ) ;
map . put ( " byteLen " , 0 ) ;
2018-10-26 14:41:27 +08:00
}
}
2018-07-13 19:39:04 +08:00
return list ;
}
2018-12-05 16:44:52 +08:00
/ * *
* 协议统计报表
2018-12-10 10:23:48 +06:00
*
2018-12-05 16:44:52 +08:00
* @return
* /
2018-12-10 10:23:48 +06:00
public List < Map > getProtocolList ( String startTime , String endTime ) {
2018-12-05 16:44:52 +08:00
TrafficProtocolStatistic maxStatTime = trafficProtocolStatisticDao . getMaxStatTime ( ) ;
2018-12-10 10:23:48 +06:00
List < Map > list = new ArrayList < Map > ( ) ;
if ( maxStatTime ! = null & & maxStatTime . getStatTime ( ) ! = null ) {
2018-12-05 16:44:52 +08:00
Date statTime = maxStatTime . getStatTime ( ) ;
2018-12-10 10:23:48 +06:00
list = trafficProtocolStatisticDao . getProtocolList ( statTime , startTime , endTime ) ;
}
2018-12-05 16:44:52 +08:00
return list ;
}
2018-12-10 10:23:48 +06:00
2018-12-06 17:19:33 +08:00
/ * *
* app应用top10 图
2018-12-10 10:23:48 +06:00
*
2018-12-06 17:19:33 +08:00
* @return
* /
2018-07-13 19:39:04 +08:00
public List < Map > appChart ( ) {
2018-12-10 10:23:48 +06:00
List < Map > list = new ArrayList < Map > ( ) ;
2018-10-26 14:41:27 +08:00
TrafficAppStatistic maxStatTime = trafficAppStatisticDao . getMaxStatTime ( ) ;
2018-12-10 10:23:48 +06:00
if ( maxStatTime ! = null & & maxStatTime . getStatTime ( ) ! = null ) {
2018-10-26 14:41:27 +08:00
Date statTime = maxStatTime . getStatTime ( ) ;
list = trafficAppStatisticDao . appChart ( statTime ) ;
2018-12-10 10:23:48 +06:00
// 当不查询包,字节时 设为0
if ( list ! = null & & list . size ( ) > 0 ) {
2018-10-26 14:41:27 +08:00
Map map = new HashMap ( ) ;
2018-12-10 10:23:48 +06:00
map . put ( " pktNum " , 0 ) ;
map . put ( " byteLen " , 0 ) ;
2018-10-26 14:41:27 +08:00
}
}
2018-07-13 19:39:04 +08:00
return list ;
}
2018-12-10 10:23:48 +06:00
2018-12-06 17:19:33 +08:00
/ * *
* App统计报表
2018-12-10 10:23:48 +06:00
*
2018-12-06 17:19:33 +08:00
* @return
* /
2018-12-10 10:23:48 +06:00
public List < Map > getAppList ( String startTime , String endTime ) {
2018-12-06 17:19:33 +08:00
TrafficAppStatistic maxStatTime = trafficAppStatisticDao . getMaxStatTime ( ) ;
2018-12-10 10:23:48 +06:00
List < Map > list = new ArrayList < Map > ( ) ;
if ( maxStatTime ! = null & & maxStatTime . getStatTime ( ) ! = null ) {
2018-12-06 17:19:33 +08:00
Date statTime = maxStatTime . getStatTime ( ) ;
2018-12-10 10:23:48 +06:00
list = trafficAppStatisticDao . getAppList ( statTime , startTime , endTime ) ;
}
2018-12-06 17:19:33 +08:00
return list ;
}
2018-12-10 10:23:48 +06:00
2018-07-23 17:44:18 +08:00
// 操作系统列表 排名TOP10
2018-07-13 19:39:04 +08:00
@SuppressWarnings ( { " unchecked " , " rawtypes " } )
2018-12-10 10:23:48 +06:00
public List < Map > systemList ( ) {
2018-07-13 19:39:04 +08:00
List < Map > result = new ArrayList < Map > ( ) ;
2018-10-26 14:41:27 +08:00
TrafficUaStatistic maxStatTime = trafficUaStatisticDao . getMaxStatTime ( ) ;
2018-12-10 10:23:48 +06:00
if ( maxStatTime ! = null ) {
Date statTime = maxStatTime . getStatTime ( ) ;
List < TrafficUaStatistic > list = trafficUaStatisticDao . systemList ( statTime ) ;
Long preCount = 0l ;
for ( TrafficUaStatistic ua : list ) {
Map map = new HashMap ( ) ;
map . put ( " osType " , ua . getOsType ( ) ) ;
map . put ( " count " , ua . getCount ( ) ) ;
map . put ( " pktNum " , 0 ) ;
map . put ( " byteLen " , 0 ) ;
preCount = trafficUaStatisticDao . preSystemListCount ( ua . getOsType ( ) , statTime ) ; // 上个时段的量 用于与现在对比
if ( preCount ! = null ) {
map . put ( " preCount " , preCount ) ;
} else {
map . put ( " preCount " , 0 ) ;
2018-10-26 14:41:27 +08:00
}
2018-12-10 10:23:48 +06:00
result . add ( map ) ;
}
2018-07-13 19:39:04 +08:00
}
return result ;
}
2018-12-10 10:23:48 +06:00
public List < Map > getBrowserBySystem ( Integer osType ) {
2018-10-26 14:41:27 +08:00
List < Map > list = new ArrayList < Map > ( ) ;
TrafficUaStatistic maxStatTime = trafficUaStatisticDao . getMaxStatTime ( ) ;
2018-12-10 10:23:48 +06:00
if ( maxStatTime ! = null ) {
Date statTime = maxStatTime . getStatTime ( ) ;
list = trafficUaStatisticDao . getBrowserBySystem ( osType , statTime ) ;
List bsType = new ArrayList ( ) ;
// 查新固定操系统下的除了TOP10以外的others
if ( list ! = null & & list . size ( ) > 0 ) {
for ( Map map : list ) {
bsType . add ( map . get ( " bsType " ) ) ;
}
if ( list . size ( ) > 10 ) {
Map others = new HashMap ( ) ;
others = trafficUaStatisticDao . systemOthers ( bsType , osType , statTime ) ;
if ( others ! = null & & others . size ( ) > 0 ) {
others . put ( " bsType " , " -1 " ) ;
list . add ( others ) ;
2018-10-26 14:41:27 +08:00
}
}
2018-12-10 10:23:48 +06:00
}
2018-07-23 17:44:18 +08:00
}
2018-07-13 19:39:04 +08:00
return list ;
}
public List < Map > browserList ( ) {
List < Map > result = new ArrayList < Map > ( ) ;
2018-10-26 14:41:27 +08:00
TrafficUaStatistic maxStatTime = trafficUaStatisticDao . getMaxStatTime ( ) ;
2018-12-10 10:23:48 +06:00
if ( maxStatTime ! = null ) {
2018-10-26 14:41:27 +08:00
Date statTime = maxStatTime . getStatTime ( ) ;
List < TrafficUaStatistic > list = trafficUaStatisticDao . browserList ( statTime ) ;
2018-12-10 10:23:48 +06:00
Long preCount = 0l ;
if ( list ! = null & & list . size ( ) > 0 ) {
for ( TrafficUaStatistic ua : list ) {
Map map = new HashMap ( ) ;
map . put ( " bsType " , ua . getBsType ( ) ) ;
map . put ( " count " , ua . getCount ( ) ) ;
map . put ( " pktNum " , 0 ) ;
map . put ( " byteLen " , 0 ) ;
preCount = trafficUaStatisticDao . preBrowserListCount ( ua . getBsType ( ) , statTime ) ; // 上个时段的量 用于与现在对比
if ( preCount ! = null ) {
map . put ( " preCount " , preCount ) ;
} else {
map . put ( " preCount " , 0 ) ;
2018-10-26 14:41:27 +08:00
}
2018-12-10 10:23:48 +06:00
result . add ( map ) ;
2018-09-21 20:56:01 +08:00
}
2018-07-23 17:44:18 +08:00
}
2018-12-10 10:23:48 +06:00
}
2018-07-13 19:39:04 +08:00
return result ;
}
2018-12-10 10:23:48 +06:00
public List < Map > getSystemBybrowser ( Integer bsType ) {
2018-10-26 14:41:27 +08:00
List < Map > list = new ArrayList < Map > ( ) ;
TrafficUaStatistic maxStatTime = trafficUaStatisticDao . getMaxStatTime ( ) ;
2018-12-10 10:23:48 +06:00
if ( maxStatTime ! = null ) {
2018-10-26 14:41:27 +08:00
Date statTime = maxStatTime . getStatTime ( ) ;
2018-12-10 10:23:48 +06:00
list = trafficUaStatisticDao . getSystemBybrowser ( bsType , statTime ) ;
2018-10-26 14:41:27 +08:00
List osType = new ArrayList ( ) ;
2018-12-10 10:23:48 +06:00
// 查询固定操系统下的除了TOP10以外的others
if ( list ! = null & & list . size ( ) > 0 ) {
2018-10-26 14:41:27 +08:00
for ( Map map : list ) {
osType . add ( map . get ( " osType " ) ) ;
}
2018-12-10 10:23:48 +06:00
if ( list . size ( ) > 10 ) {
2018-11-16 16:28:14 +08:00
Map others = new HashMap ( ) ;
2018-12-10 10:23:48 +06:00
others = trafficUaStatisticDao . browserOthers ( osType , bsType , statTime ) ;
if ( others ! = null & & others . size ( ) > 0 ) {
2018-11-16 16:28:14 +08:00
others . put ( " osType " , " -1 " ) ;
list . add ( others ) ;
}
2018-10-26 14:41:27 +08:00
}
2018-12-10 10:23:48 +06:00
}
2018-07-23 17:44:18 +08:00
}
2018-07-13 19:39:04 +08:00
return list ;
}
2018-12-10 10:23:48 +06:00
2018-12-10 18:55:14 +06:00
// public List<Map> websiteList() {
// List<Map> result = new ArrayList<Map>();
// TrafficHttpStatistic maxStatTime = trafficHttpStatisticDao.getMaxStatTime();
// if (maxStatTime != null) {
// List<TrafficHttpStatistic> list = trafficHttpStatisticDao.websiteList(maxStatTime.getStatTime());
// Long preCount = 0l;
// if (list != null && list.size() > 0) {
// for (TrafficHttpStatistic website : list) {
// Map map = new HashMap();
// map.put("webId", website.getWebId());
// map.put("count", website.getCount());
// map.put("pktNum", 0);
// map.put("byteLen", 0);
// preCount = trafficHttpStatisticDao.preWebsiteListCount(website.getWebId(),
// maxStatTime.getStatTime());// 上个时段的量 用于与现在对比
// if (preCount != null) {
// map.put("preCount", preCount);
// } else {
// map.put("preCount", 0);
// }
// result.add(map);
// }
// }
// }
// return result;
// }
2018-12-10 10:23:48 +06:00
2018-09-21 20:56:01 +08:00
/ * *
* 根据网站服务查询子域名
2018-12-10 10:23:48 +06:00
*
2018-09-21 20:56:01 +08:00
* @param websiteServiceId
* @return list
* /
2018-12-10 10:23:48 +06:00
public List < Map > getDomainByWebsiteServiceId ( Integer websiteServiceId ) {
2018-12-10 18:55:14 +06:00
Date statTime = getBeforeByHourTime ( 1 ) ; // 获取上一个小时
List idList = trafficHttpStatisticDao . getIdByWebSiteId ( websiteServiceId ) ;
List < Map > matchList = trafficHttpStatisticDao . getDomainByWebsiteServiceId ( idList , statTime , new Date ( ) ) ; // 获取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
for ( Map map : matchList ) {
String countStr = String . valueOf ( map . get ( " count " ) ) ;
long count = Long . parseLong ( countStr ) ;
set . add ( count ) ;
if ( countMap . containsKey ( count ) ) { // 将每个count和对应的viewmap放到map中,count可能相同所以value是list
countMap . get ( count ) . add ( map ) ;
} else {
List < Map > listMap = new ArrayList < > ( ) ;
listMap . add ( map ) ;
countMap . put ( count , listMap ) ;
}
}
List < Map > top10Data = getTop10Data ( set , countMap ) ;
List < String > notTop10List = new ArrayList < > ( ) ; // 获取不在top10中的webid,用来查询标记为orther
for ( Map map : matchList ) {
String webIdStr = String . valueOf ( map . get ( " webId " ) ) ;
boolean exist = false ;
for ( Map map1 : top10Data ) {
String webIdStr1 = String . valueOf ( map1 . get ( " webId " ) ) ;
if ( webIdStr1 ! = null & & webIdStr ! = null & & webIdStr1 . equals ( webIdStr ) ) {
exist = true ;
2018-10-26 14:41:27 +08:00
}
2018-12-10 18:55:14 +06:00
if ( ! exist ) {
notTop10List . add ( webIdStr ) ;
2018-10-26 14:41:27 +08:00
}
2018-12-10 10:23:48 +06:00
}
2018-07-23 17:44:18 +08:00
}
2018-12-10 18:55:14 +06:00
// 查询固定网站下的域名除了TOP10以外的others域名
if ( matchList ! = null & & matchList . size ( ) > 10 ) {
Map others = trafficHttpStatisticDao . websiteDomainOthers ( notTop10List , statTime , new Date ( ) ) ;
if ( others ! = null & & others . size ( ) > 0 ) {
others . put ( " webId " , " -1 " ) ;
top10Data . add ( others ) ;
}
}
return top10Data ;
2018-07-13 19:39:04 +08:00
}
2018-12-10 10:23:48 +06:00
2018-09-21 20:56:01 +08:00
/ * *
2018-12-10 10:23:48 +06:00
* 获取网站列表
*
2018-09-21 20:56:01 +08:00
* @return
* /
@SuppressWarnings ( " unchecked " )
2018-12-10 10:23:48 +06:00
public List < Map > getDomainByWebsiteList ( ) {
2018-12-10 18:55:14 +06:00
Date statTime = getBeforeByHourTime ( 1 ) ; // 获取上一个小时
Map < String , List < String > > websiteIdAndIdMap = new HashMap < > ( ) ; // 存储websiteServiceId和id的对应关系,一个websiteServiceId有多个id
List < Map > websiteIdAndidList = trafficHttpStatisticDao . getDomainByWebsiteList ( statTime , new Date ( ) ) ; // 获取website_service_id和id的对应关系,group
// by
// website_service_id,id
for ( Map map : websiteIdAndidList ) {
Object websiteServiceIdObj = map . get ( " websiteServiceId " ) ;
Object idObj = map . get ( " id " ) ;
if ( websiteServiceIdObj ! = null & & idObj ! = null ) {
if ( websiteIdAndIdMap . containsKey ( String . valueOf ( websiteServiceIdObj ) ) ) {
websiteIdAndIdMap . get ( String . valueOf ( websiteServiceIdObj ) ) . add ( String . valueOf ( idObj ) ) ;
} else {
List < String > list = new ArrayList < > ( ) ;
list . add ( String . valueOf ( idObj ) ) ;
websiteIdAndIdMap . put ( String . valueOf ( websiteServiceIdObj ) , list ) ;
}
}
}
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的关系
for ( String websiteServiceId : websiteIdAndIdMap . keySet ( ) ) { // 遍历上面获取的websiteServiceId和id的对应关系,拼接json
Map viewMap = new HashMap < > ( ) ;
long count = 0l ; // 记录当前websiteServiceId所有的count
long prevCount = 0l ; // 记录当前websiteServiceId所有的count
List < String > idList = websiteIdAndIdMap . get ( websiteServiceId ) ; // 根据websiteServiceId获取对应的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累加
}
}
}
for ( Map webIdAndCountMap : prevWebIdAndCountList ) { // 遍历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 ) {
prevCount + = Long . parseLong ( countStr ) ; // 将count累加
}
2018-10-26 14:41:27 +08:00
}
2018-09-21 20:56:01 +08:00
}
2018-12-10 18:55:14 +06:00
2018-09-21 20:56:01 +08:00
}
2018-12-10 18:55:14 +06:00
viewMap . put ( " websiteServiceId " , websiteServiceId ) ;
viewMap . put ( " count " , count ) ;
viewMap . put ( " pktNum " , 0 ) ;
viewMap . put ( " byteLen " , 0 ) ;
viewMap . put ( " preCount " , prevCount ) ;
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 ) ;
2018-09-21 20:56:01 +08:00
}
2018-12-10 18:55:14 +06:00
return getTop10Data ( set , countAndViewMap ) ;
2018-09-21 20:56:01 +08:00
}
2018-12-10 10:23:48 +06:00
2018-09-21 20:56:01 +08:00
/ * *
2018-12-10 10:23:48 +06:00
* 主题网站分类 , 域名
2018-09-21 20:56:01 +08:00
*
2018-12-10 10:23:48 +06:00
* * /
public List < Map > getTopicAndDomainList ( ) {
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
for ( Map map : topicIdAndIdList ) {
Object topicIdObj = map . get ( " topicId " ) ;
Object idObj = map . get ( " id " ) ;
if ( topicIdObj ! = null & & idObj ! = null ) {
if ( topicIdAndIdMap . containsKey ( String . valueOf ( topicIdObj ) ) ) {
topicIdAndIdMap . get ( String . valueOf ( topicIdObj ) ) . add ( String . valueOf ( idObj ) ) ;
} else {
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 ) ;
}
2018-10-26 14:41:27 +08:00
}
2018-09-21 20:56:01 +08:00
}
2018-12-10 10:23:48 +06:00
}
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 ) ;
2018-09-21 20:56:01 +08:00
}
2018-12-10 10:23:48 +06:00
return getTop10Data ( set , countAndViewMap ) ;
2018-09-21 20:56:01 +08:00
}
2018-12-10 10:23:48 +06:00
2018-07-13 19:39:04 +08:00
}