Commit ca209b30 by mushishixian

修复价格排序

parent b4392473
...@@ -22,7 +22,7 @@ func init() { ...@@ -22,7 +22,7 @@ func init() {
// "amqp://huntadmin:jy2y2900@192.168.1.237:5672/", // "amqp://huntadmin:jy2y2900@192.168.1.237:5672/",
//} //}
// //
//str := `{"bom_id":48,"delivery_type":1,"sort":1}` //str := `{"bom_id":236,"delivery_type":1,"sort":3}`
//rabbitmq.Send(queueExchange, str) //rabbitmq.Send(queueExchange, str)
} }
......
...@@ -30,6 +30,9 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) { ...@@ -30,6 +30,9 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
} }
goodsIdsStr := strings.Join(goodsIds, ",") goodsIdsStr := strings.Join(goodsIds, ",")
goodsList, err := GetGoodsInfo(goodsIdsStr) goodsList, err := GetGoodsInfo(goodsIdsStr)
if len(goodsMapList)!=0 {
bomId = goodsMapList[0].BomId
}
//fmt.Println(goodsIdsStr) //fmt.Println(goodsIdsStr)
if err != nil { if err != nil {
return return
...@@ -123,31 +126,6 @@ func GetGoodsInfo(goodsIdsStr string) (goodsList []model.ApiGoods, err error) { ...@@ -123,31 +126,6 @@ func GetGoodsInfo(goodsIdsStr string) (goodsList []model.ApiGoods, err error) {
} }
} }
} }
//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
} }
......
...@@ -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
//判断是否有余数 //判断是否有余数
...@@ -222,15 +222,23 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType, sort ...@@ -222,15 +222,23 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType, sort
//构建请求参数 //构建请求参数
func getSearchParams(goodsName, brandName string, sort, number int, flag bool) (searchRequest *es.SearchRequest) { func getSearchParams(goodsName, brandName string, sort, number int, flag bool) (searchRequest *es.SearchRequest) {
query := getTermQuery(goodsName, brandName, number, flag) query := getTermQuery(goodsName, brandName, number, flag)
source := es.NewSearchSource().IndexBoost("liexin_ziying", 2).Query(query). source := es.NewSearchSource().IndexBoost("liexin_ziying", 2).Query(query)
Sort("_score", false).Sort("sort", false).From(0).Size(1) if sort == 1 {
source.Sort("sort", false)
source.Sort("_score", false)
source.Sort("stock", false)
source.Sort("single_price", true)
}
//要去判断sort,sort=2是按照价格排序 //要去判断sort,sort=2是按照价格排序
if sort == 2 { if sort == 2 {
source.Sort("single_price_sort", false)
source.Sort("single_price", true) source.Sort("single_price", true)
//sort=3是按照库存排序 //sort=3是按照库存排序
} else if sort == 3 { } else if sort == 3 {
source.Sort("stock_sort", false)
source.Sort("stock", false) source.Sort("stock", false)
} }
source = source.From(0).Size(1)
searchRequest = es.NewSearchRequest().Source(source) searchRequest = es.NewSearchRequest().Source(source)
return searchRequest return searchRequest
} }
......
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