فهرست منبع

Merge branch 'cygx_10.5.1' of http://8.136.199.33:3000/hongze/hongze_cygx

xingzai 1 سال پیش
والد
کامیت
ad2b7f6a6c

+ 18 - 0
controllers/activity_sign.go

@@ -139,6 +139,24 @@ func (this *ActivitySignCoAntroller) Detail() {
 
 		//线下调研活动扫码签到给对应销售发模版消息
 		services.SendActivitieSignTemplateMsg(user, activityInfo)
+
+		//处理用户标签
+		services.ActivityUserLabelLogAdd(activityId, []string{user.Mobile})
+
+		{
+			//用做后台联系人列表查询
+			itemD := new(models.CygxActivityAttendanceDetail)
+			itemD.ActivityId = activityId
+			itemD.RealName = user.RealName
+			itemD.Mobile = user.Mobile
+			itemD.CompanyName = user.CompanyName
+			itemD.IsMeetingStr = 1
+			itemD.CreateTime = time.Now()
+			var itemDs []*models.CygxActivityAttendanceDetail
+			itemDs = append(itemDs, itemD)
+			services.AddctivitySignupDetailByJmcjNew(itemDs, []int{activityId})
+		}
+
 	}
 	//1,没有签到记录不为潜在客户
 	//2,没有签到记录,手机号不为空,没有申请记录

+ 3 - 83
controllers/article.go

@@ -272,28 +272,7 @@ func (this *ArticleController) Detail() {
 			}
 			if hasPersion {
 				hasPermission = 1
-				historyRecord := new(models.CygxArticleHistoryRecord)
-				historyRecord.UserId = uid
-				historyRecord.ArticleId = articleId
-				historyRecord.CreateTime = time.Now()
-				historyRecord.Mobile = user.Mobile
-				historyRecord.Email = user.Email
-				historyRecord.CompanyId = user.CompanyId
-				historyRecord.CompanyName = user.CompanyName
-				recordCount, _ := models.GetNoAddStoptimeArticleCount(uid, articleId)
-				if recordCount == 0 {
-					go models.AddCygxArticleHistoryRecord(historyRecord)
-				} else {
-					detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
-					if err != nil {
-						br.Msg = "获取信息失败"
-						br.ErrMsg = "获取信息失败,Err:" + err.Error()
-						return
-					}
-					if detailNew.StopTime > 0 {
-						go models.AddCygxArticleHistoryRecord(historyRecord)
-					}
-				}
+				go services.ArticleHistory(articleId, user)
 				//30分钟之内阅读同一篇文章不错二次推送
 				key := "CYGX_ARTICLE_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
 				if !utils.Rc.IsExist(key) {
@@ -308,23 +287,6 @@ func (this *ArticleController) Detail() {
 					hasPermission = 3
 				}
 			}
-			if hasPermission == 1 {
-				key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
-				if !utils.Rc.IsExist(key) {
-					//新增浏览记录
-					record := new(models.CygxArticleViewRecord)
-					record.UserId = uid
-					record.ArticleId = articleId
-					record.CreateTime = time.Now()
-					record.Mobile = user.Mobile
-					record.Email = user.Email
-					record.CompanyId = user.CompanyId
-					record.CompanyName = user.CompanyName
-					go models.AddCygxArticleViewRecord(record)
-					utils.Rc.Put(key, 1, 5*time.Second)
-					models.ModifyReportLastViewTime(uid)
-				}
-			}
 		}
 
 		interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
@@ -533,6 +495,7 @@ func (this *ArticleController) ArticleCollect() {
 		resp.Status = 1
 		// 文章收藏消息发送
 		go services.ArticleUserRemind(user, detail, 2)
+		go services.ArticleHistoryUserLabelLogAdd(articleId, user.UserId)
 	} else {
 		err = models.RemoveArticleCollect(uid, articleId)
 		if err != nil {
@@ -937,50 +900,7 @@ func (this *ArticleController) AddStopTime() {
 				}
 			}
 			if hasPersion {
-				detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
-				if err == nil {
-					hasPermission = 1
-					historyRecord := new(models.AddStopTimeNewRep)
-					historyRecord.StopTime = detailNew.StopTime + stopTime
-					historyRecord.Id = detailNew.Id
-					historyRecord.OutType = outType
-					go models.UpdateArticleStopTime(historyRecord)
-				}
-
-				//不统计本公司的阅读记录、正常退出的不做时间差统计
-				if stopTime > 3 {
-					key := "CYGX_ARTICLE_PV" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) + "_" + strconv.Itoa(user.CompanyId) + "_" + strconv.Itoa(outType)
-					record := new(models.CygxArticleHistoryRecordNewpv)
-					record.UserId = uid
-					record.ArticleId = articleId
-					record.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
-					record.ModifyTime = time.Now()
-					record.Mobile = user.Mobile
-					record.Email = user.Email
-					record.CompanyId = user.CompanyId
-					record.CompanyName = user.CompanyName
-					record.StopTime = stopTime
-					record.OutType = outType
-					record.Source = source
-					if !utils.Rc.IsExist(key) || outType != 2 {
-						//新增浏览记录
-						go models.AddCygxArticleViewRecordNewpv(record)
-						recordRedis := new(services.ReportViewRecord)
-						recordRedis.UserId = user.UserId
-						recordRedis.ReportId = articleId
-						recordRedis.Mobile = user.Mobile
-						recordRedis.Email = user.Email
-						recordRedis.RealName = user.RealName
-						recordRedis.CompanyName = user.CompanyName
-						recordRedis.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
-						go services.PushViewRecordNewRedisData(recordRedis, user.CompanyId)
-					} else {
-						go models.UpdateCygxArticleViewRecordNewpv(record, stopTime)
-					}
-					utils.Rc.Put(key, 1, 10*time.Minute)
-				}
-
-				models.ModifyReportLastViewTime(uid)
+				go services.ArticleHistoryStopTime(articleId, stopTime, outType, user)
 			} else { //无该行业权限
 				hasPermission = 3
 			}

+ 2 - 2
controllers/report.go

@@ -864,8 +864,8 @@ func (this *ReportController) Fllow() {
 		}
 	}
 
-	//处理是否关注全部赛道字段
-	go services.IndustryFllowWithTrack(industrialManagementId, count, uid)
+	go services.IndustryFllowWithTrack(industrialManagementId, count, uid)       //处理是否关注全部赛道字段
+	go services.IndustryFllowUserLabelLogAdd(industrialManagementId, count, uid) //处理用户标签
 	br.Msg = "操作成功"
 	br.Ret = 200
 	br.Success = true

+ 12 - 0
models/activity.go

@@ -1217,6 +1217,18 @@ func GetActivityLabelListAllNoLimit(condition, sortTime string, pars []interface
 	return
 }
 
+// 列表
+func GetCygxActivityList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivity, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_activity as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
 // 批量修改弘则活动与进门财经的一个活动关联
 func UpdateJmcjActivityIdGroup(items map[int]string) (err error) {
 	o := orm.NewOrm()

+ 10 - 0
models/activity_special_trip.go

@@ -51,6 +51,16 @@ func GetCygxActivitySpecialTripList(condition string, pars []interface{}) (item
 	return
 }
 
+func GetCygxActivitySpecialmeetingDetailList(condition string, pars []interface{}) (item []*CygxActivitySpecialTripResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *
+			FROM
+			cygx_activity_special_meeting_detail  
+			WHERE 1 = 1 ` + condition
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}
+
 // 获取某一用户的报名的数量
 func GetUserActivitySpecialTripCount(uid, activityId int) (count int, err error) {
 	sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip  WHERE  user_id=?  AND   activity_id =? `

+ 0 - 13
models/article_category_mapping.go

@@ -30,19 +30,6 @@ func AddCygxArticleCategoryMapping(item *CygxArticleCategoryMapping) (lastId int
 	return
 }
 
-type CygxReportMappingCygx struct {
-	Id                  int    `orm:"column(id);pk" description:"id"`
-	ChartPermissionId   int    `description:"行业ID"`
-	ChartPermissionName string `description:"行业名称"`
-	MatchTypeName       string `description:"分类名称"`
-	ReportType          int    `description:"报告类型,2产业报告,1行业报告"`
-	Sort                int    `description:"排序"`
-	IsCustom            int    `description:"是否属于自定义的匹配类型 ,1是,0否"`
-	IsSummary           int    `description:"是否是纪要库,1是,0否"`
-	IsReport            int    `description:"是否是报告,1是,0否"`
-	PermissionType      int    `description:"1主观,2客观"`
-}
-
 type CygxReportMappingGroup struct {
 	Id              int       `orm:"column(id);pk" description:"id"`
 	IdCygx          int       `description:"分类ID"`

+ 1 - 1
models/article_history_record_newpv.go

@@ -295,7 +295,7 @@ func GetCygxArticleHistoryAllTop(pars []interface{}, condition string) (items []
 // 列表
 func GetCygxArticleHistoryRecordNewpvList(condition string, pars []interface{}) (items []*CygxArticleHistoryRecordNewpv, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM cygx_article_history_record_newpv as art WHERE 1= 1 `
+	sql := `SELECT * FROM cygx_article_history_record_newpv as art WHERE 1= 1  `
 	if condition != "" {
 		sql += condition
 	}

+ 4 - 0
models/db.go

@@ -147,6 +147,10 @@ func init() {
 		new(CygxActivitySignupBreak),
 		new(CygxBannerHistory),
 		new(CygxReportHistoryRecordLog),
+		new(CygxUserLabel),
+		new(CygxUserLabelActivity),
+		new(CygxUserLabelArticle),
+		new(CygxUserLabelActivitySpecial),
 	)
 	// 记录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
+}

+ 12 - 0
models/industry_fllow.go

@@ -203,3 +203,15 @@ func GetTopIndustryFollowData(startSize, pageSize int, condition string, pars []
 	_, err = orm.NewOrm().Raw(sql, pars, startSize, pageSize).QueryRows(&list)
 	return
 }
+
+// 列表
+func GetCygxIndustryFllowListByCon(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxIndustryFllow, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_industry_fllow as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	//sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	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
+}

+ 31 - 0
models/report_mapping_cygx.go

@@ -0,0 +1,31 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	//"time"
+)
+
+type CygxReportMappingCygx struct {
+	Id                  int    `orm:"column(id);pk" description:"id"`
+	ChartPermissionId   int    `description:"行业ID"`
+	ChartPermissionName string `description:"行业名称"`
+	MatchTypeName       string `description:"分类名称"`
+	ReportType          int    `description:"报告类型,2产业报告,1行业报告"`
+	Sort                int    `description:"排序"`
+	IsCustom            int    `description:"是否属于自定义的匹配类型 ,1是,0否"`
+	IsSummary           int    `description:"是否是纪要库,1是,0否"`
+	IsReport            int    `description:"是否是报告,1是,0否"`
+	PermissionType      int    `description:"1主观,2客观"`
+}
+
+// 列表
+func GetCygxReportMappingCygxByCon(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxReportMappingCygx, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_report_mapping_cygx as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	//sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 115 - 0
models/user_label.go

@@ -0,0 +1,115 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxUserLabelLogRedis struct {
+	UserId     int       `description:"用户ID"`
+	SourceId   int       `description:"资源ID"`
+	SourceType int       `description:"1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。"`
+	IsFllow    int       `description:"1关注、0取消关注"`
+	CreateTime time.Time `description:"创建时间"`
+}
+
+type CygxUserLabel 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:"标签内容"`
+	Weight     int       `description:"权重"`
+	SourceId   int       `description:"来源ID(产业ID,系列ID)"`
+	Source     int       `description:"来源1:产业、2:系列"`
+	IsFollow   int       `description:"是否关注,1是,0否"`
+	CreateTime time.Time `description:"创建时间"`
+	ModifyTime time.Time `description:"更新时间"`
+}
+
+// 获取数量
+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   AND modify_time > DATE_SUB(CURDATE(), INTERVAL 3 MONTH)  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}
+
+// 添加
+func AddCygxUserLabel(item *CygxUserLabel) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+// 批量添加
+func CygxUserLabelMulti(items []*CygxUserLabel) (err error) {
+	o := orm.NewOrm()
+	if len(items) > 0 {
+		//批量添加新的记录
+		_, err = o.InsertMulti(len(items), items)
+	}
+	return
+}
+
+// 修改是否关注
+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 = ? 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
+}
+
+// 把所有用户标签权重设置为0
+func UpdateCygxUserLabelWeightAll() (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_user_label SET weight = 0 `
+	_, err = o.Raw(sql).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   	`
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+// UpdateCygxUserLabelMulti 批量修改用户标签权重
+func UpdateCygxUserLabelMulti(items []*CygxUserLabel) (err error) {
+	o := orm.NewOrm()
+	p, err := o.Raw(` UPDATE cygx_user_label SET weight = ? WHERE user_id = ? AND label = ? `).Prepare()
+	if err != nil {
+		return
+	}
+	defer func() {
+		_ = p.Close() // 别忘记关闭 statement
+	}()
+	for _, v := range items {
+		_, err = p.Exec(
+			v.Weight,
+			v.UserId,
+			v.Label)
+		if err != nil {
+			return
+		}
+	}
+	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"`
+	IndustrialManagementId int       `description:"cygx_industrial_management表的主键ID"`
+	CreateTime             time.Time `description:"创建时间"`
+	ModifyTime             time.Time `description:"更新时间"`
+}
+
+// 列表
+func GetCygxUserLabelActivity(condition string, pars []interface{}) (items []*CygxUserLabelActivity, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_user_label_activity as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).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
+}

+ 43 - 0
models/user_label_activity_special.go

@@ -0,0 +1,43 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxUserLabelActivitySpecial 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"`
+	IndustrialManagementId int       `description:"cygx_industrial_management表的主键ID"`
+	CreateTime             time.Time `description:"创建时间"`
+	ModifyTime             time.Time `description:"更新时间"`
+}
+
+// 列表
+func GetCygxUserLabelActivitySpecial(condition string, pars []interface{}) (items []*CygxUserLabelActivitySpecial, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_user_label_activity_special as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+// 批量添加
+func AddCygxUserLabelActivitySpecialList(items []*CygxUserLabelActivitySpecial) (lastId int64, err error) {
+	lenitems := len(items)
+	if lenitems == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	_, err = o.InsertMulti(1, items)
+	return
+}

+ 50 - 0
models/user_label_article.go

@@ -0,0 +1,50 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxUserLabelArticle 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:"标签内容"`
+	ArticleId  int       `description:"文章ID"`
+	SourceId   int       `description:"来源ID(产业ID,系列ID)"`
+	Source     int       `description:"来源1:产业、2:系列"`
+	CreateTime time.Time `description:"创建时间"`
+	ModifyTime time.Time `description:"更新时间"`
+}
+
+// 添加
+func AddCygxUserLabelArticle(item *CygxUserLabelArticle) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+// 批量添加
+func AddCygxUserLabelArticleList(items []*CygxUserLabelArticle) (lastId int64, err error) {
+	lenitems := len(items)
+	if lenitems == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	_, err = o.InsertMulti(1, items)
+	return
+}
+
+// 列表
+func GetCygxUserLabelArticleList(condition string, pars []interface{}) (items []*CygxUserLabelArticle, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_user_label_article as art WHERE 1= 1   	`
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&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 = ? `

+ 12 - 0
models/xzs_choose_category.go

@@ -27,6 +27,18 @@ func GetCygxXzsChooseCategoryList(mobile string) (items []*CygxXzsChooseCategory
 	return
 }
 
+// 列表
+func GetCygxXzsChooseCategoryListByCon(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxXzsChooseCategory, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_xzs_choose_category as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	//sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
 // 添加
 func AddCygxCategoryFllow(item *CygxXzsChooseCategory) (lastId int64, err error) {
 	o := orm.NewOrm()

+ 10 - 0
services/activity.go

@@ -1377,6 +1377,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)
@@ -1409,6 +1410,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)
 						}
 					}
@@ -1450,7 +1452,10 @@ func ActivityAttendanceDetail(cont context.Context) (err error) {
 						return err
 					}
 
+					go ActivityUserLabelLogAdd(activityDetail.ActivityId, mobileArr)
+
 					AddctivitySignupDetailByJmcj(needAddAttendanc, activityDetail.ActivityId)
+
 				}
 			}
 		}
@@ -1486,6 +1491,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)
@@ -1518,6 +1524,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)
 						}
 					}
@@ -1558,7 +1565,10 @@ func ActivityAttendanceDetail(cont context.Context) (err error) {
 						return err
 					}
 					activityIds += strconv.Itoa(vAct.ActivityId) + ","
+
+					go ActivityUserLabelLogAdd(vAct.ActivityId, mobileArr)
 					AddctivitySignupDetailByJmcj(needAddAttendanc, vAct.ActivityId)
+
 				}
 			}
 		}

+ 85 - 0
services/article_history.go

@@ -1,9 +1,12 @@
 package services
 
 import (
+	"errors"
 	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
+	"strconv"
+	"time"
 )
 
 func GetArticleHistoryByUser(articleIds []int, user *models.WxUserItem) (mapResp map[int]int) {
@@ -32,3 +35,85 @@ func GetArticleHistoryByUser(articleIds []int, user *models.WxUserItem) (mapResp
 	}
 	return
 }
+
+// 记录用户文章浏览记录
+func ArticleHistory(articleId int, user *models.WxUserItem) (err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("记录用户文章浏览记录,失败"+err.Error(), 2)
+		}
+	}()
+	recordRedis := new(ReportViewRecord)
+	recordRedis.UserId = user.UserId
+	recordRedis.ReportId = articleId
+	recordRedis.Mobile = user.Mobile
+	recordRedis.Email = user.Email
+	recordRedis.RealName = user.RealName
+	recordRedis.CompanyName = user.CompanyName
+	recordRedis.CreateTime = time.Now()
+	go PushViewRecordNewRedisData(recordRedis, user.CompanyId)
+	uid := user.UserId
+	key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
+	if !utils.Rc.IsExist(key) {
+		//新增浏览记录
+		//这个表貌似没怎么用了,暂时保留记录
+		record := new(models.CygxArticleViewRecord)
+		record.UserId = uid
+		record.ArticleId = articleId
+		record.CreateTime = time.Now()
+		record.Mobile = user.Mobile
+		record.Email = user.Email
+		record.CompanyId = user.CompanyId
+		record.CompanyName = user.CompanyName
+		_, e := models.AddCygxArticleViewRecord(record)
+		if e != nil {
+			err = errors.New("AddCygxArticleViewRecord, Err: " + e.Error())
+			return
+		}
+
+		e = models.ModifyReportLastViewTime(uid)
+		if e != nil {
+			err = errors.New("ModifyReportLastViewTime, Err: " + e.Error())
+			return
+		}
+		utils.Rc.Put(key, 1, 2*time.Second)
+	}
+	return
+}
+
+// 记录用户文章浏览记录带时长
+func ArticleHistoryStopTime(articleId, stopTime, outType int, user *models.WxUserItem) (err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("记录用户文章浏览记录带时长,失败"+err.Error(), 2)
+		}
+	}()
+	if stopTime < 3 {
+		return
+	}
+	uid := user.UserId
+
+	key := "CYGX_ARTICLE_PV" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) + "_" + strconv.Itoa(user.CompanyId) + "_" + strconv.Itoa(outType)
+	if !utils.Rc.IsExist(key) {
+		record := new(models.CygxArticleHistoryRecordNewpv)
+		record.UserId = uid
+		record.ArticleId = articleId
+		record.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
+		record.ModifyTime = time.Now()
+		record.Mobile = user.Mobile
+		record.Email = user.Email
+		record.CompanyId = user.CompanyId
+		record.CompanyName = user.CompanyName
+		record.StopTime = stopTime
+		record.OutType = outType
+		record.Source = "WEB"
+		_, e := models.AddCygxArticleViewRecordNewpv(record)
+		if e != nil {
+			err = errors.New("AddCygxArticleViewRecordNewpv, Err: " + e.Error())
+			return
+		}
+		utils.Rc.Put(key, 1, 2*time.Second)
+	}
+	go ArticleHistoryUserLabelLogAdd(articleId, uid)
+	return
+}

+ 5 - 0
services/industrial_management.go

@@ -299,6 +299,11 @@ func IndustryFllowWithTrack(industrialManagementId, count, uid int) (err error)
 	return err
 }
 
+func init() {
+	//IndustryFllowUserLabel(136, 16, 5660)
+	//UserLabelLogReduce()
+}
+
 // GetIndustryNewLabelMap 获取产业【新】标签Map
 func GetIndustryNewLabelMap(industryIds []int) (labelMap map[int]bool, err error) {
 	labelMap = make(map[int]bool, 0)

+ 1 - 1
services/init_10.3.go

@@ -7,7 +7,7 @@ import (
 
 //10.3版本上线需要更新的数据
 
-func init1111() {
+func init51111() {
 	var condition string
 	var pars []interface{}
 	var err error

+ 447 - 0
services/init_10.5.1.go

@@ -0,0 +1,447 @@
+package services
+
+import (
+	"fmt"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+	"time"
+)
+
+//10.5.1版本上线需要更新的数据
+
+func init1111() {
+	var condition string
+	var pars []interface{}
+	var err error
+	fmt.Print()
+
+	var topCond string
+	var topPars []interface{}
+	toplist, err := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
+	if err != nil {
+		return
+	}
+
+	mapIndustryName := make(map[int]string)
+	for _, v := range toplist {
+		mapIndustryName[v.IndustrialManagementId] = v.IndustryName
+	}
+	fmt.Println(mapIndustryName)
+	//处理上周纪要汇总
+	condition = ` AND  type = 1  `
+	list, err := models.GetCygxIndustryFllowListByCon(condition, pars, 0, 100000)
+	if err != nil {
+		fmt.Println(err)
+	}
+	var items []*models.CygxUserLabel
+	for _, user := range list {
+		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 = mapIndustryName[user.IndustrialManagementId]
+		item.SourceId = user.IndustrialManagementId
+		item.Source = 1
+		item.IsFollow = 1
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		items = append(items, item)
+		if len(items)%5000 == 0 {
+			err = models.CygxUserLabelMulti(items)
+			fmt.Println(err)
+			items = make([]*models.CygxUserLabel, 0)
+		}
+	}
+	if len(items) > 0 {
+		err = models.CygxUserLabelMulti(items)
+		fmt.Println(err, "555")
+	}
+}
+
+func init5222() {
+	var condition string
+	var pars []interface{}
+	var err error
+	fmt.Print()
+
+	var topCond string
+	var topPars []interface{}
+	toplist, err := models.GetCygxReportMappingCygxByCon(topCond, topPars, 0, 0)
+	if err != nil {
+		return
+	}
+
+	mapIndustryName := make(map[int]string)
+	for _, v := range toplist {
+		mapIndustryName[v.Id] = v.MatchTypeName
+	}
+	fmt.Println(mapIndustryName)
+
+	condition = ` `
+	list, err := models.GetCygxXzsChooseCategoryListByCon(condition, pars, 0, 100000)
+	if err != nil {
+		fmt.Println(err)
+	}
+	var items []*models.CygxUserLabel
+	for _, user := range list {
+		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 = mapIndustryName[user.IdCygx]
+		item.SourceId = user.IdCygx
+		item.Source = 2
+		item.IsFollow = 1
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		items = append(items, item)
+		if len(items)%5000 == 0 {
+			err = models.CygxUserLabelMulti(items)
+			fmt.Println(err)
+			items = make([]*models.CygxUserLabel, 0)
+		}
+	}
+	if len(items) > 0 {
+		err = models.CygxUserLabelMulti(items)
+		fmt.Println(err, "555")
+	}
+}
+
+func init5333() {
+	var condition string
+	var pars []interface{}
+	var err error
+	fmt.Print()
+
+	var topCond string
+	var topPars []interface{}
+	toplist, err := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
+	if err != nil {
+		return
+	}
+
+	mapIndustryName := make(map[int]string)
+	for _, v := range toplist {
+		mapIndustryName[v.IndustrialManagementId] = v.IndustryName
+	}
+	fmt.Println(mapIndustryName)
+	condition = ` AND activity_time > '2022-11-25 00:00:00' AND publish_status = 1    `
+	listAct, err := models.GetCygxActivityList(condition, pars, 0, 100000)
+	if err != nil {
+		fmt.Println(err)
+	}
+	var items []*models.CygxUserLabelActivity
+	for _, v := range listAct {
+		fmt.Println(v.ActivityTime)
+		var condition1 string
+		var pars1 []interface{}
+		condition1 = ` AND activity_id = ?  `
+		pars1 = append(pars1, v.ActivityId)
+		total, e := models.GetCygxIndustrialActivityGroupManagementCount(condition1+"  AND  source = 1 ", pars1)
+		if e != nil {
+			fmt.Println(e)
+			return
+		}
+		if total == 0 {
+			continue
+		}
+		industrialList, e := models.GetCygxIndustrialActivityGroupManagementList(condition1+"  AND  source = 1 ", pars1)
+		if e != nil {
+			fmt.Println(e)
+			return
+		}
+
+		pars = make([]interface{}, 0)
+		condition = ` AND activity_id  = ? AND is_meeting = 1  `
+		pars = append(pars, v.ActivityId)
+		signUpList, err := models.GetSignupDetailBySignup(condition, pars)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			return
+		}
+		for _, vi := range industrialList {
+			for _, user := range signUpList {
+				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 = v.ActivityId
+				item.IndustrialManagementId = vi.IndustrialManagementId
+				item.Label = mapIndustryName[vi.IndustrialManagementId]
+				item.CreateTime = utils.StrTimeToTime(v.ActivityTime)
+				item.ModifyTime = time.Now()
+				items = append(items, item)
+				if len(items)%5000 == 0 {
+					_, err = models.AddCygxUserLabelActivityList(items)
+					fmt.Println(err)
+					items = make([]*models.CygxUserLabelActivity, 0)
+				}
+			}
+		}
+	}
+	fmt.Println(len(items))
+	if len(items) > 0 {
+		_, err = models.AddCygxUserLabelActivityList(items)
+		fmt.Println(err, "555")
+	}
+}
+
+func init5444() {
+	var condition string
+	var pars []interface{}
+	var err error
+	fmt.Print()
+
+	var topCond string
+	var topPars []interface{}
+	toplist, err := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
+	if err != nil {
+		return
+	}
+
+	mapIndustryName := make(map[int]string)
+	for _, v := range toplist {
+		mapIndustryName[v.IndustrialManagementId] = v.IndustryName
+	}
+	fmt.Println(mapIndustryName)
+	condition = ` AND is_meeting = 1  `
+	listAct, err := models.GetCygxActivitySpecialmeetingDetailList(condition, pars)
+	if err != nil {
+		fmt.Println(err)
+	}
+	var items []*models.CygxUserLabelActivitySpecial
+	for _, user := range listAct {
+		var condition1 string
+		var pars1 []interface{}
+		condition1 = ` AND activity_id = ?  `
+		pars1 = append(pars1, user.ActivityId)
+		total, e := models.GetCygxIndustrialActivityGroupManagementCount(condition1+"  AND  source = 2 ", pars1)
+		if e != nil {
+			fmt.Println(e)
+			return
+		}
+		if total == 0 {
+			continue
+		}
+		industrialList, e := models.GetCygxIndustrialActivityGroupManagementList(condition1+"  AND  source = 2 ", pars1)
+		if e != nil {
+			fmt.Println(e)
+			return
+		}
+		for _, vi := range industrialList {
+			item := new(models.CygxUserLabelActivitySpecial)
+			item.UserId = user.UserId
+			item.CompanyId = user.CompanyId
+			item.RealName = user.RealName
+			item.Mobile = user.Mobile
+			item.Email = user.Email
+			item.ActivityId = user.ActivityId
+			item.IndustrialManagementId = vi.IndustrialManagementId
+			item.Label = mapIndustryName[vi.IndustrialManagementId]
+			item.CreateTime = utils.StrTimeToTime(user.CreateTime)
+			item.ModifyTime = time.Now()
+			items = append(items, item)
+			if len(items)%5000 == 0 {
+				_, err = models.AddCygxUserLabelActivitySpecialList(items)
+				fmt.Println(err)
+				items = make([]*models.CygxUserLabelActivitySpecial, 0)
+			}
+		}
+	}
+	fmt.Println(len(items))
+	if len(items) > 0 {
+		_, err = models.AddCygxUserLabelActivitySpecialList(items)
+		fmt.Println(err, "555")
+	}
+}
+
+func init555() {
+	var condition string
+	var pars []interface{}
+	var err error
+	fmt.Print()
+
+	var topCond string
+	var topPars []interface{}
+	toplist, err := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
+	if err != nil {
+		return
+	}
+
+	mapIndustryName := make(map[int]string)
+	for _, v := range toplist {
+		mapIndustryName[v.IndustrialManagementId] = v.IndustryName
+	}
+	//fmt.Println(mapIndustryName)
+	condition = ` AND   stop_time > 3  AND create_time > '2022-11-25 00:00:00' GROUP BY article_id  `
+	//condition = `   AND   stop_time > 4   AND create_time > '2023-04-25 00:00:00' GROUP BY article_id  `
+	listArtGroup, err := models.GetCygxArticleHistoryRecordNewpvList(condition, pars)
+	if err != nil {
+		fmt.Println(err)
+	}
+	fmt.Println(len(listArtGroup))
+	var source int
+
+	itemsMap := make(map[int][]*models.CygxUserLabel)
+	for _, v := range listArtGroup {
+		fmt.Println(v.ArticleId)
+		var items []*models.CygxUserLabel
+		articleId := v.ArticleId
+		var condition string
+		var pars []interface{}
+		condition = ` AND article_id = ? `
+		pars = append(pars, v.ArticleId)
+		industrialList, e := models.GetIndustrialArticleGroupManagementList(condition, pars)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			fmt.Println(e)
+			return
+		}
+		if len(industrialList) == 0 {
+			//如果没有行产业归类就按照行业报告处理
+			source = 2
+			detailArticle, e := models.GetArticleDetailById(articleId)
+			if e != nil {
+				fmt.Println(e)
+				return
+			}
+
+			labelDetail, e := models.GetdetailByCategoryIdLabel(detailArticle.CategoryId)
+			if e != nil {
+				fmt.Println(e)
+				return
+			}
+			label := labelDetail.MatchTypeName
+			industrialManagementId := labelDetail.Id
+			item := new(models.CygxUserLabel)
+
+			item.Label = label
+			item.SourceId = industrialManagementId
+			item.Source = source
+			item.Weight = 1
+			item.CreateTime = time.Now()
+			item.ModifyTime = time.Now()
+			items = append(items, item)
+		} 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 {
+				fmt.Println(e)
+				return
+			}
+			source = 1
+			for _, v := range industrNamelist {
+				label := v.IndustryName
+				industrialManagementId := v.IndustrialManagementId
+
+				item := new(models.CygxUserLabel)
+				item.Label = label
+				item.SourceId = industrialManagementId
+				item.Source = source
+				item.Weight = 1
+				item.CreateTime = time.Now()
+				item.ModifyTime = time.Now()
+				items = append(items, item)
+
+			}
+
+			//for _, vi := range industrialList {
+			//	for _, user := range signUpList {
+			//		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 = v.ActivityId
+			//		item.IndustrialManagementId = vi.IndustrialManagementId
+			//		item.Label = mapIndustryName[vi.IndustrialManagementId]
+			//		item.CreateTime = utils.StrTimeToTime(v.ActivityTime)
+			//		item.ModifyTime = time.Now()
+			//		items = append(items, item)
+			//		if len(items)%50 == 0 {
+			//			_, err = models.AddCygxUserLabelActivityList(items)
+			//			fmt.Println(err)
+			//			items = make([]*models.CygxUserLabelActivity, 0)
+			//		}
+			//	}
+			//}
+			itemsMap[articleId] = items
+		}
+	}
+	condition = `   AND   stop_time > 3   AND create_time > '2022-11-25 00:00:00'   `
+	//condition = `  AND   stop_time > 4    AND create_time > '2023-4-25 00:00:00'   `
+	listArt, err := models.GetCygxArticleHistoryRecordNewpvList(condition, pars)
+	if err != nil {
+		fmt.Println(err)
+	}
+	var items []*models.CygxUserLabelArticle
+
+	for _, user := range listArt {
+		if len(itemsMap[user.ArticleId]) > 0 {
+			for k2, vlsit := range itemsMap {
+				if k2 != user.ArticleId {
+					continue
+				}
+				for _, vm := range vlsit {
+
+					//if user.ArticleId == 8365 {
+					//	fmt.Println("k", k, "_k2:", k2, "_k3:", k3)
+					//	fmt.Println(vm.Label)
+					//}
+					item := new(models.CygxUserLabelArticle)
+					item.UserId = user.UserId
+					item.ArticleId = user.ArticleId
+					item.CompanyId = user.CompanyId
+					//item.RealName = user.R
+					item.Mobile = user.Mobile
+					item.Email = user.Email
+					item.Label = vm.Label
+					item.SourceId = vm.SourceId
+					item.Source = vm.Source
+					item.CreateTime = user.CreateTime
+					item.ModifyTime = time.Now()
+					items = append(items, item)
+					if len(items)%5000 == 0 {
+						_, err = models.AddCygxUserLabelArticleList(items)
+						fmt.Println(err)
+						items = make([]*models.CygxUserLabelArticle, 0)
+					}
+				}
+			}
+		}
+	}
+	//for k, vlsit := range itemsMap[8365] {
+	//	fmt.Println(k)
+	//	fmt.Println(vlsit)
+	//	//for _, vm := range vlsit {
+	//	//	fmt.Println(vm)
+	//	//}
+	//}
+	fmt.Println(len(items))
+	fmt.Println(len(itemsMap))
+	fmt.Println((itemsMap))
+	fmt.Println(len(items))
+	if len(items) > 0 {
+		_, err = models.AddCygxUserLabelArticleList(items)
+		fmt.Println(err, "555")
+	}
+}

+ 2 - 0
services/task.go

@@ -125,6 +125,8 @@ func Task() {
 		getArticleListByApi := task.NewTask("getArticleListByApi", "0 */60 * * * *", GetArticleListByApi) //通过三方接口获取策略平台上的文章
 		task.AddTask("getArticleListByApi", getArticleListByApi)
 	}
+
+	go UserLabelLogReduce() // 处理用户标签的队列消息
 	//GetCygxActivityAttendanceDetail()
 	//CreateIndexNameArticleHistory()
 	//AddAllArticleHistory()

+ 974 - 0
services/user_label.go

@@ -0,0 +1,974 @@
+package services
+
+import (
+	"encoding/json"
+	"errors"
+	"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
+}
+
+// 添加用户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
+}
+
+// 添加用户活动到会标签到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
+}
+
+func UserLabelLogReduce() (err error) {
+	for {
+		//SourceType int       `description:"1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。"`
+		utils.Rc.Brpop(utils.CYGX_USER_KEY_LABEL, func(b []byte) {
+			var log models.CygxUserLabelLogRedis
+			if err := json.Unmarshal(b, &log); err != nil {
+				fmt.Println("json unmarshal wrong!")
+				go utils.SendAlarmMsg("用户更新相关标签处理Redis队列消息失败:"+err.Error()+string(b), 2)
+			}
+			switch log.SourceType {
+			case 1:
+				go ArticleHistoryUserLabelLogReduce(log)
+				fmt.Println("文章阅读")
+				break
+			case 2:
+				go IndustryFllowUserLabelLogReduce(log)
+				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:
+				fmt.Println(string(b))
+				go utils.SendAlarmMsg("用户更新相关标签处理Redis队列消息失败:"+string(b), 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
+	}
+	var items []*models.CygxUserLabel
+	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
+		}
+		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()
+		items = append(items, item)
+		if total == 0 {
+			_, 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
+			}
+			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()
+			items = append(items, item)
+			if total == 0 {
+				_, 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
+				}
+			}
+		}
+	}
+	if len(items) > 0 {
+		go AddArticleHistoryUserLabelLog(items, articleId)
+	}
+	updateUserLabelByUserId(userId)
+	return
+}
+
+// 添加文章阅读记录日志,处理文章阅读三个月之内标签权重有效逻辑
+func AddArticleHistoryUserLabelLog(items []*models.CygxUserLabel, articleId int) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("添加文章阅读记录日志,处理文章阅读三个月之内标签权重有效逻辑失败:"+err.Error(), 2)
+		}
+	}()
+	if len(items) == 0 {
+		return
+	}
+	for _, v := range items {
+		item := new(models.CygxUserLabelArticle)
+		item.UserId = v.UserId
+		item.CompanyId = v.CompanyId
+		item.RealName = v.RealName
+		item.Mobile = v.Mobile
+		item.Email = v.Email
+		item.Label = v.Label
+		item.SourceId = v.SourceId
+		item.Source = v.Source
+		item.ArticleId = articleId
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		_, e := models.AddCygxUserLabelArticle(item)
+		if e != nil {
+			err = errors.New("AddCygxUserLabelArticle" + e.Error())
+			return
+		}
+	}
+	return
+}
+
+// 2:产业关注
+func IndustryFllowUserLabelLogReduce(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 := 1
+	detailIndustrial, e := models.GetIndustrialManagementDetail(industrialManagementId)
+	if e != nil {
+		err = errors.New("GetIndustrialManagementDetail" + e.Error())
+		return
+	}
+	label := detailIndustrial.IndustryName
+	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
+			}
+		}
+	}
+	updateUserLabelByUserId(userId)
+	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
+			}
+		}
+	}
+	updateUserLabelByUserId(userId)
+	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
+			}
+		}
+	}
+	updateUserLabelByUserId(userId)
+	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
+			}
+		}
+	}
+	updateUserLabelByUserId(userId)
+	return
+}
+
+// 更新用户标签
+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
+}
+
+//func init() {
+//	UpdateUserLabelWeight()
+//}
+
+// 更新用户标签权重
+func UpdateUserLabelWeight() (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("更新用户标签权重失败:"+err.Error(), 2)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	list, e := models.GetCygxUserLabelList(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxUserLabelList" + e.Error())
+		return
+	}
+	updateTime := time.Now().AddDate(0, -3, 0)
+	condition = ` AND create_time > ?`
+	pars = append(pars, updateTime)
+
+	listArticle, e := models.GetCygxUserLabelArticleList(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxUserLabelArticleList" + e.Error())
+		return
+	}
+
+	listActivity, e := models.GetCygxUserLabelActivity(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxUserLabelActivity" + e.Error())
+		return
+	}
+
+	listActivitySpecial, e := models.GetCygxUserLabelActivitySpecial(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxUserLabelActivitySpecial" + e.Error())
+		return
+	}
+	userLabel := make(map[string]bool)
+	userLabelWeight := make(map[string]int)
+	for _, v := range list {
+		userLabel[fmt.Sprint("user_id{|}", v.UserId, "{|}source_id{|}", v.SourceId, "{|}source{|}", v.Source)] = true
+	}
+	//处理文章标签
+	var items []*models.CygxUserLabel
+	for _, user := range listArticle {
+		if !userLabel[fmt.Sprint("user_id{|}", user.UserId, "{|}source_id{|}", user.SourceId, "{|}source{|}", user.Source)] {
+			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 = user.Label
+			item.SourceId = user.SourceId
+			item.Source = user.Source
+			item.CreateTime = user.CreateTime
+			item.ModifyTime = time.Now()
+			items = append(items, item)
+			userLabel[fmt.Sprint("user_id{|}", user.UserId, "{|}source_id{|}", user.SourceId, "{|}source{|}", user.Source)] = true
+		}
+		userLabelWeight[fmt.Sprint("user_id{|}", user.UserId, "{|}label{|}", user.Label)]++
+	}
+
+	//处理活动标签
+	for _, user := range listActivity {
+		if !userLabel[fmt.Sprint("user_id{|}", user.UserId, "{|}source_id{|}", user.IndustrialManagementId, "{|}source{|}", 1)] {
+			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 = user.Label
+			item.SourceId = user.IndustrialManagementId
+			item.Source = 1
+			item.CreateTime = user.CreateTime
+			item.ModifyTime = time.Now()
+			items = append(items, item)
+			userLabel[fmt.Sprint("user_id{|}", user.UserId, "{|}source_id{|}", user.IndustrialManagementId, "{|}source{|}", 1)] = true
+		}
+		userLabelWeight[fmt.Sprint("user_id{|}", user.UserId, "{|}label{|}", user.Label)]++
+	}
+
+	//处理专项调研活动标签
+	for _, user := range listActivitySpecial {
+		if !userLabel[fmt.Sprint("user_id{|}", user.UserId, "{|}source_id{|}", user.IndustrialManagementId, "{|}source{|}", 1)] {
+			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 = user.Label
+			item.SourceId = user.IndustrialManagementId
+			item.Source = 1
+			item.CreateTime = user.CreateTime
+			item.ModifyTime = time.Now()
+			items = append(items, item)
+			userLabel[fmt.Sprint("user_id{|}", user.UserId, "{|}source_id{|}", user.IndustrialManagementId, "{|}source{|}", 1)] = true
+		}
+		userLabelWeight[fmt.Sprint("user_id{|}", user.UserId, "{|}label{|}", user.Label)]++
+	}
+
+	if len(items) > 0 {
+		e = models.CygxUserLabelMulti(items)
+		if e != nil {
+			err = errors.New("CygxUserLabelMulti" + e.Error())
+			return
+		}
+	}
+	var itemsUpdate []*models.CygxUserLabel
+	for k, v := range userLabelWeight {
+		sliceUser := strings.Split(k, "{|}")
+		userid, _ := strconv.Atoi(sliceUser[1])
+		label := sliceUser[len(sliceUser)-1]
+		item := new(models.CygxUserLabel)
+		item.UserId = userid
+		item.Label = label
+		item.Weight = v
+		itemsUpdate = append(itemsUpdate, item)
+	}
+	e = models.UpdateCygxUserLabelMulti(itemsUpdate)
+	if e != nil {
+		err = errors.New("UpdateCygxUserLabelMulti" + e.Error())
+		return
+	}
+
+	e = models.UpdateCygxUserLabelWeightAll()
+	if e != nil {
+		err = errors.New("UpdateCygxUserLabelWeightAll" + e.Error())
+		return
+	}
+
+	pars = make([]interface{}, 0)
+	condition = ` GROUP BY user_id`
+	listUser, e := models.GetCygxUserLabelList(condition, pars)
+	for _, v := range listUser {
+		go updateUserLabelByUserId(v.UserId)
+	}
+	return
+}

+ 167 - 165
services/wx_user.go

@@ -5,7 +5,6 @@ import (
 	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
-	"sort"
 	"strconv"
 	"strings"
 	"time"
@@ -336,170 +335,170 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 	}
 
 	//处理用户标签
-	for _, vUser := range listUser {
-		labels, err := models.GetCygxCompanyUserListSplit(strconv.Itoa(vUser.UserId))
-		if err != nil {
-			fmt.Println("GetCygxCompanyUserListSplit Err", err)
-			return err
-		}
-		mapLabels := make(map[string]string)
-		var labelsListStr []*models.UserLabel
-		mapActivityLabels := make(map[string]string)
-		labelsList := strings.Split(labels, ",")
-		for _, vL := range labelsList {
-			if mapLabels[vL] == "" && vL != "" {
-				mapLabels[vL] = vL
-				item := new(models.UserLabel)
-				item.Label = vL
-				labelsListStr = append(labelsListStr, item)
-			}
-		}
-		dateTime := time.Now().AddDate(0, -3, 0).Format(utils.FormatDate)
-		listArticlePv, err := models.GetArticlePvCount(vUser.Mobile, vUser.Email, dateTime)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			fmt.Println("GetArticlePvCount Err", err)
-			return err
-		}
-		var articleIds string
-		mapArticleIdLabelTotal := make(map[string]int)
-		mapArticleIdPv := make(map[int]int)
-		if len(listArticlePv) > 0 {
-			for _, v := range listArticlePv {
-				articleIds += strconv.Itoa(v.ArticleId) + ","
-				mapArticleIdPv[v.ArticleId] = v.Pv
-			}
-			articleIds = strings.TrimRight(articleIds, ",")
-			//产业、标的标签
-			listLabelName, err := models.GetArticleGroupyIndustryName(articleIds)
-			if err != nil && err.Error() != utils.ErrNoRow() {
-				fmt.Println("GetArticleGroupyIndustryName Err", err)
-				return err
-			}
-			if len(listLabelName) > 0 {
-				for _, v := range listLabelName {
-					labelsIndustryList := strings.Split(v.IndustryName, "/")
-					labelsSubjectList := strings.Split(v.SubjectName, "/")
-					//添加产业统计
-					if len(labelsIndustryList) > 0 {
-						for _, vIn := range labelsIndustryList {
-							if mapActivityLabels[vIn] != "" {
-								mapArticleIdLabelTotal[vIn] += mapArticleIdPv[v.ArticleId]
-							} else {
-								mapArticleIdLabelTotal[vIn] = mapArticleIdPv[v.ArticleId]
-								mapActivityLabels[vIn] = vIn
-							}
-						}
-					}
-					if len(labelsSubjectList) > 0 {
-						//添加标的统计
-						for _, vIn := range labelsSubjectList {
-							if mapActivityLabels[vIn] != "" {
-								mapArticleIdLabelTotal[vIn] += mapArticleIdPv[v.ArticleId]
-							} else {
-								mapArticleIdLabelTotal[vIn] = mapArticleIdPv[v.ArticleId]
-								mapActivityLabels[vIn] = vIn
-							}
-						}
-					}
-				}
-			}
-		}
-		articleIds, err = models.GetCygxArticleCollectId(vUser.UserId, dateTime)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			fmt.Println("GetCygxArticleCollectId Err", err)
-			return err
-		}
-		if articleIds != "" {
-			//产业、标的标签
-			listLabelName, err := models.GetArticleGroupyIndustryName(articleIds)
-			if err != nil && err.Error() != utils.ErrNoRow() {
-				fmt.Println("GetArticleGroupyIndustryName Err", err)
-				return err
-			}
-			if len(listLabelName) > 0 {
-				for _, v := range listLabelName {
-					labelsIndustryList := strings.Split(v.IndustryName, "/")
-					labelsSubjectList := strings.Split(v.SubjectName, "/")
-					//添加产业统计
-					if len(labelsIndustryList) > 0 {
-						for _, vIn := range labelsIndustryList {
-							if mapActivityLabels[vIn] != "" {
-								mapArticleIdLabelTotal[vIn] += 1
-							} else {
-								mapArticleIdLabelTotal[vIn] = 1
-								mapActivityLabels[vIn] = vIn
-							}
-						}
-					}
-					if len(labelsSubjectList) > 0 {
-						//添加标的统计
-						for _, vIn := range labelsSubjectList {
-							if mapActivityLabels[vIn] != "" {
-								mapArticleIdLabelTotal[vIn] += 1
-							} else {
-								mapArticleIdLabelTotal[vIn] = 1
-								mapActivityLabels[vIn] = vIn
-							}
-						}
-					}
-				}
-			}
-		}
-		//活动标签计算
-		listActivityPv, err := models.GetActivitySignCount(vUser.Mobile, dateTime)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			fmt.Println("GetActivitySignCount Err", err)
-			return err
-		}
-		if len(listActivityPv) > 0 {
-			for _, v := range listActivityPv {
-				labelsList := strings.Split(v.Label, "-")
-				for _, v2 := range labelsList {
-					labelsListSon := strings.Split(v2, "/")
-					for _, v3 := range labelsListSon {
-						if mapActivityLabels[v3] != "" {
-							mapArticleIdLabelTotal[v3] += 1
-						} else {
-							mapArticleIdLabelTotal[v3] = 1
-							mapActivityLabels[v3] = v3
-						}
-					}
-				}
-			}
-		}
-		//对标签数量进行排序
-		type KvPair struct {
-			Key string
-			Val int
-		}
-		tmpList := make([]KvPair, 0)
-		for k, v := range mapArticleIdLabelTotal {
-			tmpList = append(tmpList, KvPair{Key: k, Val: v})
-		}
-		sort.Slice(tmpList, func(i, j int) bool {
-			return tmpList[i].Val > tmpList[j].Val // 降序
-		})
-		for _, v := range tmpList {
-			if v.Key != "" {
-				mapLabels[v.Key] = v.Key
-				item := new(models.UserLabel)
-				item.Label = v.Key
-				labelsListStr = append(labelsListStr, item)
-			}
-		}
-		var labelNew string
-		for _, v := range labelsListStr {
-			labelNew += v.Label + ","
-		}
-		labelNew = strings.TrimRight(labelNew, ",")
-		if labelNew != "" {
-			err = models.UpdateUserLabel(labelNew, vUser.UserId)
-			if err != nil {
-				fmt.Println("UpdateUserLabel Err", err)
-				return err
-			}
-		}
-	}
+	//for _, vUser := range listUser {
+	//	labels, err := models.GetCygxCompanyUserListSplit(strconv.Itoa(vUser.UserId))
+	//	if err != nil {
+	//		fmt.Println("GetCygxCompanyUserListSplit Err", err)
+	//		return err
+	//	}
+	//	mapLabels := make(map[string]string)
+	//	var labelsListStr []*models.UserLabel
+	//	mapActivityLabels := make(map[string]string)
+	//	labelsList := strings.Split(labels, ",")
+	//	for _, vL := range labelsList {
+	//		if mapLabels[vL] == "" && vL != "" {
+	//			mapLabels[vL] = vL
+	//			item := new(models.UserLabel)
+	//			item.Label = vL
+	//			labelsListStr = append(labelsListStr, item)
+	//		}
+	//	}
+	//	dateTime := time.Now().AddDate(0, -3, 0).Format(utils.FormatDate)
+	//	listArticlePv, err := models.GetArticlePvCount(vUser.Mobile, vUser.Email, dateTime)
+	//	if err != nil && err.Error() != utils.ErrNoRow() {
+	//		fmt.Println("GetArticlePvCount Err", err)
+	//		return err
+	//	}
+	//	var articleIds string
+	//	mapArticleIdLabelTotal := make(map[string]int)
+	//	mapArticleIdPv := make(map[int]int)
+	//	if len(listArticlePv) > 0 {
+	//		for _, v := range listArticlePv {
+	//			articleIds += strconv.Itoa(v.ArticleId) + ","
+	//			mapArticleIdPv[v.ArticleId] = v.Pv
+	//		}
+	//		articleIds = strings.TrimRight(articleIds, ",")
+	//		//产业、标的标签
+	//		listLabelName, err := models.GetArticleGroupyIndustryName(articleIds)
+	//		if err != nil && err.Error() != utils.ErrNoRow() {
+	//			fmt.Println("GetArticleGroupyIndustryName Err", err)
+	//			return err
+	//		}
+	//		if len(listLabelName) > 0 {
+	//			for _, v := range listLabelName {
+	//				labelsIndustryList := strings.Split(v.IndustryName, "/")
+	//				labelsSubjectList := strings.Split(v.SubjectName, "/")
+	//				//添加产业统计
+	//				if len(labelsIndustryList) > 0 {
+	//					for _, vIn := range labelsIndustryList {
+	//						if mapActivityLabels[vIn] != "" {
+	//							mapArticleIdLabelTotal[vIn] += mapArticleIdPv[v.ArticleId]
+	//						} else {
+	//							mapArticleIdLabelTotal[vIn] = mapArticleIdPv[v.ArticleId]
+	//							mapActivityLabels[vIn] = vIn
+	//						}
+	//					}
+	//				}
+	//				if len(labelsSubjectList) > 0 {
+	//					//添加标的统计
+	//					for _, vIn := range labelsSubjectList {
+	//						if mapActivityLabels[vIn] != "" {
+	//							mapArticleIdLabelTotal[vIn] += mapArticleIdPv[v.ArticleId]
+	//						} else {
+	//							mapArticleIdLabelTotal[vIn] = mapArticleIdPv[v.ArticleId]
+	//							mapActivityLabels[vIn] = vIn
+	//						}
+	//					}
+	//				}
+	//			}
+	//		}
+	//	}
+	//	articleIds, err = models.GetCygxArticleCollectId(vUser.UserId, dateTime)
+	//	if err != nil && err.Error() != utils.ErrNoRow() {
+	//		fmt.Println("GetCygxArticleCollectId Err", err)
+	//		return err
+	//	}
+	//	if articleIds != "" {
+	//		//产业、标的标签
+	//		listLabelName, err := models.GetArticleGroupyIndustryName(articleIds)
+	//		if err != nil && err.Error() != utils.ErrNoRow() {
+	//			fmt.Println("GetArticleGroupyIndustryName Err", err)
+	//			return err
+	//		}
+	//		if len(listLabelName) > 0 {
+	//			for _, v := range listLabelName {
+	//				labelsIndustryList := strings.Split(v.IndustryName, "/")
+	//				labelsSubjectList := strings.Split(v.SubjectName, "/")
+	//				//添加产业统计
+	//				if len(labelsIndustryList) > 0 {
+	//					for _, vIn := range labelsIndustryList {
+	//						if mapActivityLabels[vIn] != "" {
+	//							mapArticleIdLabelTotal[vIn] += 1
+	//						} else {
+	//							mapArticleIdLabelTotal[vIn] = 1
+	//							mapActivityLabels[vIn] = vIn
+	//						}
+	//					}
+	//				}
+	//				if len(labelsSubjectList) > 0 {
+	//					//添加标的统计
+	//					for _, vIn := range labelsSubjectList {
+	//						if mapActivityLabels[vIn] != "" {
+	//							mapArticleIdLabelTotal[vIn] += 1
+	//						} else {
+	//							mapArticleIdLabelTotal[vIn] = 1
+	//							mapActivityLabels[vIn] = vIn
+	//						}
+	//					}
+	//				}
+	//			}
+	//		}
+	//	}
+	//	//活动标签计算
+	//	listActivityPv, err := models.GetActivitySignCount(vUser.Mobile, dateTime)
+	//	if err != nil && err.Error() != utils.ErrNoRow() {
+	//		fmt.Println("GetActivitySignCount Err", err)
+	//		return err
+	//	}
+	//	if len(listActivityPv) > 0 {
+	//		for _, v := range listActivityPv {
+	//			labelsList := strings.Split(v.Label, "-")
+	//			for _, v2 := range labelsList {
+	//				labelsListSon := strings.Split(v2, "/")
+	//				for _, v3 := range labelsListSon {
+	//					if mapActivityLabels[v3] != "" {
+	//						mapArticleIdLabelTotal[v3] += 1
+	//					} else {
+	//						mapArticleIdLabelTotal[v3] = 1
+	//						mapActivityLabels[v3] = v3
+	//					}
+	//				}
+	//			}
+	//		}
+	//	}
+	//	//对标签数量进行排序
+	//	type KvPair struct {
+	//		Key string
+	//		Val int
+	//	}
+	//	tmpList := make([]KvPair, 0)
+	//	for k, v := range mapArticleIdLabelTotal {
+	//		tmpList = append(tmpList, KvPair{Key: k, Val: v})
+	//	}
+	//	sort.Slice(tmpList, func(i, j int) bool {
+	//		return tmpList[i].Val > tmpList[j].Val // 降序
+	//	})
+	//	for _, v := range tmpList {
+	//		if v.Key != "" {
+	//			mapLabels[v.Key] = v.Key
+	//			item := new(models.UserLabel)
+	//			item.Label = v.Key
+	//			labelsListStr = append(labelsListStr, item)
+	//		}
+	//	}
+	//	var labelNew string
+	//	for _, v := range labelsListStr {
+	//		labelNew += v.Label + ","
+	//	}
+	//	labelNew = strings.TrimRight(labelNew, ",")
+	//	if labelNew != "" {
+	//		err = models.UpdateUserLabel(labelNew, vUser.UserId)
+	//		if err != nil {
+	//			fmt.Println("UpdateUserLabel Err", err)
+	//			return err
+	//		}
+	//	}
+	//}
 
 	//处理用户、机构互动量数据
 	{
@@ -754,5 +753,8 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 			}
 		}
 	}
+
+	//更新用户标签以及权重
+	go UpdateUserLabelWeight()
 	return
 }

+ 1 - 0
utils/constants.go

@@ -121,6 +121,7 @@ const (
 
 const (
 	YI_DONG_ZHENG_TONG_YUN_TOKEN_KEY = "YI_DONG_ZHENG_TONG_YUN_TOKEN_KEY" //易董证通云的token,存Redis使用
+	CYGX_USER_KEY_LABEL              = "CYGX_USER_KEY_LABEL"              //查研观向用户标签
 )
 
 const (