Browse Source

定时任务更新用户互动数据

xingzai 2 years ago
parent
commit
a3a849f845

+ 16 - 0
models/article_department_follow.go

@@ -55,3 +55,19 @@ func GetArticleDepartmentFollowByUid(userId int) (count int, err error) {
 	err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
 	return
 }
+
+//获取列表信息根据手机号分组
+func GetArticleDepartmentFollowByMobileList() (items []*CygxArticleDepartmentFollow, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_article_department_follow GROUP BY mobile  `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//修改用户阅读的相关信息
+func UpdateCygxArticleDepartmentFollow(wxUser *WxUserItem) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_article_department_follow SET real_name=? WHERE mobile=? `
+	_, err = o.Raw(sql, wxUser.RealName, wxUser.Mobile).Exec()
+	return
+}

+ 2 - 2
models/article_history_record_newpv.go

@@ -160,9 +160,9 @@ func GetArticleHistoryRecordAllList() (items []*CygxArticleHistoryRecordNewpv, e
 }
 
 //获取列表信息根据手机号分组
-func GetArticleHistoryRecordAllByMobileList() (items []*CygxArticleHistoryRecordAll, err error) {
+func GetArticleHistoryRecordAllByMobileList(condition string) (items []*CygxArticleHistoryRecordAll, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM cygx_article_history_record_all GROUP BY mobile  `
+	sql := `SELECT * FROM cygx_article_history_record_all  WHERE 1 = 1 ` + condition + `  GROUP BY mobile   `
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }

+ 3 - 2
models/chart.go

@@ -27,8 +27,9 @@ type Pagination struct {
 }
 
 type ChartInfo struct {
-	ChartInfo *ChartResultApidate `json:"chart_info"`
-	ChartId   int                 `json:"chart_id"`
+	ChartInfo  *ChartResultApidate `json:"chart_info"`
+	ChartId    int                 `json:"chart_id"`
+	CreateDate string              `json:"add_favorites_time"`
 }
 
 type ChartResultApidate struct {

+ 30 - 0
models/chart_collect.go

@@ -86,3 +86,33 @@ func GetChartTopCountByUserId(userId, chartID int) (count int, err error) {
 	err = orm.NewOrm().Raw(sql, userId, chartID).QueryRow(&count)
 	return
 }
+
+func RemoveChartCollectByMobile(mobile string) (err error) {
+	o := orm.NewOrm()
+	sql := `DELETE FROM cygx_chart_collect WHERE mobile IN  (` + mobile + `)`
+	_, err = o.Raw(sql).Exec()
+	return
+}
+
+//批量添加收藏信息
+func AddCygxChartCollectList(items []*CygxChartCollect) (lastId int64, err error) {
+	o := orm.NewOrm()
+	_, err = o.InsertMulti(1, items)
+	return
+}
+
+//获取列表信息根据手机号分组
+func GetCygxChartCollectByMobileList() (items []*CygxChartCollect, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_chart_collect GROUP BY mobile  `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//修改用户收藏文章的相关信息
+func UpdateCygxChartCollect(wxUser *WxUserItem) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_chart_collect SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
+	_, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
+	return
+}

+ 1 - 0
models/db.go

@@ -106,6 +106,7 @@ func init() {
 		new(CygxArticleHistoryRecordAll),
 		new(CygxActivityAppointment),
 		new(UserTemplateRecord),
+		new(CygxUserInteractionNum),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 16 - 0
models/industry_fllow.go

@@ -55,3 +55,19 @@ func GetCountCygxIndustryFllowByUid(userId int) (count int, err error) {
 	err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
 	return
 }
+
+//获取列表信息根据手机号分组
+func GetCygxIndustryFllowList() (items []*CygxIndustryFllow, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_industry_fllow GROUP BY mobile  `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//修改用户阅读的相关信息
+func UpdateCygxIndustryFllow(wxUser *WxUserItem) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_industry_fllow SET real_name=? WHERE mobile=? `
+	_, err = o.Raw(sql, wxUser.RealName, wxUser.Mobile).Exec()
+	return
+}

+ 64 - 0
models/user_interaction_num.go

@@ -0,0 +1,64 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxUserInteractionNum struct {
+	Id                  int       `orm:"column(id);pk"`
+	UserId              int       `description:"用户ID"`
+	ArticleHistoryNum   int       `description:"文章浏览数量"`
+	ArticleCountNum     int       `description:"文章收藏数量"`
+	ChartCountNum       int       `description:"图表收藏"`
+	IndustryFllowNum    int       `description:"产业关注数量"`
+	DepartmentFollowNum int       `description:"作者关注数量"`
+	KeyWordNum          int       `description:"关键词搜索次数"`
+	ActivityOnLineNum   int       `description:"线上活动报名次数"`
+	ActivityOfficeNum   int       `description:"线下活动报名次数"`
+	ActivityNum         int       `description:"活动报名次数"`
+	CreateTime          time.Time `description:"创建时间"`
+	ModifyTime          time.Time `description:"更新时间"`
+}
+
+//添加
+func AddCygxUserInteractionNum(item *CygxUserInteractionNum) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+//修改
+func UpdateCygxUserInteractionNum(item *CygxUserInteractionNum) (err error) {
+	updateParams := make(map[string]interface{})
+	updateParams["UserId"] = item.UserId
+	updateParams["ArticleHistoryNum"] = item.ArticleHistoryNum
+	updateParams["ArticleCountNum"] = item.ArticleCountNum
+	updateParams["ChartCountNum"] = item.ChartCountNum
+	updateParams["IndustryFllowNum"] = item.IndustryFllowNum
+	updateParams["DepartmentFollowNum"] = item.DepartmentFollowNum
+	updateParams["KeyWordNum"] = item.KeyWordNum
+	updateParams["ActivityOnLineNum"] = item.ActivityOnLineNum
+	updateParams["ActivityOfficeNum"] = item.ActivityOfficeNum
+	updateParams["ActivityNum"] = item.ActivityNum
+	updateParams["CreateTime"] = time.Now()
+	updateParams["ModifyTime"] = time.Now()
+	whereParam := map[string]interface{}{"user_id": item.UserId}
+	err = UpdateByExpr(CygxUserInteractionNum{}, whereParam, updateParams)
+	return
+}
+
+//获取列表
+func GetCygxUserInteractionNumList() (items []*CygxUserInteractionNum, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_user_interaction_num   `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//批量添加用户互动信息
+func AddCygxUserInteractionNumList(items []*CygxUserInteractionNum) (lastId int64, err error) {
+	o := orm.NewOrm()
+	_, err = o.InsertMulti(1, items)
+	return
+}

+ 6 - 4
models/wx_user.go

@@ -319,9 +319,9 @@ func GetUserRegisterList() (items []*WxUser, err error) {
 				AND cp.product_id = 2 
 			) 
 			AND u.register_time IS NOT NULL
-			AND cp.product_id = 2 
+			AND cp.product_id = 2
 		GROUP BY
-			u.user_id`
+			u.user_id  `
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
@@ -449,7 +449,7 @@ func GetActivitySignCount(mobile, dateTime string) (item []*ActivityLabelCountRe
 	return
 }
 
-type CygxUserInteractionNum struct {
+type CygxUserInteractionNumDetail struct {
 	UserId              int64  `orm:"column(user_id);pk"`
 	Mobile              string `description:"手机号"`
 	Email               string `description:"邮箱"`
@@ -469,6 +469,7 @@ type CygxUserInteractionNum struct {
 	IsShowSeeNum        int    `description:"是否展示查看"`
 	HistoryNum          int    `description:"报告阅读"`
 	CountNum            int    `description:"报告收藏"`
+	ChartCountNum       int    `description:"图表收藏"`
 	IndustryFllowNum    int    `description:"产业关注"`
 	DepartmentFollowNum int    `description:"作者关注"`
 	KeyWordNum          int    `description:"搜索关键词"`
@@ -479,13 +480,14 @@ type CygxUserInteractionNum struct {
 }
 
 //获取用户的互动量
-func GetCygxCompanyUserUserInteraction(userIds string) (items []*CygxUserInteractionNum, err error) {
+func GetCygxCompanyUserUserInteraction(userIds string) (items []*CygxUserInteractionNumDetail, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
 			u.user_id,
 			u.company_id,
 			( SELECT COUNT( 1 ) FROM cygx_article_history_record_all AS h  INNER JOIN cygx_article  as art  ON  art.article_id = h.article_id  WHERE h.mobile = u.mobile AND h.is_del = 0   AND h.mobile <>'' ) AS history_num,
 			( SELECT COUNT( 1 ) FROM cygx_article_collect AS h WHERE h.user_id = u.user_id  ) AS count_num,
+			( SELECT COUNT( 1 ) FROM cygx_chart_collect AS h WHERE h.user_id = u.user_id  ) AS chart_count_num,
 			( SELECT COUNT( 1 ) FROM cygx_industry_fllow AS h WHERE h.user_id = u.user_id  ) AS industry_fllow_num,
 			( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS h WHERE h.user_id = u.user_id  ) AS department_follow_num,
 			( SELECT COUNT( 1 ) FROM cygx_search_key_word AS h WHERE h.user_id = u.user_id  ) AS key_word_num,

+ 22 - 0
services/article.go

@@ -1092,6 +1092,28 @@ func GetCeLueArticlePv(cont context.Context) (err error) {
 			}
 		}
 	}
+
+	//处理同步过来的阅读记录所属用户
+	var condition string
+	condition = ` AND create_time  > ` + "'" + startTime + "'"
+	listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList(condition)
+	if err != nil {
+		fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
+	}
+	for _, v := range listArticlePv {
+		if v.Mobile != "" {
+			user, err := models.GetWxUserItemByMobile(v.Mobile)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
+			}
+			if user != nil {
+				err = models.UpdateCygxArticleHistoryRecordAll(user)
+				if err != nil {
+					fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
+				}
+			}
+		}
+	}
 	return
 
 }

+ 69 - 4
services/chart.go

@@ -217,7 +217,7 @@ func GetChartCollectionByApi(mobile string, take, skip int) (items []*models.Hom
 		item.ChartId = v.ChartId
 		item.Title = v.ChartInfo.Title
 		item.TitleEn = v.ChartInfo.TitleEn
-		item.CreateDate = v.ChartInfo.CreateDate
+		item.CreateDate = v.CreateDate
 		item.PtagName = v.ChartInfo.Ptag.Name
 		item.CtagName = v.ChartInfo.Ctag.Name
 		item.BodyHtml = v.ChartInfo.Cover
@@ -341,8 +341,10 @@ func DoCompany() {
 	//		}
 	//	}
 	//}
-
-	//listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList()
+	//var condition string
+	//updateTime := time.Now().Add(-time.Hour * 25).Format(utils.FormatDateTime)
+	//condition = ` AND create_time  > ` + "'" + updateTime + "'"
+	//listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList(condition)
 	//if err != nil {
 	//	fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
 	//}
@@ -363,5 +365,68 @@ func DoCompany() {
 	//	}
 	//}
 
-	fmt.Println("来了老弟")
+	//listIndustryFllow, err := models.GetCygxIndustryFllowList()
+	//if err != nil {
+	//	fmt.Println("GetArticleDepartmentFollowByMobileList ,Err" + err.Error())
+	//}
+	//fmt.Println("长度", len(listIndustryFllow))
+	//for k, v := range listIndustryFllow {
+	//	if v.Mobile != "" {
+	//		user, err := models.GetWxUserItemByMobile(v.Mobile)
+	//		if err != nil && err.Error() != utils.ErrNoRow() {
+	//			fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
+	//		}
+	//		if user != nil {
+	//			fmt.Println(user.RealName, k)
+	//			err = models.UpdateCygxIndustryFllow(user)
+	//			if err != nil {
+	//				fmt.Println("UpdateCygxIndustryFllow ,Err" + err.Error())
+	//			}
+	//		}
+	//	}
+	//}
+	//
+	//lisDepartmentF, err := models.GetArticleDepartmentFollowByMobileList()
+	//if err != nil {
+	//	fmt.Println("GetArticleDepartmentFollowByMobileList ,Err" + err.Error())
+	//}
+	//fmt.Println("长度", len(lisDepartmentF))
+	//for k, v := range lisDepartmentF {
+	//	if v.Mobile != "" {
+	//		user, err := models.GetWxUserItemByMobile(v.Mobile)
+	//		if err != nil && err.Error() != utils.ErrNoRow() {
+	//			fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
+	//		}
+	//		if user != nil {
+	//			fmt.Println(user.RealName, k)
+	//			err = models.UpdateCygxArticleDepartmentFollow(user)
+	//			if err != nil {
+	//				fmt.Println("UpdateCygxArticleDepartmentFollow ,Err" + err.Error())
+	//			}
+	//		}
+	//	}
+	//}
+
+	//listChartCollect, err := models.GetCygxChartCollectByMobileList()
+	//if err != nil {
+	//	fmt.Println("GetCygxChartCollectByMobileList ,Err" + err.Error())
+	//}
+	//fmt.Println("长度", len(listChartCollect))
+	//for k, v := range listChartCollect {
+	//	if v.Mobile != "" {
+	//		user, err := models.GetWxUserItemByMobile(v.Mobile)
+	//		if err != nil && err.Error() != utils.ErrNoRow() {
+	//			fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
+	//		}
+	//		if user != nil {
+	//			fmt.Println(user.RealName, k)
+	//			err = models.UpdateCygxChartCollect(user)
+	//			if err != nil {
+	//				fmt.Println("UpdateCygxChartCollect ,Err" + err.Error())
+	//			}
+	//		}
+	//	}
+	//}
+
+	fmt.Println("end")
 }

+ 2 - 1
services/task.go

@@ -66,7 +66,7 @@ func Task() {
 		sendEmailFileForAskMsg := task.NewTask("sendEmailFileForAskMsg", "0 */5 8-22 * * *", SendEmailFileForAskMsg) //非研选系列专家电话会,根据主持人姓名,会前15分钟将问题列表发送给至该主持人对应邮箱
 		task.AddTask("sendEmailFileForAskMsg", sendEmailFileForAskMsg)
 
-		updateWxUserLabel := task.NewTask("updateWxUserLabel", "0 50 3 * * *", UpdateWxUserLabel) //更新用户的标签
+		updateWxUserLabel := task.NewTask("updateWxUserLabel", "0 01 0 * * *", UpdateWxUserLabel) //更新用户的标签
 		task.AddTask("updateWxUserLabel", updateWxUserLabel)
 
 		getCeLueArticlePv := task.NewTask("getCeLueArticlePv", "0 */10 * * * *", GetCeLueArticlePv) //通过三方接口获取策略平台上的阅读记录
@@ -76,6 +76,7 @@ func Task() {
 		getArticleListByApi := task.NewTask("getArticleListByApi", "0 */60 * * * *", GetArticleListByApi) //通过三方接口获取策略平台上的文章
 		task.AddTask("getArticleListByApi", getArticleListByApi)
 	}
+
 	//DoCompany()
 	//ActivityAttendanceDetail()
 	//SynchronizationArthistory()//同步原有的阅读记录

+ 169 - 42
services/wx_user.go

@@ -1,6 +1,7 @@
 package services
 
 import (
+	"context"
 	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
@@ -13,7 +14,7 @@ import (
 func UpdateWxUserLabel(cont context.Context) (err error) {
 	defer func() {
 		if err != nil {
-			go utils.SendAlarmMsg("更新用户标签失败", 2)
+			go utils.SendAlarmMsg("更新用户标签失败;Err:"+err.Error(), 2)
 			go utils.SendEmail("更新用户标签失败"+"【"+utils.APPNAME+"】"+time.Now().Format(utils.FormatDateTime), ";Err:"+err.Error(), utils.EmailSendToUsers)
 			utils.FileLog.Info("更新用户标签失败,Err:%s", err.Error())
 		}
@@ -21,12 +22,75 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 	listUser, err := models.GetUserRegisterList()
 	if err != nil {
 		fmt.Println("GetUserRegisterList Err", err)
+		return err
 	}
 	var userIds string
+
 	var interactionNum int //  互动量
 	mapComapnyInteractionNum := make(map[int]int)
-	for kUser, vUser := range listUser {
-		fmt.Println(vUser.Mobile)
+
+	//拉取策略平台用户同步的图表信息
+	{
+		var chartMobile string
+		var chartItems []*models.CygxChartCollect
+		for k, vUser := range listUser {
+			if vUser.Mobile != "" {
+				mobile := vUser.Mobile
+				chartMobile += mobile + ","
+				listChart, _, _ := GetChartCollectionByApi(mobile, 9999, 0)
+				if len(listChart) > 0 {
+					for _, vChart := range listChart {
+						item := new(models.CygxChartCollect)
+						item.ChartId = vChart.ChartId
+						t1, _ := time.Parse("2006-01-02T15:04:05Z", vChart.CreateDate)
+						item.CreateTime = t1
+						item.Mobile = mobile
+						chartItems = append(chartItems, item)
+					}
+				}
+				fmt.Println(mobile, "长度", len(listChart), "条数", k)
+			}
+		}
+
+		fmt.Println("总长度", len(chartItems))
+		chartMobile = strings.TrimRight(chartMobile, ",")
+		err = models.RemoveChartCollectByMobile(chartMobile)
+		if err != nil {
+			fmt.Println(" RemoveChartCollectByMobile Err", err)
+		}
+		_, err = models.AddCygxChartCollectList(chartItems)
+		if err != nil {
+			fmt.Println(" RemoveChartCollectByMobile Err", err)
+		}
+
+		//处理图表关注后的用户
+		{
+			fmt.Println("处理图表关注后的用户")
+			listChartCollect, err := models.GetCygxChartCollectByMobileList()
+			if err != nil {
+				fmt.Println("GetCygxChartCollectByMobileList ,Err" + err.Error())
+			}
+			fmt.Println("长度", len(listChartCollect))
+			for k, v := range listChartCollect {
+				if v.Mobile != "" {
+					user, err := models.GetWxUserItemByMobile(v.Mobile)
+					if err != nil && err.Error() != utils.ErrNoRow() {
+						fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
+					}
+					if user != nil {
+						fmt.Println(user.RealName, k)
+						err = models.UpdateCygxChartCollect(user)
+						if err != nil {
+							fmt.Println("UpdateCygxChartCollect ,Err" + err.Error())
+						}
+					}
+				}
+			}
+		}
+	}
+
+	// 处理用户标签
+	for _, vUser := range listUser {
 		labels, err := models.GetCygxCompanyUserListSplit(strconv.Itoa(vUser.UserId))
 		if err != nil {
 			fmt.Println("GetCygxCompanyUserListSplit Err", err)
@@ -34,9 +98,7 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 		}
 		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 != "" {
@@ -46,7 +108,6 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 				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() {
@@ -97,7 +158,6 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 				}
 			}
 		}
-
 		articleIds, err = models.GetCygxArticleCollectId(vUser.UserId, dateTime)
 		if err != nil && err.Error() != utils.ErrNoRow() {
 			fmt.Println("GetCygxArticleCollectId Err", err)
@@ -139,7 +199,6 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 				}
 			}
 		}
-
 		//活动标签计算
 		listActivityPv, err := models.GetActivitySignCount(vUser.Mobile, dateTime)
 		if err != nil && err.Error() != utils.ErrNoRow() {
@@ -162,7 +221,6 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 				}
 			}
 		}
-
 		//对标签数量进行排序
 		type KvPair struct {
 			Key string
@@ -183,7 +241,6 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 				labelsListStr = append(labelsListStr, item)
 			}
 		}
-
 		var labelNew string
 		for _, v := range labelsListStr {
 			labelNew += v.Label + ","
@@ -196,18 +253,84 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 				return err
 			}
 		}
-		userIds += strconv.Itoa(vUser.UserId) + ","
-		if kUser%100 == 0 {
-			userIds = strings.TrimRight(userIds, ",")
+	}
+
+	//处理用户、机构互动量数据
+	{
+		var itemsInteraction []*models.CygxUserInteractionNum
+		mapUserInteraction := make(map[int]int)
+		//获取已经处理记录的用户并记录切片
+		listUserInteractionNum, err := models.GetCygxUserInteractionNumList()
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			fmt.Println("GetCygxUserInteractionNumList Err", err)
+			return err
+		}
+		for _, v := range listUserInteractionNum {
+			mapUserInteraction[v.UserId] = v.UserId
+		}
+
+		//处理用户互动量数据
+		for kUser, vUser := range listUser {
+			userIds += strconv.Itoa(vUser.UserId) + ","
+			//一次查询一百个避免用户过多
+			if kUser%100 == 0 {
+				userIds = strings.TrimRight(userIds, ",")
+				userUserInteractionList, err := models.GetCygxCompanyUserUserInteraction(userIds)
+				if err != nil {
+					fmt.Println("GetCygxCompanyUserUserInteraction Err", err)
+					return err
+				}
+				//处理用户的互动量
+				if len(userUserInteractionList) > 0 {
+					for _, vsplit := range userUserInteractionList {
+						interactionNum = vsplit.HistoryNum + vsplit.CountNum + vsplit.IndustryFllowNum + vsplit.DepartmentFollowNum + vsplit.KeyWordNum + vsplit.OnLineNum + vsplit.OfficeNum + vsplit.ChartCountNum
+						if interactionNum > 0 {
+							//更改用户的互动量
+							err = models.UpdateUserInteractionNum(interactionNum, int(vsplit.UserId))
+							if err != nil {
+								fmt.Println("UpdateUserInteractionNum Err", err)
+								return err
+							}
+							mapComapnyInteractionNum[vsplit.CompanyId] += interactionNum
+
+							itemInteraction := new(models.CygxUserInteractionNum)
+							itemInteraction.UserId = int(vsplit.UserId)
+							itemInteraction.ArticleCountNum = vsplit.HistoryNum
+							itemInteraction.ArticleCountNum = vsplit.CountNum
+							itemInteraction.ChartCountNum = vsplit.ChartCountNum
+							itemInteraction.IndustryFllowNum = vsplit.IndustryFllowNum
+							itemInteraction.DepartmentFollowNum = vsplit.DepartmentFollowNum
+							itemInteraction.KeyWordNum = vsplit.KeyWordNum
+							itemInteraction.ActivityOnLineNum = vsplit.OnLineNum
+							itemInteraction.ActivityOfficeNum = vsplit.OfficeNum
+							itemInteraction.ActivityNum = vsplit.OnLineNum + vsplit.OfficeNum
+							itemInteraction.CreateTime = time.Now()
+							itemInteraction.ModifyTime = time.Now()
+							//如果存在就修改不存在就新增
+							if mapUserInteraction[int(vsplit.UserId)] == 0 {
+								itemsInteraction = append(itemsInteraction, itemInteraction)
+							} else {
+								err = models.UpdateCygxUserInteractionNum(itemInteraction)
+							}
+						}
+					}
+				}
+				userIds = ""
+			}
+		}
+
+		userIds = strings.TrimRight(userIds, ",")
+		if userIds != "" {
 			userUserInteractionList, err := models.GetCygxCompanyUserUserInteraction(userIds)
 			if err != nil {
 				fmt.Println("GetCygxCompanyUserUserInteraction Err", err)
 				return err
 			}
+			fmt.Println("处理用户剩余的")
 			//处理用户的互动量
 			if len(userUserInteractionList) > 0 {
 				for _, vsplit := range userUserInteractionList {
-					interactionNum = vsplit.HistoryNum + vsplit.CountNum + vsplit.IndustryFllowNum + vsplit.DepartmentFollowNum + vsplit.KeyWordNum + vsplit.OnLineNum + vsplit.OfficeNum
+					interactionNum = vsplit.HistoryNum + vsplit.CountNum + vsplit.IndustryFllowNum + vsplit.DepartmentFollowNum + vsplit.KeyWordNum + vsplit.OnLineNum + vsplit.OfficeNum + vsplit.ChartCountNum
 					if interactionNum > 0 {
 						err = models.UpdateUserInteractionNum(interactionNum, int(vsplit.UserId))
 						if err != nil {
@@ -215,40 +338,44 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 							return err
 						}
 						mapComapnyInteractionNum[vsplit.CompanyId] += interactionNum
+
+						itemInteraction := new(models.CygxUserInteractionNum)
+						itemInteraction.UserId = int(vsplit.UserId)
+						itemInteraction.ArticleCountNum = vsplit.HistoryNum
+						itemInteraction.ArticleCountNum = vsplit.CountNum
+						itemInteraction.ChartCountNum = vsplit.ChartCountNum
+						itemInteraction.IndustryFllowNum = vsplit.IndustryFllowNum
+						itemInteraction.DepartmentFollowNum = vsplit.DepartmentFollowNum
+						itemInteraction.KeyWordNum = vsplit.KeyWordNum
+						itemInteraction.ActivityOnLineNum = vsplit.OnLineNum
+						itemInteraction.ActivityOfficeNum = vsplit.OfficeNum
+						itemInteraction.ActivityNum = vsplit.OnLineNum + vsplit.OfficeNum
+						itemInteraction.CreateTime = time.Now()
+						itemInteraction.ModifyTime = time.Now()
+						//如果存在就修改不存在就新增
+						if mapUserInteraction[int(vsplit.UserId)] == 0 {
+							itemsInteraction = append(itemsInteraction, itemInteraction)
+						} else {
+							err = models.UpdateCygxUserInteractionNum(itemInteraction)
+						}
 					}
 				}
 			}
-			userIds = ""
-		}
-		//fmt.Println(labelNew)
-	}
-	userIds = strings.TrimRight(userIds, ",")
-	if userIds != "" {
-		userUserInteractionList, err := models.GetCygxCompanyUserUserInteraction(userIds)
-		if err != nil {
-			fmt.Println("GetCygxCompanyUserUserInteraction Err", err)
-			return err
 		}
-		//处理用户的互动量
-		if len(userUserInteractionList) > 0 {
-			for _, vsplit := range userUserInteractionList {
-				interactionNum = vsplit.HistoryNum + vsplit.CountNum + vsplit.IndustryFllowNum + vsplit.DepartmentFollowNum + vsplit.KeyWordNum + vsplit.OnLineNum + vsplit.OfficeNum
-				if interactionNum > 0 {
-					err = models.UpdateUserInteractionNum(interactionNum, int(vsplit.UserId))
-					if err != nil {
-						fmt.Println("UpdateUserInteractionNum Err", err)
-						return err
-					}
-					mapComapnyInteractionNum[vsplit.CompanyId] += interactionNum
-				}
+
+		//修改机构互动量信息
+		if len(mapComapnyInteractionNum) > 0 {
+			for k, v := range mapComapnyInteractionNum {
+				err = models.UpdateComapanyInteractionNum(v, k)
+				fmt.Println(k, "修改", v)
 			}
 		}
-	}
-
-	if len(mapComapnyInteractionNum) > 0 {
-		for k, v := range mapComapnyInteractionNum {
-			err = models.UpdateComapanyInteractionNum(v, k)
-			fmt.Println(k, "修改", v)
+		// 批量添加用户互动量信息
+		if len(itemsInteraction) > 0 {
+			_, err = models.AddCygxUserInteractionNumList(itemsInteraction)
+			if err != nil {
+				fmt.Println(" RemoveChartCollectByMobile Err", err)
+			}
 		}
 	}
 	return