@@ -12,6 +12,7 @@ type MasterAreaVisitsFlows struct { | |||||
ProvinceId string `json:"province_id"` | ProvinceId string `json:"province_id"` | ||||
CityName string `json:"city_name"` | CityName string `json:"city_name"` | ||||
CityId string `json:"city_id"` | CityId string `json:"city_id"` | ||||
Pvd string `json:"pvd"` | |||||
CreateAt time.Time `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"` | CreateAt time.Time `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"` | ||||
UpdateAt time.Time `json:"update_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"` | UpdateAt time.Time `json:"update_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"` | ||||
} | } |
@@ -0,0 +1,8 @@ | |||||
package model | |||||
type UserAppDomain struct { | |||||
Domain string `json:"domain" xorm:"not null pk comment('绑定域名') VARCHAR(100)"` | |||||
Uuid int `json:"uuid" xorm:"not null comment('对应APP ID编号') index unique(IDX_UUID_TYPE) INT(10)"` | |||||
Type string `json:"type" xorm:"not null comment('api接口域名,wap.h5域名,admin管理后台') unique(IDX_UUID_TYPE) ENUM('admin','api','wap')"` | |||||
IsSsl int `json:"is_ssl" xorm:"not null default 0 comment('是否开启ssl:0否;1是') TINYINT(255)"` | |||||
} |
@@ -5,8 +5,11 @@ type ZhiOsUserVisitIpAddressMessage struct { | |||||
Province string `json:"province"` | Province string `json:"province"` | ||||
City string `json:"city"` | City string `json:"city"` | ||||
Ip string `json:"ip"` | Ip string `json:"ip"` | ||||
Url string `json:"url"` | |||||
MasterId string `json:"master_id"` | MasterId string `json:"master_id"` | ||||
Pvd string `json:"pvd"` | |||||
} | } | ||||
const ZhiOsUserVisitIpAddressHashMapCacheKey = "zhiOs_user_visit_ip_address_hash_map_cache:%s:%s" //访问ip缓存hashMap键zhiOs_user_visit_ip_address_hash_map_cache:masterId:date | const ZhiOsUserVisitIpAddressHashMapCacheKey = "zhiOs_user_visit_ip_address_hash_map_cache:%s:%s" //访问ip缓存hashMap键zhiOs_user_visit_ip_address_hash_map_cache:masterId:date | ||||
const ZhiOsMasterIdForUrlHashMapCacheKey = "zhiOs_master_id_for_url_hash_map_cache" //访问url缓存hashMap键zhiOs_master_id_for_url_hash_map_cache | |||||
const ZhiOsUserVisitIpAddressHashMapCacheTime = 60 * 60 * 24 //1天 | const ZhiOsUserVisitIpAddressHashMapCacheTime = 60 * 60 * 24 //1天 |
@@ -69,6 +69,20 @@ func handleUserVisitIpAddress(msg []byte) error { | |||||
return err | return err | ||||
} | } | ||||
if msgStruct.MasterId == "" { | |||||
cacheKeyForUrl := fmt.Sprintf(md.ZhiOsMasterIdForUrlHashMapCacheKey) | |||||
get, _ := cache.HGetString(cacheKeyForUrl, msgStruct.Url) | |||||
if get == "" { | |||||
var domainType string | |||||
if msgStruct.Pvd == "app" || msgStruct.Pvd == "applet" { | |||||
domainType = "api" | |||||
} else { | |||||
domainType = "wap" | |||||
} | |||||
msgStruct.MasterId = GetWebSiteDomainMasterId(domainType, msgStruct.Url) | |||||
} | |||||
} | |||||
//1、判断ip是否已统计 | //1、判断ip是否已统计 | ||||
cacheKey := fmt.Sprintf(md.ZhiOsUserVisitIpAddressHashMapCacheKey, msgStruct.MasterId, today) | cacheKey := fmt.Sprintf(md.ZhiOsUserVisitIpAddressHashMapCacheKey, msgStruct.MasterId, today) | ||||
//get, _ := cache.HGetString(cacheKey, msgStruct.Ip) | //get, _ := cache.HGetString(cacheKey, msgStruct.Ip) | ||||
@@ -84,6 +98,7 @@ func handleUserVisitIpAddress(msg []byte) error { | |||||
if cityName == "" { | if cityName == "" { | ||||
cityName = msgStruct.City | cityName = msgStruct.City | ||||
} | } | ||||
data = append(data, &model.MasterAreaVisitsFlows{ | data = append(data, &model.MasterAreaVisitsFlows{ | ||||
Ip: msgStruct.Ip, | Ip: msgStruct.Ip, | ||||
MasterId: utils.StrToInt(msgStruct.MasterId), | MasterId: utils.StrToInt(msgStruct.MasterId), | ||||
@@ -93,6 +108,7 @@ func handleUserVisitIpAddress(msg []byte) error { | |||||
ProvinceId: provinceId, | ProvinceId: provinceId, | ||||
CityName: cityName, | CityName: cityName, | ||||
CityId: cityId, | CityId: cityId, | ||||
Pvd: msgStruct.Pvd, | |||||
CreateAt: now, | CreateAt: now, | ||||
UpdateAt: now, | UpdateAt: now, | ||||
}) | }) | ||||
@@ -129,3 +145,13 @@ func getIpAddress(Db *xorm.Engine, message md.ZhiOsUserVisitIpAddressMessage) (c | |||||
} | } | ||||
return | return | ||||
} | } | ||||
// 获取指定类型的域名对应的masterId:admin、wap、api | |||||
func GetWebSiteDomainMasterId(domainType string, host string) string { | |||||
obj := new(model.UserAppDomain) | |||||
has, err := db.Db.Where("domain=? and type=?", host, domainType).Get(obj) | |||||
if err != nil || !has { | |||||
return "" | |||||
} | |||||
return utils.AnyToString(obj.Uuid) | |||||
} |