report_chapter.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package ficc_report
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_clpt/utils"
  5. "time"
  6. )
  7. type ReportChapter struct {
  8. ReportChapterId int `gorm:"primaryKey;column:report_chapter_id;type:int(10) unsigned;not null" json:"-"`
  9. ReportId int `gorm:"column:report_id;type:int(10);not null;default:0" json:"report_id"` //报告ID
  10. ReportType string `gorm:"column:report_type;type:varchar(255);not null;default:''" json:"report_type"` //晨报-day;周报-week;
  11. ClassifyIdFirst int `gorm:"column:classify_id_first;type:int(10);default:0" json:"classify_id_first"` //一级分类id
  12. ClassifyNameFirst string `gorm:"column:classify_name_first;type:varchar(255);default:''" json:"classify_name_first"` //一级分类名称
  13. TypeId int `gorm:"column:type_id;type:int(10);not null;default:0" json:"type_id"` //品种ID
  14. TypeName string `gorm:"column:type_name;type:varchar(255);not null;default:''" json:"type_name"` //品种名称
  15. Title string `gorm:"column:title;type:varchar(255);not null;default:''" json:"title"` //章节标题
  16. Abstract string `gorm:"column:abstract;type:varchar(255);not null;default:''" json:"abstract"` //摘要
  17. AddType int `gorm:"column:add_type;type:int(10);not null;default:0" json:"add_type"` //是否为继承报告1-空白报告2-继承报告
  18. Author string `gorm:"column:author;type:varchar(255);not null;default:''" json:"author"` //作者
  19. Content string `gorm:"column:content;type:longtext;" json:"content"` //内容
  20. ContentSub string `gorm:"column:content_sub;type:longtext;" json:"content_sub"` //内容前两章
  21. Stage int `gorm:"column:stage;type:int(10);not null;default:0" json:"stage"` //期数
  22. Trend string `gorm:"column:trend;type:varchar(255);not null;default:''" json:"trend"` //趋势观点
  23. Sort int `gorm:"column:sort;type:int(10);not null;default:0" json:"sort"` //排序:数值越小越靠前
  24. IsEdit int `gorm:"column:is_edit;type:int(10);not null;default:0" json:"is_edit"` //是否编辑
  25. PublishState int `gorm:"column:publish_state;type:int(4);not null;default:0" json:"publish_state"` //发布状态1-待发布2-已发布
  26. PublishTime time.Time `gorm:"column:publish_time;type:datetime" json:"publish_time"` //发布时间
  27. VideoUrl string `gorm:"column:video_url;type:varchar(255);not null;default:''" json:"video_url"` //音频文件URL
  28. VideoName string `gorm:"column:video_name;type:varchar(255);not null;default:''" json:"video_name"` //音频文件名称
  29. VideoPlaySeconds string `gorm:"column:video_play_seconds;type:varchar(255);not null;default:''" json:"video_play_seconds"` //音频播放时长
  30. VideoSize string `gorm:"column:video_size;type:varchar(255);not null;default:''" json:"video_size"` //音频文件大小,单位M
  31. CreateTime time.Time `gorm:"column:create_time;type:datetime" json:"create_time"` //创建时间
  32. ModifyTime time.Time `gorm:"column:modify_time;type:datetime" json:"modify_time"` //修改时间
  33. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1" json:"report_layout"`
  34. VoiceGenerateType int8 `description:"音频生成方式,0:系统生成,1:人工上传" json:"voice_generate_type"`
  35. }
  36. // ReportChapterPermissionMappingItem 报告章节的权限关系表
  37. type ReportChapterPermissionMappingItem struct {
  38. ReportChapterPermissionMappingId int `gorm:"primaryKey;column:report_chapter_permission_mapping_id" json:"report_chapter_permission_mapping_id"`
  39. ReportChapterId int `gorm:"column:report_chapter_id" json:"report_chapter_id"` // 报告章节的id
  40. ChartPermissionId int `gorm:"column:chart_permission_id" json:"chart_permission_id"` // 权限id
  41. TypeId int `gorm:"column:type_id" json:"type_id"` // 报告章节类型id
  42. CreateTime time.Time `gorm:"column:create_time" json:"create_time"`
  43. }
  44. // @Description: 根据报告ID列表获取章节
  45. func GetReportChapterPermissionMappingItemListByReportId(reportId int) (items []*ReportChapterPermissionMappingItem, err error) {
  46. o := orm.NewOrmUsingDB("rddp")
  47. sql := `SELECT a.report_chapter_permission_mapping_id ,a.report_chapter_id ,a.chart_permission_id ,a.create_time ,b.type_id
  48. FROM report_chapter_permission_mapping AS a
  49. INNER JOIN report_chapter AS b ON a.report_chapter_id = b.report_chapter_id
  50. WHERE b.report_id = ? `
  51. _, err = o.Raw(sql, reportId).QueryRows(&items)
  52. return
  53. }
  54. type ReportChapterList []*ReportChapterListItem
  55. // GetListByChapterIds 根据章节IDs获取列表
  56. func GetListByChapterIds(chapterIds []int) (items []*ReportChapter, err error) {
  57. o := orm.NewOrmUsingDB("rddp")
  58. var condition string
  59. var pars []interface{}
  60. condition = ` AND publish_state = 2 `
  61. if len(chapterIds) > 0 {
  62. condition += ` AND report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) `
  63. pars = append(pars, chapterIds)
  64. }
  65. sql := `SELECT *
  66. FROM report_chapter
  67. WHERE 1=1 ` + condition + ` ORDER BY sort asc, report_chapter_id asc `
  68. _, err = o.Raw(sql, pars).QueryRows(&items)
  69. return
  70. }
  71. // GetListByReportId 根据报告ID获取章节列表
  72. func GetListByReportId(reportId int, classifyNameFirst string) (items []*ReportChapter, err error) {
  73. var where string
  74. if classifyNameFirst == "周报" {
  75. where = " AND report_id = ? AND is_edit = 1 AND publish_state = 2"
  76. } else {
  77. where = " AND report_id = ? AND publish_state = 2"
  78. }
  79. o := orm.NewOrmUsingDB("rddp")
  80. sql := `SELECT report_chapter_id, report_id, type_id, type_name, abstract, title, author, publish_time, trend,video_url,video_name,video_play_seconds,video_size
  81. FROM report_chapter
  82. WHERE 1=1 ` + where + ` ORDER BY sort asc, report_chapter_id asc `
  83. _, err = o.Raw(sql, reportId).QueryRows(&items)
  84. return
  85. }