Commit e3bcc1db by mushishixian

修改匹配请求量

parent a7126d63
Showing with 44 additions and 34 deletions
...@@ -30,7 +30,7 @@ func MatchGoods(message model.BomMessage) (err error) { ...@@ -30,7 +30,7 @@ func MatchGoods(message model.BomMessage) (err error) {
if configs.ApiSetting.Mode == "debug" { if configs.ApiSetting.Mode == "debug" {
perGoDealNumber = 200 perGoDealNumber = 200
} else { } else {
perGoDealNumber = 40 perGoDealNumber = 100
} }
//开启协程处理搜索 //开启协程处理搜索
var wg sync.WaitGroup var wg sync.WaitGroup
...@@ -80,41 +80,51 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg ...@@ -80,41 +80,51 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
bomItems = common.TrimBomItemSpace(bomItems) bomItems = common.TrimBomItemSpace(bomItems)
//获取转换后的标准参数,或者是识别出参数列是否有型号 //获取转换后的标准参数,或者是识别出参数列是否有型号
bomItems = GetStandardAttrs(bomItems) bomItems = GetStandardAttrs(bomItems)
//第一次先去精确匹配 //线上es性能垃圾,批量请求条数或者并发数过高,就会拒绝请求,只能用循环,控制每次批量请求的条数,所以要循环再处理
goodsMapList, err := getUpdateGoodsData(bomId, bomItems, deliveryType, sort, client, true) perNumber := 5
if err != nil { var needDealBomItems []model.BomItem
return for i := 0; i < len(bomItems); i = i + perNumber {
} if i+perNumber > len(bomItems) {
//要删除已经精确匹配过的bomItem,得到需要去模糊匹配的商品 needDealBomItems = bomItems[i:]
var fuzzyBomItems []model.BomItem } else {
for _, bomItem := range bomItems { needDealBomItems = bomItems[i : i+perNumber]
//不在精确匹配结果里面的,同时商品名称不能为空的
if !checkInGoodsMap(bomItem, goodsMapList) && bomItem.GoodsName != "" {
fuzzyBomItems = append(fuzzyBomItems, bomItem)
} }
} //第一次先去精确匹配
//第二次去模糊匹配 goodsMapList, err := getUpdateGoodsData(bomId, needDealBomItems, deliveryType, sort, client, true)
fuzzyGoodsMapList, err := getUpdateGoodsData(bomId, fuzzyBomItems, deliveryType, sort, client, false) if err != nil {
if err != nil { return err
return }
} //要删除已经精确匹配过的bomItem,得到需要去模糊匹配的商品
//再删除模糊匹配到的数据,就得到完全没有匹配的数据了 var fuzzyBomItems []model.BomItem
var notMatchBomItems []model.BomItem for _, bomItem := range needDealBomItems {
var needMatchGoodsMapList = append(goodsMapList, fuzzyGoodsMapList...) //不在精确匹配结果里面的,同时商品名称不能为空的
for _, bomItem := range bomItems { if !checkInGoodsMap(bomItem, goodsMapList) && bomItem.GoodsName != "" {
if !checkInGoodsMap(bomItem, needMatchGoodsMapList) { fuzzyBomItems = append(fuzzyBomItems, bomItem)
notMatchBomItems = append(notMatchBomItems, bomItem) }
}
//第二次去模糊匹配
fuzzyGoodsMapList, err := getUpdateGoodsData(bomId, fuzzyBomItems, deliveryType, sort, client, false)
if err != nil {
return err
}
//再删除模糊匹配到的数据,就得到完全没有匹配的数据了
var notMatchBomItems []model.BomItem
var needMatchGoodsMapList = append(goodsMapList, fuzzyGoodsMapList...)
for _, bomItem := range needDealBomItems {
if !checkInGoodsMap(bomItem, needMatchGoodsMapList) {
notMatchBomItems = append(notMatchBomItems, bomItem)
}
}
//先去处理没有匹配到的数据
err = UpdateNoMatchBomItem(notMatchBomItems, true)
if err != nil {
return err
}
//然后去处理匹配到的数据
err = UpdateGoodsData(needMatchGoodsMapList)
if err != nil {
return err
} }
}
//先去处理没有匹配到的数据
err = UpdateNoMatchBomItem(notMatchBomItems, true)
if err != nil {
return
}
//然后去处理匹配到的数据
err = UpdateGoodsData(needMatchGoodsMapList)
if err != nil {
return
} }
return return
} }
......
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