Browse Source

修复专栏列表查询最新期数bug

xiexiaoyuan 2 years ago
parent
commit
a65c17c501

+ 1 - 1
controller/company/company_permission.go

@@ -36,7 +36,7 @@ func GetPermissionList(c *gin.Context)  {
 	response.OkData("获取成功", list, c)
 }
 
-
+// GetHomeFiccPermissions 首页品种权限列表
 func GetHomeFiccPermissions(c *gin.Context) {
 	userinfo := userService.GetInfoByClaims(c)
 

+ 2 - 0
controller/purchase/purchase.go

@@ -13,6 +13,7 @@ import (
 	"strings"
 )
 
+// List 已购列表
 func List(c *gin.Context) {
 	userinfo := userService.GetInfoByClaims(c)
 	// 判断用户是否有已购权限
@@ -41,6 +42,7 @@ func List(c *gin.Context) {
 	response.OkData("获取成功", list, c)
 }
 
+// Detail 已购详情
 func Detail(c *gin.Context)  {
     reqClassifyIdFirst := c.DefaultQuery("classify_id_first", "")
 	reqActivityId := c.DefaultQuery("activity_id", "")

+ 5 - 2
controller/report/classify.go

@@ -9,6 +9,7 @@ import (
 	"strconv"
 )
 
+// ClassifyList 专栏列表
 func ClassifyList(c *gin.Context)  {
 	reqClassifyIdFirst := c.DefaultQuery("classify_id_first", "")
 	if reqClassifyIdFirst == "" {
@@ -32,6 +33,7 @@ func ClassifyList(c *gin.Context)  {
 	return
 }
 
+// ClassifyDetail 专栏详情
 func ClassifyDetail(c *gin.Context)  {
 	reqClassifyIdSecond := c.DefaultQuery("classify_id_second", "")
 	if reqClassifyIdSecond == "" {
@@ -55,6 +57,7 @@ func ClassifyDetail(c *gin.Context)  {
 	return
 }
 
+// ClassifyDetailReports 专栏目录列表
 func ClassifyDetailReports(c *gin.Context)  {
 	reqClassifyIdSecond := c.DefaultQuery("classify_id_second", "")
 	reqPageIndex := c.DefaultQuery("current_index", "1")
@@ -94,7 +97,7 @@ func ClassifyDetailReports(c *gin.Context)  {
 	return
 }
 
-
+// ClassifySimpleList 简单查询二级分类名称列表
 func ClassifySimpleList(c *gin.Context)  {
 	reqClassifyIdFirst := c.DefaultQuery("classify_id_first", "")
 	if reqClassifyIdFirst == ""{
@@ -117,7 +120,7 @@ func ClassifySimpleList(c *gin.Context)  {
 	return
 }
 
-
+// ClassifyFirstList Ficc 菜单
 func ClassifyFirstList(c *gin.Context)  {
 	userinfo := userService.GetInfoByClaims(c)
 

+ 6 - 1
controller/report/report.go

@@ -9,6 +9,7 @@ import (
 	"strconv"
 )
 
+// Detail 报告详情
 func Detail(c *gin.Context)  {
 	reqReportId := c.DefaultQuery("report_id", "")
 	if reqReportId == ""{
@@ -31,6 +32,7 @@ func Detail(c *gin.Context)  {
 	return
 }
 
+// ChapterDetail 章节详情
 func ChapterDetail(c *gin.Context)  {
 	reqReportChapterId := c.DefaultQuery("report_chapter_id", "")
 	if reqReportChapterId == ""{
@@ -53,7 +55,7 @@ func ChapterDetail(c *gin.Context)  {
 	return
 }
 
-
+// List 研报列表
 func List(c *gin.Context)  {
 	reqClassifyIdFirst := c.DefaultQuery("classify_id_first", "")
 	reqClassifyIdSec := c.DefaultQuery("classify_id_second", "")
@@ -102,6 +104,7 @@ func List(c *gin.Context)  {
 	return
 }
 
+// CollectReportList 首页研报汇总
 func CollectReportList(c *gin.Context) {
 	reqChartPermissionId := c.DefaultQuery("chart_permission_id", "")
 	reqPageIndex := c.DefaultQuery("current_index", "1")
@@ -139,6 +142,7 @@ func CollectReportList(c *gin.Context) {
 	return
 }
 
+// Search 首页研报搜索
 func Search(c *gin.Context) {
 	keyWord := c.DefaultQuery("key_word", "")
 	reqPageIndex := c.DefaultQuery("current_index", "1")
@@ -170,6 +174,7 @@ func Search(c *gin.Context) {
 	return
 }
 
+// TickerData 报告详情获取指标数据
 func TickerData(c *gin.Context)  {
 	reqReportChapterId := c.DefaultQuery("report_chapter_id", "")
 	if reqReportChapterId == ""{

+ 1 - 1
go.mod

@@ -12,7 +12,7 @@ require (
 	github.com/go-redis/redis/v8 v8.11.4
 	github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
 	github.com/jonboulle/clockwork v0.2.2 // indirect
-	github.com/json-iterator/go v1.1.12 // indirect
+	github.com/json-iterator/go v1.1.12
 	github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
 	github.com/lestrrat-go/strftime v1.0.5 // indirect
 	github.com/mattn/go-isatty v0.0.14 // indirect

+ 46 - 28
models/tables/rddp/report/query.go

@@ -8,24 +8,32 @@ import (
 
 // GetLatestClassReportsByClassifyIdSeconds 根据用户已购买的分类权限查询个分类最新的报告
 func GetLatestClassReportsByClassifyIdSeconds(classifyIdSeconds []int) (reportList []*Report, err error) {
-	sql := `SELECT
-	max( publish_time ) as publish_time,
-	classify_id_first,
-	classify_name_first,
-	title,
-	classify_id_second,
-	classify_name_second,
-	id,
-	stage
-FROM
-	report 
-WHERE
+	sql := `SELECT t1.id,
+t1.classify_id_first,
+t1.classify_id_second,
+t1.stage,
+t1.title,
+t1.classify_name_first,
+t1.classify_name_second,
+t1.publish_time
+FROM report t1
+INNER JOIN
+(
+    SELECT classify_id_first, max( publish_time ) AS max_publish_time
+    FROM report
+    WHERE
 	state = 2 
-	AND classify_id_second IN ?
 	AND classify_name_first !="权益研报"
+    AND classify_id_second IN ?
 GROUP BY
-	classify_id_first`
-	err = global.MYSQL["rddp"].Raw(sql, classifyIdSeconds).Scan(&reportList).Error
+	classify_id_first
+) t2
+    ON t1.classify_id_first = t2.classify_id_first AND
+       t1.publish_time   = t2.max_publish_time
+	 WHERE t1.state = 2 
+	 AND t1.classify_name_first !="权益研报"
+	 AND t1.classify_id_second IN ?`
+	err = global.MYSQL["rddp"].Raw(sql, classifyIdSeconds, classifyIdSeconds).Scan(&reportList).Error
 	return
 }
 
@@ -120,23 +128,33 @@ func GetLatestDay() (item *Report, err error) {
 
 // GetLatestReportsByClassifyIdFirst 查询当前一级分类下,二级分类中,最新的报告
 func GetLatestReportsByClassifyIdFirst(classifyIdFirst int, classifyIdSeconds []int) (reportList []*Report, err error) {
-	sql := `SELECT
-	max( publish_time ) as publish_time,
-	classify_id_first,
-	classify_name_first,
-	classify_id_second,
-	classify_name_second,
-	id,
-	stage
-FROM
-	report 
-WHERE
+	sql := `
+SELECT t1.id,
+t1.classify_id_first,
+t1.classify_id_second,
+t1.stage,
+t1.classify_name_first,
+t1.classify_name_second,
+t1.publish_time
+FROM report t1
+INNER JOIN
+(
+    SELECT classify_id_first, classify_id_second, max( publish_time ) AS max_publish_time
+    FROM report
+    WHERE
 	state = 2 
 	AND classify_id_first = ?
     AND classify_id_second IN ?
 GROUP BY
-	classify_id_second`
-	err = global.MYSQL["rddp"].Raw(sql, classifyIdFirst, classifyIdSeconds).Scan(&reportList).Error
+	classify_id_second
+) t2
+    ON t1.classify_id_second = t2.classify_id_second AND
+		 t1.classify_id_first = t2.classify_id_first AND
+       t1.publish_time   = t2.max_publish_time
+	 WHERE t1.state = 2 
+	 AND t1.classify_id_first = ?
+	 AND t1.classify_id_second IN ?`
+	err = global.MYSQL["rddp"].Raw(sql, classifyIdFirst, classifyIdSeconds, classifyIdFirst, classifyIdSeconds).Scan(&reportList).Error
 	return
 }
 

+ 3 - 1
services/report/report.go

@@ -834,7 +834,7 @@ func SearchReport(user user.UserInfo, keyWord string, pageIndex, pageSize int)(r
 }
 
 // GetTickerData 获取指标数据
-func GetTickerData(user user.UserInfo, reportChapterId int) (ret response.TickerData, err error) {
+func GetTickerData(user user.UserInfo, reportChapterId int) (ret *response.TickerData, err error) {
 	var errMsg string
 	defer func() {
 		if err != nil {
@@ -907,6 +907,8 @@ func GetTickerData(user user.UserInfo, reportChapterId int) (ret response.Ticker
 		tickerTitle.ReportChapterTypeId = int(chapterTypeInfo.ReportChapterTypeId)
 		tickerTitle.ReportChapterTypeName = chapterTypeInfo.ReportChapterTypeName
 		tickerTitle.DataTableImage = fmt.Sprintf("http://hongze.oss-cn-shanghai.aliyuncs.com/data_table/%s.png", chapterTypeInfo.ReportChapterTypeKey)
+
+		ret = new(response.TickerData)
 		ret.List = list
 		ret.TickerTitle = tickerTitle
 	}