123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- package services
- import (
- "encoding/json"
- "errors"
- "fmt"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/utils"
- "time"
- )
- // 添加用户搜索标签到Redis
- func KeyWordsWxUserRaiLabelRedisAdd(sourceId, uid int, label string) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- msg := fmt.Sprint("sourceId:", sourceId, "userId:", uid)
- go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
- }
- }()
- log := &models.WxUserRaiLabelRedis{UserId: uid, SourceId: sourceId, SourceType: 1, Label: label, CreateTime: time.Now(), RegisterPlatform: utils.REGISTER_PLATFORM}
- if utils.Re == nil {
- err := utils.Rc.LPush(utils.WX_USER_RAI_LABEL_KEY, log)
- if err != nil {
- fmt.Println("WxUserRaiLabelRedis LPush Err:" + err.Error())
- }
- }
- return
- }
- // 添加用户阅读文章标签到Redis
- func ArticleWxUserRaiLabelRedisAdd(sourceId, uid int, createTime time.Time) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- msg := fmt.Sprint("sourceId:", sourceId, "userId:", uid)
- go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
- }
- }()
- log := &models.WxUserRaiLabelRedis{UserId: uid, SourceId: sourceId, SourceType: 1, TableName: utils.CYGX_OBJ_ARTICLE, CreateTime: createTime, RegisterPlatform: utils.REGISTER_PLATFORM}
- if utils.Re == nil {
- err := utils.Rc.LPush(utils.WX_USER_RAI_LABEL_KEY, log)
- if err != nil {
- fmt.Println("WxUserRaiLabelRedis LPush Err:" + err.Error())
- }
- }
- return
- }
- func UpdateWxUserRaiLabelRedis() (err error) {
- for {
- // SourceType int `description:"来源1:搜索关键字标签、2:产业/个股标签(线下活动)、3:产业/个股标签(线下路演)、4:产业/个股标签(线上活动)、5:产业/个股标签(线上路演)、6:销售输入标签、7:产业/个股标签(报告)、8:报告类型标签"`
- utils.Rc.Brpop(utils.WX_USER_RAI_LABEL_KEY, func(b []byte) {
- var log models.WxUserRaiLabelRedis
- if err := json.Unmarshal(b, &log); err != nil {
- fmt.Println("json unmarshal wrong!")
- go utils.SendAlarmMsg("用户更新相关标签处理Redis队列消息失败:"+err.Error()+string(b), 2)
- }
- if log.TableName == "" {
- switch log.SourceType {
- case 1:
- go KeyWordsWxUserRaiLabelRedisAddReduce(log)
- fmt.Println("搜索关键词")
- break
- //case 2:
- // go IndustryFllowUserLabelLogReduce(log)
- // fmt.Println("2产业关注")
- // break
- //case 3:
- // go ActivityUserLabelLogReduce(log)
- // fmt.Println("活动到会")
- // break
- //case 4:
- // go CategoryFllowUserLabelLogReduce(log)
- // fmt.Println("4系列关注")
- // break
- //case 5:
- // go ActivitySpecialUserLabelLogReduce(log)
- // fmt.Println("5专项调研活动到会")
- // break
- default:
- fmt.Println(string(b))
- go utils.SendAlarmMsg("用户更新相关标签处理Redis队列消息失败:"+string(b), 2)
- }
- } else {
- switch log.TableName {
- case utils.CYGX_OBJ_ARTICLE:
- go ArticleWxUserRaiLabelRedisAddReduce(log)
- fmt.Println("阅读文章")
- }
- }
- })
- }
- }
- // 1:搜索关键词
- func KeyWordsWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg("用户文章阅读更新相关标签,处理Redis队列消息失败:"+err.Error()+fmt.Sprint("articleId", log.SourceId, "userId", log.UserId), 2)
- }
- }()
- userId := log.UserId
- label := log.Label
- if userId == 0 {
- return
- }
- wxUser, e := models.GetWxUserItemByUserId(userId)
- if e != nil {
- err = errors.New("GetWxUserItemByUserId" + e.Error())
- return
- }
- item := new(models.WxUserRaiLabel)
- item.UserId = wxUser.UserId
- item.RealName = wxUser.RealName
- item.Mobile = wxUser.Mobile
- item.Email = wxUser.Email
- item.CompanyId = wxUser.CompanyId
- item.CompanyName = wxUser.CompanyName
- item.Label = label
- item.SourceType = log.SourceType
- item.CreateTime = log.CreateTime
- item.ModifyTime = time.Now()
- item.RegisterPlatform = log.RegisterPlatform
- err = models.AddWxUserRaiLabel(item)
- if e != nil {
- err = errors.New("AddWxUserRaiLabel" + e.Error())
- return
- }
- return
- }
- // 7:产业/个股标签(报告)、8:报告类型标签
- func ArticleWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg("用户文章阅读更新相关标签,处理Redis队列消息失败:"+err.Error()+fmt.Sprint("articleId", log.SourceId, "userId", log.UserId), 2)
- }
- }()
- userId := log.UserId
- sourceId := log.SourceId
- wxUser, e := models.GetWxUserItemByUserId(userId)
- if e != nil {
- err = errors.New("GetWxUserItemByUserId" + e.Error())
- return
- }
- articleDetail, e := models.GetArticleDetailTestById(sourceId)
- if e != nil {
- err = errors.New("GetArticleDetailTestById" + e.Error())
- return
- }
- articlePermission, e := models.GetArticlePermission(articleDetail.CategoryId)
- if e != nil {
- err = errors.New("GetArticlePermission" + e.Error())
- return
- }
- if articlePermission == nil {
- err = errors.New("报告权限不存在" + e.Error())
- return
- }
- articlePermissionName := articlePermission.PermissionName
- matchTypeName := articlePermission.MatchTypeName
- if articlePermissionName == utils.CE_LUE_NAME || articlePermissionName == utils.GU_SHOU_NAME { // 策略、固收的所有报告,以报告类型做标签
- item := new(models.WxUserRaiLabel)
- item.UserId = wxUser.UserId
- item.RealName = wxUser.RealName
- item.Mobile = wxUser.Mobile
- item.Email = wxUser.Email
- item.CompanyId = wxUser.CompanyId
- item.CompanyName = wxUser.CompanyName
- item.Label = matchTypeName
- item.SourceType = 8
- item.CreateTime = log.CreateTime
- item.ModifyTime = time.Now()
- item.RegisterPlatform = log.RegisterPlatform
- item.TableName = "cygx_article"
- err = models.AddWxUserRaiLabel(item)
- if e != nil {
- err = errors.New("AddWxUserRaiLabel" + e.Error())
- return
- }
- }
- return
- }
|