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
dd2c7e26
authored
Jun 22, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix
parent
4d08965e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
20 deletions
cmd/queue/bom.go
internal/logic/attr.go
internal/logic/match.go
cmd/queue/bom.go
View file @
dd2c7e26
...
...
@@ -14,16 +14,16 @@ type RecvPro struct {
}
func
init
()
{
//
queueExchange := rabbitmq.QueueExchange{
//
"bom_match",
//
"bom_match",
//
"bom",
//
"direct",
//
"amqp://huntadmin:jy2y2900@192.168.1.237:5672/",
//
}
//
//str := `{"bom_id":568
,"delivery_type":1,"sort":1}`
//
rabbitmq.Send(queueExchange, str)
queueExchange
:=
rabbitmq
.
QueueExchange
{
"bom_match"
,
"bom_match"
,
"bom"
,
"direct"
,
"amqp://huntadmin:jy2y2900@192.168.1.237:5672/"
,
}
str
:=
`{"bom_id":545
,"delivery_type":1,"sort":1}`
rabbitmq
.
Send
(
queueExchange
,
str
)
}
func
(
t
*
RecvPro
)
Consumer
(
dataByte
[]
byte
)
(
err
error
)
{
...
...
internal/logic/attr.go
View file @
dd2c7e26
...
...
@@ -31,8 +31,9 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
for
_
,
item
:=
range
bomItems
{
//如果有型号,但是型号有可能是参数,所以先去匹配下参数,有的话转成对应的型号
if
item
.
GoodsName
!=
""
&&
item
.
Attrs
==
""
{
//search = searchAttr(item.GoodsName, item.BrandName, item.Encap, search)
//searchFlag = true
//todo
search
=
searchAttr
(
item
.
GoodsName
,
item
.
BrandName
,
item
.
Encap
,
search
)
searchFlag
=
true
}
//如果没有型号,但是有参数(参数有可能是型号),那就去匹配参数
if
item
.
GoodsName
==
""
&&
item
.
Attrs
!=
""
{
...
...
@@ -66,29 +67,31 @@ 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个的时候,就
代表这的确是参数了,就
要去针对每个参数进行里面再一次提纯
//当切割出来的参数大于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
]
if
ek
==
0
{
attrs
[
key
]
=
extractRes
[
0
]
}
else
{
attrs
=
append
(
attrs
,
eAttr
)
}
}
}
}
else
{
attrs
=
extractAttrsByStr
(
attrs
[
0
])
}
fmt
.
Println
(
attrs
)
var
attrsSlice
[]
string
//去转换每一个参数,得到去查询es的标准格式
for
_
,
attr
:=
range
attrs
{
attr
=
TransformESParam
(
attr
)
attrsSlice
=
append
(
attrsSlice
,
attr
)
if
attr
!=
""
{
attrsSlice
=
append
(
attrsSlice
,
attr
)
}
}
//单独针对封装进行转换
if
encap
!=
""
{
...
...
@@ -103,7 +106,7 @@ func searchAttr(attrOrigin, brandName, encap string, search *es.MultiSearchServi
}
}
query
:=
getQuery
(
attrsSlice
)
if
brandName
!=
""
{
if
brandName
!=
""
&&
len
(
attrsSlice
)
>
0
{
//提取全英文,转成大写
if
strings
.
Contains
(
brandName
,
" "
)
{
//有空格隔开只取第一个
...
...
@@ -120,6 +123,7 @@ func searchAttr(attrOrigin, brandName, encap string, search *es.MultiSearchServi
source
.
Sort
(
"brand_sort"
,
true
)
source
=
source
.
From
(
0
)
.
Size
(
1
)
searchRequest
:=
es
.
NewSearchRequest
()
.
Source
(
source
)
//fmt.Println(searchRequest.Body())
return
search
.
Add
(
searchRequest
)
}
...
...
@@ -152,8 +156,19 @@ func splitAttrs(attrs string) (result []string) {
//提取参数
func
extractAttr
(
attr
string
)
[]
string
{
regexpUnit
:=
strings
.
Join
(
getNeedCheckUnit
(),
"|"
)
r
,
_
:=
regexp
.
Compile
(
"(
\\
d+(
\\
.
\\
d+)?)("
+
regexpUnit
+
")"
)
r
,
_
:=
regexp
.
Compile
(
"(
\\
d+[
\\
/
\\
d. ]*|
\\
d)("
+
regexpUnit
+
")"
+
""
)
res
:=
r
.
FindAllString
(
attr
,
100
)
return
res
}
//提取参数,从一个字符串里面,注意要提取出两个参数才当作是
func
extractAttrsByStr
(
attr
string
)
[]
string
{
regexpUnit
:=
strings
.
Join
(
getNeedCheckUnit
(),
"|"
)
r
,
_
:=
regexp
.
Compile
(
"(
\\
d+[
\\
/
\\
d. ]*|
\\
d)("
+
regexpUnit
+
")"
+
""
)
res
:=
r
.
FindAllString
(
attr
,
100
)
if
len
(
res
)
<
2
{
return
[]
string
{
attr
}
}
return
res
}
...
...
@@ -237,6 +252,10 @@ func getAttrValueByAttr(attr string) (attrValue string) {
//获取匹配的条件
func
getQuery
(
attrs
[]
string
)
(
query
*
es
.
BoolQuery
)
{
//如果attrs为空,也要构建一个结果为空的查询,因为要使结果和bomItems数量对应起来
if
len
(
attrs
)
==
0
{
attrs
=
[]
string
{
"€_€"
}
}
var
subQuery
*
es
.
TermQuery
var
nestedQuery
*
es
.
NestedQuery
query
=
es
.
NewBoolQuery
()
...
...
internal/logic/match.go
View file @
dd2c7e26
...
...
@@ -7,6 +7,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"math"
"regexp"
"strings"
...
...
@@ -83,6 +84,9 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
defer
client
.
Stop
()
//匹配之前,去遍历bom_item,把没有型号名称但是有参数的bom_item进行型号补充
bomItems
,
err
=
MatchGoodsNameByAttrs
(
bomItems
)
for
_
,
value
:=
range
bomItems
{
fmt
.
Println
(
value
.
GoodsName
)
}
//第一次先去精确匹配
goodsMapList
,
err
:=
getUpdateGoodsData
(
bomId
,
bomItems
,
deliveryType
,
sort
,
client
,
true
)
if
err
!=
nil
{
...
...
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