user_rai_label.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package cygx
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hz_crm_api/models/cygx"
  6. "hongze/hz_crm_api/services/alarm_msg"
  7. "hongze/hz_crm_api/utils"
  8. "time"
  9. )
  10. // GetUserLabelByUserIdArr 根据多个userId 获取每个UserId最新的十条数据
  11. func GetUserLabelByUserIdArr(userIdArr []int) (mapRsp map[int][]*cygx.WxUserRaiLabelListResp) {
  12. if len(userIdArr) == 0 {
  13. return
  14. }
  15. var err error
  16. defer func() {
  17. if err != nil {
  18. fmt.Println(err)
  19. go alarm_msg.SendAlarmMsg(fmt.Sprint("根据多个userId 获取每个UserId最新的十条数据失败:"+err.Error(), "userIdArr", userIdArr), 2)
  20. }
  21. }()
  22. labelList, e := cygx.GetWxUserRaiLabelListByUserIds(userIdArr)
  23. if e != nil {
  24. err = errors.New("GetWxUserRaiLabelListByUserIds, Err: " + e.Error())
  25. return
  26. }
  27. mapRsp = make(map[int][]*cygx.WxUserRaiLabelListResp)
  28. for _, v := range labelList {
  29. mapRsp[v.UserId] = append(mapRsp[v.UserId], v)
  30. }
  31. return
  32. }
  33. // 添加用户参加活动标签到Redis
  34. func ActivityWxUserRaiLabelRedisAdd(sourceId, uid int, createTime time.Time) (err error) {
  35. defer func() {
  36. if err != nil {
  37. fmt.Println(err)
  38. msg := fmt.Sprint("sourceId:", sourceId, "userId:", uid)
  39. go alarm_msg.SendAlarmMsg("添加用户参加活动标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
  40. }
  41. }()
  42. log := &cygx.WxUserRaiLabelRedis{UserId: uid, SourceId: sourceId, SourceType: 2, CreateTime: createTime}
  43. if utils.Re == nil {
  44. err := utils.Rc.LPush(utils.WX_USER_RAI_LABEL_KEY, log)
  45. if err != nil {
  46. fmt.Println("ActivityWxUserRaiLabelRedisAdd LPush Err:" + err.Error())
  47. }
  48. }
  49. return
  50. }
  51. // 添加用户参加路演标签到Redis
  52. func RoadShowWxUserRaiLabelRedisAdd(sourceId, uid int, createTime time.Time) (err error) {
  53. defer func() {
  54. if err != nil {
  55. fmt.Println(err)
  56. msg := fmt.Sprint("sourceId:", sourceId, "userId:", uid)
  57. go alarm_msg.SendAlarmMsg("添加用户参加路演标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
  58. }
  59. }()
  60. log := &cygx.WxUserRaiLabelRedis{UserId: uid, SourceId: sourceId, SourceType: 3, CreateTime: createTime}
  61. if utils.Re == nil {
  62. err := utils.Rc.LPush(utils.WX_USER_RAI_LABEL_KEY, log)
  63. if err != nil {
  64. fmt.Println("RoadShowWxUserRaiLabelRedisAdd LPush Err:" + err.Error())
  65. }
  66. }
  67. return
  68. }