package models import ( "eta_gn/eta_api/global" "fmt" "github.com/rdlucklib/rdluck_tools/paging" "time" ) // ReportHistory 定义报告历史记录的结构体 type ReportHistory struct { Id int `gorm:"primaryKey"` ReportId int `description:"报告id"` ReportChapterId int `description:"报告章节id"` Title string `description:"标题"` Content string `description:"内容"` CreateTime time.Time `description:"创建时间"` ContentSub string `description:"部分内容"` AdminId int `description:"创建人id"` AdminName string `description:"创建人姓名"` ContentStruct string `description:"内容组件"` CanvasColor string `description:"画布颜色"` HeadResourceId int `description:"版头资源ID"` EndResourceId int `description:"版尾资源ID"` } func (r *ReportHistory) TableName() string { return "report_history" } func (r *ReportHistory) Add() (err error) { err = global.DmSQL["rddp"].Create(r).Error return } func (r *ReportHistory) GetNoContentPageList(condition string, pars []interface{}, startSize, pageSize int) (list []*ReportHistory, err error) { sql := fmt.Sprintf(`SELECT id, report_id, report_chapter_id, title, create_time, admin_id, admin_name FROM %s WHERE 1=1 `, r.TableName()) if condition != "" { sql += condition } sql += ` ORDER BY create_time DESC, id DESC LIMIT ?, ?` pars = append(pars, startSize, pageSize) err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&list).Error return } func (r *ReportHistory) GetPageListCount(condition string, pars []interface{}) (count int, err error) { sql := fmt.Sprintf(`SELECT COUNT(1) AS count FROM %s WHERE 1=1 `, r.TableName()) if condition != "" { sql += condition } err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error return } // 删除接口 func (r *ReportHistory) Delete() (err error) { err = global.DmSQL["rddp"].Delete(r).Error return } // 查询单条记录 func (r *ReportHistory) GetById(id int) (item *ReportHistory, err error) { err = global.DmSQL["rddp"].Where("id = ?", id).First(&item).Error return } // ReportHistoryListItem 定义报告历史记录列表项的结构体 type ReportHistoryListItem struct { Id int `description:"报告历史记录id"` ReportId int `description:"报告id"` ReportChapterId int `description:"报告章节id"` Title string `description:"标题"` CreateTime string `description:"创建时间"` AdminId int `description:"创建人id"` AdminName string `description:"创建人姓名"` } type ReportHistoryListResp struct { List []*ReportHistoryListItem Paging *paging.PagingItem `description:"分页数据"` } type DeleteReportHistoryReq struct { Id int `description:"报告历史记录id"` }