修复状态问题

parent 1bf9ad55
...@@ -131,8 +131,7 @@ func GetGoodsInfo(goodsIdsStr string) (goodsList []model.ApiGoods, err error) { ...@@ -131,8 +131,7 @@ func GetGoodsInfo(goodsIdsStr string) (goodsList []model.ApiGoods, err error) {
goods.Mpl = int(data.Get("mpl").Int()) goods.Mpl = int(data.Get("mpl").Int())
goods.Encap = data.Get("encap").String() goods.Encap = data.Get("encap").String()
goods.SupplierID = int(data.Get("supplier_id").Int()) goods.SupplierID = int(data.Get("supplier_id").Int())
//goods.Status = int(data.Get("status").Int()) goods.Status = int(data.Get("status").Int())
goods.Status = 1
goods.GoodsType = int(data.Get("goods_type").Int()) goods.GoodsType = int(data.Get("goods_type").Int())
goods.AcType = int(data.Get("ac_type").Int()) goods.AcType = int(data.Get("ac_type").Int())
var ladderPrice []model.LadderPrice var ladderPrice []model.LadderPrice
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"bom_server/internal/model" "bom_server/internal/model"
"context" "context"
"encoding/json" "encoding/json"
"github.com/tidwall/gjson"
es "gopkg.in/olivere/elastic.v5" es "gopkg.in/olivere/elastic.v5"
"strings" "strings"
) )
...@@ -50,39 +51,65 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor ...@@ -50,39 +51,65 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
common.PrintDebug(res.Responses) common.PrintDebug(res.Responses)
v, err := json.Marshal(res.Responses)
gjArray := gjson.Get(string(v), "hits.hits.#._source").Array()
if err != nil { if err != nil {
return return
} }
if len(res.Responses) == 0 { if len(res.Responses) == 0 {
return return
} }
//因为是多重查询,所以会有多套结果
for key, responses := range res.Responses { for key, item := range gjArray {
//有数据进行转换
if responses.Hits != nil { if item.Get("goods_name").String() == "" {
for _, hit := range responses.Hits.Hits { break
var goods model.Goods
err := json.Unmarshal(*hit.Source, &goods)
if err != nil {
return nil, err
}
if goods.GoodsName == "" {
break
}
var goodsMap GoodsMap
goodsMap.GoodsId = hit.Id
goodsMap.Amount = bomItems[key].Amount
goodsMap.Number = bomItems[key].Number
goodsMap.GoodsName = bomItems[key].GoodsName
goodsMap.BomItemId = bomItems[key].BomItemID
goodsMap.BomId = bomId
goodsMap.DeliveryType = deliveryType
goodsMapList = append(goodsMapList, goodsMap)
break
}
} }
var goodsMap GoodsMap
goodsMap.GoodsId = item.Get("goods_id").String()
goodsMap.Amount = bomItems[key].Amount
goodsMap.Number = bomItems[key].Number
goodsMap.GoodsName = bomItems[key].GoodsName
goodsMap.BomItemId = bomItems[key].BomItemID
goodsMap.BomId = bomId
goodsMap.DeliveryType = deliveryType
goodsMapList = append(goodsMapList, goodsMap)
common.PrintDebug(goodsMap)
break
} }
////因为是多重查询,所以会有多套结果
//for key, responses := range res.Responses {
// //有数据进行转换
// if responses.Hits != nil {
// for _, hit := range responses.Hits.Hits {
// //var goods model.Goods
// err := json.Unmarshal(*hit.Source, &goods)
// if err != nil {
// return nil, err
// }
// source := *hit.Source
// goodsNameObj := gjson.Get(source, "hit.Source.GoodsName")
// if goodsNameObj.String() == "" {
// break
// }
// var goodsMap GoodsMap
// goodsMap.GoodsId = hit.Id
// goodsMap.Amount = bomItems[key].Amount
// goodsMap.Number = bomItems[key].Number
// goodsMap.GoodsName = bomItems[key].GoodsName
// goodsMap.BomItemId = bomItems[key].BomItemID
// goodsMap.BomId = bomId
// goodsMap.DeliveryType = deliveryType
// goodsMapList = append(goodsMapList, goodsMap)
// break
// }
// }
//}
common.PrintDebug("search end") common.PrintDebug("search end")
return 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