my_report.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package models
  2. import (
  3. "time"
  4. "github.com/beego/beego/v2/client/orm"
  5. )
  6. type MyReport struct {
  7. MyReportId int `orm:"pk" description:"id"`
  8. ReportId int `description:"报告id"`
  9. UserId int `description:"用户id"`
  10. Title string `description:"标题"`
  11. Abstract string `description:"摘要"`
  12. Author string `description:"作者"`
  13. PublishTime time.Time `description:"发布时间"`
  14. Stage int `description:"期数"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ReportType int `description:"报告类型:1-普通研报;2-pdf研报"`
  17. }
  18. func (m *MyReport) Insert() (err error) {
  19. o := orm.NewOrm()
  20. _, err = o.Insert(m)
  21. return
  22. }
  23. func GetMyReportCountByUserIdAndReportId(userId, reportId, reportType int) (count int, err error) {
  24. o := orm.NewOrm()
  25. sql := `SELECT COUNT(*) AS count FROM my_report WHERE user_id = ? AND report_id = ? AND report_type = ? `
  26. err = o.Raw(sql, userId, reportId, reportType).QueryRow(&count)
  27. return
  28. }
  29. func DeleteMyReportByUserIdAndReportId(userId, reportId, reportType int) (err error) {
  30. o := orm.NewOrm()
  31. sql := "DELETE FROM my_report WHERE user_id = ? AND report_id = ? AND report_type = ?"
  32. _, err = o.Raw(sql, userId, reportId, reportType).Exec()
  33. return
  34. }
  35. func GetMyReportListCountByUserId(userId int) (count int, err error) {
  36. o := orm.NewOrm()
  37. sql := "SELECT COUNT(*) AS count FROM my_report WHERE user_id = ?"
  38. err = o.Raw(sql, userId).QueryRow(&count)
  39. return
  40. }
  41. func GetMyReportListByUserId(userId, startSize, pageSize int) (items []*MyReport, err error) {
  42. o := orm.NewOrm()
  43. sql := "SELECT * FROM my_report WHERE user_id = ? ORDER BY create_time DESC LIMIT ?, ?"
  44. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  45. return
  46. }