|
@@ -0,0 +1,109 @@
|
|
|
+package services
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "hongze/hongze_cygxzs/models"
|
|
|
+ "hongze/hongze_cygxzs/utils"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+func UserSubmit(itemsFllow []*models.CygxIndustryFllow, itemsCategory []*models.CygxXzsChooseCategory, userId int) (err error) {
|
|
|
+ e := models.UpdateCygxUserLabelNofollow(userId)
|
|
|
+ if e != nil {
|
|
|
+ go utils.SendAlarmMsg("用户关注产业更新相关标签,UpdateCygxUserLabelNofollow,Err :"+e.Error(), 2)
|
|
|
+ }
|
|
|
+ if len(itemsFllow) > 0 {
|
|
|
+ mapIndustryId := make(map[int]bool)
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition = ` AND is_follow=1 AND source = 1 AND user_id = ? `
|
|
|
+ pars = append(pars, userId)
|
|
|
+ list, e := models.GetCygxUserLabelList(condition, pars)
|
|
|
+ if e != nil {
|
|
|
+ go utils.SendAlarmMsg("用户关注产业更新相关标签,查询相关信息失败:"+e.Error(), 2)
|
|
|
+ }
|
|
|
+ for _, v := range list {
|
|
|
+ mapIndustryId[v.SourceId] = true
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range itemsFllow {
|
|
|
+ if !mapIndustryId[v.IndustrialManagementId] {
|
|
|
+ IndustryFllowUserLabelLogAdd(v.IndustrialManagementId, 0, userId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(itemsCategory) > 0 {
|
|
|
+ mapIndustryId := make(map[int]bool)
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition = ` AND is_follow=1 AND source = 2 AND user_id = ? `
|
|
|
+ pars = append(pars, userId)
|
|
|
+ list, e := models.GetCygxUserLabelList(condition, pars)
|
|
|
+ if e != nil {
|
|
|
+ go utils.SendAlarmMsg("用户关注系列更新相关标签,查询相关信息失败:"+e.Error(), 2)
|
|
|
+ }
|
|
|
+ for _, v := range list {
|
|
|
+ mapIndustryId[v.SourceId] = true
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range itemsCategory {
|
|
|
+ if !mapIndustryId[v.IdCygx] {
|
|
|
+ CategoryFllowUserLabelLogAdd(v.IdCygx, 0, userId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+//SourceType int `description:"1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。"`
|
|
|
+
|
|
|
+// 添加用户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
|
|
|
+}
|
|
|
+
|
|
|
+// 添加用户4系列关注标签到Redis
|
|
|
+func CategoryFllowUserLabelLogAdd(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: 4, 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
|
|
|
+}
|