Преглед на файлове

Merge branch 'dev/v1.1.55_fu' of https://jygit.jydev.jianyu360.cn/BaseService/jyMicroservices into dev/v1.1.55_fu

wangshan преди 1 година
родител
ревизия
d7ba36cd53
променени са 2 файла, в които са добавени 68 реда и са изтрити 1 реда
  1. 60 0
      jyBXCore/rpc/init/label.go
  2. 8 1
      jyBXCore/rpc/util/search.go

+ 60 - 0
jyBXCore/rpc/init/label.go

@@ -2,7 +2,9 @@ package init
 
 import (
 	MC "app.yhyue.com/moapp/jybase/common"
+	"encoding/json"
 	"fmt"
+	"log"
 	"strings"
 )
 
@@ -14,7 +16,24 @@ type labelStruct struct {
 	Url         string `json:"url"`
 }
 
+// 地区code 信息
+type areaCodeInfo struct {
+	Code         string `json:"code"`     //地区编码
+	Area         string `json:"area"`     //省份
+	City         string `json:"city"`     //城市
+	District     string `json:"district"` //区县
+	Class        int    `json:"class"`    //1:省份 2:城市 3:直辖市 4:县区
+	RegionalCode string `json:"pcode"`    //地区拼音简称
+	Location     int    `json:"location"` //区位 1:华北 2:华中,3:东北,4:华中 5:华南 6:西南 7:西北
+}
+
 var LabelMap = map[string]labelStruct{}
+var (
+	AreaMap     = map[string]string{}
+	CityMap     = map[string]string{}
+	DistrictMap = map[string]string{}
+	AreaInfos   []areaCodeInfo
+)
 
 /*
 *包含地区标签、信息类型标签、行业标签;
@@ -51,3 +70,44 @@ func LabelInit() {
 		}
 	}
 }
+
+func AreaInit() {
+	sql := `SELECT * FROM global_common_data.seo_area_code;`
+	areaInfos := BaseMysql.SelectBySql(sql)
+	if areaInfos != nil && len(*areaInfos) > 0 {
+		AreaMap = map[string]string{}
+		CityMap = map[string]string{}
+		DistrictMap = map[string]string{}
+		b, err := json.Marshal(*areaInfos)
+		if err == nil {
+			err = json.Unmarshal(b, &AreaInfos)
+		}
+		if err != nil {
+			log.Println("初始化地区信息 err :", err)
+		}
+		if len(AreaInfos) > 0 {
+			for _, a := range AreaInfos {
+				if a.RegionalCode == "" {
+					continue
+				}
+				switch a.Class {
+				case 1, 3:
+					if a.Area == "" {
+						continue
+					}
+					AreaMap[a.Area] = a.RegionalCode
+				case 2:
+					if a.City == "" {
+						continue
+					}
+					CityMap[a.City] = a.RegionalCode
+				case 4:
+					if a.District == "" {
+						continue
+					}
+					DistrictMap[a.District] = a.RegionalCode
+				}
+			}
+		}
+	}
+}

+ 8 - 1
jyBXCore/rpc/util/search.go

@@ -26,6 +26,7 @@ var (
 	filterReg_4 = regexp.MustCompile("([)>》】\\]\\}}〕,,;;::'\"“”。\\.\\??、/\\+=\\\\_—\\*&……\\^%$¥@!!`~·(\\(<《【\\[\\{{〔])")
 	//PhoneReg     = regexp.MustCompile("^[1][3-9][0-9]{9}$")
 	//EmailPattern = regexp.MustCompile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$")
+	AreaLabelLink = "/list/%s/%s.html"
 )
 
 // SearchHistory 格式化 关键词搜索历史记录
@@ -202,7 +203,6 @@ func SearchListFormat(userid, subInformation, propertyForm, industry string, rep
 		}
 		searchList.Id = ME.EncodeArticleId2ByCheck(MC.ObjToString(v["_id"]))                                    //ME.EncodeArticleId2ByCheck(MC.ObjToString(v["_id"]))                                         //加密信息id
 		searchList.Area = MC.ObjToString(v["area"])                                                             //地区
-		searchList.AreaUrl = IC.LabelMap[searchList.Area].Url                                                   //地区分类链接
 		searchList.BuyerClass = MC.ObjToString(v["buyerclass"])                                                 //采购单位类型
 		searchList.City = MC.ObjToString(v["city"])                                                             //城市
 		searchList.District = MC.ObjToString(v["district"])                                                     // 区县       //城市
@@ -326,6 +326,13 @@ func SearchListFormat(userid, subInformation, propertyForm, industry string, rep
 				}
 			}
 		}
+		if searchList.District != "" && IC.DistrictMap[searchList.District] != "" {
+			searchList.AreaUrl = fmt.Sprintf(AreaLabelLink, "city", IC.DistrictMap[searchList.District])
+		} else if searchList.City != "" && IC.CityMap[searchList.City] != "" {
+			searchList.AreaUrl = fmt.Sprintf(AreaLabelLink, "city", IC.CityMap[searchList.City])
+		} else if searchList.Area != "" && IC.AreaMap[searchList.Area] != "" {
+			searchList.AreaUrl = fmt.Sprintf(AreaLabelLink, "area", IC.AreaMap[searchList.Area])
+		}
 		list = append(list, searchList)
 	}
 	return