1:新增业务

2:修改统计报表业务
This commit is contained in:
renkaige
2018-12-17 14:08:03 +06:00
parent d58b7ae780
commit 980ecdf7a8
16 changed files with 1683 additions and 843 deletions

View File

@@ -0,0 +1,99 @@
package com.nis.domain.restful;
import java.io.Serializable;
import java.util.Map;
import javax.xml.bind.annotation.XmlTransient;
import org.apache.poi.ss.formula.functions.T;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Maps;
import com.nis.domain.Page;
public class NtcIpRangeReport<T> implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String ipStart;
private String ipEnd;
private Long ipStartNum;
private Long ipEndNum;
private String ipSub;
private String country;
private String searchType;
private String searchCountry;
public String getIpStart() {
return ipStart;
}
public void setIpStart(String ipStart) {
this.ipStart = ipStart;
}
public String getIpEnd() {
return ipEnd;
}
public void setIpEnd(String ipEnd) {
this.ipEnd = ipEnd;
}
public Long getIpStartNum() {
return ipStartNum;
}
public void setIpStartNum(Long ipStartNum) {
this.ipStartNum = ipStartNum;
}
public Long getIpEndNum() {
return ipEndNum;
}
public void setIpEndNum(Long ipEndNum) {
this.ipEndNum = ipEndNum;
}
public String getIpSub() {
return ipSub;
}
public void setIpSub(String ipSub) {
this.ipSub = ipSub;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
@JsonIgnore
public String getSearchType() {
return searchType;
}
public void setSearchType(String searchType) {
this.searchType = searchType;
}
@JsonIgnore
public String getSearchCountry() {
return searchCountry;
}
public void setSearchCountry(String searchCountry) {
this.searchCountry = searchCountry;
}
}

View File

@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
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.restful.RestBusinessCode;
@@ -32,35 +33,37 @@ 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;
@SuppressWarnings("unchecked")
@RestController
@RequestMapping(value = "${servicePath}/log/v1")
@Api(value = "DashboardServiceController", description = "统计分析图表基本服务接口")
public class DashboardServiceController extends BaseRestController {
@Autowired
protected ServicesRequestLogService servicesRequestLogService;
@Autowired
public DashboardService dashboardService;
/**
* 流量统计info滚动条数据显示 封堵监测回流丢弃
*/
@RequestMapping(value = "ntcTotalReport", method = RequestMethod.GET)
@ApiOperation(value = "业务总量汇聚", httpMethod = "GET", notes = "对应流量统计info滚动条数据显示")
public Map<String,?> ntcTotalReport(Model model, HttpServletRequest request, HttpServletResponse response) {
public Map<String, ?> ntcTotalReport(Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<Map> list = new ArrayList<Map>();
try {
List<Map> resultList = dashboardService.getTotalReportList();
if (resultList!=null&&resultList.size() > 0) {
list = resultList;
if (resultList != null && resultList.size() > 0) {
list = resultList;
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("业务总量汇聚实时统计数据检索失败:"+e.getMessage());
logger.error("业务总量汇聚实时统计数据检索失败:"+ExceptionUtil.getExceptionMsg(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());
@@ -71,35 +74,39 @@ public class DashboardServiceController extends BaseRestController {
throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start,
"业务总量汇聚实时统计数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "业务总量汇聚实时统计数据检索成功",list, 0);
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "业务总量汇聚实时统计数据检索成功", list,
0);
}
/**
* 流量统计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) {
public Map<String, ?> ntcTotalReport(Model model, HttpServletRequest request, HttpServletResponse response,
String searchAction, String beginDate, String endDate) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<HashMap> list = new ArrayList<HashMap>();
try {
if(StringUtils.isEmpty(beginDate)||StringUtils.isEmpty(endDate)) {
Calendar cal = Calendar. getInstance ();
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());//获取到完整的时间
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());
beginDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cal.getTime());
}
List<HashMap> resultList = dashboardService.getActionTrans(beginDate,endDate,searchAction);
if (resultList!=null&&resultList.size() > 0) {
list = resultList;
List<HashMap> resultList = dashboardService.getActionTrans(beginDate, endDate, searchAction);
if (resultList != null && resultList.size() > 0) {
list = resultList;
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("动作趋势分析统计数据检索失败:"+e.getMessage());
logger.error("动作趋势分析统计数据检索失败:"+ExceptionUtil.getExceptionMsg(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());
@@ -111,32 +118,36 @@ public class DashboardServiceController extends BaseRestController {
"动作趋势分析统计数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "动作趋势分析统计数据检索成功",list, 0);
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "动作趋势分析统计数据检索成功", list,
0);
}
/**
* 根据ip46,协议tcpudp查询带宽
* 根据ip46,协议tcpudp查询带宽
*/
@RequestMapping(value = "trafficBandwidthTrans", method = RequestMethod.GET)
@ApiOperation(value = "带宽根据ip46,协议tcp,udp查询详情", httpMethod = "GET", notes = "对应带宽根据IPv4,6,协议tcp,udp统计数据显示")
public Map<String,?> trafficBandwidthTrans(String beginDate,String endDate,String addrType,Integer transType,Model model, HttpServletRequest request, HttpServletResponse response) {
public Map<String, ?> trafficBandwidthTrans(String beginDate, String endDate, String addrType, Integer transType,
Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<HashMap> list = new ArrayList<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());
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 = dashboardService.getBandwidthTrans(addrType, transType,beginDate,endDate);
if (resultList!=null&&resultList.size() > 0) {
List<HashMap> resultList = dashboardService.getBandwidthTrans(addrType, transType, beginDate, endDate);
if (resultList != null && resultList.size() > 0) {
list = resultList;
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("带宽实时统计数据检索失败:"+e.getMessage());
logger.error("带宽实时统计数据检索失败:"+ExceptionUtil.getExceptionMsg(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());
@@ -148,32 +159,35 @@ public class DashboardServiceController extends BaseRestController {
"带宽实时统计数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "带宽实时统计数据检索成功",list, 0);
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "带宽实时统计数据检索成功", list, 0);
}
/**
* 根据ip46,协议tcpudp查询带宽
* 根据ip46,协议tcpudp查询带宽
*/
@RequestMapping(value = "trafficBandwidthTransTwo", method = RequestMethod.GET)
@ApiOperation(value = "带宽根据ip46,协议tcp,udp查询详情", httpMethod = "GET", notes = "对应带宽根据IPv4,6,协议tcp,udp统计数据显示")
public Map<String,?> trafficBandwidthTransTow(String beginDate,String endDate,String addrType,Integer transType,Model model, HttpServletRequest request, HttpServletResponse response) {
public Map<String, ?> trafficBandwidthTransTow(String beginDate, String endDate, String addrType, Integer transType,
Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<HashMap> list = new ArrayList<HashMap>();
try {
if(StringUtils.isEmpty(beginDate)||StringUtils.isEmpty(endDate)) {
Calendar cal = Calendar. getInstance ();
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());//获取到完整的时间
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());
beginDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cal.getTime());
}
List<HashMap> resultList = dashboardService.getBandwidthTrans2(addrType, transType,beginDate,endDate);
if (resultList!=null&&resultList.size() > 0) {
List<HashMap> resultList = dashboardService.getBandwidthTrans2(addrType, transType, beginDate, endDate);
if (resultList != null && resultList.size() > 0) {
list = resultList;
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("带宽实时统计数据检索失败:"+e.getMessage());
logger.error("带宽实时统计数据检索失败:"+ExceptionUtil.getExceptionMsg(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());
@@ -185,27 +199,29 @@ public class DashboardServiceController extends BaseRestController {
"带宽实时统计数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "带宽实时统计数据检索成功",list, 0);
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "带宽实时统计数据检索成功", list, 0);
}
/**
* 流量统计活跃端口统计
*/
@RequestMapping(value = "trafficPortActive", method = RequestMethod.GET)
@ApiOperation(value = "活跃端口统计", httpMethod = "GET", notes = "对应流量统计活跃端口统计")
public Map<String,?> trafficPortActive(Model model, HttpServletRequest request, HttpServletResponse response) {
public Map<String, ?> trafficPortActive(Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<Map> list = new ArrayList<Map>();
try {
List<Map> resultList = dashboardService.getPortActiveList();
if(resultList!=null&&resultList.size()>0) {
list=resultList;
if (resultList != null && resultList.size() > 0) {
list = resultList;
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("活跃端口实时统计数据检索失败:"+e.getMessage());
logger.error("活跃端口实时统计数据检索失败:"+ExceptionUtil.getExceptionMsg(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());
@@ -217,28 +233,29 @@ public class DashboardServiceController extends BaseRestController {
"活跃端口实时统计数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "活跃端口实时统计数据检索成功",list, 0);
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "活跃端口实时统计数据检索成功", list,
0);
}
/**
* 协议统计
*/
@RequestMapping(value="trafficProtocol", method = RequestMethod.GET)
@RequestMapping(value = "trafficProtocol", method = RequestMethod.GET)
@ApiOperation(value = "协议统计", httpMethod = "GET", notes = "对应协议统计实时统计查询服务。")
public Map<String,?> trafficProtocol(Model model, HttpServletRequest request, HttpServletResponse response){
public Map<String, ?> trafficProtocol(Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<HashMap> list = new ArrayList<HashMap>();
try {
List<Map> ipActiveChart = dashboardService.protocolChart();
if (ipActiveChart!=null&&ipActiveChart.size() > 0) {
String jsonString = JsonMapper.toJsonString(ipActiveChart);
list = (java.util.List<HashMap>) JsonMapper.fromJsonList(jsonString,HashMap.class);
if (ipActiveChart != null && ipActiveChart.size() > 0) {
String jsonString = JsonMapper.toJsonString(ipActiveChart);
list = (java.util.List<HashMap>) JsonMapper.fromJsonList(jsonString, HashMap.class);
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("协议统计图表数据检索失败:"+e.getMessage());
logger.error("协议统计图表数据检索失败:"+ExceptionUtil.getExceptionMsg(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());
@@ -250,27 +267,29 @@ public class DashboardServiceController extends BaseRestController {
"协议统计图表数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "协议统计图表数据检索成功",
list, 0);
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "协议统计图表数据检索成功", list, 0);
}
/**
* 协议统计详情图与表
*/
@RequestMapping(value="trafficProtocolList", method = RequestMethod.GET)
@RequestMapping(value = "trafficProtocolList", method = RequestMethod.GET)
@ApiOperation(value = "协议统计占比与报表", httpMethod = "GET", notes = "对应协议统计详情占比与报表")
public Map<String,?> trafficProtocolList(String beginDate,String endDate,Model model, HttpServletRequest request, HttpServletResponse response){
public Map<String, ?> trafficProtocolList(String beginDate, String endDate, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<HashMap> list = new ArrayList<HashMap>();
try {
List<Map> ipActiveList = dashboardService.getProtocolList(beginDate,endDate);
if (ipActiveList!=null&&ipActiveList.size() > 0) {
List<Map> ipActiveList = dashboardService.getProtocolList(beginDate, endDate);
if (ipActiveList != null && ipActiveList.size() > 0) {
String jsonString = JsonMapper.toJsonString(ipActiveList);
list = (java.util.List<HashMap>) JsonMapper.fromJsonList(jsonString,HashMap.class);
list = (java.util.List<HashMap>) JsonMapper.fromJsonList(jsonString, HashMap.class);
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("协议统计占比与报表检索失败:"+e.getMessage());
logger.error("协议统计占比与报表检索失败:"+ExceptionUtil.getExceptionMsg(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());
@@ -282,42 +301,43 @@ public class DashboardServiceController extends BaseRestController {
"协议统计占比与报表检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "协议统计占比与报表检索成功",
list, 0);
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "协议统计占比与报表检索成功", list,
0);
}
/**
* 活跃IP TOP10
*/
@RequestMapping(value = "trafficIpActive", method = RequestMethod.GET)
@ApiOperation(value = "活跃IP统计", httpMethod = "GET", notes = "对应活跃IP实时统计查询服务。")
public Map<String,?> trafficIpActive(String beginDate, String endDate ,Model model, HttpServletRequest request, HttpServletResponse response) {
public Map<String, ?> trafficIpActive(String beginDate, String endDate, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<LinkedHashMap> list = new ArrayList<LinkedHashMap>();
try {
Date begin=null;
Date end=null;
if(StringUtils.isEmpty(beginDate)||StringUtils.isEmpty(endDate)) {
Calendar cal = Calendar. getInstance ();
Date begin = null;
Date end = null;
if (StringUtils.isEmpty(beginDate) || StringUtils.isEmpty(endDate)) {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
begin = cal.getTime();//获取到完整的时间
begin = cal.getTime();// 获取到完整的时间
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1);
end = cal.getTime();
}else {
end = cal.getTime();
} else {
begin = DateUtils.parseDate(beginDate);
end = DateUtils.parseDate(endDate);
}
List<LinkedHashMap> ipActiveChart = dashboardService.ipActiveChart(begin,end);
if (ipActiveChart!=null&&ipActiveChart.size() > 0) {
list = ipActiveChart;
List<LinkedHashMap> ipActiveChart = dashboardService.ipActiveChart(begin, end);
if (ipActiveChart != null && ipActiveChart.size() > 0) {
list = ipActiveChart;
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("活跃IP实时统计数据检索失败:"+e.getMessage());
logger.error("活跃IP实时统计数据检索失败:"+ExceptionUtil.getExceptionMsg(e));
auditLogThread.setExceptionInfo("活跃IP实时统计数据检索失败:" + e.getMessage());
logger.error("活跃IP实时统计数据检索失败:" + ExceptionUtil.getExceptionMsg(e));
if (e instanceof RestServiceException) {
throw new RestServiceException(auditLogThread, System.currentTimeMillis() - start,
"活跃IP实时统计数据检索失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
@@ -329,28 +349,32 @@ public class DashboardServiceController extends BaseRestController {
"活跃IP实时统计数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "活跃IP实时统计数据检索成功",list, 0);
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "活跃IP实时统计数据检索成功", list,
0);
}
/**
* 活跃IP TOP10 一小时数据
*/
@RequestMapping(value = "trafficIpActiveOneHour", method = RequestMethod.GET)
@ApiOperation(value = "活跃IP统计一个小时的活跃IP", httpMethod = "GET", notes = "对应活跃IP实时统计查询服务。")
public Map<String,?> trafficIpActiveOneHour(String beginDate, String endDate ,Model model, HttpServletRequest request, HttpServletResponse response) {
public Map<String, ?> trafficIpActiveOneHour(String beginDate, String endDate, Model model,
HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<HashMap> list = new ArrayList<HashMap>();
try {
Date begin = DateUtils.parseDate(beginDate);
Date end = DateUtils.parseDate(endDate);
List<HashMap> ipActiveChart = dashboardService.ipActiveOneHour(begin,end);
if (ipActiveChart!=null&&ipActiveChart.size() > 0) {
List<HashMap> ipActiveChart = dashboardService.ipActiveOneHour(begin, end);
if (ipActiveChart != null && ipActiveChart.size() > 0) {
list = ipActiveChart;
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("活跃IP统计一个小时的活跃IP检索失败:"+e.getMessage());
logger.error("活跃IP统计一个小时的活跃IP检索失败:"+ExceptionUtil.getExceptionMsg(e));
auditLogThread.setExceptionInfo("活跃IP统计一个小时的活跃IP检索失败:" + e.getMessage());
logger.error("活跃IP统计一个小时的活跃IP检索失败:" + ExceptionUtil.getExceptionMsg(e));
if (e instanceof RestServiceException) {
throw new RestServiceException(auditLogThread, System.currentTimeMillis() - start,
"活跃IP统计一个小时的活跃IP检索失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
@@ -362,32 +386,36 @@ public class DashboardServiceController extends BaseRestController {
"活跃IP统计一个小时的活跃IP检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "活跃IP统计一个小时的活跃IP检索成功",list, 0);
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "活跃IP统计一个小时的活跃IP检索成功",
list, 0);
}
/**
* 活跃IP TOP10 一小时间隔五分钟数据
*/
@RequestMapping(value = "trafficIpActiveFiveMinute", method = RequestMethod.GET)
@ApiOperation(value = "活跃IP最近一个小时的变化趋势统计", httpMethod = "GET", notes = "对最新TOP10的活跃IP在近一个小时的变化情况进行统计")
public Map<String,?> trafficIpActiveFiveMinute(String beginDate, String endDate ,Model model, HttpServletRequest request, HttpServletResponse response) {
public Map<String, ?> trafficIpActiveFiveMinute(String beginDate, String endDate, Model model,
HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<HashMap> list = new ArrayList<HashMap>();
try {
Date begin=null;
Date end=null;
if(!StringUtils.isEmpty(beginDate)&&!StringUtils.isEmpty(endDate)) {
begin=DateUtils.parseDate(beginDate);
end=DateUtils.parseDate(endDate);
Date begin = null;
Date end = null;
if (!StringUtils.isEmpty(beginDate) && !StringUtils.isEmpty(endDate)) {
begin = DateUtils.parseDate(beginDate);
end = DateUtils.parseDate(endDate);
}
List<HashMap> ipActiveChart = dashboardService.ipActiveFiveMinute(begin,end);
if (ipActiveChart!=null&&ipActiveChart.size() > 0) {
List<HashMap> ipActiveChart = dashboardService.ipActiveFiveMinute(begin, end);
if (ipActiveChart != null && ipActiveChart.size() > 0) {
list = ipActiveChart;
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("活跃IP最近一个小时的变化趋势统计失败:"+e.getMessage());
logger.error("活跃IP最近一个小时的变化趋势统计失败:"+ExceptionUtil.getExceptionMsg(e));
auditLogThread.setExceptionInfo("活跃IP最近一个小时的变化趋势统计失败:" + e.getMessage());
logger.error("活跃IP最近一个小时的变化趋势统计失败:" + ExceptionUtil.getExceptionMsg(e));
if (e instanceof RestServiceException) {
throw new RestServiceException(auditLogThread, System.currentTimeMillis() - start,
"活跃IP最近一个小时的变化趋势统计失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
@@ -399,26 +427,29 @@ public class DashboardServiceController extends BaseRestController {
"活跃IP最近一个小时的变化趋势统计失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "活跃IP最近一个小时的变化趋势统计成功",list, 0);
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "活跃IP最近一个小时的变化趋势统计成功",
list, 0);
}
/**
* app应用流量分析 TOP10
*/
@RequestMapping(value = "trafficApp", method = RequestMethod.GET)
@ApiOperation(value = "App流量分析统计", httpMethod = "GET", notes = "对应app流量分析实时统计查询服务。")
public Map<String, ?> trafficApp(Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<Map> list = new ArrayList<Map>();
try {
List<Map> appChart = dashboardService.appChart();
if (appChart!=null&&appChart.size() > 0) {
if (appChart != null && appChart.size() > 0) {
list = appChart;
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("App流量统计数据检索失败:"+e.getMessage());
logger.error("App流量统计数据检索失败:"+ExceptionUtil.getExceptionMsg(e));
auditLogThread.setExceptionInfo("App流量统计数据检索失败:" + e.getMessage());
logger.error("App流量统计数据检索失败:" + ExceptionUtil.getExceptionMsg(e));
if (e instanceof RestServiceException) {
throw new RestServiceException(auditLogThread, System.currentTimeMillis() - start,
"App流量统计数据检索失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
@@ -430,26 +461,30 @@ public class DashboardServiceController extends BaseRestController {
"App流量统计数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "App流量统计数据检索成功",list, 0);
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "App流量统计数据检索成功", list,
0);
}
/**
* App统计详情图与表
*/
@RequestMapping(value="trafficAppList", method = RequestMethod.GET)
@RequestMapping(value = "trafficAppList", method = RequestMethod.GET)
@ApiOperation(value = "App统计占比与报表", httpMethod = "GET", notes = "对应App统计详情占比与报表")
public Map<String,?> trafficAppList(Integer appType,String beginDate,String endDate,Model model, HttpServletRequest request, HttpServletResponse response){
public Map<String, ?> trafficAppList(Integer appType, String beginDate, String endDate, Model model,
HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<HashMap> list = new ArrayList<HashMap>();
try {
List<Map> appList = dashboardService.getAppList(beginDate,endDate,appType);
if (appList!=null&&appList.size() > 0) {
List<Map> appList = dashboardService.getAppList(beginDate, endDate, appType);
if (appList != null && appList.size() > 0) {
String jsonString = JsonMapper.toJsonString(appList);
list = (java.util.List<HashMap>) JsonMapper.fromJsonList(jsonString,HashMap.class);
list = (java.util.List<HashMap>) JsonMapper.fromJsonList(jsonString, HashMap.class);
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("App统计图表数据检索失败:"+e.getMessage());
logger.error("App统计图表数据检索失败:"+ExceptionUtil.getExceptionMsg(e));
auditLogThread.setExceptionInfo("App统计图表数据检索失败:" + e.getMessage());
logger.error("App统计图表数据检索失败:" + ExceptionUtil.getExceptionMsg(e));
if (e instanceof RestServiceException) {
throw new RestServiceException(auditLogThread, System.currentTimeMillis() - start,
"App统计图表数据检索失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
@@ -461,23 +496,25 @@ public class DashboardServiceController extends BaseRestController {
"App统计图表数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "App统计图表数据检索成功",
list, 0);
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "App统计图表数据检索成功", list,
0);
}
@RequestMapping(value = "trafficOsList", method = RequestMethod.GET)
@ApiOperation(value = "操作系统流量分析统计", httpMethod = "GET", notes = "对应终端用户的操作系统列表显示")
public Map<String,?> trafficOsList(Model model, HttpServletRequest request, HttpServletResponse response) {
public Map<String, ?> trafficOsList(Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<Map> list = new ArrayList<Map>();
try {
List<Map> osChart = dashboardService.systemList();
if (osChart!=null&&osChart.size() > 0) {
if (osChart != null && osChart.size() > 0) {
list = osChart;
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("操作系统流量分析统计检索失败:"+e.getMessage());
logger.error("操作系统流量分析统计检索失败:"+ExceptionUtil.getExceptionMsg(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());
@@ -489,23 +526,27 @@ public class DashboardServiceController extends BaseRestController {
"操作系统流量分析统计检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "操作系统流量分析统计检索成功",list, 0);
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "操作系统流量分析统计检索成功", list,
0);
}
@RequestMapping(value = "trafficBrowserChart", method = RequestMethod.GET)
@ApiOperation(value = "操作系统下浏览器流量分析统计", httpMethod = "GET", notes = "对应终端用户某个操作系统的浏览器分类统计显示")
public Map<String, ?> trafficBrowserChart(Integer osType,Model model, HttpServletRequest request, HttpServletResponse response) {
public Map<String, ?> trafficBrowserChart(Integer osType, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<Map> list = new ArrayList<Map>();
try {
List<Map> osChart = dashboardService.getBrowserBySystem(osType);
if (osChart!=null&&osChart.size() > 0) {
list=osChart;
if (osChart != null && osChart.size() > 0) {
list = osChart;
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("操作系统下浏览器分类统计数据检索失败:"+e.getMessage());
logger.error("操作系统下浏览器分类统计数据检索失败:"+ExceptionUtil.getExceptionMsg(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());
@@ -517,22 +558,25 @@ public class DashboardServiceController extends BaseRestController {
"操作系统下浏览器分类统计数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "操作系统下浏览器分类统计数据检索成功",list, 0);
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "操作系统下浏览器分类统计数据检索成功",
list, 0);
}
@RequestMapping(value = "trafficBsList", method = RequestMethod.GET)
@ApiOperation(value = "浏览器流量分析统计", httpMethod = "GET", notes = "对应终端用户的浏览器列表显示")
public Map<String, ?> trafficBsList(Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<Map> list = new ArrayList<Map>();
try {
List<Map> bsChart = dashboardService.browserList();
if (bsChart!=null&&bsChart.size() > 0) {
if (bsChart != null && bsChart.size() > 0) {
list = bsChart;
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("浏览器流量分析统计数据检索失败:"+e.getMessage());
logger.error("浏览器流量分析统计数据检索失败:"+ExceptionUtil.getExceptionMsg(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());
@@ -544,23 +588,27 @@ public class DashboardServiceController extends BaseRestController {
"浏览器流量分析统计数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "浏览器流量分析统计数据检索成功",list, 0);
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "浏览器流量分析统计数据检索成功", list,
0);
}
@RequestMapping(value = "trafficSystemChart", method = RequestMethod.GET)
@ApiOperation(value = "浏览器下操作系统流量分析统计", httpMethod = "GET", notes = "对应终端用户某个浏览器的操作系统分类统计显示")
public Map<String,?> trafficSystemChart(Integer bsType,Model model, HttpServletRequest request, HttpServletResponse response) {
public Map<String, ?> trafficSystemChart(Integer bsType, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<Map> list = new ArrayList<Map>();
try {
List<Map> bsChart = dashboardService.getSystemBybrowser(bsType);
if (bsChart!=null&&bsChart.size() > 0) {
if (bsChart != null && bsChart.size() > 0) {
list = bsChart;
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("浏览器下操作系统流量统计数据检索失败:"+e.getMessage());
logger.error("浏览器下操作系统流量统计数据检索失败:"+ExceptionUtil.getExceptionMsg(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());
@@ -572,35 +620,33 @@ public class DashboardServiceController extends BaseRestController {
"浏览器下操作系统流量统计数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "浏览器下操作系统流量统计数据检索成功",list, 0);
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "浏览器下操作系统流量统计数据检索成功",
list, 0);
}
@RequestMapping(value = "trafficWebsiteList", method = RequestMethod.GET)
@ApiOperation(value = "网站流量分析统计", httpMethod = "GET", notes = "对应网站http分类显示")
public Map<String,?> trafficWebsiteList(String beginDate,String endDate,Model model, HttpServletRequest request, HttpServletResponse response) {
public Map<String, ?> trafficWebsiteList(@RequestParam String beginDate, @RequestParam String endDate, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<Map> list = new ArrayList<Map>();
try {
if(!StringUtils.isEmpty(beginDate)&&!StringUtils.isEmpty(endDate)) {
if (!StringUtils.isEmpty(beginDate) && !StringUtils.isEmpty(endDate)) {
Date begin = DateUtils.parseDate(beginDate);
Date end = DateUtils.parseDate(endDate);
// 带查询时间查询所有
List<Map> websiteChart = dashboardService.getWebsiteDetails(begin,end);
if (websiteChart!=null&&websiteChart.size() > 0) {
list = websiteChart;
}
}else {
// 不带时间默认top10
List<Map> websiteChart = dashboardService.getWebsiteTop10();
if (websiteChart!=null&&websiteChart.size() > 0) {
List<Map> websiteChart = dashboardService.getWebsiteDetails(begin, end);
if (websiteChart != null && websiteChart.size() > 0) {
list = websiteChart;
}
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("网站流量分析统计数据检索失败:"+e.getMessage());
logger.error("网站流量分析统计数据检索失败:"+ExceptionUtil.getExceptionMsg(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());
@@ -612,35 +658,73 @@ public class DashboardServiceController extends BaseRestController {
"网站流量分析统计数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "网站流量分析统计数据检索成功",list, 0);
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "网站流量分析统计数据检索成功", list,
0);
}
@RequestMapping(value = "trafficWebTypeChart", method = RequestMethod.GET)
@ApiOperation(value = "HTTP网站分类分析统计", httpMethod = "GET", notes = "对应某个网站类型分类统计图")
public Map<String, ?> trafficWebTypeChart(String beginDate,String endDate,Integer websiteServiceId,Model model, HttpServletRequest request, HttpServletResponse response) {
@RequestMapping(value = "trafficWebsiteListNoTime", method = RequestMethod.GET)
@ApiOperation(value = "网站流量分析统计", httpMethod = "GET", notes = "对应网站http分类显示")
public Map<String, ?> trafficWebsiteListNoTime(Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<Map> list = new ArrayList<Map>();
try {
if(!StringUtils.isEmpty(beginDate)&&!StringUtils.isEmpty(endDate)) {
// 不带时间默认top10
List<Map> websiteChart = dashboardService.getWebsiteTop10();
if (websiteChart != null && websiteChart.size() > 0) {
list = websiteChart;
}
} 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, "网站流量分析统计数据检索成功", list,
0);
}
@RequestMapping(value = "trafficWebTypeChart", method = RequestMethod.GET)
@ApiOperation(value = "HTTP网站分类分析统计", httpMethod = "GET", notes = "对应某个网站类型分类统计图")
public Map<String, ?> trafficWebTypeChart(String beginDate, String endDate, Integer websiteServiceId, Model model,
HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<Map> list = new ArrayList<Map>();
try {
if (!StringUtils.isEmpty(beginDate) && !StringUtils.isEmpty(endDate)) {
Date begin = DateUtils.parseDate(beginDate);
Date end = DateUtils.parseDate(endDate);
// 带查询时间查询所有
List<Map> websiteChart = dashboardService.getWebsiteDetailsById(websiteServiceId,begin,end);
if (websiteChart!=null&&websiteChart.size() > 0) {
List<Map> websiteChart = dashboardService.getWebsiteDetailsById(websiteServiceId, begin, end);
if (websiteChart != null && websiteChart.size() > 0) {
list = websiteChart;
}
}else {
} else {
// 不带时间默认top10
List<Map> websiteChart = dashboardService.getWebsiteTop10ById(websiteServiceId);
if (websiteChart!=null&&websiteChart.size() > 0) {
List<Map> websiteChart = dashboardService.getWebsiteDetailsById(websiteServiceId, null, null);
if (websiteChart != null && websiteChart.size() > 0) {
list = websiteChart;
}
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("HTTP网站分类分析统计失败:"+e.getMessage());
logger.error("HTTP网站分类分析统计失败:"+ExceptionUtil.getExceptionMsg(e));
auditLogThread.setExceptionInfo("HTTP网站分类分析统计失败:" + e.getMessage());
logger.error("HTTP网站分类分析统计失败:" + ExceptionUtil.getExceptionMsg(e));
if (e instanceof RestServiceException) {
throw new RestServiceException(auditLogThread, System.currentTimeMillis() - start,
"HTTP网站分类分析统计失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
@@ -652,34 +736,38 @@ public class DashboardServiceController extends BaseRestController {
"HTTP网站分类分析统计失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "HTTP网站分类分析统计成功",list, 0);
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "HTTP网站分类分析统计成功", list,
0);
}
@RequestMapping(value = "trafficTopicAndDomainChart", method = RequestMethod.GET)
@ApiOperation(value = "HTTP网站主题分类分析统计", httpMethod = "GET", notes = "对应某个网站主题类型分类统计图")
public Map<String, ?> trafficTopicAndDomainChart(String beginDate,String endDate,Model model, HttpServletRequest request, HttpServletResponse response) {
public Map<String, ?> trafficTopicAndDomainChart(String beginDate, String endDate, Model model,
HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List<Map> list = new ArrayList<Map>();
try {
if(!StringUtils.isEmpty(beginDate)&&!StringUtils.isEmpty(endDate)) {
if (!StringUtils.isEmpty(beginDate) && !StringUtils.isEmpty(endDate)) {
Date begin = DateUtils.parseDate(beginDate);
Date end = DateUtils.parseDate(endDate);
// 带查询时间查询所有
List<Map> websiteChart = dashboardService.getTopicDetails(begin,end);
if (websiteChart!=null&&websiteChart.size() > 0) {
List<Map> websiteChart = dashboardService.getTopicDetails(begin, end);
if (websiteChart != null && websiteChart.size() > 0) {
list = websiteChart;
}
}else {
} else {
// 不带时间默认top10
List<Map> websiteChart = dashboardService.getTopicTop10();
if (websiteChart!=null&&websiteChart.size() > 0) {
if (websiteChart != null && websiteChart.size() > 0) {
list = websiteChart;
}
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("HTTP网站主题分类分析数据检索失败:"+e.getMessage());
logger.error("HTTP网站主题分类分析数据检索失败:"+ExceptionUtil.getExceptionMsg(e));
auditLogThread.setExceptionInfo("HTTP网站主题分类分析数据检索失败:" + e.getMessage());
logger.error("HTTP网站主题分类分析数据检索失败:" + ExceptionUtil.getExceptionMsg(e));
if (e instanceof RestServiceException) {
throw new RestServiceException(auditLogThread, System.currentTimeMillis() - start,
"HTTP网站主题分类分析数据检索失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
@@ -691,6 +779,7 @@ public class DashboardServiceController extends BaseRestController {
"HTTP网站主题分类分析数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "HTTP网站主题分类分析数据检索成功",list, 0);
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "HTTP网站主题分类分析数据检索成功",
list, 0);
}
}

View File

@@ -1,5 +1,6 @@
package com.nis.web.controller.restful;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -16,6 +17,7 @@ import com.nis.domain.Page;
import com.nis.domain.restful.NtcAttrTypeReport;
import com.nis.domain.restful.NtcDestipCountryReport;
import com.nis.domain.restful.NtcEntranceReport;
import com.nis.domain.restful.NtcIpRangeReport;
import com.nis.domain.restful.NtcLwhhReport;
import com.nis.domain.restful.NtcPzReport;
import com.nis.domain.restful.NtcRadiusReport;
@@ -36,25 +38,33 @@ import com.nis.web.service.ServicesRequestLogService;
import com.nis.web.service.restful.NtcReportService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.zdjizhi.utils.IPUtil;
import com.zdjizhi.utils.StringUtil;
/**
*
* <p>Title: SingleDimensionReport</p>
* <p>Description: 单维度统计查询报表controller</p>
* <p>Company: IIE</p>
* <p>
* Title: SingleDimensionReport
* </p>
* <p>
* Description: 单维度统计查询报表controller
* </p>
* <p>
* Company: IIE
* </p>
*
* @author rkg
* @date 2018年7月24日
* @date 2018年7月24日
*
*/
@RestController
@RequestMapping("${servicePath}/log/v1")
@Api(value = "SingleDimensionReport", description = "单维度统计查询报表controller")
public class SingleDimensionReport extends BaseRestController {
@Autowired
protected ServicesRequestLogService servicesRequestLogService;
@Autowired
protected NtcReportService ntcReportService;
@@ -63,16 +73,16 @@ public class SingleDimensionReport extends BaseRestController {
public Map<String, ?> ntcPzReport(Page page, NtcPzReport ntcPzReport, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
Page<?> ntcPzReportPage = null;
try {
resetReportTime(ntcPzReport,true);
//验证实时报表
resetReportTime(ntcPzReport, true);
// 验证实时报表
ntcReportService.queryReportConditionCheck(saveLogThread, start, ntcPzReport, NtcPzReport.class, page);
//验证serachCfgId
ntcReportService.checkNumericCondition(saveLogThread,start,ntcPzReport.getSearchCfgId(),"searchCfgId");
// 验证serachCfgId
ntcReportService.checkNumericCondition(saveLogThread, start, ntcPzReport.getSearchCfgId(), "searchCfgId");
String orderBy = "";
if (null != page.getOrderBy() && !page.getOrderBy().equals("")) {
orderBy = Page.getOrderBySql(NtcPzReport.class.getSimpleName(), page.getOrderBy());
@@ -80,11 +90,11 @@ public class SingleDimensionReport extends BaseRestController {
orderBy = "report_time";
}
page.setOrderBy(orderBy);
ntcPzReportPage = ntcReportService.findNtcPzReport(new Page<NtcPzReport>(request, response, NtcPzReport.class),
ntcPzReport);
ntcPzReportPage = ntcReportService
.findNtcPzReport(new Page<NtcPzReport>(request, response, NtcPzReport.class), ntcPzReport);
} catch (Exception e) {
saveLogThread.setExceptionInfo("配置日志总量统计失败:"+e.getMessage());
logger.error("配置日志总量统计失败:"+ExceptionUtil.getExceptionMsg(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());
@@ -103,16 +113,17 @@ public class SingleDimensionReport extends BaseRestController {
@RequestMapping(value = "/ntcServiceReport", method = RequestMethod.GET)
@ApiOperation(value = "业务类型统计查询服务", httpMethod = "GET", notes = "业务类型统计查询服务基于业务类型service维度聚合")
public Map<String, ?> ntcServiceReport(Page page, NtcServiceReport ntcServiceReport, Model model, HttpServletRequest request,
HttpServletResponse response) {
public Map<String, ?> ntcServiceReport(Page page, NtcServiceReport ntcServiceReport, Model model,
HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
Page<?> reportPage = null;
try {
resetReportTime(ntcServiceReport,false);
ntcReportService.queryReportConditionCheck(saveLogThread, start, ntcServiceReport, NtcServiceReport.class, page);
resetReportTime(ntcServiceReport, false);
ntcReportService.queryReportConditionCheck(saveLogThread, start, ntcServiceReport, NtcServiceReport.class,
page);
String orderBy = "";
if (null != page.getOrderBy() && !page.getOrderBy().equals("")) {
orderBy = Page.getOrderBySql(NtcServiceReport.class.getSimpleName(), page.getOrderBy());
@@ -120,11 +131,11 @@ public class SingleDimensionReport extends BaseRestController {
orderBy = "report_time";
}
page.setOrderBy(orderBy);
reportPage = ntcReportService.findNtcServiceReport(new Page<NtcServiceReport>(request, response, NtcServiceReport.class),
ntcServiceReport);
reportPage = ntcReportService.findNtcServiceReport(
new Page<NtcServiceReport>(request, response, NtcServiceReport.class), ntcServiceReport);
} catch (Exception e) {
saveLogThread.setExceptionInfo("业务类型统计查询失败:"+e.getMessage());
logger.error("业务类型统计查询失败:"+ExceptionUtil.getExceptionMsg(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());
@@ -137,26 +148,24 @@ public class SingleDimensionReport extends BaseRestController {
}
}
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "业务类型统计查询成功",
reportPage, 0);
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "业务类型统计查询成功", reportPage,
0);
}
@RequestMapping(value = "/ntcTagReport", method = RequestMethod.GET)
@ApiOperation(value = "标签统计查询服务", httpMethod = "GET", notes = "标签统计查询服务基于标签与业务类型service维度聚合")
public Map<String, ?> ntcTagReport(Page page, NtcTagReport ntcTagReport, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
Page<?> reportPage = null;
try {
resetReportTime(ntcTagReport,false);
resetReportTime(ntcTagReport, false);
ntcReportService.queryReportConditionCheck(saveLogThread, start, ntcTagReport, NtcTagReport.class, page);
//验证serachTag
ntcReportService.checkNumericCondition(saveLogThread,start,ntcTagReport.getSearchTag(),"searchTag");
// 验证serachTag
ntcReportService.checkNumericCondition(saveLogThread, start, ntcTagReport.getSearchTag(), "searchTag");
String orderBy = "";
if (null != page.getOrderBy() && !page.getOrderBy().equals("")) {
orderBy = Page.getOrderBySql(NtcTagReport.class.getSimpleName(), page.getOrderBy());
@@ -164,11 +173,11 @@ public class SingleDimensionReport extends BaseRestController {
orderBy = "report_time";
}
page.setOrderBy(orderBy);
reportPage = ntcReportService.findNtcTagReport(new Page<NtcTagReport>(request, response, NtcTagReport.class),
ntcTagReport);
reportPage = ntcReportService
.findNtcTagReport(new Page<NtcTagReport>(request, response, NtcTagReport.class), ntcTagReport);
} catch (Exception e) {
saveLogThread.setExceptionInfo("标签统计查询失败:"+e.getMessage());
logger.error("标签统计查询失败:"+ExceptionUtil.getExceptionMsg(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());
@@ -181,23 +190,26 @@ public class SingleDimensionReport extends BaseRestController {
}
}
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "标签统计查询成功",
reportPage, 0);
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "标签统计查询成功", reportPage,
0);
}
@RequestMapping(value = "/ntcAttrTypeReport", method = RequestMethod.GET)
@ApiOperation(value = "性质统计查询服务", httpMethod = "GET", notes = "性质统计查询服务基于性质与业务类型service维度聚合")
public Map<String, ?> ntcAttrTypeReport(Page page, NtcAttrTypeReport ntcAttrTypeReport, Model model, HttpServletRequest request,
HttpServletResponse response) {
public Map<String, ?> ntcAttrTypeReport(Page page, NtcAttrTypeReport ntcAttrTypeReport, Model model,
HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
Page<?> reportPage = null;
try {
resetReportTime(ntcAttrTypeReport,false);
ntcReportService.queryReportConditionCheck(saveLogThread, start, ntcAttrTypeReport, NtcAttrTypeReport.class, page);
//验证searchAttrType
ntcReportService.checkNumericCondition(saveLogThread,start,ntcAttrTypeReport.getSearchAttrType(),"searchAttrType");
resetReportTime(ntcAttrTypeReport, false);
ntcReportService.queryReportConditionCheck(saveLogThread, start, ntcAttrTypeReport, NtcAttrTypeReport.class,
page);
// 验证searchAttrType
ntcReportService.checkNumericCondition(saveLogThread, start, ntcAttrTypeReport.getSearchAttrType(),
"searchAttrType");
String orderBy = "";
if (null != page.getOrderBy() && !page.getOrderBy().equals("")) {
orderBy = Page.getOrderBySql(NtcAttrTypeReport.class.getSimpleName(), page.getOrderBy());
@@ -205,11 +217,11 @@ public class SingleDimensionReport extends BaseRestController {
orderBy = "report_time";
}
page.setOrderBy(orderBy);
reportPage = ntcReportService.findNtcAttrTypeReport(new Page<NtcAttrTypeReport>(request, response, NtcAttrTypeReport.class),
ntcAttrTypeReport);
reportPage = ntcReportService.findNtcAttrTypeReport(
new Page<NtcAttrTypeReport>(request, response, NtcAttrTypeReport.class), ntcAttrTypeReport);
} catch (Exception e) {
saveLogThread.setExceptionInfo("性质统计查询失败:"+e.getMessage());
logger.error("性质统计查询失败:"+ExceptionUtil.getExceptionMsg(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());
@@ -222,25 +234,25 @@ public class SingleDimensionReport extends BaseRestController {
}
}
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "性质统计查询成功",
reportPage, 0);
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "性质统计查询成功", reportPage,
0);
}
@RequestMapping(value = "/ntcLwhhReport", method = RequestMethod.GET)
@ApiOperation(value = "来文函号统计查询服务", httpMethod = "GET", notes = "来文函号统计查询服务基于来文函号与业务类型service维度聚合")
public Map<String, ?> ntcLwhhReport(Page page, NtcLwhhReport ntcLwhhReport, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
Page<?> reportPage = null;
try {
resetReportTime(ntcLwhhReport,false);
//验证实时报表
resetReportTime(ntcLwhhReport, false);
// 验证实时报表
ntcReportService.queryReportConditionCheck(saveLogThread, start, ntcLwhhReport, NtcLwhhReport.class, page);
//验证serachCfgId
ntcReportService.checkNumericCondition(saveLogThread,start,ntcLwhhReport.getSearchLwhh(),"searchLwhh");
// 验证serachCfgId
ntcReportService.checkNumericCondition(saveLogThread, start, ntcLwhhReport.getSearchLwhh(), "searchLwhh");
String orderBy = "";
if (null != page.getOrderBy() && !page.getOrderBy().equals("")) {
orderBy = Page.getOrderBySql(NtcLwhhReport.class.getSimpleName(), page.getOrderBy());
@@ -248,11 +260,11 @@ public class SingleDimensionReport extends BaseRestController {
orderBy = "report_time";
}
page.setOrderBy(orderBy);
reportPage = ntcReportService.findNtcLwhhReport(new Page<NtcLwhhReport>(request, response, NtcLwhhReport.class),
ntcLwhhReport);
reportPage = ntcReportService
.findNtcLwhhReport(new Page<NtcLwhhReport>(request, response, NtcLwhhReport.class), ntcLwhhReport);
} catch (Exception e) {
saveLogThread.setExceptionInfo("来文函号统计查询失败:"+e.getMessage());
logger.error("来文函号统计查询失败:"+ExceptionUtil.getExceptionMsg(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());
@@ -265,23 +277,24 @@ public class SingleDimensionReport extends BaseRestController {
}
}
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "来文函号统计查询成功",
reportPage, 0);
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "来文函号统计查询成功", reportPage,
0);
}
@RequestMapping(value = "/ntcSrcipDomesticReport", method = RequestMethod.GET)
@ApiOperation(value = "境内源IP统计查询服务", httpMethod = "GET", notes = "境内源IP统计查询服务基于源IP所属省、市与业务类型service维度聚合")
public Map<String, ?> ntcSrcipDomesticReport(Page page, NtcSrcipDomesticReport ntcSrcipDomesticReport, Model model, HttpServletRequest request,
HttpServletResponse response) {
public Map<String, ?> ntcSrcipDomesticReport(Page page, NtcSrcipDomesticReport ntcSrcipDomesticReport, Model model,
HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
Page<?> reportPage = null;
try {
resetReportTime(ntcSrcipDomesticReport,false);
//验证实时报表
ntcReportService.queryReportConditionCheck(saveLogThread, start, ntcSrcipDomesticReport, NtcSrcipDomesticReport.class, page);
resetReportTime(ntcSrcipDomesticReport, false);
// 验证实时报表
ntcReportService.queryReportConditionCheck(saveLogThread, start, ntcSrcipDomesticReport,
NtcSrcipDomesticReport.class, page);
String orderBy = "";
if (null != page.getOrderBy() && !page.getOrderBy().equals("")) {
orderBy = Page.getOrderBySql(NtcSrcipDomesticReport.class.getSimpleName(), page.getOrderBy());
@@ -289,11 +302,12 @@ public class SingleDimensionReport extends BaseRestController {
orderBy = "report_time";
}
page.setOrderBy(orderBy);
reportPage = ntcReportService.findNtcSrcipDomesticReport(new Page<NtcSrcipDomesticReport>(request, response, NtcSrcipDomesticReport.class),
reportPage = ntcReportService.findNtcSrcipDomesticReport(
new Page<NtcSrcipDomesticReport>(request, response, NtcSrcipDomesticReport.class),
ntcSrcipDomesticReport);
} catch (Exception e) {
saveLogThread.setExceptionInfo("境内源IP统计查询失败:"+e.getMessage());
logger.error("境内源IP统计查询失败:"+ExceptionUtil.getExceptionMsg(e));
saveLogThread.setExceptionInfo("境内源IP统计查询失败:" + e.getMessage());
logger.error("境内源IP统计查询失败:" + ExceptionUtil.getExceptionMsg(e));
if (e instanceof RestServiceException) {
throw new RestServiceException(saveLogThread, System.currentTimeMillis() - start,
"境内源IP统计查询失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
@@ -306,10 +320,10 @@ public class SingleDimensionReport extends BaseRestController {
}
}
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "境内源IP统计查询成功",
reportPage, 0);
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "境内源IP统计查询成功", reportPage,
0);
}
@RequestMapping(value = "/ntcDestipCountryReport", method = RequestMethod.GET)
@ApiOperation(value = "各国家目的IP统计查询服务", httpMethod = "GET", notes = "各国家目的IP统计查询服务基于目的IP所属国家与业务类型service维度聚合")
public Map<String, ?> ntcDestipCountryReport(Page page, NtcDestipCountryReport ntcDestipCountryReport, Model model,
@@ -320,7 +334,7 @@ public class SingleDimensionReport extends BaseRestController {
Page<?> reportPage = null;
try {
resetReportTime(ntcDestipCountryReport,false);
resetReportTime(ntcDestipCountryReport, false);
// 验证实时报表
ntcReportService.queryReportConditionCheck(saveLogThread, start, ntcDestipCountryReport,
NtcDestipCountryReport.class, page);
@@ -335,8 +349,8 @@ public class SingleDimensionReport extends BaseRestController {
new Page<NtcDestipCountryReport>(request, response, NtcDestipCountryReport.class),
ntcDestipCountryReport);
} catch (Exception e) {
saveLogThread.setExceptionInfo("各国家目的IP统计查询失败:"+e.getMessage());
logger.error("各国家目的IP统计查询失败:"+ExceptionUtil.getExceptionMsg(e));
saveLogThread.setExceptionInfo("各国家目的IP统计查询失败:" + e.getMessage());
logger.error("各国家目的IP统计查询失败:" + ExceptionUtil.getExceptionMsg(e));
if (e instanceof RestServiceException) {
throw new RestServiceException(saveLogThread, System.currentTimeMillis() - start,
"各国家目的IP统计查询失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
@@ -363,7 +377,7 @@ public class SingleDimensionReport extends BaseRestController {
Page<?> reportPage = null;
try {
resetReportTime(ntcEntranceReport,false);
resetReportTime(ntcEntranceReport, false);
ntcReportService.queryReportConditionCheck(saveLogThread, start, ntcEntranceReport, NtcEntranceReport.class,
page);
// 验证searchEntrance
@@ -379,8 +393,8 @@ public class SingleDimensionReport extends BaseRestController {
reportPage = ntcReportService.findNtcEntranceReport(
new Page<NtcEntranceReport>(request, response, NtcEntranceReport.class), ntcEntranceReport);
} catch (Exception e) {
saveLogThread.setExceptionInfo("运营商局点统计查询失败:"+e.getMessage());
logger.error("运营商局点统计查询失败:"+ExceptionUtil.getExceptionMsg(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());
@@ -396,35 +410,19 @@ public class SingleDimensionReport extends BaseRestController {
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "运营商局点统计查询成功", reportPage,
0);
}
@RequestMapping(value = "/ntcURLReport", method = RequestMethod.GET)
@ApiOperation(value = "URL统计查询服务", httpMethod = "GET", notes = "URL统计查询服务")
public Map<String, ?> ntcURLReport(Page page, NtcURLReport urlReport, Model model,
HttpServletRequest request, HttpServletResponse response) {
public Map<String, ?> ntcURLReport(Page page, NtcURLReport urlReport, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
Page<?> reportPage = null;
try {
resetReportTime(urlReport,false);
ntcReportService.queryReportConditionCheck(saveLogThread, start, urlReport, NtcURLReport.class,
page);
resetReportTime(urlReport, false);
ntcReportService.queryReportConditionCheck(saveLogThread, start, urlReport, NtcURLReport.class, page);
String orderBy = "";
if (null != page.getOrderBy() && !page.getOrderBy().equals("")) {
orderBy = Page.getOrderBySql(NtcURLReport.class.getSimpleName(), page.getOrderBy());
@@ -432,11 +430,11 @@ public class SingleDimensionReport extends BaseRestController {
orderBy = "report_time";
}
page.setOrderBy(orderBy);
reportPage = ntcReportService.findNtcURLReport(
new Page<NtcURLReport>(request, response, NtcURLReport.class), urlReport);
reportPage = ntcReportService
.findNtcURLReport(new Page<NtcURLReport>(request, response, NtcURLReport.class), urlReport);
} catch (Exception e) {
saveLogThread.setExceptionInfo("URL统计查询失败:"+e.getMessage());
logger.error("URL统计查询失败:"+ExceptionUtil.getExceptionMsg(e));
saveLogThread.setExceptionInfo("URL统计查询失败:" + e.getMessage());
logger.error("URL统计查询失败:" + ExceptionUtil.getExceptionMsg(e));
if (e instanceof RestServiceException) {
throw new RestServiceException(saveLogThread, System.currentTimeMillis() - start,
"URL统计查询失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
@@ -452,30 +450,22 @@ public class SingleDimensionReport extends BaseRestController {
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "URL统计查询成功", reportPage,
0);
}
@RequestMapping(value = "/ntcRadiusReport", method = RequestMethod.GET)
@ApiOperation(value = "用户行为统计查询服务", httpMethod = "GET", notes = "用户行为统计查询服务基于用户名或接入IP维度聚合")
public Map<String, ?> ntcRadiusReport(NtcRadiusReport ntcRadiusReport, Model model,
HttpServletRequest request, HttpServletResponse response) {
public Map<String, ?> ntcRadiusReport(NtcRadiusReport ntcRadiusReport, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List dataList = null;
try {
ntcReportService.checkNtcRadiusReportCondition(saveLogThread, start, ntcRadiusReport);
dataList= ntcReportService.findNtcRadiusReport(ntcRadiusReport);
dataList = ntcReportService.findNtcRadiusReport(ntcRadiusReport);
} catch (Exception e) {
saveLogThread.setExceptionInfo("用户行为统计查询失败:"+e.getMessage());
logger.error("用户行为统计查询失败:"+ExceptionUtil.getExceptionMsg(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());
@@ -491,39 +481,75 @@ public class SingleDimensionReport extends BaseRestController {
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "用户行为统计查询成功", dataList,
0);
}
/**
* @Description:
* @author (zdx)
* @date 2018年7月12日 上午11:01:30
* @param entity
* @throws Exception
*/
public void resetReportTime(NtcReportEntity<?> entity,Boolean isTotal) throws Exception {
//日志总量统计查询全部
if ("1".equals(entity.getSearchBusinessType())&&isTotal) {
return ;
@RequestMapping(value = "/ntcIpRangeReport", method = RequestMethod.GET)
@ApiOperation(value = "ip范围段统计查询服务", httpMethod = "GET", notes = "ip范围段统计查询服务")
public Map<String, ?> ntcIpRangeReport(Page page, NtcIpRangeReport ntcIpRangeReport, Model model,
HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
try {
// List<NtcIpRangeReport> list=new ArrayList<>();
// ntcIpRangeReport.setIpStart("192.168.10.121");
// ntcIpRangeReport.setIpEnd("192.168.10.122");
// ntcIpRangeReport.setIpEndNum(3232238202l);
// ntcIpRangeReport.setIpStartNum(3232238201l);
// ntcIpRangeReport.setIpSub("255.255.255.252");
// list.add(ntcIpRangeReport);
page.setList( ntcReportService.findNtcIpRangeReport(ntcIpRangeReport));
} catch (Exception e) {
saveLogThread.setExceptionInfo("ip范围段统计查询失败:" + e.getMessage());
logger.error("ip范围段统计查询失败:" + ExceptionUtil.getExceptionMsg(e));
if (e instanceof RestServiceException) {
throw new RestServiceException(saveLogThread, System.currentTimeMillis() - start,
"ip范围段统计查询失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
} else if (e instanceof ServiceRuntimeException) {
throw new ServiceRuntimeException(saveLogThread, System.currentTimeMillis() - start,
"ip范围段统计查询失败:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode());
} else {
throw new ServiceRuntimeException(saveLogThread, System.currentTimeMillis() - start,
"ip范围段统计查询失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
if (StringUtil.isEmpty(entity.getSearchReportStartTime())&&StringUtil.isEmpty(entity.getSearchReportEndTime())) {
String dateType = "minute"; //默认为分钟
if (!isTotal){
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "ip范围段统计查询成功", page, 0);
}
/**
* @Description:
* @author (zdx)
* @date 2018年7月12日 上午11:01:30
* @param entity
* @throws Exception
*/
public void resetReportTime(NtcReportEntity<?> entity, Boolean isTotal) throws Exception {
// 日志总量统计查询全部
if ("1".equals(entity.getSearchBusinessType()) && isTotal) {
return;
}
if (StringUtil.isEmpty(entity.getSearchReportStartTime())
&& StringUtil.isEmpty(entity.getSearchReportEndTime())) {
String dateType = "minute"; // 默认为分钟
if (!isTotal) {
if (entity.getSearchBusinessType().equals("2")) {
dateType = "hour";
}else if (entity.getSearchBusinessType().equals("3")) {
} else if (entity.getSearchBusinessType().equals("3")) {
dateType = "daily";
}else if (entity.getSearchBusinessType().equals("4")) {
} else if (entity.getSearchBusinessType().equals("4")) {
dateType = "month";
}
}else{
} else {
if (entity.getSearchBusinessType().equals("3")) {
dateType = "hour";
}else if (entity.getSearchBusinessType().equals("4")) {
} else if (entity.getSearchBusinessType().equals("4")) {
dateType = "daily";
}else if (entity.getSearchBusinessType().equals("5")) {
} else if (entity.getSearchBusinessType().equals("5")) {
dateType = "month";
}
}
Map<String, String> map = DateUtils.getLocalTime(entity.getSearchReportStartTime(),
entity.getSearchReportEndTime(), Constants.PZ_REPORT_TIME, dateType);
entity.getSearchReportEndTime(), Constants.PZ_REPORT_TIME, dateType);
entity.setSearchReportStartTime(map.get("startTime"));
entity.setSearchReportEndTime(map.get("endTime"));
}

View File

@@ -5,6 +5,7 @@ import java.util.List;
import com.nis.domain.restful.NtcAttrTypeReport;
import com.nis.domain.restful.NtcDestipCountryReport;
import com.nis.domain.restful.NtcEntranceReport;
import com.nis.domain.restful.NtcIpRangeReport;
import com.nis.domain.restful.NtcIpURLReport;
import com.nis.domain.restful.NtcLwhhReport;
import com.nis.domain.restful.NtcPzReport;
@@ -36,4 +37,7 @@ public interface NtcReportDao extends CrudDao {
List<NtcRadiusReport> findAccounList(NtcRadiusReport pz);
List<NtcRadiusReport> findNasIpList(NtcRadiusReport pz);
List<NtcRadiusReport> findNtcRadiusReport(NtcRadiusReport pz);
List<NtcIpRangeReport> findNtcIpRangeReport(NtcIpRangeReport pz);
}

View File

@@ -87,6 +87,19 @@
property="reportTime" />
</resultMap>
<resultMap id="NtcIpRangeReportMap"
type="com.nis.domain.restful.NtcIpRangeReport">
<result column="ip_start" jdbcType="VARCHAR" property="ipStart" />
<result column="ip_end" jdbcType="VARCHAR" property="ipEnd" />
<result column="ip_start_num" jdbcType="BIGINT"
property="ipStartNum" />
<result column="ip_end_num" jdbcType="BIGINT"
property="ipEndNum" />
<result column="ip_sub" jdbcType="VARCHAR" property="ipSub" />
<result column="country" jdbcType="VARCHAR" property="country" />
</resultMap>
<sql id="commonPorperty">
SERVICE,SUM,REPORT_TIME
</sql>
@@ -835,4 +848,20 @@
ORDER BY
REPORT_TIME ASC
</select>
<select id="findNtcIpRangeReport"
parameterType="com.nis.domain.restful.NtcIpRangeReport"
resultMap="NtcIpRangeReportMap">
SELECT ip_start,ip_end,ip_start_num,ip_end_num,ip_sub
FROM traffic_ip_identify
<where>
<if test="searchType != null and searchType !=''">
<![CDATA[AND areaType = #{searchType}]]>
</if>
<if test="searchCountry != null and searchCountry !=''">
<![CDATA[AND country= #{searchCountry ]]>
</if>
</where>
</select>
</mapper>

View File

@@ -72,7 +72,7 @@
<!-- 获取近一小时的带宽根据ip46协议 tcp,udp变化 -->
<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<=#{endDate} and stat_time>=#{beginDate}]]>
where <![CDATA[stat_time>=#{beginDate} and stat_time<=#{endDate} ]]>
<if test="addrType != null">
and addr_type=#{addrType}
</if>

View File

@@ -18,19 +18,12 @@ public interface TrafficHttpStatisticDao {
// 获取域名分类之后属于的网站
List<Map> getDomainByWebsiteList(@Param("statTime") Date statTime, @Param("endTime") Date endTime);
List<Map> preWebsiteListCount(@Param("statTime") Date statTime, @Param("endTime") Date endTime);
List<Map> getDomainByWebsiteServiceId(@Param("webIdList") List webIdList,@Param("statTime") Date statTime, @Param("endTime") Date endTime);
Map websiteDomainOthers(@Param("webIdList") List webIdList, @Param("statTime") Date statTime,
@Param("endTime") Date endTime);
List<Map> getDomainByTopicList(@Param("statTime") Date statTime, @Param("endTime") Date endTime);
List<Map> getDomainByTopicId(@Param("statTime") Date statTime, @Param("endTime") Date endTime);
List<Map> getTrafficHttpStatistic(@Param("statTime") Date statTime, @Param("endTime") Date endTime);
List getIdByWebSiteId(@Param("websiteId") Integer websiteId);
List<Map> getDomainList(@Param("beginDate")Date beginDate, @Param("endDate") Date endDate);
}

View File

@@ -59,10 +59,13 @@
</select>
<!--获取上个时间段该网站站域名流量的数据量 -->
<select id="preWebsiteListCount" resultType="java.util.HashMap">
select web_id webId,SUM(c2s_byte_len + s2c_byte_len) count from
<select id="getTrafficHttpStatistic" resultType="java.util.HashMap">
select web_id webId,
SUM(c2s_byte_len + s2c_byte_len) byteCount,
sum(c2s_pkt_num + s2c_pkt_num) pktCount,
link_num linkNum from
traffic_http_statistic t where
<![CDATA[ stat_time>= #{statTime} and stat_time< #{endTime} group by t.web_id ]]>
<![CDATA[ stat_time>= #{statTime} and stat_time< #{endTime} group by t.web_id,link_num order by byteCount]]>
</select>
@@ -96,23 +99,6 @@ FROM
SELECT
distinct id FROM ui_website_domain_topic where website_service_id= #{websiteId}
</select>
<!-- 根据主题分组获取子域名 -->
<select id="getDomainByTopicId" resultType="java.util.HashMap">
select web_id webId,link_num linkNum,SUM(c2s_pkt_num+s2c_pkt_num) packets,sum(c2s_byte_len + s2c_byte_len) count from
traffic_http_statistic t where
<![CDATA[ stat_time>= #{statTime} and stat_time< #{endTime} group by t.web_id]]>
</select>
<!-- 获取域名列表 -->
<select id="getDomainList" resultType="java.util.HashMap">
select web_id webId,link_num linkNum,SUM(c2s_pkt_num+s2c_pkt_num) packets,sum(c2s_byte_len + s2c_byte_len) count from
traffic_http_statistic t where
<![CDATA[ stat_time>= #{beginDate} and stat_time< #{endDate} group by t.web_id order by count]]>
</select>
<!-- 指定网站下的TOP10之外为others -->
<select id="websiteDomainOthers" resultType="java.util.HashMap">

View File

@@ -202,6 +202,29 @@ public class LocalLogJDBCByDruid {
return list;
}
public List<String> getAllIp(String frontier) throws Exception {
List<String> list = new LinkedList<>();
try {
String sql = "select distinct ip from ip_location_database_local where ip like '145%' and frontier='"+frontier+"'";
conn = getConnection();
logger.info("连接数据中心日志库成功--------------------------");
st = conn.createStatement();
logger.info("开始执行日志查询语句sql={}", sql);
rs = st.executeQuery(sql);
num.setMinimumFractionDigits(2);// 保留两位小数
while (rs.next()) {
String bps = rs.getString("ip");
if(bps!=null&&!bps.trim().equals("")) {
list.add(bps);
}
}
logger.info("执行日志查询语句成功,sql={}", sql);
} finally {
closeConn();
}
return list;
}
/**
* 截取字符串后两位
*

View File

@@ -14,6 +14,7 @@ import com.nis.domain.Page;
import com.nis.domain.restful.NtcAttrTypeReport;
import com.nis.domain.restful.NtcDestipCountryReport;
import com.nis.domain.restful.NtcEntranceReport;
import com.nis.domain.restful.NtcIpRangeReport;
import com.nis.domain.restful.NtcIpURLReport;
import com.nis.domain.restful.NtcLwhhReport;
import com.nis.domain.restful.NtcPzReport;
@@ -183,4 +184,12 @@ public class NtcReportService extends BaseLogService {
return resultList;
}
public List<NtcIpRangeReport> findNtcIpRangeReport(NtcIpRangeReport entity) throws Exception {
List<NtcIpRangeReport> list = dao.findNtcIpRangeReport(entity);
return list;
}
}

View File

@@ -0,0 +1,153 @@
package com.nis.web.task;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.apache.avro.file.SyncableFileOutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.nis.web.dao.impl.LocalLogJDBCByDruid;
@Component
@PropertySource(value = { "classpath:nis.properties", "classpath:jdbc.properties" })
public class GetIpRangeTask {
private static Logger logger = LoggerFactory.getLogger(GetIpRangeTask.class);
@Autowired
private LocalLogJDBCByDruid localLogJDBCByDruid;
// @Scheduled(cron = "0/5 * * * * ?")
public void test() {
try {
getAllIp4();
} catch (Exception e) {
e.printStackTrace();
}
}
public Map<Long, String> getNumAndIpReal(List<String> allIp) throws InterruptedException, ExecutionException {
logger.info("开始将ip转换为数字");
Map<Long, String> map = new HashMap<>();
int ever = 10000;
int count = allIp.size() / ever;
if (allIp.size() % ever != 0) {
count++;
}
List<Future<Map<Long, String>>> futures = new ArrayList<>();
ExecutorService executor = Executors.newFixedThreadPool(10);
for (int i = 0; i < count; i++) {
int start = i * ever;
int end = i * ever + ever;
if (end > allIp.size()) {
end = allIp.size();
}
IpToLongThread ipToLongThread = new IpToLongThread(allIp.subList(start, end));
Future<Map<Long, String>> res = executor.submit(ipToLongThread);// 异步提交, non blocking.
futures.add(res);
}
executor.shutdown();
for (Future<Map<Long, String>> future : futures) {
try {
map.putAll(future.get());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
logger.info("{}个ip转换为数字成功,转换了{}个", allIp.size(), map.size());
return map;
}
private static String testbb(Long[] NoNum) {
int state = 0;
String result = "";
for (int i = 0; i < NoNum.length; i++) {
if (i == NoNum.length - 1)
state = 2;
if (state == 0) {
if (NoNum[i + 1].longValue() == NoNum[i].longValue() + 1) {
result += String.valueOf(NoNum[i]);
result += "-";
state = 1;
} else {
result += String.valueOf(NoNum[i]);
result += ",";
}
} else if (state == 1) {
if (NoNum[i + 1] != NoNum[i] + 1) {
result += String.valueOf(NoNum[i]);
result += ",";
state = 0;
}
} else {
result += String.valueOf(NoNum[i]);
}
}
return result;
}
public void getAllIp4() throws Exception {
List<String> allIp = localLogJDBCByDruid.getAllIp("1");
Map<Long, String> map = getNumAndIpReal(allIp);
Set<Long> keySet = map.keySet();
List<Long> ipList = new ArrayList<>(keySet);
Long[] array = new Long[ipList.size()];
Collections.sort(ipList);
ipList.toArray(array);
String result = testbb(array);
if (result != null && !result.trim().equals("")) {
String substring = result;
if (result.endsWith(",")) {
substring = result.substring(0, result.length() - 1);
}
String[] split = substring.split(",");
List<Long> list = new ArrayList<>();
for (String str : split) {
String[] ipAddr = str.split("-");
if (ipAddr.length > 1) {
for (String ipStr : ipAddr) {
System.out.print(ipStr + "[" + map.get(Long.parseLong(ipStr)) + "]");
}
System.out.println();
} else {
list.add(Long.parseLong(str));
}
}
Collections.sort(list);
for (int i = 0; i < list.size(); i = i + 2) {
System.out.print(list.get(i) + "[" + map.get(list.get(i)) + "]");
if (i < list.size() - 1) {
System.out.print(list.get(i + 1) + "[" + map.get(list.get(i + 1)) + "]");
}
System.out.println();
}
}
}
public String longToIp(long ip) {
return ((ip >> 24) & 0xFF) + "." + ((ip >> 16) & 0xFF) + "." + ((ip >> 8) & 0xFF) + "." + (ip & 0xFF);
}
}

View File

@@ -0,0 +1,423 @@
package com.nis.web.task;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.apache.avro.file.SyncableFileOutputStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.nis.web.dao.impl.LocalLogJDBCByDruid;
@Component
@PropertySource(value = { "classpath:nis.properties", "classpath:jdbc.properties" })
public class GetIpRangeTask2 {
@Autowired
private LocalLogJDBCByDruid localLogJDBCByDruid;
// @Scheduled(cron = "0/5 * * * * ?")
public void test() {
try {
getAllIp4();
} catch (Exception e) {
e.printStackTrace();
}
}
public Map<Long, String> threadTest(List<String> allIp) throws InterruptedException, ExecutionException {
Map<Long, String> map = new HashMap<>();
int ever = 10000;
int count = allIp.size() / ever;
if (allIp.size() % ever != 0) {
count++;
}
List<Future<Map<Long, String>>> futures = new ArrayList<>();
ExecutorService executor = Executors.newFixedThreadPool(10);
for (int i = 0; i < count; i++) {
int start = i * ever;
int end = i * ever + ever;
if (end > allIp.size()) {
end = allIp.size();
}
IpToLongThread ipToLongThread = new IpToLongThread(allIp.subList(start, end));
Future<Map<Long, String>> res = executor.submit(ipToLongThread);// 异步提交, non blocking.
futures.add(res);
}
executor.shutdown();
System.out.println("开始关闭线程");
for (Future<Map<Long, String>> future : futures) {
try {
map.putAll(future.get());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
System.out.println("list=" + map.size() + ",allIp=" + allIp.size());
System.out.println("线程执行完毕");
return map;
}
private static String testbb(Long[] NoNum) {
int state = 0;
String result = "";
for (int i = 0; i < NoNum.length; i++) {
if (i == NoNum.length - 1)
state = 2;
if (state == 0) {
if (NoNum[i + 1].longValue() == NoNum[i].longValue() + 1) {
result += String.valueOf(NoNum[i]);
result += "-";
state = 1;
} else {
result += String.valueOf(NoNum[i]);
result += ",";
}
} else if (state == 1) {
if (NoNum[i + 1] != NoNum[i] + 1) {
result += String.valueOf(NoNum[i]);
result += ",";
state = 0;
}
} else {
result += String.valueOf(NoNum[i]);
}
}
return result;
}
public void getAllIp4() throws Exception {
List<String> allIp = localLogJDBCByDruid.getAllIp("1");
Map<Long, String> map = threadTest(allIp);
Set<Long> keySet = map.keySet();
List<Long> ipList = new ArrayList<>(keySet);
Long[] array = new Long[ipList.size()];
Collections.sort(ipList);
ipList.toArray(array);
String result = testbb(array);
if (result != null && !result.trim().equals("")) {
String substring = result;
if(result.endsWith(",")) {
substring=result.substring(0, result.length() - 1);
}
String[] split = substring.split(",");
List<Long> list = new ArrayList<>();
for (String str : split) {
String[] ipAddr = str.split("-");
if (ipAddr.length > 1) {
for (String ipStr : ipAddr) {
System.out.print(ipStr + "[" + map.get(Long.parseLong(ipStr)) + "]");
}
System.out.println();
} else {
list.add(Long.parseLong(str));
}
}
Collections.sort(list);
for (int i = 0; i < list.size(); i = i + 2) {
System.out.print(list.get(i) + "[" + map.get(list.get(i)) + "]");
if (i < list.size() - 1) {
System.out.print(list.get(i + 1) + "[" + map.get(list.get(i + 1)) + "]");
}
System.out.println();
}
}
}
public String longToIp(long ip) {
return ((ip >> 24) & 0xFF) + "." + ((ip >> 16) & 0xFF) + "." + ((ip >> 8) & 0xFF) + "." + (ip & 0xFF);
}
public static void main(String[] args) {
// Long [] NoNum = { 2449052146l,
// 2449052148l,
// 2449052136l,
// 2449052139l,
// 2449052138l,
// 2449052141l,
// 2449052128l,
// 2449052134l,
// 2449052120l,
// 2449052124l,
// 2449052127l};
Set<Long> keySet = new HashSet<>();
keySet.add(2449052146l);
keySet.add(2449052136l);
keySet.add(2449052139l);
keySet.add(2449052120l);
List<Long> ipList = new ArrayList<>(keySet);
Long[] array = new Long[ipList.size()];
Collections.sort(ipList);
ipList.toArray(array);
System.out.println(Arrays.toString(array));
Long[] NoNum = { 3l, 2l, 1l };
String testbb = testbb(NoNum);
System.out.println(testbb);
}
public void a() {
int[] NoNum = { 1, 2, 3, 5, 7, 8, 9, 10, 13 };
int state = 0;
String result = "";
for (int i = 0; i < NoNum.length; i++) {
if (i == NoNum.length - 1)
state = 2;
if (state == 0) {
if (NoNum[i + 1] == NoNum[i] + 1) {
result += Integer.toString(NoNum[i]);
result += "-";
state = 1;
} else {
result += Integer.toString(NoNum[i]);
result += ",";
}
} else if (state == 1) {
if (NoNum[i + 1] != NoNum[i] + 1) {
result += Integer.toString(NoNum[i]);
result += ",";
state = 0;
}
} else {
result += Integer.toString(NoNum[i]);
}
}
System.out.println(result);
}
public static String convert(Long[] ints, int index) {
int end = index;
if (ints.length == index) {// 结束条件,遍历完数组
return "";
} else {
for (int i = index; i < ints.length; i++) {
if (i < ints.length - 1) {
if (ints[i] + 1 == ints[i + 1]) {
end = i;
} else {
if (i > index)
end = end + 1;
break;
}
} else {
if (end == ints.length - 2) {
end = ints.length - 1;
break;
}
}
}
if (index == end)// 相等说明不连续
return ints[index] + "," + convert(ints, end + 1);
else// 连续
return ints[index] + "-" + ints[end] + "," + convert(ints, end + 1);
}
}
public void getAllIp() throws Exception {
List<String> allIp = localLogJDBCByDruid.getAllIp("1");
Map<String, Map<Integer, List<Integer>>> map = new HashMap<>();
for (String ip : allIp) {
String topTwo = ip.substring(0, ip.indexOf(".", ip.indexOf(".") + 1));
String lastTwo = ip.substring(ip.indexOf(".", ip.indexOf(".") + 1) + 1);
String[] endIpAddr = lastTwo.split("\\.");
int third = Integer.parseInt(endIpAddr[0]);
int fourth = Integer.parseInt(endIpAddr[1]);
if (map.containsKey(topTwo)) {
Map<Integer, List<Integer>> thridMap = map.get(topTwo);
if (thridMap.containsKey(third)) {
thridMap.get(third).add(fourth);
} else {
List<Integer> list = new ArrayList<>();
list.add(fourth);
thridMap.put(third, list);
}
} else {
Map<Integer, List<Integer>> thridMap = new HashMap<>();
List<Integer> list = new ArrayList<>();
list.add(fourth);
thridMap.put(third, list);
map.put(topTwo, thridMap);
}
}
Map<String, String> rangMap = new HashMap<>();
for (Entry<String, Map<Integer, List<Integer>>> entry : map.entrySet()) {
String topTwo = entry.getKey();
Map<Integer, List<Integer>> endIpMap = entry.getValue();
Set<Integer> keySet = endIpMap.keySet();
ArrayList<Integer> arrayList = new ArrayList<Integer>(keySet);
Collections.sort(arrayList);
Integer minThrid = arrayList.get(0);
Integer maxThrid = arrayList.get(arrayList.size() - 1);
List<Integer> minThridList = endIpMap.get(minThrid);
List<Integer> maxThridList = endIpMap.get(maxThrid);
Collections.sort(minThridList);
Collections.sort(maxThridList);
if (minThridList.size() > 0 && maxThridList.size() > 0) {
rangMap.put(topTwo + "." + minThrid + "." + minThridList.get(0),
topTwo + "." + maxThrid + "." + maxThridList.get(maxThridList.size() - 1));
} else {
System.out.println("1");
}
}
for (String minIp : rangMap.keySet()) {
System.out.println(minIp + "--" + rangMap.get(minIp));
}
}
public void getAllIp2() throws Exception {
Map<String, List<Integer>> map = new HashMap<>();
List<String> allIp = localLogJDBCByDruid.getAllIp("1");
for (String ip : allIp) {
String[] split = ip.split(",");
for (int i = 0; i < split.length; i++) {
String prev = ip.substring(0, ip.lastIndexOf("."));
int forth = Integer.parseInt(ip.substring(ip.lastIndexOf(".") + 1));
if (map.containsKey(prev)) {
map.get(prev).add(forth);
} else {
List<Integer> list = new ArrayList<>();
list.add(forth);
map.put(prev, list);
}
}
}
if (map.size() > 0) {
Map<String, String> ipMap = new HashMap<>();
for (Entry<String, List<Integer>> entry : map.entrySet()) {
String prev = entry.getKey();
List<Integer> endList = entry.getValue();
a(prev, endList, ipMap);
}
Map<String, List<Integer>> map2 = new HashMap<>();
for (String minIp : ipMap.keySet()) {
String endIp = ipMap.get(minIp);
String prev = minIp.substring(0, minIp.lastIndexOf("."));
int minEnd = Integer.parseInt(minIp.substring(minIp.lastIndexOf(".") + 1));
int maxEnd = Integer.parseInt(endIp.substring(endIp.lastIndexOf(".") + 1));
for (int i = minEnd; i <= maxEnd; i++) {
if (map.containsKey(prev)) {
map.get(prev).add(i);
} else {
List<Integer> list = new ArrayList<>();
list.add(i);
map.put(prev, list);
}
}
}
Map<String, String> ipMap2 = new HashMap<>();
for (Entry<String, List<Integer>> entry : map2.entrySet()) {
String prev = entry.getKey();
List<Integer> endList = entry.getValue();
a(prev, endList, ipMap2);
}
for (String minIp : ipMap2.keySet()) {
System.out.println(minIp + "--" + ipMap2.get(minIp));
}
}
}
private void a(String prev, List<Integer> endList, Map<String, String> ipMap) {
Collections.sort(endList);
Integer start = endList.get(0);
if (endList.size() == 256) {// 0-255
ipMap.put(prev + "." + start, prev + ".255");
} else {
for (int i = 0; i < endList.size(); i++) {
Integer curr = endList.get(i);
if (i < endList.size() - 1) {
Integer next = endList.get(i + 1);
if (curr + 1 == next) {
ipMap.put(prev + "." + start, prev + "." + next);
} else {
start = curr;
}
}
}
}
}
public void getAllIp1() throws Exception {
Map<Integer, Map<Integer, Map<Integer, List<Integer>>>> map = new HashMap<>();
List<String> allIp = localLogJDBCByDruid.getAllIp("1");
for (String ip : allIp) {
String[] split = ip.split(",");
for (int i = 0; i < split.length; i++) {
int first = Integer.parseInt(split[0]);
int second = Integer.parseInt(split[1]);
int third = Integer.parseInt(split[2]);
int fourth = Integer.parseInt(split[3]);
if (map.containsKey(first)) {
Map<Integer, Map<Integer, List<Integer>>> secondMap = map.get(first);
if (secondMap.containsKey(second)) {
Map<Integer, List<Integer>> thridMap = secondMap.get(second);
if (thridMap.containsKey(third)) {
thridMap.get(third).add(fourth);
} else {
List<Integer> list = new ArrayList<>();
list.add(fourth);
thridMap.put(third, list);
}
} else {
Map<Integer, List<Integer>> thridMap = new HashMap<>();
List<Integer> list = new ArrayList<>();
list.add(fourth);
thridMap.put(third, list);
secondMap.put(second, thridMap);
}
} else {
Map<Integer, Map<Integer, List<Integer>>> secondMap = new HashMap<>();
Map<Integer, List<Integer>> thridMap = new HashMap<>();
List<Integer> list = new ArrayList<>();
list.add(fourth);
thridMap.put(third, list);
secondMap.put(second, thridMap);
map.put(first, secondMap);
}
}
}
if (map.size() > 0) {
for (Entry<Integer, Map<Integer, Map<Integer, List<Integer>>>> entry : map.entrySet()) {
Integer key = entry.getKey();
}
}
}
}

View File

@@ -0,0 +1,53 @@
package com.nis.web.task;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class IpToLongThread implements Callable<Map<Long, String>> {
private static Logger logger = LoggerFactory.getLogger(IpToLongThread.class);
private List<String> list;
public IpToLongThread(List<String> list) {
super();
this.list = list;
}
public IpToLongThread() {
super();
}
@Override
public Map<Long, String> call() throws Exception {
Map<Long, String> map=new HashMap<>();
logger.info("线程{}开始执行", Thread.currentThread().getName());
for (int i = 0; i < list.size(); i++) {
map.put(ipToLong(list.get(i)), list.get(i));
}
logger.info("线程{}执行结束", Thread.currentThread().getName());
return map;
}
public long ipToLong(String ipAddress) {
long result = 0;
String[] ipAddressInArray = ipAddress.split("\\.");
for (int i = 3; i >= 0; i--) {
long ip = Long.parseLong(ipAddressInArray[3 - i]);
// left shifting 24,16,8,0 and bitwise OR
// 1. 192 << 24
// 1. 168 << 16
// 1. 1 << 8
// 1. 2 << 0
result |= ip << (i * 8);
}
return result;
}
}