|
@@ -8,6 +8,7 @@ import (
|
|
"github.com/PuerkitoBio/goquery"
|
|
"github.com/PuerkitoBio/goquery"
|
|
"github.com/beego/beego/v2/client/orm"
|
|
"github.com/beego/beego/v2/client/orm"
|
|
"hongze/hongze_cygx/models"
|
|
"hongze/hongze_cygx/models"
|
|
|
|
+ "hongze/hongze_cygx/models/company"
|
|
"hongze/hongze_cygx/utils"
|
|
"hongze/hongze_cygx/utils"
|
|
"html"
|
|
"html"
|
|
"net/url"
|
|
"net/url"
|
|
@@ -583,6 +584,7 @@ func PushViewRecordNewRedisData(reportViewRecord *ReportViewRecord, companyId in
|
|
|
|
|
|
// 获取策略平台报告阅读数据
|
|
// 获取策略平台报告阅读数据
|
|
func GetCeLueArticlePv(cont context.Context) (err error) {
|
|
func GetCeLueArticlePv(cont context.Context) (err error) {
|
|
|
|
+ //func GetCeLueArticlePv() (err error) {
|
|
defer func() {
|
|
defer func() {
|
|
if err != nil {
|
|
if err != nil {
|
|
go utils.SendAlarmMsg("同步策略平台阅读数据失败", 2)
|
|
go utils.SendAlarmMsg("同步策略平台阅读数据失败", 2)
|
|
@@ -620,55 +622,138 @@ func GetCeLueArticlePv(cont context.Context) (err error) {
|
|
mapMobileArticleId[fmt.Sprint(v.Mobile, "_", v.ArticleId)] = v.ArticleId
|
|
mapMobileArticleId[fmt.Sprint(v.Mobile, "_", v.ArticleId)] = v.ArticleId
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ var celueHistoryIds []int
|
|
|
|
+ var mobiles []string
|
|
|
|
+ for _, v := range chartResult.Data {
|
|
|
|
+ celueHistoryIds = append(celueHistoryIds, v.CelueHistoryId)
|
|
|
|
+ mobiles = append(mobiles, v.Mobile)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ listcelueHistory, e := models.GetCeLueArticleListByIds(celueHistoryIds)
|
|
|
|
+ if e != nil {
|
|
|
|
+ err = errors.New("GetCeLueArticleListByIds, Err: " + e.Error())
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ mapCelueHistoryIds := make(map[int]int)
|
|
|
|
+ for _, v := range listcelueHistory {
|
|
|
|
+ mapCelueHistoryIds[v.CelueHistoryId] = v.CelueHistoryId
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ listMobileCompany, e := company.GetCompanyProductListByMobiles(mobiles)
|
|
|
|
+ if e != nil {
|
|
|
|
+ err = errors.New("GetCompanyProductListByMobiles, Err: " + e.Error())
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ mapUserCompany := make(map[string]*company.CompanyProductUser)
|
|
|
|
+
|
|
|
|
+ for _, v := range listMobileCompany {
|
|
|
|
+ mapUserCompany[v.Mobile] = v
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var celueArticleHistoryItems []*models.CygxCelueArticleHistoryRecord
|
|
|
|
+ var allRecordItems []*models.CygxArticleHistoryRecordAll
|
|
for _, v := range chartResult.Data {
|
|
for _, v := range chartResult.Data {
|
|
|
|
+ articleId, _ := strconv.Atoi(v.ArticleId)
|
|
|
|
+ if articleId == 0 {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
//fmt.Println(v.ArticleId)
|
|
//fmt.Println(v.ArticleId)
|
|
item := new(models.CygxCelueArticleHistoryRecord)
|
|
item := new(models.CygxCelueArticleHistoryRecord)
|
|
item.CelueHistoryId = v.CelueHistoryId
|
|
item.CelueHistoryId = v.CelueHistoryId
|
|
item.Mobile = v.Mobile
|
|
item.Mobile = v.Mobile
|
|
item.ArticleId = v.ArticleId
|
|
item.ArticleId = v.ArticleId
|
|
|
|
+ if v.CompanyName != nil {
|
|
|
|
+ item.CompanyName = v.CompanyName.RealName
|
|
|
|
+ }
|
|
if v.CrmUser != nil {
|
|
if v.CrmUser != nil {
|
|
item.RealName = v.CrmUser.RealName
|
|
item.RealName = v.CrmUser.RealName
|
|
}
|
|
}
|
|
- if v.CompanyName != nil {
|
|
|
|
- item.CompanyName = v.CompanyName.RealName
|
|
|
|
|
|
+
|
|
|
|
+ if mapUserCompany[v.Mobile] != nil {
|
|
|
|
+ mapUser := mapUserCompany[v.Mobile]
|
|
|
|
+ item.CompanyName = mapUser.CompanyName
|
|
|
|
+ item.CompanyStatus = mapUser.Status
|
|
|
|
+ item.SellerName = mapUser.SellerName
|
|
}
|
|
}
|
|
|
|
+
|
|
item.CreateDateApi = time.Now()
|
|
item.CreateDateApi = time.Now()
|
|
t1, _ := time.Parse("2006-01-02T15:04:05Z", v.CreateDate)
|
|
t1, _ := time.Parse("2006-01-02T15:04:05Z", v.CreateDate)
|
|
item.CreateTime = t1.Add(+time.Hour * 8).Format(utils.FormatDateTime)
|
|
item.CreateTime = t1.Add(+time.Hour * 8).Format(utils.FormatDateTime)
|
|
- count, err := models.GetCeLueArticleCountById(v.CelueHistoryId)
|
|
|
|
- if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- if count == 0 {
|
|
|
|
- _, err := models.AddCeLueArticle(item, mapMobileArticleId)
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Println(err)
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ //email=?,company_id=?,company_name=?,user_id=?,real_name=?
|
|
|
|
+ if mapCelueHistoryIds[v.CelueHistoryId] == 0 {
|
|
|
|
+ celueArticleHistoryItems = append(celueArticleHistoryItems, item)
|
|
|
|
+ //写入记录到总的统计表
|
|
|
|
+ record := new(models.CygxArticleHistoryRecordAll)
|
|
|
|
+
|
|
|
|
+ record.ArticleId = articleId
|
|
|
|
+ record.CelueHistoryId = item.CelueHistoryId
|
|
|
|
+ record.CreateTime = item.CreateTime
|
|
|
|
+ record.ModifyTime = time.Now()
|
|
|
|
+ record.CreateDateApi = time.Now()
|
|
|
|
+
|
|
|
|
+ if mapUserCompany[v.Mobile] != nil {
|
|
|
|
+ mapUser := mapUserCompany[v.Mobile]
|
|
|
|
+ record.Mobile = mapUser.Mobile
|
|
|
|
+ record.CompanyName = mapUser.CompanyName
|
|
|
|
+ record.CompanyStatus = mapUser.Status
|
|
|
|
+ record.SellerName = mapUser.SellerName
|
|
|
|
+ record.CompanyId = mapUser.CompanyId
|
|
|
|
+ record.RealName = mapUser.RealName
|
|
|
|
+ record.UserId = mapUser.UserId
|
|
|
|
+ record.Email = mapUser.Email
|
|
|
|
+ }
|
|
|
|
+ record.Platfor = 2
|
|
|
|
+ record.Source = "CELUE"
|
|
|
|
+ if mapMobileArticleId[fmt.Sprint(item.Mobile, "_", item.ArticleId)] == articleId {
|
|
|
|
+ record.IsDel = 1
|
|
|
|
+ }
|
|
|
|
+ allRecordItems = append(allRecordItems, record)
|
|
|
|
+ }
|
|
|
|
+ //count, err := models.GetCeLueArticleCountById(v.CelueHistoryId)
|
|
|
|
+ //if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
|
+ // return err
|
|
|
|
+ //}
|
|
|
|
+ //if count == 0 {
|
|
|
|
+ // _, err := models.AddCeLueArticle(item, mapMobileArticleId)
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // fmt.Println(err)
|
|
|
|
+ // return err
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
}
|
|
}
|
|
|
|
|
|
- //处理同步过来的阅读记录所属用户
|
|
|
|
- var condition string
|
|
|
|
- condition = ` AND create_time > ` + "'" + startTime + "'"
|
|
|
|
- listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList(condition)
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
|
|
|
|
- }
|
|
|
|
- for _, 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 {
|
|
|
|
- err = models.UpdateCygxArticleHistoryRecordAll(user)
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if len(celueArticleHistoryItems) > 0 {
|
|
|
|
+ e = models.AddCygxArticleHistoryRecordAllMulti(celueArticleHistoryItems, allRecordItems)
|
|
|
|
+ if e != nil {
|
|
|
|
+ err = errors.New("AddCygxArticleHistoryRecordAllMulti, Err: " + e.Error())
|
|
|
|
+ return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ //处理同步过来的阅读记录所属用户
|
|
|
|
+ //var condition string
|
|
|
|
+ //condition = ` AND create_time > ` + "'" + startTime + "'"
|
|
|
|
+ //listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList(condition)
|
|
|
|
+ //if err != nil {
|
|
|
|
+ // fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
|
|
|
|
+ //}
|
|
|
|
+ //for _, 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 {
|
|
|
|
+ // err = models.UpdateCygxArticleHistoryRecordAll(user)
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
return
|
|
return
|
|
|
|
|
|
}
|
|
}
|