databus.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package model
  2. import (
  3. "encoding/json"
  4. "strings"
  5. )
  6. // Message ...
  7. type Message struct {
  8. Action string `json:"action"`
  9. Table string `json:"table"`
  10. New json.RawMessage `json:"new"`
  11. Old json.RawMessage `json:"old"`
  12. }
  13. // Season ...
  14. type Season struct {
  15. ID int `json:"id"`
  16. Title string `json:"title"`
  17. SeasonTitle string `json:"season_title"`
  18. Mode int `json:"mode"`
  19. Type int `json:"type"`
  20. Alias string `json:"alias"`
  21. AliasSearch string `json:"alias_search"`
  22. Brief string `json:"brief"`
  23. Evaluate string `json:"evaluate"`
  24. Actors string `json:"actors"`
  25. Staff string `json:"staff"`
  26. SquareCover string `json:"square_cover"`
  27. Cover string `json:"cover"`
  28. EpCover string `json:"epcover"`
  29. Area int `json:"area"`
  30. Ctime string `json:"ctime"`
  31. Mtime string `json:"mtime"`
  32. }
  33. // EsSeason ...
  34. type EsSeason struct {
  35. ID int `json:"id"`
  36. Title string `json:"title"`
  37. Alias string `json:"alias"`
  38. AliasSearch []string `json:"alias_search"`
  39. Actors []string `json:"actors"`
  40. }
  41. //EsFormat ...
  42. func (s *Season) EsFormat() (es *EsSeason) {
  43. es = &EsSeason{
  44. ID: s.ID,
  45. Title: s.Title,
  46. Alias: s.Alias,
  47. AliasSearch: make([]string, 0),
  48. Actors: make([]string, 0),
  49. }
  50. if s.AliasSearch != "" {
  51. es.AliasSearch = strings.Split(s.AliasSearch, ",")
  52. }
  53. if s.Actors != "" {
  54. for _, act := range strings.Split(s.Actors, "\n") {
  55. if act == "" {
  56. continue
  57. }
  58. act := strings.Split(act, ":")
  59. if len(act) > 0 {
  60. es.Actors = append(es.Actors, act[0])
  61. }
  62. }
  63. }
  64. return
  65. }
  66. // FieldDiff 检查指定字段是有变化
  67. func (s *Season) FieldDiff(season *Season) bool {
  68. return s.Title != season.Title ||
  69. s.Alias != season.Alias ||
  70. s.AliasSearch != season.AliasSearch ||
  71. s.Actors != season.Actors ||
  72. s.Mtime != season.Mtime
  73. }