report_history.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package models
  2. import (
  3. "eta_gn/eta_api/global"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. // ReportHistory 定义报告历史记录的结构体
  9. type ReportHistory struct {
  10. Id int `gorm:"primaryKey"`
  11. ReportId int `description:"报告id"`
  12. ReportChapterId int `description:"报告章节id"`
  13. Title string `description:"标题"`
  14. Content string `description:"内容"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ContentSub string `description:"部分内容"`
  17. AdminId int `description:"创建人id"`
  18. AdminName string `description:"创建人姓名"`
  19. ContentStruct string `description:"内容组件"`
  20. CanvasColor string `description:"画布颜色"`
  21. HeadResourceId int `description:"版头资源ID"`
  22. EndResourceId int `description:"版尾资源ID"`
  23. }
  24. func (r *ReportHistory) TableName() string {
  25. return "report_history"
  26. }
  27. func (r *ReportHistory) Add() (err error) {
  28. err = global.DmSQL["rddp"].Create(r).Error
  29. return
  30. }
  31. func (r *ReportHistory) GetNoContentPageList(condition string, pars []interface{}, startSize, pageSize int) (list []*ReportHistory, err error) {
  32. sql := fmt.Sprintf(`SELECT id, report_id, report_chapter_id, title, create_time, admin_id, admin_name FROM %s WHERE 1=1 `, r.TableName())
  33. if condition != "" {
  34. sql += condition
  35. }
  36. sql += ` ORDER BY create_time DESC, id DESC LIMIT ?, ?`
  37. pars = append(pars, startSize, pageSize)
  38. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&list).Error
  39. return
  40. }
  41. func (r *ReportHistory) GetPageListCount(condition string, pars []interface{}) (count int, err error) {
  42. sql := fmt.Sprintf(`SELECT COUNT(1) AS count FROM %s WHERE 1=1 `, r.TableName())
  43. if condition != "" {
  44. sql += condition
  45. }
  46. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  47. return
  48. }
  49. // 删除接口
  50. func (r *ReportHistory) Delete() (err error) {
  51. err = global.DmSQL["rddp"].Delete(r).Error
  52. return
  53. }
  54. // 查询单条记录
  55. func (r *ReportHistory) GetById(id int) (item *ReportHistory, err error) {
  56. err = global.DmSQL["rddp"].Where("id = ?", id).First(&item).Error
  57. return
  58. }
  59. // ReportHistoryListItem 定义报告历史记录列表项的结构体
  60. type ReportHistoryListItem struct {
  61. Id int `description:"报告历史记录id"`
  62. ReportId int `description:"报告id"`
  63. ReportChapterId int `description:"报告章节id"`
  64. Title string `description:"标题"`
  65. CreateTime string `description:"创建时间"`
  66. AdminId int `description:"创建人id"`
  67. AdminName string `description:"创建人姓名"`
  68. }
  69. type ReportHistoryListResp struct {
  70. List []*ReportHistoryListItem
  71. Paging *paging.PagingItem `description:"分页数据"`
  72. }
  73. type DeleteReportHistoryReq struct {
  74. Id int `description:"报告历史记录id"`
  75. }