Explorar o código

获取报告详情的推荐列表

xyxie hai 2 semanas
pai
achega
49dea5aac5
Modificáronse 3 ficheiros con 44 adicións e 5 borrados
  1. 13 4
      controller/pc/pc.go
  2. 30 1
      models/response/pc/report.go
  3. 1 0
      models/response/report.go

+ 13 - 4
controller/pc/pc.go

@@ -420,10 +420,19 @@ func Recommend(c *gin.Context) {
 			reportType = 2
 		}
 
-		recommendList, err := pcModels.GetRecommendListV2(reportId, reportType, reportInfo.ClassifyIdFirst, reportInfo.ClassifyIdSecond, reportInfo.ClassifyIdThird)
-		if err != nil {
-			response.Fail("获取报告详情失败"+err.Error(), c)
-			return
+		recommendList := make([]*pcModels.Report, 0)
+		if reportInfo.RaiReportId > 0 {
+			recommendList, err = pcModels.GetRaiRecommendList(reportId, reportInfo.ClassifyIdFirst, reportInfo.ClassifyIdSecond, reportInfo.ClassifyIdThird, reportInfo.PublishTime)
+			if err != nil {
+				response.Fail("获取报告详情失败"+err.Error(), c)
+				return
+			}
+		} else {
+			recommendList, err = pcModels.GetRecommendListV2(reportId, reportType, reportInfo.ClassifyIdFirst, reportInfo.ClassifyIdSecond, reportInfo.ClassifyIdThird)
+			if err != nil {
+				response.Fail("获取报告详情失败"+err.Error(), c)
+				return
+			}
 		}
 		for _, chapter := range recommendList {
 			resp := &pcModels.RecommendResp{

+ 30 - 1
models/response/pc/report.go

@@ -135,7 +135,7 @@ type LatestReportBanner struct {
 // @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=? `
+	sql := `SELECT id,title,classify_name_first,classify_name_second, stage 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 {
@@ -145,3 +145,32 @@ func GetRecommendListV2(reportId, reportType, firstId, secondId, thirdId int) (i
 	err = global.MYSQL["rddp"].Raw(sql, reportId, firstId, secondId, thirdId, "权益研报").Scan(&items).Error
 	return
 }
+
+// 更多推荐展示该二级分类下发布时间在该报告前后的3篇报告,优先往前找,不足3篇时往后找补全,若都不足3篇,则有几篇展示几篇,报告按发布时间降序排,展示报告二级分类和报告标题,不展示期数;
+func GetRaiRecommendList(reportId, firstId, secondId, thirdId int, publishTime time.Time) (items []*Report, err error) {
+	// 获取发布时间在当前报告之前的报告
+	var beforeItems []*Report
+	beforeSql := `SELECT id,title,classify_name_first,classify_name_second, stage FROM report WHERE state=2 AND id<>? AND classify_id_first=? AND classify_id_second=? AND classify_id_third=? 
+		AND publish_time <= ? ORDER BY publish_time DESC, id DESC LIMIT 3`
+	err = global.MYSQL["rddp"].Raw(beforeSql, reportId, firstId, secondId, thirdId, publishTime).Find(&beforeItems).Error
+	if err != nil {
+		return
+	}
+
+	items = append(items, beforeItems...)
+
+	// 如果前面的报告不足3篇,则获取发布时间在当前报告之后的报告补全
+	if len(beforeItems) < 3 {
+		var afterItems []*Report
+		remainCount := 3 - len(beforeItems)
+		afterSql := `SELECT id,title,classify_name_first,classify_name_second, state FROM report WHERE state=2 AND id<>? AND classify_id_first=? AND classify_id_second=? AND classify_id_third=? 
+			AND publish_time > ? ORDER BY publish_time ASC, id ASC LIMIT ?`
+		err = global.MYSQL["rddp"].Raw(afterSql, reportId, firstId, secondId, thirdId, publishTime, remainCount).Find(&afterItems).Error
+		if err != nil {
+			return
+		}
+		items = append(items, afterItems...)
+	}
+
+	return
+}

+ 1 - 0
models/response/report.go

@@ -63,6 +63,7 @@ type ReportItem struct {
 	CanvasColor        string    `description:"画布颜色" json:"canvas_color"`
 	HeadStyle          string    `description:"版头样式" json:"head_style"`
 	EndStyle           string    `description:"版尾样式" json:"end_style"`
+	RaiReportId        int       `description:"权益报告ID" json:"rai_report_id"`
 }
 
 type ReportChapterItem struct {