|
@@ -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
|
|
|
}
|
|
|
|