Forráskód Böngészése

feat:增加映射文件

wangchuanjin 2 éve
szülő
commit
3f9b11fad2
1 módosított fájl, 77 hozzáadás és 0 törlés
  1. 77 0
      p/mapping.go

+ 77 - 0
p/mapping.go

@@ -0,0 +1,77 @@
+package p
+
+import (
+	"log"
+
+	util "app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/mysql"
+)
+
+var PushMapping = &pushMapping{}
+
+type pushMapping struct {
+	Area          map[string]int
+	City          map[string]int
+	Toptype       map[string]int
+	Subtype       map[string]int
+	Buyerclass    map[string]int
+	Subscopeclass map[string]int
+}
+
+func (p *pushMapping) Init(Mysql *mysql.Mysql) {
+	infotype := Mysql.SelectBySql("select id,type,name from infotype")
+	p.Toptype = map[string]int{}
+	p.Subtype = map[string]int{}
+	p.Buyerclass = map[string]int{}
+	p.Subscopeclass = map[string]int{}
+	if infotype != nil && len(*infotype) > 0 {
+		for _, v := range *infotype {
+			id := util.IntAll(v["id"])
+			tp := util.IntAll(v["type"])
+			name := util.ObjToString(v["name"])
+			if tp == 1 {
+				p.Toptype[name] = id
+			} else if tp == 2 {
+				p.Subtype[name] = id
+			} else if tp == 3 {
+				p.Buyerclass[name] = id
+			} else if tp == 4 {
+				p.Subscopeclass[name] = id
+			}
+		}
+		if len(p.Toptype) == 0 {
+			log.Fatalln("PushMapping Toptype Init Error")
+		}
+		if len(p.Subtype) == 0 {
+			log.Fatalln("PushMapping Subtype Init Error")
+		}
+		if len(p.Buyerclass) == 0 {
+			log.Fatalln("PushMapping Buyerclass Init Error")
+		}
+		if len(p.Subscopeclass) == 0 {
+			log.Fatalln("PushMapping Subscopeclass Init Error")
+		}
+	}
+	//
+	p.Area = map[string]int{}
+	p.City = map[string]int{}
+	province := Mysql.SelectBySql("select id,level,name from province")
+	if province != nil && len(*province) > 0 {
+		for _, v := range *province {
+			id := util.IntAll(v["id"])
+			level := util.IntAll(v["level"])
+			name := util.ObjToString(v["name"])
+			if level == 1 {
+				p.Area[name] = id
+			} else if level == 2 {
+				p.City[name] = id
+			}
+		}
+		if len(p.Area) == 0 {
+			log.Fatalln("PushMapping Area Init Error")
+		}
+		if len(p.City) == 0 {
+			log.Fatalln("PushMapping City Init Error")
+		}
+	}
+}