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
8709c3b6
authored
Jun 29, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix
parent
ae492025
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
14 deletions
internal/logic/attr.go
internal/mapping/search_keyword.go
internal/logic/attr.go
View file @
8709c3b6
...
@@ -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
}
}
...
...
internal/mapping/search_keyword.go
View file @
8709c3b6
...
@@ -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"
:
"阻值(欧姆)|直流电阻(内阻)"
,
...
...
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