|
@@ -3,7 +3,6 @@ package front
|
|
import (
|
|
import (
|
|
qu "app.yhyue.com/moapp/jybase/common"
|
|
qu "app.yhyue.com/moapp/jybase/common"
|
|
"app.yhyue.com/moapp/jybase/encrypt"
|
|
"app.yhyue.com/moapp/jybase/encrypt"
|
|
- elastic "app.yhyue.com/moapp/jybase/es"
|
|
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
"app.yhyue.com/moapp/jypkg/common/src/qfw/util/bidsearch"
|
|
"app.yhyue.com/moapp/jypkg/common/src/qfw/util/bidsearch"
|
|
"app.yhyue.com/moapp/jypkg/public"
|
|
"app.yhyue.com/moapp/jypkg/public"
|
|
@@ -25,6 +24,12 @@ import (
|
|
"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+const (
|
|
|
|
+ //企业主体库身份类型区分 sql传值
|
|
|
|
+ IdentityTypeBuyer = 0 // 采购单位
|
|
|
|
+ IdentityTypeWinner = 1 // 中标单位
|
|
|
|
+)
|
|
|
|
+
|
|
type KeyType struct {
|
|
type KeyType struct {
|
|
Name string `json:"name"`
|
|
Name string `json:"name"`
|
|
Url string `json:"url"`
|
|
Url string `json:"url"`
|
|
@@ -67,25 +72,68 @@ func HotSubjectMatter() []map[string]interface{} {
|
|
return subjectMatter
|
|
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
|
|
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 实用内容推荐
|
|
// ContentRecommendation 实用内容推荐
|
|
func ContentRecommendation() []KeyType {
|
|
func ContentRecommendation() []KeyType {
|
|
if bytes, err := redis.GetBytes(RedisNameNew, "contentRecommendation"); err == nil && bytes != nil {
|
|
if bytes, err := redis.GetBytes(RedisNameNew, "contentRecommendation"); err == nil && bytes != nil {
|
|
@@ -298,29 +346,31 @@ type BuyerList struct {
|
|
|
|
|
|
// 热门采购单位
|
|
// 热门采购单位
|
|
func HotBuyerList(entIsNew bool) []*BuyerList {
|
|
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{} {
|
|
func GetIncludedInfo() map[string]interface{} {
|