Browse Source

省份代码处理

WH01243 1 year ago
parent
commit
2fffadb0f0
2 changed files with 26 additions and 2 deletions
  1. 14 0
      api/common/initconfig.go
  2. 12 2
      api/internal/service/employService.go

+ 14 - 0
api/common/initconfig.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"flag"
 	"fmt"
+	"github.com/gogf/gf/v2/util/gconv"
 	"log"
 	"time"
 
@@ -36,6 +37,7 @@ var DB config.Db
 
 var pushFile = flag.String("pf", "etc/push.yaml", "the push file")
 var Push config.Push
+var AreaCodeMap map[string]interface{}
 
 var (
 	MgoBidding        mongodb.MongodbSim
@@ -179,6 +181,7 @@ func InitConf() {
 		RegResourceCenter(C.ResourceCenterKey)
 	conf.MustLoad(*pushFile, &Push)
 	ConnectClickhouse(DB.Clickhouse)
+	InitArea()
 }
 func ConnectClickhouse(cHouseConfig *config.CHouseConfig) error {
 	var (
@@ -210,3 +213,14 @@ func ConnectClickhouse(cHouseConfig *config.CHouseConfig) error {
 	}
 	return nil
 }
+func InitArea() {
+	data := CrmMysql.SelectBySql("select  code,name from  d_area_code where   ( level  is  NULL or   level in (1,2))")
+	for _, m := range *data {
+		code := gconv.String(m["code"])
+		name := gconv.String(m["name"])
+		if name == "" {
+			continue
+		}
+		AreaCodeMap[name] = code
+	}
+}

+ 12 - 2
api/internal/service/employService.go

@@ -273,8 +273,18 @@ func infoFind(id string, v1 string) map[string]interface{} {
 	pushTime := ""
 	if obj != nil && len(obj) > 0 {
 		data["title"] = common.ObjToString(obj["title"])
-		data["city"] = obj["city"]
-		data["area"] = obj["area"]
+		city := gconv.String(obj["city"])
+		area := gconv.String(obj["area"])
+		data["city"] = city
+		data["area"] = area
+		//省份代码处理
+		areaCode := ""
+		if MC.AreaCodeMap[city] != "" {
+			areaCode = gconv.String(MC.AreaCodeMap[city])
+		} else {
+			areaCode = gconv.String(MC.AreaCodeMap[area])
+		}
+		data["area_code"] = areaCode
 		data["subtype"] = obj["subtype"]
 		data["buyerclass"] = obj["buyerclass"]
 		data["budget"] = obj["budget"]