|
@@ -300,257 +300,579 @@ func FixArticleFirstCount(body string) (contentSub string, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func GetArticleListByApi(cont context.Context) (err error) {
|
|
|
- defer func() {
|
|
|
+func SynchronizationArtclehistory() {
|
|
|
+ fmt.Println("同步开始")
|
|
|
+ list, err := models.GetArticleHistoryList()
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("获取列表失败", err)
|
|
|
+ }
|
|
|
+ fmt.Println(len(list))
|
|
|
+ for _, v := range list {
|
|
|
+ //endDate := v.ModifyTime.Add(+time.Minute * 10).Format(utils.FormatDateTime)
|
|
|
+ //detail, err := models.GetNewArticleHistoryRecordNewpv(v.UserId, v.ArticleId, endDate)
|
|
|
+ //if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ // fmt.Println("获取信息失败", err)
|
|
|
+ //}
|
|
|
+ v.OutType = 1
|
|
|
+ //fmt.Println(v.Id)
|
|
|
+ //if detail == nil {
|
|
|
+ // _, err = models.AddCygxArticleViewRecordNewpv(v)
|
|
|
+ // if err != nil {
|
|
|
+ // fmt.Println("新增失败", err)
|
|
|
+ // }
|
|
|
+ //} else {
|
|
|
+ // err = models.UpdateCygxArticleViewRecordNewpvList(v, v.StopTime)
|
|
|
+ // if err != nil {
|
|
|
+ // fmt.Println("修改失败", err)
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ newId, err := models.AddCygxArticleViewRecordNewpv(v)
|
|
|
+ fmt.Println("新增", newId)
|
|
|
if err != nil {
|
|
|
- //fmt.Println("GetArticleListByApi Err:" + err.Error())
|
|
|
- go utils.SendAlarmMsg("同步策略平台数据失败", 2)
|
|
|
- go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
|
|
|
+ fmt.Println("新增失败", err)
|
|
|
}
|
|
|
- }()
|
|
|
- requestUrl := "https://vmp.hzinsights.com/v2api/articles/mp?take=100&skip=0&publish_status=2,4&order=publish_date&sort=DESC"
|
|
|
- method := "GET"
|
|
|
- client := &nhttp.Client{}
|
|
|
- req, err := nhttp.NewRequest(method, requestUrl, nil)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("GetListApi Err:", err.Error())
|
|
|
- return err
|
|
|
}
|
|
|
- req.Header.Add("Authorization", "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkiLCJwaG9uZV9udW1iZXIiOiIxMjM0NTY3ODkiLCJuYW1lIjoi5YW25LuWIiwiZW50cmFuY2UiOiJwYXNzd3dvcmQiLCJpYXQiOjE2MzQ4NzA1OTQsImV4cCI6MTYzNDg3NDE5NH0.tho2L9jsbDPn8ltEGUVDve_nHsh0Kzf6ZrSz0RcZ0ag")
|
|
|
- res, err := client.Do(req)
|
|
|
+ fmt.Println("同步结束")
|
|
|
+}
|
|
|
+
|
|
|
+//统计报表
|
|
|
+func StatisticalReport() {
|
|
|
+ var isSummaryNumAll, isClassNum, pvNumAll, uvNumAll int
|
|
|
+ list, err := models.GetChartPermissionActivity()
|
|
|
if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
- return err
|
|
|
+ fmt.Println("获取列表失败", err)
|
|
|
}
|
|
|
- defer res.Body.Close()
|
|
|
- body, err := ioutil.ReadAll(res.Body)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Getres.Body Err:", err.Error())
|
|
|
- return err
|
|
|
+ for _, v := range list {
|
|
|
+ var listPv []*models.ReportMappingStatistical
|
|
|
+ if v.PermissionName == "研选" {
|
|
|
+ listPv, err = models.GetStatisticalReportArtilceExpert()
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("获取Pv列表失败", err)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ listPv, err = models.GetStatisticalReportArtilce(v.ChartPermissionId)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("获取Pv列表失败", err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var pvNum, uvNum, isSummaryNum int
|
|
|
+ for _, v2 := range listPv {
|
|
|
+ pvNum += v2.Pv
|
|
|
+ uvNum += v2.Uv
|
|
|
+ if v2.IsSummary == "1" {
|
|
|
+ isSummaryNum += 1
|
|
|
+ }
|
|
|
+ if v2.IsClass == "1" && v.ChartPermissionId <= 22 {
|
|
|
+ isClassNum += 1
|
|
|
+ }
|
|
|
+ if v2.IsSummary == "1" && v.ChartPermissionId <= 22 {
|
|
|
+ isSummaryNumAll += 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if v.ChartPermissionId <= 22 {
|
|
|
+ pvNumAll += pvNum
|
|
|
+ uvNumAll += uvNum
|
|
|
+ }
|
|
|
+ fmt.Println(v.PermissionName+"行业", len(listPv), "篇,其中主观类报告", isSummaryNum, "篇,客观类报告", len(listPv)-isSummaryNum, "篇。共产生阅读量pv-,", pvNum, ",uv-", uvNum)
|
|
|
}
|
|
|
- var pdfResult models.ArticleResultApi
|
|
|
- err = json.Unmarshal(body, &pdfResult)
|
|
|
+ fmt.Println("目前同步四大行业的总报告(已归类)数量", isClassNum, "篇,其中主观类报告", isSummaryNumAll, "篇,客观类报告", isClassNum-isSummaryNumAll, "篇。共产生阅读量pv-", pvNumAll, ",uv-", uvNumAll)
|
|
|
+ var totalOnline int //线上
|
|
|
+ var totalOffline int //线下
|
|
|
+ var totalPeople int //共累计预约外呼人数
|
|
|
+ var totalSignUpOff int //线下报名人数
|
|
|
+ var totalSignUpOffTime int //线下报名人数
|
|
|
+ var totalPeopleMeet int //线下参会人数
|
|
|
+ o := orm.NewOrm()
|
|
|
+ sql := `SELECT COUNT(1) FROM cygx_activity WHERE activity_type_id IN (1,2,3) AND publish_status = 1 AND is_submit_meeting = 1 AND activity_time <= NOW();`
|
|
|
+ err = o.Raw(sql).QueryRow(&totalOnline)
|
|
|
if err != nil {
|
|
|
- fmt.Println("Getres.pdfResult Err:", err.Error())
|
|
|
- return err
|
|
|
+ fmt.Println("获取线上", err)
|
|
|
}
|
|
|
- exitMap := make(map[int]int)
|
|
|
- classMap := make(map[int]int)
|
|
|
- reportMap := make(map[int]int)
|
|
|
- summaryMap := make(map[int]int)
|
|
|
- listMap, err := models.GetArticleApiMap()
|
|
|
+ sql = `SELECT COUNT(1) FROM cygx_activity WHERE activity_type_id IN (4,5,6) AND publish_status = 1 AND is_submit_meeting = 1 AND activity_time <= NOW();`
|
|
|
+ err = o.Raw(sql).QueryRow(&totalOffline)
|
|
|
if err != nil {
|
|
|
- fmt.Println("GetlistMap Err:", err.Error())
|
|
|
- return err
|
|
|
+ fmt.Println("获取线下", err)
|
|
|
}
|
|
|
- openIdList, err := models.GetUserRecordListByMobile(4, utils.ArticleTaskClassMobile)
|
|
|
+ sql = `SELECT COUNT( 1 ) FROM
|
|
|
+ cygx_activity_signup as s
|
|
|
+ INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
|
|
|
+ WHERE
|
|
|
+ s.do_fail_type = 0
|
|
|
+ AND a.is_submit_meeting = 1
|
|
|
+ AND a.activity_time <= NOW()
|
|
|
+ AND a.publish_status = 1`
|
|
|
+ err = o.Raw(sql).QueryRow(&totalPeople)
|
|
|
if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
- return err
|
|
|
- }
|
|
|
- fmt.Println(openIdList)
|
|
|
- //新旧分类 反向隐射,是否归类,是否是报告,是否是纪要库
|
|
|
- for _, v := range listMap {
|
|
|
- exitMap[v.Id] = v.OldId
|
|
|
- if v.IsClass == 1 {
|
|
|
- classMap[v.OldId] = 1
|
|
|
- }
|
|
|
- if v.IsReport == 1 {
|
|
|
- reportMap[v.OldId] = 1
|
|
|
- }
|
|
|
- if v.IsSummary == 1 {
|
|
|
- summaryMap[v.OldId] = 1
|
|
|
- }
|
|
|
- }
|
|
|
- listData := pdfResult.Data
|
|
|
- var list []*models.Tactics2
|
|
|
- var listAuthor []*models.CygxArticleAuthor
|
|
|
- for _, v := range listData {
|
|
|
- //状态等于 2 跟 4 的进行同步
|
|
|
- if exitMap[v.SeriesId] > 0 && (v.PublishStatus == 2 || v.PublishStatus == 4) {
|
|
|
- v.PublishDate = time.Date(v.PublishDate.Year(), v.PublishDate.Month(), v.PublishDate.Day(), v.PublishDate.Hour(), v.PublishDate.Minute(), v.PublishDate.Second(), v.PublishDate.Nanosecond(), time.Local)
|
|
|
- item := new(models.Tactics2)
|
|
|
- itemAuthor := new(models.CygxArticleAuthor)
|
|
|
- item.ArticleId = v.ArticleId
|
|
|
- item.Title = v.Title
|
|
|
- item.TitleEn = v.TitleEn
|
|
|
- item.File = v.File
|
|
|
- if v.Frequency == "日度" {
|
|
|
- item.UpdateFrequency = "daily"
|
|
|
- } else if v.Frequency == "周度" {
|
|
|
- item.UpdateFrequency = "weekly"
|
|
|
- } else if v.Frequency == "月度" {
|
|
|
- item.UpdateFrequency = "monthly"
|
|
|
- } else if v.Frequency == "季度" {
|
|
|
- item.UpdateFrequency = "quarterly"
|
|
|
- } else if v.Frequency == "年度" {
|
|
|
- item.UpdateFrequency = "yearly"
|
|
|
- } else {
|
|
|
- item.UpdateFrequency = "unknow"
|
|
|
- }
|
|
|
- item.CreateDate = v.CreateDate
|
|
|
- item.PublishDate = v.PublishDate.Add(time.Hour * 8)
|
|
|
- item.PublishStatus = 1
|
|
|
- item.Body = v.Content.Body
|
|
|
- item.Abstract = v.Content.Abstract
|
|
|
- item.CategoryName = v.Industry.Name
|
|
|
- item.CategoryId = exitMap[v.SeriesId]
|
|
|
- item.SubCategoryName = v.Series.Name
|
|
|
- if len(v.Stock) > 0 {
|
|
|
- var stock string
|
|
|
- for _, vS := range v.Stock {
|
|
|
- stock += vS + "/"
|
|
|
- }
|
|
|
- stock = strings.TrimRight(stock, "/")
|
|
|
- item.Stock = stock
|
|
|
- }
|
|
|
- item.FieldName = v.Field.Name
|
|
|
- list = append(list, item)
|
|
|
- itemAuthor.ArticleId = v.ArticleId
|
|
|
- itemAuthor.Name = v.Author.Name
|
|
|
- itemAuthor.Mobile = v.Author.PhoneNumber
|
|
|
- listAuthor = append(listAuthor, itemAuthor)
|
|
|
- }
|
|
|
+ fmt.Println("共累计预约外呼人数", err)
|
|
|
}
|
|
|
- //同步作者
|
|
|
- for _, v := range listAuthor {
|
|
|
- var count int
|
|
|
- count, err = models.GetActivityAuthorCount(v.ArticleId, v.Mobile)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("GetCount Err:", err.Error())
|
|
|
- return err
|
|
|
- }
|
|
|
- if count == 0 {
|
|
|
- _, err = models.AddCygxActivityAuthor(v)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("AddCygxActivityAuthor Err:", err.Error())
|
|
|
- return err
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+ sql = `SELECT COUNT( 1 ) FROM
|
|
|
+ cygx_activity_signup as s
|
|
|
+ INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
|
|
|
+ WHERE
|
|
|
+ s.do_fail_type = 0
|
|
|
+ AND a.is_submit_meeting = 1
|
|
|
+ AND a.activity_time <= NOW()
|
|
|
+ AND a.activity_type_id IN (4,5,6)
|
|
|
+ AND a.publish_status = 1`
|
|
|
+ err = o.Raw(sql).QueryRow(&totalSignUpOff)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("共累计预约外呼人数", err)
|
|
|
}
|
|
|
- fmt.Println("同步文章条数:", len(list))
|
|
|
- listCustomArticle, err := models.GetCustomArticleId() //手动归类的文章,不替换文章类型
|
|
|
+
|
|
|
+ sql = `SELECT COUNT( 1 ) FROM
|
|
|
+ cygx_activity_signup as s
|
|
|
+ INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
|
|
|
+ WHERE
|
|
|
+ s.do_fail_type = 0
|
|
|
+ AND a.publish_status = 1
|
|
|
+ AND a.is_submit_meeting = 1
|
|
|
+ AND a.activity_time <= NOW()
|
|
|
+ AND a.is_submit_meeting = 1
|
|
|
+ AND a.activity_type_id IN (4,5,6);`
|
|
|
+ err = o.Raw(sql).QueryRow(&totalSignUpOffTime)
|
|
|
if err != nil {
|
|
|
- fmt.Println("GetTacticsList Err:", err.Error())
|
|
|
- return err
|
|
|
+ fmt.Println("线下报名参会人数", err)
|
|
|
}
|
|
|
- listGetMatchTypeName, errMatch := models.GetMatchTypeNamenNotNull() //手动归类的文章,不替换文章类型
|
|
|
- if errMatch != nil {
|
|
|
- fmt.Println("GetTacticsList Err:", errMatch.Error())
|
|
|
- return err
|
|
|
+
|
|
|
+ sql = `SELECT COUNT( 1 ) FROM
|
|
|
+ cygx_activity_signup as s
|
|
|
+ INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
|
|
|
+ WHERE
|
|
|
+ s.do_fail_type = 0
|
|
|
+ AND a.is_submit_meeting = 1
|
|
|
+ AND a.activity_time <= NOW()
|
|
|
+ AND a.publish_status = 1
|
|
|
+ AND s.is_meeting = 1
|
|
|
+ AND a.activity_type_id IN (4,5,6);`
|
|
|
+ err = o.Raw(sql).QueryRow(&totalPeopleMeet)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("线下参会人数", err)
|
|
|
}
|
|
|
- fmt.Println("list len:", len(list))
|
|
|
- noSummaryArticleIds := "3454,3456,3457,3459,2449,2450,2453,2454,2459,2530,2583,2663,2670,2699,2715,2732,2748,2759,2399,2356,2870,3173,2978,2826,3470" //非纪要库类型的文章ID
|
|
|
- listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
|
|
|
- for k, v := range list {
|
|
|
- //同步匹配类型
|
|
|
- matchTypeName := ""
|
|
|
- for _, vMatch := range listGetMatchTypeName {
|
|
|
- if v.CategoryId == vMatch.CategoryId {
|
|
|
- matchTypeName = vMatch.MatchTypeName
|
|
|
- }
|
|
|
+
|
|
|
+ fmt.Println("共上线活动", totalOnline+totalOffline, "个,其中线上", totalOnline, "个,线下", totalOffline, "个")
|
|
|
+ fmt.Println("共累计预约外呼人数", totalPeople, "人")
|
|
|
+ fmt.Println("报名线下参会", totalSignUpOff, "人,实际到会人数", totalPeopleMeet, "人,线下到会率约", totalPeopleMeet*100/totalSignUpOff, "%")
|
|
|
+
|
|
|
+ num := totalPeopleMeet / totalSignUpOffTime
|
|
|
+ fmt.Println(num)
|
|
|
+ fmt.Println(totalOnline)
|
|
|
+ fmt.Println(totalOffline)
|
|
|
+ fmt.Println(totalPeople)
|
|
|
+ fmt.Println(totalSignUpOff)
|
|
|
+ fmt.Println(totalPeopleMeet)
|
|
|
+ fmt.Println(totalSignUpOffTime)
|
|
|
+ fmt.Println(totalPeopleMeet / totalSignUpOffTime)
|
|
|
+ return
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// UserViewRedisData 阅读数据
|
|
|
+type UserViewRedisData struct {
|
|
|
+ Mobile string `json:"mobile"`
|
|
|
+ Email string `json:"email"`
|
|
|
+ RealName string `json:"real_name"`
|
|
|
+ CompanyName string `json:"company_name"`
|
|
|
+ ViewTime string `json:"view_time" description:"阅读时间,格式:2022-02-17 13:06:13"`
|
|
|
+ ProductId int `json:"product_id" description:"报告所属产品,ficc:1,权益:2"`
|
|
|
+ CompanyId int `json:"company_id" description:"客户id"`
|
|
|
+}
|
|
|
+
|
|
|
+type ReportViewRecord struct {
|
|
|
+ Id int `orm:"column(id);pk"`
|
|
|
+ UserId int `description:"用户id"`
|
|
|
+ ReportId int `description:"报告id"`
|
|
|
+ Mobile string `description:"手机号"`
|
|
|
+ Email string `description:"邮箱"`
|
|
|
+ RealName string `description:"用户实际姓名"`
|
|
|
+ CompanyName string `description:"公司名称"`
|
|
|
+ CreateTime time.Time `description:"创建时间"`
|
|
|
+}
|
|
|
+
|
|
|
+// PushViewRecordNewRedisData 阅读数据加入到redis
|
|
|
+func PushViewRecordNewRedisData(reportViewRecord *ReportViewRecord, companyId int) bool {
|
|
|
+ data := &UserViewRedisData{
|
|
|
+ Mobile: reportViewRecord.Mobile,
|
|
|
+ Email: reportViewRecord.Email,
|
|
|
+ RealName: reportViewRecord.RealName,
|
|
|
+ CompanyName: reportViewRecord.CompanyName,
|
|
|
+ ViewTime: reportViewRecord.CreateTime.Format(utils.FormatDateTime),
|
|
|
+ ProductId: 2,
|
|
|
+ CompanyId: companyId,
|
|
|
+ }
|
|
|
+ if utils.Re == nil {
|
|
|
+ err := utils.Rc.LPush(utils.CACHE_KEY_USER_VIEW, data)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("PushViewRecordNewRedisData LPush Err:" + err.Error())
|
|
|
}
|
|
|
- //是否属于纪要库的数据
|
|
|
- if _, has := summaryMap[v.CategoryId]; has {
|
|
|
- v.IsSummary = 1
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
+//func GetCeLueArticlePv() {
|
|
|
+// sum := 0
|
|
|
+// for i := 0; i <= 450; i++ {
|
|
|
+// if i >= 102 {
|
|
|
+// //GetCeLueArticlePvs(strconv.Itoa(i * 1000))
|
|
|
+// }
|
|
|
+// }
|
|
|
+// fmt.Println(sum)
|
|
|
+//}
|
|
|
+
|
|
|
+//获取策略平台报告阅读数据
|
|
|
+func GetCeLueArticlePv(cont context.Context) (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ go utils.SendAlarmMsg("同步策略平台阅读数据失败", 2)
|
|
|
+ go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetCeLueArticlePv ErrMsg:"+err.Error(), utils.EmailSendToUsers)
|
|
|
}
|
|
|
- //排除不属于纪要库类型的文章
|
|
|
- for _, vArt := range listNoSummaryArticleIds {
|
|
|
- vArtInt, _ := strconv.Atoi(vArt)
|
|
|
- if v.ArticleId == vArtInt {
|
|
|
- v.IsSummary = 0
|
|
|
- }
|
|
|
+ }()
|
|
|
+ startTime := time.Now().Add(-time.Minute * 12).Format("2006-01-02 15:04:05")
|
|
|
+ endTime := time.Now().Format("2006-01-02 15:04:05")
|
|
|
+ requestUrl := utils.ApiUrl + "backend/statistics_access?take=1000&skip=0&sort=ASC&mode=all&"
|
|
|
+ encodeData := url.Values{}
|
|
|
+ encodeData.Add("start_dt", startTime)
|
|
|
+ encodeData.Add("end_dt", endTime)
|
|
|
+ encodeStr := encodeData.Encode()
|
|
|
+ requestUrl += encodeStr
|
|
|
+ authorization := utils.ApiAuthorization
|
|
|
+ body, err := PublicGetDate(requestUrl, authorization)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var chartResult models.CeLueArticleResultApi
|
|
|
+ err = json.Unmarshal(body, &chartResult)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ mapMobileArticleId := make(map[string]int)
|
|
|
+ //获取当天阅读记录
|
|
|
+ listPv, err := models.GetArticleHistoryRecordAllList()
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ fmt.Println("获取当天阅读记录失败", err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if len(listPv) > 0 {
|
|
|
+ for _, v := range listPv {
|
|
|
+ mapMobileArticleId[fmt.Sprint(v.Mobile, "_", v.ArticleId)] = v.ArticleId
|
|
|
}
|
|
|
- if _, has := reportMap[v.CategoryId]; has {
|
|
|
- v.IsReport = 1
|
|
|
- if _, ok := classMap[v.CategoryId]; ok {
|
|
|
- v.IsClass = 1
|
|
|
- v.ReportType = 1 //是否属于行业报告
|
|
|
- } else {
|
|
|
- v.ReportType = 2 //是否属于产业报告
|
|
|
- }
|
|
|
+ }
|
|
|
+ for _, v := range chartResult.Data {
|
|
|
+ //fmt.Println(v.ArticleId)
|
|
|
+ item := new(models.CygxCelueArticleHistoryRecord)
|
|
|
+ item.CelueHistoryId = v.CelueHistoryId
|
|
|
+ item.Mobile = v.Mobile
|
|
|
+ item.ArticleId = v.ArticleId
|
|
|
+ if v.CrmUser != nil {
|
|
|
+ item.RealName = v.CrmUser.RealName
|
|
|
}
|
|
|
- v.Department = "弘则权益研究"
|
|
|
- //判断是否已经存在
|
|
|
- if v.ArticleId < 0 {
|
|
|
- fmt.Println("AddCygxArticle Err:")
|
|
|
- return err
|
|
|
+ if v.CompanyName != nil {
|
|
|
+ item.CompanyName = v.CompanyName.RealName
|
|
|
}
|
|
|
- var count int
|
|
|
- count, err = models.GetArticleCountById(v.ArticleId)
|
|
|
+ item.CreateDateApi = time.Now()
|
|
|
+ t1, _ := time.Parse("2006-01-02T15:04:05Z", v.CreateDate)
|
|
|
+ item.CreateTime = t1.Add(+time.Hour * 8).Format(utils.FormatDateTime)
|
|
|
+ count, err := models.GetCeLueArticleCountById(v.CelueHistoryId)
|
|
|
if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- fmt.Println("AddCygxArticle Err:", err.Error())
|
|
|
return err
|
|
|
}
|
|
|
- v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
|
|
|
- expertNumStr, expertContentStr, interviewDateStr, _, bodyReturn := BodyAnalysis2(v.Body)
|
|
|
- if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
|
|
|
- v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
|
|
|
- v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
|
|
|
- v.Body = strings.Replace(v.Body, "):", "", -1)
|
|
|
+ if count == 0 {
|
|
|
+ _, err := models.AddCeLueArticle(item, mapMobileArticleId)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
}
|
|
|
- var titleNew string
|
|
|
- titleNew = v.Title
|
|
|
- // 7资金流向 、11大类资产 、51每日复盘 、80医药周报、9估值研究
|
|
|
- if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 9 {
|
|
|
- if v.UpdateFrequency == "daily" {
|
|
|
- var daystr string
|
|
|
- daystr = strconv.Itoa(v.PublishDate.Day())
|
|
|
- if len(daystr) == 1 {
|
|
|
- daystr = "0" + daystr
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理同步过来的阅读记录所属用户
|
|
|
+ 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())
|
|
|
}
|
|
|
- titleNew = v.Title + "(" + strconv.Itoa(v.PublishDate.Year())[2:len(strconv.Itoa(v.PublishDate.Year()))-0] + v.PublishDate.Format("01") + daystr + ")"
|
|
|
- } else if v.UpdateFrequency == "weekly" {
|
|
|
- titleNew = v.Title + utils.WeekByDate(v.PublishDate)
|
|
|
}
|
|
|
}
|
|
|
- if v.CategoryId == 80 {
|
|
|
- titleNew = v.Title + utils.WeekByDate(v.PublishDate)
|
|
|
+ }
|
|
|
+ return
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func GetArticleListByApi(cont context.Context) (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ //fmt.Println("GetArticleListByApi Err:" + err.Error())
|
|
|
+ go utils.SendAlarmMsg("同步策略平台数据失败", 2)
|
|
|
+ go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
|
|
|
}
|
|
|
- if count > 0 {
|
|
|
- fmt.Println(k, v.ArticleId, "edit")
|
|
|
- var isCustom bool
|
|
|
- bodyText, _ := GetReportContentTextSub(v.Body)
|
|
|
- updateParams := make(map[string]interface{})
|
|
|
- //updateParams["Title"] = v.Title
|
|
|
- updateParams["Title"] = titleNew
|
|
|
- updateParams["TitleEn"] = v.TitleEn
|
|
|
- updateParams["UpdateFrequency"] = v.UpdateFrequency
|
|
|
- updateParams["CreateDate"] = v.CreateDate
|
|
|
- updateParams["PublishDate"] = v.PublishDate
|
|
|
- //updateParams["Body"] = html.EscapeString(v.Body)
|
|
|
- updateParams["Body"] = html.EscapeString(bodyReturn)
|
|
|
- updateParams["BodyText"] = bodyText
|
|
|
- updateParams["Abstract"] = html.EscapeString(v.Abstract)
|
|
|
- updateParams["CategoryName"] = v.CategoryName
|
|
|
- for _, vCustom := range listCustomArticle {
|
|
|
- if v.ArticleId == vCustom.ArticleId {
|
|
|
- fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
|
|
|
- isCustom = true
|
|
|
- }
|
|
|
- }
|
|
|
- if isCustom == false {
|
|
|
- updateParams["CategoryId"] = v.CategoryId
|
|
|
- updateParams["MatchTypeName"] = matchTypeName
|
|
|
- updateParams["IsSummary"] = v.IsSummary
|
|
|
- updateParams["IsReport"] = v.IsReport
|
|
|
- updateParams["ReportType"] = v.ReportType
|
|
|
- updateParams["SubCategoryName"] = v.SubCategoryName
|
|
|
- }
|
|
|
- //updateParams["CategoryId"] = v.CategoryId
|
|
|
- updateParams["PublishStatus"] = 1
|
|
|
- updateParams["ExpertBackground"] = expertContentStr
|
|
|
- updateParams["ExpertNumber"] = expertNumStr
|
|
|
- updateParams["InterviewDate"] = interviewDateStr
|
|
|
- //updateParams["IsClass"] = v.IsClass
|
|
|
- v.Department = "弘则权益研究"
|
|
|
- updateParams["Department"] = v.Department
|
|
|
- updateParams["FileLink"] = v.File
|
|
|
- updateParams["Stock"] = v.Stock
|
|
|
- updateParams["FieldName"] = v.FieldName
|
|
|
- whereParam := map[string]interface{}{"article_id": v.ArticleId}
|
|
|
- err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
|
|
|
- if err != nil {
|
|
|
+ }()
|
|
|
+
|
|
|
+ listUpdateArticle, err := models.GetArticleCeluePushList()
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ //如果长度为零就不处理
|
|
|
+ if len(listUpdateArticle) == 0 {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ requestUrl := "https://vmp.hzinsights.com/v2api/articles/mp?take=100&skip=0&publish_status=2,4&order=publish_date&sort=DESC"
|
|
|
+ method := "GET"
|
|
|
+ client := &nhttp.Client{}
|
|
|
+ req, err := nhttp.NewRequest(method, requestUrl, nil)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("GetListApi Err:", err.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ req.Header.Add("Authorization", "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkiLCJwaG9uZV9udW1iZXIiOiIxMjM0NTY3ODkiLCJuYW1lIjoi5YW25LuWIiwiZW50cmFuY2UiOiJwYXNzd3dvcmQiLCJpYXQiOjE2MzQ4NzA1OTQsImV4cCI6MTYzNDg3NDE5NH0.tho2L9jsbDPn8ltEGUVDve_nHsh0Kzf6ZrSz0RcZ0ag")
|
|
|
+ res, err := client.Do(req)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ defer res.Body.Close()
|
|
|
+ body, err := ioutil.ReadAll(res.Body)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Getres.Body Err:", err.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ var pdfResult models.ArticleResultApi
|
|
|
+ err = json.Unmarshal(body, &pdfResult)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Getres.pdfResult Err:", err.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ exitMap := make(map[int]int)
|
|
|
+ classMap := make(map[int]int)
|
|
|
+ reportMap := make(map[int]int)
|
|
|
+ summaryMap := make(map[int]int)
|
|
|
+ listMap, err := models.GetArticleApiMap()
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("GetlistMap Err:", err.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ openIdList, err := models.GetUserRecordListByMobile(4, utils.ArticleTaskClassMobile)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ fmt.Println(openIdList)
|
|
|
+ //新旧分类 反向隐射,是否归类,是否是报告,是否是纪要库
|
|
|
+ for _, v := range listMap {
|
|
|
+ exitMap[v.Id] = v.OldId
|
|
|
+ if v.IsClass == 1 {
|
|
|
+ classMap[v.OldId] = 1
|
|
|
+ }
|
|
|
+ if v.IsReport == 1 {
|
|
|
+ reportMap[v.OldId] = 1
|
|
|
+ }
|
|
|
+ if v.IsSummary == 1 {
|
|
|
+ summaryMap[v.OldId] = 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ listData := pdfResult.Data
|
|
|
+ var list []*models.Tactics2
|
|
|
+ var listAuthor []*models.CygxArticleAuthor
|
|
|
+ for _, v := range listData {
|
|
|
+ //状态等于 2 跟 4 的进行同步
|
|
|
+ if exitMap[v.SeriesId] > 0 && (v.PublishStatus == 2 || v.PublishStatus == 4) {
|
|
|
+ v.PublishDate = time.Date(v.PublishDate.Year(), v.PublishDate.Month(), v.PublishDate.Day(), v.PublishDate.Hour(), v.PublishDate.Minute(), v.PublishDate.Second(), v.PublishDate.Nanosecond(), time.Local)
|
|
|
+ item := new(models.Tactics2)
|
|
|
+ itemAuthor := new(models.CygxArticleAuthor)
|
|
|
+ item.ArticleId = v.ArticleId
|
|
|
+ item.Title = v.Title
|
|
|
+ item.TitleEn = v.TitleEn
|
|
|
+ item.File = v.File
|
|
|
+ if v.Frequency == "日度" {
|
|
|
+ item.UpdateFrequency = "daily"
|
|
|
+ } else if v.Frequency == "周度" {
|
|
|
+ item.UpdateFrequency = "weekly"
|
|
|
+ } else if v.Frequency == "月度" {
|
|
|
+ item.UpdateFrequency = "monthly"
|
|
|
+ } else if v.Frequency == "季度" {
|
|
|
+ item.UpdateFrequency = "quarterly"
|
|
|
+ } else if v.Frequency == "年度" {
|
|
|
+ item.UpdateFrequency = "yearly"
|
|
|
+ } else {
|
|
|
+ item.UpdateFrequency = "unknow"
|
|
|
+ }
|
|
|
+ item.CreateDate = v.CreateDate
|
|
|
+ item.PublishDate = v.PublishDate.Add(time.Hour * 8)
|
|
|
+ item.PublishStatus = 1
|
|
|
+ item.Body = v.Content.Body
|
|
|
+ item.Abstract = v.Content.Abstract
|
|
|
+ item.CategoryName = v.Industry.Name
|
|
|
+ item.CategoryId = exitMap[v.SeriesId]
|
|
|
+ item.SubCategoryName = v.Series.Name
|
|
|
+ if len(v.Stock) > 0 {
|
|
|
+ var stock string
|
|
|
+ for _, vS := range v.Stock {
|
|
|
+ stock += vS + "/"
|
|
|
+ }
|
|
|
+ stock = strings.TrimRight(stock, "/")
|
|
|
+ item.Stock = stock
|
|
|
+ }
|
|
|
+ item.FieldName = v.Field.Name
|
|
|
+ list = append(list, item)
|
|
|
+ itemAuthor.ArticleId = v.ArticleId
|
|
|
+ itemAuthor.Name = v.Author.Name
|
|
|
+ itemAuthor.Mobile = v.Author.PhoneNumber
|
|
|
+ listAuthor = append(listAuthor, itemAuthor)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //同步作者
|
|
|
+ for _, v := range listAuthor {
|
|
|
+ var count int
|
|
|
+ count, err = models.GetActivityAuthorCount(v.ArticleId, v.Mobile)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("GetCount Err:", err.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if count == 0 {
|
|
|
+ _, err = models.AddCygxActivityAuthor(v)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("AddCygxActivityAuthor Err:", err.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fmt.Println("同步文章条数:", len(list))
|
|
|
+ listCustomArticle, err := models.GetCustomArticleId() //手动归类的文章,不替换文章类型
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("GetTacticsList Err:", err.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ listGetMatchTypeName, errMatch := models.GetMatchTypeNamenNotNull() //手动归类的文章,不替换文章类型
|
|
|
+ if errMatch != nil {
|
|
|
+ fmt.Println("GetTacticsList Err:", errMatch.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ fmt.Println("list len:", len(list))
|
|
|
+ noSummaryArticleIds := "3454,3456,3457,3459,2449,2450,2453,2454,2459,2530,2583,2663,2670,2699,2715,2732,2748,2759,2399,2356,2870,3173,2978,2826,3470" //非纪要库类型的文章ID
|
|
|
+ listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
|
|
|
+ for k, v := range list {
|
|
|
+ //同步匹配类型
|
|
|
+ matchTypeName := ""
|
|
|
+ for _, vMatch := range listGetMatchTypeName {
|
|
|
+ if v.CategoryId == vMatch.CategoryId {
|
|
|
+ matchTypeName = vMatch.MatchTypeName
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //是否属于纪要库的数据
|
|
|
+ if _, has := summaryMap[v.CategoryId]; has {
|
|
|
+ v.IsSummary = 1
|
|
|
+ }
|
|
|
+ //排除不属于纪要库类型的文章
|
|
|
+ for _, vArt := range listNoSummaryArticleIds {
|
|
|
+ vArtInt, _ := strconv.Atoi(vArt)
|
|
|
+ if v.ArticleId == vArtInt {
|
|
|
+ v.IsSummary = 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if _, has := reportMap[v.CategoryId]; has {
|
|
|
+ v.IsReport = 1
|
|
|
+ if _, ok := classMap[v.CategoryId]; ok {
|
|
|
+ v.IsClass = 1
|
|
|
+ v.ReportType = 1 //是否属于行业报告
|
|
|
+ } else {
|
|
|
+ v.ReportType = 2 //是否属于产业报告
|
|
|
+ }
|
|
|
+ }
|
|
|
+ v.Department = "弘则权益研究"
|
|
|
+ //判断是否已经存在
|
|
|
+ if v.ArticleId < 0 {
|
|
|
+ fmt.Println("AddCygxArticle Err:")
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ var count int
|
|
|
+ count, err = models.GetArticleCountById(v.ArticleId)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ fmt.Println("AddCygxArticle Err:", err.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
|
|
|
+ expertNumStr, expertContentStr, interviewDateStr, _, bodyReturn := BodyAnalysis2(v.Body)
|
|
|
+ if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
|
|
|
+ v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
|
|
|
+ v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
|
|
|
+ v.Body = strings.Replace(v.Body, "):", "", -1)
|
|
|
+ }
|
|
|
+ var titleNew string
|
|
|
+ titleNew = v.Title
|
|
|
+ // 7资金流向 、11大类资产 、51每日复盘 、80医药周报、9估值研究
|
|
|
+ if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 9 {
|
|
|
+ if v.UpdateFrequency == "daily" {
|
|
|
+ var daystr string
|
|
|
+ daystr = strconv.Itoa(v.PublishDate.Day())
|
|
|
+ if len(daystr) == 1 {
|
|
|
+ daystr = "0" + daystr
|
|
|
+ }
|
|
|
+ titleNew = v.Title + "(" + strconv.Itoa(v.PublishDate.Year())[2:len(strconv.Itoa(v.PublishDate.Year()))-0] + v.PublishDate.Format("01") + daystr + ")"
|
|
|
+ } else if v.UpdateFrequency == "weekly" {
|
|
|
+ titleNew = v.Title + utils.WeekByDate(v.PublishDate)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if v.CategoryId == 80 {
|
|
|
+ titleNew = v.Title + utils.WeekByDate(v.PublishDate)
|
|
|
+ }
|
|
|
+ if count > 0 {
|
|
|
+ fmt.Println(k, v.ArticleId, "edit")
|
|
|
+ var isCustom bool
|
|
|
+ bodyText, _ := GetReportContentTextSub(v.Body)
|
|
|
+ updateParams := make(map[string]interface{})
|
|
|
+ //updateParams["Title"] = v.Title
|
|
|
+ updateParams["Title"] = titleNew
|
|
|
+ updateParams["TitleEn"] = v.TitleEn
|
|
|
+ updateParams["UpdateFrequency"] = v.UpdateFrequency
|
|
|
+ updateParams["CreateDate"] = v.CreateDate
|
|
|
+ updateParams["PublishDate"] = v.PublishDate
|
|
|
+ //updateParams["Body"] = html.EscapeString(v.Body)
|
|
|
+ updateParams["Body"] = html.EscapeString(bodyReturn)
|
|
|
+ updateParams["BodyText"] = bodyText
|
|
|
+ updateParams["Abstract"] = html.EscapeString(v.Abstract)
|
|
|
+ updateParams["CategoryName"] = v.CategoryName
|
|
|
+ for _, vCustom := range listCustomArticle {
|
|
|
+ if v.ArticleId == vCustom.ArticleId {
|
|
|
+ fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
|
|
|
+ isCustom = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if isCustom == false {
|
|
|
+ updateParams["CategoryId"] = v.CategoryId
|
|
|
+ updateParams["MatchTypeName"] = matchTypeName
|
|
|
+ updateParams["IsSummary"] = v.IsSummary
|
|
|
+ updateParams["IsReport"] = v.IsReport
|
|
|
+ updateParams["ReportType"] = v.ReportType
|
|
|
+ updateParams["SubCategoryName"] = v.SubCategoryName
|
|
|
+ }
|
|
|
+ //updateParams["CategoryId"] = v.CategoryId
|
|
|
+ updateParams["PublishStatus"] = 1
|
|
|
+ updateParams["ExpertBackground"] = expertContentStr
|
|
|
+ updateParams["ExpertNumber"] = expertNumStr
|
|
|
+ updateParams["InterviewDate"] = interviewDateStr
|
|
|
+ //updateParams["IsClass"] = v.IsClass
|
|
|
+ v.Department = "弘则权益研究"
|
|
|
+ updateParams["Department"] = v.Department
|
|
|
+ updateParams["FileLink"] = v.File
|
|
|
+ updateParams["Stock"] = v.Stock
|
|
|
+ updateParams["FieldName"] = v.FieldName
|
|
|
+ whereParam := map[string]interface{}{"article_id": v.ArticleId}
|
|
|
+ err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
|
|
|
+ if err != nil {
|
|
|
fmt.Println("UpdateByExpr Err:" + err.Error())
|
|
|
return err
|
|
|
}
|
|
@@ -806,314 +1128,4 @@ func GetArticleListByApi(cont context.Context) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func SynchronizationArtclehistory() {
|
|
|
- fmt.Println("同步开始")
|
|
|
- list, err := models.GetArticleHistoryList()
|
|
|
- if err != nil {
|
|
|
- fmt.Println("获取列表失败", err)
|
|
|
- }
|
|
|
- fmt.Println(len(list))
|
|
|
- for _, v := range list {
|
|
|
- //endDate := v.ModifyTime.Add(+time.Minute * 10).Format(utils.FormatDateTime)
|
|
|
- //detail, err := models.GetNewArticleHistoryRecordNewpv(v.UserId, v.ArticleId, endDate)
|
|
|
- //if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- // fmt.Println("获取信息失败", err)
|
|
|
- //}
|
|
|
- v.OutType = 1
|
|
|
- //fmt.Println(v.Id)
|
|
|
- //if detail == nil {
|
|
|
- // _, err = models.AddCygxArticleViewRecordNewpv(v)
|
|
|
- // if err != nil {
|
|
|
- // fmt.Println("新增失败", err)
|
|
|
- // }
|
|
|
- //} else {
|
|
|
- // err = models.UpdateCygxArticleViewRecordNewpvList(v, v.StopTime)
|
|
|
- // if err != nil {
|
|
|
- // fmt.Println("修改失败", err)
|
|
|
- // }
|
|
|
- //}
|
|
|
- newId, err := models.AddCygxArticleViewRecordNewpv(v)
|
|
|
- fmt.Println("新增", newId)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("新增失败", err)
|
|
|
- }
|
|
|
- }
|
|
|
- fmt.Println("同步结束")
|
|
|
-}
|
|
|
-
|
|
|
-//统计报表
|
|
|
-func StatisticalReport() {
|
|
|
- var isSummaryNumAll, isClassNum, pvNumAll, uvNumAll int
|
|
|
- list, err := models.GetChartPermissionActivity()
|
|
|
- if err != nil {
|
|
|
- fmt.Println("获取列表失败", err)
|
|
|
- }
|
|
|
- for _, v := range list {
|
|
|
- var listPv []*models.ReportMappingStatistical
|
|
|
- if v.PermissionName == "研选" {
|
|
|
- listPv, err = models.GetStatisticalReportArtilceExpert()
|
|
|
- if err != nil {
|
|
|
- fmt.Println("获取Pv列表失败", err)
|
|
|
- }
|
|
|
- } else {
|
|
|
- listPv, err = models.GetStatisticalReportArtilce(v.ChartPermissionId)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("获取Pv列表失败", err)
|
|
|
- }
|
|
|
- }
|
|
|
- var pvNum, uvNum, isSummaryNum int
|
|
|
- for _, v2 := range listPv {
|
|
|
- pvNum += v2.Pv
|
|
|
- uvNum += v2.Uv
|
|
|
- if v2.IsSummary == "1" {
|
|
|
- isSummaryNum += 1
|
|
|
- }
|
|
|
- if v2.IsClass == "1" && v.ChartPermissionId <= 22 {
|
|
|
- isClassNum += 1
|
|
|
- }
|
|
|
- if v2.IsSummary == "1" && v.ChartPermissionId <= 22 {
|
|
|
- isSummaryNumAll += 1
|
|
|
- }
|
|
|
- }
|
|
|
- if v.ChartPermissionId <= 22 {
|
|
|
- pvNumAll += pvNum
|
|
|
- uvNumAll += uvNum
|
|
|
- }
|
|
|
- fmt.Println(v.PermissionName+"行业", len(listPv), "篇,其中主观类报告", isSummaryNum, "篇,客观类报告", len(listPv)-isSummaryNum, "篇。共产生阅读量pv-,", pvNum, ",uv-", uvNum)
|
|
|
- }
|
|
|
- fmt.Println("目前同步四大行业的总报告(已归类)数量", isClassNum, "篇,其中主观类报告", isSummaryNumAll, "篇,客观类报告", isClassNum-isSummaryNumAll, "篇。共产生阅读量pv-", pvNumAll, ",uv-", uvNumAll)
|
|
|
- var totalOnline int //线上
|
|
|
- var totalOffline int //线下
|
|
|
- var totalPeople int //共累计预约外呼人数
|
|
|
- var totalSignUpOff int //线下报名人数
|
|
|
- var totalSignUpOffTime int //线下报名人数
|
|
|
- var totalPeopleMeet int //线下参会人数
|
|
|
- o := orm.NewOrm()
|
|
|
- sql := `SELECT COUNT(1) FROM cygx_activity WHERE activity_type_id IN (1,2,3) AND publish_status = 1 AND is_submit_meeting = 1 AND activity_time <= NOW();`
|
|
|
- err = o.Raw(sql).QueryRow(&totalOnline)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("获取线上", err)
|
|
|
- }
|
|
|
- sql = `SELECT COUNT(1) FROM cygx_activity WHERE activity_type_id IN (4,5,6) AND publish_status = 1 AND is_submit_meeting = 1 AND activity_time <= NOW();`
|
|
|
- err = o.Raw(sql).QueryRow(&totalOffline)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("获取线下", err)
|
|
|
- }
|
|
|
- sql = `SELECT COUNT( 1 ) FROM
|
|
|
- cygx_activity_signup as s
|
|
|
- INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
|
|
|
- WHERE
|
|
|
- s.do_fail_type = 0
|
|
|
- AND a.is_submit_meeting = 1
|
|
|
- AND a.activity_time <= NOW()
|
|
|
- AND a.publish_status = 1`
|
|
|
- err = o.Raw(sql).QueryRow(&totalPeople)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("共累计预约外呼人数", err)
|
|
|
- }
|
|
|
-
|
|
|
- sql = `SELECT COUNT( 1 ) FROM
|
|
|
- cygx_activity_signup as s
|
|
|
- INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
|
|
|
- WHERE
|
|
|
- s.do_fail_type = 0
|
|
|
- AND a.is_submit_meeting = 1
|
|
|
- AND a.activity_time <= NOW()
|
|
|
- AND a.activity_type_id IN (4,5,6)
|
|
|
- AND a.publish_status = 1`
|
|
|
- err = o.Raw(sql).QueryRow(&totalSignUpOff)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("共累计预约外呼人数", err)
|
|
|
- }
|
|
|
-
|
|
|
- sql = `SELECT COUNT( 1 ) FROM
|
|
|
- cygx_activity_signup as s
|
|
|
- INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
|
|
|
- WHERE
|
|
|
- s.do_fail_type = 0
|
|
|
- AND a.publish_status = 1
|
|
|
- AND a.is_submit_meeting = 1
|
|
|
- AND a.activity_time <= NOW()
|
|
|
- AND a.is_submit_meeting = 1
|
|
|
- AND a.activity_type_id IN (4,5,6);`
|
|
|
- err = o.Raw(sql).QueryRow(&totalSignUpOffTime)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("线下报名参会人数", err)
|
|
|
- }
|
|
|
-
|
|
|
- sql = `SELECT COUNT( 1 ) FROM
|
|
|
- cygx_activity_signup as s
|
|
|
- INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
|
|
|
- WHERE
|
|
|
- s.do_fail_type = 0
|
|
|
- AND a.is_submit_meeting = 1
|
|
|
- AND a.activity_time <= NOW()
|
|
|
- AND a.publish_status = 1
|
|
|
- AND s.is_meeting = 1
|
|
|
- AND a.activity_type_id IN (4,5,6);`
|
|
|
- err = o.Raw(sql).QueryRow(&totalPeopleMeet)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("线下参会人数", err)
|
|
|
- }
|
|
|
-
|
|
|
- fmt.Println("共上线活动", totalOnline+totalOffline, "个,其中线上", totalOnline, "个,线下", totalOffline, "个")
|
|
|
- fmt.Println("共累计预约外呼人数", totalPeople, "人")
|
|
|
- fmt.Println("报名线下参会", totalSignUpOff, "人,实际到会人数", totalPeopleMeet, "人,线下到会率约", totalPeopleMeet*100/totalSignUpOff, "%")
|
|
|
-
|
|
|
- num := totalPeopleMeet / totalSignUpOffTime
|
|
|
- fmt.Println(num)
|
|
|
- fmt.Println(totalOnline)
|
|
|
- fmt.Println(totalOffline)
|
|
|
- fmt.Println(totalPeople)
|
|
|
- fmt.Println(totalSignUpOff)
|
|
|
- fmt.Println(totalPeopleMeet)
|
|
|
- fmt.Println(totalSignUpOffTime)
|
|
|
- fmt.Println(totalPeopleMeet / totalSignUpOffTime)
|
|
|
- return
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-// UserViewRedisData 阅读数据
|
|
|
-type UserViewRedisData struct {
|
|
|
- Mobile string `json:"mobile"`
|
|
|
- Email string `json:"email"`
|
|
|
- RealName string `json:"real_name"`
|
|
|
- CompanyName string `json:"company_name"`
|
|
|
- ViewTime string `json:"view_time" description:"阅读时间,格式:2022-02-17 13:06:13"`
|
|
|
- ProductId int `json:"product_id" description:"报告所属产品,ficc:1,权益:2"`
|
|
|
- CompanyId int `json:"company_id" description:"客户id"`
|
|
|
-}
|
|
|
-
|
|
|
-type ReportViewRecord struct {
|
|
|
- Id int `orm:"column(id);pk"`
|
|
|
- UserId int `description:"用户id"`
|
|
|
- ReportId int `description:"报告id"`
|
|
|
- Mobile string `description:"手机号"`
|
|
|
- Email string `description:"邮箱"`
|
|
|
- RealName string `description:"用户实际姓名"`
|
|
|
- CompanyName string `description:"公司名称"`
|
|
|
- CreateTime time.Time `description:"创建时间"`
|
|
|
-}
|
|
|
-
|
|
|
-// PushViewRecordNewRedisData 阅读数据加入到redis
|
|
|
-func PushViewRecordNewRedisData(reportViewRecord *ReportViewRecord, companyId int) bool {
|
|
|
- data := &UserViewRedisData{
|
|
|
- Mobile: reportViewRecord.Mobile,
|
|
|
- Email: reportViewRecord.Email,
|
|
|
- RealName: reportViewRecord.RealName,
|
|
|
- CompanyName: reportViewRecord.CompanyName,
|
|
|
- ViewTime: reportViewRecord.CreateTime.Format(utils.FormatDateTime),
|
|
|
- ProductId: 2,
|
|
|
- CompanyId: companyId,
|
|
|
- }
|
|
|
- if utils.Re == nil {
|
|
|
- err := utils.Rc.LPush(utils.CACHE_KEY_USER_VIEW, data)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("PushViewRecordNewRedisData LPush Err:" + err.Error())
|
|
|
- }
|
|
|
- return true
|
|
|
- }
|
|
|
- return false
|
|
|
-}
|
|
|
-
|
|
|
-//func GetCeLueArticlePv() {
|
|
|
-// sum := 0
|
|
|
-// for i := 0; i <= 450; i++ {
|
|
|
-// if i >= 102 {
|
|
|
-// //GetCeLueArticlePvs(strconv.Itoa(i * 1000))
|
|
|
-// }
|
|
|
-// }
|
|
|
-// fmt.Println(sum)
|
|
|
-//}
|
|
|
-
|
|
|
-//获取策略平台报告阅读数据
|
|
|
-func GetCeLueArticlePv(cont context.Context) (err error) {
|
|
|
- defer func() {
|
|
|
- if err != nil {
|
|
|
- go utils.SendAlarmMsg("同步策略平台阅读数据失败", 2)
|
|
|
- go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetCeLueArticlePv ErrMsg:"+err.Error(), utils.EmailSendToUsers)
|
|
|
- }
|
|
|
- }()
|
|
|
- startTime := time.Now().Add(-time.Minute * 12).Format("2006-01-02 15:04:05")
|
|
|
- endTime := time.Now().Format("2006-01-02 15:04:05")
|
|
|
- requestUrl := utils.ApiUrl + "backend/statistics_access?take=1000&skip=0&sort=ASC&mode=all&"
|
|
|
- encodeData := url.Values{}
|
|
|
- encodeData.Add("start_dt", startTime)
|
|
|
- encodeData.Add("end_dt", endTime)
|
|
|
- encodeStr := encodeData.Encode()
|
|
|
- requestUrl += encodeStr
|
|
|
- authorization := utils.ApiAuthorization
|
|
|
- body, err := PublicGetDate(requestUrl, authorization)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- var chartResult models.CeLueArticleResultApi
|
|
|
- err = json.Unmarshal(body, &chartResult)
|
|
|
- if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
- return err
|
|
|
- }
|
|
|
- mapMobileArticleId := make(map[string]int)
|
|
|
- //获取当天阅读记录
|
|
|
- listPv, err := models.GetArticleHistoryRecordAllList()
|
|
|
- if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- fmt.Println("获取当天阅读记录失败", err)
|
|
|
- return err
|
|
|
- }
|
|
|
- if len(listPv) > 0 {
|
|
|
- for _, v := range listPv {
|
|
|
- mapMobileArticleId[fmt.Sprint(v.Mobile, "_", v.ArticleId)] = v.ArticleId
|
|
|
- }
|
|
|
- }
|
|
|
- for _, v := range chartResult.Data {
|
|
|
- //fmt.Println(v.ArticleId)
|
|
|
- item := new(models.CygxCelueArticleHistoryRecord)
|
|
|
- item.CelueHistoryId = v.CelueHistoryId
|
|
|
- item.Mobile = v.Mobile
|
|
|
- item.ArticleId = v.ArticleId
|
|
|
- if v.CrmUser != nil {
|
|
|
- item.RealName = v.CrmUser.RealName
|
|
|
- }
|
|
|
- if v.CompanyName != nil {
|
|
|
- item.CompanyName = v.CompanyName.RealName
|
|
|
- }
|
|
|
- item.CreateDateApi = time.Now()
|
|
|
- t1, _ := time.Parse("2006-01-02T15:04:05Z", v.CreateDate)
|
|
|
- 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
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //处理同步过来的阅读记录所属用户
|
|
|
- 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
|
|
|
-
|
|
|
-}
|
|
|
+//func
|