1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- package report_chapter
- import (
- "hongze/hongze_yb/global"
- "hongze/hongze_yb/utils"
- )
- func GetLatestChapterByTypeIdsAndClass(typeIds []int, classifyNameFirst string) (reportChapter *ReportChapter, err error) {
- sql := `SELECT
- max( publish_time ) as publish_time,
- classify_id_first,
- classify_name_first,
- title,
- type_id,
- type_name,
- report_chapter_id
- FROM
- report_chapter
- WHERE
- type_id IN (?)
- AND publish_state = 2
- AND is_edit = 1
- AND classify_name_first = ?
- ORDER BY
- publish_time desc`
- err = global.MYSQL["rddp"].Model(ReportChapter{}).Raw(sql, typeIds, classifyNameFirst).First(&reportChapter).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").
- 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, content, trend, type_id, type_name, abstract, title, author, 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
- }
|