开关库存、移除商品库存缓存
This commit is contained in:
parent
2688efc638
commit
450cc693d0
|
|
@ -67,7 +67,7 @@ public class ShopProductSkuInfoVo implements Serializable {
|
|||
*/
|
||||
private BigDecimal realSalesNumber;
|
||||
/**
|
||||
* 是否售罄
|
||||
* 是否售罄(同isSoldStock)
|
||||
*/
|
||||
private Integer isPauseSale;
|
||||
/**
|
||||
|
|
@ -75,11 +75,19 @@ public class ShopProductSkuInfoVo implements Serializable {
|
|||
*/
|
||||
private Integer stockNumber;
|
||||
/**
|
||||
* 是否售罄
|
||||
* 是否售罄(isPauseSale)
|
||||
*/
|
||||
private Integer isSoldStock;
|
||||
/**
|
||||
* 是否上架
|
||||
* 是否上架(同isGrounding)
|
||||
*/
|
||||
private Integer isSale;
|
||||
/**
|
||||
* 是否开启库存
|
||||
*/
|
||||
private Integer isStock;
|
||||
/**
|
||||
* 是否上架(同isSale)
|
||||
*/
|
||||
private Integer isGrounding;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,4 +113,8 @@ public class ShopProductVo implements Serializable {
|
|||
* 店铺id
|
||||
*/
|
||||
private Long shopId;
|
||||
/**
|
||||
* 是否开启库存
|
||||
*/
|
||||
private Integer isStock;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -403,17 +403,20 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|||
entity.setIsDel(DeleteEnum.NORMAL.value());
|
||||
entity.setShopId(shopId);
|
||||
if (!ProductTypeEnum.SKU.value().equals(entity.getType())) {
|
||||
entity.setSpecId(null);
|
||||
UpdateChain.of(Product.class).set(Product::getSpecId, null).eq(Product::getId, dto.getId()).update();
|
||||
}
|
||||
entity.setSpecId(null);
|
||||
super.updateById(entity);
|
||||
// 清除商品分类列表缓存
|
||||
if (!old.getCategoryId().equals(dto.getCategoryId())) {
|
||||
Long categoryId = ObjUtil.defaultIfNull(dto.getCategoryId(), old.getCategoryId());
|
||||
if (!old.getCategoryId().equals(categoryId)) {
|
||||
// 清除旧分类缓存&新分类缓存
|
||||
clearProductCache(old.getCategoryId(), entity.getCategoryId());
|
||||
}else {
|
||||
} else {
|
||||
clearProductCache(old.getCategoryId());
|
||||
}
|
||||
if (ObjUtil.defaultIfNull(dto.getIsStock(), old.getIsStock()) == YesNoEnum.NO.value()) {
|
||||
redisService.del(StrUtil.format(CacheConstant.SHOP_PRODUCT_STOCK, shopId, dto.getId()));
|
||||
}
|
||||
List<ProdSkuDTO> skuList = dto.getSkuList();
|
||||
// 商品SKU-ID列表
|
||||
List<Long> skuIdList = prodSkuMapper.selectListByQueryAs(query().select(ProdSku::getId).eq(ProdSku::getProductId, dto.getId()), Long.class);
|
||||
|
|
@ -772,9 +775,14 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|||
Map<Long, Integer> stock = list.stream().collect(Collectors.toMap(Product::getId, Product::getStockNumber));
|
||||
records.parallelStream().forEach(record -> {
|
||||
record.setStockNumber(stock.getOrDefault(record.getId(), 0));
|
||||
refreshRedisStock(record.getShopId(), record.getId(), record.getStockNumber());
|
||||
if (record.getIsStock() == YesNoEnum.YES.value()) {
|
||||
refreshRedisStock(record.getShopId(), record.getId(), record.getStockNumber());
|
||||
} else {
|
||||
redisService.del(StrUtil.format(CacheConstant.SHOP_PRODUCT_STOCK, record.getShopId(), record.getStockNumber()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void refreshRedisStock(Long shopId, Long productId, Integer stockNumber) {
|
||||
String key = StrUtil.format(CacheConstant.SHOP_PRODUCT_STOCK, shopId, productId);
|
||||
redisService.set(key, stockNumber);
|
||||
|
|
|
|||
|
|
@ -153,8 +153,9 @@ public class UProductServiceImpl extends ServiceImpl<ProductMapper, Product> imp
|
|||
// throw new CzgException("商品SKU不可售或不存在");
|
||||
if (data != null) {
|
||||
data.setStockNumber(ObjUtil.defaultIfNull(product.getStockNumber(), 0));
|
||||
data.setIsSoldStock(product.getIsSoldStock());
|
||||
data.setIsSale(product.getIsSale());
|
||||
data.setIsSoldStock(data.getIsPauseSale());
|
||||
data.setIsSale(data.getIsGrounding());
|
||||
data.setIsStock(product.getIsStock());
|
||||
return data;
|
||||
}
|
||||
return null;
|
||||
|
|
@ -188,7 +189,11 @@ public class UProductServiceImpl extends ServiceImpl<ProductMapper, Product> imp
|
|||
}
|
||||
productList.parallelStream().forEach(record -> {
|
||||
record.setStockNumber(productStock.getOrDefault(record.getId(), 0));
|
||||
refreshRedisStock(record.getShopId(), record.getId(), record.getStockNumber());
|
||||
if (record.getIsStock() == YesNoEnum.YES.value()) {
|
||||
refreshRedisStock(record.getShopId(), record.getId(), record.getStockNumber());
|
||||
} else {
|
||||
redisService.del(StrUtil.format(CacheConstant.SHOP_PRODUCT_STOCK, record.getShopId(), record.getId()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -93,7 +93,8 @@
|
|||
t1.group_snap,
|
||||
t1.pack_fee,
|
||||
ifnull(t4.sales_volume, 0) as sales_volume,
|
||||
t1.shop_id
|
||||
t1.shop_id,
|
||||
t1.is_stock
|
||||
from tb_product t1
|
||||
left join (select x.product_id,
|
||||
x.id as sku_id,
|
||||
|
|
|
|||
Loading…
Reference in New Issue