video_repository.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/bbq/video/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. )
  8. const (
  9. insertVR = "insert into video_repository (`cid`,`svid`,`mid`,`title`,`from`,`sync_status`) values (?,?,?,?,?,?)"
  10. updateVRSyncStatus = "update video_repository set sync_status = ?"
  11. queryVRBySvid = "select `title`,`mid`,`home_img_url`,`home_img_width`,`home_img_height` from video_repository where svid = ?"
  12. )
  13. //InsertVR ..
  14. func (d *Dao) InsertVR(c context.Context, vr *model.VideoRepository) (err error) {
  15. if vr == nil {
  16. err = ecode.BBQSystemErr
  17. log.Errorw(c, "event", "InsertVR req nil")
  18. return
  19. }
  20. if _, err = d.cmsdb.Exec(c, insertVR, vr.SVID, vr.SVID, vr.MID, vr.Title, vr.From,
  21. vr.SyncStatus); err != nil {
  22. log.Errorw(c, "event", "InsertVR err", "err", err, "param", vr)
  23. return
  24. }
  25. return
  26. }
  27. //UpdateVR ..
  28. func (d *Dao) UpdateVR(c context.Context, vr *model.VideoRepository) (err error) {
  29. if vr == nil {
  30. err = ecode.BBQSystemErr
  31. log.Errorw(c, "event", "InsertVR req nil")
  32. return
  33. }
  34. if _, err = d.cmsdb.Exec(c, updateVRSyncStatus, vr.SyncStatus); err != nil {
  35. log.Errorw(c, "event", "UpdateVR err", "err", err, "param", vr)
  36. return
  37. }
  38. return
  39. }
  40. //QueryVR ..
  41. func (d *Dao) QueryVR(c context.Context, vr *model.VideoRepository) (res *model.VideoRepository, err error) {
  42. if vr == nil {
  43. err = ecode.BBQSystemErr
  44. log.Errorw(c, "event", "InsertVR req nil")
  45. return
  46. }
  47. res = new(model.VideoRepository)
  48. if err = d.cmsdb.QueryRow(c, queryVRBySvid, vr.SVID).Scan(&res.Title, &res.MID, &res.HomeImgURL, &res.HomeImgWidth, &res.HomeImgHeight); err != nil {
  49. log.Errorw(c, "event", "queryVR scan err", "err", err, "param", vr)
  50. return
  51. }
  52. return
  53. }
  54. //HomeImgCreate ..
  55. func (d *Dao) HomeImgCreate(c context.Context, vr *model.VideoRepository) (err error) {
  56. if vr == nil {
  57. err = ecode.BBQSystemErr
  58. log.Errorw(c, "event", "HomeImgCreate req nil")
  59. return
  60. }
  61. if _, err = d.cmsdb.Exec(c, "update video_repository set home_img_url = ?,home_img_width = ? ,home_img_height = ? where svid = ? and mid = ?",
  62. vr.HomeImgURL, vr.HomeImgWidth, vr.HomeImgHeight, vr.SVID, vr.MID); err != nil {
  63. log.Errorw(c, "update home_img err", "err", err, "param", vr)
  64. return
  65. }
  66. return
  67. }