|
@@ -4,6 +4,7 @@ import (
|
|
"fmt"
|
|
"fmt"
|
|
"strings"
|
|
"strings"
|
|
|
|
|
|
|
|
+ . "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"
|
|
elastic "app.yhyue.com/moapp/jybase/es"
|
|
. "app.yhyue.com/moapp/jybase/mysql"
|
|
. "app.yhyue.com/moapp/jybase/mysql"
|
|
@@ -16,19 +17,19 @@ const (
|
|
|
|
|
|
var (
|
|
var (
|
|
VarRecommend = &Recommend{}
|
|
VarRecommend = &Recommend{}
|
|
- query = `{"query":{"bool":{"must":[{"terms":{"autoid":[%s]}}]}},"_source":[` + fields + `],"sort":[{"publishtime":"desc"}],"from":0,"size":100}`
|
|
|
|
- newestQuery = `{"query":{"bool":{"must":[{"match_all":{}}]}},"_source":[` + fields + `],"sort":[{"publishtime":"desc"}],"size":10}`
|
|
|
|
|
|
+ query = `{"query":{"bool":{"must":[{"terms":{"autoid":[%s]}}]}},"_source":[` + fields + `],"sort":[{"publishtime":"desc"}],"from":0,"size":%d}`
|
|
|
|
+ newestQuery = `{"query":{"bool":{"must":[{"match_all":{}}]}},"_source":[` + fields + `],"sort":[{"publishtime":"desc"}],"size":%d}`
|
|
)
|
|
)
|
|
|
|
|
|
type Recommend struct {
|
|
type Recommend struct {
|
|
newest *[]map[string]interface{}
|
|
newest *[]map[string]interface{}
|
|
}
|
|
}
|
|
|
|
|
|
-func (r *Recommend) SetNewest() {
|
|
|
|
- r.newest = elastic.Get(Es_Bidding, Es_Bidding, newestQuery)
|
|
|
|
|
|
+func (r *Recommend) SetNewest(size int) {
|
|
|
|
+ r.newest = elastic.Get(Es_Bidding, Es_Bidding, fmt.Sprintf(newestQuery, size))
|
|
}
|
|
}
|
|
-func (r *Recommend) SubRecommend(clickhouse *Mysql, domain, userId, content string, mailPush int) (string, string, string, int) {
|
|
|
|
- list, area := r.getList(clickhouse, userId)
|
|
|
|
|
|
+func (r *Recommend) SubRecommend(tidb *Mysql, domain, userId, content string, mailPush, limit int) (string, string, string, int) {
|
|
|
|
+ list, area := r.getList(tidb, userId, limit)
|
|
if area == "" {
|
|
if area == "" {
|
|
area = "全国"
|
|
area = "全国"
|
|
}
|
|
}
|
|
@@ -72,20 +73,31 @@ func (r *Recommend) SubRecommend(clickhouse *Mysql, domain, userId, content stri
|
|
}
|
|
}
|
|
|
|
|
|
//
|
|
//
|
|
-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)
|
|
|
|
|
|
+func (r *Recommend) getList(tidb *Mysql, userId string, limit int) (*[]map[string]interface{}, string) {
|
|
|
|
+ datas := tidb.SelectBySql(`select autoid,area,type from push.sub_recommend_list where userid=? order by create_time desc limit ?`, userId, limit)
|
|
if datas == nil || len(*datas) == 0 {
|
|
if datas == nil || len(*datas) == 0 {
|
|
return nil, ""
|
|
return nil, ""
|
|
}
|
|
}
|
|
- area, _ := (*datas)[0]["area"].(string)
|
|
|
|
- infoids, _ := (*datas)[0]["infoids"].([]uint64)
|
|
|
|
- if len(infoids) == 0 {
|
|
|
|
|
|
+ areaMap := map[string]bool{}
|
|
|
|
+ ids := []string{}
|
|
|
|
+ areas := []string{}
|
|
|
|
+ for _, v := range *datas {
|
|
|
|
+ ids = append(ids, fmt.Sprint(Int64All(v["autoid"])))
|
|
|
|
+ area, _ := (*datas)[0]["area"].(string)
|
|
|
|
+ for _, vv := range strings.Split(area, " ") {
|
|
|
|
+ if !areaMap[vv] {
|
|
|
|
+ areas = append(areas, vv)
|
|
|
|
+ }
|
|
|
|
+ areaMap[vv] = true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if len(ids) == 0 {
|
|
return nil, ""
|
|
return nil, ""
|
|
}
|
|
}
|
|
- ids := []string{}
|
|
|
|
- for _, v := range infoids {
|
|
|
|
- ids = append(ids, fmt.Sprint(v))
|
|
|
|
|
|
+ list := elastic.Get(Es_Bidding, Es_Bidding, fmt.Sprintf(query, strings.Join(ids, ","), limit))
|
|
|
|
+ area := "全国"
|
|
|
|
+ if !areaMap[area] {
|
|
|
|
+ area = strings.Join(areas, " ")
|
|
}
|
|
}
|
|
- list := elastic.Get(Es_Bidding, Es_Bidding, fmt.Sprintf(query, strings.Join(ids, ",")))
|
|
|
|
return list, area
|
|
return list, area
|
|
}
|
|
}
|