diff --git a/app/db/model/master_area_visits_flows.go b/app/db/model/master_area_visits_flows.go index 69575df..82c98e8 100644 --- a/app/db/model/master_area_visits_flows.go +++ b/app/db/model/master_area_visits_flows.go @@ -12,6 +12,7 @@ type MasterAreaVisitsFlows struct { ProvinceId string `json:"province_id"` CityName string `json:"city_name"` CityId string `json:"city_id"` + Pvd string `json:"pvd"` 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"` } diff --git a/app/db/model/user_app_domain.go b/app/db/model/user_app_domain.go new file mode 100644 index 0000000..4522cef --- /dev/null +++ b/app/db/model/user_app_domain.go @@ -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)"` +} diff --git a/consume/md/md_user_visit_ip_address_consume.go b/consume/md/md_user_visit_ip_address_consume.go index dd1aeaf..f9056dd 100644 --- a/consume/md/md_user_visit_ip_address_consume.go +++ b/consume/md/md_user_visit_ip_address_consume.go @@ -5,8 +5,11 @@ type ZhiOsUserVisitIpAddressMessage struct { Province string `json:"province"` City string `json:"city"` Ip string `json:"ip"` + Url string `json:"url"` 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 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天 diff --git a/consume/zhios_user_visit_ip_address_consume.go b/consume/zhios_user_visit_ip_address_consume.go index 6f57d23..ee6edaf 100644 --- a/consume/zhios_user_visit_ip_address_consume.go +++ b/consume/zhios_user_visit_ip_address_consume.go @@ -69,6 +69,20 @@ func handleUserVisitIpAddress(msg []byte) error { 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是否已统计 cacheKey := fmt.Sprintf(md.ZhiOsUserVisitIpAddressHashMapCacheKey, msgStruct.MasterId, today) //get, _ := cache.HGetString(cacheKey, msgStruct.Ip) @@ -84,6 +98,7 @@ func handleUserVisitIpAddress(msg []byte) error { if cityName == "" { cityName = msgStruct.City } + data = append(data, &model.MasterAreaVisitsFlows{ Ip: msgStruct.Ip, MasterId: utils.StrToInt(msgStruct.MasterId), @@ -93,6 +108,7 @@ func handleUserVisitIpAddress(msg []byte) error { ProvinceId: provinceId, CityName: cityName, CityId: cityId, + Pvd: msgStruct.Pvd, CreateAt: now, UpdateAt: now, }) @@ -129,3 +145,13 @@ func getIpAddress(Db *xorm.Engine, message md.ZhiOsUserVisitIpAddressMessage) (c } 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) +}