Commit 9739a732 by hcy001

4.0

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