xingzai 2 жил өмнө
parent
commit
92ed888b58

+ 15 - 0
models/article_collect.go

@@ -67,3 +67,18 @@ type ArticleCollectList struct {
 	CategoryName    string `description:"一级分类"`
 	SubCategoryName string `description:"二级分类"`
 }
+
+func GetCygxArticleCollectList() (items []*CygxArticleCollect, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_article_collect GROUP BY user_id  `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//修改用户收藏文章的相关信息
+func UpdateCygxArticleCollect(wxUser *WxUserItem) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_article_collect SET email=?,company_id=?,company_name=?,mobile=?,real_name=? WHERE user_id=? `
+	_, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.Mobile, wxUser.RealName, wxUser.UserId).Exec()
+	return
+}

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

+ 16 - 0
models/article_history_record_newpv.go

@@ -158,3 +158,19 @@ func GetArticleHistoryRecordAllList() (items []*CygxArticleHistoryRecordNewpv, e
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+//获取列表信息根据手机号分组
+func GetArticleHistoryRecordAllByMobileList(condition string) (items []*CygxArticleHistoryRecordAll, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_article_history_record_all  WHERE 1 = 1 ` + condition + `  GROUP BY mobile   `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//修改用户阅读的相关信息
+func UpdateCygxArticleHistoryRecordAll(wxUser *WxUserItem) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_article_history_record_all 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
+}

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

+ 8 - 0
models/company.go

@@ -209,3 +209,11 @@ func GetCompanyByThirdName(tripartiteCompanyCode string) (item *Company, err err
 	err = o.Raw(sql, tripartiteCompanyCode).QueryRow(&item)
 	return
 }
+
+//更新机构互动量
+func UpdateComapanyInteractionNum(interactionNum, companyId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE company SET interaction_num = ? WHERE company_id=? `
+	_, err = o.Raw(sql, interactionNum, companyId).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
+}

+ 15 - 0
models/search_key_word.go

@@ -39,3 +39,18 @@ func GetSearchKeyWordTop() (items []*CygxSearchKeyWord, err error) {
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+func GetCygxSearchKeyWordList() (items []*CygxSearchKeyWord, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_search_key_word GROUP BY user_id  `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//修改用户收藏文章的相关信息
+func UpdateCygxSearchKeyWord(wxUser *WxUserItem) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_search_key_word SET email=?,company_id=?,company_name=?,mobile=?,real_name=? WHERE user_id=? `
+	_, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.Mobile, wxUser.RealName, wxUser.UserId).Exec()
+	return
+}

+ 8 - 0
models/user.go

@@ -455,3 +455,11 @@ func UpdateUserLabel(userLabel string, userId int) (err error) {
 	_, err = o.Raw(sql, userLabel, userId).Exec()
 	return
 }
+
+//更新用户互动量
+func UpdateUserInteractionNum(interactionNum, userId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE wx_user SET interaction_num = ? WHERE user_id=? `
+	_, err = o.Raw(sql, interactionNum, userId).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
+}

+ 74 - 4
models/wx_user.go

@@ -91,6 +91,7 @@ func GetWxUserItemByUnionid(unionid string) (item *WxUserItem, err error) {
 	return
 }
 
+//根据用户ID获取相关信息
 func GetWxUserItemByUserId(userId int) (item *WxUserItem, err error) {
 	sql := `SELECT a.*,b.company_name FROM wx_user AS a
 			LEFT JOIN company AS b on a.company_id=b.company_id
@@ -184,11 +185,12 @@ type WxGetPhoneNumberResp struct {
 	CountryCode     string `description:"区号"`
 }
 
+//根据用户手机号获取相关信息
 func GetWxUserItemByMobile(mobile string) (item *WxUserItem, err error) {
 	sql := `SELECT a.*,b.company_name FROM wx_user AS a
 			LEFT JOIN company AS b on a.company_id=b.company_id
-			WHERE a.mobile=? `
-	err = orm.NewOrm().Raw(sql, mobile).QueryRow(&item)
+			WHERE a.mobile=  '` + mobile + `'  ORDER BY a.company_id DESC LIMIT 1 `
+	err = orm.NewOrm().Raw(sql).QueryRow(&item)
 	return
 }
 
@@ -317,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
 }
@@ -446,3 +448,71 @@ func GetActivitySignCount(mobile, dateTime string) (item []*ActivityLabelCountRe
 	_, err = o.Raw(sql, mobile, dateTime).QueryRows(&item)
 	return
 }
+
+type CygxUserInteractionNumDetail struct {
+	UserId              int64  `orm:"column(user_id);pk"`
+	Mobile              string `description:"手机号"`
+	Email               string `description:"邮箱"`
+	CompanyId           int    `description:"公司id"`
+	CompanyName         string `description:"公司名称"`
+	RealName            string `description:"姓名"`
+	CreatedTime         string `description:"创建时间"`
+	IsMaker             int    `description:"是否决策人,1:是,0:否"`
+	IsRegister          bool   `description:"是否注册,true:已注册,false:未注册"`
+	Status              string `description:"客户状态"`
+	RegisterTime        string `description:"注册时间"`
+	SellerName          string `description:"销售名称"`
+	InteractionNum      int    `description:"互动量"`
+	Labels              string `description:"标签,用英文,隔开"`
+	ActivityLabel       string `description:"活动标签,用英文,隔开"`
+	IsShowSee           bool   `description:"是否展示查看"`
+	IsShowSeeNum        int    `description:"是否展示查看"`
+	HistoryNum          int    `description:"报告阅读"`
+	CountNum            int    `description:"报告收藏"`
+	ChartCountNum       int    `description:"图表收藏"`
+	IndustryFllowNum    int    `description:"产业关注"`
+	DepartmentFollowNum int    `description:"作者关注"`
+	KeyWordNum          int    `description:"搜索关键词"`
+	OnLineNum           int    `description:"线上互动活动"`
+	OfficeNum           int    `description:"线下互动活动"`
+	PackageType         int    `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
+	TryStage            int    `description:"试用客户子标签:0全部、1未分类、2 推进、3 跟踪、4 预备"`
+}
+
+//获取用户的互动量
+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,
+			( SELECT COUNT( 1 ) FROM cygx_activity_signup AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id  INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id   WHERE h.mobile = u.mobile  
+					AND a.is_submit_meeting = 1  AND t.activity_type = 1  AND h.do_fail_type = 0 ) AS on_line_num,
+			( SELECT COUNT( 1 ) FROM cygx_activity_signup AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id  INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id   WHERE h.mobile = u.mobile  
+					AND a.is_submit_meeting = 1  AND t.activity_type = 0 AND h.do_fail_type = 0 ) AS office_num,
+			(
+			SELECT
+				GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR ',' ) 
+			FROM
+				cygx_industrial_management AS man 
+			WHERE
+				man.industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industry_fllow AS f WHERE f.user_id = u.user_id  AND f.type = 1 ) 
+			) AS labels,
+			(
+			SELECT
+				GROUP_CONCAT( DISTINCT man.label SEPARATOR ',' ) 
+			FROM
+				cygx_activity AS man 
+			WHERE
+				man.activity_id IN ( SELECT activity_id FROM cygx_activity_signup AS f WHERE f.user_id = u.user_id  AND label != '') 
+			) AS activity_label
+		FROM
+			wx_user AS u WHERE  u.user_id IN( ` + userIds + `) `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

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

+ 128 - 1
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
@@ -303,3 +303,130 @@ func DeleteCollectionChart(mobile string, chartId int) (err error) {
 	}
 	return
 }
+
+func DoCompany() {
+
+	//listCollect, err := models.GetCygxArticleCollectList()
+	//if err != nil {
+	//	fmt.Println("GetAddCygxArticleCollectList ,Err" + err.Error())
+	//}
+	//for _, v := range listCollect {
+	//	user, err := models.GetWxUserItemByUserId(v.UserId)
+	//	if err != nil && err.Error() != utils.ErrNoRow() {
+	//		fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
+	//	}
+	//	if user != nil {
+	//		fmt.Println(user.RealName)
+	//		err = models.UpdateCygxArticleCollect(user)
+	//		if err != nil {
+	//			fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
+	//		}
+	//	}
+	//}
+
+	//listCollect, err := models.GetCygxSearchKeyWordList()
+	//if err != nil {
+	//	fmt.Println("GetAddCygxArticleCollectList ,Err" + err.Error())
+	//}
+	//for _, v := range listCollect {
+	//	user, err := models.GetWxUserItemByUserId(v.UserId)
+	//	if err != nil && err.Error() != utils.ErrNoRow() {
+	//		fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
+	//	}
+	//	if user != nil {
+	//		fmt.Println(user.RealName)
+	//		err = models.UpdateCygxSearchKeyWord(user)
+	//		if err != nil {
+	//			fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
+	//		}
+	//	}
+	//}
+	//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())
+	//}
+	//fmt.Println("长度", len(listArticlePv))
+	//for k, 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 {
+	//			fmt.Println(user.RealName, k)
+	//			err = models.UpdateCygxArticleHistoryRecordAll(user)
+	//			if err != nil {
+	//				fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
+	//			}
+	//		}
+	//	}
+	//}
+
+	//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) //通过三方接口获取策略平台上的阅读记录
@@ -77,6 +77,7 @@ func Task() {
 		task.AddTask("getArticleListByApi", getArticleListByApi)
 	}
 
+	//DoCompany()
 	//ActivityAttendanceDetail()
 	//SynchronizationArthistory()//同步原有的阅读记录
 	//GetAddpArticle() //同步日度点评数据

+ 192 - 10
services/wx_user.go

@@ -14,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())
 		}
@@ -22,9 +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)
+
+	//拉取策略平台用户同步的图表信息
+	{
+		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 {
-		//fmt.Println(vUser.Mobile)
 		labels, err := models.GetCygxCompanyUserListSplit(strconv.Itoa(vUser.UserId))
 		if err != nil {
 			fmt.Println("GetCygxCompanyUserListSplit Err", err)
@@ -32,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 != "" {
@@ -44,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() {
@@ -95,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)
@@ -137,7 +199,6 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 				}
 			}
 		}
-
 		//活动标签计算
 		listActivityPv, err := models.GetActivitySignCount(vUser.Mobile, dateTime)
 		if err != nil && err.Error() != utils.ErrNoRow() {
@@ -160,7 +221,6 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 				}
 			}
 		}
-
 		//对标签数量进行排序
 		type KvPair struct {
 			Key string
@@ -181,7 +241,6 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 				labelsListStr = append(labelsListStr, item)
 			}
 		}
-
 		var labelNew string
 		for _, v := range labelsListStr {
 			labelNew += v.Label + ","
@@ -194,7 +253,130 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 				return err
 			}
 		}
-		//fmt.Println(labelNew)
+	}
+
+	//处理用户、机构互动量数据
+	{
+		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 + 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)
+						}
+					}
+				}
+			}
+		}
+
+		//修改机构互动量信息
+		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
 }