bgm.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package income
  2. import (
  3. "context"
  4. "fmt"
  5. model "go-common/app/job/main/growup/model/income"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _insertBGMSQL = "INSERT INTO background_music(mid,sid,aid,cid,join_at,title) VALUES %s"
  10. _getBGMSQL = "SELECT id,mid,sid,aid,cid,join_at FROM background_music WHERE id > ? ORDER BY id LIMIT ?"
  11. _delBGMSQL = "DELETE FROM background_music LIMIT ?"
  12. )
  13. // InsertBGM insert bgm from data platform
  14. func (d *Dao) InsertBGM(c context.Context, values string) (rows int64, err error) {
  15. res, err := d.db.Exec(c, fmt.Sprintf(_insertBGMSQL, values))
  16. if err != nil {
  17. log.Error("insert bgm error(%v)", err)
  18. return
  19. }
  20. return res.RowsAffected()
  21. }
  22. // GetBGM get bgms
  23. func (d *Dao) GetBGM(c context.Context, id int64, limit int64) (bs []*model.BGM, last int64, err error) {
  24. rows, err := d.db.Query(c, _getBGMSQL, id, limit)
  25. if err != nil {
  26. return
  27. }
  28. defer rows.Close()
  29. for rows.Next() {
  30. b := &model.BGM{}
  31. err = rows.Scan(&last, &b.MID, &b.SID, &b.AID, &b.CID, &b.JoinAt)
  32. if err != nil {
  33. return
  34. }
  35. bs = append(bs, b)
  36. }
  37. return
  38. }
  39. // DelBGM del bgm
  40. func (d *Dao) DelBGM(c context.Context, limit int64) (rows int64, err error) {
  41. res, err := d.db.Exec(c, _delBGMSQL, limit)
  42. if err != nil {
  43. log.Error("del bgm error(%v)", err)
  44. return
  45. }
  46. return res.RowsAffected()
  47. }