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
10d1366d
authored
May 27, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
各种修改
parent
8ce9c84e
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
84 additions
and
27 deletions
cmd/cmd.exe~
cmd/queue/bom.go
conf/config.ini
configs/config.go
internal/logic/goods.go
internal/logic/match.go
internal/model/bom.go
internal/model/bom_matching.go
internal/service/oss.go
cmd/cmd.exe~
View file @
10d1366d
The file could not be displayed because it is too large.
cmd/queue/bom.go
View file @
10d1366d
...
...
@@ -3,9 +3,10 @@ package queue
import
(
"bom_server/configs"
"bom_server/internal/logic"
"bom_server/internal/model"
"encoding/json"
"fmt"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"strconv"
"time"
)
...
...
@@ -21,18 +22,20 @@ func init() {
"amqp://huntadmin:jy2y2900@192.168.1.237:5672/"
,
}
rabbitmq
.
Send
(
queueExchange
,
"48"
)
str
:=
`{"bom_id":48,"delivery_type":1,"sort_type":1}`
rabbitmq
.
Send
(
queueExchange
,
str
)
}
func
(
t
*
RecvPro
)
Consumer
(
dataByte
[]
byte
)
error
{
func
(
t
*
RecvPro
)
Consumer
(
dataByte
[]
byte
)
(
err
error
)
{
start
:=
time
.
Now
()
bomIdStr
:=
string
(
dataByte
)
bomId
,
err
:=
strconv
.
ParseInt
(
bomIdStr
,
10
,
64
)
fmt
.
Println
(
bomId
)
var
message
model
.
BomMessage
if
err
=
json
.
Unmarshal
(
dataByte
,
&
message
);
err
!=
nil
{
fmt
.
Println
(
err
)
}
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
err
=
logic
.
MatchGoods
(
int
(
bomId
)
)
err
=
logic
.
MatchGoods
(
message
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
...
...
conf/config.ini
View file @
10d1366d
...
...
@@ -12,6 +12,7 @@ url = "amqp://huntadmin:jy2y2900@192.168.1.237:5672/"
[api]
base
=
http://192.168.2.232:40001
goods
=
http://192.168.2.232:60004
upload
=
http://api.liexin.net
[falcon]
push_url
=
http://192.168.1.237:1988/v1/push
...
...
configs/config.go
View file @
10d1366d
...
...
@@ -42,6 +42,7 @@ type RabbitMQ struct {
type
Api
struct
{
Goods
string
`ini:"goods"`
Upload
string
`ini:"upload"`
}
var
DatabaseSetting
=
&
Database
{}
...
...
internal/logic/goods.go
View file @
10d1366d
...
...
@@ -17,6 +17,7 @@ type GoodsMap struct {
BomItemId
int
BomId
int
Number
int
DeliveryType
int
}
func
UpdateGoodsData
(
goodsMapList
[]
GoodsMap
)
(
err
error
)
{
...
...
@@ -49,6 +50,12 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
if
goodsMap
.
GoodsId
==
goods
.
GoodsID
{
bomId
=
goodsMap
.
BomId
//组装需要去更新的商品信息
var
delivery
string
if
goodsMap
.
DeliveryType
==
1
{
delivery
=
goods
.
CnDeliveryTime
}
else
{
delivery
=
goods
.
HkDeliveryTime
}
bomMatching
:=
model
.
BomItemMatching
{
BomID
:
goodsMap
.
BomId
,
BomItemID
:
goodsMap
.
BomItemId
,
...
...
@@ -59,8 +66,8 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
GoodsType
:
goods
.
GoodsType
,
SupplierID
:
goods
.
SupplierID
,
SupplierName
:
goods
.
SupplierName
,
CnDelivery
:
goods
.
CnDeliveryTime
,
HkDelivery
:
goods
.
HkDeliveryTim
e
,
Delivery
:
delivery
,
DeliveryType
:
goodsMap
.
DeliveryTyp
e
,
Number
:
goodsMap
.
Number
,
Stock
:
goods
.
Stock
,
IsBuy
:
goods
.
IsBuy
,
...
...
@@ -94,11 +101,10 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
if
goodsMap
.
Number
<=
purchases
{
//判断是否有优惠价,有的话取优惠价
if
price
.
PriceAc
!=
0
{
bomMatching
.
Cn
Price
=
price
.
PriceAc
bomMatching
.
Price
=
price
.
PriceAc
}
else
{
bomMatching
.
Cn
Price
=
price
.
PriceCn
bomMatching
.
Price
=
price
.
PriceCn
}
bomMatching
.
HkPrice
=
price
.
PriceUs
break
}
}
...
...
internal/logic/match.go
View file @
10d1366d
...
...
@@ -23,14 +23,15 @@ import (
4.得到具体的商品数据以后,针对对应的商品进行修改
**/
func
MatchGoods
(
bomId
int
)
(
err
error
)
{
func
MatchGoods
(
message
model
.
BomMessage
)
(
err
error
)
{
//获取bom
bomId
:=
message
.
BomId
bom
:=
GetBomInfoWithItems
(
bomId
)
if
len
(
bom
.
BomItems
)
==
0
{
return
errors
.
New
(
"没有商品的bom单"
)
}
bomItems
:=
bom
.
BomItems
perGoDealNumber
:=
5
0
perGoDealNumber
:=
20
0
//开启协程处理搜索.每50个开启一个协程
var
wg
sync
.
WaitGroup
//判断是否有余数
...
...
@@ -52,7 +53,7 @@ func MatchGoods(bomId int) (err error) {
bomData
=
bomItems
[
i
:
i
+
perGoDealNumber
]
}
go
func
()
{
if
err
:=
SearchGoods
(
bomId
,
bomData
,
&
wg
);
err
!=
nil
{
if
err
:=
SearchGoods
(
bomId
,
bomData
,
message
.
DeliveryType
,
message
.
Sort
,
&
wg
);
err
!=
nil
{
fmt
.
Println
(
err
)
}
}()
...
...
@@ -63,7 +64,7 @@ func MatchGoods(bomId int) (err error) {
}
//去es搜索商品,得到对应的商品对应关系
func
SearchGoods
(
bomId
int
,
bomItems
[]
model
.
BomItem
,
wg
*
sync
.
WaitGroup
)
(
err
error
)
{
func
SearchGoods
(
bomId
int
,
bomItems
[]
model
.
BomItem
,
deliveryType
,
sort
int
,
wg
*
sync
.
WaitGroup
)
(
err
error
)
{
defer
func
()
{
wg
.
Done
()
}()
...
...
@@ -76,7 +77,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, wg *sync.WaitGroup) (err e
}
defer
client
.
Stop
()
//第一次先去精确匹配
goodsMapList
,
err
:=
getUpdateGoodsData
(
bomId
,
bomItems
,
client
,
true
)
goodsMapList
,
err
:=
getUpdateGoodsData
(
bomId
,
bomItems
,
deliveryType
,
client
,
true
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
...
...
@@ -88,7 +89,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, wg *sync.WaitGroup) (err e
}
}
//第二次去模糊匹配
fuzzyGoodsMapList
,
err
:=
getUpdateGoodsData
(
bomId
,
fuzzyBomItems
,
client
,
true
)
fuzzyGoodsMapList
,
err
:=
getUpdateGoodsData
(
bomId
,
fuzzyBomItems
,
deliveryType
,
client
,
true
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
...
...
@@ -121,7 +122,7 @@ func checkInGoodsMap(bom model.BomItem, goodsMapList []GoodsMap) bool {
return
false
}
func
getUpdateGoodsData
(
bomId
int
,
bomItems
[]
model
.
BomItem
,
client
*
es
.
Client
,
rawSearch
bool
)
(
goodsMapList
[]
GoodsMap
,
err
error
)
{
func
getUpdateGoodsData
(
bomId
int
,
bomItems
[]
model
.
BomItem
,
deliveryType
int
,
client
*
es
.
Client
,
rawSearch
bool
)
(
goodsMapList
[]
GoodsMap
,
err
error
)
{
if
len
(
bomItems
)
==
0
{
return
}
...
...
@@ -160,6 +161,7 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, client *es.Client,
goodsMap
.
GoodsName
=
bomItems
[
key
]
.
GoodsName
goodsMap
.
BomItemId
=
bomItems
[
key
]
.
BomItemID
goodsMap
.
BomId
=
bomId
goodsMap
.
DeliveryType
=
deliveryType
goodsMapList
=
append
(
goodsMapList
,
goodsMap
)
break
}
...
...
internal/model/bom.go
View file @
10d1366d
...
...
@@ -25,6 +25,12 @@ type Bom struct {
BomItems
[]
BomItem
}
type
BomMessage
struct
{
BomId
int
`json:"bom_id"`
DeliveryType
int
`json:"delivery_type"`
Sort
int
`json:"sort"`
}
//func (Bom) TableName() string {
// return "bom"
//}
\ No newline at end of file
internal/model/bom_matching.go
View file @
10d1366d
...
...
@@ -18,15 +18,11 @@ type BomItemMatching struct {
SupplierID
int
`json:"supplier_id"`
// SupplierName 供应商名字
SupplierName
string
`json:"supplier_name"`
// CnDelivery 大陆货期
CnDelivery
string
`json:"cn_delivery"`
// HkDelivery 香港货期
HkDelivery
string
`json:"hk_delivery"`
//货期
Delivery
string
`json:"delivery"`
DeliveryType
int
`json:"delivery_type"`
Number
int
`json:"number"`
// CnPrice 大陆单价
CnPrice
float64
`json:"cn_price"`
// HkPrice 香港单价
HkPrice
float64
`json:"hk_price"`
Price
float64
`json:"price"`
// Stock 库存
Stock
int
`json:"stock"`
// Moq 起订量
...
...
internal/service/oss.go
0 → 100644
View file @
10d1366d
package
service
import
(
"bom_server/configs"
"errors"
"github.com/imroc/req"
"github.com/syyongx/php2go"
"strconv"
"time"
)
type
Response
struct
{
Code
int
`json:"code"`
}
func
UploadToOss
(
path
,
fileType
,
k1
,
key
string
)
(
err
error
)
{
if
path
==
""
{
return
nil
}
url
:=
configs
.
ApiSetting
.
Upload
uploadKey
:=
"1232"
md5Input
:=
strconv
.
FormatInt
(
time
.
Now
()
.
Unix
(),
10
)
params
:=
req
.
Param
{
"source"
:
1
,
"k1"
:
time
.
Now
()
.
Unix
(),
"k2"
:
php2go
.
Md5
(
php2go
.
Md5
(
md5Input
))
+
uploadKey
,
"FileType"
:
fileType
,
}
resp
,
err
:=
req
.
Post
(
url
,
params
)
if
err
!=
nil
{
return
err
}
var
response
Response
if
err
=
resp
.
ToJSON
(
&
response
);
err
!=
nil
{
return
errors
.
New
(
resp
.
String
())
}
if
response
.
Code
!=
200
{
return
}
}
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