Commit 10d1366d by mushishixian

各种修改

parent 8ce9c84e
The file could not be displayed because it is too large.
......@@ -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)
}
......
......@@ -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
......
......@@ -42,6 +42,7 @@ type RabbitMQ struct {
type Api struct {
Goods string `ini:"goods"`
Upload string `ini:"upload"`
}
var DatabaseSetting = &Database{}
......
......@@ -12,11 +12,12 @@ import (
)
type GoodsMap struct {
GoodsId string
GoodsName string
BomItemId int
BomId int
Number int
GoodsId string
GoodsName string
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.HkDeliveryTime,
Delivery: delivery,
DeliveryType: goodsMap.DeliveryType,
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.CnPrice = price.PriceAc
bomMatching.Price = price.PriceAc
} else {
bomMatching.CnPrice = price.PriceCn
bomMatching.Price = price.PriceCn
}
bomMatching.HkPrice = price.PriceUs
break
}
}
......
......@@ -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 := 50
perGoDealNumber := 200
//开启协程处理搜索.每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
}
......
......@@ -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
......@@ -6,8 +6,8 @@ type BomItemMatching struct {
// BomID bom主表Id(为了方便逆向查找bom_item表)
GoodsName string `json:"goods_name"`
BrandName string `json:"brand_name"`
BrandId int `json:"brand_id"`
BomID int `json:"bom_id"`
BrandId int `json:"brand_id"`
BomID int `json:"bom_id"`
// BomItemID bom详情ID
BomItemID int `json:"bom_item_id"`
// GoodsID 匹配到的商品ID
......@@ -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"`
Number int `json:"number"`
// CnPrice 大陆单价
CnPrice float64 `json:"cn_price"`
// HkPrice 香港单价
HkPrice float64 `json:"hk_price"`
//货期
Delivery string `json:"delivery"`
DeliveryType int `json:"delivery_type"`
Number int `json:"number"`
Price float64 `json:"price"`
// Stock 库存
Stock int `json:"stock"`
// Moq 起订量
......@@ -41,11 +37,11 @@ type BomItemMatching struct {
AddTime int `json:"add_time"`
// UpdateTime 更新时间
UpdateTime int `json:"update_time"`
IsBuy int `json:"is_buy" gorm:"-"`
IsBuy int `json:"is_buy" gorm:"-"`
// LadderPrice 阶梯价
LadderPrice string `json:"ladder_price"`
}
func (BomItemMatching) TableName() string {
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