Sfoglia il codice sorgente

定时任务更新数据

xingzai 2 anni fa
parent
commit
b86f3a08e7

+ 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_history_record_newpv.go

@@ -158,3 +158,19 @@ func GetArticleHistoryRecordAllList() (items []*CygxArticleHistoryRecordNewpv, e
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+//获取列表信息根据手机号分组
+func GetArticleHistoryRecordAllByMobileList() (items []*CygxArticleHistoryRecordAll, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_article_history_record_all 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
+}

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

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

+ 70 - 2
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
 }
 
@@ -446,3 +448,69 @@ func GetActivitySignCount(mobile, dateTime string) (item []*ActivityLabelCountRe
 	_, err = o.Raw(sql, mobile, dateTime).QueryRows(&item)
 	return
 }
+
+type CygxUserInteractionNum 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:"报告收藏"`
+	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 []*CygxUserInteractionNum, 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_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
+}

+ 62 - 0
services/chart.go

@@ -303,3 +303,65 @@ 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())
+	//		}
+	//	}
+	//}
+
+	//listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList()
+	//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())
+	//			}
+	//		}
+	//	}
+	//}
+
+	fmt.Println("来了老弟")
+}

+ 1 - 1
services/task.go

@@ -76,7 +76,7 @@ func Task() {
 		getArticleListByApi := task.NewTask("getArticleListByApi", "0 */60 * * * *", GetArticleListByApi) //通过三方接口获取策略平台上的文章
 		task.AddTask("getArticleListByApi", getArticleListByApi)
 	}
-
+	DoCompany()
 	//ActivityAttendanceDetail()
 	//SynchronizationArthistory()//同步原有的阅读记录
 	//GetAddpArticle() //同步日度点评数据

+ 58 - 3
services/wx_user.go

@@ -1,7 +1,6 @@
 package services
 
 import (
-	"context"
 	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
@@ -23,8 +22,11 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 	if err != nil {
 		fmt.Println("GetUserRegisterList Err", err)
 	}
-	for _, vUser := range listUser {
-		//fmt.Println(vUser.Mobile)
+	var userIds string
+	var interactionNum int //  互动量
+	mapComapnyInteractionNum := make(map[int]int)
+	for kUser, vUser := range listUser {
+		fmt.Println(vUser.Mobile)
 		labels, err := models.GetCygxCompanyUserListSplit(strconv.Itoa(vUser.UserId))
 		if err != nil {
 			fmt.Println("GetCygxCompanyUserListSplit Err", err)
@@ -194,7 +196,60 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 				return err
 			}
 		}
+		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
+					if interactionNum > 0 {
+						err = models.UpdateUserInteractionNum(interactionNum, int(vsplit.UserId))
+						if err != nil {
+							fmt.Println("UpdateUserInteractionNum Err", err)
+							return err
+						}
+						mapComapnyInteractionNum[vsplit.CompanyId] += interactionNum
+					}
+				}
+			}
+			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)
+		}
+	}
 	return
 }