首先定義一張表用來記錄使用者的IP訪問
--------------------------------------使用者繫結的IP------------------------------------DECLARE VC_STR VARCHAR2(2000); VN_COUNT NUMBER; BEGIN --檢視是否存在NRE_BUSINESSTYPE SELECT COUNT(*) INTO VN_COUNT FROM USER_TABLES WHERE TABLE_NAME = 'CHAT_USER_BIND'; --如果沒有則新增加表 IF VN_COUNT < 1 THEN VC_STR :=' CREATE TABLE CHAT_USER_BIND ( ID VARCHAR2(32) DEFAULT SYS_GUID() PRIMARY KEY, USER_CODE VARCHAR2(32), USER_IP VARCHAR2(50), USER_TYPE VARCHAR2(2), CREATE_DATE DATE DEFAULT SYSDATE, )'; EXECUTE IMMEDIATE VC_STR; commit; END IF; END;/comment on column CHAT_USER_BIND.ID is '主鍵';comment on column CHAT_USER_BIND.USER_CODE is '使用者程式碼';comment on column CHAT_USER_BIND.USER_IP is '繫結服務端IP';comment on column CHAT_USER_BIND.CREATE_DATE is '建立時間';comment on column CHAT_USER_BIND.USER_TYPE is '0註冊成功,1登入成功,2繫結成功';/
2.統計IP的訪問數量,單個使用者重複IP去重
3.透過工具ip2region獲取ip的地址資訊
1.獲取IP119.118.179.94=>地址中國|0|遼寧省|瀋陽市|聯通2.獲取的IP資訊主要用到的是第二個座標的省份,這裡把省份去掉(因為echarts的map資訊沒有用省結尾)@ResponseBody @RequestMapping(value="/ipMap") public List<Map<String,String>> getIPMap(){ List<Map<String,Object>> ipMap=this.userService.getIPCount(); Map<String,String> mapCount=new HashMap<String,String>(); if(null!=ipMap && ipMap.size()>0) { for(Map<String,Object> map : ipMap) { String address=IPUtil.getAddress(map.get("IP").toString(),IPDBTargetPath); logger.info("獲取IP{}=>地址{}",map.get("IP"),address); if(!StringUtil.isNUll(address)) { String provice=address.split("\\|")[2]; if(provice.endsWith("省")) { provice=provice.substring(0,provice.length()-1); if(StringUtil.isNUll(mapCount.get(provice))) { mapCount.put(provice, map.get("COUNT_IP").toString()); }else { mapCount.put(provice, Integer.valueOf(mapCount.get(provice))+Integer.valueOf(map.get("COUNT_IP").toString())+""); } } } } } List<Map<String,String>> listMapCount=new ArrayList<Map<String,String>>(); for(String key : mapCount.keySet()) { Map<String,String> map=new HashMap<String,String>(); map.put("name", key); map.put("value", mapCount.get(key)); listMapCount.add(map); } return listMapCount; }
4.藉助echarts展示
這裡主要參考了(https://github.com/Jackyyans/code123/tree/master/normal)
5.效果圖
最新評論