spu分离

parent d66e63ff
[web]
port = 9008
mode = debug
cors_domain = http://bom.liexin.com,http://liexin.com,http://www.liexin.com
cors_domain = http://bom.liexin.com,http://liexin.com,http://www.liexin.com,http://localhost:8080,http://localhost
[message]
api_domain = http://api.ichunt.com/msg/sendMessageByAuto
......
......@@ -13,6 +13,14 @@ max_idle = 500
max_active = 500
idle_timeout = 20
;新spu redis
[default_redis_spu]
host = 192.168.1.234:6379
password = icDb29mLy2s
max_idle = 2000
max_active = 5000
idle_timeout = 20
[api_redis]
host = 192.168.1.235:6379
password = icDb29mLy2s
......
......@@ -67,7 +67,11 @@ func QuoteIndex(ctx *gin.Context) {
func mouserOrg(ctx *gin.Context,keyword, suppliedId string) (result map[string]interface{}, err error) {
mouserRes := ly.OutLinkMouser(ctx,&keyword)
redisCon := gredis.Conn("search_r")
defer redisCon.Close()
redisConSpu := gredis.Conn("spu")
defer func() {
redisCon.Close()
redisConSpu.Close()
}()
skuMouser := make(map[string]string)
var goodsIds []string
for k, mouseItem := range mouserRes {
......@@ -75,7 +79,7 @@ func mouserOrg(ctx *gin.Context,keyword, suppliedId string) (result map[string]i
continue
}
snSku := php2go.Md5(strings.ToLower(k + "_" + suppliedId))
skuId, _ := redis.String(redisCon.Do("HGET", config.Get("SKU_UNIQUE_JUDGE").String(), snSku))
skuId, _ := redis.String(redisConSpu.Do("HGET", config.Get("SKU_UNIQUE_JUDGE").String(), snSku))
if skuId != "" {
skuMouser[skuId] = mouseItem.RestrictionMessage
goodsIds = append(goodsIds, skuId)
......
......@@ -16,6 +16,8 @@ func BuildRedisConfgs() (RedisDatabaseMap map[string]RedisDatabase) {
redis_read_max_active,_ := Get("default_redis_read.max_active").Int()
redis_write_max_idle,_ := Get("default_redis_write.max_idle").Int()
redis_write_max_active,_ := Get("default_redis_write.max_active").Int()
redisSpuMaxIdle,_ := Get("default_redis_spu.max_idle").Int()
redisSpuMaxActive,_ := Get("default_redis_spu.max_active").Int()
return map[string]RedisDatabase{
"search_r": {
Host: Get("default_redis_read.host").String(),
......@@ -35,5 +37,11 @@ func BuildRedisConfgs() (RedisDatabaseMap map[string]RedisDatabase) {
MaxIdle: redis_write_max_idle,
MaxActive: redis_write_max_active,
},
"spu": {
Host: Get("default_redis_spu.host").String(),
Password: Get("default_redis_spu.password").String(),
MaxIdle: redisSpuMaxIdle,
MaxActive: redisSpuMaxActive,
},
}
}
......@@ -57,7 +57,11 @@ func (t *CommonLyService) GetSkuByGoodsSn(ctx *gin.Context,goodsList map[string]
}
redisWrite := gredis.Conn("search_w")
defer redisWrite.Close()
redisSpu := gredis.Conn("spu")
defer func() {
redisWrite.Close()
redisSpu.Close()
}()
t.supplierId = supplierInfo.SupplierId
supplierIdStr := common.MyInt64ToStr(supplierInfo.SupplierId);
......@@ -74,7 +78,7 @@ func (t *CommonLyService) GetSkuByGoodsSn(ctx *gin.Context,goodsList map[string]
}
snSku := php2go.Md5(strings.ToLower(goodsSn+"_"+supplierIdStr))
skuId,_ := gredis.String(redisWrite.Do("HGET",config.Get("redis_all.SKU_UNIQUE_JUDGE").String(),snSku)) //查询唯一值,反查sku_id
skuId,_ := gredis.String(redisSpu.Do("HGET",config.Get("redis_all.SKU_UNIQUE_JUDGE").String(),snSku)) //查询唯一值,反查sku_id
common.PrintDebugHtml(ctx,"算法goodsSn:"+goodsSn+"_"+supplierIdStr+" :md5("+strings.ToLower(goodsSn+"_"+supplierIdStr)+") = snSku:"+snSku+" 查询 sku_unique_judge 得出skuid: "+skuId)
......@@ -118,7 +122,7 @@ func (t *CommonLyService) GetSkuByGoodsSn(ctx *gin.Context,goodsList map[string]
//获取spu详情
spuId := gjson.Get(redisData,"spu_id").String();
spuStr,_ := redis.String(redisWrite.Do("HGET",config.Get("redis_all.SPU").String(),spuId))
spuStr,_ := redis.String(redisSpu.Do("HGET",config.Get("redis_all.SPU").String(),spuId))
info.SpuId = spuId //平台spuid
info.BrandId = gjson.Get(spuStr,"brand_id").String(); //平台品牌id
......@@ -182,10 +186,14 @@ func (t *CommonLyService) GetSkuByGoodsSn(ctx *gin.Context,goodsList map[string]
*/
func (t *CommonLyService) writeSkuInfo(ctx *gin.Context,skuInfo *model.LyClearGoodsList,skuId string) string {
redisWrite := gredis.Conn("search_w")
defer redisWrite.Close()
redisSpu := gredis.Conn("spu")
defer func() {
redisWrite.Close()
redisSpu.Close()
}()
spuKey := common.GetKey(skuInfo.GoodsName+"_"+skuInfo.BrandName)
spuId,_ := gredis.String(redisWrite.Do("HGET",config.Get("redis_all.SPU_UNIQUE_JUDGE").String(),spuKey))
spuId,_ := gredis.String(redisSpu.Do("HGET",config.Get("redis_all.SPU_UNIQUE_JUDGE").String(),spuKey))
common.PrintDebugHtml(ctx,"spu唯一值---spu_unique_judge:"+spuKey + " spu_id:"+spuId)
......@@ -224,7 +232,7 @@ func (t *CommonLyService) writeSkuInfo(ctx *gin.Context,skuInfo *model.LyClearGo
common.PrintDebugHtml(ctx,inSkuInfo)
skuKey := common.GetKey(skuInfo.GoodsSn+"_"+strconv.FormatInt(t.supplierId,10))
redisWrite.Do("HSET",config.Get("redis_all.SKU_UNIQUE_JUDGE").String(),skuKey,skuId)
redisSpu.Do("HSET",config.Get("redis_all.SKU_UNIQUE_JUDGE").String(),skuKey,skuId)
//todo 如果是digikey新增,需要插入原始映射表
if t.supplierId == 7 {
......@@ -240,7 +248,11 @@ func (t *CommonLyService) writeSkuInfo(ctx *gin.Context,skuInfo *model.LyClearGo
*/
func (t *CommonLyService) writeSpuInfo(ctx *gin.Context,skuInfo *model.LyClearGoodsList) string {
redisWrite := gredis.Conn("search_w")
defer redisWrite.Close()
redisSpu := gredis.Conn("spu")
defer func() {
redisWrite.Close()
redisSpu.Close()
}()
brand_key := common.GetKey(strings.ToLower(skuInfo.BrandName))
brandId,_ := redis.Int64(redisWrite.Do("HGET", config.Get("redis_all.BRAND_NAME_ALL").String(),brand_key))
......@@ -271,12 +283,12 @@ func (t *CommonLyService) writeSpuInfo(ctx *gin.Context,skuInfo *model.LyClearGo
}
jsonStr, _ := json.Marshal(Spuinfo)
redisWrite.Do("HSET","spu",spuId,jsonStr)
redisSpu.Do("HSET","spu",spuId,jsonStr)
common.PrintDebugHtml(ctx,"新增spu:"+string(jsonStr))
spuKey := common.GetKey(skuInfo.GoodsName+"_"+skuInfo.BrandName)
redisWrite.Do("HSET",config.Get("redis_all.SPU_UNIQUE_JUDGE").String(),spuKey,spuId)
redisSpu.Do("HSET",config.Get("redis_all.SPU_UNIQUE_JUDGE").String(),spuKey,spuId)
return spuId
}
......
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