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