user_label.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package services
  2. import (
  3. "fmt"
  4. "hongze/hongze_clpt/models"
  5. "hongze/hongze_clpt/utils"
  6. "time"
  7. )
  8. // 添加用户阅读标签到Redis
  9. func ArticleHistoryUserLabelLogAdd(articleId, uid int) (err error) {
  10. defer func() {
  11. if err != nil {
  12. fmt.Println(err)
  13. msg := fmt.Sprint("articleId:", articleId, "userId:", uid)
  14. go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
  15. }
  16. }()
  17. // SourceType 1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。
  18. log := &models.CygxUserLabelLogRedis{UserId: uid, SourceId: articleId, SourceType: 1, CreateTime: time.Now()}
  19. if utils.Re == nil {
  20. err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
  21. if err != nil {
  22. fmt.Println("CygxUserLabelLogRedis LPush Err:" + err.Error())
  23. }
  24. }
  25. return
  26. }
  27. // 添加用户2产业关注标签到Redis
  28. func IndustryFllowUserLabelLogAdd(industrialManagementId, count, uid int) (err error) {
  29. var isFllow int
  30. if count == 0 {
  31. isFllow = 1
  32. } else {
  33. isFllow = 0
  34. }
  35. defer func() {
  36. if err != nil {
  37. fmt.Println(err)
  38. msg := fmt.Sprint("industrialManagementId:", industrialManagementId, "isFllow:", isFllow, "userId:", uid)
  39. go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
  40. }
  41. }()
  42. log := &models.CygxUserLabelLogRedis{UserId: uid, SourceId: industrialManagementId, SourceType: 2, IsFllow: isFllow, CreateTime: time.Now()}
  43. if utils.Re == nil {
  44. err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
  45. if err != nil {
  46. fmt.Println("RecordNewLogs LPush Err:" + err.Error())
  47. }
  48. }
  49. return
  50. }
  51. // 添加用户4系列关注标签到Redis
  52. func CategoryFllowUserLabelLogAdd(industrialManagementId, count, uid int) (err error) {
  53. var isFllow int
  54. if count == 0 {
  55. isFllow = 1
  56. } else {
  57. isFllow = 0
  58. }
  59. defer func() {
  60. if err != nil {
  61. fmt.Println(err)
  62. msg := fmt.Sprint("industrialManagementId:", industrialManagementId, "isFllow:", isFllow, "userId:", uid)
  63. go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
  64. }
  65. }()
  66. log := &models.CygxUserLabelLogRedis{UserId: uid, SourceId: industrialManagementId, SourceType: 4, IsFllow: isFllow, CreateTime: time.Now()}
  67. if utils.Re == nil {
  68. err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
  69. if err != nil {
  70. fmt.Println("RecordNewLogs LPush Err:" + err.Error())
  71. }
  72. }
  73. return
  74. }