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
ed0c545a
authored
Jun 28, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
品牌映射
parent
2b9184b3
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
22 additions
and
17 deletions
cmd/queue/bom.go
internal/logic/attr.go
internal/logic/bom_item.go
internal/logic/brand_map.go
internal/logic/goods.go
internal/logic/match.go
cmd/queue/bom.go
View file @
ed0c545a
...
@@ -22,7 +22,7 @@ func init() {
...
@@ -22,7 +22,7 @@ func init() {
// "amqp://huntadmin:jy2y2900@192.168.1.237:5672/",
// "amqp://huntadmin:jy2y2900@192.168.1.237:5672/",
//}
//}
//
//
//str := `{"bom_id":
599
,"delivery_type":1,"sort":1}`
//str := `{"bom_id":
616
,"delivery_type":1,"sort":1}`
//rabbitmq.Send(queueExchange, str)
//rabbitmq.Send(queueExchange, str)
}
}
...
...
internal/logic/attr.go
View file @
ed0c545a
...
@@ -109,7 +109,7 @@ func searchAttr(bomItem model.BomItem, search *es.MultiSearchService) (result *e
...
@@ -109,7 +109,7 @@ func searchAttr(bomItem model.BomItem, search *es.MultiSearchService) (result *e
}
}
}
}
query
:=
getQuery
(
attrsSlice
)
query
:=
getQuery
(
attrsSlice
)
//如果ZyBrandId不为空,则代表匹配到了映射id
,可以直接用must去查询
//如果ZyBrandId不为空,则代表匹配到了映射id
if
bomItem
.
ZyBrandId
!=
""
&&
len
(
attrsSlice
)
>
0
{
if
bomItem
.
ZyBrandId
!=
""
&&
len
(
attrsSlice
)
>
0
{
query
.
Should
(
es
.
NewTermQuery
(
"brand_name"
,
bomItem
.
ZyBrandName
))
query
.
Should
(
es
.
NewTermQuery
(
"brand_name"
,
bomItem
.
ZyBrandName
))
}
else
{
}
else
{
...
@@ -185,6 +185,9 @@ func extractAttrsByStr(attr string) []string {
...
@@ -185,6 +185,9 @@ func extractAttrsByStr(attr string) []string {
func
changeKeyword
(
attr
string
)
(
result
string
)
{
func
changeKeyword
(
attr
string
)
(
result
string
)
{
regulars
:=
mapping
.
KeywordRegular
regulars
:=
mapping
.
KeywordRegular
for
regexpStr
,
regular
:=
range
regulars
{
for
regexpStr
,
regular
:=
range
regulars
{
if
strings
.
Contains
(
attr
,
"Ω"
)
{
break
}
compile
,
_
:=
regexp
.
Compile
(
regexpStr
)
compile
,
_
:=
regexp
.
Compile
(
regexpStr
)
attr
=
compile
.
ReplaceAllString
(
attr
,
regular
)
attr
=
compile
.
ReplaceAllString
(
attr
,
regular
)
}
}
...
...
internal/logic/bom_item.go
View file @
ed0c545a
...
@@ -85,6 +85,8 @@ func UpdateBomItem(bomId, bomItemId int) (err error) {
...
@@ -85,6 +85,8 @@ func UpdateBomItem(bomId, bomItemId int) (err error) {
return
err
return
err
}
}
defer
client
.
Stop
()
defer
client
.
Stop
()
//先去查询品牌映射,有映射关系的,就用映射关系得到的brand_id进行查询
bomItems
,
err
=
GetBrandMap
(
bomItems
)
//匹配之前,去遍历bom_item,把没有型号名称但是有参数的bom_item进行型号补充
//匹配之前,去遍历bom_item,把没有型号名称但是有参数的bom_item进行型号补充
bomItems
,
err
=
MatchGoodsNameByAttrs
(
bomItems
)
bomItems
,
err
=
MatchGoodsNameByAttrs
(
bomItems
)
//直接模糊匹配
//直接模糊匹配
...
...
internal/logic/brand_map.go
View file @
ed0c545a
...
@@ -69,14 +69,14 @@ func getBrandMapQuery(bomItem model.BomItem) (query *es.BoolQuery) {
...
@@ -69,14 +69,14 @@ func getBrandMapQuery(bomItem model.BomItem) (query *es.BoolQuery) {
brandName
=
strings
.
ToUpper
(
brandName
)
brandName
=
strings
.
ToUpper
(
brandName
)
//提取出纯中文
//提取出纯中文
r
,
_
:=
regexp
.
Compile
(
"[
\u4e00
-
\u9fa5
]+"
)
r
,
_
:=
regexp
.
Compile
(
"[
\u4e00
-
\u9fa5
]+"
)
chineseBrandName
:=
r
.
FindString
(
brandName
)
brandNameCn
:=
r
.
FindString
(
brandName
)
if
chineseBrandName
!=
""
{
if
brandNameCn
!=
""
{
query
.
Should
(
es
.
NewMatchQuery
(
"brand_name_cn"
,
chineseBrandName
))
query
.
Should
(
es
.
NewMatchQuery
(
"brand_name_cn"
,
brandNameCn
))
}
}
//提取出纯英文
//提取出纯英文
re
,
_
:=
regexp
.
Compile
(
"[A-Za-z0-9]+"
)
re
,
_
:=
regexp
.
Compile
(
"[A-Za-z0-9]+"
)
englishBrandName
:=
re
.
FindString
(
brandName
)
brandNameEn
:=
re
.
FindString
(
brandName
)
subQuery
=
es
.
NewTermQuery
(
"attrs.attr_brand_name"
,
englishBrandName
)
subQuery
=
es
.
NewTermQuery
(
"attrs.attr_brand_name"
,
brandNameEn
)
nestedQuery
=
es
.
NewNestedQuery
(
"attrs"
,
subQuery
)
nestedQuery
=
es
.
NewNestedQuery
(
"attrs"
,
subQuery
)
query
.
Should
(
nestedQuery
)
query
.
Should
(
nestedQuery
)
query
.
MinimumNumberShouldMatch
(
1
)
query
.
MinimumNumberShouldMatch
(
1
)
...
...
internal/logic/goods.go
View file @
ed0c545a
...
@@ -4,7 +4,6 @@ import (
...
@@ -4,7 +4,6 @@ import (
"bom_server/configs"
"bom_server/configs"
"bom_server/internal/model"
"bom_server/internal/model"
"encoding/json"
"encoding/json"
"fmt"
"github.com/imroc/req"
"github.com/imroc/req"
"github.com/tidwall/gjson"
"github.com/tidwall/gjson"
"strings"
"strings"
...
@@ -30,7 +29,6 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
...
@@ -30,7 +29,6 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
goodsIds
=
append
(
goodsIds
,
goodsMap
.
GoodsId
)
goodsIds
=
append
(
goodsIds
,
goodsMap
.
GoodsId
)
}
}
goodsIdsStr
:=
strings
.
Join
(
goodsIds
,
","
)
goodsIdsStr
:=
strings
.
Join
(
goodsIds
,
","
)
fmt
.
Println
(
goodsIdsStr
)
goodsList
,
err
:=
GetGoodsInfo
(
goodsIdsStr
)
goodsList
,
err
:=
GetGoodsInfo
(
goodsIdsStr
)
if
len
(
goodsMapList
)
!=
0
{
if
len
(
goodsMapList
)
!=
0
{
bomId
=
goodsMapList
[
0
]
.
BomId
bomId
=
goodsMapList
[
0
]
.
BomId
...
...
internal/logic/match.go
View file @
ed0c545a
...
@@ -7,7 +7,6 @@ import (
...
@@ -7,7 +7,6 @@ import (
"context"
"context"
"encoding/json"
"encoding/json"
"errors"
"errors"
"fmt"
"math"
"math"
"regexp"
"regexp"
"strings"
"strings"
...
@@ -19,7 +18,7 @@ import (
...
@@ -19,7 +18,7 @@ import (
/**
/**
1.先去数据库查出所有需要匹配的数据
1.先去数据库查出所有需要匹配的数据
2.然后开协程去针对每个bom里的goods_name去请求搜索接口
2.然后开协程去针对每个bom里的goods_name去请求搜索接口
(匹配品牌映射,匹配参数)
3.搜索匹配到以后,用goods_id去请求商品服务
3.搜索匹配到以后,用goods_id去请求商品服务
4.得到具体的商品数据以后,针对对应的商品进行修改
4.得到具体的商品数据以后,针对对应的商品进行修改
**/
**/
...
@@ -241,7 +240,7 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
...
@@ -241,7 +240,7 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
bom
.
GoodsName
=
bom
.
Attrs
bom
.
GoodsName
=
bom
.
Attrs
}
}
//构建一个goods_name对应的bomItems列表
//构建一个goods_name对应的bomItems列表
searchRequest
:=
getSearchParams
(
bom
,
sort
,
rawSearch
)
searchRequest
:=
getSearchParams
(
index
,
bom
,
sort
,
rawSearch
)
searchFlag
=
true
searchFlag
=
true
search
.
Add
(
searchRequest
)
search
.
Add
(
searchRequest
)
}
}
...
@@ -286,8 +285,8 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
...
@@ -286,8 +285,8 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
}
}
//构建请求参数
//构建请求参数
func
getSearchParams
(
bomItem
model
.
BomItem
,
sort
int
,
flag
bool
)
(
searchRequest
*
es
.
SearchRequest
)
{
func
getSearchParams
(
index
string
,
bomItem
model
.
BomItem
,
sort
int
,
flag
bool
)
(
searchRequest
*
es
.
SearchRequest
)
{
query
:=
getTermQuery
(
bomItem
,
sort
,
flag
)
query
:=
getTermQuery
(
index
,
bomItem
,
sort
,
flag
)
source
:=
es
.
NewSearchSource
()
.
Query
(
query
)
source
:=
es
.
NewSearchSource
()
.
Query
(
query
)
if
sort
==
1
{
if
sort
==
1
{
source
.
Sort
(
"_score"
,
false
)
source
.
Sort
(
"_score"
,
false
)
...
@@ -306,12 +305,12 @@ func getSearchParams(bomItem model.BomItem, sort int, flag bool) (searchRequest
...
@@ -306,12 +305,12 @@ func getSearchParams(bomItem model.BomItem, sort int, flag bool) (searchRequest
}
}
source
=
source
.
From
(
0
)
.
Size
(
1
)
source
=
source
.
From
(
0
)
.
Size
(
1
)
searchRequest
=
es
.
NewSearchRequest
()
.
Source
(
source
)
searchRequest
=
es
.
NewSearchRequest
()
.
Source
(
source
)
fmt
.
Println
(
searchRequest
.
Body
())
//
fmt.Println(searchRequest.Body())
return
searchRequest
return
searchRequest
}
}
//构建term条件
//构建term条件
func
getTermQuery
(
bomItem
model
.
BomItem
,
sort
int
,
flag
bool
)
(
query
*
es
.
BoolQuery
)
{
func
getTermQuery
(
index
string
,
bomItem
model
.
BomItem
,
sort
int
,
flag
bool
)
(
query
*
es
.
BoolQuery
)
{
query
=
es
.
NewBoolQuery
()
query
=
es
.
NewBoolQuery
()
if
flag
{
if
flag
{
field
:=
"auto_goods_name.raw"
field
:=
"auto_goods_name.raw"
...
@@ -332,8 +331,11 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool) (query *es.BoolQue
...
@@ -332,8 +331,11 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool) (query *es.BoolQue
query
=
query
.
Must
(
es
.
NewTermQuery
(
field
,
bomItem
.
GoodsName
))
query
=
query
.
Must
(
es
.
NewTermQuery
(
field
,
bomItem
.
GoodsName
))
}
}
//对品牌进行判断搜索,如果能匹配到对应的自营标准品牌(那么同时也有对应的联营品牌)
//对品牌进行判断搜索,如果能匹配到对应的自营标准品牌(那么同时也有对应的联营品牌)
if
bomItem
.
ZyBrandId
!=
""
{
//还要去判断当前索引是否包含自营,不包含,直接跳过自营的brand_id
if
strings
.
Contains
(
index
,
"liexin_ziying"
)
{
query
.
Should
(
es
.
NewTermQuery
(
"brand_id"
,
bomItem
.
ZyBrandId
))
query
.
Should
(
es
.
NewTermQuery
(
"brand_id"
,
bomItem
.
ZyBrandId
))
}
if
bomItem
.
ZyBrandId
!=
""
{
for
_
,
id
:=
range
bomItem
.
LyBrandIds
{
for
_
,
id
:=
range
bomItem
.
LyBrandIds
{
query
.
Should
(
es
.
NewTermQuery
(
"brand_id"
,
id
))
query
.
Should
(
es
.
NewTermQuery
(
"brand_id"
,
id
))
}
}
...
...
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