日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
炫酷,SpringBoot+Echarts實(shí)現(xiàn)用戶訪問地圖可視化(附源碼)

SpringBoot+Echarts用戶訪問地圖可視化

創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站設(shè)計(jì)、廣水網(wǎng)絡(luò)推廣、小程序制作、廣水網(wǎng)絡(luò)營(yíng)銷、廣水企業(yè)策劃、廣水品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供廣水建站搭建服務(wù),24小時(shí)服務(wù)熱線:028-86922220,官方網(wǎng)址:www.cdcxhl.com

意義

  •  在常見的電商、新聞、社交網(wǎng)站等,合理運(yùn)用運(yùn)營(yíng)成本才能最大化輸出自己的產(chǎn)品,其中最常見的功能就有針對(duì)不同訪問熱度的城市制定不同的運(yùn)營(yíng)手段,因此我們掌握用戶城市分布情況至關(guān)重要。
  •  pc端與移動(dòng)端不同,無法依托手機(jī)自帶的gps定位到用戶所在城市,只能通過ip來進(jìn)行判斷所在地理位置。

根據(jù)ip獲取城市的方式

  •  淘寶、新浪等常年提供根據(jù)ip獲取城市的接口,但是隔一段時(shí)間會(huì)出現(xiàn)接口地址更改的情況,也有一定的限流
  •  開源純真ip庫(kù):不斷迭代更新ip庫(kù)內(nèi)容,一般場(chǎng)景下足以使用,自主可控。(下載qqwry.dat庫(kù))

思路

首先需要獲取用戶請(qǐng)求的ip地址,我們對(duì)該方法進(jìn)行簡(jiǎn)單封裝: 

 
 
 
 
  1. public class IPUtil {  
  2.     public static String getIpAddress(HttpServletRequest request) {  
  3.         String ip = request.getHeader("x-forwarded-for");  
  4.         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
  5.             ip = request.getHeader("Proxy-Client-IP");  
  6.         }  
  7.         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
  8.             ip = request.getHeader("WL-Proxy-Client-IP");  
  9.         }  
  10.         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
  11.             ip = request.getHeader("HTTP_CLIENT_IP");  
  12.         }  
  13.         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
  14.             ip = request.getHeader("HTTP_X_FORWARDED_FOR");  
  15.         }  
  16.         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
  17.             ip = request.getRemoteAddr();  
  18.         }  
  19.         return ip;  
  20.     }  

封裝純真ip的解析工具,根據(jù)ip獲取請(qǐng)求地址所在城市,github有大量實(shí)現(xiàn)版本,我們這里不做贅述,具體代碼見文末源碼 

 
 
 
 
  1. //篇幅較長(zhǎng),截取的主要方法,詳細(xì)在源碼地址查看      
  2. public IPZone findIP(final String ip) {  
  3.         final long ipNum = toNumericIP(ip);  
  4.         final QIndex idx = searchIndex(ipNum);  
  5.         if (idx == null) {  
  6.             return new IPZone(ip); 
  7.          }  
  8.         return readIP(ip, idx);  

自定義攔截器,對(duì)用戶的登錄請(qǐng)求進(jìn)行攔截,在此處判斷請(qǐng)求ip所在城市,并進(jìn)行計(jì)數(shù)。我們這里只是簡(jiǎn)單邏輯的說明,在生產(chǎn)上時(shí)應(yīng)該用redis來存放計(jì)數(shù),并且專門提供一個(gè)rest接口來推送當(dāng)前各城市訪問數(shù)量情況,再由前端配合,隔一段時(shí)間發(fā)起一次請(qǐng)求,例如隔一小時(shí)請(qǐng)求一次該rest接口,從而進(jìn)行前端數(shù)據(jù)的展示。 

 
 
 
 
  1. /**  
  2.  * 登錄攔截器  
  3.  */  
  4. @Slf4j  
  5. public class MyLoginInterceptor implements HandlerInterceptor {  
  6.     private static final String LOGIN_PATH = "/user/login";  
  7.     private static Map visitCount;  
  8.     private static final QQWry qqWry;  
  9.     static {  
  10.         visitCount = new HashMap<>(31);  
  11.         qqWry = new QQWry();  
  12.     } 
  13.     //展示訪問數(shù)量不是精確指標(biāo),如果要做到完全正確需要使用鎖,防止計(jì)數(shù)存在并發(fā)問題  
  14.     @Override  
  15.     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {  
  16.         log.info("【MyLoginInterceptor】調(diào)用了:{}", request.getRequestURI());  
  17.         if (request.getRequestURI().equals(LOGIN_PATH)) {  
  18.             String ipAddress = IPUtil.getIpAddress(request);  
  19.             String province = qqWry.findIP(ipAddress).getMainInfo();  
  20.             if (visitCount.containsKey(province)) {  
  21.                 visitCount.put(province,new AtomicInteger(visitCount.get(province).incrementAndGet()));  
  22.             } else {  
  23.                 visitCount.put(province,new AtomicInteger());  
  24.             }  
  25.         }  
  26.         return true;  
  27.     }  
  28.     @Override  
  29.     public void postHandle(HttpServletRequest request, HttpServletResponse response,  
  30.                            Object handler, ModelAndView modelAndView) throws Exception {}  
  31.     @Override  
  32.     public void afterCompletion(HttpServletRequest request, HttpServletResponse response,  
  33.                                 Object handler, Exception ex){}  

注冊(cè)自定義的攔截器 

 
 
 
 
  1. @Configuration  
  2. public class WebMvcConfig implements WebMvcConfigurer {  
  3.     @Override  
  4.     public void addInterceptors(InterceptorRegistry registry) {  
  5.         registry.addInterceptor(new MyLoginInterceptor());  
  6.     }  

登錄controller模擬邏輯,注意:如果想看效果圖需要自己寫線程用不同的虛擬ip進(jìn)行訪問url,從而達(dá)到在不同城市訪問接口的效果。 

 
 
 
 
  1. @RestController("user") 
  2. public class LoginController { 
  3.     @GetMapping("login")  
  4.     public String login() {  
  5.         //登錄邏輯  
  6.         return "success";  
  7.     }  

最終效果

前后端源碼

 
 
 
 
  1. https://github.com/Motianshi/distribute-tool  

當(dāng)前題目:炫酷,SpringBoot+Echarts實(shí)現(xiàn)用戶訪問地圖可視化(附源碼)
當(dāng)前網(wǎng)址:http://www.5511xx.com/article/coegshp.html