|
@@ -6,9 +6,109 @@ import (
|
|
|
"fmt"
|
|
|
"hongze/hongze_cygx/models"
|
|
|
"hongze/hongze_cygx/utils"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
+func init() {
|
|
|
+
|
|
|
+ //ArticleHistoryUserLabelLogAdd(8350, 53095)
|
|
|
+ //UserLabelLogReduce()
|
|
|
+ //var mobileArr []string
|
|
|
+ //mobileArr = append(mobileArr, "15557270714")
|
|
|
+ //ActivityUserLabelLogAdd(2239, mobileArr)
|
|
|
+
|
|
|
+ //UserLabelLogReduce()
|
|
|
+}
|
|
|
+
|
|
|
+// 添加用户阅读标签到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队列消息失败:"+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
|
|
|
+ }
|
|
|
+ userList, e := models.GetWxUserByOutboundMobiles(mobileArr)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetWxUserByOutboundMobiles" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ listActivityHistory, e := models.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 []*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())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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.CreateTime = time.Now()
|
|
|
+ item.ModifyTime = time.Now()
|
|
|
+ items = append(items, item)
|
|
|
+ }
|
|
|
+ if len(items) > 0 {
|
|
|
+ _, err = models.AddCygxUserLabelActivityList(items)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
func UserLabelLogReduce() (err error) {
|
|
|
for {
|
|
|
//SourceType int `description:"1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。"`
|
|
@@ -20,6 +120,7 @@ func UserLabelLogReduce() (err error) {
|
|
|
}
|
|
|
switch log.SourceType {
|
|
|
case 1:
|
|
|
+ go ArticleHistoryUserLabelLogReduce(log)
|
|
|
fmt.Println("文章阅读")
|
|
|
break
|
|
|
case 2:
|
|
@@ -27,12 +128,15 @@ func UserLabelLogReduce() (err error) {
|
|
|
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:
|
|
@@ -43,7 +147,151 @@ func UserLabelLogReduce() (err error) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 2产业关注
|
|
|
+// 1:文章阅读
|
|
|
+func ArticleHistoryUserLabelLogReduce(log models.CygxUserLabelLogRedis) (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ go utils.SendAlarmMsg("用户文章阅读更新相关标签,处理Redis队列消息失败:"+err.Error(), 2)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ articleId := log.SourceId
|
|
|
+ userId := log.UserId
|
|
|
+ var source int
|
|
|
+ user, e := models.GetWxUserItemByUserId(userId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetWxUserItemByUserId" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition = ` AND article_id = ? `
|
|
|
+ pars = append(pars, articleId)
|
|
|
+ industrialList, e := models.GetIndustrialArticleGroupManagementList(condition, pars)
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ err = errors.New("GetIndustrialArticleGroupManagementList, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(industrialList) == 0 {
|
|
|
+ //如果没有行产业归类就按照行业报告处理
|
|
|
+ source = 2
|
|
|
+ detailArticle, e := models.GetArticleDetailById(articleId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetIndustrialArticleGroupManagementList, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ labelDetail, e := models.GetdetailByCategoryIdLabel(detailArticle.CategoryId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetIndustrialArticleGroupManagementList, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ label := labelDetail.MatchTypeName
|
|
|
+ industrialManagementId := labelDetail.Id
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition += ` AND source_id=? AND source = ? AND user_id = ? `
|
|
|
+ pars = append(pars, industrialManagementId, source, userId)
|
|
|
+ total, e := models.GetCygxUserLabelCount(condition, pars)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxProductInteriorCount" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if total == 0 {
|
|
|
+ item := new(models.CygxUserLabel)
|
|
|
+ item.UserId = user.UserId
|
|
|
+ item.CompanyId = user.CompanyId
|
|
|
+ item.RealName = user.RealName
|
|
|
+ item.Mobile = user.Mobile
|
|
|
+ item.Email = user.Email
|
|
|
+ item.Label = label
|
|
|
+ item.SourceId = industrialManagementId
|
|
|
+ item.Source = source
|
|
|
+ item.Weight = 1
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ item.ModifyTime = time.Now()
|
|
|
+ _, e = models.AddCygxUserLabel(item)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("AddCygxUserLabel" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //source 来源1:产业、2:系列
|
|
|
+ e = models.UpdateCygxUserLabelWeight(industrialManagementId, source, userId, label)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("UpdateCygxUserLabelWeight" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ //如果有行产业归类就按照产业报告处理
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ source = 1
|
|
|
+ for _, v := range industrNamelist {
|
|
|
+ label := v.IndustryName
|
|
|
+ industrialManagementId := v.IndustrialManagementId
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition += ` AND source_id=? AND source = ? AND user_id = ? `
|
|
|
+ pars = append(pars, v.IndustrialManagementId, source, userId)
|
|
|
+ total, e := models.GetCygxUserLabelCount(condition, pars)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxProductInteriorCount" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if total == 0 {
|
|
|
+ item := new(models.CygxUserLabel)
|
|
|
+ item.UserId = user.UserId
|
|
|
+ item.CompanyId = user.CompanyId
|
|
|
+ item.RealName = user.RealName
|
|
|
+ item.Mobile = user.Mobile
|
|
|
+ item.Email = user.Email
|
|
|
+ item.Label = label
|
|
|
+ item.SourceId = industrialManagementId
|
|
|
+ item.Source = source
|
|
|
+ item.Weight = 1
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ item.ModifyTime = time.Now()
|
|
|
+ _, e = models.AddCygxUserLabel(item)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("AddCygxUserLabel" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //source 来源1:产业、2:系列
|
|
|
+ e = models.UpdateCygxUserLabelWeight(industrialManagementId, source, userId, label)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("UpdateCygxUserLabelWeight" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 2:产业关注
|
|
|
func IndustryFllowUserLabelLogReduce(log models.CygxUserLabelLogRedis) (err error) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -62,7 +310,7 @@ func IndustryFllowUserLabelLogReduce(log models.CygxUserLabelLogRedis) (err erro
|
|
|
}
|
|
|
label := detailIndustrial.IndustryName
|
|
|
if isFllow == 0 {
|
|
|
- e = models.UpdateCygxUserLabelIsFollow(isFllow, industrialManagementId, source, label)
|
|
|
+ e = models.UpdateCygxUserLabelIsFollow(isFllow, industrialManagementId, source, userId, label)
|
|
|
if e != nil {
|
|
|
err = errors.New("UpdateCygxUserLabelIsFollow" + e.Error())
|
|
|
return
|
|
@@ -70,8 +318,8 @@ func IndustryFllowUserLabelLogReduce(log models.CygxUserLabelLogRedis) (err erro
|
|
|
} else {
|
|
|
var condition string
|
|
|
var pars []interface{}
|
|
|
- condition += ` AND source_id=? AND source = ? `
|
|
|
- pars = append(pars, industrialManagementId, source)
|
|
|
+ condition += ` AND source_id=? AND source = ? AND user_id = ?`
|
|
|
+ pars = append(pars, industrialManagementId, source, userId)
|
|
|
total, e := models.GetCygxUserLabelCount(condition, pars)
|
|
|
if e != nil {
|
|
|
err = errors.New("GetCygxProductInteriorCount" + e.Error())
|
|
@@ -102,7 +350,7 @@ func IndustryFllowUserLabelLogReduce(log models.CygxUserLabelLogRedis) (err erro
|
|
|
}
|
|
|
} else {
|
|
|
//source 来源1:产业、2:系列
|
|
|
- e = models.UpdateCygxUserLabelIsFollow(isFllow, industrialManagementId, source, label)
|
|
|
+ e = models.UpdateCygxUserLabelIsFollow(isFllow, industrialManagementId, source, userId, label)
|
|
|
if e != nil {
|
|
|
err = errors.New("UpdateCygxUserLabelIsFollow" + e.Error())
|
|
|
return
|
|
@@ -111,3 +359,376 @@ func IndustryFllowUserLabelLogReduce(log models.CygxUserLabelLogRedis) (err erro
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// 3:活动到会
|
|
|
+func ActivityUserLabelLogReduce(log models.CygxUserLabelLogRedis) (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ go utils.SendAlarmMsg("用户活动到会更新相关标签,处理Redis队列消息失败:"+err.Error(), 2)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ activityId := log.SourceId
|
|
|
+ userId := log.UserId
|
|
|
+ var source int
|
|
|
+ user, e := models.GetWxUserItemByUserId(userId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetWxUserItemByUserId" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition = ` AND activity_id = ? `
|
|
|
+ pars = append(pars, activityId)
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ source = 1
|
|
|
+ for _, v := range industrNamelist {
|
|
|
+ label := v.IndustryName
|
|
|
+ industrialManagementId := v.IndustrialManagementId
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition += ` AND source_id=? AND source = ? AND user_id = ? `
|
|
|
+ pars = append(pars, v.IndustrialManagementId, source, userId)
|
|
|
+ total, e := models.GetCygxUserLabelCount(condition, pars)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxProductInteriorCount" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if total == 0 {
|
|
|
+ item := new(models.CygxUserLabel)
|
|
|
+ item.UserId = user.UserId
|
|
|
+ item.CompanyId = user.CompanyId
|
|
|
+ item.RealName = user.RealName
|
|
|
+ item.Mobile = user.Mobile
|
|
|
+ item.Email = user.Email
|
|
|
+ item.Label = label
|
|
|
+ item.SourceId = industrialManagementId
|
|
|
+ item.Source = source
|
|
|
+ item.Weight = 1
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ item.ModifyTime = time.Now()
|
|
|
+ _, e = models.AddCygxUserLabel(item)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("AddCygxUserLabel" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //source 来源1:产业、2:系列
|
|
|
+ e = models.UpdateCygxUserLabelWeight(industrialManagementId, source, userId, label)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("UpdateCygxUserLabelWeight" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 4:系列关注
|
|
|
+func CategoryFllowUserLabelLogReduce(log models.CygxUserLabelLogRedis) (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ go utils.SendAlarmMsg("用户关注系列更新相关标签,处理Redis队列消息失败:"+err.Error(), 2)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ isFllow := log.IsFllow
|
|
|
+ industrialManagementId := log.SourceId
|
|
|
+ userId := log.UserId
|
|
|
+ source := 2
|
|
|
+ detailIndustrial, e := models.GetCygxReportMappingById(industrialManagementId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxReportMappingById" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ label := detailIndustrial.MatchTypeName
|
|
|
+ if isFllow == 0 {
|
|
|
+ e = models.UpdateCygxUserLabelIsFollow(isFllow, industrialManagementId, source, userId, label)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("UpdateCygxUserLabelIsFollow" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition += ` AND source_id=? AND source = ? AND user_id = ?`
|
|
|
+ pars = append(pars, industrialManagementId, source, userId)
|
|
|
+ total, e := models.GetCygxUserLabelCount(condition, pars)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxProductInteriorCount" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if total == 0 {
|
|
|
+ user, e := models.GetWxUserItemByUserId(userId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetWxUserItemByUserId" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item := new(models.CygxUserLabel)
|
|
|
+ item.UserId = user.UserId
|
|
|
+ item.CompanyId = user.CompanyId
|
|
|
+ item.RealName = user.RealName
|
|
|
+ item.Mobile = user.Mobile
|
|
|
+ item.Email = user.Email
|
|
|
+ item.Label = label
|
|
|
+ item.SourceId = industrialManagementId
|
|
|
+ item.Source = source
|
|
|
+ item.IsFollow = isFllow
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ item.ModifyTime = time.Now()
|
|
|
+ _, e = models.AddCygxUserLabel(item)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("AddCygxUserLabel" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //source 来源1:产业、2:系列
|
|
|
+ e = models.UpdateCygxUserLabelIsFollow(isFllow, industrialManagementId, source, userId, label)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("UpdateCygxUserLabelIsFollow" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 5:专项调研活动到会
|
|
|
+func ActivitySpecialUserLabelLogReduce(log models.CygxUserLabelLogRedis) (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ go utils.SendAlarmMsg("用户活动到会更新相关标签,处理Redis队列消息失败:"+err.Error(), 2)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ activityId := log.SourceId
|
|
|
+ userId := log.UserId
|
|
|
+ var source int
|
|
|
+ user, e := models.GetWxUserItemByUserId(userId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetWxUserItemByUserId" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition = ` AND activity_id = ? `
|
|
|
+ pars = append(pars, activityId)
|
|
|
+ industrialList, e := models.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 := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetTopOneMonthArtReadNumIndustryAll, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ source = 1
|
|
|
+ for _, v := range industrNamelist {
|
|
|
+ label := v.IndustryName
|
|
|
+ industrialManagementId := v.IndustrialManagementId
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition += ` AND source_id=? AND source = ? AND user_id = ? `
|
|
|
+ pars = append(pars, v.IndustrialManagementId, source, userId)
|
|
|
+ total, e := models.GetCygxUserLabelCount(condition, pars)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxProductInteriorCount" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if total == 0 {
|
|
|
+ item := new(models.CygxUserLabel)
|
|
|
+ item.UserId = user.UserId
|
|
|
+ item.CompanyId = user.CompanyId
|
|
|
+ item.RealName = user.RealName
|
|
|
+ item.Mobile = user.Mobile
|
|
|
+ item.Email = user.Email
|
|
|
+ item.Label = label
|
|
|
+ item.SourceId = industrialManagementId
|
|
|
+ item.Source = source
|
|
|
+ item.Weight = 1
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ item.ModifyTime = time.Now()
|
|
|
+ _, e = models.AddCygxUserLabel(item)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("AddCygxUserLabel" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //source 来源1:产业、2:系列
|
|
|
+ e = models.UpdateCygxUserLabelWeight(industrialManagementId, source, userId, label)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("UpdateCygxUserLabelWeight" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// func init() {
|
|
|
+// updateUserLabelByUserId(53095)
|
|
|
+// }
|
|
|
+
|
|
|
+// 更新用户标签
|
|
|
+func updateUserLabelByUserId(userId int) (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ go utils.SendAlarmMsg("更新用户标签失败:"+err.Error()+"userId:"+strconv.Itoa(userId), 2)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition = ` AND is_follow=1 AND user_id = ? `
|
|
|
+ pars = append(pars, userId)
|
|
|
+ totalSource1, e := models.GetCygxUserLabelCount(condition+" AND source = 1 ", pars)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxProductInteriorCount" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ totalSource2, e := models.GetCygxUserLabelCount(condition+" AND source = 2 ", pars)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxProductInteriorCount" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ condition = ` AND user_id = ? `
|
|
|
+ var list []*models.CygxUserLabel
|
|
|
+ //当产业关注数量不超过10 ,系列关注数量不超过5
|
|
|
+ if totalSource1 <= 10 && totalSource2 <= 5 {
|
|
|
+ condition += ` AND ( is_follow > 0 OR weight > 0 ) ORDER BY is_follow DESC, weight DESC `
|
|
|
+ list, e = models.GetCygxUserLabelList(condition, pars)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxUserLabelList" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //当产业关注数量超过10 ,系列关注数量超过5
|
|
|
+ if totalSource1 > 10 && totalSource2 > 1 {
|
|
|
+ condition += ` AND weight > 0 ORDER BY weight DESC `
|
|
|
+ list, e = models.GetCygxUserLabelList(condition, pars)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxUserLabelList" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //当产业关注数量不超过10 ,系列关注数量超过5
|
|
|
+ if totalSource1 <= 10 && totalSource2 > 5 {
|
|
|
+ fmt.Println("当产业关注数量不超过10 ,系列关注数量超过5")
|
|
|
+ condition += ` AND source = 1 AND is_follow = 1 ORDER BY weight DESC `
|
|
|
+ listfollow, e := models.GetCygxUserLabelList(condition, pars)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxUserLabelList" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ idMap := make(map[int]bool)
|
|
|
+ for _, v := range listfollow {
|
|
|
+ idMap[v.Id] = true
|
|
|
+ list = append(list, v)
|
|
|
+ }
|
|
|
+ pars = make([]interface{}, 0)
|
|
|
+ condition = ` AND user_id = ? `
|
|
|
+ pars = append(pars, userId)
|
|
|
+ condition += ` AND weight > 0 ORDER BY weight DESC `
|
|
|
+ listother, e := models.GetCygxUserLabelList(condition, pars)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxUserLabelList" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range listother {
|
|
|
+ if idMap[v.Id] {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ list = append(list, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //当产业关注数量超过10 ,系列关注数量不超过5
|
|
|
+ if totalSource1 > 10 && totalSource2 <= 5 {
|
|
|
+ condition += ` AND source = 2 AND is_follow = 1 ORDER BY weight DESC `
|
|
|
+ listfollow, e := models.GetCygxUserLabelList(condition, pars)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxUserLabelList" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ idMap := make(map[int]bool)
|
|
|
+ for _, v := range listfollow {
|
|
|
+ idMap[v.Id] = true
|
|
|
+ list = append(list, v)
|
|
|
+ }
|
|
|
+ pars = make([]interface{}, 0)
|
|
|
+ condition = ` AND user_id = ? `
|
|
|
+ pars = append(pars, userId)
|
|
|
+ condition += ` AND weight > 0 ORDER BY weight DESC `
|
|
|
+ listother, e := models.GetCygxUserLabelList(condition, pars)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxUserLabelList" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range listother {
|
|
|
+ if idMap[v.Id] {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ list = append(list, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var labelUser string
|
|
|
+ for _, v := range list {
|
|
|
+ labelUser += v.Label + ","
|
|
|
+ }
|
|
|
+ labelUser = strings.TrimRight(labelUser, ",")
|
|
|
+ e = models.UpdateUserLabel(labelUser, userId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("UpdateUserLabel" + e.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|