pushmapping.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package init
  2. import (
  3. util "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/mysql"
  5. "bp.jydev.jianyu360.cn/BaseService/jyCodeService/rpc/codeservice/codeservice"
  6. "fmt"
  7. "log"
  8. )
  9. var PushMapping = &codeservice.TypeStruct{}
  10. const (
  11. CODEAREA = "code_area"
  12. CODEBIDSCOPE = "code_bidscope"
  13. CODEBIDTOPSUBTYPE = "code_bidtopsubtype"
  14. CODEBUYERCLASS = "code_buyerclass"
  15. )
  16. func Init(Mysql *mysql.Mysql) {
  17. //信息类型
  18. infotype := Mysql.SelectBySql(fmt.Sprintf("select level,code,name from %s where level=2", CODEBIDTOPSUBTYPE))
  19. Subtype := map[string]string{}
  20. if infotype != nil && len(*infotype) > 0 {
  21. for _, v := range *infotype {
  22. code := util.ObjToString(v["code"])
  23. name := util.ObjToString(v["name"])
  24. Subtype[name] = code
  25. }
  26. if len(Subtype) == 0 {
  27. log.Fatalln("PushMapping Subtype Init Error")
  28. }
  29. PushMapping.Subtype = Subtype
  30. }
  31. //采购单位行业
  32. Buyerclass := map[string]string{}
  33. buyerclass := Mysql.SelectBySql(fmt.Sprintf("select code,name from %s where level=1", CODEBUYERCLASS))
  34. if buyerclass != nil && len(*buyerclass) > 0 {
  35. for _, v := range *buyerclass {
  36. code := util.ObjToString(v["code"])
  37. name := util.ObjToString(v["name"])
  38. Buyerclass[name] = code
  39. }
  40. if len(Buyerclass) == 0 {
  41. log.Fatalln("PushMapping Buyerclass Init Error")
  42. }
  43. PushMapping.Buyerclass = Buyerclass
  44. }
  45. //公告类型处理
  46. Subscopeclass := map[string]string{}
  47. subscopeclass := Mysql.SelectBySql(fmt.Sprintf("select a.code, CONCAT(b.name,'_',a.name) as name from %s a LEFT JOIN %s b on a.pcode=b.code where a.level=2", CODEBIDSCOPE, CODEBIDSCOPE))
  48. if subscopeclass != nil && len(*subscopeclass) > 0 {
  49. for _, v := range *subscopeclass {
  50. code := util.ObjToString(v["code"])
  51. name := util.ObjToString(v["name"])
  52. Subscopeclass[name] = code
  53. }
  54. if len(Subscopeclass) == 0 {
  55. log.Fatalln("PushMapping subscopeclass Init Error")
  56. }
  57. PushMapping.Subscopeclass = Subscopeclass
  58. }
  59. //省份处理
  60. Area := map[string]string{}
  61. City := map[string]string{}
  62. province := Mysql.SelectBySql(fmt.Sprintf("select code,area,city from %s where (district is null or district='')", CODEAREA))
  63. if province != nil && len(*province) > 0 {
  64. for _, v := range *province {
  65. code := util.ObjToString(v["code"])
  66. city := util.ObjToString(v["city"])
  67. area := util.ObjToString(v["area"])
  68. if city == "" {
  69. Area[area] = code
  70. } else {
  71. City[city] = code
  72. }
  73. }
  74. if len(Area) == 0 {
  75. log.Fatalln("PushMapping Area Init Error")
  76. }
  77. if len(City) == 0 {
  78. log.Fatalln("PushMapping City Init Error")
  79. }
  80. PushMapping.Area = Area
  81. PushMapping.City = City
  82. }
  83. }