记得上下班打卡 | git大法好,push需谨慎

Commit 26ab013e authored by 胡佳晨's avatar 胡佳晨

库存相关 redis

parent dd988aa2
...@@ -48,6 +48,6 @@ public class GoblinRedisConst { ...@@ -48,6 +48,6 @@ public class GoblinRedisConst {
/** /**
* SKU剩余库存 * SKU剩余库存
*/ */
public static final String REALSTOCK_SKU = PREFIX.concat("realstock_sku:"); public static final String REAL_STOCK_SKU = PREFIX.concat("real_stock_sku:");
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */
} }
...@@ -17,6 +17,49 @@ public class GoblinRedisUtils { ...@@ -17,6 +17,49 @@ public class GoblinRedisUtils {
@Autowired @Autowired
GoblinMongoUtils goblinMongoUtils; GoblinMongoUtils goblinMongoUtils;
/* ---------------------------------------- sku库存相关 ---------------------------------------- */
public void setSkuStock(String marketPre, String skuId, Integer stock) {
String rk = GoblinRedisConst.REAL_STOCK_SKU;
if (marketPre != null) {
rk = rk.concat(marketPre + ":");
}
rk = rk.concat(skuId);
redisUtil.set(rk, stock);
}
public int getSkuStock(String marketPre, String skuId) {
String rk = GoblinRedisConst.REAL_STOCK_SKU;
if (marketPre != null) {
rk = rk.concat(marketPre + ":");
}
rk = rk.concat(skuId);
Object obj = redisUtil.get(rk);
if (obj == null) {
return 0;
} else {
return (int) obj;
}
}
public int incrSkuStock(String marketPre, String skuId, Integer stock) {
String rk = GoblinRedisConst.REAL_STOCK_SKU;
if (marketPre != null) {
rk = rk.concat(marketPre + ":");
}
rk = rk.concat(skuId);
return (int) redisUtil.incr(rk, stock);
}
public int decrSkuStock(String marketPre, String skuId, Integer stock) {
String rk = GoblinRedisConst.REAL_STOCK_SKU;
if (marketPre != null) {
rk = rk.concat(marketPre + ":");
}
rk = rk.concat(skuId);
return (int) redisUtil.decr(rk, stock);
}
/* ---------------------------------------- 商品数据源 ---------------------------------------- */ /* ---------------------------------------- 商品数据源 ---------------------------------------- */
public boolean setGoodsInfoVo(GoblinGoodsInfoVo vo) { public boolean setGoodsInfoVo(GoblinGoodsInfoVo vo) {
...@@ -129,7 +172,7 @@ public class GoblinRedisUtils { ...@@ -129,7 +172,7 @@ public class GoblinRedisUtils {
} }
} }
public void addStoreMarketIsConfig(String marketId, String storeId, String spuId,String marketSpuId) { public void addStoreMarketIsConfig(String marketId, String storeId, String spuId, String marketSpuId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_STORE_MARKET_ISCONFIG.concat(marketId).concat(":store_id:" + storeId); String redisKey = GoblinRedisConst.REDIS_GOBLIN_STORE_MARKET_ISCONFIG.concat(marketId).concat(":store_id:" + storeId);
List<GoblinStoreMarketIsConfigVo> voList = getStoreMarketIsConfig(marketId, storeId); List<GoblinStoreMarketIsConfigVo> voList = getStoreMarketIsConfig(marketId, storeId);
GoblinStoreMarketIsConfigVo vo = GoblinStoreMarketIsConfigVo.getNew(); GoblinStoreMarketIsConfigVo vo = GoblinStoreMarketIsConfigVo.getNew();
...@@ -139,12 +182,12 @@ public class GoblinRedisUtils { ...@@ -139,12 +182,12 @@ public class GoblinRedisUtils {
redisUtil.set(redisKey, voList); redisUtil.set(redisKey, voList);
} }
public void delStoreMarketIsConfig(String marketId, String storeId, String spuId,String marketSpuId) { public void delStoreMarketIsConfig(String marketId, String storeId, String spuId, String marketSpuId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_STORE_MARKET_ISCONFIG.concat(marketId).concat(":store_id:" + storeId); String redisKey = GoblinRedisConst.REDIS_GOBLIN_STORE_MARKET_ISCONFIG.concat(marketId).concat(":store_id:" + storeId);
List<GoblinStoreMarketIsConfigVo> voList = getStoreMarketIsConfig(marketId, storeId); List<GoblinStoreMarketIsConfigVo> voList = getStoreMarketIsConfig(marketId, storeId);
for (int i =0 ;i<voList.size();i++){ for (int i = 0; i < voList.size(); i++) {
String itemSpuId= voList.get(i).getSpuId(); String itemSpuId = voList.get(i).getSpuId();
if(spuId.equals(itemSpuId)){ if (spuId.equals(itemSpuId)) {
voList.remove(i); voList.remove(i);
} }
} }
......
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 to comment