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
20bf6765
authored
Jun 16, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
加上封装参数匹配
parent
27107092
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
7 deletions
cmd/queue/bom.go
internal/logic/attr.go
internal/model/bom_item.go
cmd/queue/bom.go
View file @
20bf6765
...
...
@@ -22,7 +22,7 @@ func init() {
// "amqp://huntadmin:jy2y2900@192.168.1.237:5672/",
//}
//
//str := `{"bom_id":43
2
,"delivery_type":1,"sort":1}`
//str := `{"bom_id":43
6
,"delivery_type":1,"sort":1}`
//rabbitmq.Send(queueExchange, str)
}
...
...
internal/logic/attr.go
View file @
20bf6765
...
...
@@ -31,12 +31,12 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
for
_
,
item
:=
range
bomItems
{
//如果有型号,但是型号有可能是参数,所以先去匹配下参数,有的话转成对应的型号
if
item
.
GoodsName
!=
""
{
search
=
searchAttr
(
item
.
GoodsName
,
item
.
BrandName
,
search
)
search
=
searchAttr
(
item
.
GoodsName
,
item
.
BrandName
,
item
.
Encap
,
search
)
searchFlag
=
true
}
//如果没有型号,但是有参数(参数有可能是型号),那就去匹配参数
if
item
.
GoodsName
==
""
&&
item
.
Attrs
!=
""
{
search
=
searchAttr
(
item
.
Attrs
,
item
.
BrandName
,
search
)
search
=
searchAttr
(
item
.
Attrs
,
item
.
BrandName
,
item
.
Encap
,
search
)
searchFlag
=
true
}
}
...
...
@@ -66,16 +66,27 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
return
}
func
searchAttr
(
attrOrigin
,
brandName
string
,
search
*
es
.
MultiSearchService
)
(
result
*
es
.
MultiSearchService
)
{
func
searchAttr
(
attrOrigin
,
brandName
,
encap
string
,
search
*
es
.
MultiSearchService
)
(
result
*
es
.
MultiSearchService
)
{
//先去切割参数得到参数列表
attrs
:=
splitAttrs
(
attrOrigin
)
var
attrsSlice
[]
string
//fmt.Println(attrs)
//去转换每一个参数,得到去查询es的标准格式
for
_
,
attr
:=
range
attrs
{
attr
=
TransformESParam
(
attr
)
attrsSlice
=
append
(
attrsSlice
,
attr
)
}
//单独针对封装进行转换
if
encap
!=
""
{
//先提取出纯数字
numberR
,
_
:=
regexp
.
Compile
(
mapping
.
PureNumberRegular
)
pureNumber
:=
numberR
.
FindString
(
encap
)
//再去找对应属性
attrName
,
_
:=
redis
.
String
(
gredis
.
HGet
(
"sku_map2"
,
pureNumber
))
if
attrName
!=
""
{
attrValue
:=
attrName
+
"€"
+
pureNumber
attrsSlice
=
append
(
attrsSlice
,
attrValue
)
}
}
query
:=
getQuery
(
attrsSlice
)
if
brandName
!=
""
{
//提取全英文,转成大写
...
...
@@ -177,6 +188,7 @@ func getAttrValueByAttr(attr string) (attrValue string) {
attrNumber
,
_
=
strconv
.
ParseFloat
(
pureNumber
,
64
)
//找出对应单位需要转换的值
var
attrName
string
//再去找没有单位的对应属性
if
attrUnit
!=
""
{
for
unit
,
value
:=
range
mapping
.
UnitValueMapping
{
//如果不是标准最小单位,则要进行转换
...
...
@@ -233,9 +245,11 @@ func getQuery(attrs []string) (query *es.BoolQuery) {
query
.
Should
(
nestedQuery
)
}
var
shouldMatchNumber
int
if
len
(
attrs
)
>=
2
{
if
len
(
attrs
)
>
3
{
shouldMatchNumber
=
3
}
else
if
len
(
attrs
)
>=
2
{
shouldMatchNumber
=
2
}
else
{
}
else
{
shouldMatchNumber
=
1
}
query
.
MinimumNumberShouldMatch
(
shouldMatchNumber
)
...
...
internal/model/bom_item.go
View file @
20bf6765
...
...
@@ -12,6 +12,7 @@ type BomItem struct {
// Number 需求数量
Number
int
`json:"number"`
Attrs
string
`json:"attrs"`
Encap
string
`json:"encap"`
// ItemStatus 匹配状态 1:等待匹配 2:可购现货 3:待询价 4:需要修正
ItemStatus
int
`json:"item_status"`
// DelStatus 删除状态 1:正常 2:删除
...
...
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