speaker.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package yb
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // Speaker 活动表
  7. type Speaker struct {
  8. SpeakerId int `orm:"column(speaker_id);pk" description:"主讲人ID"`
  9. SpeakerName string `description:"主讲人"`
  10. SpeakerHeadPic string `description:"主讲人头像"`
  11. SpeakerBackgroundPic string `description:"主讲人背景图"`
  12. CreateTime time.Time `description:"创建时间"`
  13. ModifyTime time.Time `description:"更新时间"`
  14. }
  15. // TableName 表名变更
  16. func (speaker *Speaker) TableName() string {
  17. return "yb_speaker"
  18. }
  19. // AddSpeaker 新增主讲人
  20. func AddSpeaker(item *Speaker) (err error) {
  21. o := orm.NewOrm()
  22. lastId, err := o.Insert(item)
  23. item.SpeakerId = int(lastId)
  24. return
  25. }
  26. // UpdateReport 更新主讲人
  27. func (speaker *Speaker) Update(cols []string) (err error) {
  28. o := orm.NewOrm()
  29. _, err = o.Update(speaker, cols...)
  30. return
  31. }
  32. // GetSpeakerById 根据主键获取主讲人
  33. func GetSpeakerById(id int) (item *Speaker, err error) {
  34. o := orm.NewOrm()
  35. sql := `SELECT * FROM yb_speaker WHERE speaker_id = ? LIMIT 1`
  36. err = o.Raw(sql, id).QueryRow(&item)
  37. return
  38. }
  39. // GetSpeakerByName 根据姓名获取主讲人
  40. func GetSpeakerByName(name string) (item *Speaker, err error) {
  41. o := orm.NewOrm()
  42. sql := `SELECT * FROM yb_speaker WHERE speaker_name = ? LIMIT 1`
  43. err = o.Raw(sql, name).QueryRow(&item)
  44. return
  45. }
  46. // GetAllSpeakerList 获取所有主讲人列表数据
  47. func GetAllSpeakerList() (list []*Speaker, err error) {
  48. o := orm.NewOrm()
  49. sql := "select * from yb_speaker order by speaker_id desc "
  50. _, err = o.Raw(sql).QueryRows(&list)
  51. return
  52. }
  53. // GetSpeakerPageList 获取主讲人列表-分页
  54. func GetSpeakerPageList(cond string, pars []interface{}, startSize, pageSize int) (total int, list []*Speaker, err error) {
  55. o := orm.NewOrm()
  56. sql := `SELECT * FROM yb_speaker WHERE 1=1 `
  57. if cond != `` {
  58. sql += cond
  59. }
  60. sql += ` ORDER BY speaker_id DESC`
  61. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  62. if err = o.Raw(totalSql, pars).QueryRow(&total); err != nil {
  63. return
  64. }
  65. sql += ` LIMIT ?,?`
  66. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  67. return
  68. }
  69. // DelSpeaker 删除主讲人
  70. func DelSpeaker(speakerId int) (err error) {
  71. o := orm.NewOrm()
  72. sql := `DELETE FROM yb_speaker WHERE speaker_id = ? LIMIT 1`
  73. _, err = o.Raw(sql, speakerId).Exec()
  74. return
  75. }