|
|
@@ -50,6 +50,7 @@ import zs.payment.mapper.flymall.B2cGoodsAttrMapper;
|
|
|
import zs.payment.mapper.flymall.B2cGoodsSpuInOnlineMapper;
|
|
|
import zs.payment.mapper.flymall.B2cGoodsStatusMapper;
|
|
|
import zs.payment.messages.KafkaProducer;
|
|
|
+import zs.payment.utils.MallRedisUtils;
|
|
|
import zs.payment.utils.RedisUtils;
|
|
|
|
|
|
import java.io.File;
|
|
|
@@ -110,6 +111,8 @@ public class CommodityProcureServiceImpl implements CommodityProcureService {
|
|
|
@Autowired
|
|
|
private RedisUtils redisUtils;
|
|
|
@Autowired
|
|
|
+ private MallRedisUtils mallRedisUtils;
|
|
|
+ @Autowired
|
|
|
private B2cGoodsSpuInOnlineMapper b2cGoodsSpuInOnlineMapper;
|
|
|
@Autowired
|
|
|
private B2cGoodsAttrMapper b2cGoodsAttrMapper;
|
|
|
@@ -1306,12 +1309,12 @@ public class CommodityProcureServiceImpl implements CommodityProcureService {
|
|
|
sku.setQyId(opt.getId() != null ? opt.getId().intValue() : null);
|
|
|
b2cGoodsSkuInOnlineService.save(sku);
|
|
|
|
|
|
- // Redis缓存:对应PHP _saveSku中的redis操作
|
|
|
+ // Redis缓存:对应PHP _saveSku中的redis操作,写入云商城Redis
|
|
|
if (sku.getSkuId() != null && opt.getId() != null) {
|
|
|
try {
|
|
|
String optionKey = "option_" + opt.getId().intValue();
|
|
|
- redisUtils.set(optionKey, String.valueOf(sku.getSkuId()));
|
|
|
- redisUtils.set(String.valueOf(sku.getSkuId()), String.valueOf(sku.getGdStock()));
|
|
|
+ mallRedisUtils.set(optionKey, String.valueOf(sku.getSkuId()));
|
|
|
+ mallRedisUtils.set(String.valueOf(sku.getSkuId()), String.valueOf(sku.getGdStock()));
|
|
|
} catch (Exception e) {
|
|
|
log.warn("Redis缓存多规格SKU库存失败 gdId={}, optionId={}", gdId, opt.getId(), e);
|
|
|
}
|
|
|
@@ -1334,12 +1337,12 @@ public class CommodityProcureServiceImpl implements CommodityProcureService {
|
|
|
sku.setUpdTime(now);
|
|
|
b2cGoodsSkuInOnlineService.save(sku);
|
|
|
|
|
|
- // Redis缓存:对应PHP _noSaleAttrSetSku中的redis操作
|
|
|
+ // Redis缓存:对应PHP _noSaleAttrSetSku中的redis操作,写入云商城Redis
|
|
|
if (sku.getSkuId() != null) {
|
|
|
try {
|
|
|
String goodsKey = "goods_" + gdId;
|
|
|
- redisUtils.set(goodsKey, String.valueOf(sku.getSkuId()));
|
|
|
- redisUtils.set(String.valueOf(sku.getSkuId()), String.valueOf(sku.getGdStock()));
|
|
|
+ mallRedisUtils.set(goodsKey, String.valueOf(sku.getSkuId()));
|
|
|
+ mallRedisUtils.set(String.valueOf(sku.getSkuId()), String.valueOf(sku.getGdStock()));
|
|
|
} catch (Exception e) {
|
|
|
log.warn("Redis缓存单SKU库存失败 gdId={}", gdId, e);
|
|
|
}
|
|
|
@@ -1667,6 +1670,53 @@ public class CommodityProcureServiceImpl implements CommodityProcureService {
|
|
|
return Result.success("gd_desc脏数据清理完成,清理 " + success + " 条,失败 " + fail + " 条");
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Result migrateSkuStockToMallRedis() {
|
|
|
+ final int BATCH = 500;
|
|
|
+ int success = 0, fail = 0;
|
|
|
+ Integer cursorSkuId = 0; // 按主键 sku_id 游标推进
|
|
|
+
|
|
|
+ log.info("开始 SKU 库存迁移到云商城 Redis");
|
|
|
+
|
|
|
+ while (true) {
|
|
|
+ List<B2cGoodsSkuInOnline> batch = b2cGoodsSkuInOnlineService.list(
|
|
|
+ new LambdaQueryWrapper<B2cGoodsSkuInOnline>()
|
|
|
+ .eq(B2cGoodsSkuInOnline::getIsDel, 0)
|
|
|
+ .isNotNull(B2cGoodsSkuInOnline::getQyId)
|
|
|
+ .eq(B2cGoodsSkuInOnline::getShopId,13537)
|
|
|
+ .gt(B2cGoodsSkuInOnline::getQyId, 0)
|
|
|
+ .gt(B2cGoodsSkuInOnline::getSkuId, cursorSkuId)
|
|
|
+ .orderByAsc(B2cGoodsSkuInOnline::getSkuId)
|
|
|
+ .last("LIMIT " + BATCH));
|
|
|
+
|
|
|
+ if (batch.isEmpty()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (B2cGoodsSkuInOnline sku : batch) {
|
|
|
+ cursorSkuId = sku.getSkuId(); // 无论成功失败都推进游标
|
|
|
+ try {
|
|
|
+ // option_id → skuId 映射
|
|
|
+ String optionKey = "option_" + sku.getQyId();
|
|
|
+ mallRedisUtils.set(optionKey, String.valueOf(sku.getSkuId()));
|
|
|
+
|
|
|
+ // skuId → 库存 映射
|
|
|
+ mallRedisUtils.set(String.valueOf(sku.getSkuId()),
|
|
|
+ String.valueOf(sku.getGdStock()));
|
|
|
+ success++;
|
|
|
+ } catch (Exception e) {
|
|
|
+ fail++;
|
|
|
+ log.warn("SKU库存迁移失败 skuId={}, qyId={}", sku.getSkuId(), sku.getQyId(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("SKU库存迁移进度:成功{},失败{},cursorSkuId={}", success, fail, cursorSkuId);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("SKU库存迁移完成,成功{},失败{}", success, fail);
|
|
|
+ return Result.success(String.format("迁移完成:成功%d条,失败%d条", success, fail));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 更新货架商品数量并软删除货架商品(对应PHP updateshelfnumbygdid + delGoodsByShelvesId)
|
|
|
*/
|