Commit 10d1366d by mushishixian

各种修改

parent 8ce9c84e
The file could not be displayed because it is too large.
...@@ -3,9 +3,10 @@ package queue ...@@ -3,9 +3,10 @@ package queue
import ( import (
"bom_server/configs" "bom_server/configs"
"bom_server/internal/logic" "bom_server/internal/logic"
"bom_server/internal/model"
"encoding/json"
"fmt" "fmt"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq" "github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"strconv"
"time" "time"
) )
...@@ -21,18 +22,20 @@ func init() { ...@@ -21,18 +22,20 @@ func init() {
"amqp://huntadmin:jy2y2900@192.168.1.237:5672/", "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() start := time.Now()
bomIdStr := string(dataByte) var message model.BomMessage
bomId, err := strconv.ParseInt(bomIdStr, 10, 64) if err = json.Unmarshal(dataByte, &message); err != nil {
fmt.Println(bomId) fmt.Println(err)
}
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
err = logic.MatchGoods(int(bomId)) err = logic.MatchGoods(message)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
......
...@@ -12,6 +12,7 @@ url = "amqp://huntadmin:jy2y2900@192.168.1.237:5672/" ...@@ -12,6 +12,7 @@ url = "amqp://huntadmin:jy2y2900@192.168.1.237:5672/"
[api] [api]
base = http://192.168.2.232:40001 base = http://192.168.2.232:40001
goods = http://192.168.2.232:60004 goods = http://192.168.2.232:60004
upload = http://api.liexin.net
[falcon] [falcon]
push_url = http://192.168.1.237:1988/v1/push push_url = http://192.168.1.237:1988/v1/push
......
...@@ -42,6 +42,7 @@ type RabbitMQ struct { ...@@ -42,6 +42,7 @@ type RabbitMQ struct {
type Api struct { type Api struct {
Goods string `ini:"goods"` Goods string `ini:"goods"`
Upload string `ini:"upload"`
} }
var DatabaseSetting = &Database{} var DatabaseSetting = &Database{}
......
...@@ -12,11 +12,12 @@ import ( ...@@ -12,11 +12,12 @@ import (
) )
type GoodsMap struct { type GoodsMap struct {
GoodsId string GoodsId string
GoodsName string GoodsName string
BomItemId int BomItemId int
BomId int BomId int
Number int Number int
DeliveryType int
} }
func UpdateGoodsData(goodsMapList []GoodsMap) (err error) { func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
...@@ -49,6 +50,12 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) { ...@@ -49,6 +50,12 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
if goodsMap.GoodsId == goods.GoodsID { if goodsMap.GoodsId == goods.GoodsID {
bomId = goodsMap.BomId bomId = goodsMap.BomId
//组装需要去更新的商品信息 //组装需要去更新的商品信息
var delivery string
if goodsMap.DeliveryType == 1 {
delivery = goods.CnDeliveryTime
} else {
delivery = goods.HkDeliveryTime
}
bomMatching := model.BomItemMatching{ bomMatching := model.BomItemMatching{
BomID: goodsMap.BomId, BomID: goodsMap.BomId,
BomItemID: goodsMap.BomItemId, BomItemID: goodsMap.BomItemId,
...@@ -59,8 +66,8 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) { ...@@ -59,8 +66,8 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
GoodsType: goods.GoodsType, GoodsType: goods.GoodsType,
SupplierID: goods.SupplierID, SupplierID: goods.SupplierID,
SupplierName: goods.SupplierName, SupplierName: goods.SupplierName,
CnDelivery: goods.CnDeliveryTime, Delivery: delivery,
HkDelivery: goods.HkDeliveryTime, DeliveryType: goodsMap.DeliveryType,
Number: goodsMap.Number, Number: goodsMap.Number,
Stock: goods.Stock, Stock: goods.Stock,
IsBuy: goods.IsBuy, IsBuy: goods.IsBuy,
...@@ -94,11 +101,10 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) { ...@@ -94,11 +101,10 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
if goodsMap.Number <= purchases { if goodsMap.Number <= purchases {
//判断是否有优惠价,有的话取优惠价 //判断是否有优惠价,有的话取优惠价
if price.PriceAc != 0 { if price.PriceAc != 0 {
bomMatching.CnPrice = price.PriceAc bomMatching.Price = price.PriceAc
} else { } else {
bomMatching.CnPrice = price.PriceCn bomMatching.Price = price.PriceCn
} }
bomMatching.HkPrice = price.PriceUs
break break
} }
} }
......
...@@ -23,14 +23,15 @@ import ( ...@@ -23,14 +23,15 @@ import (
4.得到具体的商品数据以后,针对对应的商品进行修改 4.得到具体的商品数据以后,针对对应的商品进行修改
**/ **/
func MatchGoods(bomId int) (err error) { func MatchGoods(message model.BomMessage) (err error) {
//获取bom //获取bom
bomId := message.BomId
bom := GetBomInfoWithItems(bomId) bom := GetBomInfoWithItems(bomId)
if len(bom.BomItems) == 0 { if len(bom.BomItems) == 0 {
return errors.New("没有商品的bom单") return errors.New("没有商品的bom单")
} }
bomItems := bom.BomItems bomItems := bom.BomItems
perGoDealNumber := 50 perGoDealNumber := 200
//开启协程处理搜索.每50个开启一个协程 //开启协程处理搜索.每50个开启一个协程
var wg sync.WaitGroup var wg sync.WaitGroup
//判断是否有余数 //判断是否有余数
...@@ -52,7 +53,7 @@ func MatchGoods(bomId int) (err error) { ...@@ -52,7 +53,7 @@ func MatchGoods(bomId int) (err error) {
bomData = bomItems[i : i+perGoDealNumber] bomData = bomItems[i : i+perGoDealNumber]
} }
go func() { 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) fmt.Println(err)
} }
}() }()
...@@ -63,7 +64,7 @@ func MatchGoods(bomId int) (err error) { ...@@ -63,7 +64,7 @@ func MatchGoods(bomId int) (err error) {
} }
//去es搜索商品,得到对应的商品对应关系 //去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() { defer func() {
wg.Done() wg.Done()
}() }()
...@@ -76,7 +77,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, wg *sync.WaitGroup) (err e ...@@ -76,7 +77,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, wg *sync.WaitGroup) (err e
} }
defer client.Stop() defer client.Stop()
//第一次先去精确匹配 //第一次先去精确匹配
goodsMapList, err := getUpdateGoodsData(bomId, bomItems, client, true) goodsMapList, err := getUpdateGoodsData(bomId, bomItems, deliveryType, client, true)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
...@@ -88,7 +89,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, wg *sync.WaitGroup) (err e ...@@ -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 { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
...@@ -121,7 +122,7 @@ func checkInGoodsMap(bom model.BomItem, goodsMapList []GoodsMap) bool { ...@@ -121,7 +122,7 @@ func checkInGoodsMap(bom model.BomItem, goodsMapList []GoodsMap) bool {
return false 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 { if len(bomItems) == 0 {
return return
} }
...@@ -160,6 +161,7 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, client *es.Client, ...@@ -160,6 +161,7 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, client *es.Client,
goodsMap.GoodsName = bomItems[key].GoodsName goodsMap.GoodsName = bomItems[key].GoodsName
goodsMap.BomItemId = bomItems[key].BomItemID goodsMap.BomItemId = bomItems[key].BomItemID
goodsMap.BomId = bomId goodsMap.BomId = bomId
goodsMap.DeliveryType = deliveryType
goodsMapList = append(goodsMapList, goodsMap) goodsMapList = append(goodsMapList, goodsMap)
break break
} }
......
...@@ -25,6 +25,12 @@ type Bom struct { ...@@ -25,6 +25,12 @@ type Bom struct {
BomItems []BomItem BomItems []BomItem
} }
type BomMessage struct {
BomId int `json:"bom_id"`
DeliveryType int `json:"delivery_type"`
Sort int `json:"sort"`
}
//func (Bom) TableName() string { //func (Bom) TableName() string {
// return "bom" // return "bom"
//} //}
\ No newline at end of file
...@@ -6,8 +6,8 @@ type BomItemMatching struct { ...@@ -6,8 +6,8 @@ type BomItemMatching struct {
// BomID bom主表Id(为了方便逆向查找bom_item表) // BomID bom主表Id(为了方便逆向查找bom_item表)
GoodsName string `json:"goods_name"` GoodsName string `json:"goods_name"`
BrandName string `json:"brand_name"` BrandName string `json:"brand_name"`
BrandId int `json:"brand_id"` BrandId int `json:"brand_id"`
BomID int `json:"bom_id"` BomID int `json:"bom_id"`
// BomItemID bom详情ID // BomItemID bom详情ID
BomItemID int `json:"bom_item_id"` BomItemID int `json:"bom_item_id"`
// GoodsID 匹配到的商品ID // GoodsID 匹配到的商品ID
...@@ -18,15 +18,11 @@ type BomItemMatching struct { ...@@ -18,15 +18,11 @@ type BomItemMatching struct {
SupplierID int `json:"supplier_id"` SupplierID int `json:"supplier_id"`
// SupplierName 供应商名字 // SupplierName 供应商名字
SupplierName string `json:"supplier_name"` SupplierName string `json:"supplier_name"`
// CnDelivery 大陆货期 //货期
CnDelivery string `json:"cn_delivery"` Delivery string `json:"delivery"`
// HkDelivery 香港货期 DeliveryType int `json:"delivery_type"`
HkDelivery string `json:"hk_delivery"` Number int `json:"number"`
Number int `json:"number"` Price float64 `json:"price"`
// CnPrice 大陆单价
CnPrice float64 `json:"cn_price"`
// HkPrice 香港单价
HkPrice float64 `json:"hk_price"`
// Stock 库存 // Stock 库存
Stock int `json:"stock"` Stock int `json:"stock"`
// Moq 起订量 // Moq 起订量
...@@ -41,11 +37,11 @@ type BomItemMatching struct { ...@@ -41,11 +37,11 @@ type BomItemMatching struct {
AddTime int `json:"add_time"` AddTime int `json:"add_time"`
// UpdateTime 更新时间 // UpdateTime 更新时间
UpdateTime int `json:"update_time"` UpdateTime int `json:"update_time"`
IsBuy int `json:"is_buy" gorm:"-"` IsBuy int `json:"is_buy" gorm:"-"`
// LadderPrice 阶梯价 // LadderPrice 阶梯价
LadderPrice string `json:"ladder_price"` LadderPrice string `json:"ladder_price"`
} }
func (BomItemMatching) TableName() string { func (BomItemMatching) TableName() string {
return "bom_item_matching" return "bom_item_matching"
} }
\ No newline at end of file
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
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment