transfer.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/main/dm/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. )
  8. // AddTransferJob add job
  9. func (s *Service) AddTransferJob(c context.Context, from, to, mid int64, offset float64, state int8) (err error) {
  10. _, err = s.dao.InsertTransferJob(c, from, to, mid, offset, 0)
  11. if err != nil {
  12. log.Error("s.dao.InsertTransferJob(%d, %d %d %f) error(%v)", from, to, mid, offset, err)
  13. }
  14. return
  15. }
  16. // TransferList transfer list
  17. func (s *Service) TransferList(c context.Context, cid, state, pn, ps int64) (res []*model.TransList, total int64, err error) {
  18. var (
  19. aids []int64
  20. cids []int64
  21. )
  22. if res, total, err = s.dao.TransferList(c, cid, state, pn, ps); err != nil {
  23. log.Error("s.dao.TransferList(%d, %d) error(%v)", cid, state, err)
  24. return
  25. }
  26. if len(res) <= 0 {
  27. return
  28. }
  29. for _, idx := range res {
  30. cids = append(cids, idx.From)
  31. }
  32. subs, err := s.dao.Subjects(c, model.SubTypeVideo, cids)
  33. if err != nil {
  34. return
  35. }
  36. for _, idx := range subs {
  37. aids = append(aids, idx.Pid)
  38. }
  39. avm, err := s.dao.ArchiveVideos(c, aids)
  40. if err != nil {
  41. log.Error("s.dao.ArchiveInfo(aid:%v) error(%v)", aids, err)
  42. return
  43. }
  44. for _, idx := range res {
  45. sub, ok := subs[idx.From]
  46. if !ok {
  47. continue
  48. }
  49. info, ok := avm[sub.Pid] // get archive info
  50. if !ok {
  51. continue
  52. }
  53. idx.Title = info.Archive.Title
  54. }
  55. return
  56. }
  57. // ReTransferJob retransfer job
  58. func (s *Service) ReTransferJob(c context.Context, id, mid int64) (err error) {
  59. job, err := s.dao.CheckTransferID(c, id)
  60. if err != nil {
  61. log.Error("dao.CheckTransferID(%d) err(%v)", id, err)
  62. return
  63. }
  64. if job.State != model.TransferJobStatFailed || job.MID != mid {
  65. err = ecode.RequestErr
  66. return
  67. }
  68. _, err = s.dao.SetTransferState(c, id, model.TransferJobStatInit)
  69. if err != nil {
  70. log.Error("dao.SetTransferState(id:%d,state:%d) err(%v)", id, model.TransferJobStatInit, err)
  71. }
  72. return
  73. }