瀏覽代碼

Merge branch 'cygx_need_929' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

xingzai 1 年之前
父節點
當前提交
9d3dad479f

+ 8 - 1
controllers/home.go

@@ -2,6 +2,7 @@ package controllers
 
 import (
 	"encoding/json"
+	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/services"
@@ -144,8 +145,14 @@ func (this *HomeController) ListHome() {
 		imgUrlChart = vslice[len(vslice)-1]
 		mapCategoryUrl[categoryId] = imgUrlChart
 	}
-
+	var articleIds []int
+	for _, v := range list {
+		articleIds = append(articleIds, v.ArticleId)
+	}
+	articleMapPv := services.GetArticleHistoryByArticleId(articleIds) //文章Pv
+	fmt.Println(articleMapPv)
 	for k, v := range list {
+		list[k].Pv = articleMapPv[v.ArticleId]
 		item := list[k]
 		//如果文章一开始的内容是图片,优先展示第一张图片
 		imgurl, _ := services.FixArticleImgUrl(html.UnescapeString(list[k].Body))

+ 5 - 0
controllers/research.go

@@ -136,6 +136,7 @@ func (this *ResearchController) CollectionList() {
 		}
 		articleIds = append(articleIds, v.ArticleId)
 	}
+	articleMapPv := services.GetArticleHistoryByArticleId(articleIds) //文章Pv
 	//处理关联的产业
 	industrialMap, err := services.GetArticleIndustrialByArticleId(articleIds)
 	if err != nil {
@@ -150,6 +151,7 @@ func (this *ResearchController) CollectionList() {
 			list[k].List = make([]*models.IndustrialManagementResp, 0)
 		}
 		list[k].PublishDate = utils.StrTimeToTime(v.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
+		list[k].Pv = articleMapPv[v.ArticleId]
 	}
 	resp := new(models.ArticleCollectionLIstResp)
 	resp.List = list
@@ -785,6 +787,8 @@ func (this *ResearchController) ArticleNewList() {
 	articleCollectNumMap, _ := services.GetCygxArticleCollectNumMapByArtcileIds(articleIds) //文章收藏的数量
 	articleCollectYanxuanSpecialMap, _ := services.GetYanxuanSpecialCollectMap(user.UserId) //用户收藏的研选专栏
 
+	pvMap := services.GetYanxuanSpecialRecordByYanxuanSpecialId(articleIdsSpecialArr)
+
 	//处理关联的产业
 	industrialMap, err := services.GetArticleIndustrialByArticleId(articleIds)
 	if err != nil {
@@ -795,6 +799,7 @@ func (this *ResearchController) ArticleNewList() {
 	for k, v := range list {
 		if v.IsSpecial == 1 {
 			v.IsCollect = articleCollectYanxuanSpecialMap[v.ArticleId]
+			v.Pv = pvMap[v.ArticleId]
 		} else {
 			v.Pv = articleMapPv[v.ArticleId]
 			v.CollectNum = articleCollectNumMap[v.ArticleId]

+ 32 - 0
models/article_history_record_newpv.go

@@ -339,6 +339,38 @@ func GetCygxArticleHistoryRecordNewpvListPv(condition string, pars []interface{}
 	return
 }
 
+// 查研PV列表
+func GetCygxArticleHistoryRecordNewpvListPvCy(condition string, pars []interface{}) (items []*ListPvUvResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			COUNT( 1 ) AS pv,
+			article_id
+		FROM
+			cygx_article_history_record_all  WHERE 1 = 1  AND platfor = 1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` GROUP BY article_id `
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+// 策略PV列表
+func GetCygxArticleHistoryRecordNewpvListPvCl(condition string, pars []interface{}) (items []*ListPvUvResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			COUNT( 1 ) AS pv,
+			article_id
+		FROM
+			cygx_article_history_record_all  WHERE 1 = 1  AND platfor = 2 AND is_del = 0 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` GROUP BY article_id `
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
 // 获取数量
 func GetCygxArticleHistoryRecordAllCount(condition string, pars []interface{}) (count int, err error) {
 	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_article_history_record_all  WHERE 1= 1  `

+ 22 - 0
models/cygx_yanxuan_special_record.go

@@ -110,3 +110,25 @@ func GetCygxYanxuanSpecialRecordRespList(condition string, pars []interface{}, s
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
 }
+
+type LisYanxuanSpecialRecordPvResp struct {
+	YanxuanSpecialId int `description:"文章ID"`
+	Pv               int `description:"pv"`
+	Uv               int `description:"pv"`
+}
+
+// pv 列表
+func GetCygxYanxuanSpecialRecordListPv(condition string, pars []interface{}) (items []*LisYanxuanSpecialRecordPvResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			COUNT( 1 ) AS pv,
+			yanxuan_special_id
+		FROM
+			cygx_yanxuan_special_record  WHERE 1 = 1  `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` GROUP BY yanxuan_special_id  `
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 1 - 1
models/home.go

@@ -19,7 +19,7 @@ func GetHomeCount(condition string, pars []interface{}) (count int, err error) {
 
 func GetHomeList(condition string, pars []interface{}, startSize, pageSize int) (items []*HomeArticle, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT * ,(SELECT count(1) FROM cygx_article_history_record_newpv as h WHERE h.article_id = a.article_id ) as pv
+	sql := ` SELECT * 
                  FROM cygx_article AS a
                 WHERE a.publish_status=1 `
 	if condition != "" {

+ 0 - 1
models/report.go

@@ -539,7 +539,6 @@ func GetReportCollectionBillboardListYx(limit int, pars []interface{}, condition
 			a.article_type_id,
 			d.nick_name,
 			d.department_id,
-			( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
 			( SELECT count( 1 ) FROM cygx_article_collect AS ac   WHERE ac.article_id = a.article_id  ) AS collect_num, 
 			( SELECT count( 1 ) FROM cygx_article_collect AS ac   WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time )  ) AS collection_num
 		FROM

+ 5 - 3
services/article.go

@@ -1793,9 +1793,6 @@ func HandleArticleCategoryImg(list []*models.HomeArticle) (items []*models.HomeA
 		list[k].Annotation = ArticleAnnotation(item)
 		list[k].Body = ""
 		list[k].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
-		if item.Pv > 999 {
-			list[k].Pv = 999
-		}
 
 		list[k].ChartPermissionName = mapChartPerssion[v.CategoryId]
 		//如果是研选系列的任意取五张图片的中的一张
@@ -1848,6 +1845,7 @@ func HandleArticleCategoryImg(list []*models.HomeArticle) (items []*models.HomeA
 	for i := range list {
 		articleIds = append(articleIds, list[i].ArticleId)
 	}
+	articleMapPv := GetArticleHistoryByArticleId(articleIds) //文章Pv
 	// 报告关联产业信息
 	industryMap := make(map[int][]*models.IndustrialManagementIdInt, 0)
 	if len(articleIds) > 0 {
@@ -1876,6 +1874,10 @@ func HandleArticleCategoryImg(list []*models.HomeArticle) (items []*models.HomeA
 		} else {
 			list[k].List = make([]*models.IndustrialManagementIdInt, 0)
 		}
+		v.Pv = articleMapPv[v.ArticleId]
+		if v.Pv > 999 {
+			list[k].Pv = 999
+		}
 	}
 
 	if len(list) == 0 {

+ 13 - 3
services/article_history.go

@@ -53,14 +53,24 @@ func GetArticleHistoryByArticleId(articleIds []int) (mapResp map[int]int) {
 	var pars []interface{}
 	condition = ` AND article_id IN (` + utils.GetOrmInReplace(lenIds) + `) `
 	pars = append(pars, articleIds)
-	list, err := models.GetCygxArticleHistoryRecordNewpvListPv(condition, pars)
-	if err != nil {
+	listCy, e := models.GetCygxArticleHistoryRecordNewpvListPvCy(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxArticleHistoryRecordNewpvListPvCy, Err: " + e.Error())
 		return
 	}
 	mapResp = make(map[int]int, 0)
-	for _, v := range list {
+	for _, v := range listCy {
 		mapResp[v.ArticleId] = v.Pv
 	}
+
+	listCl, e := models.GetCygxArticleHistoryRecordNewpvListPvCl(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxArticleHistoryRecordNewpvListPvCy, Err: " + e.Error())
+		return
+	}
+	for _, v := range listCl {
+		mapResp[v.ArticleId] += v.Pv
+	}
 	return
 }
 

+ 29 - 0
services/cygx_yanxuan_special_company.go

@@ -175,3 +175,32 @@ func AddSpecialRecord(user *models.WxUserItem, specialId, stopTime int) (err err
 	}
 	return
 }
+
+// GetYanxuanSpecialRecordByYanxuanSpecialId 获取研选专栏阅读 pv map
+func GetYanxuanSpecialRecordByYanxuanSpecialId(articleIds []int) (mapResp map[int]int) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("获取研选专栏阅读,信息失败,GetYanxuanSpecialRecordByYanxuanSpecialId Err:"+err.Error(), 3)
+		}
+	}()
+	lenIds := len(articleIds)
+	if lenIds == 0 {
+		return
+	}
+	var condition string
+	var pars []interface{}
+	condition = ` AND yanxuan_special_id IN (` + utils.GetOrmInReplace(lenIds) + `) `
+	pars = append(pars, articleIds)
+	listPv, e := models.GetCygxYanxuanSpecialRecordListPv(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxArticleHistoryRecordNewpvListPvCy, Err: " + e.Error())
+		return
+	}
+	mapResp = make(map[int]int, 0)
+	for _, v := range listPv {
+		mapResp[v.YanxuanSpecialId] = v.Pv
+	}
+	return
+}