12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package models
- import (
- "eta_gn/eta_report/global"
- "fmt"
- "strings"
- "time"
- )
- // ReportChapter 报告章节
- type ReportChapter struct {
- ReportChapterId int `gorm:"primaryKey;autoIncrement;column:report_chapter_id"`
- ReportId int `gorm:"column:report_id" description:"报告ID"`
- ReportType string `gorm:"column:report_type" description:"报告类型 day-晨报 week-周报"`
- ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
- ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
- TypeId int `gorm:"column:type_id" description:"品种ID"`
- TypeName string `gorm:"column:type_name" description:"品种名称"`
- Title string `gorm:"column:title" description:"标题"`
- Abstract string `gorm:"column:abstract" description:"摘要"`
- AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
- Author string `gorm:"column:author" description:"作者"`
- Content string `gorm:"column:content" description:"内容"`
- ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
- Stage int `gorm:"column:stage" description:"期数"`
- Trend string `gorm:"column:trend" description:"趋势观点"`
- Sort int `gorm:"column:sort" description:"排序: 数值越小越靠前"`
- IsEdit int `gorm:"column:is_edit" description:"是否已编辑 0-待编辑 1-已编辑"`
- PublishState int `gorm:"column:publish_state" description:"发布状态 1-待发布,2-已发布"`
- PublishTime time.Time `gorm:"column:publish_time" description:"发布时间"`
- VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
- VideoName string `gorm:"column:video_name" description:"音频文件名称"`
- VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
- VideoSize string `gorm:"column:video_size" description:"音频文件大小,单位M"`
- VideoKind int `gorm:"column:video_kind" description:"音频生成方式:1,手动上传,2:自动生成"`
- CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
- ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
- OriginalVideoUrl string `gorm:"column:original_video_url" description:"原始音频文件URL"`
- ContentStruct string `gorm:"column:content_struct" description:"内容组件"`
- LastModifyAdminId int `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
- LastModifyAdminName string `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
- ContentModifyTime time.Time `gorm:"column:content_modify_time" description:"内容更新时间"`
- ReportLayout int `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
- ReportCreateTime time.Time `gorm:"column:report_create_time" description:"报告时间创建时间"`
- VoiceGenerateType int `gorm:"column:voice_generate_type" description:"音频生成方式,0:系统生成,1:人工上传"`
- }
- // GetPublishedChapterListByReportId 根据ReportId获取已发布章节列表
- func GetPublishedChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
- sql := ` SELECT * FROM report_chapter WHERE report_id = ? AND publish_state = 2 ORDER BY sort ASC`
- err = global.DEFAULT_DmSQL.Raw(sql, reportId).Find(&list).Error
- return
- }
- func (m *ReportChapter) TableName() string {
- return "report_chapter"
- }
- func (m *ReportChapter) GetItemById(id int) (item *ReportChapter, err error) {
- sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), "id")
- err = global.DEFAULT_DmSQL.Raw(sql, id).First(&item).Error
- return
- }
- func (m *ReportChapter) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *ReportChapter, err error) {
- order := ``
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).First(&item).Error
- return
- }
- func (m *ReportChapter) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
- sql := fmt.Sprintf(`SELECT COUNT(1) FROM report WHERE 1=1 %s`, condition)
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
- return
- }
- func (m *ReportChapter) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*ReportChapter, err error) {
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := `ORDER BY create_time DESC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
- return
- }
|