pushmapping.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package init
  2. import (
  3. util "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/mysql"
  5. "log"
  6. )
  7. var PushMapping = &pushMapping{}
  8. type pushMapping struct {
  9. Area map[string]int
  10. City map[string]int
  11. Toptype map[string]int
  12. Subtype map[string]int
  13. Buyerclass map[string]int
  14. Subscopeclass map[string]int
  15. }
  16. func (p *pushMapping) Init(Mysql *mysql.Mysql) {
  17. infotype := Mysql.SelectBySql("select id,type,name from infotype")
  18. p.Toptype = map[string]int{}
  19. p.Subtype = map[string]int{}
  20. p.Buyerclass = map[string]int{}
  21. p.Subscopeclass = map[string]int{}
  22. if infotype != nil && len(*infotype) > 0 {
  23. for _, v := range *infotype {
  24. id := util.IntAll(v["id"])
  25. tp := util.IntAll(v["type"])
  26. name := util.ObjToString(v["name"])
  27. if tp == 1 {
  28. p.Toptype[name] = id
  29. } else if tp == 2 {
  30. p.Subtype[name] = id
  31. } else if tp == 3 {
  32. p.Buyerclass[name] = id
  33. } else if tp == 4 {
  34. p.Subscopeclass[name] = id
  35. }
  36. }
  37. if len(p.Toptype) == 0 {
  38. log.Fatalln("PushMapping Toptype Init Error")
  39. }
  40. if len(p.Subtype) == 0 {
  41. log.Fatalln("PushMapping Subtype Init Error")
  42. }
  43. if len(p.Buyerclass) == 0 {
  44. log.Fatalln("PushMapping Buyerclass Init Error")
  45. }
  46. if len(p.Subscopeclass) == 0 {
  47. log.Fatalln("PushMapping Subscopeclass Init Error")
  48. }
  49. }
  50. //
  51. p.Area = map[string]int{}
  52. p.City = map[string]int{}
  53. province := Mysql.SelectBySql("select id,level,name from province")
  54. if province != nil && len(*province) > 0 {
  55. for _, v := range *province {
  56. id := util.IntAll(v["id"])
  57. level := util.IntAll(v["level"])
  58. name := util.ObjToString(v["name"])
  59. if level == 1 {
  60. p.Area[name] = id
  61. } else if level == 2 {
  62. p.City[name] = id
  63. }
  64. }
  65. if len(p.Area) == 0 {
  66. log.Fatalln("PushMapping Area Init Error")
  67. }
  68. if len(p.City) == 0 {
  69. log.Fatalln("PushMapping City Init Error")
  70. }
  71. }
  72. }