track.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package service
  2. import (
  3. "context"
  4. "sort"
  5. "go-common/app/admin/main/videoup/model/archive"
  6. "go-common/app/admin/main/videoup/model/track"
  7. "go-common/library/log"
  8. )
  9. const (
  10. historyTimeMin = 0
  11. historyTimeMax = 0x7fffffffffffffff
  12. )
  13. // TrackArchive get archive list.
  14. func (s *Service) TrackArchive(c context.Context, aid int64) (archive []*track.Archive, err error) {
  15. if archive, err = s.track.ArchiveTrack(c, aid); err != nil {
  16. log.Error("s.track.ArchiveTrack(%d) error(%v)", aid, err)
  17. return
  18. }
  19. sort.Sort(track.Archives(archive))
  20. return
  21. }
  22. //TrackArchiveInfo 稿件信息追踪
  23. func (s *Service) TrackArchiveInfo(c context.Context, aid int64) (info *track.ArcTrackInfo, err error) {
  24. relation := [][]int{}
  25. editHistory, err := s.AllEditHistory(c, aid)
  26. if err != nil {
  27. log.Error("TrackArchiveInfo s.AllEditHistory(aid(%d)) error(%v)", aid, err)
  28. return
  29. }
  30. tr, err := s.TrackArchive(c, aid)
  31. if err != nil {
  32. log.Error("TrackArchiveInfo s.TrackArchive(aid(%d)) error(%v)", aid, err)
  33. return
  34. }
  35. //2个降序数组,track根据history聚合
  36. cpHistoryTime := []int64{historyTimeMax}
  37. for _, h := range editHistory {
  38. cpHistoryTime = append(cpHistoryTime, int64(h.ArcHistory.CTime))
  39. }
  40. cpHistoryTime = append(cpHistoryTime, historyTimeMin)
  41. index := 0
  42. histlen := len(cpHistoryTime) - 1
  43. for i := 1; i <= histlen; i++ {
  44. rela := []int{}
  45. for ; index < len(tr); index++ {
  46. t := int64(tr[index].Timestamp)
  47. if t >= cpHistoryTime[i] && t < cpHistoryTime[i-1] {
  48. rela = append(rela, index)
  49. continue
  50. }
  51. break
  52. }
  53. if i == histlen && len(rela) == 0 {
  54. continue
  55. }
  56. relation = append(relation, rela)
  57. }
  58. info = &track.ArcTrackInfo{
  59. EditHistory: editHistory,
  60. Track: tr,
  61. Relation: relation,
  62. }
  63. return
  64. }
  65. //TrackHistoryDetail 稿件某条编辑历史的详细情况
  66. func (s *Service) TrackHistoryDetail(c context.Context, hid int64) (h *archive.EditHistory, err error) {
  67. if h, err = s.EditHistory(c, hid); err != nil {
  68. log.Error("TrackHistoryDetail s.EditHistory(hid(%d)) error(%v)", hid, err)
  69. return
  70. }
  71. if h == nil {
  72. return
  73. }
  74. //获取最新的src_type
  75. cids := []int64{}
  76. for _, vh := range h.VHistory {
  77. cids = append(cids, vh.CID)
  78. }
  79. srcTypes, err := s.arc.VideoSrcTypeByIDs(c, cids)
  80. if err != nil {
  81. log.Error("TrackHistoryDetail s.arc.VideoSrcTypeByID(hid(%d)) error(%v)", hid, err)
  82. return
  83. }
  84. for _, vh := range h.VHistory {
  85. vh.SRCType = srcTypes[vh.CID]
  86. }
  87. return
  88. }
  89. // TrackVideo get video process.
  90. func (s *Service) TrackVideo(c context.Context, filename string, aid int64) (video []*track.Video, err error) {
  91. if video, err = s.track.VideoTrack(c, filename, aid); err != nil {
  92. log.Error("s.track.VideoTrack(%s) error(%v)", filename, err)
  93. return
  94. }
  95. //以下努力均为获取当时视频审核的属性
  96. vid, err := s.arc.VIDByAIDFilename(c, aid, filename)
  97. if err != nil {
  98. log.Error("s.arc.VIDByAIDFilename error(%v), filename(%s)", err, filename)
  99. return
  100. }
  101. if vid <= 0 {
  102. return
  103. }
  104. attrs, ctimes, err := s.arc.VideoOperAttrsCtimes(c, vid)
  105. if err != nil {
  106. log.Error("s.arc.VideoOperAttrsCtimes error(%v) vid(%d)", err, vid)
  107. return
  108. }
  109. for _, tk := range video {
  110. i := 0
  111. for ; i < len(attrs); i++ {
  112. if ctimes[i] > int64(tk.Timestamp) {
  113. continue
  114. }
  115. tk.Attribute = attrs[i]
  116. break
  117. }
  118. }
  119. return
  120. }