分类

parent e81fc24f
;存放es配置
[es]
url_es8 = http://192.168.1.234:9201
url = http://192.168.1.237:9200
urls = http://192.168.1.237:9200,http://192.168.1.237:9200
index_name = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,zhuanmai,peigenesis,powell,rs,buerklin,liexin_ziying
......
......@@ -2,37 +2,19 @@ package main
import (
"fmt"
"encoding/json"
"search_server/model"
"strings"
"github.com/tidwall/gjson"
)
func main() {
jsonContent := `{"spu_id":2170358070290851004,"old_goods_id":17003294699,"update_time":1703580702,"cp_time":0,"goods_status":1,"goods_type":1,"supplier_id":5,"goods_name":"NFM21HC105R1C3D","encoded":"","batch_sn":"2310","moq":232,"mpq":1,"stock":3562,"hk_delivery_time":"","cn_delivery_time":"","ladder_price":[{"purchases":232,"price_cn":0,"price_us":0.1377,"cost_price":0},{"purchases":500,"price_cn":0,"price_us":0.1211,"cost_price":0},{"purchases":1000,"price_cn":0,"price_us":0.0961,"cost_price":0},{"purchases":2000,"price_cn":0,"price_us":0.0924,"cost_price":0}],"goods_images":"","canal":"","eccn":"EAR99","multiple":0,"source":2}`
spu_id := gjson.Get(jsonContent,"spu_id").String()
var LyClearGoodsList model.LyClearGoodsList
LyClearGoodsList.GoodsName = "LM358"
fmt.Println(spu_id)
fmt.Println("ddddddddd")
ladderPrice := make([]*model.TierItem, 0)
ladder := model.TierItem{
Purchases: 1,
PriceUs: 0.44,
PriceCn: 1.55,
}
ladderPrice = append(ladderPrice, &ladder)
LyClearGoodsList.Tiered = ladderPrice
jsonContent = strings.Replace(jsonContent, spu_id, "\""+spu_id+"\"", 1)
var productList map[string]*model.LyClearGoodsList
productList = make(map[string]*model.LyClearGoodsList,0)
productList["595-LM358BIDR"] = &LyClearGoodsList
fmt.Println(jsonContent)
//map的遍历
for k, v := range productList{
fmt.Println(k,v)
}
jsonStr, err := json.Marshal(productList)
if err!=nil{
return
}
fmt.Printf("%s\n",jsonStr)
}
\ No newline at end of file
......@@ -20,6 +20,20 @@ type HitsResult struct {
Hits string `json:"hits"`
}
//新版es8 请求
func CurlESNew(index string, param string) (result string, err error) {
endpoints := config.Get("es.url_es8").Strings(",")
//随机获取一个节点进行请求
esUrl := endpoints[rand.Intn(len(endpoints))]
params := req.BodyJSON(param)
resp, err := req.Get(esUrl+"/"+index+"/_search", params)
if err != nil {
return
}
result = resp.String()
return
}
func CurlES(index string, param string) (result string, err error) {
endpoints := config.Get("es.urls").Strings(",")
//随机获取一个节点进行请求
......
......@@ -156,8 +156,8 @@ func CurlGoodsInfo(ctx *gin.Context, goodsIdsStr string, params req.Param) (good
goods.ScmBrandName = data.Get("scm_brand_name").String()
goods.AllowCoupon = int(data.Get("allow_coupon").Int())
goods.UpdateTime = int(data.Get("update_time").Int())
goods.ClassId1Name = data.Get("class_id1_name").String()
goods.CLassId2Name = data.Get("c_lass_id2_name").String()
goods.ClassId1Name = data.Get("class_name1").String()
goods.CLassId2Name = data.Get("class_name2").String()
goods.SpuId = data.Get("spu_id").String()
goods.BatchSn = data.Get("batch_sn").String()
goods.Canal = data.Get("canal").String()
......
......@@ -87,7 +87,7 @@ func (qs *OptimumService) GetOptimumAttr(ctx *gin.Context) (results model.LyResp
return
}
//查询es
esResult, err := es.CurlES("goods_optimum", queryString)
esResult, err := es.CurlESNew("goods_optimum", queryString)
if err != nil {
results.ErrorCode = 1002
results.ErrorMsg = err.Error()
......@@ -194,7 +194,7 @@ func (qs *OptimumService) GetOptimumAttrInfo(ctx *gin.Context) (results model.Ly
results.ErrorMsg = err.Error()
return
}
esResult, err := es.CurlES("goods_optimum", queryString)
esResult, err := es.CurlESNew("goods_optimum", queryString)
if err != nil {
results.ErrorCode = 0
results.ErrorMsg = "查询es没有数据"
......@@ -219,7 +219,7 @@ func (qs *OptimumService) GetOptimumAttrInfo(ctx *gin.Context) (results model.Ly
}
//判断返回总条数
total := gjson.Get(esResult, "hits.total").Int()
total := gjson.Get(esResult, "hits.total.value").Int()
if total == 0 {
results.ErrorCode = 0
results.ErrorMsg = "查询没有数据"
......
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