recall.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package dao
  2. import (
  3. "context"
  4. recsys "go-common/app/service/bbq/recsys/api/grpc/v1"
  5. "go-common/app/service/bbq/recsys/model"
  6. "go-common/app/service/bbq/recsys/service/retrieve"
  7. "go-common/library/cache/redis"
  8. "go-common/library/log"
  9. "strconv"
  10. "strings"
  11. )
  12. //DownGradeRecall ...
  13. func (d *Dao) DownGradeRecall(c context.Context) (response *recsys.RecsysResponse, err error) {
  14. conn := d.redis.Get(c)
  15. defer conn.Close()
  16. key := retrieve.RecallHotDefault
  17. var str string
  18. if str, err = redis.String(conn.Do("GET", key)); err != nil {
  19. if err == redis.ErrNil {
  20. err = nil
  21. } else {
  22. log.Errorw(c, "recall", "get hot recall error", "err", err)
  23. }
  24. }
  25. response = new(recsys.RecsysResponse)
  26. response.Message = make(map[string]string)
  27. records := make([]*recsys.RecsysRecord, 0)
  28. response.Message[model.ResponseDownGrade] = "2"
  29. for _, svidStr := range strings.Split(str, ",") {
  30. svid, _ := strconv.ParseInt(svidStr, 10, 64)
  31. record := &recsys.RecsysRecord{
  32. Svid: svid,
  33. Score: 0,
  34. Map: make(map[string]string),
  35. }
  36. record.Map[model.RecallClasses] = retrieve.HotRecall
  37. records = append(records, record)
  38. }
  39. key = retrieve.RecallOpVideoKey
  40. if str, err = redis.String(conn.Do("GET", key)); err != nil {
  41. if err == redis.ErrNil {
  42. err = nil
  43. } else {
  44. log.Errorw(c, "recall", "get selection recall error", "err", err)
  45. }
  46. }
  47. response = new(recsys.RecsysResponse)
  48. response.Message = make(map[string]string)
  49. for _, svidStr := range strings.Split(str, ",") {
  50. svid, _ := strconv.ParseInt(svidStr, 10, 64)
  51. record := &recsys.RecsysRecord{
  52. Svid: svid,
  53. Score: 0,
  54. Map: make(map[string]string),
  55. }
  56. record.Map[model.RecallClasses] = retrieve.SelectionRecall
  57. records = append(records, record)
  58. }
  59. response.List = records
  60. return
  61. }