优化Traffic和IP top10趋势图统计功能

This commit is contained in:
zhangdongxu
2018-12-22 21:41:54 +08:00
parent 1ecac8aae8
commit 007e8e14bf
5 changed files with 206 additions and 218 deletions

View File

@@ -212,76 +212,15 @@ public class DashboardServiceController extends BaseRestController {
String[] transTypes=dashboardService.getFiledTypeByName("trans_type");
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
Map<String,List<HashMap>> resultMap=new HashMap<String,List<HashMap>>();
Map<String, Map> resultMap=new HashMap<String,Map>();
try {
if(StringUtils.isEmpty(beginDate)||StringUtils.isEmpty(endDate)) {
if(StringUtils.isEmpty(beginDate)&&StringUtils.isEmpty(endDate)) {
Calendar cal = Calendar. getInstance ();
cal.setTime(new Date());
endDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ).format(cal.getTime());//获取到完整的时间
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1);
beginDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ).format(cal.getTime());
}
String addrType=null;
Integer transType=null;
if(addrTypes!=null){
for(int i=0;i<addrTypes.length;i++){
addrType=addrTypes[i];
List<HashMap> resultList = dashboardService.getBandwidthTrans(addrType, transType,beginDate,endDate);
if (resultList!=null&&resultList.size() > 0) {
resultMap.put("ipv"+addrType+"Type1", resultList);
}
resultList = dashboardService.getBandwidthTrans2(addrType, transType,beginDate,endDate);
if (resultList!=null&&resultList.size() > 0) {
resultMap.put("ipv"+addrType+"Type2", resultList);
}
addrType=null;
}
}
if(transTypes!=null){
for(int i=0;i<transTypes.length;i++){
transType=Integer.valueOf(transTypes[i]);
List<HashMap> resultList = dashboardService.getBandwidthTrans(addrType, transType,beginDate,endDate);
if (resultList!=null&&resultList.size() > 0) {
resultMap.put("trans"+transType+"Type1", resultList);
}
resultList = dashboardService.getBandwidthTrans2(addrType, transType,beginDate,endDate);
if (resultList!=null&&resultList.size() > 0) {
resultMap.put("trans"+transType+"Type2", resultList);
}
transType=null;
}
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("带宽实时统计数据检索失败:"+e.getMessage());
logger.error("带宽实时统计数据检索失败:"+ExceptionUtil.getExceptionMsg(e));
if (e instanceof RestServiceException) {
throw new RestServiceException(auditLogThread, System.currentTimeMillis() - start,
"带宽实时统计数据检索失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
} else if (e instanceof ServiceRuntimeException) {
throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start,
"带宽实时统计数据检索失败:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode());
} else {
throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start,
"带宽实时统计数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "带宽实时统计数据检索成功",resultMap, 0);
}
/**
* 根据ip46,协议tcpudp查询带宽
*/
@RequestMapping(value = "trafficBandwidthTransFour", method = RequestMethod.GET)
@ApiOperation(value = "带宽根据ip46,协议tcp,udp查询详情", httpMethod = "GET", notes = "对应带宽根据IPv4,6,协议tcp,udp统计数据显示")
public Map<String,?> trafficBandwidthTransFour(String beginDate,String endDate,Model model, HttpServletRequest request, HttpServletResponse response) {
String[] addrTypes=dashboardService.getFiledTypeByName("addr_type");
String[] transTypes=dashboardService.getFiledTypeByName("trans_type");
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
Map<String, List<HashMap>> resultMap=new HashMap<String, List<HashMap>>();
try {
resultMap = dashboardService.getBandwidthTransEntrance(beginDate, endDate);
} catch (Exception e) {
@@ -499,7 +438,7 @@ public class DashboardServiceController extends BaseRestController {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<HashMap> list = new ArrayList<HashMap>();
List<Map> list = new ArrayList<Map>();
try {
Date begin = null;
Date end = null;
@@ -507,7 +446,7 @@ public class DashboardServiceController extends BaseRestController {
begin = DateUtils.parseDate(beginDate);
end = DateUtils.parseDate(endDate);
}
List<HashMap> ipActiveChart = dashboardService.ipActiveFiveMinute(begin, end);
List<Map> ipActiveChart = dashboardService.ipActiveFiveMinute(begin, end);
if (ipActiveChart != null && ipActiveChart.size() > 0) {
list = ipActiveChart;
}

View File

@@ -17,6 +17,8 @@ public interface NtcTotalReportDao {
List<Map> getTotalReportList(@Param("reportTime") Date reportTime);
List<Map> getNetFlowPortInfoNew(@Param("statTime") Date statTime);
List<TrafficTransStatistic> getBandwidthTrans(@Param("entranceId") Integer entranceId,@Param("beginDate") String beginDate,@Param("endDate") String endDate,@Param("addrType") String addrType,@Param("transType") Integer transType);
List<TrafficTransStatistic> getBandwidthTransIPVx(@Param("beginDate") String beginDate,@Param("endDate") String endDate);
List<TrafficTransStatistic> getBandwidthTransProtocol(@Param("beginDate") String beginDate,@Param("endDate") String endDate);
String getAddrType();
String getTransType();
String getEntranceId();

View File

@@ -39,10 +39,6 @@
SELECT IFNULL(SUM(c2s_byte_len),0) inoctets ,IFNULL(SUM(s2c_byte_len),0) outoctets FROM traffic_trans_statistic
where stat_time = (SELECT stat_time FROM traffic_trans_statistic WHERE entrance_id=2 ORDER BY stat_time DESC LIMIT 0,1) and entrance_id=2
) total_traffic
</select>
<!-- 获取近五分钟的带宽根据ip46协议 tcp,udp变化 -->
<!-- <select id="getBandwidthTrans" resultMap="BandwidthResultMap">
@@ -70,6 +66,24 @@
ORDER by time
</select> -->
<!-- 获取近一小时的带宽根据ip46协议 tcp,udp变化 -->
<select id="getBandwidthTransIPVx" resultMap="BandwidthResultMap">
select addr_type,trans_type,entrance_id,IFNULL((SUM(c2s_byte_len+s2c_byte_len)*8)/300/1024/1024/1024,0) gbps,IFNULL(SUM(c2s_pkt_num+s2c_pkt_num)/300,0) pps,IFNULL(SUM(link_num),0) linkNum, stat_time from traffic_trans_statistic
WHERE
<![CDATA[stat_id BETWEEN (select stat_id from traffic_trans_statistic where stat_time >= #{beginDate} order by stat_id limit 1)
and
(select stat_id from traffic_trans_statistic where stat_time < #{endDate} order by stat_id desc limit 1)
]]>
and addr_type in (4,6)
group by addr_type,stat_time ,entrance_id order by stat_time
</select>
<select id="getBandwidthTransProtocol" resultMap="BandwidthResultMap">
select addr_type,trans_type,entrance_id,IFNULL((SUM(c2s_byte_len+s2c_byte_len)*8)/300/1024/1024/1024,0) gbps,IFNULL(SUM(c2s_pkt_num+s2c_pkt_num)/300,0) pps,IFNULL(SUM(link_num),0) linkNum, stat_time from traffic_trans_statistic
WHERE stat_id BETWEEN
<![CDATA[(select stat_id from traffic_trans_statistic where stat_time >= #{beginDate} order by stat_id limit 1)
and (select stat_id from traffic_trans_statistic where stat_time < #{endDate} order by stat_id desc limit 1) ]]>
and trans_type in (6,17) group by trans_type,stat_time ,entrance_id order by stat_time
</select>
<select id="getBandwidthTrans" resultMap="BandwidthResultMap">
select IFNULL((SUM(c2s_byte_len+s2c_byte_len)*8)/300/1024/1024/1024,0) gbps,IFNULL(SUM(c2s_pkt_num+s2c_pkt_num)/300,0) pps,IFNULL(SUM(link_num),0) linkNum, stat_time time from traffic_trans_statistic
where <![CDATA[stat_time>=#{beginDate} and stat_time<=#{endDate} ]]>
@@ -82,14 +96,6 @@
and entrance_id=#{entranceId}
group by stat_time order by stat_time
</select>
<!-- 获取近一小时的带宽根据ip46协议 tcp,udp变化 -->
<select id="getBandwidthTrans2" resultMap="BandwidthResultMap">
select addr_type,trans_type,entrance_id,IFNULL((SUM(c2s_byte_len+s2c_byte_len)*8)/300/1024/1024/1024,0) gbps,IFNULL(SUM(c2s_pkt_num+s2c_pkt_num)/300,0) pps,IFNULL(SUM(link_num),0) linkNum, stat_time time from traffic_trans_statistic
where <![CDATA[stat_time<=#{endDate} and stat_time>=#{beginDate}]]>
and addr_type !=0
and trans_type!=0
group by stat_time,addr_type,trans_type order by stat_time
</select>
<select id="getAddrType" resultType="String">
SELECT GROUP_CONCAT(DISTINCT addr_type) FROM traffic_trans_statistic where addr_type!=0

View File

@@ -27,11 +27,19 @@
SELECT stat_time statTime FROM traffic_ip_active_statistic order by stat_time desc limit 1
</select>
<!-- IP流量统计五分钟TOp10-->
<select id="ipActiveChart" resultType="java.util.LinkedHashMap">
<!-- <select id="ipActiveChart" resultType="java.util.LinkedHashMap">
SELECT ip_addr ipAddr, SUM(c2s_byte_len+s2c_byte_len) linkNum FROM traffic_ip_active_statistic
WHERE
<![CDATA[ stat_time> #{beginDate} and stat_time<=#{endDate}]]>
GROUP BY ip_addr ORDER BY linkNum DESC limit 0,10
</select>-->
<select id="ipActiveChart" resultType="java.util.LinkedHashMap">
SELECT ip_addr ipAddr,SUM(c2s_byte_len + s2c_byte_len) linkNum FROM traffic_ip_active_statistic WHERE
stat_id BETWEEN
(select stat_id from traffic_ip_active_statistic where<![CDATA[ stat_time >= #{beginDate} order by stat_id limit 1)]]>
AND
(select stat_id from traffic_ip_active_statistic where<![CDATA[ stat_time < #{endDate} order by stat_id desc limit 1)]]>
GROUP BY ip_addr ORDER BY linkNum DESC LIMIT 0,10
</select>
<!-- IP流量统计一小时内每隔五分钟数据-->
@@ -47,10 +55,17 @@
on date_format(p.timestamp,'%Y-%m-%d %H:%i')=date_format(a.min5,'%Y-%m-%d %H:%i')
ORDER by time
</select> -->
<select id="ipActiveFiveMinute" resultMap="BaseResultMap">
<!--<select id="ipActiveFiveMinute" resultMap="BaseResultMap">
select SUM(c2s_byte_len+s2c_byte_len) count ,stat_time time from traffic_ip_active_statistic
WHERE ip_addr=#{ipAddr} and
<![CDATA[ stat_time> #{beginDate} and stat_time<=#{endDate} GROUP BY stat_time]]>
</select> -->
<select id="ipActiveFiveMinute" resultMap="BaseResultMap">
select ip_addr,SUM(c2s_byte_len+s2c_byte_len) count ,stat_time from traffic_ip_active_statistic
WHERE
<![CDATA[ip_addr in (${ipAddr}) and
stat_time>= #{beginDate} and stat_time<#{endDate} GROUP BY stat_time,ip_addr order by stat_time asc]]>
</select>
<!-- IP流量统计一小时-->
<select id="ipActiveOneHour" resultType="java.util.HashMap">

View File

@@ -11,6 +11,7 @@ import com.zdjizhi.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;
@@ -435,56 +436,78 @@ public class DashboardService extends BaseService {
/**
* 获取活跃IPtop10 的趋势图
*/
public List<HashMap> ipActiveFiveMinute(Date beginDate, Date endDate) {
ArrayList<HashMap> listMap = new ArrayList<HashMap>();
ArrayList<LinkedHashMap> ipListTop10 = trafficIpActiveStatisticDao.ipActiveChart(beginDate, endDate);
public List<Map> ipActiveFiveMinute(Date beginDate, Date endDate) {
List<Map> listMap = new ArrayList<Map>();
List<LinkedHashMap> ipListTop10 = trafficIpActiveStatisticDao.ipActiveChart(beginDate, endDate);
if (ipListTop10 != null && ipListTop10.size() > 0) {
StringBuilder ipStr = new StringBuilder();
for (LinkedHashMap map : ipListTop10) {
HashMap m1 = new HashMap();
String ipAddr = (String) map.get("ipAddr");
m1.put("ipAddr", ipAddr);
ArrayList<TrafficIpActiveStatistic> ipList = trafficIpActiveStatisticDao.ipActiveFiveMinute(ipAddr,
beginDate, endDate);
List timeList = new ArrayList();
List sumList1 = new ArrayList();
Map<String, Comparable> m = new HashMap<String, Comparable>();
int inter = 1000 * 60 * 5;// 间隔时间为五分钟
// 开始时间,结束时间 时间戳
Long b = dateToStamp(DateUtils.formatDateTime(beginDate));
Long e = dateToStamp(DateUtils.formatDateTime(endDate));
int num = 0;
Long pointTime = b;
while (pointTime < e) {
Map rm = new HashMap();
Long sum1 = 0l;
if (pointTime >= e) {
break; // 停止
}
for (TrafficIpActiveStatistic e1 : ipList) {
// 实际时间
String time = e1.getTime();
Long t = dateToStamp(time);
if (t >= pointTime && t < pointTime + inter) {
// 范围之内分到此pointTime组
sum1 = sum1 + e1.getCount();
ipStr.append("'"+(String) map.get("ipAddr")+"',");
}
if (!StringUtil.isEmpty(ipStr)&&ipStr.indexOf(",")>0) {
ipStr.deleteCharAt(ipStr.lastIndexOf(","));
}
//如果所有IP在最后一个时间点的count都为0则移除最后一个点
//开始划分时间段,间隔5分钟
List<Date> dateRangeList = new ArrayList<Date>();
List<String> strDateRangeList = new ArrayList<String>();
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());
strDateRangeList.add(sdf.format(calendar.getTime()));
calendar.add(Calendar.MINUTE, 5);
}
ArrayList<TrafficIpActiveStatistic> ipInfoList = trafficIpActiveStatisticDao.ipActiveFiveMinute(ipStr.toString(),
beginDate, endDate);
//存放每个IP每个时间点的总数
Map<String,List<Long>> ipCountListMap = new HashMap<String, List<Long>>();
int index=0;
for (int i = 0; i < dateRangeList.size(); i++) {
//存放一个时间点中每个IP的总数
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);
if (ipInfo.getStatTime()!=null){
if(ipInfo.getStatTime().compareTo(date)>=0&&(i+1<dateRangeList.size()&&ipInfo.getStatTime().compareTo(dateRangeList.get(i+1))<0)) {
Long num = ipInfo.getCount();
if (ipCountMap.containsKey(ipInfo.getIpAddr())) {
num=num+ipCountMap.get(ipInfo.getIpAddr());
}
ipCountMap.put(ipInfo.getIpAddr(), num);
}else{
index = j;
break;
}
}
// 在结束时间只有当值大于0时才记录数据防止折线降为0引起误会
if (pointTime >= e - inter && sum1 > 0) {
sumList1.add(sum1);
timeList.add(stampToDate(pointTime));
}
if (pointTime < e - inter) {
sumList1.add(sum1);
timeList.add(stampToDate(pointTime));
}
num = num + 1;
pointTime = b + inter * num;
}
m1.put("linkNum", sumList1);
m1.put("statTime", timeList);
listMap.add(m1);
for (LinkedHashMap map : ipListTop10) {
String ip = (String) map.get("ipAddr");
Long sum = 0l;
if (ipCountMap.containsKey(ip)) {
sum=ipCountMap.get(ip);
}
if (ipCountListMap.containsKey(ip)) {
ipCountListMap.get(ip).add(sum);
}else{
List<Long> list = new ArrayList<Long>();
list.add(sum);
ipCountListMap.put(ip, list);
}
}
}
//整合IP count time
Iterator iterator = ipCountListMap.keySet().iterator();
while (iterator.hasNext()) {
String ip = iterator.next()+"";
Map ipTrafficMap = new HashMap();
ipTrafficMap.put("ipAddr", ip);
ipTrafficMap.put("linkNum", ipCountListMap.get(ip));
ipTrafficMap.put("statTime", strDateRangeList);
listMap.add(ipTrafficMap);
}
}
return listMap;
@@ -1127,109 +1150,112 @@ public class DashboardService extends BaseService {
return fieldType == null ? null : fieldType.split(",");
}
public Map<String, List<HashMap>> getBandwidthTransEntrance(String beginDate, String endDate) {
long start = System.currentTimeMillis();
Map<String, List<TrafficTransStatistic>> listMap = new HashMap<String, List<TrafficTransStatistic>>();
List<TrafficTransStatistic> bandwidthList = new ArrayList<TrafficTransStatistic>();
bandwidthList = ntcTotalReportDao.getBandwidthTrans2(beginDate, endDate);
String[] addrTypes = getFiledTypeByName("addr_type");
String[] transTypes = getFiledTypeByName("trans_type");
String[] entranceIds = getFiledTypeByName("entrance_id");
for (String entranceId : entranceIds) {
for (String addrType : addrTypes) {
listMap.put("ipv" + addrType + "Type" + entranceId, new ArrayList<TrafficTransStatistic>());
public Map<String, Map> getBandwidthTransEntrance(String beginDate, String endDate) throws ParseException {
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>();
if((!StringUtil.isEmpty(bandwidthListIPvx)&&bandwidthListIPvx.size()>0)||(!StringUtil.isEmpty(bandwidthListProtocol)&&bandwidthListProtocol.size()>0)){
//划分时间段
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date startTime = sdf.parse(beginDate);
Date endTime = sdf.parse(endDate);
List<Date> dateRangeList = new ArrayList<Date>();
List<String> strDateRangeList = new ArrayList<String>();
Calendar calendar = Calendar.getInstance();
calendar.setTime(startTime);
while (calendar.getTime().compareTo(endTime)<=0) {
dateRangeList.add(calendar.getTime());
strDateRangeList.add(sdf.format(calendar.getTime()));
calendar.add(Calendar.MINUTE, 5);
}
}
for (String entranceId : entranceIds) {
for (String transType : transTypes) {
listMap.put("trans" + transType + "Type" + entranceId, new ArrayList<TrafficTransStatistic>());
}
}
for (TrafficTransStatistic tts : bandwidthList) {
String addrType = tts.getAddrType();
Integer entranceId = tts.getEntranceId();
Integer transType = tts.getTransType();
String key1 = "ipv" + addrType + "Type" + entranceId;
String key2 = "trans" + transType + "Type" + entranceId;
listMap.get(key1).add(tts);
listMap.get(key2).add(tts);
}
Map<String, List<HashMap>> resultMap = new HashMap<String, List<HashMap>>();
Set<Entry<String, List<TrafficTransStatistic>>> entrySet = listMap.entrySet();
for (Entry<String, List<TrafficTransStatistic>> entry : entrySet) {
String key = entry.getKey();
String entranceId = key.substring(key.length() - 1);
List<TrafficTransStatistic> value = entry.getValue();
HashMap newData = getNewData(beginDate, endDate, value);
newData.put("entranceId", entranceId);
ArrayList<HashMap> resultList = new ArrayList<HashMap>();
resultList.add(newData);
resultMap.put(key, resultList);
}
return resultMap;
}
private HashMap getNewData(String beginDate, String endDate, List<TrafficTransStatistic> bandwidthList) {
HashMap resulMap = new HashMap();
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) {
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();
sumP = sumP + tt.getPps();
sumG = sumG + tt.getGbps();
String[] addrTypes = getFiledTypeByName("addr_type");
String[] transTypes = getFiledTypeByName("trans_type");
String[] entranceIds = getFiledTypeByName("entrance_id");
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
for (String entranceId : entranceIds) {
for (String addrType : addrTypes) {
listMap.put("ipv" + addrType + "Type" + entranceId, new ArrayList<TrafficTransStatistic>());
}
}
// 在结束时间只有当值大于0时才记录数据防止折线降为0引起误会
if (pointTime >= e - inter && sumL > 0) {
linkList.add(sumL);
for (String entranceId : entranceIds) {
for (String transType : transTypes) {
listMap.put("trans" + transType + "Type" + entranceId, new ArrayList<TrafficTransStatistic>());
}
}
if (pointTime >= e - inter && sumP > 0) {
ppsList.add(sumP);
//按区域和类型提取数据到列表中
for (TrafficTransStatistic tts : bandwidthListIPvx) {
String addrType = tts.getAddrType();
Integer entranceId = tts.getEntranceId();
Integer transType = tts.getTransType();
String key = "ipv" + addrType + "Type" + entranceId;
listMap.get(key).add(tts);
}
if (pointTime >= e - inter && sumG > 0) {
gbpsList.add(sumG);
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);
}
if (pointTime >= e - inter && (sumL > 0 || sumG > 0 || sumP > 0)) {
timeList.add(stampToDate(pointTime));
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();
resultMap.put(key, getNewData(dateRangeList,strDateRangeList,value));
}
if (pointTime < e - inter) {
timeList.add(stampToDate(pointTime));
linkList.add(sumL);
gbpsList.add(sumG);
ppsList.add(sumP);
}
num = num + 1;
pointTime = b + inter * num;
return resultMap;
}
resulMap.put("linkNum", linkList);
resulMap.put("gbps", gbpsList);
resulMap.put("pps", ppsList);
resulMap.put("statTime", timeList);
}
return null;
}
private Map getNewData(List<Date> dateRangeList,List<String> timeList, List<TrafficTransStatistic> bandwidthList) {
Map<String,List> resulMap = new HashMap<String,List>();
int index = 0;
for (int i = 0; i < dateRangeList.size(); i++) {
Date date = dateRangeList.get(i);
Map<String, Long> countMap = new HashMap<String, Long>();
Long linkNum = 0L;
Long ppsNum = 0L;
Long gbpsNum = 0L;
for (int j = index; j < bandwidthList.size(); j++) {
TrafficTransStatistic info = bandwidthList.get(j);
if (info.getStatTime()!=null){
if(info.getStatTime().compareTo(date)>=0&&(i+1<dateRangeList.size()&&info.getStatTime().compareTo(dateRangeList.get(i+1))<0)) {
linkNum =info.getLinkNum() +linkNum;
ppsNum = info.getPps()+ppsNum;
gbpsNum = info.getGbps()+gbpsNum;
}else{
index = j;
break;
}
}
}
countMap.put("linkNum", linkNum);
countMap.put("pps", ppsNum);
countMap.put("gbps", gbpsNum);
Iterator iterator = countMap.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next()+"";
if (resulMap.containsKey(key)) {
resulMap.get(key).add(countMap.get(key));
}else {
List<Long> list = new ArrayList<Long>();
list.add(countMap.get(key));
resulMap.put(key, list);
}
}
}
resulMap.put("statTime", timeList);
return resulMap;
}