2018-07-13 19:39:04 +08:00
package com.nis.web.service.restful ;
2018-12-25 16:49:09 +08:00
import java.text.ParseException ;
import java.text.SimpleDateFormat ;
import java.util.ArrayList ;
import java.util.Calendar ;
import java.util.Collections ;
import java.util.Comparator ;
import java.util.Date ;
import java.util.HashMap ;
import java.util.HashSet ;
import java.util.Iterator ;
import java.util.LinkedHashMap ;
import java.util.List ;
import java.util.Map ;
import java.util.Map.Entry ;
import java.util.Set ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
2018-12-01 13:19:30 +06:00
import com.beust.jcommander.internal.Maps ;
2018-12-25 16:49:09 +08:00
import com.nis.domain.restful.NtcConnNumReport ;
2018-12-06 17:19:33 +08:00
import com.nis.domain.restful.NtcEntranceReport ;
2019-01-05 17:21:07 +08:00
import com.nis.domain.restful.dashboard.AppConnRecordStatistic ;
2018-12-25 16:49:09 +08:00
import com.nis.domain.restful.dashboard.NtcTotalReport ;
2019-01-05 17:21:07 +08:00
import com.nis.domain.restful.dashboard.TrafficAppFocusStatistic ;
2018-12-25 16:49:09 +08:00
import com.nis.domain.restful.dashboard.TrafficAppStatistic ;
import com.nis.domain.restful.dashboard.TrafficHttpFocusStatistic ;
import com.nis.domain.restful.dashboard.TrafficIpActiveStatistic ;
import com.nis.domain.restful.dashboard.TrafficPortActiveStatistic ;
import com.nis.domain.restful.dashboard.TrafficProtocolStatistic ;
import com.nis.domain.restful.dashboard.TrafficTransStatistic ;
import com.nis.domain.restful.dashboard.TrafficUaStatistic ;
import com.nis.restful.RestBusinessCode ;
import com.nis.restful.RestServiceException ;
2019-01-03 15:38:57 +08:00
import com.nis.util.Constants ;
2018-12-17 10:12:20 +08:00
import com.nis.util.DateUtils ;
2018-12-06 17:19:33 +08:00
import com.nis.util.StringUtils ;
2018-12-25 16:49:09 +08:00
import com.nis.web.dao.dashboard.NtcTotalReportDao ;
import com.nis.web.dao.dashboard.TrafficAppStatisticDao ;
import com.nis.web.dao.dashboard.TrafficHttpStatisticDao ;
import com.nis.web.dao.dashboard.TrafficIpActiveStatisticDao ;
import com.nis.web.dao.dashboard.TrafficPortActiveStatisticDao ;
import com.nis.web.dao.dashboard.TrafficProtocolStatisticDao ;
import com.nis.web.dao.dashboard.TrafficUaStatisticDao ;
2018-12-01 13:19:30 +06:00
import com.nis.web.service.BaseService ;
import com.zdjizhi.utils.StringUtil ;
2018-12-18 06:05:16 +06:00
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-17 14:08:03 +06:00
/ *
* public List < HashMap > getBandwidthTrans ( String addrType , Integer
* transType , String beginDate , String endDate ) { ArrayList < HashMap > listMap = new
* ArrayList < HashMap > ( ) ; List < TrafficTransStatistic > bandwidthList = new
* ArrayList < TrafficTransStatistic > ( ) ; Map maxStatTime =
* ntcTotalReportDao . getMaxStatTime ( ) ; if ( maxStatTime ! = null & &
* maxStatTime . get ( " statTime " ) ! = null ) { Date stat = ( Date )
* maxStatTime . get ( " statTime " ) ; HashMap m = new HashMap ( ) ; bandwidthList =
* ntcTotalReportDao . getBandwidthTrans ( stat , addrType , transType ) ; List timeList
* = new ArrayList ( ) ; List linkList = new ArrayList ( ) ; List gbpsList = new
* ArrayList ( ) ; List ppsList = new ArrayList ( ) ; if ( bandwidthList ! = null & &
* bandwidthList . size ( ) > 0 ) { for ( TrafficTransStatistic tt : bandwidthList ) {
* if ( tt . getTime ( ) ! = null ) { timeList . add ( tt . getTime ( ) ) ; if ( tt . getLinkNum ( )
* ! = null ) { linkList . add ( tt . getLinkNum ( ) ) ; } if ( tt . getPps ( ) ! = null ) {
* ppsList . add ( tt . getPps ( ) ) ; } if ( tt . getGbps ( ) ! = null ) {
* gbpsList . add ( tt . getGbps ( ) ) ; } } } } m . put ( " linkNum " , linkList ) ; m . put ( " gbps " ,
* gbpsList ) ; m . put ( " pps " , ppsList ) ; m . put ( " statTime " , timeList ) ;
* listMap . add ( m ) ; } return listMap ; }
* /
2018-12-12 10:43:47 +08:00
/ * *
* 根据ip46 , 协议tcp , udp查询带宽
*
* @param addrType
* @param transType
* @return
* /
2018-12-24 22:18:12 +06:00
@Deprecated
2018-12-17 14:08:03 +06:00
public List < HashMap > getBandwidthTrans ( String addrType , Integer transType , String beginDate , String endDate ) {
2018-12-12 10:43:47 +08:00
ArrayList < HashMap > listMap = new ArrayList < HashMap > ( ) ;
2018-12-17 14:08:03 +06:00
2018-12-12 10:43:47 +08:00
HashMap m1 = getBandwidthTransEntrance ( addrType , transType , beginDate , endDate , 1 ) ;
2018-12-17 14:08:03 +06:00
if ( m1 ! = null & & m1 . size ( ) > 0 ) {
2018-12-12 10:43:47 +08:00
m1 . put ( " entranceId " , 1 ) ; // 局点1.2 不同来源
listMap . add ( m1 ) ;
}
return listMap ;
2018-12-17 14:08:03 +06:00
2018-12-12 10:43:47 +08:00
}
2018-12-17 14:08:03 +06:00
2018-12-12 10:43:47 +08:00
/ * *
* 根据ip46 , 协议tcp , udp查询带宽
*
* @param addrType
* @param transType
* @return
* /
2018-12-24 22:18:12 +06:00
@Deprecated
2018-12-17 14:08:03 +06:00
public List < HashMap > getBandwidthTrans2 ( String addrType , Integer transType , String beginDate , String endDate ) {
2018-12-12 10:43:47 +08:00
ArrayList < HashMap > listMap = new ArrayList < HashMap > ( ) ;
2018-12-17 14:08:03 +06:00
2018-12-12 10:43:47 +08:00
HashMap m2 = getBandwidthTransEntrance ( addrType , transType , beginDate , endDate , 2 ) ;
2018-12-17 14:08:03 +06:00
if ( m2 ! = null & & m2 . size ( ) > 0 ) {
2018-12-12 10:43:47 +08:00
m2 . put ( " entranceId " , 2 ) ;
listMap . add ( m2 ) ;
}
return listMap ;
2018-12-17 14:08:03 +06:00
2018-12-12 10:43:47 +08:00
}
2018-12-17 14:08:03 +06:00
2018-12-12 10:43:47 +08:00
/ * *
2018-12-17 14:08:03 +06:00
* 查询单个局点流量的数据信息
*
2018-12-12 10:43:47 +08:00
* @param addrType
* @param transType
* @param beginDate
* @param endDate
* @param entranceId
* @return
* /
2018-12-24 22:18:12 +06:00
@Deprecated
2018-12-17 14:08:03 +06:00
public HashMap getBandwidthTransEntrance ( String addrType , Integer transType , String beginDate , String endDate ,
Integer entranceId ) {
2018-12-12 10:43:47 +08:00
long start = System . currentTimeMillis ( ) ;
ArrayList < HashMap > listMap = new ArrayList < HashMap > ( ) ;
List < TrafficTransStatistic > bandwidthList = new ArrayList < TrafficTransStatistic > ( ) ;
2018-12-17 14:08:03 +06:00
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 ; // 间隔时间为五分钟
// 开始时间,结束时间 时间戳
Long b = dateToStamp ( beginDate ) ;
Long e = dateToStamp ( endDate ) ;
int num = 0 ;
Long pointTime = b ;
while ( pointTime < e ) {
Map rm = new HashMap ( ) ;
Long sumL = 0l ;
Long sumP = 0l ;
Long sumG = 0l ;
if ( pointTime > = e ) {
break ; // 停止
}
for ( TrafficTransStatistic tt : bandwidthList ) {
// 实际时间
String time = tt . getTime ( ) ;
Long t = dateToStamp ( time ) ;
if ( t > = pointTime & & t < pointTime + inter ) {
// 范围之内分到此pointTime组
sumL = sumL + tt . getLinkNum ( ) ;
2018-12-24 22:18:12 +06:00
sumP = sumP + Long . parseLong ( tt . getPps ( ) . substring ( 0 , tt . getPps ( ) . lastIndexOf ( " . " ) ) ) ;
sumG = sumG + Long . parseLong ( tt . getGbps ( ) . substring ( 0 , tt . getGbps ( ) . lastIndexOf ( " . " ) ) ) ;
2018-12-13 19:17:52 +08:00
}
2018-12-12 10:43:47 +08:00
}
2018-12-17 14:08:03 +06: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 ) ;
}
num = num + 1 ;
pointTime = b + inter * num ;
}
resulMap . put ( " linkNum " , linkList ) ;
resulMap . put ( " gbps " , gbpsList ) ;
resulMap . put ( " pps " , ppsList ) ;
resulMap . put ( " statTime " , timeList ) ;
2018-12-12 10:43:47 +08:00
}
2018-12-17 14:08:03 +06:00
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数据
2018-12-17 14:08:03 +06:00
*
2018-12-12 10:43:47 +08:00
* @param begin
* @param end
* @param li
* @return
* /
2018-12-24 22:18:12 +06:00
@Deprecated
2018-12-17 14:08:03 +06:00
public static List < Map > formatDateData ( String begin , String end , List < Map > li ) {
2018-12-12 10:43:47 +08:00
List < Map > resList = new ArrayList < Map > ( ) ;
2018-12-17 14:08:03 +06:00
Map < String , Comparable > m = new HashMap < String , Comparable > ( ) ;
int inter = 1000 * 60 * 60 ; // 间隔时间为一小时
2018-12-12 10:43:47 +08:00
// 开始时间,结束时间 时间戳
Long b = dateToStamp ( begin ) ;
Long e = dateToStamp ( end ) ;
2018-12-17 14:08:03 +06:00
int num = 0 ;
Long pointTime = b ;
while ( pointTime < e ) {
Map rm = new HashMap ( ) ;
Long sum = 0l ;
if ( pointTime > = e ) {
break ; // 停止
2018-12-12 10:43:47 +08:00
}
for ( Map < ? , ? > map : li ) {
2018-12-17 14:08:03 +06:00
// 实际时间
String time = ( String ) map . get ( " time " ) ;
2018-12-12 10:43:47 +08:00
Long t = dateToStamp ( time ) ;
2018-12-17 14:08:03 +06:00
if ( t > = pointTime & & t < pointTime + inter ) {
2018-12-12 10:43:47 +08:00
// 范围之内分到此pointTime组
2018-12-17 14:08:03 +06:00
sum = sum + ( Long ) map . get ( " count " ) ;
2018-12-12 10:43:47 +08:00
}
}
rm . put ( " time " , stampToDate ( pointTime ) ) ;
rm . put ( " sum " , sum ) ;
2018-12-17 14:08:03 +06:00
num = num + 1 ;
pointTime = b + inter * num ;
2018-12-12 10:43:47 +08:00
resList . add ( rm ) ;
}
return resList ;
}
2018-12-17 14:08:03 +06:00
/ * *
* 日期格式字符串转换成时间戳
*
* @param date 字符串日期
* @param format 如 : yyyy - MM - dd HH : mm : ss
* @return
* /
2018-12-24 22:18:12 +06:00
@Deprecated
2018-12-17 14:08:03 +06:00
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
* /
2018-12-24 22:18:12 +06:00
@Deprecated
2018-12-17 14:08:03 +06:00
public static String stampToDate ( long timeStamp ) {
SimpleDateFormat sdf = new SimpleDateFormat ( " MM-dd HH:mm " ) ; // 这个是你要转成后的时间的格式
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-24 22:18:12 +06:00
/ *
* public List < HashMap > getActionTrans ( String begin , String end , String
* serviceType ) { 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)) "
* ; // 监测 String sqlDrop =
* " ((service>=1040 and service<=1042) or (service=3) or (service=5) or (service=25) or (service=28) or (service=274)) "
* ; // 丢弃 String sqlLoop = "((service=4) or (service>=832 and service<=834))";
* // 回流 // 区分动作 if (StringUtils.isNotBlank(serviceType)) { if
* ( serviceType . equalsIgnoreCase ( " block " ) ) { sql = sqlBlock ; } if
* ( serviceType . equalsIgnoreCase ( " monitor " ) ) { sql = sqlMonitor ; } if
* ( serviceType . equalsIgnoreCase ( " drop " ) ) { sql = sqlDrop ; } if
* ( serviceType . equalsIgnoreCase ( " loop " ) ) { sql = sqlLoop ; } }
* ArrayList < HashMap > listMap = new ArrayList < HashMap > ( ) ;
* List < NtcEntranceReport > entrance1 = new ArrayList < NtcEntranceReport > ( ) ;
* List < NtcEntranceReport > entrance2 = new ArrayList < NtcEntranceReport > ( ) ;
* HashMap m1 = new HashMap ( ) ; HashMap m2 = new HashMap ( ) ; entrance1 =
* ntcTotalReportDao . getActionTrans ( begin , end , 1 , sql ) ; entrance2 =
* ntcTotalReportDao . getActionTrans ( begin , end , 2 , sql ) ; List timeList = new
* ArrayList ( ) ; List sumList1 = new ArrayList ( ) ; List sumList2 = new
* ArrayList ( ) ;
*
* 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(); } } for
* ( NtcEntranceReport e2 : entrance2 ) { // 实际时间 String time = e2.getTime(); Long
* t = dateToStamp ( time ) ; if ( t > = pointTime & & t < pointTime + inter ) { //
* 范围之内分到此pointTime组 sum2 = sum2 + e2 . getSum ( ) ; } } //
* 在结束时间只有当值大于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 ; } m1 . put ( " count " , sumList1 ) ;
* m1 . put ( " statTime " , timeList ) ; m1 . put ( " entranceId " , 1 ) ; m2 . put ( " count " ,
* sumList2 ) ; // m2.put("statTime", timeList); m2.put("entranceId", 2);
* listMap . add ( m1 ) ; listMap . add ( m2 ) ; return listMap ; }
* /
2018-12-23 18:09:29 +08:00
/ * *
* 根据service 动作查询近五分钟变化趋势 entrance 默认为1 , 2
* /
public List < HashMap > getActionTrans2 ( String begin , String end , String serviceType ) {
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-23 20:04:19 +08:00
String sqlDrop = " ((service>=1040 and service<=1042) or (service=3) or (service=5) or (service=25) or (service=28) or (service=274)) " ; // 丢弃
2018-12-23 18:09:29 +08:00
String sqlLoop = " ((service=4) or (service>=832 and service<=834)) " ; // 回流
// 区分动作
if ( StringUtils . isNotBlank ( serviceType ) ) {
2018-12-23 20:04:19 +08:00
if ( serviceType . equalsIgnoreCase ( " action_reject " ) ) {
2018-12-23 18:09:29 +08:00
sql = sqlBlock ;
}
2018-12-23 20:04:19 +08:00
if ( serviceType . equalsIgnoreCase ( " action_monit " ) ) {
2018-12-23 18:09:29 +08:00
sql = sqlMonitor ;
}
2018-12-23 20:04:19 +08:00
if ( serviceType . equalsIgnoreCase ( " action_drop " ) ) {
2018-12-23 18:09:29 +08:00
sql = sqlDrop ;
}
2018-12-23 20:04:19 +08:00
if ( serviceType . equalsIgnoreCase ( " action_loop " ) ) {
2018-12-23 18:09:29 +08:00
sql = sqlLoop ;
}
}
ArrayList < HashMap > listMap = new ArrayList < HashMap > ( ) ;
List < NtcEntranceReport > entrance1 = new ArrayList < NtcEntranceReport > ( ) ;
List < NtcEntranceReport > entrance2 = new ArrayList < NtcEntranceReport > ( ) ;
HashMap m1 = new HashMap ( ) ;
HashMap m2 = new HashMap ( ) ;
entrance1 = ntcTotalReportDao . getActionTrans ( begin , end , 1 , sql ) ;
entrance2 = ntcTotalReportDao . getActionTrans ( begin , end , 2 , sql ) ;
2018-12-24 22:18:12 +06:00
2018-12-27 17:18:47 +08:00
if ( ! StringUtil . isEmpty ( entrance1 ) | | ! StringUtil . isEmpty ( entrance2 ) ) {
Map < String , Comparable > m = new HashMap < String , Comparable > ( ) ;
Date beginDate = DateUtils . parseDate ( begin ) ;
Date endDate = DateUtils . parseDate ( end ) ;
List < Date > dateRangeList = new ArrayList < Date > ( ) ;
Calendar calendar = Calendar . getInstance ( ) ;
calendar . setTime ( beginDate ) ;
2018-12-29 18:57:21 +08:00
SimpleDateFormat sdf = new SimpleDateFormat ( " yyyy-MM-dd HH:mm:ss " ) ;
2018-12-29 19:41:24 +08:00
while ( calendar . getTime ( ) . compareTo ( endDate ) < 0 ) {
2018-12-27 17:18:47 +08:00
dateRangeList . add ( calendar . getTime ( ) ) ;
2019-01-03 15:38:57 +08:00
calendar . add ( Calendar . MINUTE , Constants . TREND_TIME_INTERVAL ) ;
2018-12-27 17:18:47 +08:00
}
// 存放每个时间点的总数
Map < String , List < Long > > ipCountListMap = new HashMap < String , List < Long > > ( ) ;
2018-12-28 17:09:59 +08:00
int index1 = 0 ;
int index2 = 0 ;
2018-12-27 17:18:47 +08:00
List sumList1 = new ArrayList ( ) ;
List sumList2 = new ArrayList ( ) ;
2019-01-03 15:38:57 +08:00
Long sumEnt1 = 0L ;
Long sumEnt2 = 0L ;
2018-12-27 17:18:47 +08:00
for ( int i = 0 ; i < dateRangeList . size ( ) ; i + + ) {
// 存放一个时间点中总数
2019-01-03 15:38:57 +08:00
List listEnt1 = new ArrayList ( ) ;
List listEnt2 = new ArrayList ( ) ;
2018-12-27 17:18:47 +08:00
Map < String , Long > ipCountMap = new HashMap < String , Long > ( ) ;
Date date = dateRangeList . get ( i ) ;
Long num1 = 0L ;
Long num2 = 0L ;
2018-12-28 17:09:59 +08:00
for ( int j = index1 ; j < entrance1 . size ( ) ; j + + ) {
2018-12-27 17:18:47 +08:00
NtcEntranceReport ipInfo = entrance1 . get ( j ) ;
if ( ipInfo . getReportTime ( ) ! = null ) {
2018-12-29 18:57:21 +08:00
if ( ipInfo . getReportTime ( ) . compareTo ( date ) > = 0 & & ( i + 1 < dateRangeList . size ( ) ? ipInfo . getReportTime ( ) . compareTo ( dateRangeList . get ( i + 1 ) ) < 0 : true ) ) {
2018-12-27 17:18:47 +08:00
num1 = num1 + ipInfo . getSum ( ) ;
} else {
2018-12-28 17:09:59 +08:00
index1 = j ;
2018-12-27 17:18:47 +08:00
break ;
}
2018-12-23 18:09:29 +08:00
}
}
2019-01-03 15:38:57 +08:00
sumEnt1 + = num1 ;
listEnt1 . add ( date . getTime ( ) ) ;
listEnt1 . add ( num1 ) ;
sumList1 . add ( listEnt1 ) ;
2018-12-28 17:09:59 +08:00
for ( int j = index2 ; j < entrance2 . size ( ) ; j + + ) {
2018-12-27 17:18:47 +08:00
NtcEntranceReport ipInfo = entrance2 . get ( j ) ;
if ( ipInfo . getReportTime ( ) ! = null ) {
2018-12-29 18:57:21 +08:00
if ( ipInfo . getReportTime ( ) . compareTo ( date ) > = 0 & & ( i + 1 < dateRangeList . size ( ) ? ipInfo . getReportTime ( ) . compareTo ( dateRangeList . get ( i + 1 ) ) < 0 : true ) ) {
2018-12-27 17:18:47 +08:00
num2 = num2 + ipInfo . getSum ( ) ;
} else {
2018-12-28 17:09:59 +08:00
index2 = j ;
2018-12-27 17:18:47 +08:00
break ;
}
2018-12-23 18:09:29 +08:00
}
}
2019-01-03 15:38:57 +08:00
sumEnt2 + = num2 ;
listEnt2 . add ( date . getTime ( ) ) ;
listEnt2 . add ( num2 ) ;
sumList2 . add ( listEnt2 ) ;
2018-12-23 18:09:29 +08:00
}
2018-12-27 17:18:47 +08:00
// 整合 count time
2019-01-03 15:38:57 +08:00
m1 . put ( " sum " , sumEnt1 ) ;
m1 . put ( " result " , sumList1 ) ;
2018-12-27 17:18:47 +08:00
m1 . put ( " entranceId " , 1 ) ;
2019-01-03 15:38:57 +08:00
m2 . put ( " sum " , sumEnt2 ) ; //
m2 . put ( " result " , sumList2 ) ;
2018-12-27 17:18:47 +08:00
m2 . put ( " entranceId " , 2 ) ;
listMap . add ( m1 ) ;
listMap . add ( m2 ) ;
2018-12-24 22:18:12 +06:00
}
2018-12-23 18:09:29 +08:00
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-17 14:08:03 +06:00
/ *
* 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>
* 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最近一小时的变化 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 ) { for
* ( TrafficIpActiveStatistic ip : ipList ) { if ( ip . getLinkNum ( ) ! = null & &
* ip . getTime ( ) ! = null ) { linkList . add ( ip . getLinkNum ( ) ) ;
* timeList . add ( ip . getTime ( ) ) ; } } } m . put ( " linkNum " , linkList ) ;
* m . put ( " statTime " , timeList ) ; listMap . add ( m ) ; } } } }
*
* return listMap ; }
* /
2018-12-17 10:12:20 +08:00
/ * *
* 获取活跃IPtop10 的趋势图
* /
2018-12-22 21:41:54 +08:00
public List < Map > ipActiveFiveMinute ( Date beginDate , Date endDate ) {
List < Map > listMap = new ArrayList < Map > ( ) ;
List < LinkedHashMap > ipListTop10 = trafficIpActiveStatisticDao . ipActiveChart ( beginDate , endDate ) ;
2018-12-17 14:08:03 +06:00
if ( ipListTop10 ! = null & & ipListTop10 . size ( ) > 0 ) {
2018-12-22 21:41:54 +08:00
StringBuilder ipStr = new StringBuilder ( ) ;
2018-12-17 14:08:03 +06:00
for ( LinkedHashMap map : ipListTop10 ) {
2018-12-24 22:18:12 +06:00
ipStr . append ( " ' " + ( String ) map . get ( " ipAddr " ) + " ', " ) ;
2018-12-22 21:41:54 +08:00
}
2018-12-24 22:18:12 +06:00
if ( ! StringUtil . isEmpty ( ipStr ) & & ipStr . indexOf ( " , " ) > 0 ) {
2018-12-22 21:41:54 +08:00
ipStr . deleteCharAt ( ipStr . lastIndexOf ( " , " ) ) ;
}
2018-12-24 22:18:12 +06:00
// 如果所有IP在最后一个时间点的count都为0, 则移除最后一个点
// 开始划分时间段,间隔5分钟
2018-12-22 21:41:54 +08:00
List < Date > dateRangeList = new ArrayList < Date > ( ) ;
Calendar calendar = Calendar . getInstance ( ) ;
calendar . setTime ( beginDate ) ;
2019-01-03 15:38:57 +08:00
SimpleDateFormat sdf = new SimpleDateFormat ( " yyyy-MM-dd HH:mm:ss " ) ;
2018-12-27 17:18:47 +08:00
while ( calendar . getTime ( ) . compareTo ( endDate ) < 0 ) {
2018-12-22 21:41:54 +08:00
dateRangeList . add ( calendar . getTime ( ) ) ;
2019-01-03 15:38:57 +08:00
calendar . add ( Calendar . MINUTE , Constants . TREND_TIME_INTERVAL ) ;
2018-12-22 21:41:54 +08:00
}
2018-12-24 22:18:12 +06:00
ArrayList < TrafficIpActiveStatistic > ipInfoList = trafficIpActiveStatisticDao
. ipActiveFiveMinute ( ipStr . toString ( ) , beginDate , endDate ) ;
// 存放每个IP, 每个时间点的总数
2019-01-03 15:38:57 +08:00
Map < String , List > ipCountListMap = new HashMap < String , List > ( ) ;
2018-12-24 22:18:12 +06:00
int index = 0 ;
2018-12-22 21:41:54 +08:00
for ( int i = 0 ; i < dateRangeList . size ( ) ; i + + ) {
2018-12-24 22:18:12 +06:00
// 存放一个时间点中每个IP的总数
2018-12-22 21:41:54 +08:00
Map < String , Long > ipCountMap = new HashMap < String , Long > ( ) ;
Date date = dateRangeList . get ( i ) ;
for ( int j = index ; j < ipInfoList . size ( ) ; j + + ) {
TrafficIpActiveStatistic ipInfo = ipInfoList . get ( j ) ;
2018-12-24 22:18:12 +06:00
if ( ipInfo . getStatTime ( ) ! = null ) {
2019-01-03 15:38:57 +08:00
if ( ipInfo . getStatTime ( ) . compareTo ( date ) > = 0 & & ( i + 1 < dateRangeList . size ( )
& & ipInfo . getStatTime ( ) . compareTo ( dateRangeList . get ( i + 1 ) ) < 0 ) ) {
2018-12-22 21:41:54 +08:00
Long num = ipInfo . getCount ( ) ;
if ( ipCountMap . containsKey ( ipInfo . getIpAddr ( ) ) ) {
2018-12-24 22:18:12 +06:00
num = num + ipCountMap . get ( ipInfo . getIpAddr ( ) ) ;
2018-12-22 21:41:54 +08:00
}
ipCountMap . put ( ipInfo . getIpAddr ( ) , num ) ;
2018-12-24 22:18:12 +06:00
} else {
2018-12-22 21:41:54 +08:00
index = j ;
break ;
2018-12-17 10:12:20 +08:00
}
}
2018-12-22 21:41:54 +08:00
}
for ( LinkedHashMap map : ipListTop10 ) {
String ip = ( String ) map . get ( " ipAddr " ) ;
2019-01-03 15:38:57 +08:00
List sumList = new ArrayList ( ) ;
sumList . add ( date . getTime ( ) ) ;
2018-12-22 21:41:54 +08:00
Long sum = 0l ;
if ( ipCountMap . containsKey ( ip ) ) {
2018-12-24 22:18:12 +06:00
sum = ipCountMap . get ( ip ) ;
2018-12-17 14:08:03 +06:00
}
2019-01-03 15:38:57 +08:00
sumList . add ( sum ) ;
2018-12-22 21:41:54 +08:00
if ( ipCountListMap . containsKey ( ip ) ) {
2019-01-03 15:38:57 +08:00
List ipList = ipCountListMap . get ( ip ) ;
ipList . add ( sumList ) ;
2018-12-24 22:18:12 +06:00
} else {
2019-01-03 15:38:57 +08:00
List iplist = new ArrayList ( ) ;
iplist . add ( sumList ) ;
ipCountListMap . put ( ip , iplist ) ;
2018-12-17 14:08:03 +06:00
}
2018-12-17 10:12:20 +08:00
}
2018-12-22 21:41:54 +08:00
}
2019-01-03 15:38:57 +08:00
// 整合IP计算总数
2018-12-22 21:41:54 +08:00
Iterator iterator = ipCountListMap . keySet ( ) . iterator ( ) ;
while ( iterator . hasNext ( ) ) {
2018-12-24 22:18:12 +06:00
String ip = iterator . next ( ) + " " ;
2018-12-22 21:41:54 +08:00
Map ipTrafficMap = new HashMap ( ) ;
ipTrafficMap . put ( " ipAddr " , ip ) ;
2019-01-03 15:38:57 +08:00
Long total = 0L ;
for ( Object obj : ipCountListMap . get ( ip ) ) {
List < Long > list = ( List ) obj ;
total + = list . get ( 1 ) ;
}
ipTrafficMap . put ( " result " , ipCountListMap . get ( ip ) ) ;
ipTrafficMap . put ( " sum " , total ) ;
2018-12-22 21:41:54 +08:00
listMap . add ( ipTrafficMap ) ;
2018-12-17 10:12:20 +08:00
}
2018-12-17 14:08:03 +06:00
}
2018-12-17 10:12:20 +08:00
return listMap ;
2018-10-12 17:45:45 +08:00
}
2018-12-17 14:08:03 +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-17 14:08:03 +06:00
public List < HashMap > ipActiveOneHour ( Date beginDate , Date endDate ) {
2018-12-24 22:31:42 +06:00
2018-12-24 22:18:12 +06:00
// TrafficIpActiveStatistic maxStatTime = trafficIpActiveStatisticDao.getMaxStatTime();
2018-12-10 10:23:48 +06:00
ArrayList < HashMap > listMap = new ArrayList < HashMap > ( ) ;
2018-12-24 22:18:12 +06:00
// if (maxStatTime != null && maxStatTime.getStatTime() != null) {
// Date statTime = maxStatTime.getStatTime();
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 " ) ;
HashMap resMap = trafficIpActiveStatisticDao . ipActiveOneHour ( ipAddr , beginDate , endDate ) ;
if ( resMap ! = null ) {
listMap . add ( resMap ) ;
2018-10-26 14:41:27 +08:00
}
2018-10-12 17:45:45 +08:00
}
}
}
2018-12-24 22:18:12 +06:00
// }
2018-12-10 10:23:48 +06:00
2018-10-12 17:45:45 +08:00
return listMap ;
2018-12-24 22:31:42 +06:00
2018-10-12 17:45:45 +08:00
}
2018-12-10 10:23:48 +06:00
2018-12-17 10:12:20 +08:00
/ * *
* 活跃IP首页top10
2018-12-17 14:08:03 +06:00
*
2018-12-17 10:12:20 +08:00
* @param beginDate
* @param endDate
* @return
* /
2018-10-26 14:41:27 +08:00
@SuppressWarnings ( " rawtypes " )
2018-12-17 10:12:20 +08:00
public List < LinkedHashMap > ipActiveChart ( Date beginDate , Date endDate ) {
// TrafficIpActiveStatistic maxStatTime = trafficIpActiveStatisticDao.getMaxStatTime();
2018-10-26 14:41:27 +08:00
ArrayList < LinkedHashMap > list = new ArrayList < > ( ) ;
2018-12-17 10:12:20 +08:00
// if (maxStatTime != null && maxStatTime.getStatTime() != null) {
// Date statTime = maxStatTime.getStatTime();
2018-12-17 14:08:03 +06:00
list = trafficIpActiveStatisticDao . ipActiveChart ( beginDate , endDate ) ;
if ( list ! = null & & list . size ( ) > 0 ) {
for ( LinkedHashMap map : list ) {
if ( map . get ( " ipAddr " ) ! = null ) {
Map m = new LinkedHashMap ( ) ;
map . put ( " pktNum " , 0 ) ;
map . put ( " byteLen " , 0 ) ;
2018-10-26 14:41:27 +08:00
}
}
2018-12-17 14:08:03 +06:00
}
2018-12-17 10:12:20 +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-24 22:18:12 +06:00
public List < Map > getProtocolList ( String startTime , String endTime , Integer [ ] protoType ) {
2018-12-22 23:01:37 +08:00
// TrafficProtocolStatistic maxStatTime = trafficProtocolStatisticDao.getMaxStatTime();
2018-12-10 10:23:48 +06:00
List < Map > list = new ArrayList < Map > ( ) ;
2018-12-22 23:01:37 +08:00
// if (maxStatTime != null && maxStatTime.getStatTime() != null) {
// Date statTime = maxStatTime.getStatTime();
2018-12-24 22:18:12 +06:00
list = trafficProtocolStatisticDao . getProtocolList ( startTime , endTime , protoType ) ;
2018-12-22 23:01:37 +08:00
// }
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-22 23:01:37 +08:00
public List < Map > getAppList ( String startTime , String endTime , Integer [ ] appType ) {
2018-12-17 10:12:20 +08:00
// TrafficAppStatistic maxStatTime = trafficAppStatisticDao.getMaxStatTime();
2018-12-10 10:23:48 +06:00
List < Map > list = new ArrayList < Map > ( ) ;
2018-12-17 10:12:20 +08:00
// if (maxStatTime != null && maxStatTime.getStatTime() != null) {
// Date statTime = maxStatTime.getStatTime();
2018-12-17 14:08:03 +06:00
list = trafficAppStatisticDao . getAppList ( startTime , endTime , appType ) ;
2018-12-17 10:12:20 +08:00
// }
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-17 10:12:20 +08:00
/ * *
*
* 网站子域名详情
2018-12-17 14:08:03 +06:00
*
2018-12-17 10:12:20 +08:00
* @param beginDate
* @param endDate
* @return
* /
2018-12-17 14:08:03 +06:00
public List < Map > getWebsiteDetailsById ( Integer websiteServiceId , Date beginDate , Date endDate ) {
List < Map > list = null ;
if ( beginDate ! = null & & endDate ! = null ) {
list = getDomainByWebsiteServiceId ( websiteServiceId , beginDate , endDate , null ) ;
} else {
Date startTime = getBeforeByHourTime ( 1 ) ; // 获取上一个小时
list = getDomainByWebsiteServiceId ( websiteServiceId , startTime , new Date ( ) , " top " ) ;
}
2018-12-17 10:12:20 +08:00
return list ;
}
2018-12-17 14:08:03 +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-17 14:08:03 +06:00
public List < Map > getDomainByWebsiteServiceId ( Integer websiteServiceId , Date beginDate , Date endDate , String top ) {
2018-12-10 18:55:14 +06:00
2018-12-17 10:12:20 +08:00
// Date statTime = getBeforeByHourTime(1);// 获取上一个小时
2018-12-10 18:55:14 +06:00
List idList = trafficHttpStatisticDao . getIdByWebSiteId ( websiteServiceId ) ;
2018-12-17 10:12:20 +08:00
List < Map > matchList = trafficHttpStatisticDao . getDomainByWebsiteServiceId ( idList , beginDate , endDate ) ; // 获取webid和count的对应关系,key是webid,val是count
2018-12-10 18:55:14 +06:00
// 获取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 ) ;
}
}
2018-12-17 14:08:03 +06:00
List < Map > top10Data = new ArrayList ( ) ;
if ( top ! = null ) {
top10Data = getTop10Data ( set , countMap , 1 ) ;
} else {
top10Data = getTop10Data ( set , countMap , 2 ) ;
2018-12-17 10:12:20 +08:00
}
2018-12-10 18:55:14 +06:00
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 ) {
2018-12-17 10:12:20 +08:00
Map others = trafficHttpStatisticDao . websiteDomainOthers ( notTop10List , beginDate , endDate ) ;
2018-12-10 18:55:14 +06:00
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-17 14:08:03 +06:00
2018-12-17 10:12:20 +08:00
/ * *
*
* 网站详情
2018-12-17 14:08:03 +06:00
*
2018-12-17 10:12:20 +08:00
* @param beginDate
* @param endDate
* @return
* /
2018-12-22 23:01:37 +08:00
public List < Map > getWebsiteDetails ( Date beginDate , Date endDate , Integer domain [ ] , Integer entranceId ) {
2018-12-18 06:05:16 +06:00
List < Map > list = trafficHttpStatisticDao . getTrafficHttpDomain ( beginDate , endDate , domain , entranceId ) ;
2018-12-17 10:12:20 +08:00
return list ;
}
2018-12-17 14:08:03 +06:00
/ * *
*
* 网站TOP10 默认一小时
*
2018-12-17 10:12:20 +08:00
* @param beginDate
* @param endDate
* @return
* /
2018-12-17 14:08:03 +06:00
public List < Map > getWebsiteTop10 ( ) {
Date startTime = getBeforeByHourTime ( 1 ) ; // 获取上一个小时
List < Map > list = getDomainByWebsiteList ( startTime , new Date ( ) , " top " ) ;
2018-12-17 10:12:20 +08:00
return list ;
}
2018-12-17 14:08:03 +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-17 14:08:03 +06:00
public List < Map > getDomainByWebsiteList ( Date beginDate , Date endDate , String top ) {
2018-12-10 18:55:14 +06:00
Map < String , List < String > > websiteIdAndIdMap = new HashMap < > ( ) ; // 存储websiteServiceId和id的对应关系,一个websiteServiceId有多个id
2018-12-17 10:12:20 +08:00
List < Map > websiteIdAndidList = trafficHttpStatisticDao . getDomainByWebsiteList ( beginDate , endDate ) ; // 获取website_service_id和id的对应关系,group
2018-12-10 18:55:14 +06:00
// 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
2018-12-17 16:28:43 +06:00
List < Map > webIdAndCountList = trafficHttpStatisticDao . getHttpStatisticNoLinkAndPkt ( beginDate , endDate ) ; // 获取最近一小时的webid和count的关系
List < Map > prevWebIdAndCountList = trafficHttpStatisticDao . getHttpStatisticNoLinkAndPkt ( getBeforeByHourTime ( 2 ) ,
2018-12-17 14:08:03 +06:00
beginDate ) ; // 获取最近一小时的webid和count的关系
2018-12-10 18:55:14 +06:00
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数据并统计
2018-12-17 14:08:03 +06:00
String countStr = String . valueOf ( webIdAndCountMap . get ( " byteCount " ) ) ;
2018-12-10 18:55:14 +06:00
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数据并统计
2018-12-17 14:08:03 +06:00
String countStr = String . valueOf ( webIdAndCountMap . get ( " byteCount " ) ) ;
2018-12-10 18:55:14 +06:00
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-17 10:12:20 +08:00
List < Map > dataList = new ArrayList ( ) ;
2018-12-17 14:08:03 +06:00
if ( top ! = null ) {
dataList = getTop10Data ( set , countAndViewMap , 1 ) ; // 取top10
} else {
dataList = getTop10Data ( set , countAndViewMap , 2 ) ;
2018-12-17 10:12:20 +08:00
}
return dataList ;
2018-09-21 20:56:01 +08:00
}
2018-12-17 14:08:03 +06:00
2018-12-17 10:12:20 +08:00
/ * *
*
* 主题详情
2018-12-17 14:08:03 +06:00
*
2018-12-17 10:12:20 +08:00
* @param beginDate
* @param endDate
* @return
* /
2018-12-17 14:08:03 +06:00
public List < Map > getTopicDetails ( Date beginDate , Date endDate ) {
List < Map > topicAndDomainList = getTopicAndDomainList ( beginDate , endDate , null ) ;
2018-12-17 10:12:20 +08:00
return topicAndDomainList ;
}
2018-12-17 14:08:03 +06:00
/ * *
*
* 主题TOP10 默认一小时
*
2018-12-17 10:12:20 +08:00
* @param beginDate
* @param endDate
* @return
* /
2018-12-17 14:08:03 +06:00
public List < Map > getTopicTop10 ( ) {
Date startTime = getBeforeByHourTime ( 1 ) ; // 获取上一个小时
2018-12-18 06:05:16 +06:00
List < Map > topicAndDomainList = getTopicAndDomainListNoLink ( startTime , new Date ( ) , " top " ) ;
2018-12-17 10:12:20 +08:00
return topicAndDomainList ;
}
2018-12-17 14:08:03 +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
* * /
2018-12-18 06:05:16 +06:00
public List < Map > getTopicAndDomainListNoLink ( Date beginDate , Date endDate , String top ) {
Map < String , List < String > > topicIdAndIdMap = new HashMap < > ( ) ; // 存储topicid和id的对应关系,一个topicid有多个id
List < Map > topicIdAndIdList = trafficHttpStatisticDao . getDomainByTopicList ( beginDate , endDate ) ; // 获取最近一个小时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 . getHttpStatisticNoLinkAndPkt ( beginDate , endDate ) ; // 获取最近一小时的webid和count的关系
for ( String topicId : topicIdAndIdMap . keySet ( ) ) { // 遍历上面获取的topicid和id的对应关系,拼接json
Map viewMap = new HashMap < > ( ) ;
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 ( " byteCount " ) ) ;
// String linkNumStr = String.valueOf(webIdAndCountMap.get("linkNum"));
// String packetsStr = String.valueOf(webIdAndCountMap.get("pktCount"));
if ( countStr ! = null ) {
2018-12-28 17:08:12 +08:00
count + = Long . parseLong ( countStr ) ; // 将count累加 转换单位小于0的不加
2018-12-18 06:05:16 +06:00
}
// if (linkNumStr != null) {
// linkNum += Long.parseLong(linkNumStr);// 将count累加
// }
// if (packetsStr != null) {
// packets += Long.parseLong(packetsStr);// 将count累加
// }
// webIdAndCountMap.remove("linkNum");
// webIdAndCountMap.remove("pktCount");
list . add ( webIdAndCountMap ) ;
}
}
}
2018-12-22 23:01:37 +08:00
Collections . sort ( list , new Comparator < Object > ( ) {
@Override
public int compare ( Object o1 , Object o2 ) {
2018-12-24 22:18:12 +06:00
if ( o1 = = null & & o2 ! = null ) {
2018-12-22 23:01:37 +08:00
return 1 ;
}
2018-12-24 22:18:12 +06:00
if ( o1 ! = null & & o2 = = null ) {
2018-12-22 23:01:37 +08:00
return - 1 ;
}
2018-12-24 22:18:12 +06:00
if ( o1 = = o2 & & o1 = = null ) {
2018-12-22 23:01:37 +08:00
return 0 ;
}
2018-12-24 22:18:12 +06:00
Map m1 = ( Map ) o1 ;
Map m2 = ( Map ) o2 ;
2018-12-22 23:01:37 +08:00
Object ob1 = m1 . get ( " byteCount " ) ;
Object ob2 = m2 . get ( " byteCount " ) ;
2018-12-24 22:18:12 +06:00
Long b1 = Long . parseLong ( ob1 . toString ( ) ) ;
Long b2 = Long . parseLong ( ob2 . toString ( ) ) ;
2018-12-22 23:01:37 +08:00
return - ( b1 ) . compareTo ( b2 ) ;
}
} ) ;
2018-12-18 06:05:16 +06:00
if ( list . size ( ) > 0 ) {
viewMap . put ( " count " , count ) ;
// viewMap.put("linkNum", linkNum);
// viewMap.put("packets", packets);
viewMap . put ( " domainData " , list ) ;
viewMap . put ( " topicId " , topicId ) ;
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 ) ;
}
}
List < Map > dataList = new ArrayList ( ) ;
if ( top ! = null ) {
dataList = getTop10Data ( set , countAndViewMap , 1 ) ;
} else {
dataList = getTop10Data ( set , countAndViewMap , 2 ) ;
}
return dataList ;
}
2018-12-17 14:08:03 +06:00
public List < Map > getTopicAndDomainList ( Date beginDate , Date endDate , String top ) {
2018-12-10 10:23:48 +06:00
Map < String , List < String > > topicIdAndIdMap = new HashMap < > ( ) ; // 存储topicid和id的对应关系,一个topicid有多个id
2018-12-17 14:08:03 +06:00
List < Map > topicIdAndIdList = trafficHttpStatisticDao . getDomainByTopicList ( beginDate , endDate ) ; // 获取最近一个小时topicId和id的对应关系,group
2018-12-10 10:23:48 +06:00
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
2018-12-17 14:08:03 +06:00
List < Map > webIdAndCountList = trafficHttpStatisticDao . getTrafficHttpStatistic ( beginDate , endDate ) ; // 获取最近一小时的webid和count的关系
2018-12-10 10:23:48 +06:00
for ( String topicId : topicIdAndIdMap . keySet ( ) ) { // 遍历上面获取的topicid和id的对应关系,拼接json
Map viewMap = new HashMap < > ( ) ;
List < Map > list = new ArrayList < > ( ) ;
long count = 0l ; // 记录当前topicid所有的count
2018-12-17 14:08:03 +06:00
long linkNum = 0l ;
2018-12-17 10:12:20 +08:00
long packets = 0l ;
2018-12-10 10:23:48 +06:00
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数据并统计
2018-12-17 14:08:03 +06:00
String countStr = String . valueOf ( webIdAndCountMap . get ( " byteCount " ) ) ;
2018-12-17 10:12:20 +08:00
String linkNumStr = String . valueOf ( webIdAndCountMap . get ( " linkNum " ) ) ;
2018-12-17 14:40:32 +06:00
String packetsStr = String . valueOf ( webIdAndCountMap . get ( " pktCount " ) ) ;
2018-12-10 10:23:48 +06:00
if ( countStr ! = null ) {
count + = Long . parseLong ( countStr ) ; // 将count累加
}
2018-12-17 10:12:20 +08:00
if ( linkNumStr ! = null ) {
linkNum + = Long . parseLong ( linkNumStr ) ; // 将count累加
}
if ( packetsStr ! = null ) {
packets + = Long . parseLong ( packetsStr ) ; // 将count累加
}
2018-12-17 14:40:32 +06:00
webIdAndCountMap . remove ( " linkNum " ) ;
webIdAndCountMap . remove ( " pktCount " ) ;
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
}
2018-12-18 06:05:16 +06:00
if ( list . size ( ) > 0 ) {
viewMap . put ( " count " , count ) ;
viewMap . put ( " linkNum " , linkNum ) ;
viewMap . put ( " packets " , packets ) ;
viewMap . put ( " domainData " , list ) ;
viewMap . put ( " topicId " , topicId ) ;
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-12-10 10:23:48 +06:00
}
2018-09-21 20:56:01 +08:00
}
2018-12-17 10:12:20 +08:00
List < Map > dataList = new ArrayList ( ) ;
2018-12-17 14:08:03 +06:00
if ( top ! = null ) {
dataList = getTop10Data ( set , countAndViewMap , 1 ) ;
} else {
dataList = getTop10Data ( set , countAndViewMap , 2 ) ;
2018-12-17 10:12:20 +08:00
}
return dataList ;
2018-09-21 20:56:01 +08:00
}
2018-12-24 22:18:12 +06:00
2018-12-18 06:05:16 +06:00
public String [ ] getFiledTypeByName ( String fieldName ) {
if ( fieldName = = null ) {
2018-12-17 23:41:00 +08:00
return null ;
}
2018-12-18 06:05:16 +06:00
String fieldType = null ;
if ( " addr_type " . equals ( fieldName ) ) {
fieldType = ntcTotalReportDao . getAddrType ( ) ;
2018-12-17 23:41:00 +08:00
}
2018-12-18 06:05:16 +06:00
if ( " trans_type " . equals ( fieldName ) ) {
fieldType = ntcTotalReportDao . getTransType ( ) ;
2018-12-17 23:41:00 +08:00
}
2018-12-18 06:05:16 +06:00
if ( " entrance_id " . equals ( fieldName ) ) {
fieldType = ntcTotalReportDao . getEntranceId ( ) ;
2018-12-17 23:41:00 +08:00
}
2018-12-18 06:05:16 +06:00
return fieldType = = null ? null : fieldType . split ( " , " ) ;
2018-12-17 23:41:00 +08:00
}
2018-12-18 06:05:16 +06:00
2018-12-29 18:57:21 +08:00
public Map < String , Map > getBandwidthTransEntrance ( String beginDate , String endDate , String searchQuotaType ) throws ParseException {
2018-12-22 21:41:54 +08:00
Map < String , Map > resultMap = new HashMap < String , Map > ( ) ;
Map < String , ArrayList < TrafficTransStatistic > > listMap = new HashMap < String , ArrayList < TrafficTransStatistic > > ( ) ;
List < TrafficTransStatistic > bandwidthListIPvx = new ArrayList < TrafficTransStatistic > ( ) ;
List < TrafficTransStatistic > bandwidthListProtocol = new ArrayList < TrafficTransStatistic > ( ) ;
bandwidthListIPvx = ntcTotalReportDao . getBandwidthTransIPVx ( beginDate , endDate ) ;
bandwidthListProtocol = ntcTotalReportDao . getBandwidthTransProtocol ( beginDate , endDate ) ;
Map < String , Map > trafficMap = new HashMap < String , Map > ( ) ;
2018-12-24 22:18:12 +06:00
if ( ( ! StringUtil . isEmpty ( bandwidthListIPvx ) & & bandwidthListIPvx . size ( ) > 0 )
| | ( ! StringUtil . isEmpty ( bandwidthListProtocol ) & & bandwidthListProtocol . size ( ) > 0 ) ) {
// 划分时间段
2018-12-25 17:12:48 +08:00
SimpleDateFormat sdf = new SimpleDateFormat ( " yyyy-MM-dd HH:mm:ss " ) ;
2018-12-22 21:41:54 +08:00
Date startTime = sdf . parse ( beginDate ) ;
Date endTime = sdf . parse ( endDate ) ;
List < Date > dateRangeList = new ArrayList < Date > ( ) ;
Calendar calendar = Calendar . getInstance ( ) ;
calendar . setTime ( startTime ) ;
2018-12-24 22:18:12 +06:00
2018-12-27 17:18:47 +08:00
while ( calendar . getTime ( ) . compareTo ( endTime ) < 0 ) {
2018-12-22 21:41:54 +08:00
dateRangeList . add ( calendar . getTime ( ) ) ;
2019-01-03 15:38:57 +08:00
calendar . add ( Calendar . MINUTE , Constants . TREND_TIME_INTERVAL ) ;
2018-12-17 23:41:00 +08:00
}
2018-12-22 21:41:54 +08:00
String [ ] addrTypes = getFiledTypeByName ( " addr_type " ) ;
String [ ] transTypes = getFiledTypeByName ( " trans_type " ) ;
String [ ] entranceIds = getFiledTypeByName ( " entrance_id " ) ;
2018-12-24 22:18:12 +06:00
if ( bandwidthListIPvx ! = null & & bandwidthListIPvx . size ( ) > 0 & & bandwidthListProtocol ! = null
& & bandwidthListProtocol . size ( ) > 0 & & addrTypes ! = null & & addrTypes . length > 0
& & transTypes ! = null & & transTypes . length > 0 & & entranceIds ! = null & & entranceIds . length > 0 ) {
// 按区域和类型构建Map
2018-12-22 21:41:54 +08:00
for ( String entranceId : entranceIds ) {
for ( String addrType : addrTypes ) {
listMap . put ( " ipv " + addrType + " Type " + entranceId , new ArrayList < TrafficTransStatistic > ( ) ) ;
}
2018-12-17 23:41:00 +08:00
}
2018-12-22 21:41:54 +08:00
for ( String entranceId : entranceIds ) {
for ( String transType : transTypes ) {
listMap . put ( " trans " + transType + " Type " + entranceId , new ArrayList < TrafficTransStatistic > ( ) ) ;
2018-12-17 23:41:00 +08:00
}
}
2018-12-24 22:18:12 +06:00
// 按区域和类型提取数据到列表中
2018-12-22 21:41:54 +08:00
for ( TrafficTransStatistic tts : bandwidthListIPvx ) {
String addrType = tts . getAddrType ( ) ;
2018-12-24 22:18:12 +06:00
2018-12-22 21:41:54 +08:00
Integer entranceId = tts . getEntranceId ( ) ;
Integer transType = tts . getTransType ( ) ;
String key = " ipv " + addrType + " Type " + entranceId ;
listMap . get ( key ) . add ( tts ) ;
2018-12-17 23:41:00 +08:00
}
2018-12-22 21:41:54 +08:00
for ( TrafficTransStatistic tts : bandwidthListProtocol ) {
String addrType = tts . getAddrType ( ) ;
Integer entranceId = tts . getEntranceId ( ) ;
Integer transType = tts . getTransType ( ) ;
String key = " trans " + transType + " Type " + entranceId ;
listMap . get ( key ) . add ( tts ) ;
2018-12-17 23:41:00 +08:00
}
2018-12-22 21:41:54 +08:00
Set < Entry < String , ArrayList < TrafficTransStatistic > > > entrySet = listMap . entrySet ( ) ;
for ( Entry < String , ArrayList < TrafficTransStatistic > > entry : entrySet ) {
String key = entry . getKey ( ) ;
String entranceId = key . substring ( key . length ( ) - 1 ) ;
ArrayList < TrafficTransStatistic > value = entry . getValue ( ) ;
2018-12-29 18:57:21 +08:00
resultMap . put ( key , getNewData ( dateRangeList , value , searchQuotaType ) ) ;
2018-12-17 23:41:00 +08:00
}
2018-12-22 21:41:54 +08:00
}
}
2018-12-25 16:49:09 +08:00
return resultMap ;
2018-12-22 21:41:54 +08:00
}
2018-12-29 18:57:21 +08:00
private Map getNewData ( List < Date > dateRangeList , List < TrafficTransStatistic > bandwidthList , String searchQuotaType ) {
Map restMap = new HashMap ( ) ;
List < List > restList = new ArrayList < List > ( ) ;
2018-12-22 21:41:54 +08:00
int index = 0 ;
2018-12-29 18:57:21 +08:00
Long sum = 0l ;
2018-12-22 21:41:54 +08:00
for ( int i = 0 ; i < dateRangeList . size ( ) ; i + + ) {
Date date = dateRangeList . get ( i ) ;
2018-12-29 18:57:21 +08:00
List countList = new ArrayList ( ) ;
countList . add ( date . getTime ( ) ) ;
long num = 0l ;
2018-12-22 21:41:54 +08:00
for ( int j = index ; j < bandwidthList . size ( ) ; j + + ) {
TrafficTransStatistic info = bandwidthList . get ( j ) ;
2018-12-24 22:18:12 +06:00
if ( info . getStatTime ( ) ! = null ) {
2018-12-29 18:57:21 +08:00
if ( info . getStatTime ( ) . compareTo ( date ) > = 0 & & ( i + 1 < dateRangeList . size ( ) ? info . getStatTime ( ) . compareTo ( dateRangeList . get ( i + 1 ) ) < 0 : true ) ) {
if ( " pps " . equalsIgnoreCase ( searchQuotaType ) ) {
num = Long . parseLong ( info . getPps ( ) . substring ( 0 , info . getPps ( ) . lastIndexOf ( " . " ) ) ) + num ;
} else if ( " linkNumber " . equalsIgnoreCase ( searchQuotaType ) ) {
num = Long . parseLong ( info . getPps ( ) . substring ( 0 , info . getPps ( ) . lastIndexOf ( " . " ) ) ) + num ;
} else {
num = Long . parseLong ( info . getGbps ( ) . substring ( 0 , info . getGbps ( ) . lastIndexOf ( " . " ) ) ) + num ;
}
2018-12-24 22:18:12 +06:00
} else {
2018-12-22 21:41:54 +08:00
index = j ;
break ;
}
2018-12-17 23:41:00 +08:00
}
2018-12-22 21:41:54 +08:00
}
2018-12-29 18:57:21 +08:00
countList . add ( num ) ;
sum + = num ;
restList . add ( countList ) ;
2018-12-18 06:05:16 +06:00
}
2018-12-29 18:57:21 +08:00
restMap . put ( " sum " , sum ) ;
restMap . put ( " result " , restList ) ;
return restMap ;
2018-12-17 23:41:00 +08:00
}
2018-12-18 06:05:16 +06:00
2018-12-18 04:59:07 +08:00
/ * *
*
* @param beginDate
* @param endDate
* @param domain
* @param entranceId
* @return
* /
2018-12-23 18:09:29 +08:00
/ *
2018-12-24 22:18:12 +06:00
* public List < HashMap > getDomainTrans ( String beginDate , String endDate , Integer
* domain , Integer entranceId ) { List < HashMap > listMap = new
2018-12-23 18:09:29 +08:00
* ArrayList < HashMap > ( ) ; HashMap resulMap = new HashMap ( ) ;
* List < TrafficHttpFocusStatistic > domainList = new
* ArrayList < TrafficHttpFocusStatistic > ( ) ; domainList =
* trafficHttpStatisticDao . getDomainTrans ( entranceId , beginDate , endDate ,
2018-12-24 22:18:12 +06:00
* domain ) ; List timeList = new ArrayList ( ) ; List countList = new ArrayList ( ) ;
* if ( domainList ! = null & & domainList . size ( ) > 0 ) { Map < String , Comparable > m
* = new HashMap < String , Comparable > ( ) ; int inter = 1000 * 60 * 30 ; // 间隔时间为30分钟
* // 开始时间,结束时间 时间戳 Long b = dateToStamp(beginDate); Long e =
* dateToStamp ( endDate ) ; int num = 0 ; Long pointTime = b ; while ( pointTime < e )
* { Map rm = new HashMap ( ) ; Long sumL = 0l ; if ( pointTime > = e ) { break ; // 停止
* } for ( TrafficHttpFocusStatistic tt : domainList ) { // 实际时间 String time =
* tt . getTime ( ) ; Long t = dateToStamp ( time ) ; if ( t > = pointTime & & t < pointTime
* + inter ) { // 范围之内分到此pointTime组 sumL = sumL + tt.getCount(); } } //
2018-12-23 18:09:29 +08:00
* 在结束时间只有当值大于0时才记录数据 , 防止折线降为0引起误会 if ( pointTime > = e - inter & & sumL > 0 ) {
2018-12-24 22:18:12 +06:00
* countList . add ( sumL ) ; timeList . add ( stampToDate ( pointTime ) ) ; } if ( pointTime <
* e - inter ) { timeList . add ( stampToDate ( pointTime ) ) ; countList . add ( sumL ) ; } num
* = num + 1 ; pointTime = b + inter * num ; } resulMap . put ( " count " , countList ) ;
* resulMap . put ( " statTime " , timeList ) ; listMap . add ( resulMap ) ; } return listMap ;
* }
2018-12-23 18:09:29 +08:00
* /
/ * *
* 优化后的网站详情域名趋势查询
2018-12-24 22:18:12 +06:00
*
2018-12-23 18:09:29 +08:00
* @param beginDate
* @param endDate
* @param domain
* @param entranceId
* @return
* /
public List < HashMap > getDomainTrans2 ( String begin , String end , Integer domain , Integer entranceId ) {
2018-12-18 04:59:07 +08:00
List < TrafficHttpFocusStatistic > domainList = new ArrayList < TrafficHttpFocusStatistic > ( ) ;
2018-12-23 18:09:29 +08:00
domainList = trafficHttpStatisticDao . getDomainTrans ( entranceId , begin , end , domain ) ;
List < HashMap > listMap = new ArrayList < HashMap > ( ) ;
2018-12-27 17:18:47 +08:00
if ( ! StringUtil . isEmpty ( domainList ) ) {
Date beginDate = DateUtils . parseDate ( begin ) ;
Date endDate = DateUtils . parseDate ( end ) ;
List < Date > dateRangeList = new ArrayList < Date > ( ) ;
Calendar calendar = Calendar . getInstance ( ) ;
calendar . setTime ( beginDate ) ;
2018-12-29 18:57:21 +08:00
SimpleDateFormat sdf = new SimpleDateFormat ( " yyyy-MM-dd HH:mm:ss " ) ;
2018-12-27 17:18:47 +08:00
while ( calendar . getTime ( ) . compareTo ( endDate ) < 0 ) {
dateRangeList . add ( calendar . getTime ( ) ) ;
2019-01-03 15:38:57 +08:00
calendar . add ( Calendar . MINUTE , Constants . TREND_TIME_INTERVAL ) ;
2018-12-27 17:18:47 +08:00
}
// 存放每个时间点的总数
Map < String , List < Long > > ipCountListMap = new HashMap < String , List < Long > > ( ) ;
int index = 0 ;
2019-01-03 15:38:57 +08:00
List resultList = new ArrayList ( ) ;
Long total = 0L ;
2018-12-27 17:18:47 +08:00
for ( int i = 0 ; i < dateRangeList . size ( ) ; i + + ) {
// 存放一个时间点中总数
2019-01-03 15:38:57 +08:00
List sumList = new ArrayList ( ) ;
2018-12-27 17:18:47 +08:00
Date date = dateRangeList . get ( i ) ;
Long num = 0L ;
for ( int j = index ; j < domainList . size ( ) ; j + + ) {
TrafficHttpFocusStatistic ipInfo = domainList . get ( j ) ;
if ( ipInfo . getStatTime ( ) ! = null ) {
2018-12-29 18:57:21 +08:00
if ( ipInfo . getStatTime ( ) . compareTo ( date ) > = 0 & & ( i + 1 < dateRangeList . size ( ) ? ipInfo . getStatTime ( ) . compareTo ( dateRangeList . get ( i + 1 ) ) < 0 : true ) ) {
2018-12-27 17:18:47 +08:00
num = num + ipInfo . getCount ( ) ;
} else {
index = j ;
break ;
}
2018-12-18 04:59:07 +08:00
}
}
2019-01-03 15:38:57 +08:00
sumList . add ( date . getTime ( ) ) ;
sumList . add ( num ) ;
resultList . add ( sumList ) ;
total + = num ;
2018-12-18 04:59:07 +08:00
}
2018-12-27 17:18:47 +08:00
// 整合 count time
HashMap ipTrafficMap = new HashMap ( ) ;
2019-01-03 15:38:57 +08:00
ipTrafficMap . put ( " result " , resultList ) ;
ipTrafficMap . put ( " sum " , total ) ;
2018-12-27 17:18:47 +08:00
listMap . add ( ipTrafficMap ) ;
2018-12-24 22:18:12 +06:00
}
2018-12-18 04:59:07 +08:00
return listMap ;
}
2018-12-23 20:46:19 +08:00
/ * *
* 获取活跃Port top10 的趋势图
2018-12-24 22:18:12 +06:00
*
* @throws ParseException
2018-12-23 20:46:19 +08:00
* /
2018-12-24 22:18:12 +06:00
public List < Map > findTrafficPortActive ( String beginDate , String endDate , Integer [ ] portArray )
throws ParseException {
2018-12-23 20:46:19 +08:00
List < Map > listMap = new ArrayList < Map > ( ) ;
StringBuilder portStr = new StringBuilder ( ) ;
2018-12-24 22:18:12 +06:00
List < LinkedHashMap > portListTop10 = null ;
if ( portArray ! = null & & portArray . length > 0 ) { // 如果有传人参数,获取传人参数
for ( int pi = 0 ; pi < portArray . length ; pi + + ) {
portStr . append ( " ' " + portArray [ pi ] + " ', " ) ;
2018-12-23 20:46:19 +08:00
}
2018-12-24 22:18:12 +06:00
} else { // 否则获取TOP10
2018-12-23 20:46:19 +08:00
portListTop10 = trafficPortActiveStatisticDao . findTrafficPortActiveTopN ( beginDate , endDate ) ;
for ( LinkedHashMap map : portListTop10 ) {
2018-12-24 22:18:12 +06:00
portStr . append ( " ' " + map . get ( " port " ) + " ', " ) ;
2018-12-23 20:46:19 +08:00
}
}
2018-12-24 22:18:12 +06:00
if ( ! StringUtil . isEmpty ( portStr ) & & portStr . indexOf ( " , " ) > 0 ) {
2018-12-23 20:46:19 +08:00
portStr . deleteCharAt ( portStr . lastIndexOf ( " , " ) ) ;
}
Date beginDate1 = DateUtils . strToDate ( beginDate , " yyyy-MM-dd HH:mm:ss " ) ;
Date endDate1 = DateUtils . strToDate ( endDate , " yyyy-MM-dd HH:mm:ss " ) ;
2018-12-24 22:18:12 +06:00
// if (portListTop10 != null && portListTop10.size() > 0) {
// StringBuilder portStr = new StringBuilder();
if ( ! StringUtil . isEmpty ( portStr ) ) {
// 如果所有IP在最后一个时间点的count都为0, 则移除最后一个点
// 开始划分时间段,间隔5分钟
2018-12-23 20:46:19 +08:00
List < Date > dateRangeList = new ArrayList < Date > ( ) ;
Calendar calendar = Calendar . getInstance ( ) ;
calendar . setTime ( beginDate1 ) ;
2018-12-27 17:18:47 +08:00
while ( calendar . getTime ( ) . compareTo ( endDate1 ) < 0 ) {
2018-12-23 20:46:19 +08:00
dateRangeList . add ( calendar . getTime ( ) ) ;
2019-01-03 15:38:57 +08:00
calendar . add ( Calendar . MINUTE , Constants . TREND_TIME_INTERVAL ) ;
2018-12-23 20:46:19 +08:00
}
2018-12-24 22:18:12 +06:00
ArrayList < TrafficPortActiveStatistic > portInfoList = trafficPortActiveStatisticDao
. findTrafficPortActive ( beginDate , endDate , portStr . toString ( ) ) ;
// 存放每个IP, 每个时间点的总数
Map < String , List < Long > > portCountListMap = new HashMap < String , List < Long > > ( ) ;
int index = 0 ;
2018-12-23 20:46:19 +08:00
for ( int i = 0 ; i < dateRangeList . size ( ) ; i + + ) {
2018-12-24 22:18:12 +06:00
// 存放一个时间点中每个IP的总数
2018-12-23 20:46:19 +08:00
Map < String , Long > portCountMap = new HashMap < String , Long > ( ) ;
Date date = dateRangeList . get ( i ) ;
for ( int j = index ; j < portInfoList . size ( ) ; j + + ) {
TrafficPortActiveStatistic portInfo = portInfoList . get ( j ) ;
2018-12-24 22:18:12 +06:00
if ( portInfo . getStatTime ( ) ! = null ) {
2018-12-29 18:57:21 +08:00
if ( portInfo . getStatTime ( ) . compareTo ( date ) > = 0 & & ( i + 1 < dateRangeList . size ( ) ? portInfo . getStatTime ( ) . compareTo ( dateRangeList . get ( i + 1 ) ) < 0 : true ) ) {
2018-12-23 20:46:19 +08:00
Long num = portInfo . getSum ( ) ;
if ( portCountMap . containsKey ( portInfo . getPort ( ) ) ) {
2018-12-24 22:18:12 +06:00
num = num + portCountMap . get ( portInfo . getPort ( ) ) ;
2018-12-23 20:46:19 +08:00
}
portCountMap . put ( portInfo . getPort ( ) . toString ( ) , num ) ;
2018-12-24 22:18:12 +06:00
} else {
2018-12-23 20:46:19 +08:00
index = j ;
break ;
}
}
}
2018-12-24 22:18:12 +06:00
if ( portArray ! = null & & portArray . length > 0 ) { // 如果有传人参数,获取传人参数
for ( int m = 0 ; m < portArray . length ; m + + ) {
2018-12-23 20:46:19 +08:00
String port = portArray [ m ] . toString ( ) ;
2018-12-29 18:57:21 +08:00
List sumList = new ArrayList ( ) ;
sumList . add ( date . getTime ( ) ) ;
2018-12-23 20:46:19 +08:00
Long sum = 0l ;
if ( portCountMap . containsKey ( port ) ) {
2018-12-24 22:18:12 +06:00
sum = portCountMap . get ( port ) ;
2018-12-23 20:46:19 +08:00
}
2019-01-03 15:38:57 +08:00
sumList . add ( sum ) ;
2018-12-23 20:46:19 +08:00
if ( portCountListMap . containsKey ( port ) ) {
2019-01-03 15:38:57 +08:00
List list = portCountListMap . get ( port ) ;
list . add ( sumList ) ;
2018-12-24 22:18:12 +06:00
} else {
2019-01-03 15:38:57 +08:00
List list = new ArrayList ( ) ;
list . add ( sumList ) ;
2018-12-23 20:46:19 +08:00
portCountListMap . put ( port , list ) ;
}
}
2018-12-24 22:18:12 +06:00
} else if ( portListTop10 ! = null ) {
2018-12-23 20:46:19 +08:00
for ( LinkedHashMap map : portListTop10 ) {
String port = map . get ( " port " ) . toString ( ) ;
2019-01-03 15:38:57 +08:00
List sumList = new ArrayList ( ) ;
sumList . add ( date . getTime ( ) ) ;
2018-12-23 20:46:19 +08:00
Long sum = 0l ;
if ( portCountMap . containsKey ( port ) ) {
2018-12-24 22:18:12 +06:00
sum = portCountMap . get ( port ) ;
2018-12-23 20:46:19 +08:00
}
2019-01-03 15:38:57 +08:00
sumList . add ( sum ) ;
2018-12-23 20:46:19 +08:00
if ( portCountListMap . containsKey ( port ) ) {
2019-01-03 15:38:57 +08:00
List list = portCountListMap . get ( port ) ;
list . add ( sumList ) ;
2018-12-24 22:18:12 +06:00
} else {
2019-01-03 15:38:57 +08:00
List list = new ArrayList ( ) ;
list . add ( sumList ) ;
2018-12-23 20:46:19 +08:00
portCountListMap . put ( port , list ) ;
}
}
}
}
2018-12-24 22:18:12 +06:00
// 整合port sum time
2018-12-23 20:46:19 +08:00
Iterator iterator = portCountListMap . keySet ( ) . iterator ( ) ;
while ( iterator . hasNext ( ) ) {
2019-01-03 15:38:57 +08:00
String port = iterator . next ( ) + " " ;
2018-12-23 20:46:19 +08:00
Map trafficPortActiveMap = new HashMap ( ) ;
2019-01-03 15:38:57 +08:00
Long total = 0L ;
for ( Object obj : portCountListMap . get ( port ) ) {
List < Long > list = ( List ) obj ;
total + = list . get ( 1 ) ;
}
trafficPortActiveMap . put ( " port " , port ) ;
trafficPortActiveMap . put ( " result " , portCountListMap . get ( port ) ) ;
trafficPortActiveMap . put ( " sum " , total ) ;
2018-12-23 20:46:19 +08:00
listMap . add ( trafficPortActiveMap ) ;
}
}
return listMap ;
}
2018-12-25 16:49:09 +08:00
/ * *
* 根据指标 ( drop , loop , New Link , Close Link , Pass , Live Link ) 统计各业务的趋势
* @throws ParseException
* /
2019-01-03 15:38:57 +08:00
public Map trendTotalReport ( NtcConnNumReport ntcConnNumReport ) {
Map restMap = new HashMap ( ) ;
2018-12-25 16:49:09 +08:00
List < NtcConnNumReport > list = ntcTotalReportDao . trendTotalReport ( ntcConnNumReport ) ;
if ( list ! = null & & list . size ( ) > 0 ) {
//开始划分时间段,间隔5分钟
Date beginDate ;
Date endDate ;
try {
beginDate = DateUtils . strToDate ( ntcConnNumReport . getSearchReportStartTime ( ) , " yyyy-MM-dd HH:mm:ss " ) ;
endDate = DateUtils . strToDate ( ntcConnNumReport . getSearchReportEndTime ( ) , " yyyy-MM-dd HH:mm:ss " ) ;
} catch ( ParseException e ) {
// TODO Auto-generated catch block
throw new RestServiceException ( " searchReportStartTime或searchReportEndTime参数格式错误 " , RestBusinessCode . param_formate_error . getValue ( ) ) ;
}
List < Date > dateRangeList = new ArrayList < Date > ( ) ;
List < String > strDateRangeList = new ArrayList < String > ( ) ;
Calendar calendar = Calendar . getInstance ( ) ;
calendar . setTime ( beginDate ) ;
2018-12-29 18:57:21 +08:00
SimpleDateFormat sdf = new SimpleDateFormat ( " yyyy-MM-dd HH:mm:ss " ) ;
2018-12-27 17:18:47 +08:00
while ( calendar . getTime ( ) . compareTo ( endDate ) < 0 ) {
2018-12-25 16:49:09 +08:00
dateRangeList . add ( calendar . getTime ( ) ) ;
2019-01-03 15:38:57 +08:00
calendar . add ( Calendar . MINUTE , Constants . TREND_TIME_INTERVAL ) ;
2018-12-25 16:49:09 +08:00
}
int index = 0 ;
2019-01-03 15:38:57 +08:00
List sumList = new ArrayList ( ) ;
Long totalNum = 0L ;
2018-12-25 16:49:09 +08:00
for ( int i = 0 ; i < dateRangeList . size ( ) ; i + + ) {
//存放一个时间点中每个IP的总数
2019-01-03 15:38:57 +08:00
List tempList = new ArrayList ( ) ;
2018-12-25 16:49:09 +08:00
Map < String , Long > ipCountMap = new HashMap < String , Long > ( ) ;
Date date = dateRangeList . get ( i ) ;
Long sum = 0l ;
for ( int j = index ; j < list . size ( ) ; j + + ) {
NtcConnNumReport info = list . get ( j ) ;
if ( info . getReportTime ( ) ! = null ) {
2018-12-29 18:57:21 +08:00
if ( info . getReportTime ( ) . compareTo ( date ) > = 0 & & ( i + 1 < dateRangeList . size ( ) ? info . getReportTime ( ) . compareTo ( dateRangeList . get ( i + 1 ) ) < 0 : true ) ) {
2018-12-25 16:49:09 +08:00
sum = sum + info . getNum ( ) ;
} else {
index = j ;
break ;
}
}
}
2019-01-03 15:38:57 +08:00
totalNum + = sum ;
tempList . add ( date . getTime ( ) ) ;
tempList . add ( sum ) ;
sumList . add ( tempList ) ;
2018-12-25 16:49:09 +08:00
}
2019-01-03 15:38:57 +08:00
restMap . put ( " sum " , totalNum ) ;
restMap . put ( " result " , sumList ) ;
2018-12-25 16:49:09 +08:00
}
return restMap ;
}
2019-01-05 17:21:07 +08:00
public Map getAppTrend ( TrafficAppFocusStatistic entity ) {
List < TrafficAppFocusStatistic > appFocusList = new ArrayList < TrafficAppFocusStatistic > ( ) ;
appFocusList = trafficAppStatisticDao . getAppTrend ( entity ) ;
Map resultMap = new HashMap ( ) ;
if ( ! StringUtil . isEmpty ( appFocusList ) ) {
Date beginDate = DateUtils . parseDate ( entity . getSearchStartTime ( ) ) ;
Date endDate = DateUtils . parseDate ( entity . getSearchEndTime ( ) ) ;
List < Date > dateRangeList = new ArrayList < Date > ( ) ;
Calendar calendar = Calendar . getInstance ( ) ;
calendar . setTime ( beginDate ) ;
SimpleDateFormat sdf = new SimpleDateFormat ( " yyyy-MM-dd HH:mm:ss " ) ;
while ( calendar . getTime ( ) . compareTo ( endDate ) < 0 ) {
dateRangeList . add ( calendar . getTime ( ) ) ;
2019-01-05 18:02:57 +08:00
calendar . add ( Calendar . MINUTE , 1 ) ;
2019-01-05 17:21:07 +08:00
}
// 存放每个时间点的总数
Map < String , List < Long > > ipCountListMap = new HashMap < String , List < Long > > ( ) ;
int index = 0 ;
List resultSipList = new ArrayList ( ) ;
List resultDipList = new ArrayList ( ) ;
Long sipTotal = 0L ;
Long dipTotal = 0L ;
for ( int i = 0 ; i < dateRangeList . size ( ) ; i + + ) {
// 存放一个时间点中总数
List sipList = new ArrayList ( ) ;
List dipList = new ArrayList ( ) ;
Date date = dateRangeList . get ( i ) ;
Long sipNum = 0L ;
Long dipNum = 0L ;
for ( int j = index ; j < appFocusList . size ( ) ; j + + ) {
TrafficAppFocusStatistic info = appFocusList . get ( j ) ;
if ( info . getTime ( ) ! = null ) {
if ( info . getTime ( ) . compareTo ( date ) > = 0 & & ( i + 1 < dateRangeList . size ( ) ? info . getTime ( ) . compareTo ( dateRangeList . get ( i + 1 ) ) < 0 : true ) ) {
sipNum = sipNum + info . getSipNum ( ) ;
dipNum = dipNum + info . getDipNum ( ) ;
} else {
index = j ;
break ;
}
}
}
sipList . add ( date . getTime ( ) ) ;
sipList . add ( sipNum ) ;
resultSipList . add ( sipList ) ;
dipList . add ( date . getTime ( ) ) ;
dipList . add ( dipNum ) ;
resultDipList . add ( dipList ) ;
sipTotal + = sipNum ;
dipTotal + = dipNum ;
}
resultMap . put ( " sipResult " , resultSipList ) ;
resultMap . put ( " dipResult " , resultDipList ) ;
resultMap . put ( " sipSum " , sipTotal ) ;
resultMap . put ( " dipSum " , dipTotal ) ;
}
return resultMap ;
}
public List < AppConnRecordStatistic > appConnRecordTop100 ( AppConnRecordStatistic entity ) {
List < AppConnRecordStatistic > list = new ArrayList < AppConnRecordStatistic > ( ) ;
list = trafficAppStatisticDao . appConnRecordTop100 ( entity ) ;
return list ;
}
2018-07-13 19:39:04 +08:00
}