123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- package report
- import (
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type ReportFreeLayout struct {
- Id int `gorm:"primaryKey;autoIncrement;column:id"` // 主键
- ReportId int `gorm:"column:report_id"` // 研报Id
- ReportChapterId int `gorm:"column:report_chapter_id"` // 章节Id
- Page int `gorm:"column:page"` // 页码
- IsChapter int `gorm:"column:is_chapter"` // 是否多章节
- Content string `gorm:"column:content;size:255"` // 内容
- ContentStruct string `gorm:"column:content_struct;size:255"` // 内容
- CreateTime time.Time `gorm:"column:create_time"` // 创建时间
- ModifyTime time.Time `gorm:"column:modify_time"` // 修改时间
- }
- type PagePositionEnum string
- const (
- Left PagePositionEnum = "left"
- Right PagePositionEnum = "right"
- Center PagePositionEnum = "center"
- )
- type ContentPage struct {
- Id int `json:"Id"`
- Page int `json:"Page"`
- Content string `json:"Content"`
- ContentStruct string `json:"ContentStruct"`
- ReportId int `json:"ChapterId"`
- ReportChapterId int `json:"ReportChapterId"`
- }
- func (cp *ContentPage) ToView(isChapter bool, ReportId int, ReportChapterId int) *ReportFreeLayout {
- if isChapter {
- return &ReportFreeLayout{
- ReportId: ReportId,
- ReportChapterId: ReportChapterId,
- Page: cp.Page,
- IsChapter: 1,
- Content: cp.Content,
- ContentStruct: cp.ContentStruct,
- CreateTime: time.Now(),
- }
- } else {
- return &ReportFreeLayout{
- ReportId: ReportId,
- ReportChapterId: ReportChapterId,
- Page: cp.Page,
- IsChapter: 0,
- Content: cp.Content,
- ContentStruct: cp.ContentStruct,
- CreateTime: time.Now(),
- }
- }
- }
- func (cp *ReportFreeLayout) ToPageView() *ContentPage {
- return &ContentPage{
- Page: cp.Page,
- Content: cp.Content,
- ContentStruct: cp.ContentStruct,
- ReportId: cp.ReportId,
- ReportChapterId: cp.ReportChapterId,
- }
- }
- func ToPageViewList(srcList []*ReportFreeLayout) (list []*ContentPage) {
- for _, v := range srcList {
- list = append(list, v.ToPageView())
- }
- return
- }
- // TableName 设置表名
- func (*ReportFreeLayout) TableName() string {
- return "report_free_layout"
- }
- func GetFreeLayoutChapterPagesByReportId(reportId int) (list []*ContentPage, err error) {
- o := orm.NewOrmUsingDB("rddp")
- var ormList []*ReportFreeLayout
- 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`
- _, err = o.Raw(sql, reportId).QueryRows(&ormList)
- if err != nil {
- return nil, err
- }
- list = ToPageViewList(ormList)
- return
- }
- func GetFreeLayoutPagesByReportId(id int) (list []*ContentPage, err error) {
- o := orm.NewOrmUsingDB("rddp")
- var ormList []*ReportFreeLayout
- sql := `select * from report_free_layout where report_id =? and is_chapter=0 order by page asc`
- _, err = o.Raw(sql, id).QueryRows(&ormList)
- if err != nil {
- return nil, err
- }
- list = ToPageViewList(ormList)
- return
- }
- // GetReportFreeLayoutListByReportId
- // @Description: 根据报告ID和章节ID获取所有的布局列表
- // @author: Roc
- // @datetime 2025-04-16 13:46:38
- // @param reportId int
- // @param chapterId int
- // @return list []*ReportFreeLayout
- // @return err error
- func GetReportFreeLayoutListByReportId(reportId, chapterId int) (list []*ReportFreeLayout, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `select * from report_free_layout where report_id =? and report_chapter_id=? order by page asc`
- _, err = o.Raw(sql, reportId, chapterId).QueryRows(&list)
- return
- }
- // GetAllReportFreeLayoutListByReportId
- // @Description: 根据报告id获取所有的报告自由布局列表(含章节的)
- // @author: Roc
- // @datetime 2025-04-16 13:46:24
- // @param reportId int
- // @return list []*ReportFreeLayout
- // @return err error
- func GetAllReportFreeLayoutListByReportId(reportId int) (list []*ReportFreeLayout, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `select * from report_free_layout where report_id =? order by page asc`
- _, err = o.Raw(sql, reportId).QueryRows(&list)
- return
- }
|