Commit f4087c27 by mushishixian

修改bom逻辑

parent d9864388
......@@ -14,20 +14,21 @@ type RecvPro struct {
}
func init() {
queueExchange := rabbitmq.QueueExchange{
"bom_match",
"bom_match",
"bom",
"direct",
"amqp://huntadmin:jy2y2900@192.168.1.237:5672/",
}
//queueExchange := rabbitmq.QueueExchange{
// "bom_match",
// "bom_match",
// "bom",
// "direct",
// "amqp://huntadmin:jy2y2900@192.168.1.237:5672/",
//}
//str := `{"bom_id":666,"delivery_type":1,"sort":1}`
str := `{"bom_id":692,"delivery_type":1,"sort":1}`
rabbitmq.Send(queueExchange, str)
//str := `{"bom_id":692,"delivery_type":1,"sort":1}`
//rabbitmq.Send(queueExchange, str)
}
func (t *RecvPro) Consumer(dataByte []byte) (err error) {
fmt.Println("开始")
var message model.BomMessage
if err = json.Unmarshal(dataByte, &message); err != nil {
log.Error(err)
......
......@@ -48,6 +48,7 @@ type Api struct {
Upload string `ini:"upload"`
ApiPort string `ini:"api_port"`
Mode string `ini:"mode"`
Attrs string `ini:"attrs"`
}
type Oss struct {
......
package logic
import (
"bom_server/configs"
"bom_server/internal/mapping"
"bom_server/internal/model"
"bom_server/internal/pkg/gredis"
......@@ -15,7 +16,6 @@ import (
func GetStandardAttrs(bomItems []model.BomItem) []model.BomItem {
//先根据参数去构建批量查询条件
for key, item := range bomItems {
//用参数去请求接口,获取转换后的参数
var attrParams []string
//如果有型号,没有参数,则尝试用型号当作参数去请求,判断是否为参数
......@@ -25,12 +25,11 @@ func GetStandardAttrs(bomItems []model.BomItem) []model.BomItem {
attrParams = []string{item.Attrs}
}
params := req.BodyJSON(attrParams)
resp, err := req.Post("http://192.168.2.141:50053/unit_conversion", params)
resp, err := req.Post(configs.ApiSetting.Attrs, params)
if err != nil {
fmt.Println(err)
}
result := resp.String()
//匹配出来的型号
var words, attrsList, encapList []string
wordsArray := gjson.Get(result, "words").Array()
......@@ -42,7 +41,6 @@ func GetStandardAttrs(bomItems []model.BomItem) []model.BomItem {
attrsList = append(attrsList, attr.String())
}
encapArray := gjson.Get(result, "encap").Array()
fmt.Println(result)
for _, attr := range encapArray {
encapList = append(encapList, attr.String())
}
......@@ -52,9 +50,6 @@ func GetStandardAttrs(bomItems []model.BomItem) []model.BomItem {
}
//如果words等于0,但是属性有的情况
if len(words) == 0 && len(attrsList) > 0 {
if item.GoodsName != "" {
item.GoodsName = ""
}
item.AttrList = attrsList
}
//如果原来的encap为空的情况下,识别出encap的话,就要补充
......@@ -64,22 +59,22 @@ func GetStandardAttrs(bomItems []model.BomItem) []model.BomItem {
var attrsSlice []string
for _, attr := range item.AttrList {
attr = GetStandardEsAttr(attr)
attrs := GetStandardEsAttr(attr)
fmt.Println(attrs)
if attr != "" {
attrsSlice = append(attrsSlice, attr)
attrsSlice = append(attrsSlice, attrs...)
}
}
//转换成新约定的形式
attrsSlice = transformNew(attrsSlice)
item.AttrList = attrsSlice
bomItems[key] = item
fmt.Println("goooooooooo", item.AttrList)
}
return bomItems
}
//将属性值转成ES的标准值(例如 : 阻值(欧姆)€3000)
func GetStandardEsAttr(attr string) (result string) {
func GetStandardEsAttr(attr string) (result []string) {
//先找出单位,通过将数字替换成,第一个字符不是数字的,跳过
r, _ := regexp.Compile(mapping.GetAttrUnitRegular)
attrUnit := strings.Trim(r.ReplaceAllString(attr, ""), " ")
......@@ -88,7 +83,7 @@ func GetStandardEsAttr(attr string) (result string) {
pureNumberStr := numberR.FindString(attr)
//如果属性是纯数字,则代表是精度
if pureNumberStr == attr {
return "精度" + "€" + attr
return []string{"精度" + "€" + attr}
}
//找出对应单位需要转换的值
var attrName, baseUnit string
......@@ -97,17 +92,28 @@ func GetStandardEsAttr(attr string) (result string) {
baseUnit = value
}
if baseUnit == "" {
return attr
return []string{attr}
}
//获取重要属性名称
spUnit := "阻值(欧姆)|直流电阻(内阻)"
var spUnits []string
if value, exist := mapping.UnitAttrMapping[baseUnit]; exist {
//特殊处理,因为Ω代表的可能是这两个
if value == spUnit {
spUnits = strings.Split(spUnit, "|")
for _, unit := range spUnits {
result = append(result, unit+"€"+pureNumberStr)
}
} else {
attrName = value
result = append(result, attrName+"€"+pureNumberStr)
}
}
result = attrName + "€" + pureNumberStr
//再去找没有单位的对应属性
attrName, _ = redis.String(gredis.HGet("sku_map2", attr))
if attrName != "" {
result = attrName + "€" + attr
result = append(result, attrName+"€"+attr)
}
return result
}
......
......@@ -91,7 +91,6 @@ func UpdateBomItem(bomId, bomItemId int) (err error) {
defer client.Stop()
//匹配之前,去遍历bom_item,把没有型号名称但是有参数的bom_item进行型号补充
bomItems = GetStandardAttrs(bomItems)
//bomItems, err = MatchGoodsNameByAttrs(bomItems)
//第一次去精确匹配,没有再去模糊匹配
var goodsMapList []GoodsMap
goodsMapList, err = getUpdateGoodsData(bomId, bomItems, where.DeliveryType, where.Sort, client, true)
......
......@@ -180,5 +180,3 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType, sort
}
return
}
......@@ -80,10 +80,10 @@ 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) {
fmt.Println("商品名称 : ",bomItem.GoodsName)
fmt.Println("参数列表 : ",bomItem.AttrList)
fmt.Println("商品名称 : ", bomItem.GoodsName)
fmt.Println("参数列表 : ", bomItem.AttrList)
bomItem.Encap = TransformEncap(bomItem.Encap)
fmt.Println("封装 : ",bomItem.Encap)
fmt.Println("封装 : ", bomItem.Encap)
query := getTermQuery(bomItem, sort, flag)
source := es.NewSearchSource().Query(query)
if sort == 1 {
......@@ -116,11 +116,15 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool) (query *es.BoolQue
//商品名称太短的或者没有商品名称的,去搜索参数
if len(goodsName) <= 3 {
if len(bomItem.AttrList) > 0 {
var params []interface{}
//var params []interface{}
for _, attr := range bomItem.AttrList {
params = append(params, attr)
//需要注意的点 : 因为0.158Ω可以对应 电阻 或者 直流电阻 ,所以当识别出来是电阻 或者 直流电阻 的时候,就不能用must,要用should
if strings.Contains(attr,"ZLNZ€") || strings.Contains(attr,"OM€") {
query.Should(es.NewTermQuery("attr_bom", attr))
}else{
query.Must(es.NewTermQuery("attr_bom", attr))
}
}
query = query.Must(es.NewTermsQuery("attr_bom", params...))
} else {
query = query.Must(es.NewTermsQuery("attr_bom", "$_$"))
}
......
......@@ -6,7 +6,7 @@ var GetAttrUnitRegular = `[\d.]|±|\+_|\+-|/|\(.*\)|\+/-|`
//属性单位对应属性
var UnitAttrMapping = map[string]string{
"r": "阻值(欧姆)|直流电阻(内阻)",
"Ω": "阻值(欧姆)",
"Ω": "阻值(欧姆)|直流电阻(内阻)",
"OHM": "阻值(欧姆)|直流电阻(内阻)",
"mh": "电感值",
"H": "电感值",
......
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