123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package mapping
- import (
- "log"
- util "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/mysql"
- )
- var BidCodeMapping = &bidCodeMapping{}
- type bidCodeMapping struct {
- Area map[string]string //省
- City map[string]string //市
- District map[string]map[string]string //市-区
- Toptype map[string]string //一级信息类型
- Subtype map[string]string //二级信息类型
- Buyerclass map[string]string //采购单位行业
- Subscopeclass map[string]string //信息行业
- }
- func (b *bidCodeMapping) Init(Mysql *mysql.Mysql) {
- b.Buyerclass = map[string]string{}
- codeBuyerclass := Mysql.SelectBySql("select code,name from global_common_data.code_buyerclass where level=1")
- if codeBuyerclass != nil && len(*codeBuyerclass) > 0 {
- for _, v := range *codeBuyerclass {
- code, _ := v["code"].(string)
- name, _ := v["name"].(string)
- b.Buyerclass[name] = code
- }
- }
- if len(b.Buyerclass) == 0 {
- log.Fatalln("PushMapping Buyerclass Init Error")
- }
- //
- b.Toptype = map[string]string{}
- b.Subtype = map[string]string{}
- codeBidTopSubtype := Mysql.SelectBySql("select code,name,level from global_common_data.code_bidtopsubtype")
- if codeBidTopSubtype != nil && len(*codeBidTopSubtype) > 0 {
- for _, v := range *codeBidTopSubtype {
- code, _ := v["code"].(string)
- name, _ := v["name"].(string)
- level := util.IntAll(v["level"])
- if level == 1 {
- b.Toptype[name] = code
- } else if level == 2 {
- b.Subtype[name] = code
- }
- }
- }
- if len(b.Toptype) == 0 {
- log.Fatalln("PushMapping Toptype Init Error")
- }
- if len(b.Subtype) == 0 {
- log.Fatalln("PushMapping Subtype Init Error")
- }
- //
- b.Subscopeclass = map[string]string{}
- 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)")
- if codeBidScope != nil && len(*codeBidScope) > 0 {
- for _, v := range *codeBidScope {
- code, _ := v["code"].(string)
- name, _ := v["name"].(string)
- b.Subscopeclass[name] = code
- }
- }
- if len(b.Subscopeclass) == 0 {
- log.Fatalln("PushMapping Subscopeclass Init Error")
- }
- //
- b.Area = map[string]string{}
- b.City = map[string]string{}
- b.District = map[string]map[string]string{}
- codeArea := Mysql.SelectBySql("select code,area,city,district from global_common_data.code_area")
- if codeArea != nil && len(*codeArea) > 0 {
- for _, v := range *codeArea {
- code, _ := v["code"].(string)
- area, _ := v["area"].(string)
- city, _ := v["city"].(string)
- district, _ := v["district"].(string)
- if area != "" && city == "" && district == "" {
- b.Area[area] = code
- } else if area != "" && city != "" && district == "" {
- b.City[city] = code
- } else if area != "" && city != "" && district != "" {
- if b.District[city] == nil {
- b.District[city] = map[string]string{}
- }
- b.District[city][district] = code
- }
- }
- }
- if len(b.Area) == 0 {
- log.Fatalln("BidCodeMapping Area Init Error")
- }
- if len(b.City) == 0 {
- log.Fatalln("BidCodeMapping City Init Error")
- }
- if len(b.District) == 0 {
- log.Fatalln("BidCodeMapping District Init Error")
- }
- }
|