Commit 91aafe7f by mushishixian

bom阶段

parent f6058c6f
......@@ -22,7 +22,7 @@ func init() {
"amqp://huntadmin:jy2y2900@192.168.1.237:5672/",
}
str := `{"bom_id":382,"delivery_type":1,"sort":1}`
str := `{"bom_id":408,"delivery_type":1,"sort":2}`
rabbitmq.Send(queueExchange, str)
}
......
......@@ -36,6 +36,7 @@ type Redis struct {
type ES struct {
Url string `ini:"url"`
GoodsIndexName string `ini:"goods_index_name"`
AttrIndex string `ini:"attr_index"`
}
type RabbitMQ struct {
......
......@@ -24,7 +24,8 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
return
}
defer client.Stop()
search := client.MultiSearch().Index("goods_map_test")
index := configs.ESSetting.AttrIndex
search := client.MultiSearch().Index(index)
searchFlag := false
//先根据参数去构建批量查询条件
for _, item := range bomItems {
......@@ -33,7 +34,7 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
search = searchAttr(item.GoodsName, search)
searchFlag = true
}
//如果没有型号,但是有参数,那就去匹配参数
//如果没有型号,但是有参数(参数有可能是型号),那就去匹配参数
if item.GoodsName == "" && item.Attrs != "" {
search = searchAttr(item.Attrs, search)
searchFlag = true
......@@ -69,7 +70,7 @@ func searchAttr(attrOrigin string, search *es.MultiSearchService) (result *es.Mu
//先去切割参数得到参数列表
attrs := splitAttrs(attrOrigin)
var attrsSlice []string
fmt.Println(attrs)
//fmt.Println(attrs)
//去转换每一个参数,得到去查询es的标准格式
for _, attr := range attrs {
attr = TransformESParam(attr)
......@@ -77,6 +78,7 @@ func searchAttr(attrOrigin string, search *es.MultiSearchService) (result *es.Mu
}
query := getQuery(attrsSlice)
source := es.NewSearchSource().Query(query)
source.Sort("brand_sort", true)
source = source.From(0).Size(1)
searchRequest := es.NewSearchRequest().Source(source)
fmt.Println(searchRequest.Body())
......@@ -199,6 +201,7 @@ func getAttrValueByAttr(attr string) (attrValue string) {
//获取匹配的条件
func getQuery(attrs []string) (query *es.BoolQuery) {
var subQuery *es.TermQuery
var nestedQuery *es.NestedQuery
query = es.NewBoolQuery()
for _, attr := range attrs {
//还要判断是不是一个单位对应多个属性的
......@@ -208,13 +211,15 @@ func getQuery(attrs []string) (query *es.BoolQuery) {
multiAttr := strings.Split(name, "|")
for _, temp := range multiAttr {
subQuery = es.NewTermQuery("attrs.attr_value", temp+"€"+value)
nestedQuery = es.NewNestedQuery("attrs", subQuery)
query.Should(nestedQuery)
}
} else {
subQuery = es.NewTermQuery("attrs.attr_value", attr)
nestedQuery = es.NewNestedQuery("attrs", subQuery)
query.Should(nestedQuery)
}
nestedQuery := es.NewNestedQuery("attrs", subQuery)
query.Should(nestedQuery)
query.MinimumNumberShouldMatch(2)
query.MinimumNumberShouldMatch(1)
}
return query
......
......@@ -49,18 +49,17 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er
}
}
now := time.Now().Unix()
var itemStatus int
if matching.IsBuy == 1 {
err = model.Db.Table("lie_bom_item_"+tableEnd).Where("bom_item_id = ?", matching.BomItemID).
Updates(map[string]interface{}{"item_status": 2, "update_time": now}).Error
if err != nil {
return
}
} else {
err = model.Db.Table("lie_bom_item_"+tableEnd).Where("bom_item_id = ?", matching.BomItemID).
Updates(map[string]interface{}{"item_status": 3, "update_time": now}).Error
if err != nil {
return
}
itemStatus = 2
//库存为0或者价格为0,要放到待确认
} else if matching.Price == 0 || matching.Stock == 0 {
itemStatus = 4
}
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
if err != nil {
return
}
}
return nil
......
......@@ -4,6 +4,7 @@ import (
"bom_server/configs"
"bom_server/internal/model"
"encoding/json"
"fmt"
"github.com/imroc/req"
"github.com/tidwall/gjson"
"strings"
......@@ -30,10 +31,10 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
}
goodsIdsStr := strings.Join(goodsIds, ",")
goodsList, err := GetGoodsInfo(goodsIdsStr)
fmt.Println(len(goodsList))
if len(goodsMapList) != 0 {
bomId = goodsMapList[0].BomId
}
//fmt.Println(goodsIdsStr)
if err != nil {
return
}
......
......@@ -7,6 +7,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"math"
"regexp"
"strings"
......@@ -31,7 +32,7 @@ func MatchGoods(message model.BomMessage) (err error) {
return errors.New("没有商品的bom单")
}
bomItems := bom.BomItems
perGoDealNumber := 40
perGoDealNumber := 200
//开启协程处理搜索
var wg sync.WaitGroup
//判断是否有余数
......@@ -77,16 +78,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
}
defer client.Stop()
//匹配之前,去遍历bom_item,把没有型号名称但是有参数的bom_item进行型号补充
//MatchGoodsNameByAttrs(bomItems)
bomItems, err = MatchGoodsNameByAttrs(bomItems)
//for _, item := range bomItems {
// if item.GoodsName != "" {
// fmt.Println(item.GoodsName)
// }
//}
if err != nil {
return err
}
//第一次先去精确匹配
goodsMapList, err := getUpdateGoodsData(bomId, bomItems, deliveryType, sort, client, true)
......@@ -107,6 +99,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
}
//再删除模糊匹配到的数据,就得到完全没有匹配的数据了
var notMatchBomItems []model.BomItem
fmt.Println(len(append(goodsMapList, fuzzyGoodsMapList...)))
for _, bomItem := range bomItems {
if !checkInGoodsMap(bomItem, append(goodsMapList, fuzzyGoodsMapList...)) {
notMatchBomItems = append(notMatchBomItems, bomItem)
......@@ -117,6 +110,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
if err != nil {
return
}
//然后去处理匹配到的数据
err = UpdateGoodsData(append(goodsMapList, fuzzyGoodsMapList...))
if err != nil {
return
......@@ -234,6 +228,13 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
continue
}
}
//经过了最前面的参数匹配
//如果型号还是为空,则用参数去匹配,因为有可能参数里面填了型号
//if bom.GoodsName == "" && bom.Attrs == "" {
// continue
//} else if bom.GoodsName == "" && bom.Attrs != "" {
// bom.GoodsName = bom.Attrs
//}
//构建一个goods_name对应的bomItems列表
searchRequest := getSearchParams(index, bom.GoodsName, bom.BrandName, sort, bom.Number, rawSearch)
searchFlag = true
......@@ -271,7 +272,6 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
goodsMap.BomItemId = bomItems[key].BomItemID
goodsMap.BomId = bomId
goodsMap.DeliveryType = deliveryType
goodsMapList = append(goodsMapList, goodsMap)
break
}
......@@ -331,7 +331,7 @@ func getTermQuery(goodsName, brandName string, number int, flag bool) (query *es
}
//query = query.Filter(es.NewRangeQuery("single_price").Gt(0))
//query = query.Filter(es.NewRangeQuery("stock").Gt(0))
//query = query.Filter(es.NewTermQuery("status", 1))
query = query.Filter(es.NewTermQuery("status", 1))
//query = query.Filter(es.NewRangeQuery("single_price").Gt(0))
//src, err := query.Source()
//if err != nil {
......
......@@ -15,7 +15,7 @@ var KeywordRegular = map[string]string{
`v`: "V",
}
var PureNumberRegular = `(\d+(\.\d+)?)`
var GetAttrUnitRegular = `[\d.]|±|\+_|\+-|/|\(.*\)|`
var GetAttrUnitRegular = `[\d.]|±|\+_|\+-|/|\(.*\)|\+/-|`
//`^[\d\.]+(欧姆|欧|O|o|R|r)$`: "Ω",
//`^[\d\.]+(Uf|uf|μf|uF|UF)$`: "μF",
......
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