From da5db9c07504f7684d7a41af7c02ae28492745ee Mon Sep 17 00:00:00 2001 From: zhanghongqing Date: Tue, 18 Dec 2018 04:59:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=B6=B2=E7=AB=99=E8=A9=B3?= =?UTF-8?q?=E6=83=85=E7=B5=B1=E8=A8=88=E5=9F=9F=E5=90=8D=E7=B5=B1=E8=A8=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dashboard/TrafficHttpFocusStatistic.java | 95 +++++++++++++++++++ .../restful/DashboardServiceController.java | 40 +++++++- .../dashboard/TrafficHttpStatisticDao.java | 5 + .../dao/dashboard/TrafficHttpStatisticDao.xml | 22 +++++ .../web/service/restful/DashboardService.java | 63 +++++++++++- 5 files changed, 218 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/nis/domain/restful/dashboard/TrafficHttpFocusStatistic.java diff --git a/src/main/java/com/nis/domain/restful/dashboard/TrafficHttpFocusStatistic.java b/src/main/java/com/nis/domain/restful/dashboard/TrafficHttpFocusStatistic.java new file mode 100644 index 0000000..9e5556d --- /dev/null +++ b/src/main/java/com/nis/domain/restful/dashboard/TrafficHttpFocusStatistic.java @@ -0,0 +1,95 @@ +package com.nis.domain.restful.dashboard; + +import java.util.Date; + +public class TrafficHttpFocusStatistic { + + private Long stat_id; + private Integer web_id; + private Long unique_num; + private Long link_num; + private Long c2s_pkt_num; + private Long s2c_pkt_num; + private Long c2s_byte_len; + private Long s2c_byte_len; + private Integer entrance_id; + private Date stat_time; + + private String time; + private Long count; + + public String getTime() { + return time; + } + public void setTime(String time) { + this.time = time; + } + public Long getCount() { + return count; + } + public void setCount(Long count) { + this.count = count; + } + public Long getStat_id() { + return stat_id; + } + public void setStat_id(Long stat_id) { + this.stat_id = stat_id; + } + public Integer getWeb_id() { + return web_id; + } + public void setWeb_id(Integer web_id) { + this.web_id = web_id; + } + public Long getUnique_num() { + return unique_num; + } + public void setUnique_num(Long unique_num) { + this.unique_num = unique_num; + } + public Long getLink_num() { + return link_num; + } + public void setLink_num(Long link_num) { + this.link_num = link_num; + } + public Long getC2s_pkt_num() { + return c2s_pkt_num; + } + public void setC2s_pkt_num(Long c2s_pkt_num) { + this.c2s_pkt_num = c2s_pkt_num; + } + public Long getS2c_pkt_num() { + return s2c_pkt_num; + } + public void setS2c_pkt_num(Long s2c_pkt_num) { + this.s2c_pkt_num = s2c_pkt_num; + } + public Long getC2s_byte_len() { + return c2s_byte_len; + } + public void setC2s_byte_len(Long c2s_byte_len) { + this.c2s_byte_len = c2s_byte_len; + } + public Long getS2c_byte_len() { + return s2c_byte_len; + } + public void setS2c_byte_len(Long s2c_byte_len) { + this.s2c_byte_len = s2c_byte_len; + } + public Integer getEntrance_id() { + return entrance_id; + } + public void setEntrance_id(Integer entrance_id) { + this.entrance_id = entrance_id; + } + public Date getStat_time() { + return stat_time; + } + public void setStat_time(Date stat_time) { + this.stat_time = stat_time; + } + + +} 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 17baae6..796914d 100644 --- a/src/main/java/com/nis/web/controller/restful/DashboardServiceController.java +++ b/src/main/java/com/nis/web/controller/restful/DashboardServiceController.java @@ -758,7 +758,7 @@ public class DashboardServiceController extends BaseRestController { @RequestMapping(value = "trafficWebsiteListNoTime", method = RequestMethod.GET) @ApiOperation(value = "网站流量分析详情统计", httpMethod = "GET", notes = "对应网站http分类显示") - public Map trafficWebsiteListNoTime(@RequestParam String beginDate, @RequestParam String endDate,Model model, HttpServletRequest request, + public Map trafficWebsiteListNoTime(Integer domain,Integer entranceId , @RequestParam String beginDate, @RequestParam String endDate,Model model, HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); @@ -770,7 +770,7 @@ public class DashboardServiceController extends BaseRestController { Date begin = DateUtils.parseDate(beginDate); Date end = DateUtils.parseDate(endDate); // 带查询时间查询所有 - List websiteChart = dashboardService.getWebsiteDetails(begin, end); + List websiteChart = dashboardService.getWebsiteDetails(begin, end,domain,entranceId); if (websiteChart != null && websiteChart.size() > 0) { list = websiteChart; } @@ -781,7 +781,7 @@ public class DashboardServiceController extends BaseRestController { cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1); Date end1 = cal.getTime(); // 带查询时间查询所有 - List websiteChart = dashboardService.getWebsiteDetails(begin1, end1); + List websiteChart = dashboardService.getWebsiteDetails(begin1, end1,domain,entranceId); if (websiteChart != null && websiteChart.size() > 0) { list = websiteChart; } @@ -929,4 +929,38 @@ public class DashboardServiceController extends BaseRestController { return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "HTTP网站主题分类分析数据检索成功", list, 0); } + @RequestMapping(value = "trafficDomainTrans", method = RequestMethod.GET) + @ApiOperation(value = "域名详情趋势", httpMethod = "GET", notes = "域名UV") + public Map trafficDomainTrans(String beginDate, String endDate, Model model, Integer domain,Integer entranceId, + HttpServletRequest request, HttpServletResponse response) { + + long start = System.currentTimeMillis(); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); + List list = new ArrayList(); + try { + + // 带查询时间查询所有 + List websiteChart = dashboardService.getDomainTrans(beginDate, endDate,domain,entranceId); + if (websiteChart != null && websiteChart.size() > 0) { + list = websiteChart; + } + + } catch (Exception 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()); + } else if (e instanceof ServiceRuntimeException) { + throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start, + "HTTP网站域名分类分析数据检索失败:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode()); + } else { + throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start, + "HTTP网站域名分类分析数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue()); + } + } + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "HTTP网站域名分类分析数据检索成功", + list, 0); + } } diff --git a/src/main/java/com/nis/web/dao/dashboard/TrafficHttpStatisticDao.java b/src/main/java/com/nis/web/dao/dashboard/TrafficHttpStatisticDao.java index 1b3bd8e..694fdfe 100644 --- a/src/main/java/com/nis/web/dao/dashboard/TrafficHttpStatisticDao.java +++ b/src/main/java/com/nis/web/dao/dashboard/TrafficHttpStatisticDao.java @@ -6,6 +6,7 @@ import java.util.Map; import org.apache.ibatis.annotations.Param; +import com.nis.domain.restful.dashboard.TrafficHttpFocusStatistic; import com.nis.domain.restful.dashboard.TrafficHttpStatistic; import com.nis.web.dao.MyBatisDao; @@ -27,4 +28,8 @@ public interface TrafficHttpStatisticDao { List getHttpStatisticNoLinkAndPkt(@Param("statTime") Date statTime, @Param("endTime") Date endTime); List getTrafficHttpStatistic(@Param("statTime") Date statTime, @Param("endTime") Date endTime); List getIdByWebSiteId(@Param("websiteId") Integer websiteId); + + List getTrafficHttpDomain(@Param("beginDate")Date beginDate,@Param("endDate") Date endDate,@Param("domain")Integer domain,@Param("entranceId")Integer entranceId); + List getDomainTrans(@Param("entranceId")Integer entranceId,@Param("beginDate")String beginDate,@Param("endDate")String endDate,@Param("domain")Integer domain); + } \ No newline at end of file diff --git a/src/main/java/com/nis/web/dao/dashboard/TrafficHttpStatisticDao.xml b/src/main/java/com/nis/web/dao/dashboard/TrafficHttpStatisticDao.xml index a14cbe7..36f17c5 100644 --- a/src/main/java/com/nis/web/dao/dashboard/TrafficHttpStatisticDao.xml +++ b/src/main/java/com/nis/web/dao/dashboard/TrafficHttpStatisticDao.xml @@ -121,4 +121,26 @@ FROM + + + \ No newline at end of file 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 6f5834e..914e829 100644 --- a/src/main/java/com/nis/web/service/restful/DashboardService.java +++ b/src/main/java/com/nis/web/service/restful/DashboardService.java @@ -14,7 +14,6 @@ import org.springframework.stereotype.Service; import java.text.SimpleDateFormat; import java.util.*; import java.util.Map.Entry; - @Service public class DashboardService extends BaseService { @@ -807,8 +806,8 @@ public class DashboardService extends BaseService { * @param endDate * @return */ - public List getWebsiteDetails(Date beginDate, Date endDate) { - List list = trafficHttpStatisticDao.getTrafficHttpStatistic(beginDate, endDate); + public List getWebsiteDetails(Date beginDate, Date endDate,Integer domain,Integer entranceId) { + List list = trafficHttpStatisticDao.getTrafficHttpDomain(beginDate, endDate,domain,entranceId); return list; } @@ -1130,5 +1129,61 @@ public class DashboardService extends BaseService { } return resulMap; } - + /** + * + * @param beginDate + * @param endDate + * @param domain + * @param entranceId + * @return + */ + public List getDomainTrans(String beginDate, String endDate, Integer domain, Integer entranceId) { + List listMap = new ArrayList(); + HashMap resulMap= new HashMap(); + List domainList = new ArrayList(); + domainList = trafficHttpStatisticDao.getDomainTrans(entranceId, beginDate, endDate, domain); + List timeList = new ArrayList(); + List countList = new ArrayList(); + if (domainList != null && domainList.size() > 0) { + Map m = new HashMap(); + int inter = 1000 * 60 * 30;// 间隔时间为30分钟 + // 开始时间,结束时间 时间戳 + Long b = dateToStamp(beginDate); + Long e = dateToStamp(endDate); + int num = 0; + Long pointTime = b; + while (pointTime < e) { + Map rm = new HashMap(); + Long sumL = 0l; + if (pointTime >= e) { + break; // 停止 + } + for (TrafficHttpFocusStatistic tt : domainList) { + // 实际时间 + String time = tt.getTime(); + Long t = dateToStamp(time); + if (t >= pointTime && t < pointTime + inter) { + // 范围之内分到此pointTime组 + sumL = sumL + tt.getCount(); + } + } + // 在结束时间只有当值大于0时才记录数据,防止折线降为0引起误会 + if (pointTime >= e - inter && sumL > 0) { + countList.add(sumL); + timeList.add(stampToDate(pointTime)); + } + if (pointTime < e - inter) { + timeList.add(stampToDate(pointTime)); + countList.add(sumL); + } + num = num + 1; + pointTime = b + inter * num; + } + resulMap.put("count", countList); + resulMap.put("statTime", timeList); + listMap.add(resulMap); + } + return listMap; + } + }