Parcourir la source

fix:推荐列表、bannet详情移除晨周报的固定文案校验

Roc il y a 8 mois
Parent
commit
12c04a026d

+ 50 - 32
controller/pc/pc.go

@@ -19,6 +19,7 @@ import (
 	"hongze/hongze_yb/models/tables/yb_pc_suncode"
 	"hongze/hongze_yb/services"
 	"hongze/hongze_yb/services/pc"
+	report2 "hongze/hongze_yb/services/report"
 	userService "hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/services/wechat"
 	"hongze/hongze_yb/utils"
@@ -151,28 +152,39 @@ func ClassifyDetail(c *gin.Context) {
 // ClassifyDetailBanner 专栏详情banner图
 func ClassifyDetailBanner(c *gin.Context) {
 	reqReportId := c.DefaultQuery("reportId", "")
-	classifyName := c.DefaultQuery("classify_name_first", "")
-	if reqReportId == "" {
-		response.Fail("请输入二级分类标识", c)
-		return
-	}
+	//classifyName := c.DefaultQuery("classify_name_first", "")
+	//if reqReportId == "" {
+	//	response.Fail("请输入二级分类标识", c)
+	//	return
+	//}
 	reportId, err := strconv.Atoi(reqReportId)
 	if err != nil {
 		response.Fail("报告ID格式有误", c)
 		return
 	}
+	reportInfo, err := report.GetByReportId(reportId)
+	if err != nil {
+		response.Fail("报告查询出错", c)
+		return
+	}
 
 	//查询分类类别,根据分类配置显示专栏还是报告合集
-	parentClassify, err := classify.GetByClassifyNameFirst(classifyName)
+	parentClassify, err := classify.GetByClassifyIdFirst(reportInfo.ClassifyIdFirst)
 	if err != nil {
 		response.Fail("获取分类信息失败"+err.Error(), c)
 		return
 	}
+	minClassifyId, _, err := report2.GetMinClassify(reportInfo)
+	if err != nil {
+		response.FailMsg("查询最新一期报告合集失败", "查询最新一期报告合集失败1:"+err.Error(), c)
+		return
+	}
+
 	var bannerResp *pcModels.DetailBannerResp
-	if classifyName == "周报" || classifyName == "晨报" {
-		chapterItem, err := report_chapter.GetLatestChapterByClassifyName(classifyName)
+	if reportInfo.HasChapter == 1 {
+		chapterItem, err := report_chapter.GetLatestChapterByMinClassifyId(minClassifyId)
 		if err != nil {
-			response.Fail("查询最新一期晨周报失败"+err.Error(), c)
+			response.FailMsg("查询最新一期报告合集失败2", "查询最新一期报告合集失败2:"+err.Error(), c)
 			return
 		}
 		resp := &pcModels.DetailBannerResp{
@@ -186,11 +198,6 @@ func ClassifyDetailBanner(c *gin.Context) {
 		}
 		bannerResp = resp
 	} else {
-		reportInfo, err := report.GetByReportId(reportId)
-		if err != nil {
-			response.Fail("报告查询出错", c)
-			return
-		}
 		if reportInfo.Id == 0 {
 			response.Fail("报告不存在", c)
 			return
@@ -201,23 +208,30 @@ func ClassifyDetailBanner(c *gin.Context) {
 			return
 		}
 
-		reportItem, err := report.GetLatestReportByClassifyName(classifyName, reportInfo.ClassifyIdSecond)
+		reportItem, err := report.GetLatestReportByClassifyId(reportInfo.ClassifyIdFirst, reportInfo.ClassifyIdSecond, reportInfo.ClassifyIdThird)
 		if err != nil {
 			response.Fail("获取报告详情失败"+err.Error(), c)
 			return
 		}
+		//查询分类类别,根据分类配置显示专栏还是报告合集
+		minClassify, err := classify.GetByClassifyId(minClassifyId)
+		if err != nil {
+			response.FailMsg("获取分类信息失败", "获取分类信息失败"+err.Error(), c)
+			return
+		}
+
 		resp := &pcModels.DetailBannerResp{
 			ReportId:           reportItem.ReportId,
 			Stage:              reportItem.Stage,
-			VipTitle:           reportItem.VipTitle,
+			VipTitle:           minClassify.VipTitle,
 			Author:             reportItem.Author,
-			ReportAuthor:       reportItem.ReportAuthor,
+			ReportAuthor:       minClassify.ReportAuthor,
 			ImgUrl:             "",
 			ClassifyNameFirst:  reportItem.ClassifyNameFirst,
 			ClassifyIdFirst:    reportItem.ClassifyIdFirst,
 			ClassifyNameSecond: reportItem.ClassifyNameSecond,
 			ClassifyIdSecond:   reportItem.ClassifyIdSecond,
-			ShowType:           parentClassify.ShowType,
+			ShowType:           minClassify.ShowType,
 		}
 
 		if parentClassify.ShowType == 1 || parentClassify.ShowType == 3 {
@@ -350,7 +364,6 @@ func ClassifyDetailBanner(c *gin.Context) {
 // Recommend 报告详情页更多推荐
 func Recommend(c *gin.Context) {
 	reqReportId := c.DefaultQuery("reportId", "")
-	classifyName := c.DefaultQuery("classify_name_first", "")
 	if reqReportId == "" {
 		response.Fail("请输入二级分类标识", c)
 		return
@@ -360,12 +373,26 @@ func Recommend(c *gin.Context) {
 		response.Fail("报告ID格式有误", c)
 		return
 	}
+	reportInfo, err := report.GetByReportId(reportId)
+	if err != nil {
+		response.Fail("报告查询出错", c)
+		return
+	}
+	if reportInfo.Id == 0 {
+		response.Fail("报告不存在", c)
+		return
+	}
+	minClassifyId, _, err := report2.GetMinClassify(reportInfo)
+	if err != nil {
+		response.FailMsg("查询最新一期报告合集失败", "查询最新一期报告合集失败1:"+err.Error(), c)
+		return
+	}
 
 	var recommendResp []*pcModels.RecommendResp
-	if classifyName == "周报" || classifyName == "晨报" {
-		recommendList, err := report_chapter.GetWeekRecommendList(reportId, classifyName)
+	if reportInfo.HasChapter == 1 {
+		recommendList, err := report_chapter.GetWeekRecommendListV2(reportId, minClassifyId)
 		if err != nil {
-			response.Fail("获取报告详情失败"+err.Error(), c)
+			response.FailMsg("获取推荐报告列表失败", "获取推荐报告列表失败:"+err.Error(), c)
 			return
 		}
 		for _, chapter := range recommendList {
@@ -380,15 +407,6 @@ func Recommend(c *gin.Context) {
 			recommendResp = append(recommendResp, resp)
 		}
 	} else {
-		reportInfo, err := report.GetByReportId(reportId)
-		if err != nil {
-			response.Fail("报告查询出错", c)
-			return
-		}
-		if reportInfo.Id == 0 {
-			response.Fail("报告不存在", c)
-			return
-		}
 
 		if reportInfo.State != 2 && reportInfo.State != 6 {
 			response.Fail("报告未发布", c)
@@ -402,7 +420,7 @@ func Recommend(c *gin.Context) {
 			reportType = 2
 		}
 
-		recommendList, err := pcModels.GetRecommendList(reportId, reportType, reportInfo.ClassifyIdSecond)
+		recommendList, err := pcModels.GetRecommendListV2(reportId, reportType, reportInfo.ClassifyIdFirst, reportInfo.ClassifyIdSecond, reportInfo.ClassifyIdThird)
 		if err != nil {
 			response.Fail("获取报告详情失败"+err.Error(), c)
 			return

+ 23 - 0
models/response/pc/report.go

@@ -122,3 +122,26 @@ type LatestReportBanner struct {
 	Author             string
 	ReportAuthor       string
 }
+
+// GetRecommendListV2
+// @Description: 获取报告的推荐列表
+// @author: Roc
+// @datetime 2024-06-24 14:25:01
+// @param reportId int
+// @param reportType int
+// @param firstId int
+// @param secondId int
+// @param thirdId int
+// @return items []*Report
+// @return err error
+func GetRecommendListV2(reportId, reportType, firstId, secondId, thirdId int) (items []*Report, err error) {
+	sql := `SELECT * FROM report WHERE state=2 AND id<> ? AND classify_id_first=? AND classify_id_second=? AND classify_id_third=? `
+	if reportType == 1 {
+		sql += ` AND classify_name_first = ? `
+	} else {
+		sql += ` AND classify_name_first<>? `
+	}
+	sql += ` ORDER BY publish_time DESC LIMIT 3`
+	err = global.MYSQL["rddp"].Raw(sql, reportId, firstId, secondId, thirdId, "权益研报").Scan(&items).Error
+	return
+}

+ 17 - 0
models/tables/rddp/classify/query.go

@@ -1,6 +1,7 @@
 package classify
 
 import (
+	"errors"
 	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/utils"
 )
@@ -129,3 +130,19 @@ func GetClassifyList() (list []*Classify, err error) {
 	err = global.MYSQL["rddp"].Model(Classify{}).Scan(&list).Error
 	return
 }
+
+// GetByClassifyIdFirst
+// @Description: 根据一级分类id查找一级分类
+// @author: Roc
+// @datetime 2024-06-24 13:57:59
+// @param classifyId int
+// @return item *Classify
+// @return err error
+func GetByClassifyIdFirst(classifyId int) (item *Classify, err error) {
+	err = global.MYSQL["rddp"].Model(Classify{}).Where("id = ? and parent_id = 0", classifyId).First(&item).Error
+	if errors.Is(err, utils.ErrNoRow) {
+		err = nil
+	}
+
+	return
+}

+ 31 - 0
models/tables/rddp/report/query.go

@@ -544,3 +544,34 @@ AND b.chart_permission_id = ?
 	err = global.MYSQL["rddp"].Raw(sql, classifyIdSeconds, chartPermissionId).Count(&total).Error
 	return
 }
+
+// GetLatestReportByClassifyId
+// @Description: 根据分类id获取最近一期报告
+// @author: Roc
+// @datetime 2024-06-24 14:10:05
+// @param firstId int
+// @param secondId int
+// @param thirdId int
+// @return items *pc.LatestReportBanner
+// @return err error
+func GetLatestReportByClassifyId(firstId, secondId, thirdId int) (items *pc.LatestReportBanner, err error) {
+	sql := `SELECT
+	a.id AS report_id,
+	classify_name_second,
+	classify_id_second,
+	classify_name_first,
+	classify_id_first,
+	author,
+	stage
+FROM
+	report as a
+WHERE
+	a.state IN (2, 6) 
+	AND a.classify_id_first = ? 
+	AND a.classify_id_second = ? 
+	AND a.classify_id_third = ? 
+ORDER BY
+	publish_time DESC `
+	err = global.MYSQL["rddp"].Raw(sql, firstId, secondId, thirdId).First(&items).Error
+	return
+}

+ 2 - 0
models/tables/rddp/report/report.go

@@ -9,6 +9,8 @@ type Report struct {
 	ClassifyNameFirst  string    `description:"一级分类名称" json:"classify_name_first"`
 	ClassifyIdSecond   int       `description:"二级分类id" json:"classify_id_second"`
 	ClassifyNameSecond string    `description:"二级分类名称" json:"classify_name_second"`
+	ClassifyIdThird    int       `description:"三级分类id" json:"classify_id_third"`
+	ClassifyNameThird  string    `description:"三级分类名称" json:"classify_name_third"`
 	Title              string    `description:"标题" json:"title"`
 	Abstract           string    `description:"摘要" json:"abstract"`
 	Author             string    `description:"作者" json:"author"`

+ 60 - 0
models/tables/rddp/report_chapter/query.go

@@ -194,3 +194,63 @@ func GetListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
 		Scan(&list).Error
 	return
 }
+
+// GetLatestChapterByMinClassifyId
+// @Description: 根据分类id获取最新的章节信息
+// @author: Roc
+// @datetime 2024-06-24 14:00:46
+// @param minClassifyId int
+// @return items *ReportChapter
+// @return err error
+func GetLatestChapterByMinClassifyId(minClassifyId int) (items *ReportChapter, err error) {
+	sql := `SELECT
+	report_id,
+	classify_name_first,
+	classify_id_first,
+	stage 
+FROM
+	report_chapter 
+WHERE
+	publish_state = 2 
+	AND classify_id_first = ?
+ORDER BY
+	publish_time DESC `
+	err = global.MYSQL["rddp"].Raw(sql, minClassifyId).First(&items).Error
+
+	return
+}
+
+// GetWeekRecommendListV2
+// @Description: 获取推荐列表
+// @author: Roc
+// @datetime 2024-06-24 14:20:09
+// @param reportId int
+// @param firstId int
+// @param secondId int
+// @param thirdId int
+// @return items []*ReportChapter
+// @return err error
+func GetWeekRecommendListV2(reportId, minClassifyId int) (items []*ReportChapter, err error) {
+	sql := `SELECT * FROM (SELECT
+	a.report_id,
+	a.report_chapter_id,
+	a.classify_name_first,
+	a.title,
+	a.stage,
+	a.publish_time 
+FROM
+	report_chapter AS a,
+	report AS b
+WHERE
+	a.publish_state = 2 
+	AND a.report_id <> ?
+	AND a.classify_id_first = ?
+	AND a.report_id=b.id
+	AND b.state IN (2, 6)
+ORDER BY
+	publish_time DESC) t
+	GROUP BY report_id 
+	ORDER BY publish_time desc LIMIT 3 `
+	err = global.MYSQL["rddp"].Raw(sql, reportId, minClassifyId).Scan(&items).Error
+	return
+}

+ 31 - 0
services/report/report.go

@@ -1602,6 +1602,37 @@ func GetVarietyReportList(user user.UserInfo, classifyId, chartPermissionId, pag
 	return
 }
 
+// GetMinClassify
+// @Description: 获取最小分类ID
+// @author: Roc
+// @datetime 2024-06-20 09:23:19
+// @param reportInfo *models.Report
+// @return minClassifyId int
+// @return minClassifyName string
+// @return err error
+func GetMinClassify(reportInfo *report.Report) (minClassifyId int, minClassifyName string, err error) {
+	defer func() {
+		if err != nil {
+			global.FILE_LOG.Error("获取最小分类ID失败,报告ID:%d,Err:%s", reportInfo.Id, err.Error())
+		}
+	}()
+	minClassifyId = reportInfo.ClassifyIdThird
+	minClassifyName = reportInfo.ClassifyNameThird
+	if minClassifyId <= 0 {
+		minClassifyId = reportInfo.ClassifyIdSecond
+		minClassifyName = reportInfo.ClassifyNameSecond
+	}
+	if minClassifyId <= 0 {
+		minClassifyId = reportInfo.ClassifyIdFirst
+		minClassifyName = reportInfo.ClassifyNameFirst
+	}
+	if minClassifyId <= 0 {
+		err = errors.New("分类异常")
+	}
+
+	return
+}
+
 // GetCommoditiesReportList 获取大宗商品报告列表
 //func GetCommoditiesReportList(user user.UserInfo, chartPermissionId, pageIndex, pageSize int) (ret *response.ReportList, err error) {
 //	var errMsg string

+ 2 - 4
services/report/user_access_record.go

@@ -9,7 +9,7 @@ import (
 )
 
 // AddUserAccessRecord 新增报告浏览记录
-func AddUserAccessRecord(userInfo user.UserInfo, reportId int, classifyName string, reportChapterId int, authOk bool){
+func AddUserAccessRecord(userInfo user.UserInfo, reportId int, classifyName string, reportChapterId int, authOk bool) {
 	var err error
 	defer func() {
 		if err != nil {
@@ -26,9 +26,7 @@ func AddUserAccessRecord(userInfo user.UserInfo, reportId int, classifyName stri
 			record.Remark = "0"
 		}
 		record.ReportId = reportId
-		if classifyName == "晨报" || classifyName == "周报" {
-			record.ReportChapterId = reportChapterId
-		}
+		record.ReportChapterId = reportChapterId
 		err = record.Create()
 	}
 	return