my_report.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. }
  17. func (m *MyReport) Insert() (err error) {
  18. o := orm.NewOrm()
  19. _, err = o.Insert(m)
  20. return
  21. }
  22. func GetMyReportCountByUserIdAndReportId(userId, reportId int) (count int, err error) {
  23. o := orm.NewOrm()
  24. sql := "SELECT COUNT(*) AS count FROM my_report WHERE user_id = ? AND report_id = ?"
  25. err = o.Raw(sql, userId, reportId).QueryRow(&count)
  26. return
  27. }
  28. func DeleteMyReportByUserIdAndReportId(userId, reportId int) (err error) {
  29. o := orm.NewOrm()
  30. sql := "DELETE FROM my_report WHERE user_id = ? AND report_id = ?"
  31. _, err = o.Raw(sql, userId, reportId).Exec()
  32. return
  33. }
  34. func GetMyReportListCountByUserId(userId int) (count int, err error) {
  35. o := orm.NewOrm()
  36. sql := "SELECT COUNT(*) AS count FROM my_report WHERE user_id = ?"
  37. err = o.Raw(sql, userId).QueryRow(&count)
  38. return
  39. }
  40. func GetMyReportListByUserId(userId, startSize, pageSize int) (items []*MyReport, err error) {
  41. o := orm.NewOrm()
  42. sql := "SELECT * FROM my_report WHERE user_id = ? ORDER BY create_time DESC LIMIT ?, ?"
  43. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  44. return
  45. }