From 9a87940fe9ffb3c176c1d52ed252395aa6e84435 Mon Sep 17 00:00:00 2001 From: fanxb Date: Wed, 2 Mar 2022 15:03:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=94=AF=E6=8C=81hexo=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E4=B8=8D=E5=A2=9E=E5=8A=A0=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E9=87=8F=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ApplicationController.java | 6 ++--- .../backend/service/ApplicationService.java | 4 +++- .../service/impl/ApplicationServiceImpl.java | 23 ++++--------------- .../public/qiezijs/1.0/qiezi_statistic.js | 9 +++----- .../public/qiezijs/1.0/qiezi_statistic.min.js | 2 +- 5 files changed, 15 insertions(+), 29 deletions(-) diff --git a/qieziBackend/src/main/java/com/fanxb/backend/controller/ApplicationController.java b/qieziBackend/src/main/java/com/fanxb/backend/controller/ApplicationController.java index cc1ab3c..a41bff3 100644 --- a/qieziBackend/src/main/java/com/fanxb/backend/controller/ApplicationController.java +++ b/qieziBackend/src/main/java/com/fanxb/backend/controller/ApplicationController.java @@ -45,8 +45,8 @@ public class ApplicationController { */ @GetMapping("/visit") @ResponseBody - public void visit(HttpServletRequest request, HttpServletResponse response, - @NotBlank(message = "回调函数不能为空") String callBack, @NotBlank(message = "key不能为空") String key) throws IOException { - applicationService.visit(request, response, callBack, key); + public void visit(HttpServletRequest request, HttpServletResponse response, @NotBlank(message = "回调函数不能为空") String callBack + , @NotBlank(message = "key不能为空") String key, @NotBlank(message = "path不能为空") String path, boolean notAdd) throws IOException { + applicationService.visit(request, response, callBack, key, path, notAdd); } } diff --git a/qieziBackend/src/main/java/com/fanxb/backend/service/ApplicationService.java b/qieziBackend/src/main/java/com/fanxb/backend/service/ApplicationService.java index 826a440..894ff97 100644 --- a/qieziBackend/src/main/java/com/fanxb/backend/service/ApplicationService.java +++ b/qieziBackend/src/main/java/com/fanxb/backend/service/ApplicationService.java @@ -32,8 +32,10 @@ public interface ApplicationService { * @param response response * @param callBack callBack * @param key key + * @param path path + * @param notAdd 只返回,不计数 * @author fanxb * date 2022/2/16 10:20 */ - void visit(HttpServletRequest request, HttpServletResponse response, String callBack, String key) throws IOException; + void visit(HttpServletRequest request, HttpServletResponse response, String callBack, String key, String path, boolean notAdd) throws IOException; } diff --git a/qieziBackend/src/main/java/com/fanxb/backend/service/impl/ApplicationServiceImpl.java b/qieziBackend/src/main/java/com/fanxb/backend/service/impl/ApplicationServiceImpl.java index 3138182..2f84279 100644 --- a/qieziBackend/src/main/java/com/fanxb/backend/service/impl/ApplicationServiceImpl.java +++ b/qieziBackend/src/main/java/com/fanxb/backend/service/impl/ApplicationServiceImpl.java @@ -67,22 +67,7 @@ public class ApplicationServiceImpl implements ApplicationService { } @Override - public void visit(HttpServletRequest request, HttpServletResponse response, String callBack, String key) throws IOException { - String refer = request.getHeader("Referer"); - if (StrUtil.isEmpty(refer)) { - throw new CustomBaseException("未获取到来源路径"); - } - String path; - try { - URL url = new URL(refer); - path = StrUtil.isEmpty(url.getPath()) ? "/" : url.getPath(); - } catch (Exception e) { - throw new CustomBaseException("url解析错误", e); - } - if (path.length() > 100) { - throw new CustomBaseException("路径长度不能大于100," + path); - } - + public void visit(HttpServletRequest request, HttpServletResponse response, String callBack, String key, String path, boolean notAdd) throws IOException { int hostId = getHostId(key); HostPo hostData = hostDao.getUvPvById(hostId); DetailPagePo detailData = detailPageDao.getUvPvById(hostId, path); @@ -90,7 +75,9 @@ public class ApplicationServiceImpl implements ApplicationService { detailData = new DetailPagePo().setHostId(hostId).setPath(path).setUv(0).setPv(0); } //数据计算更新 - updateData(NetUtil.getClientIp(request), hostData, detailData); + if (!notAdd) { + updateData(NetUtil.getClientIp(request), hostData, detailData); + } //写出 UvPvVo uvPvVo = new UvPvVo(hostData.getUv(), hostData.getPv(), detailData.getUv(), detailData.getPv()); String uvPvVoStr = JSON.toJSONString(uvPvVo); @@ -101,7 +88,7 @@ public class ApplicationServiceImpl implements ApplicationService { } /** - * 更新数据 + * 更新数据,pv:每次都增加,uv:24小时内同一ip,0-24点只统计一次 * * @param ip 来源ip * @param hostPo hostPo diff --git a/qiezi_front/public/qiezijs/1.0/qiezi_statistic.js b/qiezi_front/public/qiezijs/1.0/qiezi_statistic.js index 09a2334..a838b85 100644 --- a/qiezi_front/public/qiezijs/1.0/qiezi_statistic.js +++ b/qiezi_front/public/qiezijs/1.0/qiezi_statistic.js @@ -1,4 +1,3 @@ - (function () { var name = "qieziStatisticHtml"; var callback = name + "CallBack"; @@ -42,14 +41,12 @@ key = temp; } } + var ignoreLocalhost = window.CONFIG !== undefined && window.CONFIG.web_analytics.qieziStatistics.ignore_local; console.log(requestHost, key); if (!key) { return; } - script.src = requestHost + - "/qiezi/api/application/visit?callBack=" + - callback + - "&key=" + - key; + var notAdd = ignoreLocalhost && ['127.0.0.1', 'localhost'].indexOf(window.location.hostname) > -1; + script.src = `${requestHost}/qiezi/api/application/visit?callBack=${callback}&key=${key}&path=${encodeURIComponent(window.location.pathname)}¬Add=${notAdd}`; document.getElementsByTagName("head")[0].appendChild(script); })(); diff --git a/qiezi_front/public/qiezijs/1.0/qiezi_statistic.min.js b/qiezi_front/public/qiezijs/1.0/qiezi_statistic.min.js index 5641ace..7e52233 100644 --- a/qiezi_front/public/qiezijs/1.0/qiezi_statistic.min.js +++ b/qiezi_front/public/qiezijs/1.0/qiezi_statistic.min.js @@ -1 +1 @@ -(function(){var name="qieziStatisticHtml";var callback=name+"CallBack";window[callback]=function(a){var hostPvNode=document.getElementById(name+"HostPv");if(hostPvNode!=null){document.getElementById(name+"HostPvValue").innerText=a.totalPv;hostPvNode.style.display="inline"}var hostUvNode=document.getElementById(name+"HostUv");if(hostUvNode!=null){document.getElementById(name+"HostUvValue").innerText=a.totalUv;hostUvNode.style.display="inline"}var postNode=document.getElementById(name+"Post");if(postNode!=null){document.getElementById(name+"PostPv").innerText=a.pagePv;postNode.style.display="inline"}};var script=document.createElement("script");script.type="text/javascript";script.defer=true;var requestHost="https://qiezi.fleyx.com";if(window.qieziStatisticHost!=undefined&&window.qieziStatisticHost.trim().length>0){requestHost=window.qieziStatisticHost}else if(window.CONFIG&&window.CONFIG.web_analytics.qieziStatistics.app_host){var temp=window.CONFIG.web_analytics.qieziStatistics.app_host;if(temp.trim().length>0){requestHost=temp}}var key=null;if(window.qieziStatisticKey&&window.qieziStatisticKey.trim().length>0){key=window.qieziStatisticKey}else if(window.CONFIG&&window.CONFIG.web_analytics.qieziStatistics.app_key){var temp=window.CONFIG.web_analytics.qieziStatistics.app_key;if(temp.trim().length>0){key=temp}}console.log(requestHost,key);if(!key){return}script.src=requestHost+"/qiezi/api/application/visit?callBack="+callback+"&key="+key;document.getElementsByTagName("head")[0].appendChild(script)})(); +(function(){var name="qieziStatisticHtml";var callback=name+"CallBack";window[callback]=function(a){var hostPvNode=document.getElementById(name+"HostPv");if(hostPvNode!=null){document.getElementById(name+"HostPvValue").innerText=a.totalPv;hostPvNode.style.display="inline"}var hostUvNode=document.getElementById(name+"HostUv");if(hostUvNode!=null){document.getElementById(name+"HostUvValue").innerText=a.totalUv;hostUvNode.style.display="inline"}var postNode=document.getElementById(name+"Post");if(postNode!=null){document.getElementById(name+"PostPv").innerText=a.pagePv;postNode.style.display="inline"}};var script=document.createElement("script");script.type="text/javascript";script.defer=true;var requestHost="https://qiezi.fleyx.com";if(window.qieziStatisticHost!==undefined&&window.qieziStatisticHost.trim().length>0){requestHost=window.qieziStatisticHost}else if(window.CONFIG&&window.CONFIG.web_analytics.qieziStatistics.app_host){var temp=window.CONFIG.web_analytics.qieziStatistics.app_host;if(temp.trim().length>0){requestHost=temp}}var key=null;if(window.qieziStatisticKey&&window.qieziStatisticKey.trim().length>0){key=window.qieziStatisticKey}else if(window.CONFIG&&window.CONFIG.web_analytics.qieziStatistics.app_key){var temp=window.CONFIG.web_analytics.qieziStatistics.app_key;if(temp.trim().length>0){key=temp}}var ignoreLocalhost=window.CONFIG!==undefined&&window.CONFIG.web_analytics.qieziStatistics.ignore_local;console.log(requestHost,key);if(!key){return}var notAdd=ignoreLocalhost&&['127.0.0.1','localhost'].indexOf(window.location.hostname)>-1;script.src="".concat(requestHost,"/qiezi/api/application/visit?callBack=").concat(callback,"&key=").concat(key,"&path=").concat(encodeURIComponent(window.location.pathname),"¬Add=").concat(notAdd);document.getElementsByTagName("head")[0].appendChild(script)})();