Commit 9739a732 by hcy001

4.0

parent 52559afe
...@@ -28,7 +28,7 @@ func GetBomMatching(bomId, bomItemId int) (bomMatching model.BomItemMatching) { ...@@ -28,7 +28,7 @@ func GetBomMatching(bomId, bomItemId int) (bomMatching model.BomItemMatching) {
} }
//根据matchingList去修改 //根据matchingList去修改
func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err error) { func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching,status ...int) (err error) {
bomIdStr := strconv.FormatInt(int64(bomId), 10) bomIdStr := strconv.FormatInt(int64(bomId), 10)
tableEnd := string(bomIdStr[len(bomIdStr)-1]) tableEnd := string(bomIdStr[len(bomIdStr)-1])
tableName := "lie_bom_item_matching_" + tableEnd tableName := "lie_bom_item_matching_" + tableEnd
...@@ -56,6 +56,16 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er ...@@ -56,6 +56,16 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er
} else { } else {
itemStatus = 3 itemStatus = 3
} }
if len(status) > 0 { //todo 增加类型: 5 替代型号匹配 6 模糊匹配
itemStatus = status[0]
}
if match.Status == 5 && match.Status == 6 {
itemStatus = match.Status;
}
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, "is_select": 1}).Error Updates(map[string]interface{}{"item_status": itemStatus, "update_time": now, "is_select": 1}).Error
if err != nil { if err != nil {
......
...@@ -91,8 +91,8 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg ...@@ -91,8 +91,8 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
} else { } else {
needDealBomItems = bomItems[i : i+perNumber] needDealBomItems = bomItems[i : i+perNumber]
} }
//第一次先去精确匹配 //todo 精确匹配: 第一次先去精确匹配
goodsMapList, err := getUpdateGoodsData(bomId, needDealBomItems, deliveryType, sort, client, true) exactList, err := getUpdateGoodsData(bomId, needDealBomItems, deliveryType, sort, client, true,false)
if err != nil { if err != nil {
return err return err
} }
...@@ -100,33 +100,56 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg ...@@ -100,33 +100,56 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
var fuzzyBomItems []model.BomItem var fuzzyBomItems []model.BomItem
for _, bomItem := range needDealBomItems { for _, bomItem := range needDealBomItems {
//不在精确匹配结果里面的,同时商品名称不能为空的 //不在精确匹配结果里面的,同时商品名称不能为空的
if !checkInGoodsMap(bomItem, goodsMapList) && bomItem.GoodsName != "" { if !checkInGoodsMap(bomItem, exactList) && bomItem.GoodsName != "" {
fuzzyBomItems = append(fuzzyBomItems, bomItem) fuzzyBomItems = append(fuzzyBomItems, bomItem)
} }
} }
//第二次去模糊匹配
fuzzyGoodsMapList, err := getUpdateGoodsData(bomId, fuzzyBomItems, deliveryType, sort, client, false) //todo 替代型号匹配 2021.4.17 替代型号参与匹配,优先取原始型号,原始型号无法购买再推荐替代型号
AlikeGoodsMapList, err := getUpdateGoodsData(bomId, fuzzyBomItems, deliveryType, sort, client, false,true)
if err != nil {
return err
}
//删除已经类似料匹配的型号
var fuzzyBomItems2 []model.BomItem
for _, bomItem := range fuzzyBomItems {
//不在精确匹配结果里面的,同时商品名称不能为空的
if !checkInGoodsMap(bomItem, AlikeGoodsMapList) && bomItem.GoodsName != "" {
fuzzyBomItems2 = append(fuzzyBomItems2, bomItem)
}
}
//todo 模糊匹配
fuzzyGoodsMapList, err := getUpdateGoodsData(bomId, fuzzyBomItems2, deliveryType, sort, client, false,false)
if err != nil { if err != nil {
return err return err
} }
//再删除模糊匹配到的数据,就得到完全没有匹配的数据了 //再删除模糊匹配到的数据,就得到完全没有匹配的数据了
var notMatchBomItems []model.BomItem var notMatchBomItems []model.BomItem
var needMatchGoodsMapList = append(goodsMapList, fuzzyGoodsMapList...) for _, bomItem := range fuzzyBomItems2 {
for _, bomItem := range needDealBomItems { if !checkInGoodsMap(bomItem, fuzzyGoodsMapList) {
if !checkInGoodsMap(bomItem, needMatchGoodsMapList) {
notMatchBomItems = append(notMatchBomItems, bomItem) notMatchBomItems = append(notMatchBomItems, bomItem)
} }
} }
//先去处理没有匹配到的数据 //先去处理没有匹配到的数据
err = UpdateNoMatchBomItem(notMatchBomItems, true) err = UpdateNoMatchBomItem(notMatchBomItems, true)
if err != nil { if err != nil {
return err return err
} }
//然后去处理匹配到的数据 //精确匹配数据
err = UpdateGoodsData(needMatchGoodsMapList) err = UpdateGoodsData(exactList)
if err != nil { if err != nil {
return err return err
} }
//替代物料数据
err = UpdateGoodsData(exactList,5)
if err != nil {
return err
}
} }
return return
} }
...@@ -180,14 +203,14 @@ func checkInGoodsMap(bom model.BomItem, goodsMapList []GoodsMap) bool { ...@@ -180,14 +203,14 @@ func checkInGoodsMap(bom model.BomItem, goodsMapList []GoodsMap) bool {
return false return false
} }
func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType, sort int, client *es.Client, rawSearch bool) (goodsMapList []GoodsMap, err error) { func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType, sort int, client *es.Client, rawSearch bool,isAlike bool) (goodsMapList []GoodsMap, err error) {
if len(bomItems) == 0 { if len(bomItems) == 0 {
return return
} }
index := configs.ESSetting.GoodsIndexName index := configs.ESSetting.GoodsIndexName
//如果是大陆收货(type=1),就要包含专卖,其中自营单独查 //如果是大陆收货(type=1),就要包含专卖,其中自营单独查
index = index + ",zhuanmai,liexin_ziying" index = index + ",zhuanmai,liexin_ziying"
goodsMapList, err = search(index, bomId, bomItems, deliveryType, sort, client, rawSearch) goodsMapList, err = search(index, bomId, bomItems, deliveryType, sort, client, rawSearch,isAlike)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
"strings" "strings"
) )
func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sort int, client *es.Client, rawSearch bool) (goodsMapList []GoodsMap, err error) { func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sort int, client *es.Client, rawSearch bool,isAlike bool) (goodsMapList []GoodsMap, err error) {
//先去自营查一遍 //先去自营查一遍
search := client.MultiSearch().Index(index) search := client.MultiSearch().Index(index)
//是否已经搜索过标签 //是否已经搜索过标签
...@@ -33,7 +33,7 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor ...@@ -33,7 +33,7 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
paramsRawSearch = true paramsRawSearch = true
} }
//构建一个goods_name对应的bomItems列表 //构建一个goods_name对应的bomItems列表
searchRequest := getSearchParams(index, bom, sort, paramsRawSearch) searchRequest := getSearchParams(index, bom, sort, paramsRawSearch,isAlike)
searchFlag = true searchFlag = true
//randInt := rand.Intn(10) //randInt := rand.Intn(10)
//time.Sleep(10 * time.Millisecond) //time.Sleep(10 * time.Millisecond)
...@@ -80,12 +80,12 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor ...@@ -80,12 +80,12 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
} }
//构建请求参数 //构建请求参数
func getSearchParams(index string, bomItem model.BomItem, sort int, flag bool) (searchRequest *es.SearchRequest) { func getSearchParams(index string, bomItem model.BomItem, sort int, flag bool,isAlike bool) (searchRequest *es.SearchRequest) {
//fmt.Println("商品名称 : ", bomItem.GoodsName) //fmt.Println("商品名称 : ", bomItem.GoodsName)
//fmt.Println("参数列表 : ", bomItem.AttrList) //fmt.Println("参数列表 : ", bomItem.AttrList)
bomItem.Encap = TransformEncap(bomItem.Encap) bomItem.Encap = TransformEncap(bomItem.Encap)
//fmt.Println("封装 : ", bomItem.Encap) //fmt.Println("封装 : ", bomItem.Encap)
query := getTermQuery(bomItem, sort, flag) query := getTermQuery(bomItem, sort, flag,isAlike)
source := es.NewSearchSource().Query(query) source := es.NewSearchSource().Query(query)
if sort == 1 { if sort == 1 {
//source.Sort("_score", false) //source.Sort("_score", false)
...@@ -106,7 +106,7 @@ func getSearchParams(index string, bomItem model.BomItem, sort int, flag bool) ( ...@@ -106,7 +106,7 @@ func getSearchParams(index string, bomItem model.BomItem, sort int, flag bool) (
} }
//构建term条件 //构建term条件
func getTermQuery(bomItem model.BomItem, sort int, flag bool) (query *es.BoolQuery) { func getTermQuery(bomItem model.BomItem, sort int, flag bool,isAlike bool) (query *es.BoolQuery) {
query = es.NewBoolQuery() query = es.NewBoolQuery()
if flag { if flag {
field := "auto_goods_name.raw" field := "auto_goods_name.raw"
...@@ -148,6 +148,12 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool) (query *es.BoolQue ...@@ -148,6 +148,12 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool) (query *es.BoolQue
} else { } else {
query = query.Filter(es.NewTermQuery(field, goodsName)) query = query.Filter(es.NewTermQuery(field, goodsName))
} }
//todo 推荐型号搜索
if isAlike {
query = query.Must(es.NewTermsQuery("alike_spu_name", goodsName))
}
//判断是否存在brandName并且匹配不到对应的标准品牌 //判断是否存在brandName并且匹配不到对应的标准品牌
if bomItem.BrandName != "" { if bomItem.BrandName != "" {
bomItem.BrandName = strings.ToUpper(bomItem.BrandName) bomItem.BrandName = strings.ToUpper(bomItem.BrandName)
...@@ -169,7 +175,8 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool) (query *es.BoolQue ...@@ -169,7 +175,8 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool) (query *es.BoolQue
// query = query.Filter(es.NewRangeQuery("single_price").Gt(0)) // query = query.Filter(es.NewRangeQuery("single_price").Gt(0))
//} //}
//只显示起订量大于0 //只显示起订量大于0
query.Must(es.NewRangeQuery("moq").Gt(0)) query.Must(es.NewRangeQuery("moq").Lte(bomItem.Number)) //todo 2021.4.17 起订量高于需求数量的排除;
if configs.ApiSetting.Mode != "debug" { if configs.ApiSetting.Mode != "debug" {
query = query.Filter(es.NewTermQuery("status", 1)) query = query.Filter(es.NewTermQuery("status", 1))
} }
......
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