|
@@ -21,21 +21,20 @@ var (
|
|
)
|
|
)
|
|
|
|
|
|
type Recommend struct {
|
|
type Recommend struct {
|
|
- UseNewest bool
|
|
|
|
|
|
+ newest *[]map[string]interface{}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (r *Recommend) SetNewest() {
|
|
|
|
+ r.newest = elastic.Get(Es_Bidding, Es_Bidding, newestQuery)
|
|
|
|
+}
|
|
func (r *Recommend) SubRecommend(clickhouse *Mysql, domain, userId, content string, mailPush int) (string, string, string, int) {
|
|
func (r *Recommend) SubRecommend(clickhouse *Mysql, domain, userId, content string, mailPush int) (string, string, string, int) {
|
|
- query, area := r.getQuery(clickhouse, userId)
|
|
|
|
|
|
+ list, area := r.getList(clickhouse, userId)
|
|
if area == "" {
|
|
if area == "" {
|
|
area = "全国"
|
|
area = "全国"
|
|
}
|
|
}
|
|
- if query == "" && r.UseNewest {
|
|
|
|
- query = newestQuery
|
|
|
|
- }
|
|
|
|
- if query == "" {
|
|
|
|
- return "", "", "", 0
|
|
|
|
|
|
+ if list == nil || len(*list) == 0 {
|
|
|
|
+ list = r.newest
|
|
}
|
|
}
|
|
- list := elastic.Get(Es_Bidding, Es_Bidding, query)
|
|
|
|
if list == nil || len(*list) == 0 {
|
|
if list == nil || len(*list) == 0 {
|
|
return "", "", "", 0
|
|
return "", "", "", 0
|
|
}
|
|
}
|
|
@@ -73,19 +72,20 @@ func (r *Recommend) SubRecommend(clickhouse *Mysql, domain, userId, content stri
|
|
}
|
|
}
|
|
|
|
|
|
//
|
|
//
|
|
-func (r *Recommend) getQuery(clickhouse *Mysql, userId string) (string, string) {
|
|
|
|
|
|
+func (r *Recommend) getList(clickhouse *Mysql, userId string) (*[]map[string]interface{}, string) {
|
|
datas := clickhouse.SelectBySql(`select bitmapToArray(infoids) as infoids,area from jianyu.sub_recommend_list where userid=? order by update_time desc limit 1`, userId)
|
|
datas := clickhouse.SelectBySql(`select bitmapToArray(infoids) as infoids,area from jianyu.sub_recommend_list where userid=? order by update_time desc limit 1`, userId)
|
|
if datas == nil || len(*datas) == 0 {
|
|
if datas == nil || len(*datas) == 0 {
|
|
- return "", ""
|
|
|
|
|
|
+ return nil, ""
|
|
}
|
|
}
|
|
area, _ := (*datas)[0]["area"].(string)
|
|
area, _ := (*datas)[0]["area"].(string)
|
|
infoids, _ := (*datas)[0]["infoids"].([]uint64)
|
|
infoids, _ := (*datas)[0]["infoids"].([]uint64)
|
|
if len(infoids) == 0 {
|
|
if len(infoids) == 0 {
|
|
- return "", ""
|
|
|
|
|
|
+ return nil, ""
|
|
}
|
|
}
|
|
ids := []string{}
|
|
ids := []string{}
|
|
for _, v := range infoids {
|
|
for _, v := range infoids {
|
|
ids = append(ids, fmt.Sprint(v))
|
|
ids = append(ids, fmt.Sprint(v))
|
|
}
|
|
}
|
|
- return fmt.Sprintf(query, strings.Join(ids, ",")), area
|
|
|
|
|
|
+ list := elastic.Get(Es_Bidding, Es_Bidding, fmt.Sprintf(query, strings.Join(ids, ",")))
|
|
|
|
+ return list, area
|
|
}
|
|
}
|