Browse Source

no message

xingzai 1 year ago
parent
commit
713c7773ab

+ 1 - 0
controllers/article.go

@@ -971,6 +971,7 @@ func (this *ArticleController) AddStopTime() {
 						recordRedis.CompanyName = user.CompanyName
 						recordRedis.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
 						go services.PushViewRecordNewRedisData(recordRedis, user.CompanyId)
+						go services.ArticleHistoryUserLabelLogAdd(articleId, user.UserId)
 					} else {
 						go models.UpdateCygxArticleViewRecordNewpv(record, stopTime)
 					}

+ 1 - 0
models/db.go

@@ -146,6 +146,7 @@ func init() {
 		new(CygxAboutUsVideoHistory),
 		new(CygxActivitySignupBreak),
 		new(CygxUserLabel),
+		new(CygxUserLabelActivity),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 28 - 2
models/industrial_activity_group_management.go

@@ -29,7 +29,7 @@ type CygxIndustrialSubject struct {
 	Source                 int       `description:"来源,1正常添加,2:通过文章添加,3通过活动添加(默认为1)"`
 }
 
-//获取标的列表
+// 获取标的列表
 func GetCygxIndustrialSubjectList(subjectName string) (items []*CygxIndustrialSubject, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
@@ -82,4 +82,30 @@ func GetActivityIndustryRelationList(condition string, pars []interface{}) (list
 	}
 	_, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
 	return
-}
+}
+
+// 获取数量
+func GetCygxIndustrialActivityGroupManagementCount(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_industrial_activity_group_management as art WHERE 1= 1  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}
+
+// CygxIndustrialActivityGroupManagement 获取活动与产业关联列表
+func GetCygxIndustrialActivityGroupManagementList(condition string, pars []interface{}) (list []*CygxIndustrialActivityGroupManagement, err error) {
+	sql := `SELECT
+			*
+			FROM
+			cygx_industrial_activity_group_management
+			WHERE
+				1 = 1 `
+	if condition != `` {
+		sql += condition
+	}
+	_, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
+	return
+}

+ 21 - 0
models/report_mapping.go

@@ -374,3 +374,24 @@ func GetReportMapping() (items []*CygxReportMapping, err error) {
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+// 通过分类ID对应的系列名称
+func GetdetailByCategoryIdLabel(categoryId int) (item *CygxReportMapping, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			c.id,c.match_type_name
+			FROM
+			cygx_report_mapping_group as g
+			INNER JOIN cygx_report_mapping_cygx as c ON c.id = g.id_cygx
+			WHERE
+			category_id_celue = ? LIMIT 1`
+	err = o.Raw(sql, categoryId).QueryRow(&item)
+	return
+}
+
+func GetCygxReportMappingById(id int) (items *CygxReportMapping, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_report_mapping_cygx WHERE id = ?`
+	err = o.Raw(sql, id).QueryRow(&items)
+	return
+}

+ 23 - 4
models/user_label.go

@@ -31,7 +31,7 @@ type CygxUserLabel struct {
 
 // 获取数量
 func GetCygxUserLabelCount(condition string, pars []interface{}) (count int, err error) {
-	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_user_label as art WHERE 1= 1  `
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_user_label as art WHERE 1= 1   AND modify_time > DATE_SUB(CURDATE(), INTERVAL 3 MONTH)  `
 	if condition != "" {
 		sqlCount += condition
 	}
@@ -48,9 +48,28 @@ func AddCygxUserLabel(item *CygxUserLabel) (lastId int64, err error) {
 }
 
 // 修改是否关注
-func UpdateCygxUserLabelIsFollow(isFollow, sourceId, source int, label string) (err error) {
+func UpdateCygxUserLabelIsFollow(isFollow, sourceId, source, userId int, label string) (err error) {
 	o := orm.NewOrm()
-	sql := `UPDATE cygx_user_label SET is_follow=?,label = ? , modify_time=NOW()  WHERE source_id=? AND source = ? `
-	_, err = o.Raw(sql, isFollow, label, sourceId, source).Exec()
+	sql := `UPDATE cygx_user_label SET is_follow=?,label = ? , modify_time=NOW()  WHERE source_id=? AND source = ? AND user_id = ? `
+	_, err = o.Raw(sql, isFollow, label, sourceId, source, userId).Exec()
+	return
+}
+
+// 修改对应标签权重+1
+func UpdateCygxUserLabelWeight(sourceId, source, userId int, label string) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_user_label SET weight = weight +1 ,label = ? , modify_time=NOW()  WHERE source_id=? AND source = ? AND  user_id = ? `
+	_, err = o.Raw(sql, label, sourceId, source, userId).Exec()
+	return
+}
+
+// 列表
+func GetCygxUserLabelList(condition string, pars []interface{}) (items []*CygxUserLabel, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_user_label as art WHERE 1= 1   AND modify_time > DATE_SUB(CURDATE(), INTERVAL 3 MONTH)	`
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
 	return
 }

+ 42 - 0
models/user_label_activity.go

@@ -0,0 +1,42 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxUserLabelActivity struct {
+	Id         int       `orm:"column(id);pk"`
+	UserId     int       `description:"用户ID"`
+	CompanyId  int       `description:"公司id"`
+	RealName   string    `description:"用户实际名称"`
+	Mobile     string    `description:"手机号"`
+	Email      string    `description:"邮箱"`
+	Label      string    `description:"标签内容"`
+	ActivityId int       `description:"活动ID"`
+	CreateTime time.Time `description:"创建时间"`
+	ModifyTime time.Time `description:"更新时间"`
+}
+
+// 列表
+func GetCygxUserLabelActivity(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxUserLabelActivity, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_user_label_activity as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+// 批量添加
+func AddCygxUserLabelActivityList(items []*CygxUserLabelActivity) (lastId int64, err error) {
+	lenitems := len(items)
+	if lenitems == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	_, err = o.InsertMulti(1, items)
+	return
+}

+ 12 - 0
models/wx_user.go

@@ -584,6 +584,18 @@ func GetWxUserByMobiles(mobiles []string) (items []*WxUser, err error) {
 	return
 }
 
+// GetWxUserByMobiles 根据用户手机号获取用户详情
+func GetWxUserByOutboundMobiles(mobiles []string) (items []*WxUser, err error) {
+	lenmobiles := len(mobiles)
+	if lenmobiles == 0 {
+		return
+	}
+	sql := `SELECT* FROM wx_user  WHERE outbound_mobile in (` + utils.GetOrmInReplace(lenmobiles) + `)  `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, mobiles).QueryRows(&items)
+	return
+}
+
 func UserSubscribe(subscribeTime string, userId int) (err error) {
 	o := orm.NewOrm()
 	sql := `UPDATE wx_user SET cygx_subscribe=1,cygx_subscribe_time=? WHERE user_id = ? `

+ 6 - 0
services/activity.go

@@ -1355,6 +1355,7 @@ func ActivityAttendanceDetail(cont context.Context) (err error) {
 				var isPlayback bool // 是否包含回放
 				needAddAttendanc := make([]*models.CygxActivityAttendanceDetail, 0)
 				var mobileStr string
+				var mobileArr []string
 				if len(list) > 0 {
 					fmt.Println("原来的", vAct.RoadshowTitle)
 					fmt.Println("处理的", activityName)
@@ -1387,6 +1388,7 @@ func ActivityAttendanceDetail(cont context.Context) (err error) {
 							item.CrmCompanyMapStatusId = v.CrmCompanyMapStatusId
 							item.CreateTime = time.Now()
 							mobileStr += "'" + v.UserPhone + "'" + ","
+							mobileArr = append(mobileArr, v.UserPhone)
 							needAddAttendanc = append(needAddAttendanc, item)
 						}
 					}
@@ -1429,6 +1431,7 @@ func ActivityAttendanceDetail(cont context.Context) (err error) {
 					}
 
 					go AddctivitySignupDetailByJmcj(needAddAttendanc, activityDetail.ActivityId)
+					go ActivityUserLabelLogAdd(activityDetail.ActivityId, mobileArr)
 				}
 			}
 		}
@@ -1464,6 +1467,7 @@ func ActivityAttendanceDetail(cont context.Context) (err error) {
 				var isPlayback bool // 是否包含回放
 				needAddAttendanc := make([]*models.CygxActivityAttendanceDetail, 0)
 				var mobileStr string
+				var mobileArr []string
 				if len(list) > 0 {
 					fmt.Println("原来的1", vAct.ActivityName)
 					fmt.Println("处理的2", activityName)
@@ -1496,6 +1500,7 @@ func ActivityAttendanceDetail(cont context.Context) (err error) {
 							item.CrmCompanyMapStatusId = v.CrmCompanyMapStatusId
 							item.CreateTime = time.Now()
 							mobileStr += "'" + v.UserPhone + "'" + ","
+							mobileArr = append(mobileArr, v.UserPhone)
 							needAddAttendanc = append(needAddAttendanc, item)
 						}
 					}
@@ -1537,6 +1542,7 @@ func ActivityAttendanceDetail(cont context.Context) (err error) {
 					}
 					activityIds += strconv.Itoa(vAct.ActivityId) + ","
 					go AddctivitySignupDetailByJmcj(needAddAttendanc, vAct.ActivityId)
+					go ActivityUserLabelLogAdd(vAct.ActivityId, mobileArr)
 				}
 			}
 		}

+ 626 - 5
services/user_label.go

@@ -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
+}