bidcode.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package mapping
  2. import (
  3. "log"
  4. util "app.yhyue.com/moapp/jybase/common"
  5. "app.yhyue.com/moapp/jybase/mysql"
  6. )
  7. var BidCodeMapping = &bidCodeMapping{}
  8. type bidCodeMapping struct {
  9. Area map[string]string //省
  10. City map[string]string //市
  11. District map[string]map[string]string //市-区
  12. Toptype map[string]string //一级信息类型
  13. Subtype map[string]string //二级信息类型
  14. Buyerclass map[string]string //采购单位行业
  15. Subscopeclass map[string]string //信息行业
  16. }
  17. func (b *bidCodeMapping) Init(Mysql *mysql.Mysql) {
  18. b.Buyerclass = map[string]string{}
  19. codeBuyerclass := Mysql.SelectBySql("select code,name from global_common_data.code_buyerclass where level=1")
  20. if codeBuyerclass != nil && len(*codeBuyerclass) > 0 {
  21. for _, v := range *codeBuyerclass {
  22. code, _ := v["code"].(string)
  23. name, _ := v["name"].(string)
  24. b.Buyerclass[name] = code
  25. }
  26. }
  27. if len(b.Buyerclass) == 0 {
  28. log.Fatalln("PushMapping Buyerclass Init Error")
  29. }
  30. //
  31. b.Toptype = map[string]string{}
  32. b.Subtype = map[string]string{}
  33. codeBidTopSubtype := Mysql.SelectBySql("select code,name,level from global_common_data.code_bidtopsubtype")
  34. if codeBidTopSubtype != nil && len(*codeBidTopSubtype) > 0 {
  35. for _, v := range *codeBidTopSubtype {
  36. code, _ := v["code"].(string)
  37. name, _ := v["name"].(string)
  38. level := util.IntAll(v["level"])
  39. if level == 1 {
  40. b.Toptype[name] = code
  41. } else if level == 2 {
  42. b.Subtype[name] = code
  43. }
  44. }
  45. }
  46. if len(b.Toptype) == 0 {
  47. log.Fatalln("PushMapping Toptype Init Error")
  48. }
  49. if len(b.Subtype) == 0 {
  50. log.Fatalln("PushMapping Subtype Init Error")
  51. }
  52. //
  53. b.Subscopeclass = map[string]string{}
  54. codeBidScope := Mysql.SelectBySql("SELECT b.code,CONCAT(a.name,'_',b.name) as name FROM global_common_data.code_bidscope a INNER JOIN global_common_data.code_bidscope b ON (a.level=1 AND b.level=2 AND a.code=b.pcode)")
  55. if codeBidScope != nil && len(*codeBidScope) > 0 {
  56. for _, v := range *codeBidScope {
  57. code, _ := v["code"].(string)
  58. name, _ := v["name"].(string)
  59. b.Subscopeclass[name] = code
  60. }
  61. }
  62. if len(b.Subscopeclass) == 0 {
  63. log.Fatalln("PushMapping Subscopeclass Init Error")
  64. }
  65. //
  66. b.Area = map[string]string{}
  67. b.City = map[string]string{}
  68. b.District = map[string]map[string]string{}
  69. codeArea := Mysql.SelectBySql("select code,area,city,district from global_common_data.code_area")
  70. if codeArea != nil && len(*codeArea) > 0 {
  71. for _, v := range *codeArea {
  72. code, _ := v["code"].(string)
  73. area, _ := v["area"].(string)
  74. city, _ := v["city"].(string)
  75. district, _ := v["district"].(string)
  76. if area != "" && city == "" && district == "" {
  77. b.Area[area] = code
  78. } else if area != "" && city != "" && district == "" {
  79. b.City[city] = code
  80. } else if area != "" && city != "" && district != "" {
  81. if b.District[city] == nil {
  82. b.District[city] = map[string]string{}
  83. }
  84. b.District[city][district] = code
  85. }
  86. }
  87. }
  88. if len(b.Area) == 0 {
  89. log.Fatalln("BidCodeMapping Area Init Error")
  90. }
  91. if len(b.City) == 0 {
  92. log.Fatalln("BidCodeMapping City Init Error")
  93. }
  94. if len(b.District) == 0 {
  95. log.Fatalln("BidCodeMapping District Init Error")
  96. }
  97. }