Commit 20bf6765 by mushishixian

加上封装参数匹配

parent 27107092
...@@ -22,7 +22,7 @@ func init() { ...@@ -22,7 +22,7 @@ func init() {
// "amqp://huntadmin:jy2y2900@192.168.1.237:5672/", // "amqp://huntadmin:jy2y2900@192.168.1.237:5672/",
//} //}
// //
//str := `{"bom_id":432,"delivery_type":1,"sort":1}` //str := `{"bom_id":436,"delivery_type":1,"sort":1}`
//rabbitmq.Send(queueExchange, str) //rabbitmq.Send(queueExchange, str)
} }
......
...@@ -31,12 +31,12 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er ...@@ -31,12 +31,12 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
for _, item := range bomItems { for _, item := range bomItems {
//如果有型号,但是型号有可能是参数,所以先去匹配下参数,有的话转成对应的型号 //如果有型号,但是型号有可能是参数,所以先去匹配下参数,有的话转成对应的型号
if item.GoodsName != "" { if item.GoodsName != "" {
search = searchAttr(item.GoodsName, item.BrandName, search) search = searchAttr(item.GoodsName, item.BrandName, item.Encap, search)
searchFlag = true searchFlag = true
} }
//如果没有型号,但是有参数(参数有可能是型号),那就去匹配参数 //如果没有型号,但是有参数(参数有可能是型号),那就去匹配参数
if item.GoodsName == "" && item.Attrs != "" { if item.GoodsName == "" && item.Attrs != "" {
search = searchAttr(item.Attrs, item.BrandName, search) search = searchAttr(item.Attrs, item.BrandName, item.Encap, search)
searchFlag = true searchFlag = true
} }
} }
...@@ -66,16 +66,27 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er ...@@ -66,16 +66,27 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
return return
} }
func searchAttr(attrOrigin, brandName string, search *es.MultiSearchService) (result *es.MultiSearchService) { func searchAttr(attrOrigin, brandName, encap string, search *es.MultiSearchService) (result *es.MultiSearchService) {
//先去切割参数得到参数列表 //先去切割参数得到参数列表
attrs := splitAttrs(attrOrigin) attrs := splitAttrs(attrOrigin)
var attrsSlice []string var attrsSlice []string
//fmt.Println(attrs)
//去转换每一个参数,得到去查询es的标准格式 //去转换每一个参数,得到去查询es的标准格式
for _, attr := range attrs { for _, attr := range attrs {
attr = TransformESParam(attr) attr = TransformESParam(attr)
attrsSlice = append(attrsSlice, attr) attrsSlice = append(attrsSlice, attr)
} }
//单独针对封装进行转换
if encap != "" {
//先提取出纯数字
numberR, _ := regexp.Compile(mapping.PureNumberRegular)
pureNumber := numberR.FindString(encap)
//再去找对应属性
attrName, _ := redis.String(gredis.HGet("sku_map2", pureNumber))
if attrName != "" {
attrValue := attrName + "€" + pureNumber
attrsSlice = append(attrsSlice, attrValue)
}
}
query := getQuery(attrsSlice) query := getQuery(attrsSlice)
if brandName != "" { if brandName != "" {
//提取全英文,转成大写 //提取全英文,转成大写
...@@ -177,6 +188,7 @@ func getAttrValueByAttr(attr string) (attrValue string) { ...@@ -177,6 +188,7 @@ func getAttrValueByAttr(attr string) (attrValue string) {
attrNumber, _ = strconv.ParseFloat(pureNumber, 64) attrNumber, _ = strconv.ParseFloat(pureNumber, 64)
//找出对应单位需要转换的值 //找出对应单位需要转换的值
var attrName string var attrName string
//再去找没有单位的对应属性
if attrUnit != "" { if attrUnit != "" {
for unit, value := range mapping.UnitValueMapping { for unit, value := range mapping.UnitValueMapping {
//如果不是标准最小单位,则要进行转换 //如果不是标准最小单位,则要进行转换
...@@ -233,9 +245,11 @@ func getQuery(attrs []string) (query *es.BoolQuery) { ...@@ -233,9 +245,11 @@ func getQuery(attrs []string) (query *es.BoolQuery) {
query.Should(nestedQuery) query.Should(nestedQuery)
} }
var shouldMatchNumber int var shouldMatchNumber int
if len(attrs)>=2 { if len(attrs) > 3 {
shouldMatchNumber = 3
} else if len(attrs) >= 2 {
shouldMatchNumber = 2 shouldMatchNumber = 2
}else{ } else {
shouldMatchNumber = 1 shouldMatchNumber = 1
} }
query.MinimumNumberShouldMatch(shouldMatchNumber) query.MinimumNumberShouldMatch(shouldMatchNumber)
......
...@@ -12,6 +12,7 @@ type BomItem struct { ...@@ -12,6 +12,7 @@ type BomItem struct {
// Number 需求数量 // Number 需求数量
Number int `json:"number"` Number int `json:"number"`
Attrs string `json:"attrs"` Attrs string `json:"attrs"`
Encap string `json:"encap"`
// ItemStatus 匹配状态 1:等待匹配 2:可购现货 3:待询价 4:需要修正 // ItemStatus 匹配状态 1:等待匹配 2:可购现货 3:待询价 4:需要修正
ItemStatus int `json:"item_status"` ItemStatus int `json:"item_status"`
// DelStatus 删除状态 1:正常 2:删除 // DelStatus 删除状态 1:正常 2:删除
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment