history.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/main/videoup/model/archive"
  5. "go-common/library/log"
  6. "time"
  7. )
  8. //EditHistory 根据稿件的某条编辑历史id,获取当时完整的稿件、分p视频编辑历史
  9. func (s *Service) EditHistory(c context.Context, hid int64) (h *archive.EditHistory, err error) {
  10. arcHistory, err := s.arc.HistoryByID(c, hid)
  11. if err != nil {
  12. log.Error("EditHistory s.arc.HistoryByID(hid(%d)) error(%v)", hid, err)
  13. return nil, err
  14. }
  15. vHistory, err := s.arc.VideoHistoryByHID(c, hid)
  16. if err != nil {
  17. log.Error("EditHistory s.arc.VideoHistoryByHID(hid(%d)) error(%v)", hid, err)
  18. return nil, err
  19. }
  20. h = &archive.EditHistory{
  21. ArcHistory: arcHistory,
  22. VHistory: vHistory,
  23. }
  24. return
  25. }
  26. //AllEditHistory 根据aid获取 其所有的用户编辑历史
  27. func (s *Service) AllEditHistory(c context.Context, aid int64) (hs []*archive.EditHistory, err error) {
  28. stime := time.Now().Add(time.Hour * 720 * -1)
  29. arcHistory, err := s.arc.HistoryByAID(c, aid, stime)
  30. if err != nil {
  31. log.Error("AllEditHistory s.arc.HistoryByAID(aid(%d)) error(%v)", aid, err)
  32. hs = []*archive.EditHistory{}
  33. return
  34. }
  35. var (
  36. videoHistory []*archive.VideoHistory
  37. prev *archive.EditHistory
  38. total int
  39. )
  40. total = len(arcHistory)
  41. hs = make([]*archive.EditHistory, total)
  42. for i := total - 1; i >= 0; i-- {
  43. h := arcHistory[i]
  44. videoHistory, err = s.arc.VideoHistoryByHID(c, h.ID)
  45. if err != nil {
  46. log.Error("AllEditHistory s.arc.VideoHistoryByHID(hid(%d), aid(%d)) error(%v)", h.ID, aid, err)
  47. return
  48. }
  49. one := &archive.EditHistory{
  50. ArcHistory: h,
  51. VHistory: videoHistory,
  52. }
  53. //only show diff between next edit archive
  54. show, diff := one.Diff(prev)
  55. hs[i] = show
  56. if diff {
  57. prev = one
  58. }
  59. }
  60. return
  61. }