|
@@ -14,17 +14,258 @@ 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())
|
|
|
}
|
|
|
}()
|
|
|
+ //获取需要处理的权益客户
|
|
|
listUser, err := models.GetUserRegisterList()
|
|
|
if err != nil {
|
|
|
fmt.Println("GetUserRegisterList Err", err)
|
|
|
+ return err
|
|
|
}
|
|
|
+
|
|
|
+ mapChartCollect := make(map[string]int)
|
|
|
+ //获取已经处理记录的用户并记录切片
|
|
|
+ listChartCollectL, err := models.GetCygxChartCollectList()
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ fmt.Println("GetCygxUserInteractionNumList Err", err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ for _, v := range listChartCollectL {
|
|
|
+ mapChartCollect[fmt.Sprint("m:", v.Mobile, "u:", v.ChartId)] = v.UserId
|
|
|
+ }
|
|
|
+
|
|
|
+ var interactionNum int // 互动量
|
|
|
+ mapComapnyInteractionNum := make(map[int]int)
|
|
|
+
|
|
|
+ //拉取策略平台用户同步的图表信息
|
|
|
+
|
|
|
+ {
|
|
|
+ var chartMobile string
|
|
|
+ var chartItems []*models.CygxChartCollect
|
|
|
+
|
|
|
+ if utils.RunMode == "release" {
|
|
|
+ for k, vUser := range listUser {
|
|
|
+ if vUser.Mobile != "" {
|
|
|
+ mobile := vUser.Mobile
|
|
|
+ fmt.Println(vUser.Mobile, "_", k)
|
|
|
+ chartMobile += mobile + ","
|
|
|
+ listChart, _, _ := GetChartCollectionByApi(mobile, 9999, 0)
|
|
|
+ if len(listChart) > 0 {
|
|
|
+ for _, vChart := range listChart {
|
|
|
+ if mapChartCollect[fmt.Sprint("m:", mobile, "u:", vChart.ChartId)] == 0 {
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //如果有数据就添加
|
|
|
+ if len(chartItems) > 0 {
|
|
|
+ _, err = models.AddCygxChartCollectList(chartItems)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(" RemoveChartCollectByMobile Err", err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理图表关注后的用户
|
|
|
+ {
|
|
|
+
|
|
|
+ listChartCollect, err := models.GetCygxChartCollectByMobileList()
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("GetCygxChartCollectByMobileList ,Err" + err.Error())
|
|
|
+ }
|
|
|
+ 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())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理 前一天移动之后的用户的公司记录信息
|
|
|
+ {
|
|
|
+ updateTime := time.Now().Add(-time.Hour * 25).Format("2006-01-02 15:04:05")
|
|
|
+ listUpdateUser, err := models.GetWxUserOpLogList(updateTime)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ var userIds string
|
|
|
+ var mobiles string
|
|
|
+ if len(listUpdateUser) > 0 {
|
|
|
+ for _, v := range listUpdateUser {
|
|
|
+ userIds += strconv.Itoa(v.UserId) + ","
|
|
|
+ mobiles += "'" + v.Mobile + "',"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ userIds = strings.TrimRight(userIds, ",")
|
|
|
+ mobiles = strings.TrimRight(mobiles, ",")
|
|
|
+
|
|
|
+ //如果用户ID不为空那么就处理这些用户的记录信息
|
|
|
+ if userIds != "" {
|
|
|
+ var condition string
|
|
|
+ condition = ` AND user_id IN (` + userIds + `)`
|
|
|
+
|
|
|
+ //处理用户的文章收藏
|
|
|
+ listCollect, err := models.GetCygxArticleCollectList(condition)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ fmt.Println("GetAddCygxArticleCollectList ,Err" + err.Error())
|
|
|
+ }
|
|
|
+ if len(listCollect) > 0 {
|
|
|
+ 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())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //处理用户的文章收藏 end
|
|
|
+
|
|
|
+ //修改用户关注的产业
|
|
|
+ listIndustryFllow, err := models.GetCygxIndustryFllowList(condition)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("GetCygxIndustryFllowList ,Err" + err.Error())
|
|
|
+ }
|
|
|
+ for k, v := range listIndustryFllow {
|
|
|
+ if v.Mobile != "" {
|
|
|
+ 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, k)
|
|
|
+ err = models.UpdateCygxIndustryFllow(user)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("UpdateCygxIndustryFllow ,Err" + err.Error())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改用户产业关注的产业end
|
|
|
+
|
|
|
+ //修改用户的阅读记录
|
|
|
+ listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList(condition)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
|
|
|
+ }
|
|
|
+ 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())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //修改用户的阅读记录end
|
|
|
+
|
|
|
+ //处理用户的搜索记录
|
|
|
+ listSearch, err := models.GetCygxSearchKeyWordList(condition)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
|
|
|
+ }
|
|
|
+
|
|
|
+ for k, v := range listSearch {
|
|
|
+ if v.Mobile != "" {
|
|
|
+ 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, k)
|
|
|
+ err = models.UpdateCygxSearchKeyWord(user)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("UpdateCygxSearchKeyWord ,Err" + err.Error())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理用户的作者关注
|
|
|
+ lisDepartmentF, err := models.GetArticleDepartmentFollowByMobileList(condition)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("GetArticleDepartmentFollowByMobileList ,Err" + err.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ for k, v := range lisDepartmentF {
|
|
|
+ if v.Mobile != "" {
|
|
|
+ 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, k)
|
|
|
+ err = models.UpdateCygxArticleDepartmentFollow(user)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("UpdateCygxArticleDepartmentFollow ,Err" + err.Error())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 处理用户的作者关注end
|
|
|
+
|
|
|
+ //如果手机号不为空,则更新用户的报名信息
|
|
|
+ if mobiles != "" {
|
|
|
+ condition = ` AND mobile IN (` + mobiles + `)`
|
|
|
+ listSingUp, err := models.GetCygxActivitySignupByMobileList(condition)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("GetCygxChartCollectByMobileList ,Err" + err.Error())
|
|
|
+ }
|
|
|
+ //fmt.Println("更新用户的报名信息长度", len(listSingUp))
|
|
|
+ for _, v := range listSingUp {
|
|
|
+ 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.UpdateCygxActivitySignup(user)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("UpdateCygxActivitySignup ,Err" + err.Error())
|
|
|
+ //return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理用户标签
|
|
|
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 +273,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 +283,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 +333,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 +374,6 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
//活动标签计算
|
|
|
listActivityPv, err := models.GetActivitySignCount(vUser.Mobile, dateTime)
|
|
|
if err != nil && err.Error() != utils.ErrNoRow() {
|
|
@@ -160,7 +396,6 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
//对标签数量进行排序
|
|
|
type KvPair struct {
|
|
|
Key string
|
|
@@ -181,7 +416,6 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
|
|
|
labelsListStr = append(labelsListStr, item)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
var labelNew string
|
|
|
for _, v := range labelsListStr {
|
|
|
labelNew += v.Label + ","
|
|
@@ -194,7 +428,140 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
- //fmt.Println(labelNew)
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理用户、机构互动量数据
|
|
|
+ {
|
|
|
+ var userIds string
|
|
|
+ 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.ArticleHistoryNum = 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 err != nil {
|
|
|
+ fmt.Println("UpdateCygxUserInteractionNum Err", err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ fmt.Println(itemInteraction.UserId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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.ArticleHistoryNum = 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 err != nil {
|
|
|
+ fmt.Println("UpdateCygxUserInteractionNum Err", err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ fmt.Println(itemInteraction.UserId)
|
|
|
+ err = models.UpdateCygxUserInteractionNum(itemInteraction)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ////修改机构互动量信息
|
|
|
+ if len(mapComapnyInteractionNum) > 0 {
|
|
|
+ for k, v := range mapComapnyInteractionNum {
|
|
|
+ err = models.UpdateComapanyInteractionNum(v, k)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 批量添加用户互动量信息
|
|
|
+ if len(itemsInteraction) > 0 {
|
|
|
+ _, err = models.AddCygxUserInteractionNumList(itemsInteraction)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(" RemoveChartCollectByMobile Err", err)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
return
|
|
|
}
|