Browse Source

no message

xingzai 9 months ago
parent
commit
6ecd12e9e1
2 changed files with 488 additions and 1 deletions
  1. 258 0
      models/user_interaction_num.go
  2. 230 1
      services/wx_user.go

+ 258 - 0
models/user_interaction_num.go

@@ -1,7 +1,9 @@
 package models
 
 import (
+	"fmt"
 	"github.com/beego/beego/v2/client/orm"
+	"hongze/hongze_cygx/utils"
 	"time"
 )
 
@@ -74,3 +76,259 @@ func AddCygxUserInteractionNumList(items []*CygxUserInteractionNum) (lastId int6
 	_, err = o.InsertMulti(1, items)
 	return
 }
+
+// 联系人互动数量
+type CygxUserInteractionNumResp struct {
+	UserId         int `description:"用户ID"`
+	CompanyId      int `description:"公司ID"`
+	InteractionNum int `description:"互动数量"`
+}
+
+// 用户阅读记录数量统计
+func GetCygxArticleHistoryRecordInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
+	o := orm.NewOrm()
+	var sql string
+	sql += ` SELECT
+			COUNT( 1 ) AS interaction_num,
+			w.user_id,
+			w.company_id 
+		FROM
+			cygx_article_history_record_all AS h
+			INNER JOIN cygx_article AS art ON art.article_id = h.article_id
+			INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id  WHERE 1=1  ` + condition + ` GROUP BY w.user_id `
+	databaseName := utils.GetWeeklyDatabase()
+	sql = fmt.Sprintf(sql, databaseName)
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+// 用户收藏文章数量统计
+func GetCygxArticleCollectInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
+	o := orm.NewOrm()
+	var sql string
+	sql += ` SELECT
+			COUNT( 1 ) AS interaction_num,
+			w.user_id,
+			w.company_id 
+		FROM
+			cygx_article_collect AS h
+			INNER JOIN cygx_article AS art ON art.article_id = h.article_id
+			INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id  WHERE 1=1  ` + condition + ` GROUP BY w.user_id `
+	databaseName := utils.GetWeeklyDatabase()
+	sql = fmt.Sprintf(sql, databaseName)
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+// 用户收藏图表数量统计
+func GetCygxChartCollectInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
+	o := orm.NewOrm()
+	var sql string
+	sql += ` SELECT
+			COUNT( 1 ) AS interaction_num,
+			w.user_id,
+			w.company_id 
+		FROM
+			cygx_chart_collect AS h
+			INNER JOIN cygx_chart_all AS art ON art.chart_id = h.chart_id
+			INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id  WHERE 1=1  ` + condition + ` GROUP BY w.user_id `
+	databaseName := utils.GetWeeklyDatabase()
+	sql = fmt.Sprintf(sql, databaseName)
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+// 用户关注产业数量统计
+func GetCygxIndustryFllowInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
+	o := orm.NewOrm()
+	var sql string
+	sql += ` SELECT
+			COUNT( 1 ) AS interaction_num,
+			w.user_id,
+			w.company_id 
+		FROM
+			cygx_industry_fllow AS h
+			INNER JOIN cygx_industrial_management AS art ON art.industrial_management_id = h.industrial_management_id
+			INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id  WHERE 1=1  AND h.type = 1  AND  h.source   IN (0,1,2) ` + condition + ` GROUP BY w.user_id `
+	databaseName := utils.GetWeeklyDatabase()
+	sql = fmt.Sprintf(sql, databaseName)
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+// 用户搜索关键词数量统计
+func GetCygxSearchKeyWordInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
+	o := orm.NewOrm()
+	var sql string
+	sql += ` SELECT
+			COUNT( 1 ) AS interaction_num,
+			w.user_id,
+			w.company_id 
+		FROM
+			cygx_search_key_word AS h
+			INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id  WHERE 1=1  ` + condition + ` GROUP BY w.user_id `
+	databaseName := utils.GetWeeklyDatabase()
+	sql = fmt.Sprintf(sql, databaseName)
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+// 用户活动报名参会数量统计
+func GetCygxActivitySignupInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
+	o := orm.NewOrm()
+	var sql string
+	sql += ` SELECT
+			COUNT( 1 ) AS interaction_num,
+			w.user_id,
+			w.company_id 
+		FROM
+			cygx_activity_signup_detail AS h
+			INNER JOIN cygx_activity AS art ON art.activity_id = h.activity_id
+			INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id  WHERE 1=1  ` + condition + ` GROUP BY w.user_id `
+	databaseName := utils.GetWeeklyDatabase()
+	sql = fmt.Sprintf(sql, databaseName)
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+// 用户专项调研活动报名参会数量统计
+func GetCygxActivitySpecialSignupInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
+	o := orm.NewOrm()
+	var sql string
+	sql += ` SELECT
+			COUNT( 1 ) AS interaction_num,
+			w.user_id,
+			w.company_id 
+		FROM
+			cygx_activity_special_meeting_detail AS h
+			INNER JOIN cygx_activity_special AS art ON art.activity_id = h.activity_id
+			INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id  WHERE 1=1  ` + condition + ` GROUP BY w.user_id `
+	databaseName := utils.GetWeeklyDatabase()
+	sql = fmt.Sprintf(sql, databaseName)
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+// 用户路演精华播放数量统计
+func GetCygxMicroRoadshowVideoHistoryInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
+	o := orm.NewOrm()
+	var sql string
+	sql += ` SELECT
+			COUNT( 1 ) AS interaction_num,
+			w.user_id,
+			w.company_id 
+		FROM
+			cygx_micro_roadshow_video_history AS h
+			INNER JOIN cygx_micro_roadshow_video AS art ON art.video_id = h.video_id
+			INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id  WHERE 1=1  ` + condition + ` GROUP BY w.user_id `
+	databaseName := utils.GetWeeklyDatabase()
+	sql = fmt.Sprintf(sql, databaseName)
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+// 用户活动视频播放数量统计
+func GetCygxActivityVideoHistoryInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
+	o := orm.NewOrm()
+	var sql string
+	sql += ` SELECT
+			COUNT( 1 ) AS interaction_num,
+			w.user_id,
+			w.company_id 
+		FROM
+			cygx_activity_video_history AS h
+			INNER JOIN cygx_activity_video AS art ON art.activity_id = h.activity_id
+			INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id  WHERE 1=1  ` + condition + ` GROUP BY w.user_id `
+	databaseName := utils.GetWeeklyDatabase()
+	sql = fmt.Sprintf(sql, databaseName)
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+// 用户活动音频播放数量统计
+func GetCygxActivityVoiceHistoryInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
+	o := orm.NewOrm()
+	var sql string
+	sql += ` SELECT
+			COUNT( 1 ) AS interaction_num,
+			w.user_id,
+			w.company_id 
+		FROM
+			cygx_activity_voice_history AS h
+			INNER JOIN cygx_activity_voice AS art ON art.activity_id = h.activity_id
+			INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id  WHERE 1=1  ` + condition + ` GROUP BY w.user_id `
+	databaseName := utils.GetWeeklyDatabase()
+	sql = fmt.Sprintf(sql, databaseName)
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+// 用户首页标签点击量数量统计
+func GetCygxTagHistoryInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
+	o := orm.NewOrm()
+	var sql string
+	sql += ` SELECT
+			COUNT( 1 ) AS interaction_num,
+			w.user_id,
+			w.company_id 
+		FROM
+			cygx_tag_history AS h
+			INNER JOIN cygx_tag AS art ON art.tag_id = h.tag_id
+			INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id  WHERE 1=1  ` + condition + ` GROUP BY w.user_id `
+	databaseName := utils.GetWeeklyDatabase()
+	sql = fmt.Sprintf(sql, databaseName)
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+// 用户关注研选作者数量统计
+func GetCygxArticleDepartmentFollowInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
+	o := orm.NewOrm()
+	var sql string
+	sql += ` SELECT
+			COUNT( 1 ) AS interaction_num,
+			w.user_id,
+			w.company_id 
+		FROM
+			cygx_article_department_follow AS h
+			INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id  WHERE 1=1  ` + condition + ` GROUP BY w.user_id `
+	databaseName := utils.GetWeeklyDatabase()
+	sql = fmt.Sprintf(sql, databaseName)
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+// 用户关注研选专栏作者数量统计
+func GetCygxYanxuanSpecialFollowInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
+	o := orm.NewOrm()
+	var sql string
+	sql += ` SELECT
+			COUNT( 1 ) AS interaction_num,
+			w.user_id,
+			w.company_id 
+		FROM
+			cygx_yanxuan_special_follow AS h
+			INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id  WHERE 1=1  ` + condition + ` GROUP BY w.user_id `
+	databaseName := utils.GetWeeklyDatabase()
+	sql = fmt.Sprintf(sql, databaseName)
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+// 用户研选专栏阅读数量数量统计
+func GetCygxYanxuanSpecialRecordInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
+	o := orm.NewOrm()
+	var sql string
+	sql += ` SELECT
+			COUNT( 1 ) AS interaction_num,
+			w.user_id,
+			w.company_id 
+		FROM
+			cygx_yanxuan_special_record AS h
+			INNER JOIN cygx_yanxuan_special AS art ON art.id = h.yanxuan_special_id
+			INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id  WHERE 1=1  ` + condition + ` GROUP BY w.user_id `
+	databaseName := utils.GetWeeklyDatabase()
+	sql = fmt.Sprintf(sql, databaseName)
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 230 - 1
services/wx_user.go

@@ -2,6 +2,7 @@ package services
 
 import (
 	"context"
+	"errors"
 	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
@@ -780,7 +781,7 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 	}
 
 	//更新用户标签以及权重
-	go UpdateUserLabelWeight()
+	//go UpdateUserLabelWeight()
 	return
 }
 
@@ -1057,3 +1058,231 @@ func init123123() {
 		}
 	}
 }
+
+func init() {
+	UpdateWxUserLabelNew()
+}
+
+// func UpdateWxUserLabelNew(cont context.Context) (err error) {
+func UpdateWxUserLabelNew() (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("更新用户标签失败UpdateWxUserLabel, err:", err.Error()), 2)
+		}
+	}()
+
+	mapComapnyInteractionNum := make(map[int]int)
+
+	var condition string
+	condition = ` AND h.create_time < '%s' `
+	condition = fmt.Sprintf(condition, time.Now().Format(utils.FormatDate)) // 截止昨天的所有数据
+
+	//fmt.Println(condition)
+	//报告阅读记录
+	//{
+	//	listArticleHistoryRecord, e := models.GetCygxArticleHistoryRecordInteractionNum(condition)
+	//	if e != nil {
+	//		err = errors.New("GetCygxArticleHistoryRecordInteractionNum, Err: " + e.Error())
+	//		return
+	//	}
+	//	for _, v := range listArticleHistoryRecord {
+	//		mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
+	//	}
+	//}
+
+	//报告收藏记录
+	{
+		listArticleCollect, e := models.GetCygxArticleCollectInteractionNum(condition)
+		if e != nil {
+			err = errors.New("GetCygxArticleCollectInteractionNum, Err: " + e.Error())
+			return
+		}
+		for _, v := range listArticleCollect {
+			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
+		}
+	}
+
+	//图表收藏记录
+	{
+		listChartCollect, e := models.GetCygxChartCollectInteractionNum(condition)
+		if e != nil {
+			err = errors.New("GetCygxChartCollectInteractionNum, Err: " + e.Error())
+			return
+		}
+		for _, v := range listChartCollect {
+			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
+		}
+	}
+
+	//图表收藏记录
+	{
+		listChartCollect, e := models.GetCygxChartCollectInteractionNum(condition)
+		if e != nil {
+			err = errors.New("GetCygxChartCollectInteractionNum, Err: " + e.Error())
+			return
+		}
+		for _, v := range listChartCollect {
+			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
+		}
+	}
+
+	//用户关注产业数量
+	{
+		listIndustryFllow, e := models.GetCygxIndustryFllowInteractionNum(condition)
+		if e != nil {
+			err = errors.New("GetCygxIndustryFllowInteractionNum, Err: " + e.Error())
+			return
+		}
+		for _, v := range listIndustryFllow {
+			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
+		}
+	}
+
+	//用户搜索关键词数量
+	{
+		listSearchKeyWord, e := models.GetCygxSearchKeyWordInteractionNum(condition)
+		if e != nil {
+			err = errors.New("GetCygxSearchKeyWordInteractionNum, Err: " + e.Error())
+			return
+		}
+		for _, v := range listSearchKeyWord {
+			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
+		}
+	}
+
+	//用户活动报名参会数量
+	{
+		listActivitySignup, e := models.GetCygxActivitySignupInteractionNum(condition)
+		if e != nil {
+			err = errors.New("GetCygxActivitySignupInteractionNum, Err: " + e.Error())
+			return
+		}
+		for _, v := range listActivitySignup {
+			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
+		}
+	}
+
+	//用户专项调研活动报名参会数量
+	{
+		listActivitySpecialSignup, e := models.GetCygxActivitySpecialSignupInteractionNum(condition)
+		if e != nil {
+			err = errors.New("GetCygxActivitySpecialSignupInteractionNum, Err: " + e.Error())
+			return
+		}
+		for _, v := range listActivitySpecialSignup {
+			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
+		}
+	}
+
+	//用户专项调研活动报名参会数量
+	{
+		listActivitySpecialSignup, e := models.GetCygxActivitySpecialSignupInteractionNum(condition)
+		if e != nil {
+			err = errors.New("GetCygxActivitySpecialSignupInteractionNum, Err: " + e.Error())
+			return
+		}
+		for _, v := range listActivitySpecialSignup {
+			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
+		}
+	}
+
+	//用户路演精华播放数量
+	{
+		listMicroRoadshowVideoHistory, e := models.GetCygxMicroRoadshowVideoHistoryInteractionNum(condition)
+		if e != nil {
+			err = errors.New("GetCygxMicroRoadshowVideoHistoryInteractionNum, Err: " + e.Error())
+			return
+		}
+		for _, v := range listMicroRoadshowVideoHistory {
+			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
+		}
+	}
+
+	//用户活动视频播放数量
+	{
+		listActivityVideoHistory, e := models.GetCygxActivityVideoHistoryInteractionNum(condition)
+		if e != nil {
+			err = errors.New("GetCygxActivityVideoHistoryInteractionNum, Err: " + e.Error())
+			return
+		}
+		for _, v := range listActivityVideoHistory {
+			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
+		}
+	}
+
+	//用户活动音频播放数量
+	{
+		listActivityVoiceHistory, e := models.GetCygxActivityVoiceHistoryInteractionNum(condition)
+		if e != nil {
+			err = errors.New("GetCygxActivityVoiceHistoryInteractionNum, Err: " + e.Error())
+			return
+		}
+		for _, v := range listActivityVoiceHistory {
+			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
+		}
+	}
+
+	//用户首页标签点击量数量
+	{
+		listTagHistory, e := models.GetCygxTagHistoryInteractionNum(condition)
+		if e != nil {
+			err = errors.New("GetCygxTagHistoryInteractionNum, Err: " + e.Error())
+			return
+		}
+		for _, v := range listTagHistory {
+			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
+		}
+	}
+
+	//用户关注研选作者数量
+	{
+		listArticleDepartmentFollow, e := models.GetCygxArticleDepartmentFollowInteractionNum(condition)
+		if e != nil {
+			err = errors.New("GetCygxArticleDepartmentFollowInteractionNum, Err: " + e.Error())
+			return
+		}
+		for _, v := range listArticleDepartmentFollow {
+			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
+		}
+	}
+
+	//用户关注研选专栏作者数量
+	{
+		listYanxuanSpecialFollow, e := models.GetCygxYanxuanSpecialFollowInteractionNum(condition)
+		if e != nil {
+			err = errors.New("GetCygxYanxuanSpecialFollowInteractionNum, Err: " + e.Error())
+			return
+		}
+		for _, v := range listYanxuanSpecialFollow {
+			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
+		}
+	}
+
+	//用户关注研选专栏作者数量
+	{
+		listYanxuanSpecialFollow, e := models.GetCygxYanxuanSpecialFollowInteractionNum(condition)
+		if e != nil {
+			err = errors.New("GetCygxYanxuanSpecialFollowInteractionNum, Err: " + e.Error())
+			return
+		}
+		for _, v := range listYanxuanSpecialFollow {
+			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
+		}
+	}
+
+	//用户研选专栏阅读数量数量
+	{
+		listYanxuanSpecialFollow, e := models.GetCygxYanxuanSpecialRecordInteractionNum(condition)
+		if e != nil {
+			err = errors.New("GetCygxYanxuanSpecialRecordInteractionNum, Err: " + e.Error())
+			return
+		}
+		for _, v := range listYanxuanSpecialFollow {
+			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
+		}
+	}
+
+	fmt.Println(mapComapnyInteractionNum)
+	return
+}