瀏覽代碼

feat:推荐封装

wangchuanjin 1 年之前
父節點
當前提交
77741cc44f
共有 1 個文件被更改,包括 70 次插入0 次删除
  1. 70 0
      recommend/recommend.go

+ 70 - 0
recommend/recommend.go

@@ -0,0 +1,70 @@
+package recommend
+
+import (
+	"fmt"
+	"strings"
+
+	"app.yhyue.com/moapp/jybase/encrypt"
+	elastic "app.yhyue.com/moapp/jybase/es"
+	. "app.yhyue.com/moapp/jybase/mysql"
+	. "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
+)
+
+const (
+	query = `{"query":{"bool":{"must":[{"terms":{"autoid":[%s]}}]}},"_source":["_id","title","area","publishtime","buyerclass","s_subscopeclass","bidamount","budget","subtype","toptype"],"sort":[{"publishtime":"desc"}],"from":0,"size":100}`
+)
+
+var VarRecommend = &Recommend{}
+
+type Recommend struct {
+}
+
+func (r *Recommend) SubRecommend(clickhouse *Mysql, domain, userId, content string, mailPush int) (string, string, int) {
+	datas := clickhouse.SelectBySql(`select bitmapToArray(infoids) as infoids from jianyu.sub_recommend_list where userid=? order by update_time desc limit 1`, userId)
+	if datas == nil || len(*datas) == 0 {
+		return "", "", 0
+	}
+	infoids, _ := (*datas)[0]["infoids"].([]uint64)
+	if len(infoids) == 0 {
+		return "", "", 0
+	}
+	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, ",")))
+	if list == nil || len(*list) == 0 {
+		return "", "", 0
+	}
+	mailContent := ""
+	firstTitle := ""
+	infosLength := 0
+	for _, v := range *list {
+		infosLength++
+		info := NewBiddingInfo(v, []string{})
+		if infosLength == 1 {
+			firstTitle = info.ClearTitle
+		}
+		if mailPush == 1 { //关于邮件的处理
+			url := fmt.Sprintf("%s/article/mailprivate/%s.html", domain, encrypt.CommonEncodeArticle("mailprivate", info.Id))
+			acountClassName := "none_a"
+			if info.Acount != "" {
+				acountClassName = "acount"
+			}
+			industryClassName := ""
+			if info.Buyerclass != "" {
+				industryClassName = "buyerclass"
+			}
+			areaClassName := ""
+			if info.Area != "" {
+				areaClassName = "area"
+			}
+			typeClassName := ""
+			if info.Infotype != "" {
+				typeClassName = "type"
+			}
+			mailContent += fmt.Sprintf(content, infosLength, url, info.HighlightTitle, areaClassName, info.Area, typeClassName, info.Infotype, industryClassName, info.Buyerclass, acountClassName, info.Acount, info.PublishtimeDiff)
+		}
+	}
+	return firstTitle, mailContent, infosLength
+}