report_chapter.go 5.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package models
  2. import (
  3. "eta_gn/eta_report/global"
  4. "fmt"
  5. "strings"
  6. "time"
  7. )
  8. // ReportChapter 报告章节
  9. type ReportChapter struct {
  10. ReportChapterId int `gorm:"primaryKey;autoIncrement;column:report_chapter_id"`
  11. ReportId int `gorm:"column:report_id" description:"报告ID"`
  12. ReportType string `gorm:"column:report_type" description:"报告类型 day-晨报 week-周报"`
  13. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  14. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  15. TypeId int `gorm:"column:type_id" description:"品种ID"`
  16. TypeName string `gorm:"column:type_name" description:"品种名称"`
  17. Title string `gorm:"column:title" description:"标题"`
  18. Abstract string `gorm:"column:abstract" description:"摘要"`
  19. AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
  20. Author string `gorm:"column:author" description:"作者"`
  21. Content string `gorm:"column:content" description:"内容"`
  22. ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
  23. Stage int `gorm:"column:stage" description:"期数"`
  24. Trend string `gorm:"column:trend" description:"趋势观点"`
  25. Sort int `gorm:"column:sort" description:"排序: 数值越小越靠前"`
  26. IsEdit int `gorm:"column:is_edit" description:"是否已编辑 0-待编辑 1-已编辑"`
  27. PublishState int `gorm:"column:publish_state" description:"发布状态 1-待发布,2-已发布"`
  28. PublishTime time.Time `gorm:"column:publish_time" description:"发布时间"`
  29. VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
  30. VideoName string `gorm:"column:video_name" description:"音频文件名称"`
  31. VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
  32. VideoSize string `gorm:"column:video_size" description:"音频文件大小,单位M"`
  33. VideoKind int `gorm:"column:video_kind" description:"音频生成方式:1,手动上传,2:自动生成"`
  34. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  35. ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
  36. OriginalVideoUrl string `gorm:"column:original_video_url" description:"原始音频文件URL"`
  37. ContentStruct string `gorm:"column:content_struct" description:"内容组件"`
  38. LastModifyAdminId int `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
  39. LastModifyAdminName string `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
  40. ContentModifyTime time.Time `gorm:"column:content_modify_time" description:"内容更新时间"`
  41. ReportLayout int `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  42. ReportCreateTime time.Time `gorm:"column:report_create_time" description:"报告时间创建时间"`
  43. VoiceGenerateType int `gorm:"column:voice_generate_type" description:"音频生成方式,0:系统生成,1:人工上传"`
  44. }
  45. // GetPublishedChapterListByReportId 根据ReportId获取已发布章节列表
  46. func GetPublishedChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
  47. sql := ` SELECT * FROM report_chapter WHERE report_id = ? AND publish_state = 2 ORDER BY sort ASC`
  48. err = global.DEFAULT_DmSQL.Raw(sql, reportId).Find(&list).Error
  49. return
  50. }
  51. func (m *ReportChapter) TableName() string {
  52. return "report_chapter"
  53. }
  54. func (m *ReportChapter) GetItemById(id int) (item *ReportChapter, err error) {
  55. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), "id")
  56. err = global.DEFAULT_DmSQL.Raw(sql, id).First(&item).Error
  57. return
  58. }
  59. func (m *ReportChapter) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *ReportChapter, err error) {
  60. order := ``
  61. if orderRule != "" {
  62. order = ` ORDER BY ` + orderRule
  63. }
  64. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  65. err = global.DEFAULT_DmSQL.Raw(sql, pars...).First(&item).Error
  66. return
  67. }
  68. func (m *ReportChapter) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  69. sql := fmt.Sprintf(`SELECT COUNT(1) FROM report WHERE 1=1 %s`, condition)
  70. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
  71. return
  72. }
  73. func (m *ReportChapter) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*ReportChapter, err error) {
  74. fields := strings.Join(fieldArr, ",")
  75. if len(fieldArr) == 0 {
  76. fields = `*`
  77. }
  78. order := `ORDER BY create_time DESC`
  79. if orderRule != "" {
  80. order = ` ORDER BY ` + orderRule
  81. }
  82. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  83. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
  84. return
  85. }