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
19b5ff3b
authored
May 26, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
完善修改
parent
a86b8559
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
61 additions
and
15 deletions
cmd/cmd.exe~
internal/logic/bom_item.go
internal/logic/bom_matching.go
internal/logic/goods.go
internal/logic/match.go
internal/model/bom_matching.go
cmd/cmd.exe~
View file @
19b5ff3b
The file could not be displayed because it is too large.
internal/logic/bom_item.go
View file @
19b5ff3b
...
@@ -7,7 +7,8 @@ import (
...
@@ -7,7 +7,8 @@ import (
//根据bom_id查出bom表信息
//根据bom_id查出bom表信息
func
GetBomItems
(
bomId
int
)
(
bomItems
[]
model
.
BomItem
)
{
func
GetBomItems
(
bomId
int
)
(
bomItems
[]
model
.
BomItem
)
{
tableEnd
:=
strconv
.
FormatInt
(
int64
(
bomId
),
10
)
bomIdStr
:=
strconv
.
FormatInt
(
int64
(
bomId
),
10
)
tableEnd
:=
string
(
bomIdStr
[
len
(
bomIdStr
)
-
1
])
model
.
Db
.
Table
(
"lie_bom_item_"
+
tableEnd
)
.
Where
(
"bom_id = ?"
,
bomId
)
.
Find
(
&
bomItems
)
model
.
Db
.
Table
(
"lie_bom_item_"
+
tableEnd
)
.
Where
(
"bom_id = ?"
,
bomId
)
.
Find
(
&
bomItems
)
return
bomItems
return
bomItems
}
}
internal/logic/bom_matching.go
View file @
19b5ff3b
...
@@ -2,10 +2,30 @@ package logic
...
@@ -2,10 +2,30 @@ package logic
import
(
import
(
"bom_server/internal/model"
"bom_server/internal/model"
"strconv"
"time"
)
)
//根据bom_id查出bom表信息
//根据matchingList去修改
func
GetBomMatchings
(
bomId
int
)
(
bomMatchings
[]
model
.
BomItem
)
{
func
BatchSaveMatchings
(
bomId
int
,
matchingList
[]
model
.
BomItemMatching
)
(
err
error
)
{
model
.
Db
.
Where
(
"bom_id = ?"
,
bomId
)
.
Find
(
&
bomMatchings
)
bomIdStr
:=
strconv
.
FormatInt
(
int64
(
bomId
),
10
)
return
bomMatchings
tableEnd
:=
string
(
bomIdStr
[
len
(
bomIdStr
)
-
1
])
tableName
:=
"lie_bom_item_matching_"
+
tableEnd
for
_
,
matching
:=
range
matchingList
{
//先去数据库查询是否存在该记录,有的话修改,没有就新增
var
match
model
.
BomItemMatching
model
.
Db
.
Table
(
tableName
)
.
Where
(
"bom_item_id = ?"
,
matching
.
BomItemID
)
.
First
(
&
match
)
if
match
.
BomItemID
!=
0
{
matching
.
UpdateTime
=
int
(
time
.
Now
()
.
Unix
())
if
err
=
model
.
Db
.
Table
(
tableName
)
.
Model
(
&
match
)
.
Updates
(
matching
)
.
Error
;
err
!=
nil
{
return
}
}
else
{
if
err
=
model
.
Db
.
Table
(
tableName
)
.
Create
(
&
matching
)
.
Error
;
err
!=
nil
{
return
}
}
}
return
nil
}
}
internal/logic/goods.go
View file @
19b5ff3b
...
@@ -20,7 +20,10 @@ type GoodsMap struct {
...
@@ -20,7 +20,10 @@ type GoodsMap struct {
func
UpdateGoodsData
(
goodsMapList
[]
GoodsMap
)
()
{
func
UpdateGoodsData
(
goodsMapList
[]
GoodsMap
)
()
{
//根据goodsIds去商品服务获取对应的商品信息
//根据goodsIds去商品服务获取对应的商品信息
var
goodsIds
[]
string
var
(
goodsIds
[]
string
bomId
int
)
for
_
,
goodsMap
:=
range
goodsMapList
{
for
_
,
goodsMap
:=
range
goodsMapList
{
goodsIds
=
append
(
goodsIds
,
goodsMap
.
GoodsId
)
goodsIds
=
append
(
goodsIds
,
goodsMap
.
GoodsId
)
}
}
...
@@ -38,16 +41,17 @@ func UpdateGoodsData(goodsMapList []GoodsMap) () {
...
@@ -38,16 +41,17 @@ func UpdateGoodsData(goodsMapList []GoodsMap) () {
if
err
:=
resp
.
ToJSON
(
&
responseData
);
err
!=
nil
{
if
err
:=
resp
.
ToJSON
(
&
responseData
);
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
}
}
bomMatchingList
:=
map
[
string
]
model
.
BomItemMatching
{}
var
bomMatchingList
[]
model
.
BomItemMatching
for
_
,
goodsMap
:=
range
goodsMapList
{
for
_
,
goodsMap
:=
range
goodsMapList
{
for
_
,
goods
:=
range
responseData
.
Data
{
for
_
,
goods
:=
range
responseData
.
Data
{
if
goodsMap
.
GoodsId
==
goods
.
GoodsID
{
if
goodsMap
.
GoodsId
==
goods
.
GoodsID
{
bomId
=
goodsMap
.
BomId
//组装需要去更新的商品信息
//组装需要去更新的商品信息
bomMatching
:=
model
.
BomItemMatching
{
bomMatching
:=
model
.
BomItemMatching
{
BomID
:
goodsMap
.
BomId
,
BomID
:
goodsMap
.
BomId
,
BomItemID
:
goodsMap
.
BomItemId
,
BomItemID
:
goodsMap
.
BomItemId
,
GoodsID
:
goods
.
GoodsID
,
GoodsID
:
goods
.
GoodsID
,
GoodsType
:
goods
.
Ac
Type
,
GoodsType
:
goods
.
Goods
Type
,
SupplierID
:
goods
.
SupplierID
,
SupplierID
:
goods
.
SupplierID
,
SupplierName
:
goods
.
SupplierName
,
SupplierName
:
goods
.
SupplierName
,
CnDelivery
:
goods
.
CnDeliveryTime
,
CnDelivery
:
goods
.
CnDeliveryTime
,
...
@@ -68,12 +72,23 @@ func UpdateGoodsData(goodsMapList []GoodsMap) () {
...
@@ -68,12 +72,23 @@ func UpdateGoodsData(goodsMapList []GoodsMap) () {
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
}
}
bomMatching
.
LadderPrice
=
string
(
ladderPriceStr
)
bomMatching
.
LadderPrice
=
string
(
ladderPriceStr
)
//获取美元和人民币的价格
//获取美元和人民币的价格(需要去判断数量)
bomMatching
.
CnPrice
=
0
if
len
(
goods
.
LadderPrice
)
>
0
{
bomMatching
.
HkPrice
=
0
for
_
,
price
:=
range
goods
.
LadderPrice
{
if
goodsMap
.
Number
<=
price
.
Purchases
{
bomMatching
.
CnPrice
=
price
.
PriceCn
bomMatching
.
HkPrice
=
price
.
PriceUs
break
}
}
}
}
}
bomMatchingList
[
bomMatching
.
GoodsID
]
=
bomMatching
bomMatchingList
=
append
(
bomMatchingList
,
bomMatching
)
}
}
}
}
}
}
err
=
BatchSaveMatchings
(
bomId
,
bomMatchingList
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
}
}
internal/logic/match.go
View file @
19b5ff3b
...
@@ -71,9 +71,13 @@ func SearchGoods(bomId int, bomItems []model.BomItem) {
...
@@ -71,9 +71,13 @@ func SearchGoods(bomId int, bomItems []model.BomItem) {
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
}
}
UpdateGoodsData
(
goodsMapList
)
//要删除已经精确匹配过的bomItem
//for _, bom := range bomItems {
// for _, goodsMap := range goodsMapList {
//
// }
//}
//第二次去模糊匹配
//第二次去模糊匹配
//todo : 先删除第一次已经精确匹配的bom
goodsMapList
,
err
=
getUpdateGoodsData
(
bomId
,
bomItems
,
client
,
true
)
goodsMapList
,
err
=
getUpdateGoodsData
(
bomId
,
bomItems
,
client
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
...
@@ -111,6 +115,7 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, client *es.Client,
...
@@ -111,6 +115,7 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, client *es.Client,
}
}
var
goodsMap
GoodsMap
var
goodsMap
GoodsMap
goodsMap
.
GoodsId
=
strconv
.
FormatInt
(
int64
(
goods
.
GoodsID
),
10
)
goodsMap
.
GoodsId
=
strconv
.
FormatInt
(
int64
(
goods
.
GoodsID
),
10
)
goodsMap
.
Number
=
bomItems
[
key
]
.
Number
goodsMap
.
GoodsName
=
goods
.
GoodsName
goodsMap
.
GoodsName
=
goods
.
GoodsName
goodsMap
.
BomItemId
=
bomItems
[
key
]
.
BomItemID
goodsMap
.
BomItemId
=
bomItems
[
key
]
.
BomItemID
goodsMap
.
BomId
=
bomId
goodsMap
.
BomId
=
bomId
...
...
internal/model/bom_matching.go
View file @
19b5ff3b
...
@@ -2,7 +2,7 @@ package model
...
@@ -2,7 +2,7 @@ package model
type
BomItemMatching
struct
{
type
BomItemMatching
struct
{
// MatchingID 匹配ID
// MatchingID 匹配ID
MatchingID
int
`json:"matching_id"`
MatchingID
int
`json:"matching_id"
gorm:"primary_key"
`
// BomID bom主表Id(为了方便逆向查找bom_item表)
// BomID bom主表Id(为了方便逆向查找bom_item表)
BomID
int
`json:"bom_id"`
BomID
int
`json:"bom_id"`
// BomItemID bom详情ID
// BomItemID bom详情ID
...
@@ -41,3 +41,7 @@ type BomItemMatching struct {
...
@@ -41,3 +41,7 @@ type BomItemMatching struct {
// LadderPrice 阶梯价
// LadderPrice 阶梯价
LadderPrice
string
`json:"ladder_price"`
LadderPrice
string
`json:"ladder_price"`
}
}
func
(
BomItemMatching
)
TableName
()
string
{
return
"bom_item_matching"
}
\ No newline at end of file
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