ppt_v2.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package models
  2. import (
  3. "eta_gn/eta_report/global"
  4. "fmt"
  5. "strings"
  6. "time"
  7. )
  8. // PptV2 表
  9. type PptV2 struct {
  10. PptId int `gorm:"column:ppt_id;primaryKey;autoIncrement:true" description:"ppt的Id"`
  11. TemplateType int `gorm:"column:template_type" description:"模版类型"`
  12. BackgroundImg string `gorm:"column:background_img" description:"背景图片"`
  13. Title string `gorm:"column:title" description:"标题"`
  14. ReportType string `gorm:"column:report_type" description:"报告类型"`
  15. PptDate string `gorm:"column:ppt_date" description:"选择日期"`
  16. Abstract string `gorm:"column:abstract" description:"摘要"`
  17. Content string `gorm:"column:content" description:"ppt内容"`
  18. PptUrl string `gorm:"column:ppt_url" description:"ppt下载地址"`
  19. PptxUrl string `gorm:"column:pptx_url" description:"pptx下载地址"`
  20. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  21. ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
  22. AdminId int `gorm:"column:admin_id" description:"系统用户id"`
  23. AdminRealName string `gorm:"column:admin_real_name" description:"系统用户名称"`
  24. PptVersion int8 `gorm:"column:ppt_version" description:"是否ppt的旧版本;1:旧的,2:新的"`
  25. ReportId int `gorm:"column:report_id" description:"关联的报告ID"`
  26. ReportCode string `gorm:"column:report_code" description:"关联的报告code"`
  27. IsShare int8 `gorm:"column:is_share" description:"是否分享,0:不分享,1:分享"`
  28. PublishTime time.Time `gorm:"column:publish_time" description:"发布时间"`
  29. CoverContent string `gorm:"column:cover_content" description:"PPT内容-JSON"`
  30. PptPage int `gorm:"column:ppt_page" description:"PPT页数"`
  31. TitleSetting string `gorm:"column:title_setting" description:"PPT标题设置"`
  32. ClassifyId int `gorm:"column:classify_id" description:"报告分类ID"`
  33. AddType int `gorm:"column:add_type" description:"新增方式:1-新增报告;2-继承报告"`
  34. InheritReportId int `gorm:"column:inherit_report_id" description:"继承的报告ID"`
  35. CollaborateType int `gorm:"column:collaborate_type" description:"协作方式:1-个人;2-多人协作"`
  36. CollaborateUsers string `gorm:"column:collaborate_users" description:"协作人IDs, 英文逗号分隔"`
  37. IsPublicPublish int `gorm:"column:is_public_publish" description:"是否公开发布:1-是;2-否"`
  38. SubmitTime time.Time `gorm:"column:submit_time" description:"提交时间"`
  39. ApproveTime time.Time `gorm:"column:approve_time" description:"审批时间"`
  40. ReportSource int `gorm:"column:report_source" description:"报告来源:1-系统内;2-智力共享"`
  41. OutReportId string `gorm:"column:out_report_id" description:"外部报告ID(或编码)"`
  42. State int `gorm:"column:state" description:"报告状态:1-未发布;2-已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  43. TopicEndTime time.Time `gorm:"column:topic_end_time" description:"课题结束时间"`
  44. }
  45. func (m *PptV2) TableName() string {
  46. return "ppt_v2"
  47. }
  48. func (m *PptV2) Create() (err error) {
  49. err = global.DEFAULT_DmSQL.Create(m).Error
  50. return
  51. }
  52. func (m *PptV2) Update(cols []string) (err error) {
  53. err = global.DEFAULT_DmSQL.Select(cols).Updates(m).Error
  54. return
  55. }
  56. func (m *PptV2) Remove() (err error) {
  57. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), "ppt_id")
  58. err = global.DEFAULT_DmSQL.Exec(sql, m.PptId).Error
  59. return
  60. }
  61. func (m *PptV2) GetItemById(id int) (item *PptV2, err error) {
  62. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), "ppt_id")
  63. err = global.DEFAULT_DmSQL.Raw(sql, id).First(&item).Error
  64. return
  65. }
  66. func (m *PptV2) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *PptV2, err error) {
  67. order := ``
  68. if orderRule != "" {
  69. order = ` ORDER BY ` + orderRule
  70. }
  71. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  72. err = global.DEFAULT_DmSQL.Raw(sql, pars...).First(&item).Error
  73. return
  74. }
  75. func (m *PptV2) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*PptV2, err error) {
  76. fields := strings.Join(fieldArr, ",")
  77. if len(fieldArr) == 0 {
  78. fields = `*`
  79. }
  80. order := `ORDER BY create_time DESC`
  81. if orderRule != "" {
  82. order = ` ORDER BY ` + orderRule
  83. }
  84. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  85. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
  86. return
  87. }
  88. func (m *PptV2) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*PptV2, err error) {
  89. fields := strings.Join(fieldArr, ",")
  90. if len(fieldArr) == 0 {
  91. fields = `*`
  92. }
  93. order := `ORDER BY create_time DESC`
  94. if orderRule != "" {
  95. order = ` ORDER BY ` + orderRule
  96. }
  97. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  98. pars = append(pars, startSize, pageSize)
  99. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
  100. return
  101. }
  102. func (m *PptV2) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  103. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  104. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
  105. return
  106. }
  107. // PptReportQueryFields 除富文本的常用查询字段
  108. var PptReportQueryFields = []string{
  109. "ppt_id", "title", "classify_id", "ppt_version", "pptx_url", "ppt_page", "title_setting", "state", "report_source", "publish_time", "submit_time", "approve_time", "create_time", "modify_time", "admin_id", "collaborate_type", "collaborate_users",
  110. }