From f862efd37862550db05fd155b1163bb1f0ec94a3 Mon Sep 17 00:00:00 2001 From: renkaige Date: Mon, 20 May 2019 14:26:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9v1=E7=89=88=E6=9C=AC=E6=B5=81?= =?UTF-8?q?=E9=87=8F=E7=BB=9F=E8=AE=A1=E5=B8=A6=E5=AE=BD=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BB=8Eclickhouse=E4=B8=AD=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../restful/DashboardServiceController.java | 50 +++++++++++++++++++ .../web/service/restful/DashboardService.java | 38 ++++++++++---- 2 files changed, 77 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/nis/web/controller/restful/DashboardServiceController.java b/src/main/java/com/nis/web/controller/restful/DashboardServiceController.java index 83ce616..2b07da1 100644 --- a/src/main/java/com/nis/web/controller/restful/DashboardServiceController.java +++ b/src/main/java/com/nis/web/controller/restful/DashboardServiceController.java @@ -207,6 +207,53 @@ public class DashboardServiceController extends BaseRestController { AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); Map resultMap = new HashMap(); + try { + if (StringUtils.isEmpty(beginDate) && StringUtils.isEmpty(endDate)) { + Calendar cal = Calendar.getInstance(); + cal.setTime(new Date()); + endDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cal.getTime());// 获取到完整的时间 + cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1); + beginDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cal.getTime()); + } + CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_B); + resultMap = dashboardService.getBandwidthTransByQuoTaType(beginDate, endDate, searchQuotaType, + searchDirection); + } catch (Exception e) { + auditLogThread.setExceptionInfo("带宽实时统计数据检索失败:" + e.getMessage()); + logger.error("带宽实时统计数据检索失败:" + ExceptionUtil.getExceptionMsg(e)); + if (e instanceof RestServiceException) { + throw new RestServiceException(auditLogThread, System.currentTimeMillis() - start, + "带宽实时统计数据检索失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode()); + } else if (e instanceof ServiceRuntimeException) { + throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start, + "带宽实时统计数据检索失败:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode()); + } else { + throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start, + "带宽实时统计数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue()); + } + } finally { + CustomerContextHolder.clearCustomerType(); + } + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "带宽实时统计数据检索成功", + resultMap, 0); + } + + + + + + + /** + * 根据ip46,协议tcp,udp查询带宽 + */ + @RequestMapping(value = "trafficBandwidthTransThreeOld", method = RequestMethod.GET) + @ApiOperation(value = "带宽根据ip46,协议tcp,udp查询详情", httpMethod = "GET", notes = "对应带宽根据IPv4,6,协议tcp,udp统计数据显示") + public Map trafficBandwidthTransThreeOld(String beginDate, String endDate, String searchQuotaType, + Model model, Integer searchDirection, HttpServletRequest request, HttpServletResponse response) { + long start = System.currentTimeMillis(); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); + Map resultMap = new HashMap(); try { if (StringUtils.isEmpty(beginDate) && StringUtils.isEmpty(endDate)) { Calendar cal = Calendar.getInstance(); @@ -235,6 +282,9 @@ public class DashboardServiceController extends BaseRestController { return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "带宽实时统计数据检索成功", resultMap, 0); } + + + /** * 流量统计活跃端口统计 diff --git a/src/main/java/com/nis/web/service/restful/DashboardService.java b/src/main/java/com/nis/web/service/restful/DashboardService.java index c6dff6a..823c45b 100644 --- a/src/main/java/com/nis/web/service/restful/DashboardService.java +++ b/src/main/java/com/nis/web/service/restful/DashboardService.java @@ -37,6 +37,7 @@ import com.nis.domain.restful.dashboard.TrafficIpActiveStatistic; import com.nis.domain.restful.dashboard.TrafficPortActiveStatistic; import com.nis.domain.restful.dashboard.TrafficProtocolStatistic; import com.nis.domain.restful.dashboard.TrafficTransStatistic; +import com.nis.domain.restful.dashboard.TrafficTransStatisticCK; import com.nis.domain.restful.dashboard.TrafficUaStatistic; import com.nis.restful.RestBusinessCode; import com.nis.restful.RestServiceException; @@ -44,6 +45,7 @@ import com.nis.util.Constants; import com.nis.util.DateUtils; import com.nis.util.StringUtils; import com.nis.web.dao.IspInfoDao; +import com.nis.web.dao.TrafficReportDao; import com.nis.web.dao.dashboard.NtcTotalReportDao; import com.nis.web.dao.dashboard.TrafficAppStatisticDao; import com.nis.web.dao.dashboard.TrafficAsnStatisticDao; @@ -76,6 +78,9 @@ public class DashboardService extends BaseService { public TrafficPortActiveStatisticDao trafficPortActiveStatisticDao; @Autowired private IspInfoDao ispInfoDao; + + @Autowired + protected TrafficReportService trafficReportService; // ip地址类型 private final String[] addrTypes = { "4", "6" }; // tcp udp @@ -309,8 +314,7 @@ public class DashboardService extends BaseService { /** * 日期格式字符串转换成时间戳 * - * @param date_str - * 字符串日期 + * @param date_str 字符串日期 * @return */ @Deprecated @@ -327,8 +331,7 @@ public class DashboardService extends BaseService { /** * 时间戳 换成日期格式字符串转 * - * @param timeStamp - * 1544602212000 + * @param timeStamp 1544602212000 * @return */ @Deprecated @@ -1301,6 +1304,22 @@ public class DashboardService extends BaseService { return fieldType == null ? null : fieldType.split(","); } + public Map getBandwidthTransByQuoTaType(String beginDate, String endDate, String searchQuotaType, + Integer searchDirection) { + TrafficTransStatisticCK trafficTransStatisticCK = new TrafficTransStatisticCK(); + trafficTransStatisticCK.setSearchBusinessType(1); + trafficTransStatisticCK.setBeginDate(beginDate); + trafficTransStatisticCK.setEndDate(endDate); + if (searchQuotaType.toLowerCase().equals("gbps")) { + trafficTransStatisticCK.setSearchQuotaType(1); + } else if (searchQuotaType.toLowerCase().equals("pps")) { + trafficTransStatisticCK.setSearchQuotaType(2); + } else if (searchQuotaType.toLowerCase().equals("linknumber")) { + trafficTransStatisticCK.setSearchQuotaType(3); + } + return trafficReportService.getBandwidthTransByQuoTaType(trafficTransStatisticCK); + } + public Map getBandwidthTransEntrance(String beginDate, String endDate, String searchQuotaType, Integer searchDirection) throws ParseException { Map resultMap = new HashMap(); @@ -1782,15 +1801,12 @@ public class DashboardService extends BaseService { } return resultMap; } - - - public Map getAppBpsTrend(TrafficAppBpsStatistic entity) { List list = new ArrayList(); list = trafficAppStatisticDao.getAppBpsTrend(entity); Map resultMap = new HashMap(); - Long gbps = 1024l*1024l*1024l*60l; + Long gbps = 1024l * 1024l * 1024l * 60l; if (!StringUtil.isEmpty(list)) { Date beginDate = DateUtils.parseDate(entity.getSearchStartTime()); Date endDate = DateUtils.parseDate(entity.getSearchEndTime()); @@ -1919,14 +1935,14 @@ public class DashboardService extends BaseService { break; } c2sList.add(date.getTime()); - c2sList.add(c2sNum/60); + c2sList.add(c2sNum / 60); resultC2sList.add(c2sList); s2cList.add(date.getTime()); - s2cList.add(s2cNum/60); + s2cList.add(s2cNum / 60); resultS2cList.add(s2cList); totalList.add(date.getTime()); - totalList.add(totalNum/60); + totalList.add(totalNum / 60); resultTotalList.add(totalList); // c2sTotal+=c2sNum;