recommend.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package recommend
  2. import (
  3. "fmt"
  4. "strings"
  5. "app.yhyue.com/moapp/jybase/encrypt"
  6. elastic "app.yhyue.com/moapp/jybase/es"
  7. . "app.yhyue.com/moapp/jybase/mysql"
  8. . "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
  9. )
  10. const (
  11. 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}`
  12. )
  13. var VarRecommend = &Recommend{}
  14. type Recommend struct {
  15. }
  16. func (r *Recommend) SubRecommend(clickhouse *Mysql, domain, userId, content string, mailPush int) (string, string, string, int) {
  17. datas := clickhouse.SelectBySql(`select bitmapToArray(infoids) as infoids,area from jianyu.sub_recommend_list where userid=? order by update_time desc limit 1`, userId)
  18. if datas == nil || len(*datas) == 0 {
  19. return "", "", "", 0
  20. }
  21. area, _ := (*datas)[0]["area"].(string)
  22. if area == "" {
  23. area = "全国"
  24. }
  25. infoids, _ := (*datas)[0]["infoids"].([]uint64)
  26. if len(infoids) == 0 {
  27. return "", "", "", 0
  28. }
  29. ids := []string{}
  30. for _, v := range infoids {
  31. ids = append(ids, fmt.Sprint(v))
  32. }
  33. list := elastic.Get(Es_Bidding, Es_Bidding, fmt.Sprintf(query, strings.Join(ids, ",")))
  34. if list == nil || len(*list) == 0 {
  35. return "", "", "", 0
  36. }
  37. mailContent := ""
  38. firstTitle := ""
  39. infosLength := 0
  40. for _, v := range *list {
  41. infosLength++
  42. info := NewBiddingInfo(v, []string{})
  43. if infosLength == 1 {
  44. firstTitle = info.ClearTitle
  45. }
  46. if mailPush == 1 { //关于邮件的处理
  47. url := fmt.Sprintf("%s/article/mailprivate/%s.html", domain, encrypt.CommonEncodeArticle("mailprivate", info.Id))
  48. acountClassName := "none_a"
  49. if info.Acount != "" {
  50. acountClassName = "acount"
  51. }
  52. industryClassName := ""
  53. if info.Buyerclass != "" {
  54. industryClassName = "buyerclass"
  55. }
  56. areaClassName := ""
  57. if info.Area != "" {
  58. areaClassName = "area"
  59. }
  60. typeClassName := ""
  61. if info.Infotype != "" {
  62. typeClassName = "type"
  63. }
  64. mailContent += fmt.Sprintf(content, infosLength, url, info.HighlightTitle, areaClassName, info.Area, typeClassName, info.Infotype, industryClassName, info.Buyerclass, acountClassName, info.Acount, info.PublishtimeDiff)
  65. }
  66. }
  67. return firstTitle, area, mailContent, infosLength
  68. }