Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
bom_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4d08965e
authored
Jun 22, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix
parent
353582ce
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
16 deletions
internal/logic/attr.go
internal/logic/brand_map.go
internal/mapping/search_keyword.go
internal/model/bom_item.go
internal/logic/attr.go
View file @
4d08965e
...
...
@@ -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
)
{
//先去切割参数得到参数列表
fmt
.
Println
(
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
//去转换每一个参数,得到去查询es的标准格式
for
_
,
attr
:=
range
attrs
{
...
...
@@ -128,9 +145,18 @@ func splitAttrs(attrs string) (result []string) {
if
len
(
result
)
>
1
{
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,所以要统一转成正常的Ω
func
changeKeyword
(
attr
string
)
(
result
string
)
{
regulars
:=
mapping
.
KeywordRegular
...
...
@@ -143,19 +169,6 @@ func changeKeyword(attr string) (result string) {
//将属性值转成ES的标准值(例如 : 阻值(欧姆)€3000)
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
)
return
attrValue
}
...
...
@@ -163,7 +176,7 @@ func TransformESParam(attr string) (result string) {
//根据参数单位或者参数值获取对应的重要属性,组成最后查询的字符串
//±
func
getAttrValueByAttr
(
attr
string
)
(
attrValue
string
)
{
//先找出单位
//先找出单位
,通过将数字替换成
r
,
_
:=
regexp
.
Compile
(
mapping
.
GetAttrUnitRegular
)
attrUnit
:=
strings
.
Trim
(
r
.
ReplaceAllString
(
attr
,
""
),
" "
)
//如果单位是W,则要进行除法计算
...
...
internal/logic/brand_map.go
0 → 100644
View file @
4d08965e
package
logic
import
"bom_server/internal/model"
//和品牌映射有关的逻辑
//根据用户输入的品牌获取映射后的品牌,没有映射的话不变,有的话变
func
getBrandMap
(
bomItems
[]
model
.
BomItem
)
{
}
internal/mapping/search_keyword.go
View file @
4d08965e
...
...
@@ -14,7 +14,6 @@ var KeywordRegular = map[string]string{
`v`
:
"V"
,
}
var
PureNumberRegular
=
`(\d+(\.\d+)?)`
var
PureLetterRegular
=
`[a-zA-Z0-9]+`
var
GetAttrUnitRegular
=
`[\d.]|±|\+_|\+-|/|\(.*\)|\+/-|`
//`^[\d\.]+(欧姆|欧|O|o|R|r)$`: "Ω",
...
...
@@ -99,4 +98,3 @@ var UnitValueMapping = map[string]string{
"kW"
:
"1000"
,
"%"
:
"0.01"
,
}
internal/model/bom_item.go
View file @
4d08965e
...
...
@@ -22,5 +22,10 @@ type BomItem struct {
// UpdateTime 更新时间
UpdateTime
int
`json:"update_time"`
//映射后的自营品牌id
ZyBrandId
int
`json:"-"`
//映射后的联营品牌id
LyBrandId
int
`json:"-"`
Matching
BomItemMatching
`json:"matching"`
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment