Commit 8709c3b6 by mushishixian

fix

parent ae492025
...@@ -33,12 +33,15 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er ...@@ -33,12 +33,15 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
if item.GoodsName != "" && item.Attrs == "" { if item.GoodsName != "" && item.Attrs == "" {
search = searchAttr(item, search) search = searchAttr(item, search)
searchFlag = true searchFlag = true
} }else{
//如果没有型号,但是有参数(参数有可能是型号),那就去匹配参数
if item.GoodsName == "" && item.Attrs != "" {
search = searchAttr(item, search) search = searchAttr(item, search)
searchFlag = true searchFlag = true
} }
////如果没有型号,但是有参数(参数有可能是型号),那就去匹配参数
//if item.GoodsName == "" && item.Attrs != "" {
// search = searchAttr(item, search)
// searchFlag = true
//}
} }
if !searchFlag { if !searchFlag {
return bomItems, nil return bomItems, nil
...@@ -56,6 +59,10 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er ...@@ -56,6 +59,10 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
if responses.Hits != nil { if responses.Hits != nil {
for _, hit := range responses.Hits.Hits { for _, hit := range responses.Hits.Hits {
res, _ := hit.Source.MarshalJSON() res, _ := hit.Source.MarshalJSON()
//if bomItems[key].Attrs=="330Ω,1/4W,±5%,1206" {
// fmt.Println(string(res))
// fmt.Println(gjson.Get(string(res), "goods_name").String())
//}
if bomItems[key].GoodsName == "" || (bomItems[key].Attrs == "" && bomItems[key].GoodsName != "") { if bomItems[key].GoodsName == "" || (bomItems[key].Attrs == "" && bomItems[key].GoodsName != "") {
bomItems[key].GoodsName = gjson.Get(string(res), "goods_name").String() bomItems[key].GoodsName = gjson.Get(string(res), "goods_name").String()
} }
...@@ -170,7 +177,7 @@ func splitAttrs(attrs string) (result []string) { ...@@ -170,7 +177,7 @@ func splitAttrs(attrs string) (result []string) {
//提取参数 //提取参数
func extractAttr(attr string) []string { func extractAttr(attr string) []string {
regexpUnit := strings.Join(getNeedCheckUnit(), "|") regexpUnit := strings.Join(getNeedCheckUnit(), "|")
r, _ := regexp.Compile("(\\d+[\\/\\d. ]*|\\d)(" + regexpUnit + ")" + "") r, _ := regexp.Compile("$(\\d+[\\/\\d. ]*|\\d)(" + regexpUnit + ")" + "")
res := r.FindAllString(attr, 100) res := r.FindAllString(attr, 100)
return res return res
} }
......
...@@ -7,20 +7,16 @@ var KeywordRegular = map[string]string{ ...@@ -7,20 +7,16 @@ var KeywordRegular = map[string]string{
"NPO|NP0|nPO|npO|npo|nP0|np0": "C0G", "NPO|NP0|nPO|npO|npo|nP0|np0": "C0G",
"华科|华新科技|华新科": "华新", "华科|华新科技|华新科": "华新",
`(欧姆|欧|O|o|R|r)`: "Ω", `(欧姆|欧|O|o|R|r)$`: "Ω",
`(Uf|uf|μf|uF|UF)`: "μF", `(Uf|uf|μf|uF|UF)$`: "μF",
`(Uh|uh|μh|uH|UH)`: "μH", `(Nf|NF)$`: "nF",
`K`: "nF", `(Uh|uh|μh|uH|UH)$`: "μH",
`v`: "V", `K$`: "nF",
`v$`: "V",
} }
var PureNumberRegular = `(\d+(\.\d+)?)` var PureNumberRegular = `(\d+(\.\d+)?)`
var GetAttrUnitRegular = `[\d.]|±|\+_|\+-|/|\(.*\)|\+/-|` var GetAttrUnitRegular = `[\d.]|±|\+_|\+-|/|\(.*\)|\+/-|`
//`^[\d\.]+(欧姆|欧|O|o|R|r)$`: "Ω",
//`^[\d\.]+(Uf|uf|μf|uF|UF)$`: "μF",
//`^[\d\.]+(Uh|uh|μh|uH|UH)$`: "μH",
//`^[\d\.]+K$`: "KΩ",
//属性单位对应属性 //属性单位对应属性
var UnitAttrMapping = map[string]string{ var UnitAttrMapping = map[string]string{
"r": "阻值(欧姆)|直流电阻(内阻)", "r": "阻值(欧姆)|直流电阻(内阻)",
......
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