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
91aafe7f
authored
Jun 12, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
bom阶段
parent
f6058c6f
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
34 additions
and
28 deletions
cmd/queue/bom.go
configs/config.go
internal/logic/attr.go
internal/logic/bom_matching.go
internal/logic/goods.go
internal/logic/match.go
internal/mapping/search_keyword.go
cmd/queue/bom.go
View file @
91aafe7f
...
@@ -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":
382,"delivery_type":1,"sort":1
}`
str
:=
`{"bom_id":
408,"delivery_type":1,"sort":2
}`
rabbitmq
.
Send
(
queueExchange
,
str
)
rabbitmq
.
Send
(
queueExchange
,
str
)
}
}
...
...
configs/config.go
View file @
91aafe7f
...
@@ -36,6 +36,7 @@ type Redis struct {
...
@@ -36,6 +36,7 @@ type Redis struct {
type
ES
struct
{
type
ES
struct
{
Url
string
`ini:"url"`
Url
string
`ini:"url"`
GoodsIndexName
string
`ini:"goods_index_name"`
GoodsIndexName
string
`ini:"goods_index_name"`
AttrIndex
string
`ini:"attr_index"`
}
}
type
RabbitMQ
struct
{
type
RabbitMQ
struct
{
...
...
internal/logic/attr.go
View file @
91aafe7f
...
@@ -24,7 +24,8 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
...
@@ -24,7 +24,8 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
return
return
}
}
defer
client
.
Stop
()
defer
client
.
Stop
()
search
:=
client
.
MultiSearch
()
.
Index
(
"goods_map_test"
)
index
:=
configs
.
ESSetting
.
AttrIndex
search
:=
client
.
MultiSearch
()
.
Index
(
index
)
searchFlag
:=
false
searchFlag
:=
false
//先根据参数去构建批量查询条件
//先根据参数去构建批量查询条件
for
_
,
item
:=
range
bomItems
{
for
_
,
item
:=
range
bomItems
{
...
@@ -33,7 +34,7 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
...
@@ -33,7 +34,7 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
search
=
searchAttr
(
item
.
GoodsName
,
search
)
search
=
searchAttr
(
item
.
GoodsName
,
search
)
searchFlag
=
true
searchFlag
=
true
}
}
//如果没有型号,但是有参数,那就去匹配参数
//如果没有型号,但是有参数
(参数有可能是型号)
,那就去匹配参数
if
item
.
GoodsName
==
""
&&
item
.
Attrs
!=
""
{
if
item
.
GoodsName
==
""
&&
item
.
Attrs
!=
""
{
search
=
searchAttr
(
item
.
Attrs
,
search
)
search
=
searchAttr
(
item
.
Attrs
,
search
)
searchFlag
=
true
searchFlag
=
true
...
@@ -69,7 +70,7 @@ func searchAttr(attrOrigin string, search *es.MultiSearchService) (result *es.Mu
...
@@ -69,7 +70,7 @@ func searchAttr(attrOrigin string, search *es.MultiSearchService) (result *es.Mu
//先去切割参数得到参数列表
//先去切割参数得到参数列表
attrs
:=
splitAttrs
(
attrOrigin
)
attrs
:=
splitAttrs
(
attrOrigin
)
var
attrsSlice
[]
string
var
attrsSlice
[]
string
fmt
.
Println
(
attrs
)
//
fmt.Println(attrs)
//去转换每一个参数,得到去查询es的标准格式
//去转换每一个参数,得到去查询es的标准格式
for
_
,
attr
:=
range
attrs
{
for
_
,
attr
:=
range
attrs
{
attr
=
TransformESParam
(
attr
)
attr
=
TransformESParam
(
attr
)
...
@@ -77,6 +78,7 @@ func searchAttr(attrOrigin string, search *es.MultiSearchService) (result *es.Mu
...
@@ -77,6 +78,7 @@ func searchAttr(attrOrigin string, search *es.MultiSearchService) (result *es.Mu
}
}
query
:=
getQuery
(
attrsSlice
)
query
:=
getQuery
(
attrsSlice
)
source
:=
es
.
NewSearchSource
()
.
Query
(
query
)
source
:=
es
.
NewSearchSource
()
.
Query
(
query
)
source
.
Sort
(
"brand_sort"
,
true
)
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
())
...
@@ -199,6 +201,7 @@ func getAttrValueByAttr(attr string) (attrValue string) {
...
@@ -199,6 +201,7 @@ func getAttrValueByAttr(attr string) (attrValue string) {
//获取匹配的条件
//获取匹配的条件
func
getQuery
(
attrs
[]
string
)
(
query
*
es
.
BoolQuery
)
{
func
getQuery
(
attrs
[]
string
)
(
query
*
es
.
BoolQuery
)
{
var
subQuery
*
es
.
TermQuery
var
subQuery
*
es
.
TermQuery
var
nestedQuery
*
es
.
NestedQuery
query
=
es
.
NewBoolQuery
()
query
=
es
.
NewBoolQuery
()
for
_
,
attr
:=
range
attrs
{
for
_
,
attr
:=
range
attrs
{
//还要判断是不是一个单位对应多个属性的
//还要判断是不是一个单位对应多个属性的
...
@@ -208,13 +211,15 @@ func getQuery(attrs []string) (query *es.BoolQuery) {
...
@@ -208,13 +211,15 @@ func getQuery(attrs []string) (query *es.BoolQuery) {
multiAttr
:=
strings
.
Split
(
name
,
"|"
)
multiAttr
:=
strings
.
Split
(
name
,
"|"
)
for
_
,
temp
:=
range
multiAttr
{
for
_
,
temp
:=
range
multiAttr
{
subQuery
=
es
.
NewTermQuery
(
"attrs.attr_value"
,
temp
+
"€"
+
value
)
subQuery
=
es
.
NewTermQuery
(
"attrs.attr_value"
,
temp
+
"€"
+
value
)
nestedQuery
=
es
.
NewNestedQuery
(
"attrs"
,
subQuery
)
query
.
Should
(
nestedQuery
)
}
}
}
else
{
}
else
{
subQuery
=
es
.
NewTermQuery
(
"attrs.attr_value"
,
attr
)
subQuery
=
es
.
NewTermQuery
(
"attrs.attr_value"
,
attr
)
}
nestedQuery
=
es
.
NewNestedQuery
(
"attrs"
,
subQuery
)
nestedQuery
:=
es
.
NewNestedQuery
(
"attrs"
,
subQuery
)
query
.
Should
(
nestedQuery
)
query
.
Should
(
nestedQuery
)
query
.
MinimumNumberShouldMatch
(
2
)
}
query
.
MinimumNumberShouldMatch
(
1
)
}
}
return
query
return
query
...
...
internal/logic/bom_matching.go
View file @
91aafe7f
...
@@ -49,20 +49,19 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er
...
@@ -49,20 +49,19 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er
}
}
}
}
now
:=
time
.
Now
()
.
Unix
()
now
:=
time
.
Now
()
.
Unix
()
var
itemStatus
int
if
matching
.
IsBuy
==
1
{
if
matching
.
IsBuy
==
1
{
err
=
model
.
Db
.
Table
(
"lie_bom_item_"
+
tableEnd
)
.
Where
(
"bom_item_id = ?"
,
matching
.
BomItemID
)
.
itemStatus
=
2
Updates
(
map
[
string
]
interface
{}{
"item_status"
:
2
,
"update_time"
:
now
})
.
Error
//库存为0或者价格为0,要放到待确认
if
err
!=
nil
{
}
else
if
matching
.
Price
==
0
||
matching
.
Stock
==
0
{
return
itemStatus
=
4
}
}
}
else
{
err
=
model
.
Db
.
Table
(
"lie_bom_item_"
+
tableEnd
)
.
Where
(
"bom_item_id = ?"
,
matching
.
BomItemID
)
.
err
=
model
.
Db
.
Table
(
"lie_bom_item_"
+
tableEnd
)
.
Where
(
"bom_item_id = ?"
,
matching
.
BomItemID
)
.
Updates
(
map
[
string
]
interface
{}{
"item_status"
:
3
,
"update_time"
:
now
})
.
Error
Updates
(
map
[
string
]
interface
{}{
"item_status"
:
itemStatus
,
"update_time"
:
now
})
.
Error
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
}
}
}
return
nil
return
nil
}
}
...
...
internal/logic/goods.go
View file @
91aafe7f
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ 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,10 +31,10 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
...
@@ -30,10 +31,10 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
}
}
goodsIdsStr
:=
strings
.
Join
(
goodsIds
,
","
)
goodsIdsStr
:=
strings
.
Join
(
goodsIds
,
","
)
goodsList
,
err
:=
GetGoodsInfo
(
goodsIdsStr
)
goodsList
,
err
:=
GetGoodsInfo
(
goodsIdsStr
)
fmt
.
Println
(
len
(
goodsList
))
if
len
(
goodsMapList
)
!=
0
{
if
len
(
goodsMapList
)
!=
0
{
bomId
=
goodsMapList
[
0
]
.
BomId
bomId
=
goodsMapList
[
0
]
.
BomId
}
}
//fmt.Println(goodsIdsStr)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
...
...
internal/logic/match.go
View file @
91aafe7f
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"context"
"context"
"encoding/json"
"encoding/json"
"errors"
"errors"
"fmt"
"math"
"math"
"regexp"
"regexp"
"strings"
"strings"
...
@@ -31,7 +32,7 @@ func MatchGoods(message model.BomMessage) (err error) {
...
@@ -31,7 +32,7 @@ func MatchGoods(message model.BomMessage) (err error) {
return
errors
.
New
(
"没有商品的bom单"
)
return
errors
.
New
(
"没有商品的bom单"
)
}
}
bomItems
:=
bom
.
BomItems
bomItems
:=
bom
.
BomItems
perGoDealNumber
:=
4
0
perGoDealNumber
:=
20
0
//开启协程处理搜索
//开启协程处理搜索
var
wg
sync
.
WaitGroup
var
wg
sync
.
WaitGroup
//判断是否有余数
//判断是否有余数
...
@@ -77,16 +78,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
...
@@ -77,16 +78,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
}
}
defer
client
.
Stop
()
defer
client
.
Stop
()
//匹配之前,去遍历bom_item,把没有型号名称但是有参数的bom_item进行型号补充
//匹配之前,去遍历bom_item,把没有型号名称但是有参数的bom_item进行型号补充
//MatchGoodsNameByAttrs(bomItems)
bomItems
,
err
=
MatchGoodsNameByAttrs
(
bomItems
)
bomItems
,
err
=
MatchGoodsNameByAttrs
(
bomItems
)
//for _, item := range bomItems {
// if item.GoodsName != "" {
// fmt.Println(item.GoodsName)
// }
//}
if
err
!=
nil
{
return
err
}
//第一次先去精确匹配
//第一次先去精确匹配
goodsMapList
,
err
:=
getUpdateGoodsData
(
bomId
,
bomItems
,
deliveryType
,
sort
,
client
,
true
)
goodsMapList
,
err
:=
getUpdateGoodsData
(
bomId
,
bomItems
,
deliveryType
,
sort
,
client
,
true
)
...
@@ -107,6 +99,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
...
@@ -107,6 +99,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
}
}
//再删除模糊匹配到的数据,就得到完全没有匹配的数据了
//再删除模糊匹配到的数据,就得到完全没有匹配的数据了
var
notMatchBomItems
[]
model
.
BomItem
var
notMatchBomItems
[]
model
.
BomItem
fmt
.
Println
(
len
(
append
(
goodsMapList
,
fuzzyGoodsMapList
...
)))
for
_
,
bomItem
:=
range
bomItems
{
for
_
,
bomItem
:=
range
bomItems
{
if
!
checkInGoodsMap
(
bomItem
,
append
(
goodsMapList
,
fuzzyGoodsMapList
...
))
{
if
!
checkInGoodsMap
(
bomItem
,
append
(
goodsMapList
,
fuzzyGoodsMapList
...
))
{
notMatchBomItems
=
append
(
notMatchBomItems
,
bomItem
)
notMatchBomItems
=
append
(
notMatchBomItems
,
bomItem
)
...
@@ -117,6 +110,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
...
@@ -117,6 +110,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
//然后去处理匹配到的数据
err
=
UpdateGoodsData
(
append
(
goodsMapList
,
fuzzyGoodsMapList
...
))
err
=
UpdateGoodsData
(
append
(
goodsMapList
,
fuzzyGoodsMapList
...
))
if
err
!=
nil
{
if
err
!=
nil
{
return
return
...
@@ -234,6 +228,13 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
...
@@ -234,6 +228,13 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
continue
continue
}
}
}
}
//经过了最前面的参数匹配
//如果型号还是为空,则用参数去匹配,因为有可能参数里面填了型号
//if bom.GoodsName == "" && bom.Attrs == "" {
// continue
//} else if bom.GoodsName == "" && bom.Attrs != "" {
// bom.GoodsName = bom.Attrs
//}
//构建一个goods_name对应的bomItems列表
//构建一个goods_name对应的bomItems列表
searchRequest
:=
getSearchParams
(
index
,
bom
.
GoodsName
,
bom
.
BrandName
,
sort
,
bom
.
Number
,
rawSearch
)
searchRequest
:=
getSearchParams
(
index
,
bom
.
GoodsName
,
bom
.
BrandName
,
sort
,
bom
.
Number
,
rawSearch
)
searchFlag
=
true
searchFlag
=
true
...
@@ -271,7 +272,6 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
...
@@ -271,7 +272,6 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
goodsMap
.
BomItemId
=
bomItems
[
key
]
.
BomItemID
goodsMap
.
BomItemId
=
bomItems
[
key
]
.
BomItemID
goodsMap
.
BomId
=
bomId
goodsMap
.
BomId
=
bomId
goodsMap
.
DeliveryType
=
deliveryType
goodsMap
.
DeliveryType
=
deliveryType
goodsMapList
=
append
(
goodsMapList
,
goodsMap
)
goodsMapList
=
append
(
goodsMapList
,
goodsMap
)
break
break
}
}
...
@@ -331,7 +331,7 @@ func getTermQuery(goodsName, brandName string, number int, flag bool) (query *es
...
@@ -331,7 +331,7 @@ func getTermQuery(goodsName, brandName string, number int, flag bool) (query *es
}
}
//query = query.Filter(es.NewRangeQuery("single_price").Gt(0))
//query = query.Filter(es.NewRangeQuery("single_price").Gt(0))
//query = query.Filter(es.NewRangeQuery("stock").Gt(0))
//query = query.Filter(es.NewRangeQuery("stock").Gt(0))
//
query = query.Filter(es.NewTermQuery("status", 1))
query
=
query
.
Filter
(
es
.
NewTermQuery
(
"status"
,
1
))
//query = query.Filter(es.NewRangeQuery("single_price").Gt(0))
//query = query.Filter(es.NewRangeQuery("single_price").Gt(0))
//src, err := query.Source()
//src, err := query.Source()
//if err != nil {
//if err != nil {
...
...
internal/mapping/search_keyword.go
View file @
91aafe7f
...
@@ -15,7 +15,7 @@ var KeywordRegular = map[string]string{
...
@@ -15,7 +15,7 @@ var KeywordRegular = map[string]string{
`v`
:
"V"
,
`v`
:
"V"
,
}
}
var
PureNumberRegular
=
`(\d+(\.\d+)?)`
var
PureNumberRegular
=
`(\d+(\.\d+)?)`
var
GetAttrUnitRegular
=
`[\d.]|±|\+_|\+-|/|\(.*\)|`
var
GetAttrUnitRegular
=
`[\d.]|±|\+_|\+-|/|\(.*\)|
\+/-|
`
//`^[\d\.]+(欧姆|欧|O|o|R|r)$`: "Ω",
//`^[\d\.]+(欧姆|欧|O|o|R|r)$`: "Ω",
//`^[\d\.]+(Uf|uf|μf|uF|UF)$`: "μF",
//`^[\d\.]+(Uf|uf|μf|uF|UF)$`: "μF",
...
...
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