Commit 99bc6df0 by huangchengyi

1.0

parent b937bb0f
...@@ -4,6 +4,8 @@ import ( ...@@ -4,6 +4,8 @@ import (
"flag" "flag"
"os" "os"
"search_server/boot" "search_server/boot"
"search_server/pkg/es"
"strings"
) )
func main() { func main() {
...@@ -32,16 +34,32 @@ func main() { ...@@ -32,16 +34,32 @@ func main() {
//os.Exit(1) //os.Exit(1)
//dd := service.OutLink("LM358","-1") //dd := service.OutLink("LM358","-1")
//lines := []string{ lines := []string{
// `{"index":{"_index":"hcy1","_type":"goods","_id":"s1"} }`, `{"index":{"_index":"hcy1","_type":"goods","_id":"s1"} }`,
// `{"name":"john doe","age":25 }`, `{"name":"john doe","age":25 }`,
// `{"index":{"_index":"hcy1","_type":"goods","_id":"s2"} }`, `{"index":{"_index":"hcy1","_type":"goods","_id":"s2"} }`,
// `{"name":"mary smith","age":32 }`, `{"name":"mary smith","age":32 }`,
}
param := strings.Join(lines, "\n")+"\n"
result,err := es.BulkES(param)
println(result,err)
//var skuEsUpdataList []string
//
//param := map[string]interface{}{
// "goods_status":1,
// "status":1,
// "encoded": "{'ddd'}",
//} //}
//param := strings.Join(lines, "\n")+"\n"
// //
//result,err := es.BulkES(param) //paramjson,_ := json.Marshal(param)
//println(result,err) //
//skuEsUpdataList = append(skuEsUpdataList,string(paramjson))
//skuEsUpdataList = append(skuEsUpdataList,string(paramjson))
//
//
//println(strings.Join(skuEsUpdataList,"\n"))
os.Exit(1) os.Exit(1)
} }
......
...@@ -11,10 +11,8 @@ import ( ...@@ -11,10 +11,8 @@ import (
func GetMouserData(c *gin.Context) { func GetMouserData(c *gin.Context) {
goodsName, _ := c.GetPostForm("goods_name") goodsName, _ := c.GetPostForm("goods_name")
lycon := new(service.CommonLyService) lycon := new(service.CommonLyService)
//调外链拿数据 //调外链拿数据
apiData := service.OutLink(&goodsName,"1") apiData := service.OutLink(&goodsName,"1")
//供应商详情 //供应商详情
supplierInfo := model.SUPPLIER_REDIS_INFO_{ supplierInfo := model.SUPPLIER_REDIS_INFO_{
SupplierId:14, SupplierId:14,
...@@ -30,5 +28,5 @@ func GetMouserData(c *gin.Context) { ...@@ -30,5 +28,5 @@ func GetMouserData(c *gin.Context) {
ErrMsg: "", ErrMsg: "",
Data: goods, Data: goods,
} }
c.JSON(200, res) c.JSON(200,res)
} }
...@@ -18,6 +18,7 @@ type LyClearGoodsList struct { ...@@ -18,6 +18,7 @@ type LyClearGoodsList struct {
Stock int64 `json:"increment"` //库存 Stock int64 `json:"increment"` //库存
Moq int64 `json:"moq"` //最小起订量、起订量 Moq int64 `json:"moq"` //最小起订量、起订量
Tiered []*TierItem //价格梯度数量 Tiered []*TierItem //价格梯度数量
PriceTemp []interface{} //拼接梯度,目前只有联营推送队列用
} }
type TierItem struct { type TierItem struct {
Purchases uint64 //购买数量 Purchases uint64 //购买数量
......
...@@ -63,7 +63,7 @@ func BulkES(param string) (result string, err error) { ...@@ -63,7 +63,7 @@ func BulkES(param string) (result string, err error) {
//req.Debug = true //req.Debug = true
header := make(http.Header) header := make(http.Header)
header.Set("Content-Type", "application/x-ndjson") header.Set("Content-Type", "application/x-ndjson")
resp, err := req.Post(esUrl+"/_bulk", header, param) resp, err := req.Post(esUrl+"/_bulk?refresh=true", header, param) //refresh=true 立刻插入或修改 立刻生效,不需要等待es缓存写入文档
if err != nil { if err != nil {
return return
} }
......
...@@ -4,11 +4,14 @@ package service ...@@ -4,11 +4,14 @@ package service
联营请求外链后 更新或者新增到平台 (es,redis,rabmq) 联营请求外链后 更新或者新增到平台 (es,redis,rabmq)
*/ */
import ( import (
"github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"search_server/middleware"
"search_server/model" "search_server/model"
"search_server/pkg/common" "search_server/pkg/common"
"search_server/pkg/config" "search_server/pkg/config"
"search_server/pkg/es"
"search_server/pkg/gredis" "search_server/pkg/gredis"
"search_server/pkg/mysql" "search_server/pkg/mysql"
"strconv" "strconv"
...@@ -22,12 +25,14 @@ type CommonLyService struct { ...@@ -22,12 +25,14 @@ type CommonLyService struct {
supplierId int64 //调用当前方法的供应商ID supplierId int64 //调用当前方法的供应商ID
supplierName string //调用当前方法的供应商名称 supplierName string //调用当前方法的供应商名称
skuEsUpdataList []string //组装批量更新es数据 skuEsUpdataList []string //组装批量更新es数据
flag string //调试开关
flagStr string //调试输出内容
ctx *gin.Context
} }
//初始化类 //初始化类
func (t *CommonLyService) LyServerRun(){ func (t *CommonLyService) LyServerRun(){
CommonLyService := new(CommonLyService) t.supplier_over_time = map[string]int64{
CommonLyService.supplier_over_time = map[string]int64{
"arrow":3600, "arrow":3600,
"verical":3600, "verical":3600,
"mouser":3600, "mouser":3600,
...@@ -35,7 +40,13 @@ func (t *CommonLyService) LyServerRun(){ ...@@ -35,7 +40,13 @@ func (t *CommonLyService) LyServerRun(){
"tme":3600, "tme":3600,
"buerklin":3600, "buerklin":3600,
} }
t.ctx = middleware.Context
t.ctx.MultipartForm()
for requestName, requstValue := range t.ctx.Request.Form {
if requestName == "flag" {
t.flag = strings.TrimSpace(requstValue[0])
}
}
} }
/* /*
...@@ -254,20 +265,48 @@ func (t * CommonLyService) EsSkuInfo(skuInfo *model.LyClearGoodsList,spuId * str ...@@ -254,20 +265,48 @@ func (t * CommonLyService) EsSkuInfo(skuInfo *model.LyClearGoodsList,spuId * str
} }
paramjson,_ := json.Marshal(param) paramjson,_ := json.Marshal(param)
_ = append(t.skuEsUpdataList,`{"index":{"_index":"`+t.supplierName+`","_type":"goods","_id":"`+skuInfo.GoodsId+`"}}`) t.skuEsUpdataList = append(t.skuEsUpdataList,`{"index":{"_index":"`+t.supplierName+`","_type":"goods","_id":"`+skuInfo.GoodsId+`"}}`)
_ = append(t.skuEsUpdataList,string(paramjson)) t.skuEsUpdataList = append(t.skuEsUpdataList,string(paramjson))
} }
/* /*
推入队列 推入队列=》(斌 go队列去消费更新db+mongodb..等操作)
*/ */
func toGoRabmq() { func (t * CommonLyService) updateSkuDB(skuInfo *model.LyClearGoodsList) {
if skuInfo.GoodsId == "" {
return
}
param := map[string]interface{}{
"pn":t.supplierName,
"stock":skuInfo.Stock,
"tiered":skuInfo.PriceTemp,
"increment":skuInfo.Increment,
"sku_id":skuInfo.GoodsId,
"brand_name":skuInfo.BrandName,
"goods_name":skuInfo.GoodsName,
"goods_sn":skuInfo.GoodsSn,
}
} }
/* /*
更新es 批量插入或者更新es
*/ */
func toEs() { func (t *CommonLyService) pushEs() {
if len(t.skuEsUpdataList) == 0 {
if t.flag == "101" {
t.flagStr += "<br/>没有可插入es的数据"
}
return
}
param := strings.Join(t.skuEsUpdataList, "\n")+"\n"
result,_ := es.BulkES(param) //批量插入
if t.flag == "101" {
t.flagStr += "<br/>"
t.flagStr += "插入es:"
t.flagStr += param
t.flagStr += result
}
} }
...@@ -34,6 +34,7 @@ func OutLink(goodsName *string,flag string) map[string]*model.LyClearGoodsList { ...@@ -34,6 +34,7 @@ func OutLink(goodsName *string,flag string) map[string]*model.LyClearGoodsList {
goodsSn := goods.Get("MouserPartNumber").String() goodsSn := goods.Get("MouserPartNumber").String()
ladderPrice := make([]*model.TierItem, 0) ladderPrice := make([]*model.TierItem, 0)
priceTemp := make([]interface{}, 0)
//拼接价格梯度 //拼接价格梯度
apiPriceTi := goods.Get("PriceBreaks").Array() apiPriceTi := goods.Get("PriceBreaks").Array()
var apiLowerPrice float64 = 0; //计算最低价格 var apiLowerPrice float64 = 0; //计算最低价格
...@@ -51,6 +52,10 @@ func OutLink(goodsName *string,flag string) map[string]*model.LyClearGoodsList { ...@@ -51,6 +52,10 @@ func OutLink(goodsName *string,flag string) map[string]*model.LyClearGoodsList {
PriceCn: 0, PriceCn: 0,
} }
ladderPrice = append(ladderPrice, &ladder) ladderPrice = append(ladderPrice, &ladder)
//梯度缓存数据
priceTemp = append(priceTemp,gjson.Get(priceItemStr, "Quantity").Uint())
priceTemp = append(priceTemp,gjson.Get(priceItemStr, "Price").Float())
} }
//拼接联营数据 //拼接联营数据
...@@ -67,6 +72,7 @@ func OutLink(goodsName *string,flag string) map[string]*model.LyClearGoodsList { ...@@ -67,6 +72,7 @@ func OutLink(goodsName *string,flag string) map[string]*model.LyClearGoodsList {
RestrictionMessage: goods.Get("RestrictionMessage").String(), RestrictionMessage: goods.Get("RestrictionMessage").String(),
SinglePrice: apiLowerPrice, SinglePrice: apiLowerPrice,
Tiered:ladderPrice, Tiered:ladderPrice,
PriceTemp: priceTemp,
} }
productList[goodsSn] = &LyClearGoodsList productList[goodsSn] = &LyClearGoodsList
......
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