修改v1版本流量统计带宽查询接口从clickhouse中查询

This commit is contained in:
renkaige
2019-05-20 14:57:19 +08:00
parent ab4ea8fa69
commit d66892e159
8 changed files with 615 additions and 5 deletions

View File

@@ -0,0 +1,38 @@
package com.nis.domain.restful.dashboard;
import java.io.Serializable;
public abstract class TrafficEntity<T> implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
protected String beginDate;// 开始时间
protected String endDate;// 结束时间
protected Integer searchBusinessType = 1;// 1:五分钟,2:小时,3:天,4:月,5:年
public String getBeginDate() {
return beginDate;
}
public void setBeginDate(String beginDate) {
this.beginDate = beginDate;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
public Integer getSearchBusinessType() {
return searchBusinessType;
}
public void setSearchBusinessType(Integer searchBusinessType) {
this.searchBusinessType = searchBusinessType;
}
}

View File

@@ -0,0 +1,82 @@
package com.nis.domain.restful.dashboard;
import java.util.Date;
/**
* 从clickhouse中查询流量统计相关结果映射的bean
* @author RenKaiGe
*
*/
public class TrafficTransStatisticCK extends TrafficEntity<TrafficTransStatisticCK> {
/**
*
*/
private static final long serialVersionUID = 1L;
private Integer addrType;
private Integer transType;
private Integer entranceId;
private Date statTime;
private Double num;
private Integer searchDirection;//方向
private Integer searchQuotaType;//1:bps,2:pps,3:linknum
public Integer getAddrType() {
return addrType;
}
public void setAddrType(Integer addrType) {
this.addrType = addrType;
}
public Integer getTransType() {
return transType;
}
public void setTransType(Integer transType) {
this.transType = transType;
}
public Integer getEntranceId() {
return entranceId;
}
public void setEntranceId(Integer entranceId) {
this.entranceId = entranceId;
}
public Date getStatTime() {
return statTime;
}
public void setStatTime(Date statTime) {
this.statTime = statTime;
}
public Double getNum() {
return num;
}
public void setNum(Double num) {
this.num = num;
}
public Integer getSearchDirection() {
return searchDirection;
}
public void setSearchDirection(Integer searchDirection) {
this.searchDirection = searchDirection;
}
public Integer getSearchQuotaType() {
return searchQuotaType;
}
public void setSearchQuotaType(Integer searchQuotaType) {
this.searchQuotaType = searchQuotaType;
}
}

View File

@@ -4,11 +4,12 @@
package com.nis.util;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.time.DateFormatUtils;
@@ -380,4 +381,171 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
String dayAfter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(c.getTime());
return dayAfter;
}
/**
* 获取某个时间的最近五分钟,strDate和numDate传入一个即可
*
* @param date 格式yyyy-MM-dd HH:mm:ss
* @param numDate 时间戳
* @return
*/
public static Calendar getRecentFiveMinute(String strDate, Long numDate) {
Calendar instance = Calendar.getInstance();
if (strDate != null) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
instance.setTime(sdf.parse(strDate));
} catch (ParseException e) {
e.printStackTrace();
}
} else if (numDate != null) {
instance.setTimeInMillis(numDate);
}
int oldMinute = instance.get(Calendar.MINUTE);
char[] charArray = String.valueOf(oldMinute).toCharArray();
if (charArray[charArray.length - 1] - '0' >= 5) {
charArray[charArray.length - 1] = '5';
} else {
charArray[charArray.length - 1] = '0';
}
instance.set(Calendar.SECOND, 0);
instance.set(Calendar.MINUTE, Integer.valueOf(String.valueOf(charArray)));
return instance;
}
/**
* 获取两个时间的五分钟间隔,小时间隔,天间隔,月间隔
*
* @param beginDate 开始时间(包含开始时间)
* @param endDate 结束时间(不包含结束时间)
* @param type 0:五分钟间隔,1:小时间隔,2:天间隔,3:月间隔,4:年间隔
* @return 返回时间戳集合
*/
public static List<Long> getTimeInterval(String beginDate, String endDate, int type) {
Calendar beginCal = getRecentFiveMinute(beginDate,null);// 将时间转为最近的五分钟
Calendar endCal = getRecentFiveMinute(endDate,null);
List<Long> list = new ArrayList<>();
boolean bool = true;
switch (type) {
case 1:// 获取小时间隔
beginCal.set(Calendar.MINUTE, 0);
beginCal.set(Calendar.HOUR_OF_DAY, beginCal.get(Calendar.HOUR_OF_DAY));
endCal.set(Calendar.MINUTE, 0);
endCal.set(Calendar.HOUR_OF_DAY, endCal.get(Calendar.HOUR_OF_DAY));
break;
case 2:// 获取天间隔
beginCal.set(Calendar.MINUTE, 0);
beginCal.set(Calendar.HOUR_OF_DAY, 0);
beginCal.set(Calendar.DAY_OF_MONTH, beginCal.get(Calendar.DAY_OF_MONTH));
endCal.set(Calendar.MINUTE, 0);
endCal.set(Calendar.HOUR_OF_DAY, 0);
endCal.set(Calendar.DAY_OF_MONTH, endCal.get(Calendar.DAY_OF_MONTH));
break;
case 3:// 获取月间隔
beginCal.set(Calendar.MINUTE, 0);
beginCal.set(Calendar.HOUR_OF_DAY, 0);
beginCal.set(Calendar.DAY_OF_MONTH, 1);
beginCal.set(Calendar.MONTH, beginCal.get(Calendar.MONTH));
endCal.set(Calendar.MINUTE, 0);
endCal.set(Calendar.HOUR_OF_DAY, 0);
endCal.set(Calendar.DAY_OF_MONTH, 1);
endCal.set(Calendar.MONTH, endCal.get(Calendar.MONTH));
break;
case 4:// 获取年间隔
beginCal.set(Calendar.MINUTE, 0);
beginCal.set(Calendar.HOUR_OF_DAY, 0);
beginCal.set(Calendar.DAY_OF_MONTH, 1);
beginCal.set(Calendar.MONTH, 0);
beginCal.set(Calendar.YEAR, beginCal.get(Calendar.YEAR));
endCal.set(Calendar.MINUTE, 0);
endCal.set(Calendar.HOUR_OF_DAY, 0);
endCal.set(Calendar.DAY_OF_MONTH, 1);
endCal.set(Calendar.MONTH, 0);
endCal.set(Calendar.YEAR, endCal.get(Calendar.YEAR));
break;
}
list.add(beginCal.getTimeInMillis());
long endTime = endCal.getTimeInMillis();
while (bool) {
switch (type) {
case 1:// 获取小时间隔
beginCal.add(Calendar.HOUR_OF_DAY, 1);
break;
case 2:// 获取天间隔
beginCal.add(Calendar.DAY_OF_MONTH, 1);
break;
case 3:// 获取月间隔
beginCal.add(Calendar.MONTH, 1);
break;
case 4:// 获取年间隔
beginCal.add(Calendar.YEAR, 1);
break;
default:// 默认获取五分钟间隔
beginCal.add(Calendar.MINUTE, 5);
}
long timeInMillis = beginCal.getTimeInMillis();
if (timeInMillis < endTime) {
list.add(timeInMillis);
} else {
bool = false;
}
}
return list;
}
/**
* 获取一个时间对应的小时,天,月,年等粒度
*
* @param time 需要转化的时间
* @param type 0:五分钟粒度,1:小时粒度,2:天粒度,3:月粒度,4:年粒度
* @return
*/
public static Long getTimeByType(Long time, int type) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
switch (type) {
case 0:// 获取小时间隔
calendar=getRecentFiveMinute(null,time);
break;
case 1:// 获取小时间隔
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY));
break;
case 2:// 获取天间隔
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH));
break;
case 3:// 获取月间隔
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH));
break;
case 4:// 获取年间隔
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.MONTH, 0);
calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR));
break;
}
return calendar.getTimeInMillis();
}
}

View File

@@ -195,7 +195,7 @@ public class DashboardServiceController extends BaseRestController {
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "带宽实时统计数据检索成功", list, 0);
}
/**
* 根据ip46,协议tcpudp查询带宽
*/
@@ -207,6 +207,53 @@ public class DashboardServiceController extends BaseRestController {
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
Map resultMap = new HashMap();
try {
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());
}
CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_B);
resultMap = dashboardService.getBandwidthTransByQuoTaType(beginDate, endDate, searchQuotaType,
searchDirection);
} 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());
}
} finally {
CustomerContextHolder.clearCustomerType();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "带宽实时统计数据检索成功",
resultMap, 0);
}
/**
* 根据ip46,协议tcpudp查询带宽
*/
@RequestMapping(value = "trafficBandwidthTransThreeOld", method = RequestMethod.GET)
@ApiOperation(value = "带宽根据ip46,协议tcp,udp查询详情", httpMethod = "GET", notes = "对应带宽根据IPv4,6,协议tcp,udp统计数据显示")
public Map<String, ?> trafficBandwidthTransThreeOld(String beginDate, String endDate, String searchQuotaType,
Model model, Integer searchDirection, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
Map resultMap = new HashMap();
try {
if (StringUtils.isEmpty(beginDate) && StringUtils.isEmpty(endDate)) {
Calendar cal = Calendar.getInstance();
@@ -235,6 +282,7 @@ public class DashboardServiceController extends BaseRestController {
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "带宽实时统计数据检索成功",
resultMap, 0);
}
/**
* 流量统计活跃端口统计

View File

@@ -19,6 +19,7 @@ import com.nis.domain.restful.NtcTagReport;
import com.nis.domain.restful.NtcURLIpReport;
import com.nis.domain.restful.dashboard.NtcTotalReport;
import com.nis.domain.restful.dashboard.TrafficTransStatistic;
import com.nis.domain.restful.dashboard.TrafficTransStatisticCK;
/**
*
@@ -60,7 +61,11 @@ public interface TrafficReportDao extends CrudDao {
void truncateNtcIpRange();
List<TrafficTransStatisticCK> getBandwidthBpsFromCk(TrafficTransStatisticCK trafficTransStatisticCK);
List<TrafficTransStatisticCK> getBandwidthPpsFromCk(TrafficTransStatisticCK trafficTransStatisticCK);
List<TrafficTransStatisticCK> getBandwidthLinkNumFromCk(TrafficTransStatisticCK trafficTransStatisticCK);
NtcTotalReport getMaxReportTime();
Map getMaxStatTime();

View File

@@ -103,6 +103,18 @@
<result column="desc_detail" jdbcType="VARCHAR" property="desc" />
</resultMap>
<resultMap id="TrafficTransStatisticCKResultMap"
type="com.nis.domain.restful.dashboard.TrafficTransStatisticCK">
<result column="addr_type" jdbcType="INTEGER"
property="addrType" />
<result column="trans_type" jdbcType="INTEGER"
property="transType" />
<result column="entrance_id" jdbcType="INTEGER"
property="entranceId" />
<result column="num" jdbcType="DOUBLE" property="num" />
<result column="stat_time" jdbcType="TIMESTAMP"
property="statTime" />
</resultMap>
<sql id="commonPorperty">
SERVICE,SUM,REPORT_TIME
@@ -987,4 +999,112 @@
and entrance_id=#{entranceId}
group by report_time order by report_time
</select>
<select id="getBandwidthBpsFromCk"
resultMap="TrafficTransStatisticCKResultMap">
select
(SUM(c2s_byte_len + s2c_byte_len)* 8)/ 300 / 1024 / 1024 / 1024 num,
toStartOfFiveMinute(stat_time) stat_time,
addr_type,
trans_type,
entrance_id
from
ntc_network_traffic_stat
where
<![CDATA[stat_time>=#{beginDate} and stat_time<#{endDate} ]]>
<if test="searchDirection != null">
and direction=#{searchDirection}
</if>
and addr_type in('4',
'6')
and entrance_id in (1,
2)
and trans_type in(6,
17)
group by
stat_time,
addr_type,
trans_type,
entrance_id
order by
stat_time,
addr_type,
trans_type,
entrance_id
</select>
<select id="getBandwidthPpsFromCk"
resultMap="TrafficTransStatisticCKResultMap">
select
SUM(c2s_pkt_num + s2c_pkt_num)/ 300 num,
toStartOfFiveMinute(stat_time) stat_time,
addr_type,
trans_type,
entrance_id
from
ntc_network_traffic_stat
where
<![CDATA[stat_time>=#{beginDate} and stat_time<#{endDate} ]]>
<if test="searchDirection != null">
and direction=#{searchDirection}
</if>
and addr_type in('4',
'6')
and entrance_id in (1,
2)
and trans_type in(6,
17)
group by
stat_time,
addr_type,
trans_type,
entrance_id
order by
stat_time,
addr_type,
trans_type,
entrance_id
</select>
<select id="getBandwidthLinkNumFromCk"
resultMap="TrafficTransStatisticCKResultMap">
select
SUM(link_num) num,
toStartOfFiveMinute(stat_time) stat_time,
addr_type,
trans_type,
entrance_id
from
ntc_network_traffic_stat
where
<![CDATA[stat_time>=#{beginDate} and stat_time<#{endDate} ]]>
<if test="searchDirection != null">
and direction=#{searchDirection}
</if>
and addr_type in('4',
'6')
and entrance_id in (1,
2)
and trans_type in(6,
17)
group by
stat_time,
addr_type,
trans_type,
entrance_id
order by
stat_time,
addr_type,
trans_type,
entrance_id
</select>
</mapper>

View File

@@ -27,8 +27,8 @@ import com.nis.domain.restful.NtcEntranceReport;
import com.nis.domain.restful.dashboard.AppConnRecordStatistic;
import com.nis.domain.restful.dashboard.NtcTotalReport;
import com.nis.domain.restful.dashboard.SysDeviceInfo;
import com.nis.domain.restful.dashboard.TrafficAppFocusStatistic;
import com.nis.domain.restful.dashboard.TrafficAppBpsStatistic;
import com.nis.domain.restful.dashboard.TrafficAppFocusStatistic;
import com.nis.domain.restful.dashboard.TrafficAppPpsStatistic;
import com.nis.domain.restful.dashboard.TrafficAppStatistic;
import com.nis.domain.restful.dashboard.TrafficAsnStatistic;
@@ -37,6 +37,7 @@ 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.TrafficTransStatisticCK;
import com.nis.domain.restful.dashboard.TrafficUaStatistic;
import com.nis.restful.RestBusinessCode;
import com.nis.restful.RestServiceException;
@@ -76,6 +77,8 @@ public class DashboardService extends BaseService {
public TrafficPortActiveStatisticDao trafficPortActiveStatisticDao;
@Autowired
private IspInfoDao ispInfoDao;
@Autowired
protected TrafficReportService trafficReportService;
// ip地址类型
private final String[] addrTypes = { "4", "6" };
// tcp udp
@@ -1300,6 +1303,21 @@ public class DashboardService extends BaseService {
}
return fieldType == null ? null : fieldType.split(",");
}
public Map<?, ?> getBandwidthTransByQuoTaType(String beginDate, String endDate, String searchQuotaType,
Integer searchDirection) {
TrafficTransStatisticCK trafficTransStatisticCK = new TrafficTransStatisticCK();
trafficTransStatisticCK.setSearchBusinessType(1);
trafficTransStatisticCK.setBeginDate(beginDate);
trafficTransStatisticCK.setEndDate(endDate);
if (searchQuotaType.toLowerCase().equals("gbps")) {
trafficTransStatisticCK.setSearchQuotaType(1);
} else if (searchQuotaType.toLowerCase().equals("pps")) {
trafficTransStatisticCK.setSearchQuotaType(2);
} else if (searchQuotaType.toLowerCase().equals("linknumber")) {
trafficTransStatisticCK.setSearchQuotaType(3);
}
return trafficReportService.getBandwidthTransByQuoTaType(trafficTransStatisticCK);
}
public Map<String, Map> getBandwidthTransEntrance(String beginDate, String endDate, String searchQuotaType,
Integer searchDirection) throws ParseException {

View File

@@ -6,8 +6,11 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -15,8 +18,9 @@ import org.springframework.stereotype.Service;
import com.nis.domain.Page;
import com.nis.domain.restful.NtcRadiusReport;
import com.nis.domain.restful.dashboard.TrafficTransStatistic;
import com.nis.domain.restful.dashboard.TrafficTransStatisticCK;
import com.nis.util.DateUtils;
import com.nis.web.dao.TrafficReportDao;
import com.nis.web.dao.dashboard.NtcTotalReportDao;
import com.nis.web.service.BaseLogService;
@Service
@@ -87,6 +91,133 @@ public class TrafficReportService extends BaseLogService {
return listMap;
}
/**
* 查询bps/pps/linnum在ip46,tcp,udp的统计数据
*
* @param beginDate
* @param endDate
* @param searchQuotaType bps,pps,linknum
* @param searchDirection
* @return
*/
public Map<?, ?> getBandwidthTransByQuoTaType(TrafficTransStatisticCK trafficTransStatisticCK) {
List<TrafficTransStatisticCK> list = null;
List<Long> timeList = null;
Integer searchBusinessType = trafficTransStatisticCK.getSearchBusinessType();
if (searchBusinessType == 1) {
timeList = DateUtils.getTimeInterval(trafficTransStatisticCK.getBeginDate(),
trafficTransStatisticCK.getEndDate(), 0);
} else if (searchBusinessType == 2) {
timeList = DateUtils.getTimeInterval(trafficTransStatisticCK.getBeginDate(),
trafficTransStatisticCK.getEndDate(), 1);
} else if (searchBusinessType == 3) {
timeList = DateUtils.getTimeInterval(trafficTransStatisticCK.getBeginDate(),
trafficTransStatisticCK.getEndDate(), 2);
} else if (searchBusinessType == 4) {
timeList = DateUtils.getTimeInterval(trafficTransStatisticCK.getBeginDate(),
trafficTransStatisticCK.getEndDate(), 3);
} else if (searchBusinessType == 5) {
timeList = DateUtils.getTimeInterval(trafficTransStatisticCK.getBeginDate(),
trafficTransStatisticCK.getEndDate(), 4);
}
if (trafficTransStatisticCK.getSearchQuotaType() == 1) {
list = trafficReportDao.getBandwidthBpsFromCk(trafficTransStatisticCK);
} else if (trafficTransStatisticCK.getSearchQuotaType() == 2) {
list = trafficReportDao.getBandwidthPpsFromCk(trafficTransStatisticCK);
} else if (trafficTransStatisticCK.getSearchQuotaType() == 3) {
list = trafficReportDao.getBandwidthLinkNumFromCk(trafficTransStatisticCK);
}
Map<?, ?> map = convertData2List(list, timeList, searchBusinessType);
return map;
}
private Map<?, ?> convertData2List(List<TrafficTransStatisticCK> list, List<Long> timeList,
Integer searchBusinessType) {
Map<String, List<TrafficTransStatisticCK>> mapList = new HashMap<>();
Map<String, Map<String, Object>> map = new HashMap<>();
if (list != null) {
Set<String> dataKey = new HashSet<>();//无论有没有数据都要组装这几个json,界面需要这几个数据
dataKey.add("ipv4Type1");//ip只有4,6两种,协议只有tcp和udp,这里都写死了
dataKey.add("ipv4Type2");
dataKey.add("ipv6Type1");
dataKey.add("ipv6Type2");
dataKey.add("trans6Type1");
dataKey.add("trans6Type2");
dataKey.add("trans17Type1");
dataKey.add("trans17Type2");
for (TrafficTransStatisticCK trafficTransStatisticCK : list) {
Integer entranceId = trafficTransStatisticCK.getEntranceId();
Integer addrType = trafficTransStatisticCK.getAddrType();
Integer transType = trafficTransStatisticCK.getTransType();
String addrAndEntrKey = "ipv" + addrType + "Type" + entranceId;
String transAndEntrKey = "trans" + transType + "Type" + entranceId;
if (mapList.containsKey(addrAndEntrKey)) {
mapList.get(addrAndEntrKey).add(trafficTransStatisticCK);
} else {
List<TrafficTransStatisticCK> transList = new ArrayList<>();
transList.add(trafficTransStatisticCK);
mapList.put(addrAndEntrKey, transList);
}
if (mapList.containsKey(transAndEntrKey)) {
mapList.get(transAndEntrKey).add(trafficTransStatisticCK);
} else {
List<TrafficTransStatisticCK> transList = new ArrayList<>();
transList.add(trafficTransStatisticCK);
mapList.put(transAndEntrKey, transList);
}
}
for (String key : dataKey) {//无论这8种key是否都查询出了数据,都要给界面提供每个时间点的数据
Map<Long, Long> timeAndNum = new TreeMap<>();
Long count = 0l;
for (Long time : timeList) {
long num = 0l;
List<TrafficTransStatisticCK> list2 = mapList.get(key);
if (list2 != null && list2.size() > 0) {
for (TrafficTransStatisticCK trafficTransStatisticCK : list2) {
long transTime = trafficTransStatisticCK.getStatTime().getTime();
if (searchBusinessType == 1) {// 五分钟不需要转换了,时间已经是五分钟的格式了
// transTime = DateUtils.getTimeByType(transTime, 0);//
} else if (searchBusinessType == 2) {
transTime = DateUtils.getTimeByType(transTime, 1);
} else if (searchBusinessType == 3) {
transTime = DateUtils.getTimeByType(transTime, 2);
} else if (searchBusinessType == 4) {
transTime = DateUtils.getTimeByType(transTime, 3);
} else if (searchBusinessType == 5) {
transTime = DateUtils.getTimeByType(transTime, 4);
}
if (transTime == time) {
num += trafficTransStatisticCK.getNum().longValue();
count += trafficTransStatisticCK.getNum().longValue();
}
}
}
timeAndNum.put(time, num);
}
Map<String, Object> resultMap = new HashMap<>();
List<List<Long>> restList = new ArrayList<List<Long>>();
for (Long timeKey : timeAndNum.keySet()) {
List<Long> dataList = new ArrayList<>();
dataList.add(timeKey);
dataList.add(timeAndNum.get(timeKey));
restList.add(dataList);
}
resultMap.put("result", restList);
resultMap.put("sum", count);
map.put(key, resultMap);
}
}
return map;
}
/**
* 根据ip46,协议tcpudp查询带宽