report_free_layout.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package report
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type ReportFreeLayout struct {
  7. Id int `gorm:"primaryKey;autoIncrement;column:id"` // 主键
  8. ReportId int `gorm:"column:report_id"` // 研报Id
  9. ReportChapterId int `gorm:"column:report_chapter_id"` // 章节Id
  10. Page int `gorm:"column:page"` // 页码
  11. IsChapter int `gorm:"column:is_chapter"` // 是否多章节
  12. Content string `gorm:"column:content;size:255"` // 内容
  13. ContentStruct string `gorm:"column:content_struct;size:255"` // 内容
  14. CreateTime time.Time `gorm:"column:create_time"` // 创建时间
  15. ModifyTime time.Time `gorm:"column:modify_time"` // 修改时间
  16. }
  17. type PagePositionEnum string
  18. const (
  19. Left PagePositionEnum = "left"
  20. Right PagePositionEnum = "right"
  21. Center PagePositionEnum = "center"
  22. )
  23. type ContentPage struct {
  24. Id int `json:"Id"`
  25. Page int `json:"Page"`
  26. Content string `json:"Content"`
  27. ContentStruct string `json:"ContentStruct"`
  28. ReportId int `json:"ChapterId"`
  29. ReportChapterId int `json:"ReportChapterId"`
  30. }
  31. func (cp *ContentPage) ToView(isChapter bool, ReportId int, ReportChapterId int) *ReportFreeLayout {
  32. if isChapter {
  33. return &ReportFreeLayout{
  34. ReportId: ReportId,
  35. ReportChapterId: ReportChapterId,
  36. Page: cp.Page,
  37. IsChapter: 1,
  38. Content: cp.Content,
  39. ContentStruct: cp.ContentStruct,
  40. CreateTime: time.Now(),
  41. }
  42. } else {
  43. return &ReportFreeLayout{
  44. ReportId: ReportId,
  45. ReportChapterId: ReportChapterId,
  46. Page: cp.Page,
  47. IsChapter: 0,
  48. Content: cp.Content,
  49. ContentStruct: cp.ContentStruct,
  50. CreateTime: time.Now(),
  51. }
  52. }
  53. }
  54. func (cp *ReportFreeLayout) ToPageView() *ContentPage {
  55. return &ContentPage{
  56. Page: cp.Page,
  57. Content: cp.Content,
  58. ContentStruct: cp.ContentStruct,
  59. ReportId: cp.ReportId,
  60. ReportChapterId: cp.ReportChapterId,
  61. }
  62. }
  63. func ToPageViewList(srcList []*ReportFreeLayout) (list []*ContentPage) {
  64. for _, v := range srcList {
  65. list = append(list, v.ToPageView())
  66. }
  67. return
  68. }
  69. // TableName 设置表名
  70. func (*ReportFreeLayout) TableName() string {
  71. return "report_free_layout"
  72. }
  73. func GetFreeLayoutChapterPagesByReportId(reportId int) (list []*ContentPage, err error) {
  74. o := orm.NewOrmUsingDB("rddp")
  75. var ormList []*ReportFreeLayout
  76. sql := `select rfl.*,rc.sort from report_free_layout rfl LEFT JOIN report_chapter rc on rc.report_id=rfl.report_id and rc.report_chapter_id=rfl.report_chapter_id where rfl.report_id =? order by rc.sort,rfl.page asc`
  77. _, err = o.Raw(sql, reportId).QueryRows(&ormList)
  78. if err != nil {
  79. return nil, err
  80. }
  81. list = ToPageViewList(ormList)
  82. return
  83. }
  84. func GetFreeLayoutPagesByReportId(id int) (list []*ContentPage, err error) {
  85. o := orm.NewOrmUsingDB("rddp")
  86. var ormList []*ReportFreeLayout
  87. sql := `select * from report_free_layout where report_id =? and is_chapter=0 order by page asc`
  88. _, err = o.Raw(sql, id).QueryRows(&ormList)
  89. if err != nil {
  90. return nil, err
  91. }
  92. list = ToPageViewList(ormList)
  93. return
  94. }
  95. // GetReportFreeLayoutListByReportId
  96. // @Description: 根据报告ID和章节ID获取所有的布局列表
  97. // @author: Roc
  98. // @datetime 2025-04-16 13:46:38
  99. // @param reportId int
  100. // @param chapterId int
  101. // @return list []*ReportFreeLayout
  102. // @return err error
  103. func GetReportFreeLayoutListByReportId(reportId, chapterId int) (list []*ReportFreeLayout, err error) {
  104. o := orm.NewOrmUsingDB("rddp")
  105. sql := `select * from report_free_layout where report_id =? and report_chapter_id=? order by page asc`
  106. _, err = o.Raw(sql, reportId, chapterId).QueryRows(&list)
  107. return
  108. }
  109. // GetAllReportFreeLayoutListByReportId
  110. // @Description: 根据报告id获取所有的报告自由布局列表(含章节的)
  111. // @author: Roc
  112. // @datetime 2025-04-16 13:46:24
  113. // @param reportId int
  114. // @return list []*ReportFreeLayout
  115. // @return err error
  116. func GetAllReportFreeLayoutListByReportId(reportId int) (list []*ReportFreeLayout, err error) {
  117. o := orm.NewOrmUsingDB("rddp")
  118. sql := `select * from report_free_layout where report_id =? order by page asc`
  119. _, err = o.Raw(sql, reportId).QueryRows(&list)
  120. return
  121. }