123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- package cygx
- import (
- "errors"
- "fmt"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/cygx"
- "hongze/hz_crm_api/services/alarm_msg"
- "hongze/hz_crm_api/utils"
- "strconv"
- "strings"
- "time"
- )
- // 添加用户活动到会标签到Redis
- func ActivityUserLabelLogAdd(activityId int, userIdArr []int) (err error) {
- if len(userIdArr) == 0 {
- return
- }
- defer func() {
- if err != nil {
- fmt.Println(err)
- msg := fmt.Sprint("activityId:", activityId, "mobile:", userIdArr)
- go alarm_msg.SendAlarmMsg("添加用户活动到会标签到Redis,写入Redis队列消息失败:"+err.Error()+msg, 2)
- }
- }()
- var condition string
- var pars []interface{}
- condition = ` AND activity_id = ? `
- pars = append(pars, activityId)
- total, e := cygx.GetCygxIndustrialActivityGroupManagementCount(condition+" AND source = 1 ", pars)
- if e != nil {
- err = errors.New("GetCygxIndustrialActivityGroupManagementCount" + e.Error())
- return
- }
- if total == 0 {
- //没有关联产业的活动不做标签处理
- return
- }
- industrialList, e := cygx.GetCygxIndustrialActivityGroupManagementList(condition+" AND source = 1 ", pars)
- if e != nil {
- err = errors.New("GetCygxIndustrialActivityGroupManagementList, Err: " + e.Error())
- return
- }
- //如果有行产业归类就按照产业报告处理
- var topCond string
- var topPars []interface{}
- var industrialManagementIds []int
- for _, v := range industrialList {
- industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
- }
- idsLen := len(industrialManagementIds)
- if idsLen > 0 {
- topCond = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(idsLen) + `)`
- topPars = append(topPars, industrialManagementIds)
- } else {
- return
- }
- industrNamelist, e := cygx.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
- if e != nil {
- err = errors.New("GetTopOneMonthArtReadNumIndustryAll, Err: " + e.Error())
- return
- }
- userList, e := models.GetWxUserByUserIds(userIdArr)
- if e != nil {
- err = errors.New("GetWxUserByOutboundMobiles" + e.Error())
- return
- }
- listActivityHistory, e := cygx.GetCygxUserLabelActivity(condition, pars, 0, 9999)
- if e != nil {
- err = errors.New("GetCygxUserLabelActivity" + e.Error())
- return
- }
- activityHistoryMap := make(map[int]bool)
- for _, v := range listActivityHistory {
- activityHistoryMap[v.UserId] = true
- }
- var items []*cygx.CygxUserLabelActivity
- for _, user := range userList {
- //已经提交到会的活动写入标签的不做二次添加处理
- if activityHistoryMap[int(user.UserId)] {
- continue
- }
- // SourceType 1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。
- log := &cygx.CygxUserLabelLogRedis{UserId: int(user.UserId), SourceId: activityId, SourceType: 3, CreateTime: time.Now()}
- if utils.Re == nil {
- err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
- if err != nil {
- fmt.Println("CygxUserLabelLogRedis LPush Err:" + err.Error())
- }
- }
- for _, industr := range industrNamelist {
- item := new(cygx.CygxUserLabelActivity)
- item.UserId = int(user.UserId)
- item.CompanyId = user.CompanyId
- item.RealName = user.RealName
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.ActivityId = activityId
- item.IndustrialManagementId = industr.IndustrialManagementId
- item.Label = industr.IndustryName
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- items = append(items, item)
- }
- }
- if len(items) > 0 {
- _, err = cygx.AddCygxUserLabelActivityList(items)
- }
- return
- }
- // 添加用户活动到会标签到Redis
- func ActivitySpecialUserLabelLogAdd(activityId int, userIdArr []int) (err error) {
- if len(userIdArr) == 0 {
- return
- }
- defer func() {
- if err != nil {
- fmt.Println(err)
- msg := fmt.Sprint("activityId:", activityId, "mobile:", userIdArr)
- go alarm_msg.SendAlarmMsg("添加用户专项调研活动到会标签到Redis,写入Redis队列消息失败:"+err.Error()+msg, 2)
- }
- }()
- var condition string
- var pars []interface{}
- condition = ` AND activity_id = ? `
- pars = append(pars, activityId)
- total, e := cygx.GetCygxIndustrialActivityGroupManagementCount(condition+" AND source = 2 ", pars)
- if e != nil {
- err = errors.New("GetCygxIndustrialActivityGroupManagementCount" + e.Error())
- return
- }
- if total == 0 {
- //没有关联产业的活动不做标签处理
- return
- }
- industrialList, e := cygx.GetCygxIndustrialActivityGroupManagementList(condition+" AND source = 2 ", pars)
- if e != nil {
- err = errors.New("GetCygxIndustrialActivityGroupManagementList, Err: " + e.Error())
- return
- }
- //如果有行产业归类就按照产业报告处理
- var topCond string
- var topPars []interface{}
- var industrialManagementIds []int
- for _, v := range industrialList {
- industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
- }
- idsLen := len(industrialManagementIds)
- if idsLen > 0 {
- topCond = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(idsLen) + `)`
- topPars = append(topPars, industrialManagementIds)
- } else {
- return
- }
- industrNamelist, e := cygx.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
- if e != nil {
- err = errors.New("GetTopOneMonthArtReadNumIndustryAll, Err: " + e.Error())
- return
- }
- userList, e := models.GetWxUserByUserIds(userIdArr)
- if e != nil {
- err = errors.New("GetWxUserByOutboundMobiles" + e.Error())
- return
- }
- listActivityHistory, e := cygx.GetCygxUserLabelActivitySpecial(condition, pars, 0, 9999)
- if e != nil {
- err = errors.New("GetCygxUserLabelActivity" + e.Error())
- return
- }
- activityHistoryMap := make(map[int]bool)
- for _, v := range listActivityHistory {
- activityHistoryMap[v.UserId] = true
- }
- var items []*cygx.CygxUserLabelActivitySpecial
- for _, user := range userList {
- //已经提交到会的活动写入标签的不做二次添加处理
- if activityHistoryMap[int(user.UserId)] {
- continue
- }
- // SourceType 1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。
- log := &cygx.CygxUserLabelLogRedis{UserId: int(user.UserId), SourceId: activityId, SourceType: 5, CreateTime: time.Now()}
- if utils.Re == nil {
- err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
- if err != nil {
- fmt.Println("CygxUserLabelLogRedis LPush Err:" + err.Error())
- }
- }
- for _, industr := range industrNamelist {
- item := new(cygx.CygxUserLabelActivitySpecial)
- item.UserId = int(user.UserId)
- item.CompanyId = user.CompanyId
- item.RealName = user.RealName
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.ActivityId = activityId
- item.IndustrialManagementId = industr.IndustrialManagementId
- item.Label = industr.IndustryName
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- items = append(items, item)
- }
- }
- if len(items) > 0 {
- _, err = cygx.AddCygxUserLabelActivitySpecialList(items)
- }
- return
- }
- // 用户关注产业更新相关标签到Redis
- func IndustryFllowUserLabelLogAdd(industrialManagementId, count, uid int) (err error) {
- var isFllow int
- if count == 0 {
- isFllow = 1
- } else {
- isFllow = 0
- }
- defer func() {
- if err != nil {
- fmt.Println(err)
- msg := fmt.Sprint("industrialManagementId:", industrialManagementId, "isFllow:", isFllow, "userId:", uid)
- go alarm_msg.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
- }
- }()
- log := &cygx.CygxUserLabelLogRedis{UserId: uid, SourceId: industrialManagementId, SourceType: 2, IsFllow: isFllow, CreateTime: time.Now()}
- if utils.Re == nil {
- err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
- if err != nil {
- fmt.Println("RecordNewLogs LPush Err:" + err.Error())
- }
- }
- return
- }
- // GetUserInteractionNumMap 根据用户ID 获取对应的用户互动量
- func GetUserInteractionNumMap(userIds []int) (mapResp map[int]int) {
- lenArr := len(userIds)
- if lenArr == 0 {
- return
- }
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go alarm_msg.SendAlarmMsg(fmt.Sprint("GetUserInteractionNumMap 根据用户ID 获取对应的用户互动量 失败 userIds", userIds, err.Error()), 2)
- }
- }()
- var userIdsArr []string
- for _, v := range userIds {
- userIdsArr = append(userIdsArr, strconv.Itoa(v))
- }
- userIdstr := strings.Join(userIdsArr, ",")
- list, e := cygx.GetCygxCompanyUserListSplit(userIdstr)
- if e != nil {
- err = errors.New("GetCygxCompanyUserListSplit, Err: " + e.Error())
- return
- }
- mapResp = make(map[int]int, 0)
- for k, v := range list {
- mapResp[int(v.UserId)] = list[k].HistoryNum + list[k].CountNum + list[k].IndustryFllowNum + list[k].DepartmentFollowNum + list[k].KeyWordNum + list[k].OnLineNum + list[k].OfficeNum + list[k].ChartNum + list[k].TripNum + list[k].RoadshowVideoNum + list[k].ActivityVideoNum + list[k].ActivityVoiceNum + list[k].YanxuanspecialNum
- }
- return
- }
|