qa_video.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "strconv"
  6. "time"
  7. "go-common/app/admin/main/videoup-task/dao"
  8. "go-common/app/admin/main/videoup-task/model"
  9. accmdl "go-common/app/service/main/account/model"
  10. "go-common/library/database/sql"
  11. "go-common/library/ecode"
  12. "go-common/library/log"
  13. "go-common/library/queue/databus/report"
  14. )
  15. //GetVideoList list qa video tasks
  16. func (s *Service) GetVideoList(ctx context.Context, pm *model.ListParams) (list *model.QAVideoList, err error) {
  17. var (
  18. listLen int
  19. detailMap map[int64]map[string]int64
  20. midList []int64
  21. users map[int64]*model.UserRole
  22. infos map[int64]*accmdl.Info
  23. upGroupList map[int64][]*model.UPGroup
  24. )
  25. if list, err = s.searchQAVideo(ctx, pm); err != nil || list == nil || len(list.Result) <= 0 {
  26. return
  27. }
  28. ids := make([]int64, listLen)
  29. uids := make([]int64, listLen)
  30. for _, item := range list.Result {
  31. ids = append(ids, item.ID)
  32. uids = append(uids, item.UID)
  33. }
  34. if detailMap, midList, err = s.dao.QAVideoDetail(ctx, ids); err != nil {
  35. return
  36. }
  37. if users, err = s.dao.GetUsernameAndRole(ctx, uids); err != nil {
  38. return
  39. }
  40. if infos, err = s.dao.AccountInfos(ctx, midList); err != nil {
  41. return
  42. }
  43. //获取列表页获取
  44. if upGroupList, err = s.dao.UPGroups(ctx, midList); err != nil {
  45. return
  46. }
  47. for _, item := range list.Result {
  48. item.User = users[item.UID]
  49. item.StateName = model.QAStates[item.State]
  50. item.UPName = ""
  51. dt, exist := detailMap[item.ID]
  52. if exist {
  53. item.DetailID = dt["detail_id"]
  54. item.TaskUTime = dt["task_utime"]
  55. item.MID = dt["mid"]
  56. item.UPGroupList = upGroupList[item.MID]
  57. if infos[item.MID] != nil {
  58. item.UPName = infos[item.MID].Name
  59. }
  60. }
  61. }
  62. return
  63. }
  64. //AddQATaskVideo add a qa video task
  65. func (s *Service) AddQATaskVideo(ctx context.Context, detail *model.AddVideoParams) (taskID int64, err error) {
  66. var vid int64
  67. if vid, err = s.dao.GetVID(ctx, detail.AID, detail.CID); err != nil {
  68. log.Error("AddQATaskVideo s.dao.GetVID(aid(%d), cid(%d)) error(%v)", detail.AID, detail.CID, err)
  69. return
  70. }
  71. if vid <= 0 {
  72. log.Error("AddQATaskVideo non-deleted video(aid(%d), cid(%d)) not exist", detail.AID, detail.CID)
  73. return
  74. }
  75. taskID, err = s.insertVideoTask(ctx, detail)
  76. return
  77. }
  78. func (s *Service) insertVideoTask(ctx context.Context, detail *model.AddVideoParams) (taskID int64, err error) {
  79. var (
  80. tx *sql.Tx
  81. detailID int64
  82. )
  83. defer func() {
  84. if msg := recover(); msg != nil {
  85. if tx != nil {
  86. tx.Rollback()
  87. }
  88. log.Error("insertVideoTask panic recover, msg(%s)", msg)
  89. }
  90. }()
  91. if tx, err = s.dao.BeginTran(ctx); err != nil {
  92. return
  93. }
  94. if detailID, err = s.dao.InsertQAVideo(tx, &detail.VideoDetail); err != nil {
  95. tx.Rollback()
  96. return
  97. }
  98. if taskID, err = s.dao.InTaskQA(tx, detail.OUID, detailID, model.QATypeVideo); err != nil {
  99. tx.Rollback()
  100. return
  101. }
  102. if err = tx.Commit(); err != nil {
  103. dao.PromeErr("arcdb: commit", "insertVideoTask commit error(%v) aid(%d) cid(%d)", err, detail.AID, detail.CID)
  104. }
  105. return
  106. }
  107. func (s *Service) getQATaskVideo(ctx context.Context, id int64, simple bool) (task *model.QATaskVideo, err error) {
  108. if simple {
  109. task, err = s.dao.QATaskVideoSimpleByID(ctx, id)
  110. } else {
  111. task, err = s.dao.QATaskVideoByID(ctx, id)
  112. }
  113. if err != nil {
  114. return
  115. }
  116. if task == nil {
  117. err = ecode.NothingFound
  118. return
  119. }
  120. task.GetAttributeList()
  121. return
  122. }
  123. //GetDetail get qa video task detail
  124. func (s *Service) GetDetail(ctx context.Context, id int64) (dt *model.TaskVideoDetail, err error) {
  125. var (
  126. taskVideo *model.QATaskVideo
  127. video *model.Video
  128. history []*model.VideoOperInfo
  129. )
  130. if taskVideo, err = s.getQATaskVideo(ctx, id, false); err != nil {
  131. return
  132. }
  133. info := &model.VideoTaskInfo{
  134. QATaskVideo: *taskVideo,
  135. }
  136. groups, _ := s.dao.UPGroups(ctx, []int64{taskVideo.MID})
  137. info.UPGroupList = groups[taskVideo.MID]
  138. info.GetWarnings()
  139. if video, err = s.getVideo(ctx, taskVideo.AID, taskVideo.CID); err != nil {
  140. return
  141. }
  142. if history, err = s.getVideoOperInfo(ctx, video.ID); err != nil {
  143. return
  144. }
  145. dt = &model.TaskVideoDetail{
  146. Task: info,
  147. Video: video,
  148. VideoHistory: history,
  149. }
  150. return
  151. }
  152. //QAVideoSubmit submit qa video task
  153. func (s *Service) QAVideoSubmit(ctx context.Context, username string, uid int64, vp *model.QASubmitParams) (err error) {
  154. var (
  155. task *model.QATaskVideo
  156. video *model.Video
  157. )
  158. if task, err = s.getQATaskVideo(ctx, vp.ID, true); err != nil {
  159. log.Error("QAVideoSubmit s.arc.QATaskVideoByID error(%v), id(%d) task(%+v)", err, vp.ID, task)
  160. return
  161. }
  162. if video, err = s.getVideo(ctx, task.AID, task.CID); err != nil {
  163. log.Error("sendLog s.getVideo error(%v) qa.id(%d) aid(%d) cid(%d)", err, vp.ID, task.AID, task.CID)
  164. return
  165. }
  166. //不重复质检
  167. if task.State == model.QAStateFinish {
  168. return
  169. }
  170. //更新task
  171. task.State = model.QAStateFinish
  172. task.FTime = time.Now()
  173. if _, err = s.dao.UpTask(ctx, vp.ID, task.State, task.FTime); err != nil {
  174. return
  175. }
  176. s.dao.AddVideoOper(ctx, task.AID, uid, video.ID, video.Attribute, video.Status, 0, fmt.Sprintf("一审任务质检TAG: [%s]", vp.QATag), vp.QaNote)
  177. s.sendLog(ctx, username, uid, video, task, vp)
  178. return
  179. }
  180. func (s *Service) sendLog(ctx context.Context, username string, uid int64, video *model.Video, task *model.QATaskVideo, vp *model.QASubmitParams) (err error) {
  181. var (
  182. note string
  183. taskUIDName string
  184. )
  185. if task == nil || len(task.AttributeList) == 0 {
  186. log.Error("sendLog task/task.attributelist not exist, task(%+v) params(%+v)", task, vp)
  187. return
  188. }
  189. if note, err = task.GetNote(); err != nil {
  190. log.Error("sendLog task.GetNote() error(%v), params(%+v)", err, vp)
  191. return
  192. }
  193. if vp.Norank == 1 {
  194. video.AttributeList["norank"] = 1
  195. }
  196. if vp.Nodynamic == 1 {
  197. video.AttributeList["nodynamic"] = 1
  198. }
  199. if vp.Norecommend == 1 {
  200. video.AttributeList["norecommend"] = 1
  201. }
  202. if vp.Nosearch == 1 {
  203. video.AttributeList["nosearch"] = 1
  204. }
  205. if vp.PushBlog == 1 {
  206. video.AttributeList["push_blog"] = 1
  207. }
  208. if vp.OverseaBlock == 1 {
  209. video.AttributeList["oversea_block"] = 1
  210. }
  211. video.TagID = vp.TagID
  212. video.Status = vp.AuditStatus
  213. video.Note = vp.Note
  214. video.Reason = vp.Reason
  215. video.Encoding = vp.Encoding
  216. if taskUIDNames, err := s.dao.GetUsername(ctx, []int64{task.UID}); err != nil {
  217. taskUIDName = ""
  218. err = nil
  219. } else {
  220. taskUIDName = taskUIDNames[task.UID]
  221. }
  222. content := map[string]interface{}{
  223. "audit_status": task.AuditStatus,
  224. "audit_attr": task.AttributeList,
  225. "audit_tag_id": task.TagID,
  226. "audit_note": note,
  227. "qa_status": video.Status,
  228. "qa_attr": video.AttributeList,
  229. "qa_tag_id": video.TagID,
  230. "qa_note": video.Note,
  231. }
  232. data := &report.ManagerInfo{
  233. Uname: username,
  234. UID: uid,
  235. Business: model.LogQATask,
  236. Type: model.LogQATaskVideo,
  237. Oid: vp.ID,
  238. Action: strconv.Itoa(int(video.Status)),
  239. Ctime: task.FTime,
  240. Index: []interface{}{task.TaskID, task.MID, task.CTime.Unix(), strconv.FormatInt(vp.QaTagID, 10), strconv.FormatInt(task.UID, 10), taskUIDName},
  241. Content: content,
  242. }
  243. report.Manager(data)
  244. log.Info(" sendLog data(%+v)", data)
  245. return
  246. }
  247. //UpVideoUTime update qa video task utime
  248. func (s *Service) UpVideoUTime(ctx context.Context, aid, cid, taskID, utime int64) (err error) {
  249. var id int64
  250. if id, err = s.dao.GetQAVideoID(ctx, aid, cid, taskID); err != nil {
  251. log.Error("UpVideoUTime s.dao.GetQAVideoID error(%v) aid(%d) cid(%d) taskid(%d) utime(%d)", err, aid, cid, taskID, utime)
  252. return
  253. }
  254. if id <= 0 {
  255. log.Error("UpVideoUTime s.dao.GetQAVideoID not found aid(%d) cid(%d) taskid(%d) utime(%d)", aid, cid, taskID, utime)
  256. err = ecode.RequestErr
  257. return
  258. }
  259. return s.dao.UpdateQAVideoUTime(ctx, aid, cid, taskID, utime)
  260. }
  261. func (s *Service) delProc() {
  262. var (
  263. err error
  264. qaVideoRows, qaTaskRows int64 = 1, 1
  265. limit = 1000
  266. )
  267. for {
  268. deadLine := time.Now().AddDate(0, -1, 0)
  269. for {
  270. if qaVideoRows > 0 {
  271. if qaVideoRows, err = s.dao.DelQAVideo(context.TODO(), deadLine, limit); err != nil {
  272. log.Error("delProc s.dao.DelQAVideo(%v,%d) error(%v)", deadLine, limit, err)
  273. }
  274. }
  275. if qaTaskRows > 0 {
  276. if qaTaskRows, err = s.dao.DelQATask(context.TODO(), deadLine, limit); err != nil {
  277. log.Error("delProc s.dao.DelQATask(%v,%d) error(%v)", deadLine, limit, err)
  278. }
  279. }
  280. if qaVideoRows+qaTaskRows == 0 {
  281. break
  282. }
  283. time.Sleep(time.Minute)
  284. }
  285. time.Sleep(time.Hour * 24)
  286. }
  287. }