xingzai 2 роки тому
батько
коміт
eb7e0c0e2a

+ 11 - 35
controllers/report.go

@@ -2,7 +2,6 @@ package controllers
 
 import (
 	"encoding/json"
-	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hongze_clpt/models"
 	"hongze/hongze_clpt/services"
@@ -42,7 +41,6 @@ func (this *MobileReportController) TradeList() {
 		br.Ret = 408
 		return
 	}
-	fmt.Println(user)
 	uid := user.UserId
 	ChartPermissionId, _ := this.GetInt("ChartPermissionId")
 	if ChartPermissionId < 1 {
@@ -54,7 +52,7 @@ func (this *MobileReportController) TradeList() {
 	var err error
 	mapCategory := make(map[int]int)
 	if ChartPermissionId == utils.CE_LUE_ID {
-		listTrade, errTrade := models.GetReportMappingStrategyHomeAll()
+		listTrade, errTrade := models.GetReportMappingStrategyHomeAll(user.UserId)
 		list = listTrade
 		err = errTrade
 
@@ -83,22 +81,12 @@ func (this *MobileReportController) TradeList() {
 	}
 
 	for k, v := range list {
-
+		if v.Readnum == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.UpdateTime)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.UpdateTime)) {
+			list[k].IsRed = true
+		}
 		var condition string
 		var pars []interface{}
 
-		//categoryIdSet, errCategory := models.GetdetailByCategoryIdSet(v.CategoryId)
-		//if errCategory != nil {
-		//	br.Msg = "获取信息失败"
-		//	br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(v.CategoryId)
-		//	return
-		//}
-		//if categoryIdSet != "" {
-		//	condition = ` AND a.category_id IN(` + categoryIdSet + `)`
-		//} else {
-		//	condition = ` AND a.category_id IN(` + strconv.Itoa(v.CategoryId) + `)`
-		//}
-
 		if v.PolymerizationId != "" {
 			condition = ` AND a.category_id IN(` + v.PolymerizationId + `)`
 		} else {
@@ -107,12 +95,6 @@ func (this *MobileReportController) TradeList() {
 
 		if ChartPermissionId != utils.CE_LUE_ID {
 			var pageSize int
-			//if ChartPermissionId == utils.KE_JI_ID {
-			//	pageSize = 12
-			//} else {
-			//	pageSize = 3
-			//}
-
 			pageSize = 3
 			listArticle, err := models.GetHomeList(condition, pars, 0, pageSize)
 			if err != nil {
@@ -546,16 +528,6 @@ func (this *MobileReportController) List() {
 			imgUrlChart = vslice[len(vslice)-1]
 			mapCategoryUrl[categoryIdStr] = imgUrlChart
 		}
-		//condition += ` AND category_id_two=? `
-		//pars = append(pars, categoryId)
-
-		//categoryIdSet, errCategory := models.GetdetailByCategoryIdSet(categoryId)
-		//if errCategory != nil {
-		//	br.Msg = "获取信息失败"
-		//	br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId)
-		//	return
-		//}
-		//fmt.Println(detail.PolymerizationId)
 		if detail.PolymerizationId != "" {
 			condition = ` AND category_id IN(` + detail.PolymerizationId + `)`
 		} else {
@@ -570,8 +542,6 @@ func (this *MobileReportController) List() {
 			} else {
 				condition = ` AND category_id IN(` + strconv.Itoa(categoryId) + `)`
 			}
-			//condition = ` AND category_id IN(` + strconv.Itoa(categoryId) + `)`
-			//condition = ` AND match_type_name  = '` + detail.MatchTypeName + `'`
 		}
 
 		if industrialManagementId > 0 {
@@ -602,9 +572,15 @@ func (this *MobileReportController) List() {
 			br.Msg = "获取帖子数据失败,Err:" + err.Error()
 			return
 		}
+		articleIdMap, err := services.GetUserArticleHistoryRecord(user)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.Msg = "获取帖子数据失败,Err:" + err.Error()
+			return
+		}
 		for k, v := range list {
 			list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
-			if v.Readnum == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishDate)) {
+			if !articleIdMap[v.ArticleId] && user.CreatedTime.Before(utils.StrTimeToTime(v.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishDate)) {
 				list[k].IsRed = true
 			}
 		}

+ 14 - 0
models/article_history_record_newpv.go

@@ -140,3 +140,17 @@ type EsUserInteraction struct {
 	UserArticleHistoryNum    int    `description:"用户阅读数量"`
 	CompanyArticleHistoryNum int    `description:"机构阅读数量"`
 }
+
+// GetArticleHistoryRecord 或用户阅读过的文章ID
+func GetArticleHistoryRecord(condition string, pars []interface{}) (item []*CygxArticleHistoryRecord, err error) {
+	if condition == "" {
+		return
+	}
+	o := orm.NewOrm()
+	sql := `SELECT *
+			FROM
+			cygx_article_history_record  
+			WHERE 1 = 1 ` + condition + `  GROUP BY article_id`
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}

+ 24 - 0
models/home.go

@@ -3,6 +3,7 @@ package models
 import (
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"strconv"
 )
 
 type HomeArtAndChartListResp struct {
@@ -121,6 +122,29 @@ func GetHomeList(condition string, pars []interface{}, startSize, pageSize int)
 	return
 }
 
+// 获取产业报告列表
+func GetReportIndustrialList(condition string, pars []interface{}, categoryId, industrialManagementId, userId, startSize, pageSize int) (items []*HomeArticle, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *,( SELECT COUNT( 1 ) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND rec.article_id = a.article_id ) AS readnum 
+FROM
+	cygx_article AS a 
+	INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
+WHERE
+	a.publish_status = 1 
+	AND category_id  IN (SELECT
+	category_id 
+FROM
+	cygx_report_mapping 
+WHERE
+	chart_permission_id = any( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` ) 
+	AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` ) )
+    AND a.is_class = 1
+	AND man_g.industrial_management_id = ?` + condition
+	sql += `   GROUP BY a.article_id ORDER BY publish_date DESC LIMIT ?,? `
+	_, err = o.Raw(sql, pars, industrialManagementId, startSize, pageSize).QueryRows(&items)
+	return
+}
+
 func GetHomeListPublic(condition string, pars []interface{}, startSize, pageSize int) (items []*ArticleListResp, 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

+ 15 - 13
models/report_mapping.go

@@ -2,6 +2,7 @@ package models
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"strconv"
 )
 
 type ReportMapping struct {
@@ -56,21 +57,22 @@ func GetReportMappingStrategyAll() (items []*ReportMapping, err error) {
 }
 
 // 获取策略下面的所有分类
-func GetReportMappingStrategyHomeAll() (items []*TradeReportMapping, err error) {
+func GetReportMappingStrategyHomeAll(userId int) (items []*TradeReportMapping, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
-MAX( art.publish_date ) AS update_time,
-	re.category_id,re.sub_category_name,re.match_type_name
-FROM
-	cygx_report_mapping AS re
-	INNER JOIN cygx_article AS art ON art.category_id = re.category_id 
-WHERE
-	re.report_type = 1 
-	AND re.chart_permission_id = 23 
-GROUP  BY
-	re.match_type_name
-ORDER BY
-	sort DESC , art.publish_date DESC`
+			MAX( art.publish_date ) AS update_time,
+			(SELECT COUNT(1) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND  rec.article_id=art.article_id) AS readnum,
+			re.category_id,re.sub_category_name,re.match_type_name
+			FROM
+				cygx_report_mapping AS re
+				INNER JOIN cygx_article AS art ON art.category_id = re.category_id 
+			WHERE
+				re.report_type = 1 
+				AND re.chart_permission_id = 23 
+			GROUP  BY
+				re.match_type_name
+			ORDER BY
+				sort DESC , art.publish_date DESC`
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }

+ 17 - 2
services/article_red.go

@@ -138,9 +138,24 @@ func ArticleHistory(articleId int, user *models.WxUserItem) (err error) {
 	recordRedis.RealName = user.RealName
 	recordRedis.CompanyName = user.CompanyName
 	recordRedis.CreateTime = time.Now()
-
 	go PushViewRecordNewRedisData(recordRedis, user.CompanyId)
-
 	_, err = models.AddCygxArticleViewRecordNewpv(record)
 	return
 }
+
+// GetUserArticleHistoryRecord 获取用户已经阅读的文章ID
+func GetUserArticleHistoryRecord(user *models.WxUserItem) (articleIdMap map[int]bool, err error) {
+	var condition string
+	var pars []interface{}
+	condition = " AND user_id = ? "
+	pars = append(pars, user.UserId)
+	articleIdMap = make(map[int]bool, 0)
+	list, err := models.GetArticleHistoryRecord(condition, pars)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return
+	}
+	for _, v := range list {
+		articleIdMap[v.ArticleId] = true
+	}
+	return
+}