track.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "strconv"
  6. "go-common/app/job/main/videoup-report/model/archive"
  7. )
  8. func (s *Service) trackArchive(nw *archive.Archive, old *archive.Archive) (err error) {
  9. var (
  10. bs []byte
  11. remarks = make(map[string]string)
  12. )
  13. if addit, _ := s.arc.Addit(context.TODO(), nw.ID); addit != nil {
  14. remarks["dynamic"] = addit.Dynamic
  15. if addit.MissionID > 0 {
  16. remarks["mission_id"] = strconv.FormatInt(addit.MissionID, 10)
  17. }
  18. }
  19. if old == nil {
  20. remarks["cover"] = nw.Cover
  21. remarks["desc"] = nw.Content
  22. remarks["title"] = nw.Title
  23. remarks["typeid"] = strconv.Itoa(int(nw.TypeID))
  24. remarks["copyright"] = strconv.Itoa(int(nw.Copyright))
  25. bs, _ = json.Marshal(remarks)
  26. } else if nw.State != old.State || nw.Access != old.Access || nw.Round != old.Round || nw.Content != old.Content ||
  27. nw.Cover != old.Cover || nw.Title != old.Title || nw.TypeID != old.TypeID || nw.Copyright != old.Copyright || nw.Attribute != old.Attribute {
  28. if nw.Cover != old.Cover {
  29. remarks["cover"] = nw.Cover
  30. }
  31. if nw.Content != old.Content {
  32. remarks["desc"] = nw.Content
  33. }
  34. if nw.Title != old.Title {
  35. remarks["title"] = nw.Title
  36. }
  37. if nw.TypeID != old.TypeID {
  38. remarks["typeid"] = strconv.Itoa(int(nw.TypeID))
  39. }
  40. if nw.Copyright != old.Copyright {
  41. remarks["copyright"] = strconv.Itoa(int(nw.Copyright))
  42. }
  43. if len(remarks) != 0 {
  44. bs, _ = json.Marshal(remarks)
  45. }
  46. if nw.State >= int(archive.StateOpen) && nw.Access == int(archive.AccessMember) {
  47. nw.State = int(archive.AccessMember)
  48. }
  49. } else {
  50. // NOTE: nothing modify
  51. return
  52. }
  53. s.arc.AddTrack(context.TODO(), nw.ID, nw.State, nw.Round, nw.Attribute, string(bs), nw.MTime, nw.MTime)
  54. return
  55. }
  56. func (s *Service) trackVideo(nw *archive.Video, old *archive.Video) (err error) {
  57. var (
  58. remarks = make(map[string]interface{})
  59. bs []byte
  60. )
  61. if old == nil {
  62. if nw.Title != "" {
  63. remarks["title"] = nw.Title
  64. }
  65. if nw.Desc != "" {
  66. remarks["desc"] = nw.Desc
  67. }
  68. } else if nw.XcodeState != old.XcodeState || nw.Status != old.Status || nw.Title != old.Title || nw.Desc != old.Desc || nw.Attribute != old.Attribute {
  69. if nw.FailCode != archive.XcodeFailZero {
  70. remarks["xcode_fail"] = nw.FailCode
  71. }
  72. if nw.Title != old.Title && nw.Title != "" {
  73. remarks["title"] = nw.Title
  74. }
  75. if nw.Desc != old.Desc && nw.Desc != "" {
  76. remarks["desc"] = nw.Desc
  77. }
  78. } else {
  79. // no change
  80. return
  81. }
  82. if len(remarks) != 0 {
  83. bs, err = json.Marshal(remarks)
  84. }
  85. s.arc.AddVideoTrack(context.TODO(), nw.Aid, nw.Filename, nw.Status, nw.XcodeState, string(bs), nw.MTime, nw.MTime)
  86. return
  87. }