Commit 4d08965e by mushishixian

fix

parent 353582ce
...@@ -66,7 +66,24 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er ...@@ -66,7 +66,24 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
func searchAttr(attrOrigin, brandName, encap string, search *es.MultiSearchService) (result *es.MultiSearchService) { func searchAttr(attrOrigin, brandName, encap string, search *es.MultiSearchService) (result *es.MultiSearchService) {
//先去切割参数得到参数列表 //先去切割参数得到参数列表
fmt.Println(attrOrigin)
attrs := splitAttrs(attrOrigin) attrs := splitAttrs(attrOrigin)
//当切割出来的参数大于1个的时候,就代表这的确是参数了,就要去针对每个参数进行里面再一次提纯
if len(attrs) > 1 {
for key, attr := range attrs {
attrs[key] = changeKeyword(attr)
//切割完以后,还要去对切割后的参数提取值,因为有可能参数没有分隔符
extractRes := extractAttr(attrs[key])
for ek, eAttr := range extractRes {
if ek == 1 {
attrs[key] = extractRes[1]
} else {
attrs = append(attrs, eAttr)
}
}
}
}
fmt.Println(attrs)
var attrsSlice []string var attrsSlice []string
//去转换每一个参数,得到去查询es的标准格式 //去转换每一个参数,得到去查询es的标准格式
for _, attr := range attrs { for _, attr := range attrs {
...@@ -128,9 +145,18 @@ func splitAttrs(attrs string) (result []string) { ...@@ -128,9 +145,18 @@ func splitAttrs(attrs string) (result []string) {
if len(result) > 1 { if len(result) > 1 {
return return
} }
//按照分隔符切完了,再去每个去正则提取
return return
} }
//提取参数
func extractAttr(attr string) []string {
regexpUnit := strings.Join(getNeedCheckUnit(), "|")
r, _ := regexp.Compile("(\\d+(\\.\\d+)?)(" + regexpUnit + ")")
res := r.FindAllString(attr, 100)
return res
}
//将写法转成正规写法,转换单位,比如有的人喜欢将Ω输成欧姆或者O,所以要统一转成正常的Ω //将写法转成正规写法,转换单位,比如有的人喜欢将Ω输成欧姆或者O,所以要统一转成正常的Ω
func changeKeyword(attr string) (result string) { func changeKeyword(attr string) (result string) {
regulars := mapping.KeywordRegular regulars := mapping.KeywordRegular
...@@ -143,19 +169,6 @@ func changeKeyword(attr string) (result string) { ...@@ -143,19 +169,6 @@ func changeKeyword(attr string) (result string) {
//将属性值转成ES的标准值(例如 : 阻值(欧姆)€3000) //将属性值转成ES的标准值(例如 : 阻值(欧姆)€3000)
func TransformESParam(attr string) (result string) { func TransformESParam(attr string) (result string) {
attr = changeKeyword(attr)
//needCheckUnits := getNeedCheckUnit()
//获取该属性对应的单位
//for _, unit := range needCheckUnits {
// //todo : bug
// index := strings.Index(attr, unit)
// if index > 0 {
// attr = string([]rune(attr)[:index+len(unit)-1])
// }
// //得到截取后的参数,去得到需要用于es查询的参数
//attrValue := getAttrValueByAttr(attr)
// return attrValue
//}
attrValue := getAttrValueByAttr(attr) attrValue := getAttrValueByAttr(attr)
return attrValue return attrValue
} }
...@@ -163,7 +176,7 @@ func TransformESParam(attr string) (result string) { ...@@ -163,7 +176,7 @@ func TransformESParam(attr string) (result string) {
//根据参数单位或者参数值获取对应的重要属性,组成最后查询的字符串 //根据参数单位或者参数值获取对应的重要属性,组成最后查询的字符串
//± //±
func getAttrValueByAttr(attr string) (attrValue string) { func getAttrValueByAttr(attr string) (attrValue string) {
//先找出单位 //先找出单位,通过将数字替换成
r, _ := regexp.Compile(mapping.GetAttrUnitRegular) r, _ := regexp.Compile(mapping.GetAttrUnitRegular)
attrUnit := strings.Trim(r.ReplaceAllString(attr, ""), " ") attrUnit := strings.Trim(r.ReplaceAllString(attr, ""), " ")
//如果单位是W,则要进行除法计算 //如果单位是W,则要进行除法计算
......
package logic
import "bom_server/internal/model"
//和品牌映射有关的逻辑
//根据用户输入的品牌获取映射后的品牌,没有映射的话不变,有的话变
func getBrandMap(bomItems []model.BomItem) {
}
...@@ -14,7 +14,6 @@ var KeywordRegular = map[string]string{ ...@@ -14,7 +14,6 @@ var KeywordRegular = map[string]string{
`v`: "V", `v`: "V",
} }
var PureNumberRegular = `(\d+(\.\d+)?)` var PureNumberRegular = `(\d+(\.\d+)?)`
var PureLetterRegular = `[a-zA-Z0-9]+`
var GetAttrUnitRegular = `[\d.]|±|\+_|\+-|/|\(.*\)|\+/-|` var GetAttrUnitRegular = `[\d.]|±|\+_|\+-|/|\(.*\)|\+/-|`
//`^[\d\.]+(欧姆|欧|O|o|R|r)$`: "Ω", //`^[\d\.]+(欧姆|欧|O|o|R|r)$`: "Ω",
...@@ -67,7 +66,7 @@ var UnitBaseMapping = map[string]string{ ...@@ -67,7 +66,7 @@ var UnitBaseMapping = map[string]string{
"kW": "W", "kW": "W",
"KW": "W", "KW": "W",
"%": "%", "%": "%",
} }
//根据单位对值的转换,比如1kΩ=>1000Ω //根据单位对值的转换,比如1kΩ=>1000Ω
...@@ -99,4 +98,3 @@ var UnitValueMapping = map[string]string{ ...@@ -99,4 +98,3 @@ var UnitValueMapping = map[string]string{
"kW": "1000", "kW": "1000",
"%": "0.01", "%": "0.01",
} }
...@@ -22,5 +22,10 @@ type BomItem struct { ...@@ -22,5 +22,10 @@ type BomItem struct {
// UpdateTime 更新时间 // UpdateTime 更新时间
UpdateTime int `json:"update_time"` UpdateTime int `json:"update_time"`
//映射后的自营品牌id
ZyBrandId int `json:"-"`
//映射后的联营品牌id
LyBrandId int `json:"-"`
Matching BomItemMatching `json:"matching"` Matching BomItemMatching `json:"matching"`
} }
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