user_label.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_mfyx/models"
  6. "hongze/hongze_mfyx/utils"
  7. "time"
  8. )
  9. // 添加用户阅读标签到Redis
  10. func ArticleHistoryUserLabelLogAdd(articleId, uid int) (err error) {
  11. defer func() {
  12. if err != nil {
  13. fmt.Println(err)
  14. msg := fmt.Sprint("articleId:", articleId, "userId:", uid)
  15. go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
  16. }
  17. }()
  18. // SourceType 1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。
  19. log := &models.CygxUserLabelLogRedis{UserId: uid, SourceId: articleId, SourceType: 1, CreateTime: time.Now()}
  20. if utils.Re == nil {
  21. err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
  22. if err != nil {
  23. fmt.Println("CygxUserLabelLogRedis LPush Err:" + err.Error())
  24. }
  25. }
  26. return
  27. }
  28. // 添加用户活动到会标签到Redis
  29. func ActivityUserLabelLogAdd(activityId int, mobileArr []string) (err error) {
  30. defer func() {
  31. if err != nil {
  32. fmt.Println(err)
  33. msg := fmt.Sprint("activityId:", activityId, "mobile:", mobileArr)
  34. go utils.SendAlarmMsg("添加用户活动到会标签到Redis,写入Redis队列消息失败:"+err.Error()+msg, 2)
  35. }
  36. }()
  37. var condition string
  38. var pars []interface{}
  39. condition = ` AND activity_id = ? `
  40. pars = append(pars, activityId)
  41. total, e := models.GetCygxIndustrialActivityGroupManagementCount(condition+" AND source = 1 ", pars)
  42. if e != nil {
  43. err = errors.New("GetCygxIndustrialActivityGroupManagementCount" + e.Error())
  44. return
  45. }
  46. if total == 0 {
  47. //没有关联产业的活动不做标签处理
  48. return
  49. }
  50. industrialList, e := models.GetCygxIndustrialActivityGroupManagementList(condition+" AND source = 1 ", pars)
  51. if e != nil {
  52. err = errors.New("GetCygxIndustrialActivityGroupManagementList, Err: " + e.Error())
  53. return
  54. }
  55. //如果有行产业归类就按照产业报告处理
  56. var topCond string
  57. var topPars []interface{}
  58. var industrialManagementIds []int
  59. for _, v := range industrialList {
  60. industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
  61. }
  62. idsLen := len(industrialManagementIds)
  63. if idsLen > 0 {
  64. topCond = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(idsLen) + `)`
  65. topPars = append(topPars, industrialManagementIds)
  66. } else {
  67. return
  68. }
  69. industrNamelist, e := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
  70. if e != nil {
  71. err = errors.New("GetTopOneMonthArtReadNumIndustryAll, Err: " + e.Error())
  72. return
  73. }
  74. userList, e := models.GetWxUserByOutboundMobiles(mobileArr)
  75. if e != nil {
  76. err = errors.New("GetWxUserByOutboundMobiles" + e.Error())
  77. return
  78. }
  79. listActivityHistory, e := models.GetCygxUserLabelActivity(condition, pars)
  80. if e != nil {
  81. err = errors.New("GetCygxUserLabelActivity" + e.Error())
  82. return
  83. }
  84. activityHistoryMap := make(map[int]bool)
  85. for _, v := range listActivityHistory {
  86. activityHistoryMap[v.UserId] = true
  87. }
  88. var items []*models.CygxUserLabelActivity
  89. for _, user := range userList {
  90. //已经提交到会的活动写入标签的不做二次添加处理
  91. if activityHistoryMap[user.UserId] {
  92. continue
  93. }
  94. // SourceType 1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。
  95. log := &models.CygxUserLabelLogRedis{UserId: user.UserId, SourceId: activityId, SourceType: 3, CreateTime: time.Now()}
  96. if utils.Re == nil {
  97. err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
  98. if err != nil {
  99. fmt.Println("CygxUserLabelLogRedis LPush Err:" + err.Error())
  100. }
  101. }
  102. for _, industr := range industrNamelist {
  103. item := new(models.CygxUserLabelActivity)
  104. item.UserId = user.UserId
  105. item.CompanyId = user.CompanyId
  106. item.RealName = user.RealName
  107. item.Mobile = user.Mobile
  108. item.Email = user.Email
  109. item.ActivityId = activityId
  110. item.IndustrialManagementId = industr.IndustrialManagementId
  111. item.Label = industr.IndustryName
  112. item.CreateTime = time.Now()
  113. item.ModifyTime = time.Now()
  114. items = append(items, item)
  115. }
  116. }
  117. if len(items) > 0 {
  118. _, err = models.AddCygxUserLabelActivityList(items)
  119. }
  120. return
  121. }
  122. // 添加用户2产业关注标签到Redis
  123. func IndustryFllowUserLabelLogAdd(industrialManagementId, count, uid int) (err error) {
  124. var isFllow int
  125. if count == 0 {
  126. isFllow = 1
  127. } else {
  128. isFllow = 0
  129. }
  130. defer func() {
  131. if err != nil {
  132. fmt.Println(err)
  133. msg := fmt.Sprint("industrialManagementId:", industrialManagementId, "isFllow:", isFllow, "userId:", uid)
  134. go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
  135. }
  136. }()
  137. log := &models.CygxUserLabelLogRedis{UserId: uid, SourceId: industrialManagementId, SourceType: 2, IsFllow: isFllow, CreateTime: time.Now()}
  138. if utils.Re == nil {
  139. err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
  140. if err != nil {
  141. fmt.Println("RecordNewLogs LPush Err:" + err.Error())
  142. }
  143. }
  144. return
  145. }