Browse Source

no message

xingzai 1 year ago
parent
commit
7b705469ec
3 changed files with 127 additions and 2 deletions
  1. 1 1
      models/cygx_yanxuan_special_record.go
  2. 125 0
      services/article_history.go
  3. 1 1
      services/task.go

+ 1 - 1
models/cygx_yanxuan_special_record.go

@@ -50,7 +50,7 @@ type AddCygxYanxuanSpecialRecordReq struct {
 
 // 获取数量
 func GetCygxYanxuanSpecialRecordCount(condition string, pars []interface{}) (count int, err error) {
-	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_yanxuan_special_record as a  WHERE 1= 1  `
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_yanxuan_special_record as art  WHERE 1= 1  `
 	if condition != "" {
 		sqlCount += condition
 	}

+ 125 - 0
services/article_history.go

@@ -1,6 +1,7 @@
 package services
 
 import (
+	"context"
 	"errors"
 	"fmt"
 	"hongze/hongze_cygx/models"
@@ -148,3 +149,127 @@ func ArticleHistoryStopTime(articleId, stopTime, outType int, user *models.WxUse
 	go ArticleHistoryUserLabelLogAdd(articleId, uid)
 	return
 }
+
+//func init() {
+//	AddAllArticleAndYanxuanHistory()
+//}
+
+// 定时任务更新文章和研选专栏记录
+func AddAllArticleAndYanxuanHistory(cont context.Context) (err error) {
+	//func AddAllArticleAndYanxuanHistory() (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("同步阅读记录到es失败;AddAllArticleHistory Err:"+err.Error(), 2)
+		}
+	}()
+
+	var pars []interface{}
+	var condition string
+
+	var companyIds []int
+	condition = " AND  product_id = 2  AND STATUS IN ( '正式', '试用', '冻结' ) "
+	list, e := models.GetCompanyProductList(condition, pars)
+	if e != nil {
+		err = errors.New("GetCompanyProductList, Err: " + e.Error())
+		return
+	}
+
+	for _, v := range list {
+		companyIds = append(companyIds, v.CompanyId)
+	}
+
+	//添加文章记录
+	{
+		condition = ""
+		pars = make([]interface{}, 0)
+		condition = " AND art.company_id IN (" + utils.GetOrmInReplace(len(companyIds)) + ") AND   art.is_del = 0  AND art.create_time >= ?   AND art.create_time <= ?  "
+		pars = append(pars, companyIds, time.Now().AddDate(0, 0, -1).Format(utils.FormatDate), time.Now().Format(utils.FormatDate))
+		total, e := models.GetCygxArticleHistoryRecordAllCountBycondition(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxArticleHistoryRecordAllCount, Err: " + e.Error())
+			return
+		}
+		for i := 0; i <= total/2000; i++ {
+			allList, e := models.GetCygxArticleHistoryRecordAllList(condition, pars, 2000*i, 2000)
+			if e != nil {
+				err = errors.New("GetCygxArticleHistoryRecordAllList, Err: " + e.Error())
+				return
+			}
+			var items []*models.CygxArticleAndYanxuanRecord
+			for _, v := range allList {
+				item := new(models.CygxArticleAndYanxuanRecord)
+				item.SourceId = v.ArticleId
+				item.Source = utils.CYGX_OBJ_ARTICLE
+				item.UserId = v.UserId
+				item.RealName = v.RealName
+				item.Mobile = v.Mobile
+				item.Email = v.Email
+				item.CompanyId = v.CompanyId
+				item.CompanyName = v.CompanyName
+				item.CompanyId = v.CompanyId
+				item.CreateTime = v.CreateTime
+				item.ModifyTime = v.ModifyTime
+				item.StopTime = v.StopTime
+				if v.Source == "CELUE" {
+					item.RegisterPlatform = 3
+				} else if v.Source == "WEB" {
+					item.RegisterPlatform = 2
+				} else {
+					item.RegisterPlatform = 1
+				}
+				items = append(items, item)
+			}
+			e = models.AddCygxArticleAndYanxuanRecordMulti(items)
+			if e != nil {
+				err = errors.New("AddCygxArticleAndYanxuanRecordMulti, Err: " + e.Error())
+				return
+			}
+		}
+	}
+
+	//添加研选专栏记录
+	{
+		condition = ""
+		pars = make([]interface{}, 0)
+		condition = " AND   art.create_time >= ?   AND art.create_time <= ?   AND  user_id > 0 "
+		pars = append(pars, time.Now().AddDate(0, 0, -1).Format(utils.FormatDate), time.Now().Format(utils.FormatDate))
+		totalYanxuanSpecial, e := models.GetCygxYanxuanSpecialRecordCount(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxYanxuanSpecialRecordCount, Err: " + e.Error())
+			return
+		}
+		for i := 0; i <= totalYanxuanSpecial/2000; i++ {
+			listYanxuanSpecialRecord, e := models.GetCygxYanxuanSpecialRecordRespList(condition, pars, 2000*i, 2000)
+			if e != nil {
+				err = errors.New("GetCygxYanxuanSpecialRecordRespList, Err: " + e.Error())
+				return
+			}
+			var items []*models.CygxArticleAndYanxuanRecord
+			for _, v := range listYanxuanSpecialRecord {
+				item := new(models.CygxArticleAndYanxuanRecord)
+				item.SourceId = v.YanxuanSpecialId
+				item.Source = utils.CYGX_OBJ_YANXUANSPECIAL
+				item.UserId = v.UserId
+				item.RealName = v.RealName
+				item.Mobile = v.Mobile
+				item.Email = v.Email
+				item.CompanyId = v.CompanyId
+				item.CompanyName = v.CompanyName
+				item.CompanyId = v.CompanyId
+				item.CreateTime = v.CreateTime
+				item.ModifyTime = v.ModifyTime
+				item.StopTime = v.StopTime
+				item.RegisterPlatform = v.RegisterPlatform
+				items = append(items, item)
+			}
+			e = models.AddCygxArticleAndYanxuanRecordMulti(items)
+			if e != nil {
+				err = errors.New("AddCygxArticleAndYanxuanRecordMulti, Err: " + e.Error())
+				return
+			}
+		}
+	}
+
+	return
+}

+ 1 - 1
services/task.go

@@ -84,7 +84,7 @@ func Task() {
 		updateWxUserLabel := task.NewTask("updateWxUserLabel", "0 01 0 * * *", UpdateWxUserLabel) //更新用户的标签
 		task.AddTask("updateWxUserLabel", updateWxUserLabel)
 
-		addAllArticleHistory := task.NewTask("addAllArticleHistory", "0 30 2 * * *", AddAllArticleHistory) //把前一天的用户阅读记录同步到ES
+		addAllArticleHistory := task.NewTask("addAllArticleHistory", "0 30 2 * * *", AddAllArticleAndYanxuanHistory) //把前一天的用户阅读记录同步到ES
 		task.AddTask("addAllArticleHistory", addAllArticleHistory)
 
 		getCeLueArticlePv := task.NewTask("getCeLueArticlePv", "0 */10 * * * *", GetCeLueArticlePv) //通过三方接口获取策略平台上的阅读记录