report_cid.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package ugc
  2. import (
  3. "bytes"
  4. "context"
  5. "encoding/json"
  6. "fmt"
  7. "net/http"
  8. appDao "go-common/app/job/main/tv/dao/app"
  9. ugcmdl "go-common/app/job/main/tv/model/ugc"
  10. "go-common/library/log"
  11. "go-common/library/xstr"
  12. )
  13. const (
  14. _reported = 1
  15. _finishReport = "UPDATE ugc_video SET mark = %d WHERE cid IN (%s)"
  16. )
  17. // RepCidBatch reports cid info to VideoCloud api
  18. func (d *Dao) RepCidBatch(c context.Context, cidReq []*ugcmdl.CidReq) (err error) {
  19. var (
  20. reportURL = d.conf.UgcSync.Cfg.ReportCidURL
  21. resp = ugcmdl.CidResp{}
  22. jsonBody []byte
  23. )
  24. if jsonBody, err = json.Marshal(cidReq); err != nil {
  25. log.Error("json.Marchal(%v) error(%v)", cidReq, err)
  26. return
  27. }
  28. req, err := http.NewRequest(http.MethodPost, reportURL, bytes.NewBuffer(jsonBody))
  29. if err != nil {
  30. log.Error("http.NewRequest err - %v", err)
  31. return
  32. }
  33. if err = d.client.Do(c, req, &resp); err != nil {
  34. log.Error("ReportCid jsonBody (%s) error(%v)", string(jsonBody), err)
  35. return
  36. }
  37. if resp.Code != 0 {
  38. return fmt.Errorf("ReportCid Error Code:%d, Msg:%s", resp.Code, resp.Message)
  39. }
  40. appDao.PromInfo("ReportCid:Succ")
  41. return
  42. }
  43. // FinishReport change's the ugc_video's state from 0 to 1, means it has already been reported
  44. func (d *Dao) FinishReport(c context.Context, cids []int64) (err error) {
  45. if _, err = d.DB.Exec(c, fmt.Sprintf(_finishReport, _reported, xstr.JoinInts(cids))); err != nil {
  46. log.Error("FinishReport Error: %v", cids, err)
  47. }
  48. return
  49. }