history.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package archive
  2. import "go-common/library/time"
  3. //ArcHistory 稿件的用户编辑历史
  4. type ArcHistory struct {
  5. ID int64 `json:"id"`
  6. AID int64 `json:"aid"`
  7. Title string `json:"title"`
  8. Tag string `json:"tag"`
  9. Content string `json:"content"`
  10. Cover string `json:"cover"`
  11. MID int64 `json:"mid"`
  12. CTime time.Time `json:"ctime"`
  13. }
  14. //VideoHistory 视频的用户编辑历史
  15. type VideoHistory struct {
  16. ID int64 `json:"id"`
  17. CID int64 `json:"cid"`
  18. EpTitle string `json:"eptitle"`
  19. Description string `json:"description"`
  20. Filename string `json:"filename"`
  21. SRCType string `json:"src_type"`
  22. CTime time.Time `json:"ctime"`
  23. }
  24. //EditHistory 一次完整的用户编辑历史
  25. type EditHistory struct {
  26. ArcHistory *ArcHistory `json:"arc_history"`
  27. VHistory []*VideoHistory `json:"v_history"`
  28. }
  29. func (ah *ArcHistory) diff(one *ArcHistory) (res *ArcHistory, diff bool) {
  30. if one == nil {
  31. res = ah
  32. diff = true
  33. return
  34. }
  35. res = &ArcHistory{
  36. ID: ah.ID,
  37. AID: ah.AID,
  38. CTime: ah.CTime,
  39. }
  40. if ah.Title != one.Title {
  41. res.Title = ah.Title
  42. diff = true
  43. }
  44. if ah.Tag != one.Tag {
  45. res.Tag = ah.Tag
  46. diff = true
  47. }
  48. if ah.Content != one.Content {
  49. res.Content = ah.Content
  50. diff = true
  51. }
  52. if ah.Cover != one.Cover {
  53. res.Cover = ah.Cover
  54. diff = true
  55. }
  56. if ah.MID != one.MID {
  57. res.MID = ah.MID
  58. diff = true
  59. }
  60. return
  61. }
  62. //Diff only show diff between next archive edit history
  63. func (eh *EditHistory) Diff(one *EditHistory) (res *EditHistory, diff bool) {
  64. if one == nil {
  65. res = eh
  66. diff = true
  67. return
  68. }
  69. var ah *ArcHistory
  70. vh := []*VideoHistory{}
  71. oldfs := map[string]int{}
  72. ah, diff = eh.ArcHistory.diff(one.ArcHistory)
  73. //show those whose filenames not exist in one
  74. for _, v := range one.VHistory {
  75. oldfs[v.Filename] = 1
  76. }
  77. for _, v := range eh.VHistory {
  78. if oldfs[v.Filename] != 1 {
  79. vh = append(vh, v)
  80. diff = true
  81. }
  82. }
  83. res = &EditHistory{
  84. ArcHistory: ah,
  85. VHistory: vh,
  86. }
  87. return
  88. }