user_label.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package services
  2. import (
  3. "fmt"
  4. "hongze/hongze_cygxzs/models"
  5. "hongze/hongze_cygxzs/utils"
  6. "time"
  7. )
  8. func UserSubmit(itemsFllow []*models.CygxIndustryFllow, itemsCategory []*models.CygxXzsChooseCategory, userId int) (err error) {
  9. e := models.UpdateCygxUserLabelNofollow(userId)
  10. if e != nil {
  11. go utils.SendAlarmMsg("用户关注产业更新相关标签,UserSubmit,Err :"+e.Error(), 2)
  12. }
  13. if len(itemsFllow) > 0 {
  14. mapIndustryId := make(map[int]bool)
  15. var condition string
  16. var pars []interface{}
  17. condition = ` AND is_follow=1 AND source = 1 AND user_id = ? `
  18. pars = append(pars, userId)
  19. list, e := models.GetCygxUserLabelList(condition, pars)
  20. if e != nil {
  21. go utils.SendAlarmMsg("用户关注产业更新相关标签,查询相关信息失败:"+e.Error(), 2)
  22. }
  23. for _, v := range list {
  24. mapIndustryId[v.SourceId] = true
  25. }
  26. for _, v := range itemsFllow {
  27. if !mapIndustryId[v.IndustrialManagementId] {
  28. IndustryFllowUserLabelLogAdd(v.IndustrialManagementId, 0, userId)
  29. }
  30. }
  31. }
  32. if len(itemsCategory) > 0 {
  33. mapIndustryId := make(map[int]bool)
  34. var condition string
  35. var pars []interface{}
  36. condition = ` AND is_follow=1 AND source = 2 AND user_id = ? `
  37. pars = append(pars, userId)
  38. list, e := models.GetCygxUserLabelList(condition, pars)
  39. if e != nil {
  40. go utils.SendAlarmMsg("用户关注系列更新相关标签,查询相关信息失败:"+e.Error(), 2)
  41. }
  42. for _, v := range list {
  43. mapIndustryId[v.SourceId] = true
  44. }
  45. for _, v := range itemsCategory {
  46. if !mapIndustryId[v.IdCygx] && v.IdCygx > 0 {
  47. CategoryFllowUserLabelLogAdd(v.IdCygx, 0, userId)
  48. }
  49. }
  50. }
  51. return
  52. }
  53. //SourceType int `description:"1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。"`
  54. // 添加用户2产业关注标签到Redis
  55. func IndustryFllowUserLabelLogAdd(industrialManagementId, count, uid int) (err error) {
  56. var isFllow int
  57. if count == 0 {
  58. isFllow = 1
  59. } else {
  60. isFllow = 0
  61. }
  62. defer func() {
  63. if err != nil {
  64. fmt.Println(err)
  65. msg := fmt.Sprint("industrialManagementId:", industrialManagementId, "isFllow:", isFllow, "userId:", uid)
  66. go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
  67. }
  68. }()
  69. log := &models.CygxUserLabelLogRedis{UserId: uid, SourceId: industrialManagementId, SourceType: 2, IsFllow: isFllow, CreateTime: time.Now()}
  70. if utils.Re == nil {
  71. err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
  72. if err != nil {
  73. fmt.Println("RecordNewLogs LPush Err:" + err.Error())
  74. }
  75. }
  76. return
  77. }
  78. // 添加用户4系列关注标签到Redis
  79. func CategoryFllowUserLabelLogAdd(industrialManagementId, count, uid int) (err error) {
  80. var isFllow int
  81. if count == 0 {
  82. isFllow = 1
  83. } else {
  84. isFllow = 0
  85. }
  86. defer func() {
  87. if err != nil {
  88. fmt.Println(err)
  89. msg := fmt.Sprint("industrialManagementId:", industrialManagementId, "isFllow:", isFllow, "userId:", uid)
  90. go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
  91. }
  92. }()
  93. log := &models.CygxUserLabelLogRedis{UserId: uid, SourceId: industrialManagementId, SourceType: 4, IsFllow: isFllow, CreateTime: time.Now()}
  94. if utils.Re == nil {
  95. err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
  96. if err != nil {
  97. fmt.Println("RecordNewLogs LPush Err:" + err.Error())
  98. }
  99. }
  100. return
  101. }