1.增加了 地域流量,配置日志,丢弃量接口

2.增加了一个时间处理的工具类
This commit is contained in:
lihaochen
2018-12-10 17:55:36 +08:00
parent feb178ef2a
commit 067bc29ceb
8 changed files with 949 additions and 0 deletions

View File

@@ -0,0 +1,107 @@
package com.nis.domain.restful;
import java.io.Serializable;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.nis.util.JsonDateSerializer;
import com.wordnik.swagger.annotations.ApiModel;
import com.wordnik.swagger.annotations.ApiModelProperty;
/**
* @description 配置日志TOP统计API
* @author dell
* @date 2018年12月5日11:22:21
*/
@ApiModel(value = "配置日志对象", description = "用来封装配置日志")
public class CfgLogInfo implements Serializable {
/**
*
*/
private static final long serialVersionUID = -6058402409885962868L;
@JsonInclude(value = Include.NON_NULL)
@ApiModelProperty(value = "业务码")
private String serviceCode;// 业务码
@JsonInclude(value = Include.NON_NULL)
@ApiModelProperty(value = "业务中文名称")
private String serviceNameZh;// 业务中文名称
@JsonInclude(value = Include.NON_NULL)
@ApiModelProperty(value = "业务英文名称")
private String serviceNameEn;// 业务英文名称
@JsonInclude(value = Include.NON_NULL)
@ApiModelProperty(value = "业务俄文名称")
private String serviceNameRu;// 业务俄文名称
@JsonInclude(value = Include.NON_NULL)
@ApiModelProperty(value = "日志量")
private long sum;// 日志量
@JsonInclude(value = Include.NON_NULL)
@ApiModelProperty(value = "统计时间")
private Date reportTime;// 五分钟统计时间
public String getServiceCode() {
return serviceCode;
}
public void setServiceCode(String serviceCode) {
this.serviceCode = serviceCode;
}
public String getServiceNameZh() {
return serviceNameZh;
}
public void setServiceNameZh(String serviceNameZh) {
this.serviceNameZh = serviceNameZh;
}
public String getServiceNameEn() {
return serviceNameEn;
}
public void setServiceNameEn(String serviceNameEn) {
this.serviceNameEn = serviceNameEn;
}
public String getServiceNameRu() {
return serviceNameRu;
}
public void setServiceNameRu(String serviceNameRu) {
this.serviceNameRu = serviceNameRu;
}
public long getSum() {
return sum;
}
public void setSum(long sum) {
this.sum = sum;
}
@JsonSerialize(using = JsonDateSerializer.class)
public Date getReportTime() {
return reportTime;
}
public void setReportTime(Date reportTime) {
this.reportTime = reportTime;
}
@Override
public String toString() {
return "CfgLogInfo [serviceCode=" + serviceCode + ", serviceNameZh=" + serviceNameZh + ", serviceNameEn="
+ serviceNameEn + ", serviceNameRu=" + serviceNameRu + ", sum=" + sum + ", reportTime=" + reportTime
+ "]";
}
}

View File

@@ -0,0 +1,69 @@
package com.nis.domain.restful;
import java.io.Serializable;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.nis.util.JsonDateSerializer;
import com.wordnik.swagger.annotations.ApiModel;
import com.wordnik.swagger.annotations.ApiModelProperty;
/**
* @description 丢弃量统计API
* @author dell
* @date 2018年12月5日11:22:21
*/
@ApiModel(value = "丢弃量对象", description = "用来封装丢弃量")
public class DropInfo implements Serializable {
/**
*
*/
private static final long serialVersionUID = -6058402409885962868L;
@JsonInclude(value = Include.NON_NULL)
@ApiModelProperty(value = "动作")
private String label;// 动作
@JsonInclude(value = Include.NON_NULL)
@ApiModelProperty(value = "接收字节数")
private long sum;// 接收字节数
@JsonInclude()
@ApiModelProperty(value = "统计时间")
private Date reportTime;// 五分钟统计时间
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public long getSum() {
return sum;
}
public void setSum(long sum) {
this.sum = sum;
}
@JsonSerialize(using = JsonDateSerializer.class)
public Date getReportTime() {
return reportTime;
}
public void setReportTime(Date reportTime) {
this.reportTime = reportTime;
}
@Override
public String toString() {
return "DropInfo [label=" + label + ", sum=" + sum + ", reportTime=" + reportTime + "]";
}
}

View File

@@ -0,0 +1,84 @@
package com.nis.domain.restful;
import java.io.Serializable;
import java.util.Date;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.nis.util.JsonDateSerializer;
import com.wordnik.swagger.annotations.ApiModel;
import com.wordnik.swagger.annotations.ApiModelProperty;
/**
* @description 地域流量API
* @author dell
* @date 2018年12月5日11:01:13
*
*/
@ApiModel(value = "地域流量对象", description = "用来封装地域流量")
public class NtcAreaHomeReport implements Serializable {
/**
*
*/
private static final long serialVersionUID = -3597060253861898787L;
@JsonInclude(value = Include.NON_NULL)
@ApiModelProperty(value = "局点(出入口)")
private int entranceId;// 局点(出入口)
@JsonInclude(value = Include.NON_NULL)
@ApiModelProperty(value = "地域")
private String area;// 地域
@JsonInclude(value = Include.NON_NULL)
@ApiModelProperty(value = "接收字节数")
private long sum;// 接收字节数
@JsonInclude(value = Include.NON_NULL)
@ApiModelProperty(value = "统计时间")
private Date reportTime;// 统计时间
public int getEntranceId() {
return entranceId;
}
public void setEntranceId(int entranceId) {
this.entranceId = entranceId;
}
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
public long getSum() {
return sum;
}
public void setSum(long sum) {
this.sum = sum;
}
@JsonSerialize(using = JsonDateSerializer.class)
public Date getReportTime() {
return reportTime;
}
public void setReportTime(Date reportTime) {
this.reportTime = reportTime;
}
@Override
public String toString() {
return "NtcAreaHomeReport [entranceId=" + entranceId + ", area=" + area + ", sum=" + sum + ", reportTime="
+ reportTime + "]";
}
}

View File

@@ -0,0 +1,172 @@
package com.nis.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* 常用日历操作辅助类
*
*/
public class CalendarUtils {
/**
* //小时报2018-08-01 12:00:00 //日报2018-08-15 00:00:00 //月报2018-08-01 00:00:00
*/
static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
static final SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
static final SimpleDateFormat format3 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
static final SimpleDateFormat format4 = new SimpleDateFormat("yyyy-MM-dd HH");
static final SimpleDateFormat UTC = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
/**
* 获得当前小时或者前一个小时 0/-1
*
* @throws ParseException
*/
public static Date getPrevOneHourTime(int num) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.HOUR, num);
String format5 = format4.format(calendar.getTime());
format5 += ":00:00";
Date parse = null;
try {
parse = format2.parse(format5);
} catch (Exception e) {
e.printStackTrace();
}
return parse;
}
/**
* 获取time时间的前整5分钟的时间点 eg: 2018-12-12 12:06:36 结果为2018-12-12 12:05:00
* 2018-12-12 12:04:36 结果为2018-12-12 12:00:00
*
* 传入0 获得当前时间最近的5分钟刻度时间 传入 -5 获得当前时间最近的5分钟刻度时间的前5分钟
*
* @param time
* @return 取前一个5分钟的时间若返回为null则检查传入的string类型时间格式
*/
public static Date getRangeOf5min(int num) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
Date date = calendar.getTime();
Date parse = null;
String time = null;
if (date != null) {
time = format2.format(date);
} else {
return null;
}
int length = time.length();
int cut = 4;
if (length <= cut) {
return null;
}
int max = 5;
// 获取分钟数的个位
int compare;
try {
compare = Integer.parseInt(time.substring(length - cut, length - cut + 1));
time = time.substring(0, length - cut);
} catch (Exception e) {
e.printStackTrace();
return null;
}
if (compare >= 0 && compare < max) {
time = time.concat("0:00");
} else if (compare >= max) {
time = time.concat("5:00");
}
if (num == -5) {
Date parse1 = null;
try {
parse1 = format2.parse(time);
} catch (ParseException e) {
e.printStackTrace();
return null;
}
calendar.setTime(parse1);
calendar.add(Calendar.MINUTE, num);
calendar.set(Calendar.SECOND, 0);
return calendar.getTime();
}
try {
parse = format2.parse(time);
} catch (ParseException e) {
e.printStackTrace();
return null;
}
return parse;
}
/**
* 根据传参获得当天的0点或者前一天的0点(0/当天.-24/前一天)
*
* @param times
* @return
*/
public static Date getTPrevHour(Date date, int times) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, times);
return calendar.getTime();
}
/**
* local时间转换成UTC时间
*
* @param localTime
* @return
*/
public static String localToUTC(Date localTime) {
Date localDate = null;
if (null != localTime) {
localDate = localTime;
}
long localTimeInMillis = localDate.getTime();
/** long时间转换成Calendar */
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(localTimeInMillis);
/** 取得时间偏移量 */
int zoneOffset = calendar.get(java.util.Calendar.ZONE_OFFSET);
/** 取得夏令时差 */
int dstOffset = calendar.get(java.util.Calendar.DST_OFFSET);
/** 从本地时间里扣除这些差量即可以取得UTC时间 */
calendar.add(java.util.Calendar.MILLISECOND, -(zoneOffset + dstOffset));
/** 取得的时间就是UTC标准时间 */
Date utcDate = new Date(calendar.getTimeInMillis());
String utcTime = UTC.format(utcDate);
return utcTime;
}
public static void main(String[] args) throws ParseException {
Date endtime = CalendarUtils.getRangeOf5min(0);
Date startTime = CalendarUtils.getTPrevHour(endtime, -2);
//
// long startTimes = startTime.getTime();
// long endTimes = endtime.getTime();
//
// System.out.println("now:" + format2.format(new Date()));
System.out.println("start:" + format2.format(startTime));
System.out.println("end:" + format2.format(endtime));
System.out.println(endtime.compareTo(startTime));
System.out.println(format2.parse("2018-12-10 14:15:00").compareTo(endtime));
//
// // System.out.println(startTimes);
// // System.out.println(endTimes);
// // System.out.println((endTimes - startTimes) / 300000);
// int n = 0;
// for (; startTimes <= (endTimes - 300000); startTimes += 300000) {
// n++;
// System.out.println(format2.format(new Date(startTimes)));
// System.out.println(format2.format(new Date((startTimes + 300000))));
// System.out.println("---");
// }
// System.out.println(n);
}
}

View File

@@ -0,0 +1,141 @@
package com.nis.web.controller.restful;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.nis.domain.Page;
import com.nis.domain.restful.CfgLogInfo;
import com.nis.domain.restful.DropInfo;
import com.nis.domain.restful.NtcAreaHomeReport;
import com.nis.restful.RestBusinessCode;
import com.nis.restful.RestResult;
import com.nis.restful.RestServiceException;
import com.nis.restful.ServiceRuntimeException;
import com.nis.util.Constants;
import com.nis.web.controller.BaseRestController;
import com.nis.web.service.AuditLogThread;
import com.nis.web.service.ServicesRequestLogService;
import com.nis.web.service.restful.SystemHomePageService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
/**
* @Description 系统首页整体图API(1.地域流量API 2.配置统计API 3.日志统计API 4.丢弃量API)
* @author dell
* @date 2018年12月5日10:34:03
*
*/
@RestController
@RequestMapping("${servicePath}")
@Api(value = "SystemHomePageController", description = "系统首页整体图接口")
@SuppressWarnings("all")
public class SystemHomePageController extends BaseRestController {
@Autowired
ServicesRequestLogService servicesRequestLogService;
@Autowired
SystemHomePageService systemHomePageService;
@RequestMapping(value = "/log/v1/trafficAreaStat", method = RequestMethod.GET)
@ApiOperation(value = "地域流量获取", httpMethod = "GET", notes = "对地域流量获取服务信息进行查询", response = Map.class)
public Map<String, ?> trafficAreaStat(String searchReportStartTime, String searchReportEndTime,
HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
Page<NtcAreaHomeReport> trafficAreaStatPage = null;
try {
trafficAreaStatPage = systemHomePageService.getTrafficAreaStat(searchReportStartTime, searchReportEndTime,
request, response);
} catch (Exception e) {
saveLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
e.printStackTrace();
logger.error(e.getMessage());
if (!(e instanceof RestServiceException)) {
throw new ServiceRuntimeException(saveLogThread, System.currentTimeMillis() - start,
"获取地域流量失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
} else {
throw ((RestServiceException) e);
}
}
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "获取地域流量成功",
trafficAreaStatPage, 0);
}
@RequestMapping(value = "/log/v1/cfgSortLogStat", method = RequestMethod.GET)
@ApiOperation(value = "配置日志TOP5统计获取", httpMethod = "GET", notes = "对配置日志TOP5统计信息进行查询", response = Map.class)
public Map<String, ?> cfgSortLogStat(String searchReportStartTime, String searchReportEndTime,
HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
Page<CfgLogInfo> cfgSortLogStat = null;
try {
cfgSortLogStat = systemHomePageService.getCfgSortLogStat(searchReportStartTime, searchReportEndTime,
request, response);
} catch (Exception e) {
saveLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
e.printStackTrace();
logger.error(e.getMessage());
if (!(e instanceof RestServiceException)) {
throw new ServiceRuntimeException(saveLogThread, System.currentTimeMillis() - start,
"获取配置日志TOP5统计失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
} else {
throw ((RestServiceException) e);
}
}
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "获取配置日志TOP5统计成功",
cfgSortLogStat, 0);
}
@RequestMapping(value = "/log/v1/blockAndDropStat", method = RequestMethod.GET)
@ApiOperation(value = "丢弃量获取", httpMethod = "GET", notes = "对阻断和丢弃量进行查询", response = Map.class)
public Map<String, ?> blockAndDropStat(String searchReportStartTime, String searchReportEndTime,
@RequestParam(required = true) int searchBusinessType, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
Page<DropInfo> dropInfo = null;
try {
dropInfo = systemHomePageService.getBlockAndDropStat(searchReportStartTime, searchReportEndTime,
searchBusinessType, request, response);
} catch (Exception e) {
saveLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
e.printStackTrace();
logger.error(e.getMessage());
if (!(e instanceof RestServiceException)) {
throw new ServiceRuntimeException(saveLogThread, System.currentTimeMillis() - start,
"获取丢弃量失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
} else {
throw ((RestServiceException) e);
}
}
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "获取丢弃量成功", dropInfo, 0);
}
}

View File

@@ -0,0 +1,24 @@
package com.nis.web.dao;
import java.util.Date;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.nis.domain.restful.CfgLogInfo;
import com.nis.domain.restful.DropInfo;
import com.nis.domain.restful.NtcAreaHomeReport;
@MyBatisDao
public interface SystemHomePageDao {
List<NtcAreaHomeReport> getTrafficAreaStatList(@Param("startTime") Date searchReportStartTime,
@Param("endTime") Date searchReportEndTime);
List<CfgLogInfo> getCfgSortLogStatList(@Param("startTime") Date startTime, @Param("endTime") Date endTime);
List<DropInfo> getBlockAndDropStatListAll(@Param("startTime") Date startTime, @Param("endTime") Date endTime);
List<DropInfo> getBlockAndDropStatListMinute(@Param("startTime") Date startTime, @Param("endTime") Date endTime);
}

View File

@@ -0,0 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nis.web.dao.SystemHomePageDao">
<!-- 地域流量 -->
<select id="getTrafficAreaStatList" resultType="com.nis.domain.restful.NtcAreaHomeReport"
useCache="false" flushCache="true">
SELECT
device.entrance_id entranceId,
CASE device.entrance_id
WHEN 1 THEN
'阿斯塔纳'
WHEN 2 THEN
'阿拉木图'
ELSE
- 1
END AS area,
(netflow.INOCTETS_SPEED+
netflow.OUTOCTETS_SPEED) as sum,
netflow.RECV_TIME reportTime
FROM
ntc_device_info device
LEFT JOIN (
SELECT
netflow.INOCTETS_SPEED
INOCTETS_SPEED,
netflow.OUTOCTETS_SPEED
OUTOCTETS_SPEED,
netflow.RECV_TIME,
netflow.NODE_IP
FROM
traffic_netflow_port_info netflow
<where>
<if
test="null!=startTime and null!=endTime and ''!=startTime and ''!=endTime">
netflow.RECV_TIME&gt;#{startTime}
and
netflow.RECV_TIME&lt;=#{endTime}
</if>
</where>
) netflow
ON device.manager_ip = netflow.NODE_IP
WHERE
netflow.RECV_TIME
IS NOT
NULL
</select>
<!-- 配置日志TOP统计 -->
<select id="getCfgSortLogStatList" resultType="com.nis.domain.restful.CfgLogInfo"
useCache="false" flushCache="true">
SELECT
dic.service_code as serviceCode,
sum(service.sum) as sum,
dic.service_name_zh as serviceNameZh,
dic.service_name_en as
serviceNameEn,
dic.service_name_ru as serviceNameRu,
service.report_time as reportTime
FROM
ntc_service_report
service,ntc_service_dic dic
WHERE
service.service =
dic.service_code
and
<if
test="null!=startTime and null!=endTime and ''!=startTime and ''!=endTime">
service.report_time&gt;#{startTime} and
service.report_time&lt;=#{endTime}
</if>
GROUP BY
service.report_time,
service.service
ORDER BY
service.report_time ASC,
service.sum DESC
</select>
<!-- 丢弃量 -->
<!-- 总量 -->
<select id="getBlockAndDropStatListAll" resultType="com.nis.domain.restful.DropInfo"
useCache="false" flushCache="true">
SELECT
'drop' AS label,
IFNULL(
(
sum(reject_num) + SUM(drop_conn_num)
),
0
) AS sum,#{startTime} as reportTime
FROM
ntc_total_report
<where>
<if
test="null!=startTime and null!=endTime and ''!=startTime and ''!=endTime">
report_time&gt;#{startTime} and
report_time&lt;=#{endTime}
</if>
</where>
order by report_time
asc;
</select>
<!-- 五分钟业务 -->
<select id="getBlockAndDropStatListMinute" resultType="com.nis.domain.restful.DropInfo"
useCache="false" flushCache="true">
SELECT
'drop' AS label,
IFNULL(
(
sum(reject_num) + SUM(drop_conn_num)
),
0
) AS sum,report_time as reportTime
FROM
ntc_total_report
<where>
<if
test="null!=startTime and null!=endTime and ''!=startTime and ''!=endTime">
report_time&gt;#{startTime} and
report_time&lt;=#{endTime}
</if>
</where>
GROUP BY report_time
order by report_time
asc;
</select>
</mapper>

View File

@@ -0,0 +1,222 @@
package com.nis.web.service.restful;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
import com.nis.domain.Page;
import com.nis.domain.restful.CfgLogInfo;
import com.nis.domain.restful.DropInfo;
import com.nis.domain.restful.NtcAreaHomeReport;
import com.nis.util.CalendarUtils;
import com.nis.web.dao.SystemHomePageDao;
@Service
public class SystemHomePageService {
@Autowired
SystemHomePageDao systemHomePageDao;
protected final Logger logger = Logger.getLogger(SystemHomePageService.class);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 获取地域流量
public Page<NtcAreaHomeReport> getTrafficAreaStat(String searchReportStartTime, String searchReportEndTime,
HttpServletRequest request, HttpServletResponse response) {
List<NtcAreaHomeReport> list = new LinkedList<NtcAreaHomeReport>();
Page<NtcAreaHomeReport> page = new Page<>();
Date endTime = null;
Date startTime = null;
if (null != searchReportStartTime && null != searchReportEndTime && !"".equals(searchReportStartTime)
&& !"".equals(searchReportEndTime)) {
logger.info("开始获取地域流量,参数为{"
+ ((null == searchReportStartTime && !"".equals(searchReportStartTime)) ? ""
: searchReportStartTime)
+ "},{"
+ ((null == searchReportEndTime && !"".equals(searchReportEndTime)) ? "" : searchReportEndTime)
+ "}");
try {
startTime = format.parse(searchReportStartTime);
endTime = format.parse(searchReportEndTime);
} catch (ParseException e) {
e.printStackTrace();
logger.error("处理时间转换异常,{}", e);
}
} else {
endTime = CalendarUtils.getRangeOf5min(0);
startTime = CalendarUtils.getTPrevHour(endTime, -24);
logger.info("获取地域流量API请求参数为空,默认查询最近24小时");
}
list = systemHomePageDao.getTrafficAreaStatList(startTime, endTime);
if (null != list && 0 != list.size()) {
list = converNtcAreaHomeList(list, startTime, endTime);
}
logger.trace("查询地域流量结束");
page.setList(list);
return page;
}
// 获取配置日志TOP5统计
public Page<CfgLogInfo> getCfgSortLogStat(String searchReportStartTime, String searchReportEndTime,
HttpServletRequest request, HttpServletResponse response) {
List<CfgLogInfo> list = new LinkedList<CfgLogInfo>();
Page<CfgLogInfo> page = new Page<>();
Date endTime = null;
Date startTime = null;
if (null != searchReportStartTime && null != searchReportEndTime && !"".equals(searchReportStartTime)
&& !"".equals(searchReportEndTime)) {
logger.info("开始获取配置日志TOP5,参数为{"
+ ((null == searchReportStartTime && !"".equals(searchReportStartTime)) ? ""
: searchReportStartTime)
+ "},{"
+ ((null == searchReportEndTime && !"".equals(searchReportEndTime)) ? "" : searchReportEndTime)
+ "}");
try {
startTime = format.parse(searchReportStartTime);
endTime = format.parse(searchReportEndTime);
} catch (ParseException e) {
e.printStackTrace();
logger.error("处理时间转换异常,{}", e);
}
} else {
endTime = CalendarUtils.getRangeOf5min(0);
startTime = CalendarUtils.getTPrevHour(endTime, -24);
logger.info("获取配置日志TOP5API请求参数为空,默认查询最近24小时");
}
list = systemHomePageDao.getCfgSortLogStatList(startTime, endTime);
if (null != list && 0 != list.size()) {
list = converCfgLogList(list, startTime, endTime);
} else {
logger.info("没有查到配置日志Top的数据");
}
logger.trace("查询配置日志TOP5结束");
page.setList(list);
return page;
}
// 获取丢弃量
public Page<DropInfo> getBlockAndDropStat(String searchReportStartTime, String searchReportEndTime,
int searchBusinessType, HttpServletRequest request, HttpServletResponse response) {
List<DropInfo> list = new LinkedList<DropInfo>();
Page<DropInfo> page = new Page<>();
Date endTime = null;
Date startTime = null;
if (null != searchReportStartTime && null != searchReportEndTime && !"".equals(searchReportStartTime)
&& !"".equals(searchReportEndTime)) {
logger.info("开始获取丢弃量,参数为{"
+ ((null == searchReportStartTime && !"".equals(searchReportStartTime)) ? ""
: searchReportStartTime)
+ "},{"
+ ((null == searchReportEndTime && !"".equals(searchReportEndTime)) ? "" : searchReportEndTime)
+ "},{" + searchBusinessType + "}");
try {
startTime = format.parse(searchReportStartTime);
endTime = format.parse(searchReportEndTime);
} catch (ParseException e) {
e.printStackTrace();
logger.error("处理时间转换异常,{}", e);
}
} else {
endTime = CalendarUtils.getRangeOf5min(0);
startTime = CalendarUtils.getTPrevHour(endTime, -24);
logger.info("获取丢弃量API请求参数为空,默认查询最近24小时");
}
if (1 == searchBusinessType) {
logger.info("查询类型为:{丢弃总量业务}");
list = systemHomePageDao.getBlockAndDropStatListAll(startTime, endTime);
} else if (2 == searchBusinessType) {
logger.info("查询类型为:{丢弃量统计业务-分钟}");
list = systemHomePageDao.getBlockAndDropStatListMinute(startTime, endTime);
} else {
logger.error("searchBusinessType参数异常,默认查询总量业务");
list = systemHomePageDao.getBlockAndDropStatListAll(startTime, endTime);
}
logger.trace("查询丢弃量结束");
page.setList(list);
return page;
}
/**
* 进行筛选配置日志的Top5
*
* @param list
* @param startTime
* @param endTime
* @return
*/
public List<CfgLogInfo> converCfgLogList(List<CfgLogInfo> list, Date startTime, Date endTime) {
List<CfgLogInfo> newList = new LinkedList<>();
long startTimes = (startTime.getTime() + 300000);
long endTimes = endTime.getTime();
for (; startTimes <= endTimes; startTimes += 300000) {
int nums = 0;
for (int i = 0; i < list.size(); i++) {
if (nums == 5) {
break;
}
CfgLogInfo cfgLogInfo = list.get(i);
if (cfgLogInfo.getReportTime().getTime() == startTimes) {
newList.add(cfgLogInfo);
nums++;
}
}
}
return newList;
}
public List<NtcAreaHomeReport> converNtcAreaHomeList(List<NtcAreaHomeReport> list, Date startTime, Date endTime) {
final String area1 = "阿斯塔纳";
final String area2 = "阿拉木图";
List<NtcAreaHomeReport> newList = new LinkedList<>();
long startTimes = (startTime.getTime() + 300000);
long endTimes = endTime.getTime();
for (; startTimes <= endTimes; startTimes += 300000) {
NtcAreaHomeReport ntcAreaHomeReportArea1 = new NtcAreaHomeReport();
NtcAreaHomeReport ntcAreaHomeReportArea2 = new NtcAreaHomeReport();
long sums1 = 0;
long sums2 = 0;
for (int i = 0; i < list.size(); i++) {
NtcAreaHomeReport ntcAreaHomeReport2 = list.get(i);
if (ntcAreaHomeReport2.getReportTime().getTime() > startTimes
&& ntcAreaHomeReport2.getReportTime().getTime() <= (startTimes + 300000)) {
if (ntcAreaHomeReport2.getEntranceId() == 1) {
sums1 = sums1 + ntcAreaHomeReport2.getSum();
} else if (ntcAreaHomeReport2.getEntranceId() == 2) {
sums2 = sums2 + ntcAreaHomeReport2.getSum();
} else {
logger.debug("未知地域,地域ID为{" + ntcAreaHomeReport2.getEntranceId() + "}");
}
}
}
ntcAreaHomeReportArea1.setEntranceId(1);
ntcAreaHomeReportArea2.setEntranceId(2);
ntcAreaHomeReportArea1.setArea(area1);
ntcAreaHomeReportArea2.setArea(area2);
ntcAreaHomeReportArea1.setSum(sums1);
ntcAreaHomeReportArea2.setSum(sums2);
ntcAreaHomeReportArea1.setReportTime(new Date(startTimes));
ntcAreaHomeReportArea2.setReportTime(new Date(startTimes));
newList.add(ntcAreaHomeReportArea1);
newList.add(ntcAreaHomeReportArea2);
}
return newList;
}
}