12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package init
- import (
- util "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/mysql"
- "log"
- )
- 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")
- }
- }
- }
|