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
c049e3e8
authored
Apr 19, 2021
by
hcy001
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1
parent
9739a732
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
82 additions
and
15 deletions
configs/config.go
internal/common/common.go
internal/logic/bom_item.go
internal/logic/bom_matching.go
internal/logic/goods.go
internal/logic/match.go
internal/logic/search.go
configs/config.go
View file @
c049e3e8
...
...
@@ -53,6 +53,7 @@ type Api struct {
type
Oss
struct
{
UploadKey
string
`ini:"upload_key"`
IsDebug
int
`ini:"is_debug"`
}
var
DatabaseSetting
=
&
Database
{}
...
...
internal/common/common.go
View file @
c049e3e8
package
common
import
(
"bom_server/configs"
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"github.com/shopspring/decimal"
"github.com/syyongx/php2go"
"reflect"
"strconv"
)
/*
定时任务打印输出
@parm jsonStr 需要json输出的内容
*/
func
PrintDebug
(
str
...
interface
{})
{
flag
:=
configs
.
OssSetting
.
IsDebug
if
flag
==
0
{
return
}
temp
:=
"-------"
;
for
_
,
jsonStr
:=
range
str
{
if
v
,
p
:=
jsonStr
.
(
string
);
p
{
temp
=
temp
+
"---"
+
v
}
else
{
jsonData
,
err
:=
json
.
Marshal
(
jsonStr
)
if
err
!=
nil
{
fmt
.
Println
(
"错误:-----"
,
err
)
}
temp
=
temp
+
"---"
+
string
(
jsonData
)
}
}
fmt
.
Println
(
temp
)
}
// Md5 md5()
func
Md5
(
str
string
)
string
{
hash
:=
md5
.
New
()
...
...
internal/logic/bom_item.go
View file @
c049e3e8
...
...
@@ -94,11 +94,17 @@ func UpdateBomItem(bomId, bomItemId int) (err error) {
bomItems
=
GetStandardAttrs
(
bomItems
)
//第一次去精确匹配,没有再去模糊匹配
var
goodsMapList
[]
GoodsMap
goodsMapList
,
err
=
getUpdateGoodsData
(
bomId
,
bomItems
,
where
.
DeliveryType
,
where
.
Sort
,
client
,
true
)
itemsStatus
:=
0
goodsMapList
,
err
=
getUpdateGoodsData
(
bomId
,
bomItems
,
where
.
DeliveryType
,
where
.
Sort
,
client
,
true
,
false
)
if
len
(
goodsMapList
)
==
0
{
goodsMapList
,
err
=
getUpdateGoodsData
(
bomId
,
bomItems
,
where
.
DeliveryType
,
where
.
Sort
,
client
,
false
)
if
err
!=
nil
{
return
//替代型号匹配
goodsMapList
,
err
=
getUpdateGoodsData
(
bomId
,
bomItems
,
where
.
DeliveryType
,
where
.
Sort
,
client
,
false
,
true
)
itemsStatus
=
5
;
//替代物料匹配
if
len
(
goodsMapList
)
==
0
{
goodsMapList
,
err
=
getUpdateGoodsData
(
bomId
,
bomItems
,
where
.
DeliveryType
,
where
.
Sort
,
client
,
false
,
false
)
if
len
(
goodsMapList
)
!=
0
{
itemsStatus
=
6
;
//模糊匹配
}
}
}
//fmt.Println(goodsMapList)
...
...
@@ -111,7 +117,7 @@ func UpdateBomItem(bomId, bomItemId int) (err error) {
return
}
}
else
{
err
=
UpdateGoodsData
(
goodsMapList
)
err
=
UpdateGoodsData
(
goodsMapList
,
itemsStatus
)
if
err
!=
nil
{
return
}
...
...
internal/logic/bom_matching.go
View file @
c049e3e8
...
...
@@ -61,7 +61,7 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching,status .
itemStatus
=
status
[
0
]
}
if
match
.
Status
==
5
&&
match
.
Status
==
6
{
if
match
.
Status
==
5
&&
match
.
Status
==
6
{
//当bom状态是
itemStatus
=
match
.
Status
;
}
...
...
internal/logic/goods.go
View file @
c049e3e8
...
...
@@ -2,6 +2,7 @@ package logic
import
(
"bom_server/configs"
"bom_server/internal/common"
"bom_server/internal/model"
"encoding/json"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
...
...
@@ -22,8 +23,12 @@ type GoodsMap struct {
DeliveryType
int
}
func
UpdateGoodsData
(
goodsMapList
[]
GoodsMap
)
(
err
error
)
{
func
UpdateGoodsData
(
goodsMapList
[]
GoodsMap
,
status
...
int
)
(
err
error
)
{
//根据goodsIds去商品服务获取对应的商品信息
if
len
(
goodsMapList
)
==
0
{
return
}
var
(
goodsIds
[]
string
bomId
int
...
...
@@ -61,15 +66,25 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
}
}
}
//先找出没有匹配到商品的进行批量修改状态
err
=
batchUpdateItemStatus
(
bomId
,
noGoodsInfoItemIdList
)
if
err
!=
nil
{
return
}
if
len
(
status
)
>
0
{
//todo 增加类型: 5 替代型号匹配 6 模糊匹配
err
=
BatchSaveMatchings
(
bomId
,
bomMatchingList
,
status
[
0
])
if
err
!=
nil
{
return
}
}
else
{
err
=
BatchSaveMatchings
(
bomId
,
bomMatchingList
)
if
err
!=
nil
{
return
}
}
return
}
...
...
@@ -89,6 +104,9 @@ func GetGoodsInfo(goodsIdsStr string) (goodsList []model.ApiGoods, err error) {
}
//fmt.Println(goodsIdsStr)
resp
,
err
:=
req
.
Post
(
goodsServerUrl
+
"/synchronization"
,
params
)
common
.
PrintDebug
(
"请求商品详情:"
,
goodsServerUrl
+
"/synchronization"
,
" 参数:"
,
params
,
"结果:"
,
len
(
resp
.
String
()))
if
err
!=
nil
{
return
}
...
...
internal/logic/match.go
View file @
c049e3e8
...
...
@@ -92,10 +92,14 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
needDealBomItems
=
bomItems
[
i
:
i
+
perNumber
]
}
//todo 精确匹配: 第一次先去精确匹配
common
.
PrintDebug
(
"精确匹配型号:"
,
needDealBomItems
)
exactList
,
err
:=
getUpdateGoodsData
(
bomId
,
needDealBomItems
,
deliveryType
,
sort
,
client
,
true
,
false
)
if
err
!=
nil
{
return
err
}
common
.
PrintDebug
(
"精确匹配结果:"
,
exactList
)
//要删除已经精确匹配过的bomItem,得到需要去模糊匹配的商品
var
fuzzyBomItems
[]
model
.
BomItem
for
_
,
bomItem
:=
range
needDealBomItems
{
...
...
@@ -106,10 +110,12 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
}
//todo 替代型号匹配 2021.4.17 替代型号参与匹配,优先取原始型号,原始型号无法购买再推荐替代型号
common
.
PrintDebug
(
"替代型号匹配型号:"
,
fuzzyBomItems
)
AlikeGoodsMapList
,
err
:=
getUpdateGoodsData
(
bomId
,
fuzzyBomItems
,
deliveryType
,
sort
,
client
,
false
,
true
)
if
err
!=
nil
{
return
err
}
common
.
PrintDebug
(
"替代型号匹配结果:"
,
AlikeGoodsMapList
)
//删除已经类似料匹配的型号
var
fuzzyBomItems2
[]
model
.
BomItem
...
...
@@ -121,10 +127,12 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
}
//todo 模糊匹配
common
.
PrintDebug
(
"模糊匹配型号:"
,
fuzzyBomItems2
)
fuzzyGoodsMapList
,
err
:=
getUpdateGoodsData
(
bomId
,
fuzzyBomItems2
,
deliveryType
,
sort
,
client
,
false
,
false
)
if
err
!=
nil
{
return
err
}
common
.
PrintDebug
(
"模糊匹配结果"
,
fuzzyGoodsMapList
)
//再删除模糊匹配到的数据,就得到完全没有匹配的数据了
var
notMatchBomItems
[]
model
.
BomItem
...
...
@@ -145,7 +153,12 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
return
err
}
//替代物料数据
err
=
UpdateGoodsData
(
exactList
,
5
)
err
=
UpdateGoodsData
(
AlikeGoodsMapList
,
5
)
if
err
!=
nil
{
return
err
}
//模糊匹配
err
=
UpdateGoodsData
(
fuzzyGoodsMapList
,
6
)
if
err
!=
nil
{
return
err
}
...
...
internal/logic/search.go
View file @
c049e3e8
...
...
@@ -35,6 +35,10 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
//构建一个goods_name对应的bomItems列表
searchRequest
:=
getSearchParams
(
index
,
bom
,
sort
,
paramsRawSearch
,
isAlike
)
searchFlag
=
true
common
.
PrintDebug
(
"查询es索引"
,
index
)
common
.
PrintDebug
(
searchRequest
.
Body
())
//randInt := rand.Intn(10)
//time.Sleep(10 * time.Millisecond)
search
.
Add
(
searchRequest
)
...
...
@@ -145,14 +149,8 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool,isAlike bool) (quer
}
else
{
query
=
query
.
Must
(
es
.
NewTermsQuery
(
"attr_bom"
,
"$_$"
))
}
}
else
{
query
=
query
.
Filter
(
es
.
NewTermQuery
(
field
,
goodsName
))
}
//todo 推荐型号搜索
if
isAlike
{
query
=
query
.
Must
(
es
.
NewTermsQuery
(
"alike_spu_name"
,
goodsName
))
}
query
=
query
.
Filter
(
es
.
NewTermQuery
(
field
,
goodsName
))
//判断是否存在brandName并且匹配不到对应的标准品牌
if
bomItem
.
BrandName
!=
""
{
...
...
@@ -165,9 +163,13 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool,isAlike bool) (quer
}
//搜索库存
query
=
query
.
Should
(
es
.
NewRangeQuery
(
"stock"
)
.
Gte
(
bomItem
.
Number
*
bomItem
.
Amount
))
}
else
if
isAlike
{
//todo 推荐型号搜索
query
=
query
.
Must
(
es
.
NewTermsQuery
(
"alike_spu_name.raw"
,
bomItem
.
GoodsName
))
}
else
{
query
=
query
.
Must
(
es
.
NewTermQuery
(
"auto_goods_name"
,
bomItem
.
GoodsName
))
}
common
.
PrintDebug
(
"isalike:"
,
isAlike
)
//只显示库存大于0的数据
query
.
Must
(
es
.
NewRangeQuery
(
"stock"
)
.
Gt
(
0
))
//按价格排序
...
...
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