diff --git a/app/utils/file.go b/app/utils/file.go index 70a2927..93ed08f 100644 --- a/app/utils/file.go +++ b/app/utils/file.go @@ -1,11 +1,22 @@ package utils import ( + "os" "path" "strings" + "time" ) // 获取文件后缀 func FileExt(fname string) string { return strings.ToLower(strings.TrimLeft(path.Ext(fname), ".")) } + +func FilePutContents(fileName string, content string) { + fd, _ := os.OpenFile("./tmp/"+fileName+".log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) + fd_time := time.Now().Format("2006-01-02 15:04:05") + fd_content := strings.Join([]string{"[", fd_time, "] ", content, "\n"}, "") + buf := []byte(fd_content) + fd.Write(buf) + fd.Close() +} diff --git a/consume/zhios_user_visit_ip_address_consume.go b/consume/zhios_user_visit_ip_address_consume.go index ee6edaf..039e649 100644 --- a/consume/zhios_user_visit_ip_address_consume.go +++ b/consume/zhios_user_visit_ip_address_consume.go @@ -73,13 +73,12 @@ func handleUserVisitIpAddress(msg []byte) error { 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) + msgStruct.MasterId = GetWebSiteDomainMasterId(msgStruct.Url) + utils.FilePutContents("GetWebSiteDomainMasterId", utils.SerializeStr(msgStruct)) + cache.HSet(cacheKeyForUrl, msgStruct.Url, msgStruct.MasterId) + cache.Expire(cacheKeyForUrl, md.ZhiOsUserVisitIpAddressHashMapCacheTime) + } else { + msgStruct.MasterId = get } } @@ -147,9 +146,9 @@ func getIpAddress(Db *xorm.Engine, message md.ZhiOsUserVisitIpAddressMessage) (c } // 获取指定类型的域名对应的masterId:admin、wap、api -func GetWebSiteDomainMasterId(domainType string, host string) string { +func GetWebSiteDomainMasterId(host string) string { obj := new(model.UserAppDomain) - has, err := db.Db.Where("domain=? and type=?", host, domainType).Get(obj) + has, err := db.Db.Where("domain=?", host).Get(obj) if err != nil || !has { return "" }