|
@@ -22,18 +22,19 @@ import (
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
- mobileHref = "/jyapp/tags/%s/%s.html"
|
|
|
- infoTypeRedisKey = "mobile_seo_infoType_home"
|
|
|
- areaRedisKey = "mobile_seo_area_home"
|
|
|
- hotAreaRedisKey = "mobile_seo_hot_area"
|
|
|
- biddingListKey = "mobile_seo_list_%s_%s_%d"
|
|
|
- industryRedisKey = "mobile_seo_industry"
|
|
|
- buyerListRedisKey = "mobile_seo_buyer_list_%d"
|
|
|
- winnerListRedisKey = "mobile_seo_winner_list_%d"
|
|
|
- HotArea = "北京,山东,陕西,河南,广东"
|
|
|
- AdCode = "mobile_seo_ad"
|
|
|
- randCount = 600
|
|
|
- Label = map[string]string{
|
|
|
+ mobileHref = "/jyapp/tags/%s/%s.html"
|
|
|
+ infoTypeRedisKey = "mobile_seo_infoType_home"
|
|
|
+ areaRedisKey = "mobile_seo_area_home"
|
|
|
+ hotAreaRedisKey = "mobile_seo_hot_area"
|
|
|
+ biddingListKey = "mobile_seo_list_%s_%s_%d"
|
|
|
+ biddingListTotalKey = "mobile_seo_list_total_%s_%s"
|
|
|
+ industryRedisKey = "mobile_seo_industry"
|
|
|
+ buyerListRedisKey = "mobile_seo_buyer_list_%d"
|
|
|
+ winnerListRedisKey = "mobile_seo_winner_list_%d"
|
|
|
+ HotArea = "北京,山东,陕西,河南,广东"
|
|
|
+ AdCode = "mobile_seo_ad"
|
|
|
+ randCount = 600
|
|
|
+ Label = map[string]string{
|
|
|
"area": "area",
|
|
|
"infoType": "it",
|
|
|
"industry": "indu",
|
|
@@ -343,11 +344,11 @@ func (b *BiddingInfo) GetSearchSql() string {
|
|
|
)
|
|
|
filter = append(filter, fmt.Sprintf(filterRange, now.AddDate(-5, 0, 0).Unix(), now.Unix())) //发版前 改成最近一年
|
|
|
if b.Area != "" || b.City != "" {
|
|
|
- if b.Area != "" {
|
|
|
- filterShould = append(filterShould, fmt.Sprintf(`{"terms":{"area":["%s"]}}`, b.Area))
|
|
|
- }
|
|
|
+
|
|
|
if b.City != "" {
|
|
|
filterShould = append(filterShould, fmt.Sprintf(`{"terms":{"city":["%s"]}}`, b.City))
|
|
|
+ } else if b.Area != "" {
|
|
|
+ filterShould = append(filterShould, fmt.Sprintf(`{"terms":{"area":["%s"]}}`, b.Area))
|
|
|
}
|
|
|
}
|
|
|
//信息类型
|
|
@@ -404,13 +405,21 @@ func (b *BiddingInfo) GetBiddingInfo(types, name string, currentLocation []*SeoI
|
|
|
if n := strings.Split(name, "_"); len(n) > 1 {
|
|
|
name = strings.Join(n[:len(n)-1], "_")
|
|
|
}
|
|
|
+ redisCount := 0
|
|
|
redisKey := fmt.Sprintf(biddingListKey, types, name, b.PageNum)
|
|
|
+ redisTotalKey := fmt.Sprintf(biddingListTotalKey, types, name)
|
|
|
if b, err := redis.GetBytes("seoCache", redisKey); err == nil && len(*b) > 0 {
|
|
|
if err = json.Unmarshal(*b, &birt); err != nil {
|
|
|
log.Println(err)
|
|
|
}
|
|
|
}
|
|
|
- if len(birt) == 0 {
|
|
|
+ if redisCountByte, err := redis.GetBytes("seoCache", redisTotalKey); err == nil && len(*redisCountByte) > 0 {
|
|
|
+ if err = json.Unmarshal(*redisCountByte, &redisCount); err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(birt) == 0 || ((b.Total != b.PageSize) && redisCount == 0) {
|
|
|
if flag := ReqLimitInit.Limit(context.Background()); flag == 1 {
|
|
|
defer ReqLimitInit.Release()
|
|
|
} else {
|
|
@@ -453,13 +462,20 @@ func (b *BiddingInfo) GetBiddingInfo(types, name string, currentLocation []*SeoI
|
|
|
}
|
|
|
b, err := json.Marshal(birt)
|
|
|
if err == nil && len(b) > 0 {
|
|
|
- if err := redis.PutBytes("seoCache", redisKey, &b, qu.IntAll(config.Seoconfig["cacheTime"])+RandNum.Intn(randCount)); err != nil {
|
|
|
+ if err := redis.PutBytes("seoCache", redisKey, &b, qu.IntAll(config.Seoconfig["biddingCacheTime"])+RandNum.Intn(randCount)); err != nil {
|
|
|
log.Println(err)
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
if len(currentLocation) > 0 {
|
|
|
+ redisCacheTime := qu.IntAll(config.Seoconfig["biddingCacheTime"])
|
|
|
+ start := time.Now()
|
|
|
+ if b.Keys != "" { // 标的物 一天更新一次
|
|
|
+ redisCacheTime = qu.IntAll(config.Seoconfig["cacheTime"])
|
|
|
+ }
|
|
|
count, data := elastic.GetWithCount("bidding", "bidding", "", b.GetSearchSql())
|
|
|
+ fmt.Println("GetWithCount", time.Since(start))
|
|
|
+ fmt.Println(" b.GetSearchSql()", b.GetSearchSql())
|
|
|
if count > 0 && data != nil {
|
|
|
if b.Total > int(count) {
|
|
|
b.Total = int(count)
|
|
@@ -487,15 +503,27 @@ func (b *BiddingInfo) GetBiddingInfo(types, name string, currentLocation []*SeoI
|
|
|
if len(bir) == 1 {
|
|
|
b, err := json.Marshal(bir)
|
|
|
if err == nil && len(b) > 0 {
|
|
|
- if err = redis.PutBytes("seoCache", fmt.Sprintf(biddingListKey, types, name, i+1), &b, qu.IntAll(config.Seoconfig["cacheTime"])+RandNum.Intn(randCount)); err != nil {
|
|
|
+ if err = redis.PutBytes("seoCache", fmt.Sprintf(biddingListKey, types, name, i+1), &b, redisCacheTime+RandNum.Intn(randCount)); err != nil {
|
|
|
log.Println(err)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ countByte, err := json.Marshal(b.Total)
|
|
|
+ if err == nil && len(countByte) > 0 {
|
|
|
+ if err = redis.PutBytes("seoCache", fmt.Sprintf(biddingListTotalKey, types, name), &countByte, redisCacheTime+RandNum.Intn(randCount)); err != nil {
|
|
|
+ log.Println("存缓存失败:", fmt.Sprintf(biddingListTotalKey, types, name), b.Total)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
+ } else {
|
|
|
+ if b.Total != b.PageSize {
|
|
|
+ b.Total = redisCount
|
|
|
+ }
|
|
|
}
|
|
|
return
|
|
|
}
|