Commit e8b084d6 by mushishixian

参数匹配

parent 91aafe7f
...@@ -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, search) search = searchAttr(item.GoodsName, item.BrandName, search)
searchFlag = true searchFlag = true
} }
//如果没有型号,但是有参数(参数有可能是型号),那就去匹配参数 //如果没有型号,但是有参数(参数有可能是型号),那就去匹配参数
if item.GoodsName == "" && item.Attrs != "" { if item.GoodsName == "" && item.Attrs != "" {
search = searchAttr(item.Attrs, search) search = searchAttr(item.Attrs, item.BrandName, search)
searchFlag = true searchFlag = true
} }
} }
...@@ -58,7 +58,7 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er ...@@ -58,7 +58,7 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
res, _ := hit.Source.MarshalJSON() res, _ := hit.Source.MarshalJSON()
//还要去判断至少符合特定数量参数匹配的结果,比如最小匹配参数为2,那就是要有两个参数匹配到才正确 //还要去判断至少符合特定数量参数匹配的结果,比如最小匹配参数为2,那就是要有两个参数匹配到才正确
bomItems[key].GoodsName = gjson.Get(string(res), "goods_name").String() bomItems[key].GoodsName = gjson.Get(string(res), "goods_name").String()
fmt.Println(string(res)) //fmt.Println(string(res))
} }
} }
} }
...@@ -66,7 +66,7 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er ...@@ -66,7 +66,7 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
return return
} }
func searchAttr(attrOrigin string, search *es.MultiSearchService) (result *es.MultiSearchService) { func searchAttr(attrOrigin, brandName string, search *es.MultiSearchService) (result *es.MultiSearchService) {
//先去切割参数得到参数列表 //先去切割参数得到参数列表
attrs := splitAttrs(attrOrigin) attrs := splitAttrs(attrOrigin)
var attrsSlice []string var attrsSlice []string
...@@ -77,11 +77,24 @@ func searchAttr(attrOrigin string, search *es.MultiSearchService) (result *es.Mu ...@@ -77,11 +77,24 @@ func searchAttr(attrOrigin string, search *es.MultiSearchService) (result *es.Mu
attrsSlice = append(attrsSlice, attr) attrsSlice = append(attrsSlice, attr)
} }
query := getQuery(attrsSlice) query := getQuery(attrsSlice)
if brandName != "" {
//提取全英文,转成大写
if strings.Contains(brandName, " ") {
//有空格隔开只取第一个
brandName = strings.Split(brandName, " ")[0]
//转成全大写,因为ES存的是大写
brandName = strings.ToUpper(brandName)
//去除特殊符号和中文等等
r1, _ := regexp.Compile(`/[^A-Za-z0-9]+/`)
brandName = r1.ReplaceAllString(brandName, "")
query.Should(es.NewTermQuery("brand_name", brandName))
}
}
source := es.NewSearchSource().Query(query) source := es.NewSearchSource().Query(query)
source.Sort("brand_sort", true) source.Sort("brand_sort", true)
source = source.From(0).Size(1) source = source.From(0).Size(1)
searchRequest := es.NewSearchRequest().Source(source) searchRequest := es.NewSearchRequest().Source(source)
fmt.Println(searchRequest.Body()) //fmt.Println(searchRequest.Body())
return search.Add(searchRequest) return search.Add(searchRequest)
} }
......
...@@ -50,11 +50,17 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er ...@@ -50,11 +50,17 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er
} }
now := time.Now().Unix() now := time.Now().Unix()
var itemStatus int var itemStatus int
//if matching.IsBuy == 1 && matching.Price != 0 && matching.Stock != 0 {
// itemStatus = 2
// //库存为0或者价格为0,要放到待确认
//
//} else if matching.Price == 0 || matching.Stock == 0 {
// itemStatus = 4
//}
if matching.IsBuy == 1 { if matching.IsBuy == 1 {
itemStatus = 2 itemStatus = 2
//库存为0或者价格为0,要放到待确认 }else{
} else if matching.Price == 0 || matching.Stock == 0 { itemStatus =3
itemStatus = 4
} }
err = model.Db.Table("lie_bom_item_"+tableEnd).Where("bom_item_id = ?", matching.BomItemID). err = model.Db.Table("lie_bom_item_"+tableEnd).Where("bom_item_id = ?", matching.BomItemID).
Updates(map[string]interface{}{"item_status": itemStatus, "update_time": now}).Error Updates(map[string]interface{}{"item_status": itemStatus, "update_time": now}).Error
......
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
"bom_server/configs" "bom_server/configs"
"bom_server/internal/model" "bom_server/internal/model"
"encoding/json" "encoding/json"
"fmt"
"github.com/imroc/req" "github.com/imroc/req"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"strings" "strings"
...@@ -31,7 +30,6 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) { ...@@ -31,7 +30,6 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
} }
goodsIdsStr := strings.Join(goodsIds, ",") goodsIdsStr := strings.Join(goodsIds, ",")
goodsList, err := GetGoodsInfo(goodsIdsStr) goodsList, err := GetGoodsInfo(goodsIdsStr)
fmt.Println(len(goodsList))
if len(goodsMapList) != 0 { if len(goodsMapList) != 0 {
bomId = goodsMapList[0].BomId bomId = goodsMapList[0].BomId
} }
...@@ -83,6 +81,7 @@ func GetGoodsInfo(goodsIdsStr string) (goodsList []model.ApiGoods, err error) { ...@@ -83,6 +81,7 @@ func GetGoodsInfo(goodsIdsStr string) (goodsList []model.ApiGoods, err error) {
params := req.Param{ params := req.Param{
"goods_id": goodsIdsStr, "goods_id": goodsIdsStr,
} }
//fmt.Println(goodsIdsStr)
resp, err := req.Post(goodsServerUrl+"/synchronization", params) resp, err := req.Post(goodsServerUrl+"/synchronization", params)
if err != nil { if err != nil {
return return
......
...@@ -7,7 +7,6 @@ import ( ...@@ -7,7 +7,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"math" "math"
"regexp" "regexp"
"strings" "strings"
...@@ -32,7 +31,7 @@ func MatchGoods(message model.BomMessage) (err error) { ...@@ -32,7 +31,7 @@ func MatchGoods(message model.BomMessage) (err error) {
return errors.New("没有商品的bom单") return errors.New("没有商品的bom单")
} }
bomItems := bom.BomItems bomItems := bom.BomItems
perGoDealNumber := 200 perGoDealNumber := 40
//开启协程处理搜索 //开启协程处理搜索
var wg sync.WaitGroup var wg sync.WaitGroup
//判断是否有余数 //判断是否有余数
...@@ -99,7 +98,6 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg ...@@ -99,7 +98,6 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
} }
//再删除模糊匹配到的数据,就得到完全没有匹配的数据了 //再删除模糊匹配到的数据,就得到完全没有匹配的数据了
var notMatchBomItems []model.BomItem var notMatchBomItems []model.BomItem
fmt.Println(len(append(goodsMapList, fuzzyGoodsMapList...)))
for _, bomItem := range bomItems { for _, bomItem := range bomItems {
if !checkInGoodsMap(bomItem, append(goodsMapList, fuzzyGoodsMapList...)) { if !checkInGoodsMap(bomItem, append(goodsMapList, fuzzyGoodsMapList...)) {
notMatchBomItems = append(notMatchBomItems, bomItem) notMatchBomItems = append(notMatchBomItems, bomItem)
......
...@@ -10,11 +10,11 @@ var KeywordRegular = map[string]string{ ...@@ -10,11 +10,11 @@ var KeywordRegular = map[string]string{
`(欧姆|欧|O|o|R|r)`: "Ω", `(欧姆|欧|O|o|R|r)`: "Ω",
`(Uf|uf|μf|uF|UF)`: "μF", `(Uf|uf|μf|uF|UF)`: "μF",
`(Uh|uh|μh|uH|UH)`: "μH", `(Uh|uh|μh|uH|UH)`: "μH",
`K`: "KΩ", `K`: "nF",
`v`: "V", `v`: "V",
} }
var PureNumberRegular = `(\d+(\.\d+)?)` var PureNumberRegular = `(\d+(\.\d+)?)`
var PureLetterRegular = `[a-zA-Z0-9]+`
var GetAttrUnitRegular = `[\d.]|±|\+_|\+-|/|\(.*\)|\+/-|` var GetAttrUnitRegular = `[\d.]|±|\+_|\+-|/|\(.*\)|\+/-|`
//`^[\d\.]+(欧姆|欧|O|o|R|r)$`: "Ω", //`^[\d\.]+(欧姆|欧|O|o|R|r)$`: "Ω",
......
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