report_pdf.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package models
  2. import (
  3. "eta/eta_mini_api/utils"
  4. "fmt"
  5. "time"
  6. "github.com/beego/beego/v2/client/orm"
  7. )
  8. type ReportPdf struct {
  9. ReportPdfId int `orm:"pk" description:"id"`
  10. PdfUrl string `description:"pdf文件URL"`
  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:"状态:1-已发布;2-未发布"`
  28. }
  29. type ReportPdfView struct {
  30. ReportPdfId int `orm:"pk" description:"id"`
  31. PdfUrl string `description:"pdf文件URL"`
  32. Title string `description:"pdf文件标题"`
  33. Author string `description:"作者"`
  34. Abstract string `description:"摘要"`
  35. ClassifyIdFirst int `description:"一级分类id"`
  36. ClassifyNameFirst string `description:"一级分类名称"`
  37. ClassifyIdSecond int `description:"二级分类id"`
  38. ClassifyNameSecond string `description:"二级分类名称"`
  39. ClassifyIdThird int `description:"三级分类id"`
  40. ClassifyNameThird string `description:"三级分类名称"`
  41. Stage int `description:"期数"`
  42. PublishTime string `description:"发布时间"`
  43. ModifyTime string `description:"更新时间"`
  44. Pv int `description:"pv"`
  45. Uv int `description:"uv"`
  46. SysUserId int `description:"创建人id"`
  47. SysRealName string `description:"创建人姓名"`
  48. State int `description:"状态:1-已发布;2-未发布"`
  49. IsPublic bool `description:"是否公开"`
  50. IsCollect bool `description:"是否收藏"`
  51. }
  52. func GetRecentReportPdfList(startSize, pageSize int) (items []*ReportPdf, err error) {
  53. o := orm.NewOrm()
  54. sql := ` SELECT * FROM report_pdf WHERE state=1 ORDER BY publish_time DESC LIMIT ?,?`
  55. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  56. return
  57. }
  58. func GetReportPdfListByCondition(firstClassifyIds, secondClassifyIds, thirdClassifyIds []int, condition string, startSize, pageSize int) (reportPdfs []*ReportPdf, err error) {
  59. if len(firstClassifyIds) == 0 && len(secondClassifyIds) == 0 && len(thirdClassifyIds) == 0 {
  60. return
  61. }
  62. o := orm.NewOrm()
  63. sql := `SELECT * FROM report_pdf WHERE 1=1 AND (1=2`
  64. if len(firstClassifyIds) > 0 {
  65. sql += fmt.Sprintf(" OR classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(firstClassifyIds)))
  66. }
  67. if len(secondClassifyIds) > 0 {
  68. sql += fmt.Sprintf(" OR classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(secondClassifyIds)))
  69. }
  70. if len(thirdClassifyIds) > 0 {
  71. sql += fmt.Sprintf(" OR classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(thirdClassifyIds)))
  72. }
  73. sql += ")"
  74. if condition != "" {
  75. sql += condition
  76. }
  77. sql += ` ORDER BY publish_time DESC LIMIT ?,?`
  78. _, err = o.Raw(sql, firstClassifyIds, secondClassifyIds, thirdClassifyIds, startSize, pageSize).QueryRows(&reportPdfs)
  79. return
  80. }
  81. func GetReportPdfDailyList() (reportPdfs []*ReportPdf, err error) {
  82. o := orm.NewOrm()
  83. sql := `SELECT * FROM report_pdf WHERE 1=1 AND state=1 AND DATE(publish_time) = DATE(NOW()) ORDER BY publish_time DESC `
  84. _, err = o.Raw(sql).QueryRows(&reportPdfs)
  85. return
  86. }
  87. func GetReportPdfCountByCondition(firstClassifyIds, secondClassifyIds, thirdClassifyIds []int, condition string) (count int, err error) {
  88. if len(firstClassifyIds) == 0 && len(secondClassifyIds) == 0 && len(thirdClassifyIds) == 0 {
  89. return
  90. }
  91. o := orm.NewOrm()
  92. sql := `SELECT COUNT(*) AS count FROM report_pdf WHERE 1=1 AND (1=2 `
  93. if len(firstClassifyIds) > 0 {
  94. sql += fmt.Sprintf(" OR classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(firstClassifyIds)))
  95. }
  96. if len(secondClassifyIds) > 0 {
  97. sql += fmt.Sprintf(" OR classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(secondClassifyIds)))
  98. }
  99. if len(thirdClassifyIds) > 0 {
  100. sql += fmt.Sprintf(" OR classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(thirdClassifyIds)))
  101. }
  102. sql += ` )`
  103. if condition != "" {
  104. sql += condition
  105. }
  106. err = o.Raw(sql, firstClassifyIds, secondClassifyIds, thirdClassifyIds).QueryRow(&count)
  107. return
  108. }
  109. func GetReportPdfCountById(id int) (count int, err error) {
  110. o := orm.NewOrm()
  111. sql := `SELECT COUNT(*) AS count FROM report_pdf WHERE report_pdf_id = ? `
  112. err = o.Raw(sql, id).QueryRow(&count)
  113. return
  114. }
  115. func GetReportPdfById(id int) (item *ReportPdfView, err error) {
  116. o := orm.NewOrm()
  117. sql := `SELECT * FROM report_pdf WHERE report_pdf_id = ? `
  118. err = o.Raw(sql, id).QueryRow(&item)
  119. return
  120. }
  121. // 更新pv
  122. func UpdateReportPdfPv(id int) (err error) {
  123. o := orm.NewOrm()
  124. sql := `UPDATE report_pdf SET pv = pv + 1 WHERE report_pdf_id = ?`
  125. _, err = o.Raw(sql, id).Exec()
  126. return
  127. }
  128. // 更新uv和pv
  129. func UpdateReportPdfUvAndPv(id int) (err error) {
  130. o := orm.NewOrm()
  131. sql := `UPDATE report_pdf SET uv = uv + 1, pv = pv + 1 WHERE report_pdf_id = ?`
  132. _, err = o.Raw(sql, id).Exec()
  133. return
  134. }