v2新增接口(阻断和监测统计接口)

This commit is contained in:
李皓宸
2019-05-15 18:38:19 +08:00
parent f2c8e1244e
commit 8359cf3a2a
4 changed files with 226 additions and 0 deletions

View File

@@ -1,5 +1,9 @@
package com.nis.web.controller.restful;
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;
@@ -29,6 +33,7 @@ import com.nis.restful.ServiceRuntimeException;
import com.nis.util.Constants;
import com.nis.util.DateUtils;
import com.nis.util.ExceptionUtil;
import com.nis.util.StringUtils;
import com.nis.web.controller.BaseRestController;
import com.nis.web.service.AuditLogThread;
import com.nis.web.service.ServicesRequestLogService;
@@ -167,4 +172,50 @@ public class TrafficeReportController extends BaseRestController {
entity.setSearchReportEndTime(map.get("endTime"));
}
}
/**
* 流量统计info滚动条数据显示 封堵监测回流丢弃详情趋势
*/
@RequestMapping(value = "ntcActionEntranceReport", method = RequestMethod.GET)
@ApiOperation(value = "根据不同动作统计总量汇聚", httpMethod = "GET", notes = "对应流量统计info滚动条动作类型详情数据显示")
public Map<String, ?> ntcTotalReport(Model model, HttpServletRequest request, HttpServletResponse response,
String searchAction, String beginDate, String endDate,String searchBusinessType,Integer searchEntranceId) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<HashMap> list = new ArrayList<HashMap>();
try {
CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_A);
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());
}
List<HashMap> resultList = trafficReportService.getActionTrans2(beginDate, endDate, searchAction,searchBusinessType,searchEntranceId);
if (resultList != null && resultList.size() > 0) {
list = resultList;
}
} 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, "动作趋势分析统计数据检索成功", list,
0);
}
}

View File

@@ -2,6 +2,9 @@ package com.nis.web.dao;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.nis.domain.restful.NtcEntranceReport;
import com.nis.domain.restful.NtcIpRangeReport;
import com.nis.domain.restful.NtcRadiusReport;
import com.nis.domain.restful.dashboard.TrafficTransStatisticCK;
@@ -28,5 +31,7 @@ public interface TrafficReportDao {
List<TrafficTransStatisticCK> getBandwidthPpsFromCk(TrafficTransStatisticCK trafficTransStatisticCK);
List<TrafficTransStatisticCK> getBandwidthLinkNumFromCk(TrafficTransStatisticCK trafficTransStatisticCK);
List<NtcEntranceReport> getActionTrans(@Param("beginDate") String beginDate,@Param("endDate") String endDate ,@Param("searchEntranceId") Integer entranceId,@Param("serviceSql") String serviceSql,@Param("searchBusinessType")String searchBusinessType);
}

View File

@@ -248,5 +248,39 @@
entrance_id
</select>
<select id="getActionTrans" resultType="com.nis.domain.restful.NtcEntranceReport">
select sum(sum) sum,report_time reportTime from
<choose>
<when
test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 1 ">
NTC_ENTRANCE_REPORT
</when>
<when
test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 2 ">
NTC_ENTRANCE_STAT_HOUR
</when>
<when
test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 3 ">
NTC_ENTRANCE_STAT_DAILY
</when>
<when
test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 4 ">
NTC_ENTRANCE_STAT_MONTH
</when>
<otherwise>
NTC_ENTRANCE_STAT_MONTH
</otherwise>
</choose>
where
<![CDATA[ ${serviceSql} and report_time<#{endDate} and report_time>=#{beginDate}]]>
<if test="searchEntranceId != null">
and entrance_id=#{searchEntranceId}
</if>
group by report_time order by report_time
</select>
</mapper>

View File

@@ -2,7 +2,10 @@ package com.nis.web.service.restful;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -14,11 +17,15 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.nis.domain.Page;
import com.nis.domain.restful.NtcEntranceReport;
import com.nis.domain.restful.NtcRadiusReport;
import com.nis.domain.restful.dashboard.TrafficTransStatisticCK;
import com.nis.util.Constants;
import com.nis.util.DateUtils;
import com.nis.util.StringUtils;
import com.nis.web.dao.TrafficReportDao;
import com.nis.web.service.BaseLogService;
import com.zdjizhi.utils.StringUtil;
@Service
public class TrafficReportService extends BaseLogService {
@@ -193,5 +200,134 @@ public class TrafficReportService extends BaseLogService {
}
return map;
}
/**
* 根据service 动作查询近五分钟变化趋势 entrance 默认为1,2
*/
public List<HashMap> getActionTrans2(String begin, String end, String serviceType,String searchBusinessType,Integer entranceId) {
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("action_reject")) {
sql = sqlBlock;
}
if (serviceType.equalsIgnoreCase("action_monit")) {
sql = sqlMonitor;
}
if (serviceType.equalsIgnoreCase("action_drop")) {
sql = sqlDrop;
}
if (serviceType.equalsIgnoreCase("action_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 = trafficReportDao.getActionTrans(begin, end, entranceId, sql,searchBusinessType);
// entrance2 = trafficReportDao.getActionTrans(begin, end, 2, sql,searchBusinessType);
// entrance1.addAll(entrance2);
if (!StringUtil.isEmpty(entrance1)) {
// 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);
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
int trend_time_interval = 0;
int unit = 0;
if ("1".equals(searchBusinessType)) {
unit = Calendar.MINUTE;
trend_time_interval = Constants.TREND_TIME_INTERVAL;
} else if ("2".equals(searchBusinessType)) {
unit = Calendar.HOUR_OF_DAY;
trend_time_interval = 1;
} else if ("3".equals(searchBusinessType)) {
unit = Calendar.DAY_OF_MONTH;
trend_time_interval = 1;
} else if ("4".equals(searchBusinessType)) {
unit = Calendar.MONTH;
trend_time_interval = 1;
}
while (calendar.getTime().compareTo(endDate) < 0) {
dateRangeList.add(calendar.getTime());
calendar.add(unit, trend_time_interval);
}
int index1 = 0;
// int index2 = 0;
List sumList1 = new ArrayList();
// List sumList2 = new ArrayList();
Long sumEnt1 = 0L;
// Long sumEnt2 = 0L;
for (int i = 0; i < dateRangeList.size(); i++) {
// 存放一个时间点中总数
List listEnt1 = new ArrayList();
// List listEnt2 = new ArrayList();
// Map<String, Long> ipCountMap = new HashMap<String, Long>();
Date date = dateRangeList.get(i);
Long num1 = 0L;
// Long num2 = 0L;
for (int j = index1; j < entrance1.size(); j++) {
NtcEntranceReport ipInfo = entrance1.get(j);
if (ipInfo.getReportTime() != null) {
if (ipInfo.getReportTime().compareTo(date) >= 0 && (i + 1 < dateRangeList.size()
? ipInfo.getReportTime().compareTo(dateRangeList.get(i + 1)) < 0
: true)) {
num1 = num1 + ipInfo.getSum();
} else {
index1 = j;
break;
}
}
}
// for (int j = index2; j < entrance2.size(); j++) {
// NtcEntranceReport ipInfo = entrance2.get(j);
// if (ipInfo.getReportTime() != null) {
// if (ipInfo.getReportTime().compareTo(date) >= 0 && (i + 1 < dateRangeList.size()
// ? ipInfo.getReportTime().compareTo(dateRangeList.get(i + 1)) < 0
// : true)) {
// num2 = num2 + ipInfo.getSum();
// } else {
// index2 = j;
// break;
// }
// }
// }
// 最后一个时间点,全为0 直接跳过不存入列表
if (i + 1 == dateRangeList.size() && num1.compareTo(0L) == 0) {
break;
}
sumEnt1 += num1;
listEnt1.add(date.getTime());
listEnt1.add(num1);
sumList1.add(listEnt1);
// sumEnt2 += num2;
// listEnt2.add(date.getTime());
// listEnt2.add(num2);
// sumList2.add(listEnt2);
}
// 整合 count time
m1.put("sum", sumEnt1);
m1.put("result", sumList1);
m1.put("entranceId", entranceId);
// m2.put("sum", sumEnt2);//
// m2.put("result", sumList2);
// m2.put("entranceId", 2);
listMap.add(m1);
// listMap.add(m2);
}
return listMap;
}
}