123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470 |
- package services
- import (
- "encoding/json"
- "errors"
- "fmt"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/utils"
- "strconv"
- "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
- }
- // 添加用户阅读本周研究汇总,与重点公司标签到Redis
- func ReportSelectionWxUserRaiLabelRedisAdd(sourceId, uid int, createTime time.Time, tableName, 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, TableName: tableName, Label: label, 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("ReportSelectionWxUserRaiLabelRedisAdd LPush Err:" + err.Error())
- }
- }
- return
- }
- // 添加用户参加活动标签到Redis
- func ActivityWxUserRaiLabelRedisAdd(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: 2, 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("ActivityWxUserRaiLabelRedisAdd 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, 4:
- go ActivityWxUserRaiLabelRedisAddReduce(log)
- fmt.Println("2产业关注")
- 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("阅读文章")
- case "cygx_research_summary":
- go ReportSelectionWxUserRaiLabelRedisAddReduce(log)
- fmt.Println("阅读本周研究汇总")
- case "cygx_report_selection":
- go ReportSelectionWxUserRaiLabelRedisAddReduce(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
- }
- // 2:产业/个股标签(线下活动)、 4:产业/个股标签(线上活动)
- // 用户参加活动,相关标签
- func ActivityWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg("用户参加活动,相关标签,处理Redis队列消息失败:ActivityWxUserRaiLabelRedisAddReduce"+err.Error()+fmt.Sprint("SourceId", 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
- }
- activityDetail, e := models.GetAddActivityDetailByActivityId(sourceId)
- if e != nil {
- err = errors.New("GetArticleDetailTestById" + e.Error())
- return
- }
- var sourceType int
- if activityDetail.ActivityType == 1 {
- sourceType = 4
- } else {
- sourceType = 2
- }
- //正常的有产业报告
- var labelArr []string
- //建立首页资源表,与产业的关系
- industrialList, e := models.GetIndustrialActivityGroupManagementListByArticleId(sourceId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetIndustrialArticleGroupManagementListByArticleId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
- return
- }
- var items []*models.WxUserRaiLabel
- for _, v := range industrialList {
- 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 = v.IndustryName
- item.SourceType = sourceType
- item.SourceId = sourceId
- item.CreateTime = log.CreateTime
- item.ModifyTime = time.Now()
- item.RegisterPlatform = log.RegisterPlatform
- item.TableName = ""
- items = append(items, item)
- labelArr = append(labelArr, v.IndustryName)
- }
- //建立首页资源表,与标的 的关系
- subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetSubjectArticleGroupManagementListByArtcileId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
- return
- }
- for _, v := range subjectList {
- 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 = v.SubjectName
- item.SourceType = sourceType
- item.SourceId = sourceId
- item.CreateTime = log.CreateTime
- item.ModifyTime = time.Now()
- item.RegisterPlatform = log.RegisterPlatform
- item.TableName = ""
- items = append(items, item)
- labelArr = append(labelArr, v.SubjectName)
- }
- //如果两个标签都没有,就添加临时标签
- if len(labelArr) == 0 {
- 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 = activityDetail.Label
- item.SourceType = sourceType
- item.SourceId = sourceId
- item.CreateTime = log.CreateTime
- item.ModifyTime = time.Now()
- item.RegisterPlatform = log.RegisterPlatform
- item.TableName = ""
- items = append(items, item)
- labelArr = append(labelArr, activityDetail.Label)
- }
- e = models.AddWxUserRaiLabelMulti(items, labelArr, userId)
- if e != nil {
- err = errors.New("AddWxUserRaiLabelMulti" + 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
- matchTypeNameArr := []string{"季度策略", "科技前沿(周报)", "本周荟", "智造精粹"}
- //1;四大行业汇总类报告:季度策略、科技前沿(周报)、本周荟、智造精粹以报告类型做标签
- //2:策略、固收的所有报告,以报告类型做标签
- if articlePermissionName == utils.CE_LUE_NAME || articlePermissionName == utils.GU_SHOU_NAME || utils.InArrayByStr(matchTypeNameArr, matchTypeName) { // 策略、固收的所有报告,以报告类型做标签
- if matchTypeName == "季度策略" {
- matchTypeName = articlePermissionName + matchTypeName //其中季度策略以:xx行业季度策略 呈现
- }
- 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.SourceId = sourceId
- 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
- }
- } else if articlePermissionName == utils.ZHOU_QI_NAME {
- //周期的行业深度、调研纪要、产业跟踪这些系列的报告用领域做标签,其余的周期报告,都用报告类型(也就是ficc定义的类型)做标签
- //其中周期的周度观点,以 周期周度观点 呈现
- matchTypeNameArrZhouqi := []string{"行业深度", "调研纪要", "产业跟踪"}
- if utils.InArrayByStr(matchTypeNameArrZhouqi, matchTypeName) {
- matchTypeName = articleDetail.FieldName
- }
- 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.SourceId = sourceId
- item.CreateTime = log.CreateTime
- item.ModifyTime = time.Now()
- item.RegisterPlatform = log.RegisterPlatform
- item.TableName = "cygx_article"
- e = models.AddWxUserRaiLabel(item)
- if e != nil {
- err = errors.New("AddWxUserRaiLabel" + e.Error())
- return
- }
- } else {
- //正常的有产业报告
- var labelArr []string
- //建立首页资源表,与产业的关系
- industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(sourceId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetIndustrialArticleGroupManagementListByArticleId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
- return
- }
- var items []*models.WxUserRaiLabel
- for _, v := range industrialList {
- 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 = v.IndustryName
- item.SourceType = 7
- item.SourceId = sourceId
- item.CreateTime = log.CreateTime
- item.ModifyTime = time.Now()
- item.RegisterPlatform = log.RegisterPlatform
- item.TableName = "cygx_article"
- items = append(items, item)
- labelArr = append(labelArr, v.IndustryName)
- }
- //建立首页资源表,与标的 的关系
- subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetSubjectArticleGroupManagementListByArtcileId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
- return
- }
- for _, v := range subjectList {
- 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 = v.SubjectName
- item.SourceType = 7
- item.SourceId = sourceId
- item.CreateTime = log.CreateTime
- item.ModifyTime = time.Now()
- item.RegisterPlatform = log.RegisterPlatform
- item.TableName = "cygx_article"
- items = append(items, item)
- labelArr = append(labelArr, v.SubjectName)
- }
- e = models.AddWxUserRaiLabelMulti(items, labelArr, userId)
- if e != nil {
- err = errors.New("AddWxUserRaiLabelMulti" + e.Error())
- return
- }
- }
- return
- }
- // 8:报告类型标签 (本周研究汇总,与重点公司)
- func ReportSelectionWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg("报告类型标签 (本周研究汇总,与重点公司),处理Redis队列消息失败:ReportSelectionWxUserRaiLabelRedisAddReduce"+err.Error()+fmt.Sprint("SourceId", 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
- }
- 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 = log.Label
- item.SourceType = 8
- item.SourceId = sourceId
- item.CreateTime = log.CreateTime
- item.ModifyTime = time.Now()
- item.RegisterPlatform = log.RegisterPlatform
- item.TableName = log.TableName
- err = models.AddWxUserRaiLabel(item)
- if e != nil {
- err = errors.New("AddWxUserRaiLabel" + e.Error())
- return
- }
- return
- }
|