video_upload_process.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/service/bbq/video/api/grpc/v1"
  6. "go-common/app/service/bbq/video/model"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. )
  10. const (
  11. insertOrUpdateVUP = "insert into video_upload_process (`svid`,`title`,`mid`,`upload_status`,`retry_times`,`home_img_url`,`home_img_width`,`home_img_height`) values(?,?,?,?,?,?,?,?) on duplicate key update `title` = values(`title`),`mid` = values(`mid`),`upload_status` = values(`upload_status`),`retry_times`= values(`retry_times`)"
  12. selectPrepareVUP = "select `svid`,`title`,`upload_status`,`home_img_url`,`home_img_height`,`home_img_width` from video_upload_process where mid=%d and is_deleted=0 and upload_status != 1 order by ctime desc limit 20"
  13. )
  14. //InsertOrUpdateVUP ..
  15. func (d *Dao) InsertOrUpdateVUP(c context.Context, vup *model.VideoUploadProcess) (err error) {
  16. if vup == nil {
  17. err = ecode.BBQSystemErr
  18. log.Errorw(c, "event", "InsertVUP req nil")
  19. return
  20. }
  21. if _, err = d.db.Exec(c, insertOrUpdateVUP, vup.SVID, vup.Title, vup.Mid, vup.UploadStatus, vup.RetryTimes, vup.HomeImgURL, vup.HomeImgWidth, vup.HomeImgHeight); err != nil {
  22. log.Errorw(c, "event", "InsertVR err", "err", err, "param", vup)
  23. return
  24. }
  25. return
  26. }
  27. // GetPrepareVUP 获取数据
  28. func (d *Dao) GetPrepareVUP(c context.Context, mid int64) (vups []*v1.UploadingVideo, err error) {
  29. querySQL := fmt.Sprintf(selectPrepareVUP, mid)
  30. rows, err := d.db.Query(c, querySQL)
  31. if err != nil {
  32. log.Errorw(c, "log", "get prepare vup fail", "mid", mid)
  33. return
  34. }
  35. defer rows.Close()
  36. for rows.Next() {
  37. vup := new(v1.UploadingVideo)
  38. if err = rows.Scan(&vup.Svid, &vup.Title, &vup.UploadStatus, &vup.HomeImgUrl, &vup.HomeImgHeight, &vup.HomeImgWidth); err != nil {
  39. log.Errorw(c, "log", "scan vup fail")
  40. return
  41. }
  42. vups = append(vups, vup)
  43. }
  44. return
  45. }