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
e8b084d6
authored
Jun 12, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
参数匹配
parent
91aafe7f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
21 deletions
internal/logic/attr.go
internal/logic/bom_matching.go
internal/logic/goods.go
internal/logic/match.go
internal/mapping/search_keyword.go
internal/logic/attr.go
View file @
e8b084d6
...
...
@@ -31,12 +31,12 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
for
_
,
item
:=
range
bomItems
{
//如果有型号,但是型号有可能是参数,所以先去匹配下参数,有的话转成对应的型号
if
item
.
GoodsName
!=
""
{
search
=
searchAttr
(
item
.
GoodsName
,
search
)
search
=
searchAttr
(
item
.
GoodsName
,
item
.
BrandName
,
search
)
searchFlag
=
true
}
//如果没有型号,但是有参数(参数有可能是型号),那就去匹配参数
if
item
.
GoodsName
==
""
&&
item
.
Attrs
!=
""
{
search
=
searchAttr
(
item
.
Attrs
,
search
)
search
=
searchAttr
(
item
.
Attrs
,
item
.
BrandName
,
search
)
searchFlag
=
true
}
}
...
...
@@ -58,7 +58,7 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
res
,
_
:=
hit
.
Source
.
MarshalJSON
()
//还要去判断至少符合特定数量参数匹配的结果,比如最小匹配参数为2,那就是要有两个参数匹配到才正确
bomItems
[
key
]
.
GoodsName
=
gjson
.
Get
(
string
(
res
),
"goods_name"
)
.
String
()
fmt
.
Println
(
string
(
res
))
//
fmt.Println(string(res))
}
}
}
...
...
@@ -66,7 +66,7 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
return
}
func
searchAttr
(
attrOrigin
string
,
search
*
es
.
MultiSearchService
)
(
result
*
es
.
MultiSearchService
)
{
func
searchAttr
(
attrOrigin
,
brandName
string
,
search
*
es
.
MultiSearchService
)
(
result
*
es
.
MultiSearchService
)
{
//先去切割参数得到参数列表
attrs
:=
splitAttrs
(
attrOrigin
)
var
attrsSlice
[]
string
...
...
@@ -77,11 +77,24 @@ func searchAttr(attrOrigin string, search *es.MultiSearchService) (result *es.Mu
attrsSlice
=
append
(
attrsSlice
,
attr
)
}
query
:=
getQuery
(
attrsSlice
)
if
brandName
!=
""
{
//提取全英文,转成大写
if
strings
.
Contains
(
brandName
,
" "
)
{
//有空格隔开只取第一个
brandName
=
strings
.
Split
(
brandName
,
" "
)[
0
]
//转成全大写,因为ES存的是大写
brandName
=
strings
.
ToUpper
(
brandName
)
//去除特殊符号和中文等等
r1
,
_
:=
regexp
.
Compile
(
`/[^A-Za-z0-9]+/`
)
brandName
=
r1
.
ReplaceAllString
(
brandName
,
""
)
query
.
Should
(
es
.
NewTermQuery
(
"brand_name"
,
brandName
))
}
}
source
:=
es
.
NewSearchSource
()
.
Query
(
query
)
source
.
Sort
(
"brand_sort"
,
true
)
source
=
source
.
From
(
0
)
.
Size
(
1
)
searchRequest
:=
es
.
NewSearchRequest
()
.
Source
(
source
)
fmt
.
Println
(
searchRequest
.
Body
())
//
fmt.Println(searchRequest.Body())
return
search
.
Add
(
searchRequest
)
}
...
...
internal/logic/bom_matching.go
View file @
e8b084d6
...
...
@@ -50,11 +50,17 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er
}
now
:=
time
.
Now
()
.
Unix
()
var
itemStatus
int
//if matching.IsBuy == 1 && matching.Price != 0 && matching.Stock != 0 {
// itemStatus = 2
// //库存为0或者价格为0,要放到待确认
//
//} else if matching.Price == 0 || matching.Stock == 0 {
// itemStatus = 4
//}
if
matching
.
IsBuy
==
1
{
itemStatus
=
2
//库存为0或者价格为0,要放到待确认
}
else
if
matching
.
Price
==
0
||
matching
.
Stock
==
0
{
itemStatus
=
4
}
else
{
itemStatus
=
3
}
err
=
model
.
Db
.
Table
(
"lie_bom_item_"
+
tableEnd
)
.
Where
(
"bom_item_id = ?"
,
matching
.
BomItemID
)
.
Updates
(
map
[
string
]
interface
{}{
"item_status"
:
itemStatus
,
"update_time"
:
now
})
.
Error
...
...
internal/logic/goods.go
View file @
e8b084d6
...
...
@@ -4,7 +4,6 @@ import (
"bom_server/configs"
"bom_server/internal/model"
"encoding/json"
"fmt"
"github.com/imroc/req"
"github.com/tidwall/gjson"
"strings"
...
...
@@ -31,7 +30,6 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
}
goodsIdsStr
:=
strings
.
Join
(
goodsIds
,
","
)
goodsList
,
err
:=
GetGoodsInfo
(
goodsIdsStr
)
fmt
.
Println
(
len
(
goodsList
))
if
len
(
goodsMapList
)
!=
0
{
bomId
=
goodsMapList
[
0
]
.
BomId
}
...
...
@@ -83,6 +81,7 @@ func GetGoodsInfo(goodsIdsStr string) (goodsList []model.ApiGoods, err error) {
params
:=
req
.
Param
{
"goods_id"
:
goodsIdsStr
,
}
//fmt.Println(goodsIdsStr)
resp
,
err
:=
req
.
Post
(
goodsServerUrl
+
"/synchronization"
,
params
)
if
err
!=
nil
{
return
...
...
internal/logic/match.go
View file @
e8b084d6
...
...
@@ -7,7 +7,6 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"math"
"regexp"
"strings"
...
...
@@ -32,7 +31,7 @@ func MatchGoods(message model.BomMessage) (err error) {
return
errors
.
New
(
"没有商品的bom单"
)
}
bomItems
:=
bom
.
BomItems
perGoDealNumber
:=
20
0
perGoDealNumber
:=
4
0
//开启协程处理搜索
var
wg
sync
.
WaitGroup
//判断是否有余数
...
...
@@ -99,7 +98,6 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
}
//再删除模糊匹配到的数据,就得到完全没有匹配的数据了
var
notMatchBomItems
[]
model
.
BomItem
fmt
.
Println
(
len
(
append
(
goodsMapList
,
fuzzyGoodsMapList
...
)))
for
_
,
bomItem
:=
range
bomItems
{
if
!
checkInGoodsMap
(
bomItem
,
append
(
goodsMapList
,
fuzzyGoodsMapList
...
))
{
notMatchBomItems
=
append
(
notMatchBomItems
,
bomItem
)
...
...
internal/mapping/search_keyword.go
View file @
e8b084d6
...
...
@@ -3,21 +3,21 @@ package mapping
var
KeywordRegular
=
map
[
string
]
string
{
//`^(.* )?([\d\.]+)(欧|欧姆|R|r)( .*)?$`: `$1$2Ω$4`,
//`^(.* )?([\d\.]+)(U|u|μ)(.?)( .*)?$`: `$1$2Μ$4$5`,
"COG"
:
"C0G"
,
"NPO"
:
"NP0"
,
"华科|华新科技|华新科"
:
"华新"
,
"COG"
:
"C0G"
,
"NPO"
:
"NP0"
,
"华科|华新科技|华新科"
:
"华新"
,
`(欧姆|欧|O|o|R|r)`
:
"Ω"
,
`(Uf|uf|μf|uF|UF)`
:
"μF"
,
`(Uh|uh|μh|uH|UH)`
:
"μH"
,
`K`
:
"KΩ"
,
`v`
:
"V"
,
`K`
:
"nF"
,
`v`
:
"V"
,
}
var
PureNumberRegular
=
`(\d+(\.\d+)?)`
var
PureLetterRegular
=
`[a-zA-Z0-9]+`
var
GetAttrUnitRegular
=
`[\d.]|±|\+_|\+-|/|\(.*\)|\+/-|`
//`^[\d\.]+(欧姆|欧|O|o|R|r)$`: "Ω",
//`^[\d\.]+(Uf|uf|μf|uF|UF)$`: "μF",
//`^[\d\.]+(Uh|uh|μh|uH|UH)$`: "μH",
//`^[\d\.]+K$`: "KΩ",
\ No newline at end of file
//`^[\d\.]+K$`: "KΩ",
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