123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- package report_chapter
- import (
- "fmt"
- "hongze/hongze_yb/global"
- "hongze/hongze_yb/utils"
- )
- func GetLatestChaptersByTypeIdsAndClass(typeIds []int, classifyNameFirst string) (list []*ReportChapter, err error) {
- sql := `SELECT
- DISTINCT report_id
- FROM
- report_chapter
- WHERE
- type_id IN (?)
- AND publish_state = 2
- AND is_edit = 1
- AND report_type = ?
- ORDER BY
- publish_time desc, report_chapter_id desc limit 30
- `
- err = global.MYSQL["rddp"].Model(ReportChapter{}).Raw(sql, typeIds, classifyNameFirst).Scan(&list).Error
- return
- }
- // GetListByReportId 根据报告ID获取章节列表
- func GetListByReportId(reportId int, classifyNameFirst string) (list []*ReportChapter, err error) {
- var where string
- if classifyNameFirst == "周报"{
- where = "report_id = ? AND is_edit = 1 AND publish_state = 2"
- }else{
- where = "report_id = ? AND publish_state = 2"
- }
- err = global.MYSQL["rddp"].Model(ReportChapter{}).
- Select("report_chapter_id, report_id, type_id, type_name, abstract, title, author, publish_time, trend").
- Where(where, reportId).
- Order("sort asc, report_chapter_id asc").
- Scan(&list).Error
- return
- }
- // GetListByReportIdTypeIds 根据报告ID、章节类型ID获取章节列表
- func GetListByReportIdTypeIds(reportId int, typeIds []int, classifyNameFirst string) (list []*ReportChapter, err error) {
- var where string
- if classifyNameFirst == "周报"{
- where = "report_id = ? AND type_id in (?) AND is_edit = 1 AND publish_state = 2 "
- }else{
- where = "report_id = ? AND type_id in (?) AND publish_state = 2 "
- }
- err = global.MYSQL["rddp"].Model(ReportChapter{}).
- Select("report_chapter_id, report_id, type_id, type_name, abstract, title, author, publish_time").
- Where(where, reportId, typeIds).
- Order("sort asc, report_chapter_id asc").
- Scan(&list).Error
- return
- }
- // GetContentById 根据ID获取章节详情
- func GetContentById(id int, typeIds []int) (info *ReportChapter, err error) {
- err = global.MYSQL["rddp"].Model(ReportChapter{}).Select("report_chapter_id, report_id, is_edit, classify_name_first, classify_id_first, content, trend, type_id, type_name, abstract, title, abstract, author, stage, publish_time, content, content_sub, video_url, video_name, video_play_seconds, video_size").
- Where("report_chapter_id = ? and type_id in (?) AND publish_state = 2 ", id, typeIds).
- First(&info).Error
- if err == utils.ErrNoRow {
- err = nil
- }
- return
- }
- // GetReportIdsByTypeIdsAndClass 根据章节ID获取报告ID
- func GetReportIdsByTypeIdsAndClass(typeIds []int, classifyNameFirst string) (reportIds []int, err error) {
- var list []*ReportChapter
- err = global.MYSQL["rddp"].Model(ReportChapter{}).Select("DISTINCT report_id").Where("type_id in (?) and publish_state = 2 AND is_edit = 1 AND classify_name_first= ? ", typeIds, classifyNameFirst).Scan(&list).Error
- if err != nil {
- return
- }
- for _, v := range list {
- reportIds = append(reportIds, v.ReportId)
- }
- return
- }
- // GetTypeIdById 根据ID获取章节类型
- func GetTypeIdById(id int) (info *ReportChapter, err error) {
- err = global.MYSQL["rddp"].Model(ReportChapter{}).Select("report_chapter_id, type_id").
- Where("report_chapter_id = ? AND publish_state = 2 ", id).
- First(&info).Error
- if err == utils.ErrNoRow {
- err = nil
- }
- return
- }
- // GetByTypeIdsAndReportIds 根据章节ID和ReportIds查询报告
- func GetByTypeIdsAndReportIds(typeIds []int, reportIds []int, classifyNameFirst string) (list []*ReportChapter, err error) {
- var where string
- if classifyNameFirst == "周报"{
- where = "report_id in (?) AND type_id in (?) AND is_edit = 1 AND publish_state = 2 "
- }else{
- where = "report_id in (?) AND type_id in (?) AND publish_state = 2 "
- }
- err = global.MYSQL["rddp"].Model(ReportChapter{}).
- Select("report_id, type_id, report_chapter_id, classify_name_first, classify_id_first, video_url, video_name, video_play_seconds, video_size, sort").
- Where(where, reportIds, typeIds).
- Order("sort asc, report_chapter_id asc").
- Scan(&list).Error
- if err != nil {
- return
- }
- for _, v := range list {
- reportIds = append(reportIds, v.ReportId)
- }
- return
- }
- func GetWeekRecommendList(reportId int, firstName string) (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 <> %v
- AND a.classify_name_first = "%v"
- AND a.report_id=b.id
- AND b.state = 2
- ORDER BY
- publish_time DESC) t
- GROUP BY report_id
- ORDER BY publish_time desc LIMIT 3 `
- sql = fmt.Sprintf(sql, reportId, firstName)
- err = global.MYSQL["rddp"].Raw(sql).Scan(&items).Error
- return
- }
- func GetLatestChapterByClassifyName(firstName string) (items *ReportChapter, err error) {
- sql := `SELECT
- report_id,
- classify_name_first,
- classify_id_first,
- stage
- FROM
- report_chapter
- WHERE
- publish_state = 2
- AND classify_name_first = "%v"
- ORDER BY
- publish_time DESC `
- sql = fmt.Sprintf(sql, firstName)
- err = global.MYSQL["rddp"].Raw(sql).First(&items).Error
- return
- }
|