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
0ada3b17
authored
Jul 09, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
封装为重要属性
parent
57b8c0d3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
26 deletions
internal/logic/attr.go
internal/logic/goods.go
internal/mapping/search_keyword.go
internal/model/goods.go
internal/logic/attr.go
View file @
0ada3b17
...
...
@@ -98,21 +98,20 @@ func searchAttr(bomItem model.BomItem, search *es.MultiSearchService) (result *e
attrsSlice
=
append
(
attrsSlice
,
attr
)
}
}
query
:=
getQuery
(
attrsSlice
)
//单独针对封装进行转换
if
bomItem
.
Encap
!=
""
{
//先提取出纯数字
numberR
,
_
:=
regexp
.
Compile
(
mapping
.
PureNumberRegular
)
pureNumber
:=
numberR
.
FindString
(
bomItem
.
Encap
)
//再去找对应属性
attrName
,
_
:=
redis
.
String
(
gredis
.
HGet
(
"sku_map2"
,
pureNumber
))
if
attrName
!=
""
{
attrValue
:=
attrName
+
"€"
+
pureNumber
if
!
php2go
.
InArray
(
attrValue
,
attrsSlice
)
{
attrsSlice
=
append
(
attrsSlice
,
attrValue
)
}
attrValue
:=
"封装"
+
"€"
+
pureNumber
if
!
php2go
.
InArray
(
attrValue
,
attrsSlice
)
{
subQuery
:=
es
.
NewTermQuery
(
"attrs.attr_value"
,
attrValue
)
nestedQuery
:=
es
.
NewNestedQuery
(
"attrs"
,
subQuery
)
query
.
Must
(
nestedQuery
)
}
}
query
:=
getQuery
(
attrsSlice
)
//如果ZyBrandId不为空,则代表匹配到了映射id
if
bomItem
.
ZyBrandId
!=
""
&&
len
(
attrsSlice
)
>
0
{
query
.
Should
(
es
.
NewTermQuery
(
"brand_name"
,
bomItem
.
ZyBrandName
))
...
...
@@ -144,8 +143,17 @@ func searchAttr(bomItem model.BomItem, search *es.MultiSearchService) (result *e
//切割参数
func
splitAttrs
(
attrs
string
)
(
result
[]
string
)
{
result
=
strings
.
Split
(
attrs
,
" "
)
if
len
(
result
)
>
1
{
return
}
result
=
strings
.
Split
(
attrs
,
","
)
if
len
(
result
)
>
1
{
return
}
result
=
strings
.
Split
(
attrs
,
"|"
)
if
len
(
result
)
>
1
{
return
}
result
=
strings
.
Split
(
attrs
,
","
)
if
len
(
result
)
>
1
{
return
...
...
@@ -222,7 +230,6 @@ func getAttrValueByAttr(attr string) (attrValue string) {
attrNumber
,
_
=
strconv
.
ParseFloat
(
pureNumber
,
64
)
//找出对应单位需要转换的值
var
attrName
string
//再去找没有单位的对应属性
if
attrUnit
!=
""
{
for
unit
,
value
:=
range
mapping
.
UnitValueMapping
{
//如果不是标准最小单位,则要进行转换
...
...
@@ -245,6 +252,8 @@ func getAttrValueByAttr(attr string) (attrValue string) {
break
}
}
//就算是提取出所谓的单位,也有可能是封装里面乱写的,比如 C0402R
//所以还是要去判断是否是封装
}
else
{
//再去找没有单位的对应属性
attrName
,
_
=
redis
.
String
(
gredis
.
HGet
(
"sku_map2"
,
attr
))
...
...
@@ -266,6 +275,7 @@ func getQuery(attrs []string) (query *es.BoolQuery) {
var
subQuery
*
es
.
TermQuery
var
nestedQuery
*
es
.
NestedQuery
query
=
es
.
NewBoolQuery
()
hasEncap
:=
false
for
_
,
attr
:=
range
attrs
{
//还要判断是不是一个单位对应多个属性的
if
strings
.
Contains
(
attr
,
"|"
)
{
...
...
@@ -280,21 +290,30 @@ func getQuery(attrs []string) (query *es.BoolQuery) {
}
else
{
subQuery
=
es
.
NewTermQuery
(
"attrs.attr_value"
,
attr
)
nestedQuery
=
es
.
NewNestedQuery
(
"attrs"
,
subQuery
)
query
.
Should
(
nestedQuery
)
}
var
shouldMatchNumber
int
if
len
(
attrs
)
>
3
{
shouldMatchNumber
=
3
}
else
if
len
(
attrs
)
>=
2
{
shouldMatchNumber
=
2
}
else
if
len
(
attrs
)
==
1
&&
strings
.
Contains
(
attr
,
"封装"
)
{
shouldMatchNumber
=
2
}
else
{
shouldMatchNumber
=
1
//封装是必须要完全满足
if
strings
.
Contains
(
attr
,
"封装"
)
{
hasEncap
=
true
query
.
Must
(
nestedQuery
)
}
else
{
query
.
Should
(
nestedQuery
)
}
}
query
.
MinimumNumberShouldMatch
(
shouldMatchNumber
)
}
var
shouldMatchNumber
int
shouldMatchNumber
=
2
//判断在封装存在的条件下需要满足的筛选条数
attrsLen
:=
len
(
attrs
)
if
hasEncap
{
attrsLen
=
attrsLen
-
1
}
if
attrsLen
>
4
{
shouldMatchNumber
=
3
}
else
if
attrsLen
>
2
{
shouldMatchNumber
=
2
}
else
{
shouldMatchNumber
=
1
}
query
.
MinimumNumberShouldMatch
(
shouldMatchNumber
)
return
query
}
...
...
internal/logic/goods.go
View file @
0ada3b17
...
...
@@ -185,11 +185,9 @@ func MatchGoodsInfo(goods model.ApiGoods, goodsMap GoodsMap) (bomMatching model.
bomMatching
.
Number
=
((
goodsMap
.
Number
/
goods
.
Mpl
)
+
1
)
*
goods
.
Mpl
}
}
if
goods
.
GoodsType
!=
0
||
goods
.
AcType
==
6
{
if
bomMatching
.
Number
>
goods
.
Stock
{
bomMatching
.
Number
=
goods
.
Stock
}
}
}
//判断活动系数
if
goods
.
AcType
==
6
{
}
//阶梯价处理
...
...
internal/mapping/search_keyword.go
View file @
0ada3b17
...
...
@@ -56,6 +56,7 @@ var UnitBaseMapping = map[string]string{
"V"
:
"V"
,
"kV"
:
"V"
,
"KV"
:
"V"
,
"mA"
:
"A"
,
"A"
:
"A"
,
...
...
@@ -88,6 +89,7 @@ var UnitValueMapping = map[string]string{
"V"
:
"1"
,
"kV"
:
"1000"
,
"KV"
:
"1000"
,
"mA"
:
"1"
,
"A"
:
"1000"
,
...
...
internal/model/goods.go
View file @
0ada3b17
...
...
@@ -63,6 +63,7 @@ type ApiGoods struct {
Pdf
string
`json:"pdf"`
Encap
string
`json:"encap"`
AcType
int
`json:"ac_type"`
AllowPresale
int
`json:"allow_presale"`
//ErpTax bool `json:"erp_tax"`
}
...
...
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