report_pdf.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package models
  2. import (
  3. "eta/eta_mini_crm_ht/utils"
  4. "time"
  5. "github.com/beego/beego/v2/client/orm"
  6. )
  7. type ReportPdf struct {
  8. ReportPdfId int `orm:"pk" description:"id"`
  9. PdfUrl string `description:"pdf文件URL"`
  10. PdfName string `description:"pdf文件名称"`
  11. Title string `description:"pdf文件标题"`
  12. Author string `description:"作者"`
  13. Abstract string `description:"摘要"`
  14. ClassifyIdFirst int `description:"一级分类id"`
  15. ClassifyNameFirst string `description:"一级分类名称"`
  16. ClassifyIdSecond int `description:"二级分类id"`
  17. ClassifyNameSecond string `description:"二级分类名称"`
  18. ClassifyIdThird int `description:"三级分类id"`
  19. ClassifyNameThird string `description:"三级分类名称"`
  20. Stage int `description:"期数"`
  21. PublishTime time.Time `description:"发布时间"`
  22. ModifyTime time.Time `description:"更新时间"`
  23. Pv int `description:"pv"`
  24. Uv int `description:"uv"`
  25. SysUserId int `description:"创建人id"`
  26. SysRealName string `description:"创建人姓名"`
  27. State int `description:"状态"`
  28. }
  29. type ReportPdfView struct {
  30. ReportPdfId int `orm:"pk" description:"id"`
  31. PdfUrl string `description:"pdf文件URL"`
  32. PdfName string `description:"pdf文件名称"`
  33. Title string `description:"pdf文件标题"`
  34. Author string `description:"作者"`
  35. Abstract string `description:"摘要"`
  36. ClassifyIdFirst int `description:"一级分类id"`
  37. ClassifyNameFirst string `description:"一级分类名称"`
  38. ClassifyIdSecond int `description:"二级分类id"`
  39. ClassifyNameSecond string `description:"二级分类名称"`
  40. ClassifyIdThird int `description:"三级分类id"`
  41. ClassifyNameThird string `description:"三级分类名称"`
  42. Stage int `description:"期数"`
  43. PublishTime string `description:"发布时间"`
  44. ModifyTime time.Time `description:"更新时间"`
  45. Pv int `description:"pv"`
  46. Uv int `description:"uv"`
  47. SysUserId int `description:"创建人id"`
  48. SysRealName string `description:"创建人姓名"`
  49. State int `description:"状态"`
  50. }
  51. func (r *ReportPdf) Insert() (insertId int64, err error) {
  52. o := orm.NewOrm()
  53. // 计算研报期数
  54. sql := `SELECT MAX(stage) + 1 AS count FROM report_pdf WHERE classify_id_second=?`
  55. err = o.Raw(sql, r.ClassifyIdSecond).QueryRow(&r.Stage)
  56. if r.Stage == 0 {
  57. r.Stage = 1
  58. }
  59. if err != nil {
  60. return
  61. }
  62. insertId, err = o.Insert(r)
  63. return
  64. }
  65. func (r *ReportPdf) ToView() (item *ReportPdfView) {
  66. item = new(ReportPdfView)
  67. item.ReportPdfId = r.ReportPdfId
  68. item.PdfUrl = r.PdfUrl
  69. item.PdfName = r.PdfName
  70. item.Title = r.Title
  71. item.Author = r.Author
  72. item.Abstract = r.Abstract
  73. item.ClassifyIdFirst = r.ClassifyIdFirst
  74. item.ClassifyNameFirst = r.ClassifyNameFirst
  75. item.ClassifyIdSecond = r.ClassifyIdSecond
  76. item.ClassifyNameSecond = r.ClassifyNameSecond
  77. item.Stage = r.Stage
  78. item.State = r.State
  79. item.PublishTime = r.PublishTime.Format(utils.FormatDateTime)
  80. item.ModifyTime = r.ModifyTime
  81. item.Pv = r.Pv
  82. item.Uv = r.Uv
  83. item.SysUserId = r.SysUserId
  84. item.SysRealName = r.SysRealName
  85. return
  86. }
  87. func (r *ReportPdf) Update(cols []string) (err error) {
  88. o := orm.NewOrm()
  89. _, err = o.Update(r, cols...)
  90. return
  91. }
  92. func (r *ReportPdf) Delete() (err error) {
  93. o := orm.NewOrm()
  94. _, err = o.Delete(r)
  95. return
  96. }
  97. func GetReportPdfCountByCondition(condition string, pars []interface{}) (count int, err error) {
  98. o := orm.NewOrm()
  99. sql := `SELECT COUNT(*) AS count FROM report_pdf WHERE 1=1 `
  100. if condition != "" {
  101. sql += condition
  102. }
  103. err = o.Raw(sql, pars).QueryRow(&count)
  104. return
  105. }
  106. func GetReportPdfByCondition(condition, sortCondition string, pars []interface{}, startPage, pageSize int) (items []*ReportPdf, err error) {
  107. o := orm.NewOrm()
  108. sql := `SELECT * FROM report_pdf WHERE 1=1 `
  109. if condition != "" {
  110. sql += condition
  111. }
  112. if sortCondition != "" {
  113. sql += sortCondition // 排序
  114. }
  115. sql += ` LIMIT ?,?`
  116. _, err = o.Raw(sql, pars, startPage, pageSize).QueryRows(&items)
  117. return
  118. }
  119. func GetReportPdfById(id int) (item *ReportPdf, err error) {
  120. o := orm.NewOrm()
  121. sql := `SELECT * FROM report_pdf WHERE report_pdf_id=?`
  122. err = o.Raw(sql, id).QueryRow(&item)
  123. return
  124. }