manager.go 2.3 KB

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