Browse Source

update

three
DengBiao 1 year ago
parent
commit
cbaaf49692
4 changed files with 38 additions and 0 deletions
  1. +1
    -0
      app/db/model/master_area_visits_flows.go
  2. +8
    -0
      app/db/model/user_app_domain.go
  3. +3
    -0
      consume/md/md_user_visit_ip_address_consume.go
  4. +26
    -0
      consume/zhios_user_visit_ip_address_consume.go

+ 1
- 0
app/db/model/master_area_visits_flows.go View File

@@ -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"`
}

+ 8
- 0
app/db/model/user_app_domain.go View File

@@ -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)"`
}

+ 3
- 0
consume/md/md_user_visit_ip_address_consume.go View File

@@ -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天

+ 26
- 0
consume/zhios_user_visit_ip_address_consume.go View File

@@ -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)
}

Loading…
Cancel
Save