瀏覽代碼

feat:pc首页热门采购单位中标单位调整

fuwencai 2 年之前
父節點
當前提交
be4440bf77
共有 3 個文件被更改,包括 123 次插入37 次删除
  1. 12 1
      src/config.json
  2. 25 0
      src/jfw/config/config.go
  3. 86 36
      src/jfw/front/classificationTag.go

+ 12 - 1
src/config.json

@@ -429,5 +429,16 @@
     "approvecity": true
   },
   "detailRedisByPayTimeOut": 7200,
-  "detailRedisByFreeTimeOut": 7200
+  "detailRedisByFreeTimeOut": 7200,
+  "hotWinner": {
+    "cacheKey": "hotWinnerCache",
+    "cacheTimeout": 86400,
+    "limit": 200
+  },
+  "hotBuyer": {
+    "cacheKey": "hotBuyerCache",
+    "cacheTimeout": 86400,
+    "limit": 200
+  }
+
 }

+ 25 - 0
src/jfw/config/config.go

@@ -7,6 +7,7 @@ import (
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/os/gcfg"
 	"github.com/gogf/gf/v2/os/gctx"
+	"log"
 )
 
 var (
@@ -20,8 +21,15 @@ var (
 	GmailAuth            []*mail.GmailAuth
 	EntnichePcConf       *entnichePcConf
 	Middleground         *middleground.Middleground
+	HotWinnerConfig      hotConfig
+	HotBuyerConfig       hotConfig
 )
 
+type hotConfig struct {
+	CacheKey     string `json:"cacheKey"`
+	CacheTimeout int    `json:"cacheTimeout"`
+	Limit        int    `json:"limit"`
+}
 type entnichePcConf struct {
 	EntnichePcUser   []int  `json:"entnichePcUser"`
 	HideEntnicheMenu []int  `json:"hideEntnicheMenu"`
@@ -58,4 +66,21 @@ 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(Sysconfig["hotBuyer"])
+	hotWinnerData := util.ObjToMap(Sysconfig["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("获取配置失败,请检查配置文件")
+	}
+
 }

+ 86 - 36
src/jfw/front/classificationTag.go

@@ -3,7 +3,6 @@ package front
 import (
 	qu "app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/encrypt"
-	elastic "app.yhyue.com/moapp/jybase/es"
 	"app.yhyue.com/moapp/jybase/redis"
 	"app.yhyue.com/moapp/jypkg/common/src/qfw/util/bidsearch"
 	"app.yhyue.com/moapp/jypkg/public"
@@ -25,6 +24,12 @@ import (
 	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
 )
 
+const (
+	//企业主体库身份类型区分 sql传值
+	IdentityTypeBuyer  = 0 // 采购单位
+	IdentityTypeWinner = 1 // 中标单位
+)
+
 type KeyType struct {
 	Name     string    `json:"name"`
 	Url      string    `json:"url"`
@@ -67,25 +72,68 @@ func HotSubjectMatter() []map[string]interface{} {
 	return subjectMatter
 }
 
-// 随机展示200中标企业
-func GetWinnerInfo() (data []BuyerList) {
-	randGen := rand.New(rand.NewSource(time.Now().UnixNano()))
-	from := randGen.Intn(100)
-
+// 最新更新的200中标企业
+func GetWinnerInfo() (data []*BuyerList) {
+	// 取缓存
+	cache, err := GetHotCache(config.HotWinnerConfig.CacheKey)
+	if err == nil && cache != nil && len(cache) > 0 {
+		return cache
+	}
+	// 没取到缓存查数据
+	rs := getEntBaseInfo(IdentityTypeWinner, config.HotWinnerConfig.Limit)
 	//关联中标企业
-	r := elastic.Get("qyxy", "qyxy", fmt.Sprintf(`{"query": {"bool": {"must": []}},"_source": ["_id","company_name"],"from": %d,"size": 200}`, from))
-	if r != nil {
-		for _, v := range *r {
-			var vs BuyerList
-			id := encrypt.EncodeArticleId2ByCheck(qu.InterfaceToStr(v["_id"]))
-			vs.Name = qu.InterfaceToStr(v["company_name"])
-			vs.Url = fmt.Sprintf("/swordfish/page_big_pc/ent_portrait/%s", id)
-			data = append(data, vs)
-		}
+	if rs == nil || len(*rs) == 0 {
+		return
 	}
+
+	for _, v := range *rs {
+		var vs BuyerList
+		id := encrypt.EncodeArticleId2ByCheck(qu.InterfaceToStr(v["id"]))
+		vs.Name = qu.InterfaceToStr(v["company_name"])
+		vs.Url = fmt.Sprintf("/swordfish/page_big_pc/ent_portrait/%s", id)
+		data = append(data, &vs)
+	}
+	// 存缓存
+	go PutHotCache(config.HotWinnerConfig.CacheKey, config.HotWinnerConfig.CacheTimeout, data)
 	return
 }
 
+// PutHotCache 热门采购单位、中标单位存缓存
+func PutHotCache(redisKey string, redisTimeout int, list []*BuyerList) {
+	b, err := json.Marshal(list)
+	if err != nil {
+		log.Printf("保存缓存 序列化异常,data:%s,err:%s\n", list, err.Error())
+		return
+	}
+	if err = redis.PutBytes("new", redisKey, &b, redisTimeout); err != nil {
+		log.Printf("保存缓存 redis 异常,key:%s,err:%s\n", redisKey, err.Error())
+	}
+
+}
+
+// GetHotCache 热门采购单位、中标单位取缓存
+func GetHotCache(redisKey string) (list []*BuyerList, err error) {
+	redisByte, err := redis.GetBytes("new", redisKey)
+	if err != nil || redisByte == nil || len(*redisByte) == 0 {
+		return list, err
+	}
+	err = json.Unmarshal(*redisByte, &list)
+	if err != nil {
+		log.Println(fmt.Sprintf("读取缓存 序列化异常,err:%s", err.Error()))
+		return nil, err
+	}
+	return list, nil
+}
+
+// 获取最新的中标单位
+// identityType : 0 采购单位 1-中标单位
+// limit: 数量
+func getEntBaseInfo(identityType, limit int) *[]map[string]interface{} {
+	q := "SELECT  company_id AS id,name FROM   dws_f_ent_baseinfo WHERE     company_id !='' and company_id is not null  AND (identity_type &(1 << ?)) > 0 order by datetime desc  limit ?"
+	return public.BaseMysql.SelectBySql(q, identityType, limit)
+
+}
+
 // ContentRecommendation 实用内容推荐
 func ContentRecommendation() []KeyType {
 	if bytes, err := redis.GetBytes(RedisNameNew, "contentRecommendation"); err == nil && bytes != nil {
@@ -298,29 +346,31 @@ type BuyerList struct {
 
 // 热门采购单位
 func HotBuyerList(entIsNew bool) []*BuyerList {
-	// 使用当前时间作为随机数生成器的种子
-	randGen := rand.New(rand.NewSource(time.Now().UnixNano()))
-	// 获取一个范围在 [0, 100) 的随机整数
-	start := randGen.Intn(100)
-	buyerQuery := fmt.Sprintf(`{"query": {"bool": {"must": [{"exists": {"field": "name"}}]}},"from": %d,"size": %d}`, start, 200)
-	log.Println("buyerQuery:", buyerQuery)
-	data := elastic.Get("buyer", "buyer", buyerQuery)
-	if data != nil && len(*data) > 0 {
-		var buyerList []*BuyerList
-		for _, b := range *data {
-			name := qu.ObjToString(b["name"])
-			buyerId := qu.ObjToString(b["id"])
-			if name != "" && buyerId != "" {
-				idEncode := encrypt.EncodeArticleId2ByCheck(buyerId)
-				buyerList = append(buyerList, &BuyerList{
-					Name: name,
-					Url:  qu.If(entIsNew, fmt.Sprintf("/entpc/unit_portrayal_id/%s", idEncode), fmt.Sprintf("/swordfish/page_big_pc/unit_portrayal_id/%s", idEncode)).(string),
-				})
-			}
+	// 取缓存
+	cache, err := GetHotCache(config.HotWinnerConfig.CacheKey)
+	if err == nil && cache != nil && len(cache) > 0 {
+		return cache
+	}
+	// 查数据
+	data := getEntBaseInfo(IdentityTypeBuyer, config.HotBuyerConfig.Limit)
+	if data == nil || len(*data) == 0 {
+		return nil
+	}
+	var buyerList []*BuyerList
+	for _, b := range *data {
+		name := qu.ObjToString(b["name"])
+		buyerId := qu.ObjToString(b["id"])
+		if name != "" && buyerId != "" {
+			idEncode := encrypt.EncodeArticleId2ByCheck(buyerId)
+			buyerList = append(buyerList, &BuyerList{
+				Name: name,
+				Url:  qu.If(entIsNew, fmt.Sprintf("/entpc/unit_portrayal_id/%s", idEncode), fmt.Sprintf("/swordfish/page_big_pc/unit_portrayal_id/%s", idEncode)).(string),
+			})
 		}
-		return buyerList
 	}
-	return nil
+	//存缓存
+	return buyerList
+
 }
 
 func GetIncludedInfo() map[string]interface{} {