|
@@ -3,16 +3,18 @@ package recommend
|
|
|
import (
|
|
|
"fmt"
|
|
|
"strings"
|
|
|
+ "time"
|
|
|
|
|
|
. "app.yhyue.com/moapp/jybase/common"
|
|
|
"app.yhyue.com/moapp/jybase/encrypt"
|
|
|
elastic "app.yhyue.com/moapp/jybase/es"
|
|
|
+ . "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
. "app.yhyue.com/moapp/jybase/mysql"
|
|
|
. "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
- fields = `"_id","title","area","publishtime","buyerclass","s_subscopeclass","bidamount","budget","subtype","toptype"`
|
|
|
+ fields = `"_id","title","area","publishtime","buyerclass","s_subscopeclass","bidamount","budget","subtype","toptype","autoid"`
|
|
|
searchTmpl = `您搜索的“%s”有新的机会`
|
|
|
visitTmpl = `您浏览过的“%s”项目有同类项目`
|
|
|
subsetTmpl = `您订阅的“%s”有新的机会`
|
|
@@ -31,7 +33,7 @@ type Recommend struct {
|
|
|
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) {
|
|
|
+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)
|
|
|
if area == "" {
|
|
|
area = "全国"
|
|
@@ -40,14 +42,19 @@ func (r *Recommend) SubRecommend(tidb *Mysql, domain, userId, content string, ma
|
|
|
list = r.newest
|
|
|
}
|
|
|
if list == nil || len(*list) == 0 {
|
|
|
- return "", "", "", "", 0
|
|
|
+ return "", "", "", "", 0, 0
|
|
|
}
|
|
|
mailContent := ""
|
|
|
firstTitle := ""
|
|
|
infosLength := 0
|
|
|
jcly := ""
|
|
|
- for k, v := range *list {
|
|
|
- if k == 0 {
|
|
|
+ var firstAutoId int64
|
|
|
+ for _, v := range *list {
|
|
|
+ infosLength++
|
|
|
+ info := NewBiddingInfo(v, []string{})
|
|
|
+ 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))
|
|
@@ -57,11 +64,6 @@ func (r *Recommend) SubRecommend(tidb *Mysql, domain, userId, content string, ma
|
|
|
jcly = fmt.Sprintf(visitTmpl, ShortenTxt(20, fmt.Sprintf(visitTmpl, ""), matchkeys))
|
|
|
}
|
|
|
}
|
|
|
- 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"
|
|
@@ -83,7 +85,7 @@ func (r *Recommend) SubRecommend(tidb *Mysql, domain, userId, content string, ma
|
|
|
mailContent += fmt.Sprintf(content, infosLength, url, info.HighlightTitle, areaClassName, info.Area, typeClassName, info.Infotype, industryClassName, info.Buyerclass, acountClassName, info.Acount, info.PublishtimeDiff)
|
|
|
}
|
|
|
}
|
|
|
- return firstTitle, area, jcly, mailContent, infosLength
|
|
|
+ return firstTitle, area, jcly, mailContent, infosLength, firstAutoId
|
|
|
}
|
|
|
|
|
|
//
|
|
@@ -115,3 +117,12 @@ func (r *Recommend) getList(tidb *Mysql, userId string, limit int) (*[]map[strin
|
|
|
}
|
|
|
return list, area
|
|
|
}
|
|
|
+
|
|
|
+//
|
|
|
+func (r *Recommend) SaveLog(mgo *MongodbSim, userId string, autoId int64) string {
|
|
|
+ return mgo.Save("subrecommend_log", map[string]interface{}{
|
|
|
+ "userid": userId,
|
|
|
+ "autoid": autoId,
|
|
|
+ "create_time": time.Now().Unix(),
|
|
|
+ })
|
|
|
+}
|