Commit e9e31500 by huangchengyi

1.0

parent 7033d5ca
......@@ -37,9 +37,9 @@ func GetDataIndex(c *gin.Context) {
return
}
common.PrintDebugHeader(c,&r.Flag)
common.PrintDebugHtml(c,&r.Flag,r.SupplierId)
common.PrintDebugHtml(c,&r.Flag,r.Keyword)
common.PrintDebugHeader()
common.PrintDebugHtml(r.SupplierId)
common.PrintDebugHtml(r.Keyword)
if r.SupplierId != "" && r.IsSort == 2 {
//所有供应商列表
......
......@@ -12,9 +12,8 @@ import (
func GetMouserData(c *gin.Context) {
goodsName := middleware.REQUEST["goods_name"]
flag := middleware.REQUEST["flag"]
common.PrintDebugHeader(c,&flag)
common.PrintDebugHeader() //debug
if goodsName == "" {
c.JSON(200,"goods_name不得为空")
......
......@@ -6,7 +6,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/syyongx/php2go"
"math/big"
"math/rand"
......@@ -24,30 +23,27 @@ import (
/*
输出header
*/
func PrintDebugHeader(ctx *gin.Context,flag *string) {
if *flag == "101" {
ctx.Header("Content-Type", "text/html; charset=utf-8")
func PrintDebugHeader() {
if middleware.REQUEST["flag"] == "101" {
middleware.Context.Header("Content-Type", "text/html; charset=utf-8")
}
}
/*
格式化数据直接输出浏览器
@parm ctx gin上下文
@parm flag 是否调试标志
@parm data 打印调试内容
@parm jsondata 需要json输出的内容
@parm jsonStr 需要json输出的内容
*/
func PrintDebugHtml(ctx *gin.Context,flag *string,jsonStr interface{}) {
if *flag != "101" || jsonStr == "" {
func PrintDebugHtml(jsonStr interface{}) {
if middleware.REQUEST["flag"] != "101" || jsonStr == "" {
return
}
if v, p := jsonStr.(string); p {
ctx.String(200,"</br></br>-----------"+v)
middleware.Context.String(200,"</br></br>-----------"+v)
}else{
jsonData,err := json.Marshal(jsonStr)
if err != nil {
fmt.Println("错误:-----",err)
}
ctx.String(200,"</br></br>-----------"+string(jsonData))
middleware.Context.String(200,"</br></br>-----------"+string(jsonData))
}
}
......
......@@ -6,11 +6,9 @@ package ly
import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"search_server/middleware"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/config"
......@@ -28,9 +26,6 @@ type CommonLyService struct {
supplierId int64 //调用当前方法的供应商ID
supplierName string //调用当前方法的供应商名称
skuEsUpdataList []string //组装批量更新es数据
flag string //调试开关
flagStr string //调试输出内容
ctx *gin.Context
}
//初始化类
......@@ -43,13 +38,6 @@ func (t *CommonLyService) LyServerRun(){
"tme":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])
}
}
}
......@@ -63,7 +51,7 @@ func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoo
t.LyServerRun(); //初始化变量
if len(goodsList) == 0 {
common.PrintDebugHtml(t.ctx,&t.flag,"没有数据")
common.PrintDebugHtml("没有数据")
return true
}
......@@ -76,17 +64,17 @@ func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoo
t.supplierName = supplierInfo.SupplierNickname
_,haveLimitTime := t.supplier_over_time[supplierInfo.SupplierNickname] //获取当前供应商更新周期
common.PrintDebugHtml(t.ctx,&t.flag,goodsList)
common.PrintDebugHtml(goodsList)
for goodsSn, info := range goodsList {
common.PrintDebugHtml(t.ctx,&t.flag,goodsSn+"_"+supplierIdStr)
common.PrintDebugHtml(goodsSn+"_"+supplierIdStr)
snSku := php2go.Md5(strings.ToLower(goodsSn+"_"+supplierIdStr))
skuId,_ := gredis.String(redisWrite.Do("HGET",config.Get("redis_all.SKU_UNIQUE_JUDGE").String(),snSku)) //查询唯一值,反查sku_id
common.PrintDebugHtml(t.ctx,&t.flag,"算法goodsSn:"+goodsSn+"_"+supplierIdStr+" :md5("+strings.ToLower(goodsSn+"_"+supplierIdStr)+") = snSku:"+snSku+" 查询 sku_unique_judge 得出skuid: "+skuId)
common.PrintDebugHtml("算法goodsSn:"+goodsSn+"_"+supplierIdStr+" :md5("+strings.ToLower(goodsSn+"_"+supplierIdStr)+") = snSku:"+snSku+" 查询 sku_unique_judge 得出skuid: "+skuId)
/**********新增sku**************/
skuFlag := false; //是否新增或者更新db+redis,为true则新增
......@@ -95,18 +83,18 @@ func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoo
lock_key := "searchapi_"+snSku;
flag,_ := redis.Bool(redisWrite.Do("SETNX", lock_key,php2go.Time()+2))
if !flag { //防止并发
common.PrintDebugHtml(t.ctx,&t.flag,"并发新增")
common.PrintDebugHtml("并发新增")
continue;
}
//新增操作
skuFlag = true //新增标志
redisWrite.Do("EXP",lock_key,2) //给锁有效时间2秒
common.PrintDebugHtml(t.ctx,&t.flag,"新增sku开始------------")
common.PrintDebugHtml("新增sku开始------------")
skuId = t.writeSkuInfo(info,"") //新增redis+sku+spu+brand
common.PrintDebugHtml(t.ctx,&t.flag,"新增sku结束------------")
common.PrintDebugHtml("新增sku结束------------")
redisWrite.Do("del",lock_key) //删除锁
}
......@@ -115,13 +103,13 @@ func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoo
//获取sku存在redis的详情
redisData,_ := redis.String(redisWrite.Do("HGET",config.Get("redis_all.SKU").String(),skuId))
if redisData == "" {
common.PrintDebugHtml(t.ctx,&t.flag,"此sku不存在redis:" + skuId)
common.PrintDebugHtml("此sku不存在redis:" + skuId)
logger.Log("此sku不存在redis:" + skuId,"redis_get_sku_error")
continue;
}
redisArr, ok := gjson.Parse(redisData).Value().(map[string]interface{}) //redis取值转成map
if !ok {
common.PrintDebugHtml(t.ctx,&t.flag,"此sku不是正确json格式" + redisData)
common.PrintDebugHtml("此sku不是正确json格式" + redisData)
logger.Log("此sku不是正确json格式" + redisData,"redis_get_sku_error")
continue;
}
......@@ -173,8 +161,8 @@ func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoo
redisWrite.Do("HSET",config.Get("redis_all.SKU_RAW_MAP").String(),skuMapJson)
}
common.PrintDebugHtml(t.ctx,&t.flag,"更新sku:" )
common.PrintDebugHtml(t.ctx,&t.flag,redisArr)
common.PrintDebugHtml("更新sku:" )
common.PrintDebugHtml(redisArr)
//更新db
t.updateSkuDB(info)
//更新es
......@@ -197,8 +185,8 @@ func (t *CommonLyService) writeSkuInfo(skuInfo *model.LyClearGoodsList,skuId str
spuKey := common.GetKey(skuInfo.GoodsName+"_"+skuInfo.BrandName)
spuId,_ := gredis.String(redisWrite.Do("HGET",config.Get("redis_all.SKU_UNIQUE_JUDGE").String(),spuKey))
common.PrintDebugHtml(t.ctx,&t.flag,spuKey)
common.PrintDebugHtml(t.ctx,&t.flag,spuId)
common.PrintDebugHtml(spuKey)
common.PrintDebugHtml(spuId)
if spuId == "" { //不存在spu,创建新的spu
spuId = t.writeSpuInfo(skuInfo)
......@@ -206,7 +194,7 @@ func (t *CommonLyService) writeSkuInfo(skuInfo *model.LyClearGoodsList,skuId str
if skuId == "" {
skuId = common.CreateId("sku");
common.PrintDebugHtml(t.ctx,&t.flag,"新增sku:"+skuId)
common.PrintDebugHtml("新增sku:"+skuId)
}
inSkuInfo := model.LySkuInfo{
......@@ -231,16 +219,16 @@ func (t *CommonLyService) writeSkuInfo(skuInfo *model.LyClearGoodsList,skuId str
jsonStr, _ := json.Marshal(inSkuInfo)
redisWrite.Do("HSET",config.Get("redis_all.SKU").String(),skuId,string(jsonStr))
common.PrintDebugHtml(t.ctx,&t.flag,"更新redis_sku:")
common.PrintDebugHtml(t.ctx,&t.flag,inSkuInfo)
common.PrintDebugHtml("更新redis_sku:")
common.PrintDebugHtml(inSkuInfo)
skuKey := common.GetKey(skuInfo.GoodsSn+"_"+strconv.FormatInt(t.supplierId,10))
redisWrite.Do("HSET",config.Get("redis_all.SKU_UNIQUE_JUDGE").String(),skuKey,skuId)
//todo 如果是digikey新增,需要插入原始映射表
if t.supplierId == 7 {
common.PrintDebugHtml(t.ctx,&t.flag,"sku_raw_map:")
common.PrintDebugHtml(t.ctx,&t.flag,jsonStr)
common.PrintDebugHtml("sku_raw_map:")
common.PrintDebugHtml(jsonStr)
redisWrite.Do("HSET",config.Get("redis_all.SKU_RAW_MAP").String(),skuKey,skuId)
}
return skuId
......@@ -280,8 +268,8 @@ func (t *CommonLyService) writeSpuInfo(skuInfo *model.LyClearGoodsList) string {
jsonStr, _ := json.Marshal(Spuinfo)
redisWrite.Do("HSET","spu",spuId,jsonStr)
common.PrintDebugHtml(t.ctx,&t.flag,"新增spu:")
common.PrintDebugHtml(t.ctx,&t.flag,jsonStr)
common.PrintDebugHtml("新增spu:")
common.PrintDebugHtml(jsonStr)
spuKey := common.GetKey(skuInfo.GoodsName+"_"+skuInfo.BrandName)
redisWrite.Do("HSET",config.Get("redis_all.SPU_UNIQUE_JUDGE").String(),spuKey,spuId)
......@@ -316,8 +304,8 @@ func (t *CommonLyService) writeBrandInfo(skuInfo *model.LyClearGoodsList) int64
}
brandId,_ = results.LastInsertId()
common.PrintDebugHtml(t.ctx,&t.flag,"创建品牌:")
common.PrintDebugHtml(t.ctx,&t.flag,brandId)
common.PrintDebugHtml("创建品牌:")
common.PrintDebugHtml(brandId)
}
//更新redis 品牌数据
redisWrite.Do("HSET",config.Get("redis_all.BRAND_NAME_ALL").String(),brandkey,brandId)
......@@ -402,8 +390,8 @@ func (t * CommonLyService) updateSkuDB(skuInfo *model.LyClearGoodsList) {
}
paramjson,_ := json.Marshal(param)
common.PrintDebugHtml(t.ctx,&t.flag,"推送到go更新db--search_sku_update_list:")
common.PrintDebugHtml(t.ctx,&t.flag,string(paramjson))
common.PrintDebugHtml("推送到go更新db--search_sku_update_list:")
common.PrintDebugHtml(string(paramjson))
mq.PushMsg(config.Get("rabmq_all.SEARCH_SKU_UPDATE_LIST").String(),string(paramjson))
}
......@@ -413,17 +401,15 @@ func (t * CommonLyService) updateSkuDB(skuInfo *model.LyClearGoodsList) {
*/
func (t *CommonLyService) pushEs() {
if len(t.skuEsUpdataList) == 0 {
if t.flag == "101" {
t.flagStr += "<br/>没有可插入es的数据"
}
common.PrintDebugHtml("没有可插入es的数据")
return
}
param := strings.Join(t.skuEsUpdataList, "\n")+"\n"
result,_ := es.BulkES(param) //批量插入
common.PrintDebugHtml(t.ctx,&t.flag,"插入或更新es:")
common.PrintDebugHtml(t.ctx,&t.flag,"请求参数:"+param)
common.PrintDebugHtml(t.ctx,&t.flag,"返回结果:"+result)
common.PrintDebugHtml("插入或更新es:")
common.PrintDebugHtml("请求参数:"+param)
common.PrintDebugHtml("返回结果:"+result)
}
/*
新增sku,组装好数据推送到db(斌哥队列消费后 更新 mongodb+mysql 等)
......@@ -456,8 +442,8 @@ func (t * CommonLyService) createSkuDB(skuInfo *model.LyClearGoodsList) {
paramStr := string(paramjson)
common.PrintDebugHtml(t.ctx,&t.flag,"推送到go新增db:")
common.PrintDebugHtml(t.ctx,&t.flag,"请求参数:"+paramStr)
common.PrintDebugHtml("推送到go新增db:")
common.PrintDebugHtml("请求参数:"+paramStr)
mq.PushMsg(config.Get("rabmq_all.SEARCH_SKU_LIST").String(),paramStr) //推送队列
//记录日志
......
......@@ -19,7 +19,6 @@ func OutLinkMouser(goodsName *string) map[string]*model.LyClearGoodsList {
return nil
}
var result string;
var flag = middleware.REQUEST["flag"]
if middleware.REQUEST["flags"] == "-1" { //原始数据调试
result = `{"Errors":[],"SearchResults":{"NumberOfResult":80,"Parts":[{"Availability":"15242 有庫存","DataSheetUrl":"","Description":"運算放大器 - 運放器 1.2 MHz industry standard dual-channel amplifier with -40C to 85C operation 8-SOIC -40 to 85","FactoryStock":"0","ImagePath":"https://www.mouser.com/images/texasinstruments/images/ITP_TI_SOIC-8_D_t.jpg","Category":"運算放大器 - 運放器","LeadTime":"42 日數","LifecycleStatus":"New Product","Manufacturer":"Texas Instruments","ManufacturerPartNumber":"LM358BIDR","Min":"1","Mult":"1","MouserPartNumber":"595-LM358BIDR","ProductAttributes":[{"AttributeName":"封裝","AttributeValue":"Cut Tape"},{"AttributeName":"封裝","AttributeValue":"MouseReel"},{"AttributeName":"封裝","AttributeValue":"Reel"},{"AttributeName":"標準包裝數量","AttributeValue":"2500"}],"PriceBreaks":[{"Quantity":1,"Price":"$0.44","Currency":"USD"},{"Quantity":10,"Price":"$0.287","Currency":"USD"},{"Quantity":100,"Price":"$0.154","Currency":"USD"}],"AlternatePackagings":null,"ProductDetailUrl":"https://www.mouser.hk/ProductDetail/Texas-Instruments/LM358BIDR?qs=byeeYqUIh0MUqg09TCRNgA%3D%3D","Reeling":true,"ROHSStatus":"RoHS Compliant","SuggestedReplacement":"","MultiSimBlue":0,"ProductCompliance":[{"ComplianceName":"CNHTS","ComplianceValue":"8542339000"},{"ComplianceName":"USHTS","ComplianceValue":"8542330001"},{"ComplianceName":"TARIC","ComplianceValue":"8542330000"},{"ComplianceName":"ECCN","ComplianceValue":"EAR99"}]}]}}`;
......@@ -31,7 +30,7 @@ func OutLinkMouser(goodsName *string) map[string]*model.LyClearGoodsList {
print(err)
}
result = resp.String(); //请求外链拿到结果
common.PrintDebugHtml(middleware.Context,&flag,result)
common.PrintDebugHtml(result)
}
productList := make(map[string]*model.LyClearGoodsList,0)
......
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