|
@@ -1,6 +1,8 @@
|
|
|
package models
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
|
|
|
"github.com/beego/beego/v2/client/orm"
|
|
@@ -34,14 +36,89 @@ type ReportList struct {
|
|
|
ClassifyDetail
|
|
|
}
|
|
|
|
|
|
-func GetReportListCount(classifyId int) (count int, err error) {
|
|
|
+func GetReportListCount(condition string, pars []interface{}) (count int, err error) {
|
|
|
o := orm.NewOrmUsingDB("rddp")
|
|
|
- sql := ` SELECT COUNT(*) AS count FROM report WHERE 1=1 AND state=2 AND classify_id_second=? `
|
|
|
- err = o.Raw(sql, classifyId).QueryRow(&count)
|
|
|
+ sql := ` SELECT COUNT(*) AS count FROM report WHERE 1=1 AND state=2 `
|
|
|
+ if condition != "" {
|
|
|
+ sql += condition
|
|
|
+ }
|
|
|
+ err = o.Raw(sql, pars...).QueryRow(&count)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func GetReportList(classifyId, startSize, pageSize int) (items []*ReportList, err error) {
|
|
|
+// GetReportDailyListCount 获得今日报告数量
|
|
|
+func GetReportDailyListCount() (count int, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("rddp")
|
|
|
+ sql := ` SELECT COUNT(*) AS count FROM report WHERE 1=1 AND state=2 AND DATE(modify_time)=DATE(NOW()) `
|
|
|
+ err = o.Raw(sql).QueryRow(&count)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetReportDailyList(startSize, pageSize int) (items []*ReportList, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("rddp")
|
|
|
+ sql := ` SELECT a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,
|
|
|
+ a.create_time,a.modify_time,a.state,a.publish_time,a.stage,a.msg_is_send,b.id AS classify_id,b.classify_name,b.descript,b.report_author,b.author_descript,
|
|
|
+ b.report_img_url,b.head_img_url,b.avatar_img_url,b.column_img_url,a.video_url,a.video_name,a.video_play_seconds,a.video_size,
|
|
|
+ CASE WHEN DATE(a.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
|
|
|
+ FROM report AS a
|
|
|
+ INNER JOIN classify AS b ON a.classify_id_second=b.id
|
|
|
+ WHERE a.state=2 AND DATE(a.modify_time)=DATE(NOW())
|
|
|
+ ORDER BY a.publish_time DESC LIMIT ?,? `
|
|
|
+ _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetReportListByIds(reportIds []string, startSize, pageSize int) (items []*ReportList, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("rddp")
|
|
|
+ sql := `SELECT a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,
|
|
|
+ a.create_time,a.modify_time,a.state,a.publish_time,a.stage,a.msg_is_send,b.id AS classify_id,b.classify_name,b.descript,b.report_author,b.author_descript,
|
|
|
+ b.report_img_url,b.head_img_url,b.avatar_img_url,b.column_img_url,a.video_url,a.video_name,a.video_play_seconds,a.video_size,
|
|
|
+ CASE WHEN DATE(a.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
|
|
|
+ FROM report AS a
|
|
|
+ INNER JOIN classify AS b ON a.classify_id_second=b.id
|
|
|
+ WHERE a.state=2 AND a.id IN (?)
|
|
|
+ ORDER BY a.publish_time DESC LIMIT ?,? `
|
|
|
+ var reportIdsStr string
|
|
|
+ if len(reportIds) > 0 {
|
|
|
+ reportIdsStr = strings.Join(reportIds, ",")
|
|
|
+ }
|
|
|
+ _, err = o.Raw(sql, reportIdsStr, startSize, pageSize).QueryRows(&items)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetReportCountByClassifyIds(classifyIds []string) (count int, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("rddp")
|
|
|
+ sql := `SELECT COUNT(*) AS count FROM report
|
|
|
+ WHERE state=2 AND classify_id_second IN (%s) `
|
|
|
+ var reportIdsStr string
|
|
|
+ if len(classifyIds) > 0 {
|
|
|
+ reportIdsStr = strings.Join(classifyIds, ",")
|
|
|
+ sql = fmt.Sprintf(sql, reportIdsStr)
|
|
|
+ }
|
|
|
+ err = o.Raw(sql).QueryRow(&count)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetReportListByClassifyIds(classifyIds []string, startSize, pageSize int) (items []*ReportList, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("rddp")
|
|
|
+ sql := `SELECT a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,
|
|
|
+ a.create_time,a.modify_time,a.state,a.publish_time,a.stage,a.msg_is_send,b.id AS classify_id,b.classify_name,b.descript,b.report_author,b.author_descript,
|
|
|
+ b.report_img_url,b.head_img_url,b.avatar_img_url,b.column_img_url,a.video_url,a.video_name,a.video_play_seconds,a.video_size,
|
|
|
+ CASE WHEN DATE(a.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
|
|
|
+ FROM report AS a
|
|
|
+ INNER JOIN classify AS b ON a.classify_id_second=b.id
|
|
|
+ WHERE a.state=2 AND a.classify_id_second IN (%s)
|
|
|
+ ORDER BY a.publish_time DESC LIMIT ?,? `
|
|
|
+ var reportIdsStr string
|
|
|
+ if len(classifyIds) > 0 {
|
|
|
+ reportIdsStr = strings.Join(classifyIds, ",")
|
|
|
+ sql = fmt.Sprintf(sql, reportIdsStr)
|
|
|
+ }
|
|
|
+ _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetReportList(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
|
|
|
o := orm.NewOrmUsingDB("rddp")
|
|
|
sql := ` SELECT a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,
|
|
|
a.create_time,a.modify_time,a.state,a.publish_time,a.stage,a.msg_is_send,b.id AS classify_id,b.classify_name,b.descript,b.report_author,b.author_descript,
|
|
@@ -49,8 +126,12 @@ func GetReportList(classifyId, startSize, pageSize int) (items []*ReportList, er
|
|
|
CASE WHEN DATE(a.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
|
|
|
FROM report AS a
|
|
|
INNER JOIN classify AS b ON a.classify_id_second=b.id
|
|
|
- WHERE a.state=2 AND a.classify_id_second=? ORDER BY a.publish_time DESC LIMIT ?,? `
|
|
|
- _, err = o.Raw(sql, classifyId, startSize, pageSize).QueryRows(&items)
|
|
|
+ WHERE a.state=2 `
|
|
|
+ if condition != "" {
|
|
|
+ sql += condition
|
|
|
+ }
|
|
|
+ sql += ` ORDER BY a.publish_time DESC LIMIT ?,? `
|
|
|
+ _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -68,3 +149,39 @@ func GetReportPermission(userId int, classifyNameSecond string) (count int, err
|
|
|
err = o.Raw(sql, userId, classifyNameSecond).QueryRow(&count)
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+type ReportDetail struct {
|
|
|
+ Id int `description:"报告Id"`
|
|
|
+ AddType int `description:"新增方式:1:新增报告,2:继承报告"`
|
|
|
+ ClassifyIdFirst int `description:"一级分类id"`
|
|
|
+ ClassifyNameFirst string `description:"一级分类名称"`
|
|
|
+ ClassifyIdSecond int `description:"二级分类id"`
|
|
|
+ ClassifyNameSecond string `description:"二级分类名称"`
|
|
|
+ Title string `description:"标题"`
|
|
|
+ Abstract string `description:"摘要"`
|
|
|
+ Author string `description:"作者"`
|
|
|
+ Frequency string `description:"频度"`
|
|
|
+ CreateTime string `description:"创建时间"`
|
|
|
+ ModifyTime string `description:"修改时间"`
|
|
|
+ State int `description:"1:未发布,2:已发布"`
|
|
|
+ PublishTime string `description:"发布时间"`
|
|
|
+ Stage int `description:"期数"`
|
|
|
+ MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
|
|
|
+ Content string `description:"内容"`
|
|
|
+ VideoUrl string `description:"音频文件URL"`
|
|
|
+ VideoName string `description:"音频文件名称"`
|
|
|
+ VideoPlaySeconds string `description:"音频播放时长"`
|
|
|
+ VideoSize string `description:"音频文件大小,单位M"`
|
|
|
+ ContentSub string `description:"内容前两个章节"`
|
|
|
+ IsShowNewLabel int `description:"是否显示新标签"`
|
|
|
+ IsCurrentDate int `description:"是否当前日期"`
|
|
|
+ ClassifyName string `description:"分类名称"`
|
|
|
+ TitleType string `description:"标题类型,FICC或者权益"`
|
|
|
+}
|
|
|
+
|
|
|
+func GetReportById(reportId int) (item *ReportDetail, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("rddp")
|
|
|
+ sql := `SELECT * FROM report WHERE id=?`
|
|
|
+ err = o.Raw(sql, reportId).QueryRow(&item)
|
|
|
+ return
|
|
|
+}
|