manager.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package manager
  2. import (
  3. "encoding/json"
  4. "go-common/library/log"
  5. xtime "go-common/library/time"
  6. "go-common/library/xstr"
  7. )
  8. // Relate struct
  9. type Relate struct {
  10. ID int64 `json:"id,omitempty"`
  11. Param int64 `json:"param,omitempty"`
  12. Goto string `json:"goto,omitempty"`
  13. Title string `json:"title,omitempty"`
  14. ResourceIDs string `json:"resource_ids,omitempty"`
  15. TagIDs string `json:"tag_ids,omitempty"`
  16. ArchiveIDs string `json:"archive_ids,omitempty"`
  17. RecReason string `json:"rec_reason,omitempty"`
  18. Position int `json:"position,omitempty"`
  19. STime xtime.Time `json:"stime,omitempty"`
  20. ETime xtime.Time `json:"etime,omitempty"`
  21. PlatVer json.RawMessage `json:"plat_ver,omitempty"`
  22. Versions map[int8][]*Version `json:"versions,omitempty"`
  23. Aids map[int64]struct{}
  24. Tids map[int64]struct{}
  25. Rids map[int64]struct{}
  26. }
  27. // Version struct
  28. type Version struct {
  29. Plat int8 `json:"plat,omitempty"`
  30. Build int `json:"build,omitempty"`
  31. Condition string `json:"conditions,omitempty"`
  32. }
  33. // Change is.
  34. func (r *Relate) Change() {
  35. var (
  36. vs []*Version
  37. err error
  38. )
  39. if r.ArchiveIDs != "" {
  40. var aids []int64
  41. if aids, err = xstr.SplitInts(r.ArchiveIDs); err != nil {
  42. log.Error("xstr.SplitInts(%s) error(%v)", r.ArchiveIDs, err)
  43. return
  44. }
  45. r.Aids = make(map[int64]struct{}, len(aids))
  46. for _, aid := range aids {
  47. r.Aids[aid] = struct{}{}
  48. }
  49. }
  50. if r.TagIDs != "" {
  51. var tids []int64
  52. if tids, err = xstr.SplitInts(r.TagIDs); err != nil {
  53. log.Error("xstr.SplitInts(%s) error(%v)", r.TagIDs, err)
  54. return
  55. }
  56. r.Tids = make(map[int64]struct{}, len(tids))
  57. for _, tid := range tids {
  58. r.Tids[tid] = struct{}{}
  59. }
  60. }
  61. if r.ResourceIDs != "" {
  62. var rids []int64
  63. if rids, err = xstr.SplitInts(r.ResourceIDs); err != nil {
  64. log.Error("xstr.SplitInts(%s) error(%v)", r.ResourceIDs, err)
  65. return
  66. }
  67. r.Rids = make(map[int64]struct{}, len(rids))
  68. for _, rid := range rids {
  69. r.Rids[rid] = struct{}{}
  70. }
  71. }
  72. if err = json.Unmarshal(r.PlatVer, &vs); err != nil {
  73. log.Error("json.Unmarshal(%s) error(%v)", r.PlatVer, err)
  74. return
  75. }
  76. vm := make(map[int8][]*Version, len(vs))
  77. for _, v := range vs {
  78. vm[v.Plat] = append(vm[v.Plat], v)
  79. }
  80. r.Versions = vm
  81. }