databus.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package ugc
  2. import (
  3. "time"
  4. arcmdl "go-common/app/service/main/archive/api"
  5. )
  6. // ArcMsg reprensents the archive Notify-T message structure
  7. type ArcMsg struct {
  8. Action string `json:"action"`
  9. Table string `json:"table"`
  10. Old *ArchDatabus `json:"old"`
  11. New *ArchDatabus `json:"new"`
  12. }
  13. // ArchDatabus model ( we pick the fields that we need )
  14. type ArchDatabus struct {
  15. Aid int64 `json:"aid"`
  16. Mid int64 `json:"mid"`
  17. TypeID int32 `json:"typeid"`
  18. Videos int64 `json:"videos"`
  19. Duration int `json:"duration"`
  20. Title string `json:"title"`
  21. Cover string `json:"cover"`
  22. Content string `json:"content"`
  23. Attribute int32 `json:"attribute"`
  24. Copyright int32 `json:"copyright"`
  25. State int32 `json:"state"`
  26. Access int `json:"access"`
  27. PubTime string `json:"pubtime"`
  28. }
  29. // VideoDiff reprensents the result of videos comparison
  30. type VideoDiff struct {
  31. Aid int64
  32. Equal []int64 // totally equal
  33. New []int64 // new added videos
  34. Updated []*arcmdl.Page
  35. Removed []int64
  36. }
  37. // DatabusVideo is the struct of message for the modification of ugc_Video
  38. type DatabusVideo struct {
  39. New *MarkVideo `json:"new"`
  40. Old *MarkVideo `json:"old"`
  41. }
  42. // DatabusArc is the struct of message for the modification of ugc_archive
  43. type DatabusArc struct {
  44. Old *MarkArc `json:"old"`
  45. New *MarkArc `json:"new"`
  46. }
  47. // MarkVideo contains the main fields that we want to pick up from databus message
  48. type MarkVideo struct {
  49. Mark int `json:"mark"`
  50. Deleted int `json:"deleted"`
  51. CID int64 `json:"cid"`
  52. AID int64 `json:"aid"`
  53. EPTitle string `json:"eptitle"`
  54. IndexOrder int `json:"index_order"`
  55. Valid int `json:"valid"`
  56. Result int `json:"result"`
  57. Submit int `json:"submit"`
  58. Transcoded int `json:"transcoded"`
  59. Retry int64 `json:"retry"`
  60. }
  61. // MarkArc contains the main fields that we want to pick up from databus message
  62. type MarkArc struct {
  63. ID int `json:"id"`
  64. AID int64 `json:"aid"`
  65. MID int `json:"mid"`
  66. TypeID int32 `json:"typeid"`
  67. Videos int `json:"videos"`
  68. Title string `json:"title"`
  69. Cover string `json:"cover"`
  70. Content string `json:"content"`
  71. Duration int `json:"duration"`
  72. Copyright int `json:"copyright"`
  73. Pubtime string `json:"pubtime"`
  74. Ctime string `json:"ctime"`
  75. Mtime string `json:"mtime"`
  76. State int `json:"state"`
  77. Manual int `json:"manual"`
  78. Valid int `json:"valid"`
  79. Submit int `json:"submit"`
  80. Retry int `json:"retry"`
  81. Result int `json:"result"`
  82. Deleted int `json:"deleted"`
  83. InjectTime string `json:"inject_time"`
  84. Reason string `json:"reason"`
  85. }
  86. // IsPass returns whether the arc is able to play
  87. func (a MarkArc) IsPass() bool {
  88. return a.Deleted == 0 && a.Valid == 1 && a.Result == 1
  89. }
  90. // CidReq reprensents the structure for reporting cid
  91. type CidReq struct {
  92. CID int64 `json:"cid"`
  93. }
  94. // CidResp represents the structure of cid reporting API's response
  95. type CidResp struct {
  96. Code int `json:"code"`
  97. Message string `json:"message"`
  98. }
  99. // ToReport distinguishes whether the CID need to be reported to video cloud
  100. func (vm *MarkVideo) ToReport(criCID int64) bool {
  101. return vm.Deleted == 0 && vm.Mark == 0 && vm.CID > criCID
  102. }
  103. // ToAudit distinguishes whether the CID need to be reported to the license owner
  104. func (vm *MarkVideo) ToAudit(criCID int64) bool {
  105. return vm.Submit == 1 && (vm.Transcoded == 1 || vm.CID <= criCID) && vm.Retry < time.Now().Unix() && vm.Deleted == 0
  106. }
  107. // CanPlay tells whether a video can play or not
  108. func (vm *MarkVideo) CanPlay() bool {
  109. return vm.Result == 1 && vm.Deleted == 0 && vm.Valid == 1
  110. }
  111. // ToCMS transforms a databus video to CMS info
  112. func (vm *MarkVideo) ToCMS() *VideoCMS {
  113. return &VideoCMS{
  114. CID: int(vm.CID),
  115. Title: vm.EPTitle,
  116. AID: int(vm.AID),
  117. IndexOrder: vm.IndexOrder,
  118. Valid: vm.Valid,
  119. Deleted: vm.Deleted,
  120. Result: vm.Result,
  121. }
  122. }