Ver código fonte

Merge branch 'dev/v4.8.47_fuwencai' of https://jygit.jydev.jianyu360.cn/qmx/jy into dev/v4.8.47_fuwencai

wangshan 2 anos atrás
pai
commit
e3635e72e0

+ 3 - 21
src/jfw/config/config.go

@@ -7,7 +7,6 @@ import (
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/os/gcfg"
 	"github.com/gogf/gf/v2/os/gctx"
-	"log"
 )
 
 var (
@@ -21,11 +20,11 @@ var (
 	GmailAuth            []*mail.GmailAuth
 	EntnichePcConf       *entnichePcConf
 	Middleground         *middleground.Middleground
-	HotWinnerConfig      hotConfig
-	HotBuyerConfig       hotConfig
+	HotWinnerConfig      HotConfig
+	HotBuyerConfig       HotConfig
 )
 
-type hotConfig struct {
+type HotConfig struct {
 	CacheKey     string `json:"cacheKey"`
 	CacheTimeout int    `json:"cacheTimeout"`
 	Limit        int    `json:"limit"`
@@ -66,21 +65,4 @@ func init() {
 		RegResourceCenter(g.Cfg().MustGet(ctx, "resourceCenterKey").String()).
 		RegEntManageApplication(g.Cfg().MustGet(ctx, "entManageApplication").String()).
 		RegPublicservice(g.Cfg().MustGet(ctx, "publicserviceKey").String())
-	hotBuyerData := util.ObjToMap(Seoconfig["hotBuyer"])
-	hotWinnerData := util.ObjToMap(Seoconfig["hotWinner"])
-	if hotBuyerData != nil && hotWinnerData != nil {
-		HotWinnerConfig = hotConfig{
-			CacheKey:     util.InterfaceToStr((*hotWinnerData)["cacheKey"]),
-			CacheTimeout: util.IntAll((*hotWinnerData)["cacheTimeout"]),
-			Limit:        util.IntAll((*hotWinnerData)["limit"]),
-		}
-		HotBuyerConfig = hotConfig{
-			CacheKey:     util.InterfaceToStr((*hotBuyerData)["cacheKey"]),
-			CacheTimeout: util.IntAll((*hotBuyerData)["cacheTimeout"]),
-			Limit:        util.IntAll((*hotBuyerData)["limit"]),
-		}
-	} else {
-		log.Fatal("获取配置失败,请检查配置文件")
-	}
-
 }

+ 19 - 9
src/jfw/modules/app/src/app/front/tags.go

@@ -93,6 +93,8 @@ onceAgain:
 				PageNum:  1,                                       //当前页码
 				IsSearch: true,                                    //是否进行bidding数据查询
 			}
+			isInfoList bool // 是否是在列表页面
+
 		)
 		areaList, areaToCode, cityToCode, areaToCity = jyutil.GetAllArea()
 		infoTypeList, topMap = jyutil.GetInfoType()
@@ -113,6 +115,8 @@ onceAgain:
 						title = fmt.Sprintf("%s%s", areaTopTip, suffix)
 					} else if cityCode == "0" && !directRuleCity[biddingInfo.Area] {
 						tg.T["cityList"] = areaToCity[areaCode]
+					} else if cityCode == "0" && directRuleCity[biddingInfo.Area] {
+						// 直辖市不显示下面的管理城市
 					} else {
 						biddingInfo.IsEffective = false //没有对应城市 异常
 					}
@@ -139,6 +143,7 @@ onceAgain:
 					biddingInfo.PageFormat(codes[1])
 					prevPage = fmt.Sprintf("%s_%d", codes[0], biddingInfo.PageNum-1)
 					nextPage = fmt.Sprintf("%s_%d", codes[0], biddingInfo.PageNum+1)
+					isInfoList = true
 				}
 			}
 		case jyutil.Label["industry"]: //行业
@@ -158,6 +163,7 @@ onceAgain:
 					prevPage = fmt.Sprintf("%s_%s_%d", codes[0], codes[1], biddingInfo.PageNum-1)
 					nextPage = fmt.Sprintf("%s_%s_%d", codes[0], codes[1], biddingInfo.PageNum+1)
 				}
+				isInfoList = true
 			} else if name == "home" {
 				biddingInfo.IsEffective = true
 				biddingInfo.IsSearch = false
@@ -177,6 +183,7 @@ onceAgain:
 			})
 			biddingInfo.IsSearch = false
 			hasIndustryNav = true
+			isInfoList = true
 		case jyutil.Label["winner"]: //中标单位
 			biddingInfo.IsEffective = true
 			biddingInfo.PageFormat(name)
@@ -189,6 +196,7 @@ onceAgain:
 			biddingInfo.IsSearch = false
 			hasIndustryNav = true
 			title = fmt.Sprintf("%s%s", "中标企业", suffix)
+			isInfoList = true
 		case jyutil.Label["home"]: //首页
 			if name == types {
 				biddingInfo.IsEffective = true
@@ -206,14 +214,7 @@ onceAgain:
 			goto onceAgain
 		}
 		//信息类型
-		if biddingInfo.PageNum == 1 {
-			prevPage = ""
-		}
-		if biddingInfo.PageNum == (biddingInfo.Total-1)/biddingInfo.PageSize+1 {
-			nextPage = ""
-		}
-		tg.T["prevPage"] = qu.If(prevPage != "", fmt.Sprintf("/jyapp/tags/%s/%s.html", types, prevPage), "").(string)
-		tg.T["nextPage"] = qu.If(nextPage != "", fmt.Sprintf("/jyapp/tags/%s/%s.html", types, nextPage), "").(string)
+
 		if len(currentLocation) > 0 {
 			currentLocation[len(currentLocation)-1].Url = ""
 		}
@@ -227,6 +228,14 @@ onceAgain:
 		if biddingInfo.IsSearch {
 			tg.T["biddingList"] = biddingInfo.GetBiddingInfo(types, name, currentLocation)
 		}
+		if biddingInfo.PageNum == 1 {
+			prevPage = ""
+		}
+		if biddingInfo.PageNum == (biddingInfo.Total-1)/biddingInfo.PageSize+1 {
+			nextPage = ""
+		}
+		tg.T["prevPage"] = qu.If(prevPage != "", fmt.Sprintf("/jyapp/tags/%s/%s.html", types, prevPage), "").(string)
+		tg.T["nextPage"] = qu.If(nextPage != "", fmt.Sprintf("/jyapp/tags/%s/%s.html", types, nextPage), "").(string)
 		tg.T["totalPage"] = (biddingInfo.Total-1)/biddingInfo.PageSize + 1
 		tg.T["pageNum"] = biddingInfo.PageNum
 		tg.T["hotArea"] = jyutil.GetHotArea()
@@ -251,9 +260,10 @@ onceAgain:
 		tg.T["areaTopTip"] = areaTopTip
 		tg.T["title"] = title
 		tg.T["Home"] = "/jyapp/tags/home/home.html"
+		tg.T["isInfoList"] = isInfoList
 		//模板redis缓存
 		content, _ := tg.Render4Cache("/tags/index.html", &tg.T)
-		redis.Put("seoCache", tagsMobileKey, string(content), qu.IntAll(config.Seoconfig["biddingCacheTime"]))
+		redis.Put("seoCache", tagsMobileKey, string(content), qu.IntAll(config.Seoconfig["contentCache"]))
 		return tg.SetBody(content)
 	} else {
 		return tg.SetBody([]byte(res.(string)))

+ 46 - 18
src/jfw/modules/app/src/app/jyutil/tags.go

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

+ 2 - 1
src/jfw/modules/app/src/seo.json

@@ -120,5 +120,6 @@
   "seoTotal": 5000,
   "seoUnderlyingAssetsTotal": 100,
   "seoSize": 25,
-  "biddingCacheTime": 43200
+  "biddingCacheTime": 43200,
+  "contentCache": 7200
 }

+ 4 - 6
src/jfw/modules/app/src/web/templates/tags/index.html

@@ -24,12 +24,10 @@
         {{if .T.winnerList}}
             {{include "/tags/template/tag-card-ent.html"}}
         {{end}}
-        {{if .T.biddingList}}
-            {{if or .T.prevPage .T.nextPage}}
-                {{include "/tags/template/tag-card-bidding-info-list.html"}}
-            {{else}}
-                {{include "/tags/template/bidding-card-list.html"}}
-            {{end}}
+        {{if and  .T.biddingList .T.isInfoList}}
+            {{include "/tags/template/tag-card-bidding-info-list.html"}}
+        {{else}}
+            {{include "/tags/template/bidding-card-list.html"}}
         {{end}}
         {{if .T.industryNav}}
             {{include "/tags/template/tag-card-industry-nav.html"}}

+ 18 - 3
src/jfw/tag/tag.go

@@ -15,7 +15,7 @@ var applyVersion = map[string]string{}
 var applyAction = map[string]int64{}
 var applyTime int64 = 5
 
-//自定义标签支持,读取配置文件
+// 自定义标签支持,读取配置文件
 func init() {
 	//应用版本号
 	seoConfigInit()
@@ -23,7 +23,6 @@ func init() {
 	go watchDir("./seo.json")
 }
 
-//
 func seoConfigInit() {
 	util.ReadConfig("./seo.json", &config.Seoconfig)
 	if config.Seoconfig["applyVersion"] != nil {
@@ -38,9 +37,25 @@ func seoConfigInit() {
 			}
 		}
 	}
+	hotBuyerData := util.ObjToMap(config.Seoconfig["hotBuyer"])
+	hotWinnerData := util.ObjToMap(config.Seoconfig["hotWinner"])
+	if hotBuyerData != nil && hotWinnerData != nil {
+		config.HotWinnerConfig = config.HotConfig{
+			CacheKey:     util.InterfaceToStr((*hotWinnerData)["cacheKey"]),
+			CacheTimeout: util.IntAll((*hotWinnerData)["cacheTimeout"]),
+			Limit:        util.IntAll((*hotWinnerData)["limit"]),
+		}
+		config.HotBuyerConfig = config.HotConfig{
+			CacheKey:     util.InterfaceToStr((*hotBuyerData)["cacheKey"]),
+			CacheTimeout: util.IntAll((*hotBuyerData)["cacheTimeout"]),
+			Limit:        util.IntAll((*hotBuyerData)["limit"]),
+		}
+	} else {
+		log.Fatal("获取配置失败,请检查配置文件")
+	}
 }
 
-//监控目录
+// 监控目录
 func watchDir(dir string) {
 	watch, err := fsnotify.NewWatcher()
 	if err != nil {