package services import ( "errors" "fmt" "hongze/hongze_mfyx/models" "hongze/hongze_mfyx/utils" "time" ) // 添加用户阅读标签到Redis func ArticleHistoryUserLabelLogAdd(articleId, uid int) (err error) { defer func() { if err != nil { fmt.Println(err) msg := fmt.Sprint("articleId:", articleId, "userId:", uid) go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2) } }() // SourceType 1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。 log := &models.CygxUserLabelLogRedis{UserId: uid, SourceId: articleId, SourceType: 1, 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()) } } return } // 添加用户活动到会标签到Redis func ActivityUserLabelLogAdd(activityId int, mobileArr []string) (err error) { defer func() { if err != nil { fmt.Println(err) msg := fmt.Sprint("activityId:", activityId, "mobile:", mobileArr) go utils.SendAlarmMsg("添加用户活动到会标签到Redis,写入Redis队列消息失败:"+err.Error()+msg, 2) } }() var condition string var pars []interface{} condition = ` AND activity_id = ? ` pars = append(pars, activityId) total, e := models.GetCygxIndustrialActivityGroupManagementCount(condition+" AND source = 1 ", pars) if e != nil { err = errors.New("GetCygxIndustrialActivityGroupManagementCount" + e.Error()) return } if total == 0 { //没有关联产业的活动不做标签处理 return } industrialList, e := models.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 := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars) if e != nil { err = errors.New("GetTopOneMonthArtReadNumIndustryAll, Err: " + e.Error()) return } userList, e := models.GetWxUserByOutboundMobiles(mobileArr) if e != nil { err = errors.New("GetWxUserByOutboundMobiles" + e.Error()) return } listActivityHistory, e := models.GetCygxUserLabelActivity(condition, pars) 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 []*models.CygxUserLabelActivity for _, user := range userList { //已经提交到会的活动写入标签的不做二次添加处理 if activityHistoryMap[user.UserId] { continue } // SourceType 1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。 log := &models.CygxUserLabelLogRedis{UserId: 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(models.CygxUserLabelActivity) item.UserId = 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 = models.AddCygxUserLabelActivityList(items) } return } // 添加用户2产业关注标签到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 utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2) } }() log := &models.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 }