my_chart.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package models
  2. import (
  3. "time"
  4. "github.com/beego/beego/v2/client/orm"
  5. )
  6. type MyChart struct {
  7. MyChartId int `orm:"pk" description:"我的图表ID"`
  8. ChartName string `description:"图表名称"` // 图表名称
  9. UniqueCode string `description:"图表唯一编码"` // 图表唯一编码
  10. ChartImage string `description:"图表图片"` // 图表图片
  11. ChartInfoId int `description:"图表id"` // 图表图片
  12. UserId int `description:"用户ID"`
  13. UserRealName string `description:"用户真实姓名"` // 真实姓名
  14. CreateTime time.Time `description:"创建时间"`
  15. ModifyTime time.Time `description:"修改时间"`
  16. }
  17. func (m *MyChart) Insert() (err error) {
  18. o := orm.NewOrm()
  19. _, err = o.Insert(m)
  20. return
  21. }
  22. func GetMyChartCount(userId int, uniqueCode string) (count int, err error) {
  23. o := orm.NewOrm()
  24. sql := `SELECT COUNT(*) AS count FROM my_chart WHERE user_id=? AND unique_code=?`
  25. err = o.Raw(sql, userId, uniqueCode).QueryRow(&count)
  26. return
  27. }
  28. func GetMyChartListCountById(userId int) (count int, err error) {
  29. o := orm.NewOrm()
  30. sql := `SELECT COUNT(*) AS count FROM my_chart WHERE user_id=? `
  31. err = o.Raw(sql, userId).QueryRow(&count)
  32. return
  33. }
  34. func GetMyChartListById(userId int, startSize, pageSize int) (items []*MyChart, err error) {
  35. o := orm.NewOrm()
  36. sql := `SELECT * FROM my_chart WHERE user_id=? ORDER BY create_time DESC LIMIT ?,?`
  37. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  38. return
  39. }
  40. func DeleteMyChart(userId int, uniqueCode string) (err error) {
  41. o := orm.NewOrm()
  42. sql := `DELETE FROM my_chart WHERE user_id=? AND unique_code=?`
  43. _, err = o.Raw(sql, userId, uniqueCode).Exec()
  44. return
  45. }
  46. func DeleteMyChartByUserIdAndChartInfoId(userId int, chartInfoId int) (err error) {
  47. o := orm.NewOrm()
  48. sql := `DELETE FROM my_chart WHERE user_id=? AND chart_info_id=?`
  49. _, err = o.Raw(sql, userId, chartInfoId).Exec()
  50. return
  51. }