area.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Code generated by excel export. DO NOT EDIT.
  2. package data
  3. var Area = &areaConfig{}
  4. func init() {
  5. _allList = append(_allList, Area)
  6. }
  7. type (
  8. AreaRow struct {
  9. Pid int32 `json:"Pid"` // PID
  10. AreaID int32 `json:"AreaID"` // 大区ID
  11. AreaName string `json:"AreaName"` // 大区名
  12. Gate string `json:"Gate"` // 网关地址
  13. }
  14. areaConfig struct {
  15. baseConfig
  16. list []*AreaRow // all list
  17. pidListMaps map[int32][]*AreaRow // key:pid
  18. pidAreaIDUniMaps map[int32]map[int32]*AreaRow // key:pid, areaID
  19. }
  20. )
  21. func (p *areaConfig) Name() string {
  22. return "area"
  23. }
  24. func (p *areaConfig) Init() {
  25. p.pidListMaps = map[int32][]*AreaRow{}
  26. p.pidAreaIDUniMaps = map[int32]map[int32]*AreaRow{}
  27. }
  28. func (p *areaConfig) OnLoad(maps interface{}, reload bool) (int, error) {
  29. if reload && p.denyLoad {
  30. return 0, nil
  31. }
  32. var list []*AreaRow
  33. if err := DecodeData(maps, &list); err != nil {
  34. return 0, err
  35. }
  36. p.list = list
  37. pidListMaps := map[int32][]*AreaRow{}
  38. for _, row := range list {
  39. pidListMaps[row.Pid] = append(pidListMaps[row.Pid], row)
  40. }
  41. p.pidListMaps = pidListMaps
  42. pidAreaIDUniMaps := map[int32]map[int32]*AreaRow{}
  43. for _, row := range list {
  44. itemMap := pidAreaIDUniMaps[row.Pid]
  45. if itemMap == nil {
  46. itemMap = map[int32]*AreaRow{}
  47. pidAreaIDUniMaps[row.Pid] = itemMap
  48. }
  49. itemMap[row.AreaID] = row
  50. }
  51. p.pidAreaIDUniMaps = pidAreaIDUniMaps
  52. return len(list), nil
  53. }
  54. // func (p *areaConfig) OnAfterLoad(_ bool) {
  55. // }
  56. func (p *areaConfig) List() []*AreaRow {
  57. return p.list
  58. }
  59. func (p *areaConfig) ListByPid(pid int32) ([]*AreaRow, bool) {
  60. value, found := p.pidListMaps[pid]
  61. return value, found
  62. }
  63. func (p *areaConfig) ListContainPid(pid int32) bool {
  64. _, found := p.pidListMaps[pid]
  65. return found
  66. }
  67. func (p *areaConfig) GetByPidAreaID(pid int32, areaID int32) (*AreaRow, bool) {
  68. mapItem, found := p.pidAreaIDUniMaps[pid]
  69. if !found {
  70. return nil, false
  71. }
  72. value, found := mapItem[areaID]
  73. return value, found
  74. }
  75. func (p *areaConfig) ContainPidAreaID(pid int32, areaID int32) bool {
  76. mapItem, found := p.pidAreaIDUniMaps[pid]
  77. if !found {
  78. return false
  79. }
  80. _, found = mapItem[areaID]
  81. return found
  82. }