task_qa_video.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "strconv"
  6. "go-common/app/admin/main/videoup/model/archive"
  7. "go-common/library/log"
  8. )
  9. func (s *Service) fetchQAVideo(c context.Context, vp *archive.VideoParam) (task *archive.QAVideo, err error) {
  10. auditDetails, err := s.fetchVideoAuditDetail(c, vp.ID, vp.Aid, vp.Cid, vp.TaskID)
  11. if err != nil || auditDetails == nil {
  12. return nil, err
  13. }
  14. fans := int64(0)
  15. if auditDetails.UserInfo != nil && auditDetails.UserInfo["fans"] != nil {
  16. fanss := strconv.FormatFloat(auditDetails.UserInfo["fans"].(float64), 'f', 0, 64)
  17. if fans, err = strconv.ParseInt(fanss, 10, 64); err != nil {
  18. log.Error("fetchQAVideo strconv.ParseInt(%v) error(%v)", auditDetails.UserInfo["fans"], err)
  19. return
  20. }
  21. }
  22. video := auditDetails.Video
  23. details, err := json.Marshal(auditDetails)
  24. if err != nil {
  25. log.Error("fetchQAVideo json.Marshal(auditdetails) error(%v) aid(%d) cid(%d) details(%v)", err, vp.Aid, vp.Cid, auditDetails)
  26. return
  27. }
  28. auditSubmit := &archive.AuditSubmit{
  29. Encoding: strconv.Itoa(int(vp.Encoding)),
  30. Reason: vp.Reason,
  31. ReasonID: strconv.Itoa(int(vp.RegionID)),
  32. Note: vp.Note,
  33. }
  34. submit, err := json.Marshal(auditSubmit)
  35. if err != nil {
  36. log.Error("fetchQAVideo json.Marshal(auditsubmit) error(%v) aid(%d) cid(%d) submit(%s)", err, vp.Aid, vp.Cid, auditSubmit)
  37. return
  38. }
  39. task = &archive.QAVideo{
  40. UID: vp.UID,
  41. Oname: vp.Oname,
  42. AID: vp.Aid,
  43. CID: vp.Cid,
  44. TaskID: vp.TaskID,
  45. TagID: vp.TagID,
  46. ArcTitle: video.Title,
  47. ArcTypeid: video.Typeid,
  48. AuditStatus: vp.Status,
  49. AuditSubmit: string(submit),
  50. AuditDetails: string(details),
  51. MID: video.MID,
  52. UPGroups: s.getAllUPGroups(video.MID),
  53. Fans: fans,
  54. }
  55. return
  56. }
  57. func (s *Service) fetchVideoAuditDetail(c context.Context, vid, aid, cid, taskID int64) (dt *archive.AuditDetails, err error) {
  58. video, err := s.arc.VideoInfo(c, aid, cid)
  59. if err != nil {
  60. return nil, err
  61. }
  62. if video == nil {
  63. log.Error("fetchVideoAuditDetail video not exist, aid(%d) cid(%d)", aid, cid)
  64. return
  65. }
  66. video.XcodeStateName = archive.XcodeStateNames[video.XcodeState]
  67. if tp, exist := s.typeCache[int16(video.Typeid)]; exist {
  68. video.Typename = tp.Name
  69. }
  70. video.Cover = coverURL(video.Cover)
  71. relationVideo, err := s.arc.VideoRelated(c, aid)
  72. if err != nil {
  73. return nil, err
  74. }
  75. task, err := s.arc.TaskDispatchByID(c, taskID)
  76. if err != nil {
  77. return nil, err
  78. }
  79. userInfo, err := s.arc.GetUserCard(c, video.MID)
  80. if err != nil || len(userInfo) <= 0 {
  81. return nil, err
  82. }
  83. mosaic, err := s.arc.Mosaic(c, cid)
  84. if err != nil {
  85. return nil, err
  86. }
  87. watermark, err := s.arc.Watermark(c, video.MID)
  88. if err != nil {
  89. return nil, err
  90. }
  91. dt = &archive.AuditDetails{
  92. UserInfo: userInfo,
  93. RelationVideos: relationVideo,
  94. Task: []*archive.Task{task},
  95. Video: video,
  96. Watermark: watermark,
  97. Mosaic: mosaic,
  98. }
  99. return
  100. }
  101. func (s *Service) addQAVideo(c context.Context, task *archive.QAVideo) (err error) {
  102. if task == nil {
  103. return
  104. }
  105. var bs []byte
  106. if bs, err = json.Marshal(task); err != nil {
  107. log.Error("addQAVideo json.Marshal error(%v) task(%+v)", err, task)
  108. return
  109. }
  110. err = s.arc.SendQAVideoAdd(c, bs)
  111. return
  112. }