Commit 44b4402a by mushishixian

修复

parent 6d55a733
The file could not be displayed because it is too large.
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq" "github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"github.com/prometheus/common/log"
"time" "time"
) )
...@@ -30,14 +31,14 @@ func (t *RecvPro) Consumer(dataByte []byte) (err error) { ...@@ -30,14 +31,14 @@ func (t *RecvPro) Consumer(dataByte []byte) (err error) {
start := time.Now() start := time.Now()
var message model.BomMessage var message model.BomMessage
if err = json.Unmarshal(dataByte, &message); err != nil { if err = json.Unmarshal(dataByte, &message); err != nil {
fmt.Println(err) log.Error(err)
} }
if err != nil { if err != nil {
fmt.Println(err) log.Error(err)
} }
err = logic.MatchGoods(message) err = logic.MatchGoods(message)
if err != nil { if err != nil {
fmt.Println(err) log.Error(err)
} }
duration := time.Now().Sub(start) duration := time.Now().Sub(start)
fmt.Println(duration) fmt.Println(duration)
......
...@@ -16,6 +16,7 @@ require ( ...@@ -16,6 +16,7 @@ require (
github.com/shopspring/decimal v1.2.0 github.com/shopspring/decimal v1.2.0
github.com/smartystreets/goconvey v1.6.4 // indirect github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/syyongx/php2go v0.9.4 github.com/syyongx/php2go v0.9.4
github.com/tidwall/gjson v1.6.0
gopkg.in/ini.v1 v1.56.0 // indirect gopkg.in/ini.v1 v1.56.0 // indirect
gopkg.in/olivere/elastic.v5 v5.0.85 gopkg.in/olivere/elastic.v5 v5.0.85
) )
...@@ -333,6 +333,12 @@ github.com/syyongx/php2go v0.9.4 h1:qUtETTHzqHzxZK8plkbkb0YawD8bpLpxNsbzHQmb22Y= ...@@ -333,6 +333,12 @@ github.com/syyongx/php2go v0.9.4 h1:qUtETTHzqHzxZK8plkbkb0YawD8bpLpxNsbzHQmb22Y=
github.com/syyongx/php2go v0.9.4/go.mod h1:meN2eIhhUoxOd2nMxbpe8g6cFPXI5O9/UAAuz7oDdzw= github.com/syyongx/php2go v0.9.4/go.mod h1:meN2eIhhUoxOd2nMxbpe8g6cFPXI5O9/UAAuz7oDdzw=
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161/go.mod h1:wM7WEvslTq+iOEAMDLSzhVuOt5BRZ05WirO+b09GHQU= github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161/go.mod h1:wM7WEvslTq+iOEAMDLSzhVuOt5BRZ05WirO+b09GHQU=
github.com/templexxx/xor v0.0.0-20181023030647-4e92f724b73b/go.mod h1:5XA7W9S6mni3h5uvOC75dA3m9CCCaS83lltmc0ukdi4= github.com/templexxx/xor v0.0.0-20181023030647-4e92f724b73b/go.mod h1:5XA7W9S6mni3h5uvOC75dA3m9CCCaS83lltmc0ukdi4=
github.com/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc=
github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls=
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tjfoc/gmsm v1.0.1/go.mod h1:XxO4hdhhrzAd+G4CjDqaOkd0hUzmtPR/d3EiBBMn/wc= github.com/tjfoc/gmsm v1.0.1/go.mod h1:XxO4hdhhrzAd+G4CjDqaOkd0hUzmtPR/d3EiBBMn/wc=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
......
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"bom_server/internal/model" "bom_server/internal/model"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
es "gopkg.in/olivere/elastic.v5" es "gopkg.in/olivere/elastic.v5"
"strconv" "strconv"
) )
...@@ -27,7 +26,7 @@ func GetBomItem(bomId, bomItemId int) (bomItem model.BomItem) { ...@@ -27,7 +26,7 @@ func GetBomItem(bomId, bomItemId int) (bomItem model.BomItem) {
} }
//更新没有匹配的到bom详情 //更新没有匹配的到bom详情
func UpdateNoMatchBomItem(bomItems []model.BomItem) (err error) { func UpdateNoMatchBomItem(bomItems []model.BomItem,isCancelMatch bool) (err error) {
if len(bomItems) == 0 { if len(bomItems) == 0 {
return nil return nil
} }
...@@ -46,11 +45,13 @@ func UpdateNoMatchBomItem(bomItems []model.BomItem) (err error) { ...@@ -46,11 +45,13 @@ func UpdateNoMatchBomItem(bomItems []model.BomItem) (err error) {
if err != nil { if err != nil {
return return
} }
matchingDelStatus := 2 if isCancelMatch {
err = model.Db.Table("lie_bom_item_matching_"+tableEnd).Where("bom_item_id IN (?)", updateIdList). matchingDelStatus := 2
Updates(map[string]interface{}{"status": matchingDelStatus}).Error err = model.Db.Table("lie_bom_item_matching_"+tableEnd).Where("bom_item_id IN (?)", updateIdList).
if err != nil { Updates(map[string]interface{}{"status": matchingDelStatus}).Error
return if err != nil {
return
}
} }
return nil return nil
} }
...@@ -84,13 +85,12 @@ func UpdateBomItem(bomId, bomItemId int) (err error) { ...@@ -84,13 +85,12 @@ func UpdateBomItem(bomId, bomItemId int) (err error) {
} }
defer client.Stop() defer client.Stop()
//直接模糊匹配 //直接模糊匹配
goodsMapList, err := getUpdateGoodsData(bomId, bomItems, where.DeliveryType, where.Sort, client, false) goodsMapList, err := getUpdateGoodsData(bomId, bomItems, where.DeliveryType, where.Sort, client, true)
if err != nil { if err != nil {
return return
} }
fmt.Println(goodsMapList)
if len(goodsMapList) == 0 { if len(goodsMapList) == 0 {
err = UpdateNoMatchBomItem(bomItems) err = UpdateNoMatchBomItem(bomItems,true)
if err != nil { if err != nil {
return return
} }
......
...@@ -32,7 +32,7 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er ...@@ -32,7 +32,7 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er
bomIdStr := strconv.FormatInt(int64(bomId), 10) bomIdStr := strconv.FormatInt(int64(bomId), 10)
tableEnd := string(bomIdStr[len(bomIdStr)-1]) tableEnd := string(bomIdStr[len(bomIdStr)-1])
tableName := "lie_bom_item_matching_" + tableEnd tableName := "lie_bom_item_matching_" + tableEnd
var isBuyBomItemIdList, noBuyBomItemIdList []int //批量更新每一条记录之前,要去批量更新item表的item_status
for k, matching := range matchingList { for k, matching := range matchingList {
if k == 1 || k == 2 || k == 3 { if k == 1 || k == 2 || k == 3 {
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
...@@ -50,7 +50,30 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er ...@@ -50,7 +50,30 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er
return return
} }
} }
//先找出不同购买状态的bom_id列表,还要去修改bom_item表的item_status for _, matching := range matchingList {
now := time.Now().Unix()
if matching.IsBuy == 1 {
err = model.Db.Table("lie_bom_item_"+tableEnd).Where("bom_item_id = ?", matching.BomItemID).
Updates(map[string]interface{}{"item_status": 2, "update_time": now}).Error
if err != nil {
return
}
} else {
err = model.Db.Table("lie_bom_item_"+tableEnd).Where("bom_item_id = ?", matching.BomItemID).
Updates(map[string]interface{}{"item_status": 3, "update_time": now}).Error
if err != nil {
return
}
}
}
}
return nil
}
func batchUpdateItemStatus(tableEnd string, matchingList []model.BomItemMatching) (err error) {
//先找出不同购买状态的bom_id列表,还要去修改bom_item表的item_status
var isBuyBomItemIdList, noBuyBomItemIdList []int
for _, matching := range matchingList {
if matching.IsBuy == 1 { if matching.IsBuy == 1 {
isBuyBomItemIdList = append(isBuyBomItemIdList, matching.BomItemID) isBuyBomItemIdList = append(isBuyBomItemIdList, matching.BomItemID)
} else { } else {
...@@ -69,7 +92,7 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er ...@@ -69,7 +92,7 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er
if err != nil { if err != nil {
return return
} }
return nil return
} }
//刷新bom匹配的商品信息 //刷新bom匹配的商品信息
...@@ -105,13 +128,13 @@ func RefreshBomMatchingGoods(bomId int) (err error) { ...@@ -105,13 +128,13 @@ func RefreshBomMatchingGoods(bomId int) (err error) {
} }
goodsIdsStr := strings.Join(goodsIds, ",") goodsIdsStr := strings.Join(goodsIds, ",")
//去请求商品服务 //去请求商品服务
responseData, err := GetGoodsInfo(goodsIdsStr) goodsList, err := GetGoodsInfo(goodsIdsStr)
if err != nil { if err != nil {
return return
} }
var bomMatchingList []model.BomItemMatching var bomMatchingList []model.BomItemMatching
for _, matching := range bomMatchings { for _, matching := range bomMatchings {
for _, goods := range responseData.Data { for _, goods := range goodsList {
if matching.GoodsID == goods.GoodsID { if matching.GoodsID == goods.GoodsID {
var goodsMap GoodsMap var goodsMap GoodsMap
goodsMap.Number = matching.Number goodsMap.Number = matching.Number
...@@ -149,13 +172,13 @@ func RefreshBomMatchingGoodsAbandon(bomId int) (err error) { ...@@ -149,13 +172,13 @@ func RefreshBomMatchingGoodsAbandon(bomId int) (err error) {
} }
goodsIdsStr := strings.Join(goodsIds, ",") goodsIdsStr := strings.Join(goodsIds, ",")
//去请求商品服务 //去请求商品服务
responseData, err := GetGoodsInfo(goodsIdsStr) goodsList, err := GetGoodsInfo(goodsIdsStr)
if err != nil { if err != nil {
return return
} }
var bomMatchingList []model.BomItemMatching var bomMatchingList []model.BomItemMatching
for _, matching := range bomMatchings { for _, matching := range bomMatchings {
for _, goods := range responseData.Data { for _, goods := range goodsList {
if matching.GoodsID == goods.GoodsID { if matching.GoodsID == goods.GoodsID {
var goodsMap GoodsMap var goodsMap GoodsMap
goodsMap.Number = matching.Number goodsMap.Number = matching.Number
......
...@@ -2,12 +2,10 @@ package logic ...@@ -2,12 +2,10 @@ package logic
import ( import (
"bom_server/configs" "bom_server/configs"
"bom_server/internal/common"
"bom_server/internal/model" "bom_server/internal/model"
"encoding/json" "encoding/json"
"errors"
"github.com/imroc/req" "github.com/imroc/req"
"reflect" "github.com/tidwall/gjson"
"strings" "strings"
"time" "time"
) )
...@@ -31,16 +29,15 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) { ...@@ -31,16 +29,15 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
goodsIds = append(goodsIds, goodsMap.GoodsId) goodsIds = append(goodsIds, goodsMap.GoodsId)
} }
goodsIdsStr := strings.Join(goodsIds, ",") goodsIdsStr := strings.Join(goodsIds, ",")
responseData, err := GetGoodsInfo(goodsIdsStr) goodList, err := GetGoodsInfo(goodsIdsStr)
if err != nil { if err != nil {
return return
} }
//这是匹配到的数据 //这是匹配到的数据
var bomMatchingList []model.BomItemMatching var bomMatchingList []model.BomItemMatching
for _, goodsMap := range goodsMapList { for _, goodsMap := range goodsMapList {
for _, goods := range responseData.Data { for _, goods := range goodList {
goodsId := common.Assert(goods.GoodsID, "string") if goodsMap.GoodsId == goods.GoodsID {
if goodsMap.GoodsId == goodsId.(string) {
bomId = goodsMap.BomId bomId = goodsMap.BomId
//组装需要去更新的商品信息 //组装需要去更新的商品信息
bomMatching, err := MatchGoodsInfo(goods, goodsMap) bomMatching, err := MatchGoodsInfo(goods, goodsMap)
...@@ -58,7 +55,7 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) { ...@@ -58,7 +55,7 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
return return
} }
func GetGoodsInfo(goodsIdsStr string) (responseData model.ApiGoodsResponse, err error) { func GetGoodsInfo(goodsIdsStr string) (goodsList []model.ApiGoods, err error) {
goodsServerUrl := configs.ApiSetting.Goods goodsServerUrl := configs.ApiSetting.Goods
params := req.Param{ params := req.Param{
"goods_id": goodsIdsStr, "goods_id": goodsIdsStr,
...@@ -67,30 +64,69 @@ func GetGoodsInfo(goodsIdsStr string) (responseData model.ApiGoodsResponse, err ...@@ -67,30 +64,69 @@ func GetGoodsInfo(goodsIdsStr string) (responseData model.ApiGoodsResponse, err
if err != nil { if err != nil {
return return
} }
var responseDataTemp model.ApiGoodsResponseTemp //先判断返回的data是不是字典,不是字典代表可能是返回字符串了
if err = resp.ToJSON(&responseDataTemp); err != nil { if gjson.Get(resp.String(), "data").IsObject() {
err = errors.New(err.Error()) for _, data := range gjson.Get(resp.String(), "data").Map() {
return //还要去判断是否是bool
} if data.IsObject() {
responseData.Data = make(map[string]model.ApiGoods, 200) var goods model.ApiGoods
for goodsId, goods := range responseDataTemp.Data { goods.GoodsName = data.Get("goods_name").String()
//不是bool值的,才去给数据,商品服务的商品信息有可能是bool值,蛋疼 goods.GoodsID = data.Get("goods_id").String()
if reflect.ValueOf(goods).Type().String() != "bool" { goods.BrandID = int(data.Get("goods_id").Int())
var goodsStr []byte goods.Pdf = data.Get("pdf").String()
goodsStr, err = json.Marshal(goods) goods.Stock = int(data.Get("stock").Int())
if err != nil { goods.Mpq = int(data.Get("mpq").Int())
return goods.Moq = int(data.Get("moq").Int())
} goods.SupplierName = data.Get("supplier_name").String()
var apiGoods model.ApiGoods goods.BrandName = data.Get("brand_name").String()
err = json.Unmarshal(goodsStr, &apiGoods) goods.HkDeliveryTime = data.Get("hk_delivery_time").String()
if err != nil { goods.CnDeliveryTime = data.Get("cn_delivery_time").String()
return goods.IsBuy = int(data.Get("is_buy").Int())
goods.Encap = data.Get("encap").String()
goods.SupplierID = int(data.Get("supplier_id").Int())
goods.Status = int(data.Get("status").Int())
goods.GoodsType = int(data.Get("goods_type").Int())
var ladderPrice []model.LadderPrice
for _, price := range data.Get("ladder_price").Array() {
var ladder model.LadderPrice
ladder = model.LadderPrice{
Purchases: int(price.Get("purchases").Int()),
PriceUs: price.Get("price_us").Float(),
PriceCn: price.Get("price_cn").Float(),
PriceAc: price.Get("price_ac").Float(),
}
ladderPrice = append(ladderPrice, ladder)
}
goods.LadderPrice = ladderPrice
goodsList = append(goodsList, goods)
} }
responseData.Data[goodsId] = apiGoods
} }
} }
responseData.Errmsg = responseDataTemp.Errmsg
responseData.Errcode = responseDataTemp.Errcode //var responseDataTemp model.ApiGoodsResponseTemp
//if err = resp.ToJSON(&responseDataTemp); err != nil {
// err = errors.New(err.Error())
// return
//}
//responseData.Data = make(map[string]model.ApiGoods, 200)
//for goodsId, goods := range responseDataTemp.Data {
// //不是bool值的,才去给数据,商品服务的商品信息有可能是bool值,蛋疼
// if reflect.ValueOf(goods).Type().String() != "bool" {
// var goodsStr []byte
// goodsStr, err = json.Marshal(goods)
// if err != nil {
// return
// }
// var apiGoods model.ApiGoods
// err = json.Unmarshal(goodsStr, &apiGoods)
// if err != nil {
// return
// }
// responseData.Data[goodsId] = apiGoods
// }
//}
//responseData.Errmsg = responseDataTemp.Errmsg
//responseData.Errcode = responseDataTemp.Errcode
return return
} }
...@@ -103,19 +139,21 @@ func MatchGoodsInfo(goods model.ApiGoods, goodsMap GoodsMap) (bomMatching model. ...@@ -103,19 +139,21 @@ func MatchGoodsInfo(goods model.ApiGoods, goodsMap GoodsMap) (bomMatching model.
} else { } else {
delivery = goods.HkDeliveryTime delivery = goods.HkDeliveryTime
} }
goodsIdStr := common.Assert(goods.GoodsID, "string") var pdf string
pdf := common.Assert(goods.Pdf, "string") pdf = goods.Pdf
brandId := common.Assert(goods.BrandID, "int") if goods.Pdf == "false" {
pdf = ""
}
bomMatching = model.BomItemMatching{ bomMatching = model.BomItemMatching{
BomID: goodsMap.BomId, BomID: goodsMap.BomId,
BomItemID: goodsMap.BomItemId, BomItemID: goodsMap.BomItemId,
BrandId: brandId.(int), BrandId: goods.BrandID,
GoodsID: goodsIdStr.(string), GoodsID: goods.GoodsID,
GoodsName: goods.GoodsName, GoodsName: goods.GoodsName,
BrandName: goods.BrandName, BrandName: goods.BrandName,
GoodsType: goods.GoodsType, GoodsType: goods.GoodsType,
SupplierID: goods.SupplierID, SupplierID: goods.SupplierID,
Pdf: pdf.(string), Pdf: pdf,
SupplierName: goods.SupplierName, SupplierName: goods.SupplierName,
Delivery: delivery, Delivery: delivery,
DeliveryType: goodsMap.DeliveryType, DeliveryType: goodsMap.DeliveryType,
...@@ -149,23 +187,20 @@ func MatchGoodsInfo(goods model.ApiGoods, goodsMap GoodsMap) (bomMatching model. ...@@ -149,23 +187,20 @@ func MatchGoodsInfo(goods model.ApiGoods, goodsMap GoodsMap) (bomMatching model.
} }
bomMatching.LadderPrice = string(ladderPriceStr) bomMatching.LadderPrice = string(ladderPriceStr)
//获取美元和人民币的价格(需要去判断数量) //获取美元和人民币的价格(需要去判断数量)
if len(goods.LadderPrice) > 0 { for _, price := range goods.LadderPrice {
for _, price := range goods.LadderPrice { if goodsMap.Number <= price.Purchases {
//要先去断言,因为商品服务返回的json的值类型不确定... //判断收货地,1是大陆,2是香港
purchases := common.Assert(price.Purchases, "int") if goodsMap.DeliveryType == 1 {
if goodsMap.Number <= purchases.(int) {
//判断是否有优惠价,有的话取优惠价 //判断是否有优惠价,有的话取优惠价
if price.PriceAc != nil { if price.PriceAc != 0 {
pac := common.Assert(price.PriceAc, "float") bomMatching.Price = price.PriceAc
bomMatching.Price = pac.(float64)
} else { } else {
if price.PriceCn != nil { bomMatching.Price = price.PriceCn
p := common.Assert(price.PriceCn, "float")
bomMatching.Price = p.(float64)
}
} }
break } else {
bomMatching.Price = price.PriceUs
} }
break
} }
} }
} }
......
...@@ -30,7 +30,7 @@ func MatchGoods(message model.BomMessage) (err error) { ...@@ -30,7 +30,7 @@ func MatchGoods(message model.BomMessage) (err error) {
return errors.New("没有商品的bom单") return errors.New("没有商品的bom单")
} }
bomItems := bom.BomItems bomItems := bom.BomItems
perGoDealNumber := 200 perGoDealNumber := 40
//开启协程处理搜索.每50个开启一个协程 //开启协程处理搜索.每50个开启一个协程
var wg sync.WaitGroup var wg sync.WaitGroup
//判断是否有余数 //判断是否有余数
...@@ -55,7 +55,7 @@ func MatchGoods(message model.BomMessage) (err error) { ...@@ -55,7 +55,7 @@ func MatchGoods(message model.BomMessage) (err error) {
if err := SearchGoods(bomId, bomData, message.DeliveryType, message.Sort, &wg); err != nil { if err := SearchGoods(bomId, bomData, message.DeliveryType, message.Sort, &wg); err != nil {
log.Error(err) log.Error(err)
} }
}() }()
} }
wg.Wait() wg.Wait()
//全部处理完以后要去修改主表的同步状态 //全部处理完以后要去修改主表的同步状态
...@@ -100,12 +100,12 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg ...@@ -100,12 +100,12 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
notMatchBomItems = append(notMatchBomItems, bomItem) notMatchBomItems = append(notMatchBomItems, bomItem)
} }
} }
err = UpdateGoodsData(append(goodsMapList, fuzzyGoodsMapList...)) //先去处理没有匹配到的数据
err = UpdateNoMatchBomItem(notMatchBomItems, false)
if err != nil { if err != nil {
return return
} }
//还要去处理没有匹配到的数据 err = UpdateGoodsData(append(goodsMapList, fuzzyGoodsMapList...))
err = UpdateNoMatchBomItem(notMatchBomItems)
if err != nil { if err != nil {
return return
} }
...@@ -114,7 +114,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg ...@@ -114,7 +114,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
//更新单个matching //更新单个matching
func UpdateSingleBomMatching(bomSn string, bomItemId int, goodsId string) (bomItemInfo model.BomItem, err error) { func UpdateSingleBomMatching(bomSn string, bomItemId int, goodsId string) (bomItemInfo model.BomItem, err error) {
responseData, err := GetGoodsInfo(goodsId) goodsList, err := GetGoodsInfo(goodsId)
if err != nil { if err != nil {
return return
} }
...@@ -122,8 +122,8 @@ func UpdateSingleBomMatching(bomSn string, bomItemId int, goodsId string) (bomIt ...@@ -122,8 +122,8 @@ func UpdateSingleBomMatching(bomSn string, bomItemId int, goodsId string) (bomIt
//先去获取对应的matching //先去获取对应的matching
bom := GetBomBySn(bomSn) bom := GetBomBySn(bomSn)
matching := GetBomMatching(bom.BomID, bomItemId) matching := GetBomMatching(bom.BomID, bomItemId)
if len(responseData.Data) > 0 { if len(goodsList) > 0 {
for _, goods := range responseData.Data { for _, goods := range goodsList {
var goodsMap GoodsMap var goodsMap GoodsMap
goodsMap.Number = matching.Number goodsMap.Number = matching.Number
goodsMap.GoodsName = matching.GoodsName goodsMap.GoodsName = matching.GoodsName
...@@ -175,6 +175,9 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType, sort ...@@ -175,6 +175,9 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType, sort
//如果是模糊查询,还要去截取字符串 //如果是模糊查询,还要去截取字符串
if !rawSearch { if !rawSearch {
bom.GoodsName = common.SubKeyWordStr(bom.GoodsName) bom.GoodsName = common.SubKeyWordStr(bom.GoodsName)
if bom.GoodsName == "" {
continue
}
} }
//构建一个goods_name对应的bomItems列表 //构建一个goods_name对应的bomItems列表
searchRequest := getSearchParams(bom.GoodsName, bom.BrandName, sort, bom.Number, rawSearch) searchRequest := getSearchParams(bom.GoodsName, bom.BrandName, sort, bom.Number, rawSearch)
...@@ -190,13 +193,16 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType, sort ...@@ -190,13 +193,16 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType, sort
//因为是多重查询,所以会有多套结果 //因为是多重查询,所以会有多套结果
for key, responses := range res.Responses { for key, responses := range res.Responses {
//有数据进行转换 //有数据进行转换
if responses.Hits.TotalHits > 0 { if responses.Hits != nil {
for _, hit := range responses.Hits.Hits { for _, hit := range responses.Hits.Hits {
var goods model.Goods var goods model.Goods
err := json.Unmarshal(*hit.Source, &goods) err := json.Unmarshal(*hit.Source, &goods)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if bomItems[key].GoodsName == "" {
break
}
var goodsMap GoodsMap var goodsMap GoodsMap
goodsMap.GoodsId = hit.Id goodsMap.GoodsId = hit.Id
goodsMap.Number = bomItems[key].Number goodsMap.Number = bomItems[key].Number
...@@ -230,12 +236,9 @@ func getSearchParams(goodsName, brandName string, sort, number int, flag bool) ( ...@@ -230,12 +236,9 @@ func getSearchParams(goodsName, brandName string, sort, number int, flag bool) (
//构建term条件 //构建term条件
func getTermQuery(goodsName, brandName string, number int, flag bool) (query *es.BoolQuery) { func getTermQuery(goodsName, brandName string, number int, flag bool) (query *es.BoolQuery) {
var (
field string
)
query = es.NewBoolQuery() query = es.NewBoolQuery()
if flag { if flag {
field = "auto_goods_name.raw" field := "auto_goods_name.raw"
replace, _ := regexp.Compile("[^A-Za-z0-9]+") replace, _ := regexp.Compile("[^A-Za-z0-9]+")
goodsName := replace.ReplaceAllString(goodsName, "") goodsName := replace.ReplaceAllString(goodsName, "")
goodsName = strings.ToUpper(goodsName) goodsName = strings.ToUpper(goodsName)
...@@ -249,7 +252,7 @@ func getTermQuery(goodsName, brandName string, number int, flag bool) (query *es ...@@ -249,7 +252,7 @@ func getTermQuery(goodsName, brandName string, number int, flag bool) (query *es
//搜索库存 //搜索库存
query = query.Should(es.NewConstantScoreQuery(es.NewRangeQuery("stock").Gte(number))) query = query.Should(es.NewConstantScoreQuery(es.NewRangeQuery("stock").Gte(number)))
} else { } else {
field = "auto_goods_name" field := "auto_goods_name"
query = query.Must(es.NewTermQuery(field, goodsName)) query = query.Must(es.NewTermQuery(field, goodsName))
} }
query = query.Filter(es.NewTermQuery("status", 1)) query = query.Filter(es.NewTermQuery("status", 1))
......
...@@ -45,30 +45,29 @@ type Data map[string]ApiGoods ...@@ -45,30 +45,29 @@ type Data map[string]ApiGoods
type DataTemp map[string]interface{} type DataTemp map[string]interface{}
type ApiGoods struct { type ApiGoods struct {
GoodsID interface{} `json:"goods_id"` GoodsID string `json:"goods_id"`
GoodsSn string `json:"goods_sn"` GoodsName string `json:"goods_name"`
//SpuID string `json:"spu_id"` GoodsType int `json:"goods_type"`
GoodsStatus int `json:"goods_status"` SupplierID int `json:"supplier_id"`
GoodsName string `json:"goods_name"` Moq int `json:"moq"`
GoodsType int `json:"goods_type"` Mpq int `json:"mpq"`
SupplierID int `json:"supplier_id"` Stock int `json:"stock"`
Moq int `json:"moq"` HkDeliveryTime string `json:"hk_delivery_time"`
Mpq int `json:"mpq"` CnDeliveryTime string `json:"cn_delivery_time"`
Stock int `json:"stock"` LadderPrice []LadderPrice `json:"ladder_price"`
HkDeliveryTime string `json:"hk_delivery_time"` BrandName string `json:"brand_name"`
CnDeliveryTime string `json:"cn_delivery_time"` SupplierName string `json:"supplier_name"`
LadderPrice []struct { BrandID int `json:"brand_id"`
Purchases interface{} `json:"purchases"` IsBuy int `json:"is_buy"`
PriceUs interface{} `json:"price_us"` Status int `json:"status"`
PriceCn interface{} `json:"price_cn"` Pdf string `json:"pdf"`
PriceAc interface{} `json:"price_ac"` Encap string `json:"encap"`
} `json:"ladder_price"`
BrandName string `json:"brand_name"`
SupplierName string `json:"supplier_name"`
BrandID interface{} `json:"brand_id"`
IsBuy int `json:"is_buy"`
Status int `json:"status"`
Pdf interface{} `json:"pdf"`
Encap string `json:"encap"`
//ErpTax bool `json:"erp_tax"` //ErpTax bool `json:"erp_tax"`
} }
type LadderPrice struct {
Purchases int `json:"purchases"`
PriceUs float64 `json:"price_us"`
PriceCn float64 `json:"price_cn"`
PriceAc float64 `json:"price_ac"`
}
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