wangchuanjin 8 ヶ月 前
コミット
4294fe83cc
1 ファイル変更33 行追加29 行削除
  1. 33 29
      recommend/recommend.go

+ 33 - 29
recommend/recommend.go

@@ -14,7 +14,7 @@ import (
 )
 
 const (
-	fields     = `"_id","title","area","publishtime","buyerclass","s_subscopeclass","bidamount","budget","subtype","toptype","autoid"`
+	fields     = `"_id","autoid","title","area","publishtime","buyerclass","s_subscopeclass","bidamount","budget","subtype","toptype"`
 	searchTmpl = `您搜索的“%s”有新的机会`
 	visitTmpl  = `您浏览过的“%s”项目有同类项目`
 	subsetTmpl = `您订阅的“%s”有新的机会`
@@ -34,7 +34,7 @@ func (r *Recommend) SetNewest(size int) {
 	r.newest = elastic.Get(Es_Bidding, Es_Bidding, fmt.Sprintf(newestQuery, size))
 }
 func (r *Recommend) SubRecommend(tidb *Mysql, domain, userId, content string, mailPush, limit int) (string, string, string, string, int, int64) {
-	list, area := r.getList(tidb, userId, limit)
+	list, area, jcly := r.getList(tidb, userId, limit)
 	if area == "" {
 		area = "全国"
 	}
@@ -44,10 +44,8 @@ func (r *Recommend) SubRecommend(tidb *Mysql, domain, userId, content string, ma
 	if list == nil || len(*list) == 0 {
 		return "", "", "", "", 0, 0
 	}
-	mailContent := ""
-	firstTitle := ""
+	var firstTitle, mailContent string
 	infosLength := 0
-	jcly := ""
 	var firstAutoId int64
 	for _, v := range *list {
 		infosLength++
@@ -55,14 +53,6 @@ func (r *Recommend) SubRecommend(tidb *Mysql, domain, userId, content string, ma
 		if infosLength == 1 {
 			firstTitle = info.ClearTitle
 			firstAutoId = info.AutoId
-			matchkeys := ObjToString(v["matchkeys"])
-			if typ := Int64All(v["type"]); typ == 1 {
-				jcly = fmt.Sprintf(subsetTmpl, ShortenTxt(20, fmt.Sprintf(subsetTmpl, ""), matchkeys))
-			} else if typ == 2 {
-				jcly = fmt.Sprintf(searchTmpl, ShortenTxt(20, fmt.Sprintf(searchTmpl, ""), matchkeys))
-			} else if typ == 3 {
-				jcly = fmt.Sprintf(visitTmpl, ShortenTxt(20, fmt.Sprintf(visitTmpl, ""), matchkeys))
-			}
 		}
 		if mailPush == 1 { //关于邮件的处理
 			url := fmt.Sprintf("%s/article/mailprivate/%s.html", domain, encrypt.CommonEncodeArticle("mailprivate", info.Id))
@@ -89,33 +79,47 @@ func (r *Recommend) SubRecommend(tidb *Mysql, domain, userId, content string, ma
 }
 
 //
-func (r *Recommend) getList(tidb *Mysql, userId string, limit int) (*[]map[string]interface{}, string) {
+func (r *Recommend) getList(tidb *Mysql, userId string, limit int) (*[]map[string]interface{}, string, string) {
 	datas := tidb.SelectBySql(`select type,autoid,area,matchkeys from push.sub_recommend_list where userid=? order by create_time desc limit ?`, userId, limit)
 	if datas == nil || len(*datas) == 0 {
-		return nil, ""
+		return nil, "", ""
 	}
-	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, "", ""
 	}
+	mp := map[int64]map[string]interface{}{}
 	list := elastic.Get(Es_Bidding, Es_Bidding, fmt.Sprintf(query, strings.Join(ids, ","), limit))
-	area := "全国"
-	if !areaMap[area] {
-		area = strings.Join(areas, " ")
+	if list == nil {
+		return nil, "", ""
+	}
+	for _, v := range *list {
+		mp[Int64All(v["autoid"])] = v
+	}
+	newList := []map[string]interface{}{}
+	area := ""
+	var jcly string
+	for _, v := range *datas {
+		autoid := Int64All(v["autoid"])
+		if mp[autoid] == nil {
+			continue
+		}
+		newList = append(newList, mp[autoid])
+		if jcly == "" {
+			area, _ = v["area"].(string)
+			if matchkeys, typ := ObjToString(v["matchkeys"]), Int64All(v["type"]); typ == 1 {
+				jcly = fmt.Sprintf(subsetTmpl, ShortenTxt(20, fmt.Sprintf(subsetTmpl, ""), matchkeys))
+			} else if typ == 2 {
+				jcly = fmt.Sprintf(searchTmpl, ShortenTxt(20, fmt.Sprintf(searchTmpl, ""), matchkeys))
+			} else if typ == 3 {
+				jcly = fmt.Sprintf(visitTmpl, ShortenTxt(20, fmt.Sprintf(visitTmpl, ""), matchkeys))
+			}
+		}
 	}
-	return list, area
+	return &newList, jcly, area
 }
 
 //