添加流量统计二级页面:根据指标(drop,loop,New Link,Close Link,Pass,Live Link)统计各业务的趋势
This commit is contained in:
90
src/main/java/com/nis/domain/restful/NtcConnNumReport.java
Normal file
90
src/main/java/com/nis/domain/restful/NtcConnNumReport.java
Normal file
@@ -0,0 +1,90 @@
|
||||
package com.nis.domain.restful;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
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.ApiModelProperty;
|
||||
|
||||
public class NtcConnNumReport implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -5957594320933224337L;
|
||||
@ApiModelProperty(value = "日志数量", required = true)
|
||||
protected Long num;
|
||||
@JsonInclude(value = Include.NON_NULL)
|
||||
@ApiModelProperty(value = "统计时间", required = true)
|
||||
protected Date reportTime;
|
||||
|
||||
/**
|
||||
* 查询业务类型:1:drop 2:loop 3:newLink 4:clockLink 5:liveLink 6:pass
|
||||
*/
|
||||
protected String searchBusinessType = "1";
|
||||
protected String searchReportStartTime;
|
||||
protected String searchReportEndTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public NtcConnNumReport() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public NtcConnNumReport(Long num, Date reportTime) {
|
||||
super();
|
||||
this.num = num;
|
||||
this.reportTime = reportTime;
|
||||
}
|
||||
|
||||
public Long getNum() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public void setnum(Long num) {
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
@JsonSerialize(using = JsonDateSerializer.class)
|
||||
public Date getReportTime() {
|
||||
return reportTime;
|
||||
}
|
||||
|
||||
public void setReportTime(Date reportTime) {
|
||||
this.reportTime = reportTime;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public String getSearchBusinessType() {
|
||||
return searchBusinessType;
|
||||
}
|
||||
|
||||
public void setSearchBusinessType(String searchBusinessType) {
|
||||
this.searchBusinessType = searchBusinessType;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public String getSearchReportStartTime() {
|
||||
return searchReportStartTime;
|
||||
}
|
||||
|
||||
public void setSearchReportStartTime(String searchReportStartTime) {
|
||||
this.searchReportStartTime = searchReportStartTime;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public String getSearchReportEndTime() {
|
||||
return searchReportEndTime;
|
||||
}
|
||||
|
||||
public void setSearchReportEndTime(String searchReportEndTime) {
|
||||
this.searchReportEndTime = searchReportEndTime;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,7 @@ 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.restful.NtcConnNumReport;
|
||||
import com.nis.restful.RestBusinessCode;
|
||||
import com.nis.restful.RestServiceException;
|
||||
import com.nis.restful.ServiceRuntimeException;
|
||||
@@ -33,6 +34,7 @@ import com.nis.web.service.ServicesRequestLogService;
|
||||
import com.nis.web.service.restful.DashboardService;
|
||||
import com.wordnik.swagger.annotations.Api;
|
||||
import com.wordnik.swagger.annotations.ApiOperation;
|
||||
import com.zdjizhi.utils.StringUtil;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@RestController
|
||||
@@ -949,4 +951,38 @@ public class DashboardServiceController extends BaseRestController {
|
||||
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "流量端口详情趋势数据检索成功",
|
||||
list, 0);
|
||||
}
|
||||
@RequestMapping(value = "/trendTotalReport", method = RequestMethod.GET)
|
||||
@ApiOperation(value = "流量各指标趋势统计", httpMethod = "GET", notes = "根据指标(drop,loop,New Link,Close Link,Pass,Live Link)统计各业务的趋势")
|
||||
public Map<String, ?> trendTotalReport(NtcConnNumReport ntcConnNumReport, Model model, HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
long start = System.currentTimeMillis();
|
||||
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
|
||||
null);
|
||||
|
||||
Map<String, List> restMap = new HashMap<String, List>();
|
||||
try {
|
||||
// 验证serachBusinessType
|
||||
if (!StringUtil.isBlank(ntcConnNumReport.getSearchBusinessType())
|
||||
&& !StringUtil.isNumeric(ntcConnNumReport.getSearchBusinessType())) {
|
||||
throw new RestServiceException("searchBusinessType参数格式错误", RestBusinessCode.param_formate_error.getValue());
|
||||
}
|
||||
restMap = dashboardService.trendTotalReport(ntcConnNumReport);
|
||||
} catch (Exception e) {
|
||||
saveLogThread.setExceptionInfo("流量各指标趋势统计失败:" + e.getMessage());
|
||||
logger.error("流量各指标趋势统计失败:" + ExceptionUtil.getExceptionMsg(e));
|
||||
if (e instanceof RestServiceException) {
|
||||
throw new RestServiceException(saveLogThread, System.currentTimeMillis() - start,
|
||||
"流量各指标趋势统计失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
|
||||
} else if (e instanceof ServiceRuntimeException) {
|
||||
throw new ServiceRuntimeException(saveLogThread, System.currentTimeMillis() - start,
|
||||
"流量各指标趋势统计失败:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode());
|
||||
} else {
|
||||
throw new ServiceRuntimeException(saveLogThread, System.currentTimeMillis() - start,
|
||||
"流量各指标趋势统计失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "流量各指标趋势统计成功",
|
||||
restMap, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@ import java.util.Map;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.nis.domain.restful.NtcConnNumReport;
|
||||
import com.nis.domain.restful.NtcEntranceReport;
|
||||
import com.nis.domain.restful.NtcIpRangeReport;
|
||||
import com.nis.domain.restful.dashboard.NtcTotalReport;
|
||||
import com.nis.domain.restful.dashboard.TrafficTransStatistic;
|
||||
import com.nis.web.dao.MyBatisDao;
|
||||
@@ -25,4 +27,5 @@ public interface NtcTotalReportDao {
|
||||
List<TrafficTransStatistic> getBandwidthTrans2(@Param("beginDate") String beginDate,@Param("endDate") String endDate);
|
||||
Map getEntranceMaxReportTime();
|
||||
List<NtcEntranceReport> getActionTrans(@Param("beginDate") String beginDate,@Param("endDate") String endDate ,@Param("entranceId") Integer entranceId,@Param("serviceSql") String serviceSql);
|
||||
List<NtcConnNumReport> trendTotalReport(NtcConnNumReport pz);
|
||||
}
|
||||
@@ -133,4 +133,48 @@
|
||||
and entrance_id=#{entranceId}
|
||||
group by report_time order by report_time
|
||||
</select>
|
||||
|
||||
<!-- 根据指标(1:drop 2:loop 3:newLink 4:clockLink 5:liveLink 6:pass)统计各业务的趋势-->
|
||||
<select id="trendTotalReport" parameterType="com.nis.domain.restful.NtcConnNumReport" resultType="com.nis.domain.restful.NtcConnNumReport">
|
||||
SELECT
|
||||
<choose>
|
||||
<when test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 2 ">
|
||||
loop_conn_num
|
||||
</when>
|
||||
<when test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 3 ">
|
||||
new_uni_conn_num
|
||||
</when>
|
||||
<when test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 4 ">
|
||||
live_conn_num
|
||||
</when>
|
||||
<when test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 5 ">
|
||||
(new_uni_conn_num-reject_num)
|
||||
</when>
|
||||
<when test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 6 ">
|
||||
(new_uni_conn_num-drop_conn_num)
|
||||
</when>
|
||||
<otherwise>
|
||||
drop_conn_num
|
||||
</otherwise>
|
||||
</choose>
|
||||
num,report_time
|
||||
FROM ntc_total_report
|
||||
<where>
|
||||
<choose>
|
||||
<when test="searchReportStartTime != null and searchReportStartTime !='' and searchReportEndTime != null and searchReportEndTime !=''">
|
||||
<if test="searchReportStartTime != null and searchReportStartTime !=''" >
|
||||
<![CDATA[AND REPORT_TIME >= STR_TO_DATE(#{searchReportStartTime},'%Y-%m-%d %H:%i:%s')]]>
|
||||
</if>
|
||||
<if test="searchReportEndTime != null and searchReportEndTime !=''">
|
||||
<![CDATA[AND REPORT_TIME < STR_TO_DATE(#{searchReportEndTime},'%Y-%m-%d %H:%i:%s')]]>
|
||||
</if>
|
||||
</when>
|
||||
<otherwise>
|
||||
AND report_time > DATE_SUB(now(),INTERVAL 1 hour)
|
||||
</otherwise>
|
||||
</choose>
|
||||
</where>
|
||||
order by report_time
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -1,20 +1,48 @@
|
||||
package com.nis.web.service.restful;
|
||||
|
||||
import com.beust.jcommander.internal.Maps;
|
||||
import com.nis.domain.restful.NtcEntranceReport;
|
||||
import com.nis.domain.restful.dashboard.*;
|
||||
import com.nis.util.DateUtils;
|
||||
import com.nis.util.StringUtils;
|
||||
import com.nis.web.dao.dashboard.*;
|
||||
import com.nis.web.service.BaseService;
|
||||
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.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;
|
||||
|
||||
import com.beust.jcommander.internal.Maps;
|
||||
import com.nis.domain.restful.NtcConnNumReport;
|
||||
import com.nis.domain.restful.NtcEntranceReport;
|
||||
import com.nis.domain.restful.dashboard.NtcTotalReport;
|
||||
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;
|
||||
import com.nis.util.DateUtils;
|
||||
import com.nis.util.StringUtils;
|
||||
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;
|
||||
import com.nis.web.service.BaseService;
|
||||
import com.zdjizhi.utils.StringUtil;
|
||||
|
||||
@Service
|
||||
public class DashboardService extends BaseService {
|
||||
@@ -1227,7 +1255,7 @@ public class DashboardService extends BaseService {
|
||||
if ((!StringUtil.isEmpty(bandwidthListIPvx) && bandwidthListIPvx.size() > 0)
|
||||
|| (!StringUtil.isEmpty(bandwidthListProtocol) && bandwidthListProtocol.size() > 0)) {
|
||||
// 划分时间段
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm");
|
||||
Date startTime = sdf.parse(beginDate);
|
||||
Date endTime = sdf.parse(endDate);
|
||||
List<Date> dateRangeList = new ArrayList<Date>();
|
||||
@@ -1280,10 +1308,9 @@ public class DashboardService extends BaseService {
|
||||
ArrayList<TrafficTransStatistic> value = entry.getValue();
|
||||
resultMap.put(key, getNewData(dateRangeList, strDateRangeList, value));
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
private Map getNewData(List<Date> dateRangeList, List<String> timeList, List<TrafficTransStatistic> bandwidthList) {
|
||||
@@ -1529,4 +1556,57 @@ public class DashboardService extends BaseService {
|
||||
return listMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据指标(drop,loop,New Link,Close Link,Pass,Live Link)统计各业务的趋势
|
||||
* @throws ParseException
|
||||
*/
|
||||
public Map<String, List> trendTotalReport(NtcConnNumReport ntcConnNumReport){
|
||||
Map<String, List> restMap = new HashMap<String, List>();
|
||||
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);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm");
|
||||
while (calendar.getTime().compareTo(endDate)<=0) {
|
||||
dateRangeList.add(calendar.getTime());
|
||||
strDateRangeList.add(sdf.format(calendar.getTime()));
|
||||
calendar.add(Calendar.MINUTE, 5);
|
||||
}
|
||||
int index = 0;
|
||||
List<Long> sumList = new ArrayList<Long>();
|
||||
for (int i = 0; i < dateRangeList.size(); i++) {
|
||||
//存放一个时间点中每个IP的总数
|
||||
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){
|
||||
if(info.getReportTime().compareTo(date)>=0&&(i+1<dateRangeList.size()&&info.getReportTime().compareTo(dateRangeList.get(i+1))<0)) {
|
||||
sum = sum+info.getNum();
|
||||
}else{
|
||||
index = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
sumList.add(sum);
|
||||
}
|
||||
restMap.put("sum", sumList);
|
||||
restMap.put("statTime", strDateRangeList);
|
||||
}
|
||||
return restMap;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user