|
|
@@ -12,7 +12,9 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fs.common.BeanCopyUtils;
|
|
|
+import com.fs.common.constant.LiveKeysConstant;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
+import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.exception.ServiceException;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
@@ -135,6 +137,33 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
|
|
|
@Autowired
|
|
|
private LiveLotteryProductConfMapper liveLotteryProductConfMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisCache redisCache;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 清除商品详情缓存
|
|
|
+ * @param productId 商品ID
|
|
|
+ */
|
|
|
+ private void clearProductDetailCache(Long productId) {
|
|
|
+ if (productId != null) {
|
|
|
+ String cacheKey = String.format(LiveKeysConstant.PRODUCT_DETAIL_CACHE, productId);
|
|
|
+ redisCache.deleteObject(cacheKey);
|
|
|
+ log.debug("清除商品详情缓存: productId={}", productId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量清除商品详情缓存
|
|
|
+ * @param productIds 商品ID数组
|
|
|
+ */
|
|
|
+ private void clearProductDetailCache(Long[] productIds) {
|
|
|
+ if (productIds != null && productIds.length > 0) {
|
|
|
+ for (Long productId : productIds) {
|
|
|
+ clearProductDetailCache(productId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询商品
|
|
|
*
|
|
|
@@ -189,7 +218,10 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
|
|
|
if(1 == fsStoreProduct.getIsShow() && "1".equals(fsStoreProduct.getIsAudit())){
|
|
|
fsStoreProduct.setIsAudit("0");
|
|
|
}
|
|
|
- return fsStoreProductMapper.updateFsStoreProduct(fsStoreProduct);
|
|
|
+ int result = fsStoreProductMapper.updateFsStoreProduct(fsStoreProduct);
|
|
|
+ // 清除缓存
|
|
|
+ clearProductDetailCache(fsStoreProduct.getProductId());
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -202,19 +234,17 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
|
|
|
public int deleteFsStoreProductByIds(Long[] productIds)
|
|
|
{
|
|
|
storeAuditLogUtil.addBatchAuditArray(productIds, "", "");
|
|
|
-
|
|
|
+ log.info("批量删除商品:{}", productIds);
|
|
|
int result = fsStoreProductMapper.deleteFsStoreProductByIds(productIds);
|
|
|
-
|
|
|
+
|
|
|
+ // 清除缓存
|
|
|
+ clearProductDetailCache(productIds);
|
|
|
+
|
|
|
// 异步处理商品删除联动逻辑
|
|
|
if (result > 0) {
|
|
|
- try {
|
|
|
- log.info("批量删除商品:{}", productIds);
|
|
|
- handleProductDeleteAsync(productIds);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("商品删除异步处理失败:{}", e.getMessage());
|
|
|
- }
|
|
|
+ handleProductDeleteAsync(productIds);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -228,7 +258,7 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
|
|
|
public void handleProductDeleteAsync(Long[] productIds) {
|
|
|
try {
|
|
|
log.info("开始异步处理商品删除联动,商品IDs: {}", Arrays.toString(productIds));
|
|
|
-
|
|
|
+
|
|
|
// 查询所有未直播(1)、直播中(2)和直播回放(4)的直播间
|
|
|
// 使用 LiveMapper 查询状态为1,2,4的直播间(包括所有类型)
|
|
|
List<Live> allLiveList = liveMapper.liveListAll();
|
|
|
@@ -253,19 +283,19 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (targetLiveList.isEmpty()) {
|
|
|
log.info("没有找到需要处理的直播间");
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
log.info("找到 {} 个需要处理的直播间", targetLiveList.size());
|
|
|
-
|
|
|
+
|
|
|
// 遍历每个被删除的商品
|
|
|
for (Long productId : productIds) {
|
|
|
processProductDeleteForLives(productId, targetLiveList);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
log.info("商品删除联动处理完成");
|
|
|
} catch (Exception e) {
|
|
|
log.error("异步处理商品删除联动失败", e);
|
|
|
@@ -285,19 +315,19 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
|
|
|
if (liveId == null) {
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 1. 删除直播商品
|
|
|
deleteLiveGoodsByProductId(productId, liveId);
|
|
|
-
|
|
|
+
|
|
|
// 2. 删除直播定时任务(直播上下架、直播卡片)
|
|
|
deleteLiveAutoTasksByProductId(productId, liveId);
|
|
|
-
|
|
|
+
|
|
|
// 3. 删除直播抽奖(产品关联被删除的商品)
|
|
|
deleteLiveLotteryProductConfByProductId(productId, liveId);
|
|
|
-
|
|
|
+
|
|
|
// 4. 删除直播定时任务(抽奖,里面关联了这个商品的)
|
|
|
deleteLiveAutoTasksByLotteryProductId(productId, liveId);
|
|
|
-
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
log.error("处理直播间 {} 的商品 {} 删除联动失败", live.getLiveId(), productId, e);
|
|
|
}
|
|
|
@@ -316,7 +346,7 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
|
|
|
queryGoods.setProductId(productId);
|
|
|
queryGoods.setLiveId(liveId);
|
|
|
List<LiveGoods> goodsList = liveGoodsService.selectLiveGoodsList(queryGoods);
|
|
|
-
|
|
|
+
|
|
|
if (!goodsList.isEmpty()) {
|
|
|
Long[] goodsIds = goodsList.stream()
|
|
|
.map(LiveGoods::getGoodsId)
|
|
|
@@ -340,9 +370,9 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
|
|
|
LiveAutoTask queryTask = new LiveAutoTask();
|
|
|
queryTask.setLiveId(liveId);
|
|
|
List<LiveAutoTask> taskList = liveAutoTaskService.selectLiveAutoTaskList(queryTask);
|
|
|
-
|
|
|
+
|
|
|
List<Long> taskIdsToDelete = new ArrayList<>();
|
|
|
-
|
|
|
+
|
|
|
for (LiveAutoTask task : taskList) {
|
|
|
// 任务类型:1-定时推送卡片商品 6-自动上下架
|
|
|
if (task.getTaskType() != null && (task.getTaskType() == 1L || task.getTaskType() == 6L)) {
|
|
|
@@ -366,7 +396,7 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (!taskIdsToDelete.isEmpty()) {
|
|
|
Long[] ids = taskIdsToDelete.toArray(new Long[0]);
|
|
|
liveAutoTaskService.deleteLiveAutoTaskByIds(ids);
|
|
|
@@ -389,7 +419,7 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
|
|
|
queryConf.setProductId(productId);
|
|
|
queryConf.setLiveId(liveId);
|
|
|
List<LiveLotteryProductConf> confList = liveLotteryProductConfMapper.selectLiveLotteryProductConfList(queryConf);
|
|
|
-
|
|
|
+
|
|
|
if (!confList.isEmpty()) {
|
|
|
Long[] ids = confList.stream()
|
|
|
.map(LiveLotteryProductConf::getId)
|
|
|
@@ -415,23 +445,23 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
|
|
|
queryConf.setProductId(productId);
|
|
|
queryConf.setLiveId(liveId);
|
|
|
List<LiveLotteryProductConf> confList = liveLotteryProductConfMapper.selectLiveLotteryProductConfList(queryConf);
|
|
|
-
|
|
|
+
|
|
|
if (confList.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 获取所有相关的抽奖ID
|
|
|
Set<Long> lotteryIds = confList.stream()
|
|
|
.map(LiveLotteryProductConf::getLotteryId)
|
|
|
.collect(Collectors.toSet());
|
|
|
-
|
|
|
+
|
|
|
// 查询该直播间的所有定时任务
|
|
|
LiveAutoTask queryTask = new LiveAutoTask();
|
|
|
queryTask.setLiveId(liveId);
|
|
|
List<LiveAutoTask> taskList = liveAutoTaskService.selectLiveAutoTaskList(queryTask);
|
|
|
-
|
|
|
+
|
|
|
List<Long> taskIdsToDelete = new ArrayList<>();
|
|
|
-
|
|
|
+
|
|
|
for (LiveAutoTask task : taskList) {
|
|
|
// 任务类型:4-抽奖
|
|
|
if (task.getTaskType() != null && task.getTaskType() == 4L) {
|
|
|
@@ -445,7 +475,7 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (!taskIdsToDelete.isEmpty()) {
|
|
|
Long[] ids = taskIdsToDelete.toArray(new Long[0]);
|
|
|
liveAutoTaskService.deleteLiveAutoTaskByIds(ids);
|
|
|
@@ -465,7 +495,10 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
|
|
|
@Override
|
|
|
public int deleteFsStoreProductById(Long productId)
|
|
|
{
|
|
|
- return fsStoreProductMapper.deleteFsStoreProductById(productId);
|
|
|
+ int result = fsStoreProductMapper.deleteFsStoreProductById(productId);
|
|
|
+ // 清除缓存
|
|
|
+ clearProductDetailCache(productId);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -672,6 +705,8 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
|
|
|
product.setIsAudit("1");
|
|
|
}
|
|
|
fsStoreProductMapper.updateFsStoreProduct(product);
|
|
|
+ // 清除缓存
|
|
|
+ clearProductDetailCache(product.getProductId());
|
|
|
if (param.getSpecType().equals(0)) {
|
|
|
ProductArrtDTO fromatDetailDto = ProductArrtDTO.builder()
|
|
|
.value("规格")
|
|
|
@@ -1404,10 +1439,6 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //重命名
|
|
|
- product.setProductName(product.getProductName() + " - 副本");
|
|
|
- product.setCreateTime(new Date());
|
|
|
- product.setUpdateTime(new Date());
|
|
|
|
|
|
fsStoreProductMapper.insertFsStoreProduct(product);
|
|
|
Long fsStoreProductId = product.getProductId();
|