Browse Source

数据处理异常捕获,修改处理

yuhongqi 1 tháng trước cách đây
mục cha
commit
5c2201488b
17 tập tin đã thay đổi với 390 bổ sung136 xóa
  1. 8 1
      fs-admin/src/main/java/com/fs/hisStore/task/LiveTask.java
  2. 8 1
      fs-admin/src/main/java/com/fs/hisStore/task/MallStoreTask.java
  3. 6 0
      fs-common/src/main/java/com/fs/common/constant/LiveKeysConstant.java
  4. 0 1
      fs-live-app/src/main/java/com/fs/framework/aspectj/LiveWatchUserAspect.java
  5. 9 6
      fs-live-app/src/main/java/com/fs/live/websocket/handle/LiveChatHandler.java
  6. 30 4
      fs-live-app/src/main/java/com/fs/live/websocket/service/WebSocketServer.java
  7. 1 0
      fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreOrderScrmServiceImpl.java
  8. 37 1
      fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreProductAttrScrmServiceImpl.java
  9. 37 1
      fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreProductAttrValueScrmServiceImpl.java
  10. 67 36
      fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreProductScrmServiceImpl.java
  11. 4 3
      fs-service/src/main/java/com/fs/live/service/ILiveWatchUserService.java
  12. 50 65
      fs-service/src/main/java/com/fs/live/service/impl/LiveAfterSalesServiceImpl.java
  13. 1 0
      fs-service/src/main/java/com/fs/live/service/impl/LiveOrderServiceImpl.java
  14. 91 3
      fs-service/src/main/java/com/fs/live/service/impl/LiveServiceImpl.java
  15. 6 7
      fs-service/src/main/java/com/fs/live/service/impl/LiveWatchUserServiceImpl.java
  16. 1 1
      fs-user-app/src/main/java/com/fs/app/controller/live/LiveController.java
  17. 34 6
      fs-user-app/src/main/java/com/fs/app/controller/live/LiveGoodsController.java

+ 8 - 1
fs-admin/src/main/java/com/fs/hisStore/task/LiveTask.java

@@ -198,8 +198,15 @@ public class LiveTask {
         if (ids.size() > 50) {
             ids = ids.subList(0, 50);
         }
+        // 单个异常影响全部,跳过异常单子
         for (Long id : ids) {
-            liveOrderService.createOmsOrder(id);
+            try {
+                liveOrderService.createOmsOrder(id);
+            } catch (Exception e) {
+                log.error("创建直播oms订单失败:"+id);
+                log.error("创建直播oms订单失败:"+e.getMessage());
+            }
+
         }
     }
 

+ 8 - 1
fs-admin/src/main/java/com/fs/hisStore/task/MallStoreTask.java

@@ -168,8 +168,15 @@ public class MallStoreTask
         if (!ids.isEmpty() && ids.size() > 50) {
             ids = ids.subList(0, 50);
         }
+        // 单个异常影响全部,跳过异常单子
         for (Long id : ids) {
-            fsStoreOrderService.createOmsOrder(id);
+            try {
+                fsStoreOrderService.createOmsOrder(id);
+            } catch (Exception e) {
+                log.error("创建商城oms订单失败:"+id);
+                log.error("创建商城oms订单失败:"+e.getMessage());
+            }
+
         }
     }
 

+ 6 - 0
fs-common/src/main/java/com/fs/common/constant/LiveKeysConstant.java

@@ -30,5 +30,11 @@ public class LiveKeysConstant {
     public static final String LIVE_FLAG_CACHE = "live:flag:%s"; //直播间直播/回放状态缓存
     public static final Integer LIVE_FLAG_CACHE_EXPIRE = 300; //直播间状态缓存过期时间(秒)
 
+    public static final String LIVE_DATA_CACHE = "live:data:%s"; //直播间数据缓存
+    public static final Integer LIVE_DATA_CACHE_EXPIRE = 300; //直播间数据缓存过期时间(秒)
+
+    public static final String PRODUCT_DETAIL_CACHE = "product:detail:%s"; //商品详情缓存
+    public static final Integer PRODUCT_DETAIL_CACHE_EXPIRE = 300; //商品详情缓存过期时间(秒)
+
 
 }

+ 0 - 1
fs-live-app/src/main/java/com/fs/framework/aspectj/LiveWatchUserAspect.java

@@ -33,7 +33,6 @@ public class LiveWatchUserAspect {
         try {
             String methodName = joinPoint.getSignature().getName();
             Object[] args = joinPoint.getArgs();
-            log.info("直播观看用户数据发生变化,方法: {}, 参数: {}", methodName, Arrays.toString(args));
             // 提取liveId并处理缓存更新
             Set<Long> liveIds = extractLiveIds(methodName, args);
             for (Long liveId : liveIds) {

+ 9 - 6
fs-live-app/src/main/java/com/fs/live/websocket/handle/LiveChatHandler.java

@@ -3,6 +3,8 @@ package com.fs.live.websocket.handle;
 import com.alibaba.fastjson.JSONObject;
 import com.fs.his.domain.FsUser;
 import com.fs.his.service.IFsUserService;
+import com.fs.hisStore.domain.FsUserScrm;
+import com.fs.hisStore.service.IFsUserScrmService;
 import com.fs.live.websocket.bean.SendMsgVo;
 import com.fs.live.websocket.constant.AttrConstant;
 import com.fs.common.core.domain.R;
@@ -41,7 +43,7 @@ public class LiveChatHandler extends SimpleChannelInboundHandler<TextWebSocketFr
     private final static ILiveService liveService = SpringUtils.getBean(ILiveService.class);
     private final static ILiveWatchUserService liveWatchUserService = SpringUtils.getBean(ILiveWatchUserService.class);
     private final static ILiveMsgService liveMsgService = SpringUtils.getBean(ILiveMsgService.class);
-    private final static IFsUserService fsUserService = SpringUtils.getBean(IFsUserService.class);
+    private final static IFsUserScrmService fsUserService = SpringUtils.getBean(IFsUserScrmService.class);
 
     /**
      * 处理握手
@@ -70,11 +72,12 @@ public class LiveChatHandler extends SimpleChannelInboundHandler<TextWebSocketFr
             roomGroup.add(ctx.channel());
 
             if (userType == 0) {
+
+
+                FsUserScrm fsUser = fsUserService.selectFsUserByUserId(userId);
                 // 加入房间
-                LiveWatchUser liveWatchUser = liveWatchUserService.joinWithoutLocation(liveId, userId);
+                LiveWatchUser liveWatchUser = liveWatchUserService.joinWithoutLocation(fsUser,liveId, userId);
                 room.put(userId, ctx.channel());
-
-                FsUser fsUser = fsUserService.selectFsUserByUserId(userId);
                 if (Objects.isNull(fsUser)) {
                     ctx.channel().writeAndFlush(new TextWebSocketFrame("Error: 用户信息错误")).addListener(ChannelFutureListener.CLOSE);
                     return;
@@ -218,8 +221,8 @@ public class LiveChatHandler extends SimpleChannelInboundHandler<TextWebSocketFr
         ChannelGroup roomGroup = getRoomGroup(liveId);
 
         if (userType == 0) {
-            FsUser fsUser = fsUserService.selectFsUserByUserId(userId);
-            LiveWatchUser close = liveWatchUserService.close(liveId, userId);
+            FsUserScrm fsUser = fsUserService.selectFsUserByUserId(userId);
+            LiveWatchUser close = liveWatchUserService.close(fsUser,liveId, userId);
             room.remove(userId);
 
             if (room.isEmpty()) {

+ 30 - 4
fs-live-app/src/main/java/com/fs/live/websocket/service/WebSocketServer.java

@@ -22,6 +22,7 @@ import com.fs.live.service.*;
 import com.fs.live.vo.LiveGoodsVo;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.time.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
@@ -101,7 +102,7 @@ public class WebSocketServer {
                 throw new BaseException("用户信息错误");
             }
 
-            LiveWatchUser liveWatchUserVO = liveWatchUserService.join(liveId, userId, location);
+            LiveWatchUser liveWatchUserVO = liveWatchUserService.join(fsUser,liveId, userId, location);
             room.put(userId, session);
             // 直播间浏览量 +1
             redisCache.incr(PAGE_VIEWS_KEY + liveId, 1);
@@ -209,7 +210,7 @@ public class WebSocketServer {
             // 从在线用户Set中移除用户ID
             String onlineUsersSetKey = ONLINE_USERS_SET_KEY + liveId;
             redisCache.redisTemplate.opsForSet().remove(onlineUsersSetKey, String.valueOf(userId));
-            LiveWatchUser liveWatchUserVO = liveWatchUserService.close(liveId, userId);
+            LiveWatchUser liveWatchUserVO = liveWatchUserService.close(fsUser,liveId, userId);
             SendMsgVo sendMsgVo = new SendMsgVo();
             sendMsgVo.setLiveId(liveId);
             sendMsgVo.setUserId(userId);
@@ -558,12 +559,12 @@ public class WebSocketServer {
 
         room.forEach((k, v) -> {
             if (v.isOpen()) {
-                sendWithRetry(v,message,7);
+                sendWithRetry(v,message,1);
             }
         });
         adminRoom.forEach(v -> {
             if (v.isOpen()) {
-                sendWithRetry(v,message,7);
+                sendWithRetry(v,message,1);
             }
         });
     }
@@ -602,6 +603,30 @@ public class WebSocketServer {
     }
 
 
+    @Scheduled(fixedRate = 2000)// 每2秒执行一次
+    public void broadcastUserNumMessage() {
+        // 遍历每个直播间
+        for (Map.Entry<Long, ConcurrentHashMap<Long, Session>> entry : rooms.entrySet()) {
+            Long liveId = entry.getKey();
+            ConcurrentHashMap<Long, Session> room = entry.getValue();
+
+            // 统计当前直播间的在线人数
+            int onlineCount = room.size();
+
+            // 构造消息
+            SendMsgVo sendMsgVo = new SendMsgVo();
+            sendMsgVo.setLiveId(liveId);
+            sendMsgVo.setCmd("userCount");
+            sendMsgVo.setData(String.valueOf(onlineCount));
+
+            // 广播当前直播间的在线人数
+            broadcastMessage(liveId, JSONObject.toJSONString(R.ok().put("data", sendMsgVo)));
+
+            log.debug("广播直播间在线人数: liveId={}, onlineCount={}", liveId, onlineCount);
+        }
+    }
+
+
     /**
      * 广播点赞消息
      * @param liveId   直播间ID
@@ -748,4 +773,5 @@ public class WebSocketServer {
         String key = "live:auto_task:";
         redisCache.redisTemplate.opsForZSet().removeRangeByScore(key + liveId, data, data);
     }
+
 }

+ 1 - 0
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreOrderScrmServiceImpl.java

@@ -2007,6 +2007,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
 
 
     @Override
+    @Transactional
     public R createOmsOrder(Long orderId) throws ParseException {
         FsStoreOrderScrm order = fsStoreOrderMapper.selectFsStoreOrderById(orderId);
         FsSysConfig erpConfig = configUtil.generateStructConfigByKey(SysConfigEnum.HIS_CONFIG.getKey(), FsSysConfig.class);

+ 37 - 1
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreProductAttrScrmServiceImpl.java

@@ -3,9 +3,12 @@ package com.fs.hisStore.service.impl;
 import java.util.List;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import com.fs.common.constant.LiveKeysConstant;
+import com.fs.common.core.redis.RedisCache;
 import com.fs.hisStore.mapper.FsStoreProductAttrScrmMapper;
 import com.fs.hisStore.domain.FsStoreProductAttrScrm;
 import com.fs.hisStore.service.IFsStoreProductAttrScrmService;
+import lombok.extern.slf4j.Slf4j;
 
 /**
  * 商品属性Service业务层处理
@@ -14,11 +17,27 @@ import com.fs.hisStore.service.IFsStoreProductAttrScrmService;
  * @date 2022-03-15
  */
 @Service
+@Slf4j
 public class FsStoreProductAttrScrmServiceImpl implements IFsStoreProductAttrScrmService
 {
     @Autowired
     private FsStoreProductAttrScrmMapper fsStoreProductAttrMapper;
 
+    @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);
+        }
+    }
+
     /**
      * 查询商品属性
      * 
@@ -64,7 +83,10 @@ public class FsStoreProductAttrScrmServiceImpl implements IFsStoreProductAttrScr
     @Override
     public int updateFsStoreProductAttr(FsStoreProductAttrScrm fsStoreProductAttr)
     {
-        return fsStoreProductAttrMapper.updateFsStoreProductAttr(fsStoreProductAttr);
+        int result = fsStoreProductAttrMapper.updateFsStoreProductAttr(fsStoreProductAttr);
+        // 清除对应商品的缓存
+        clearProductDetailCache(fsStoreProductAttr.getProductId());
+        return result;
     }
 
     /**
@@ -76,6 +98,15 @@ public class FsStoreProductAttrScrmServiceImpl implements IFsStoreProductAttrScr
     @Override
     public int deleteFsStoreProductAttrByIds(Long[] ids)
     {
+        // 先查询出对应的商品ID,然后清除缓存
+        if (ids != null && ids.length > 0) {
+            for (Long id : ids) {
+                FsStoreProductAttrScrm attr = fsStoreProductAttrMapper.selectFsStoreProductAttrById(id);
+                if (attr != null) {
+                    clearProductDetailCache(attr.getProductId());
+                }
+            }
+        }
         return fsStoreProductAttrMapper.deleteFsStoreProductAttrByIds(ids);
     }
 
@@ -88,6 +119,11 @@ public class FsStoreProductAttrScrmServiceImpl implements IFsStoreProductAttrScr
     @Override
     public int deleteFsStoreProductAttrById(Long id)
     {
+        // 先查询出对应的商品ID,然后清除缓存
+        FsStoreProductAttrScrm attr = fsStoreProductAttrMapper.selectFsStoreProductAttrById(id);
+        if (attr != null) {
+            clearProductDetailCache(attr.getProductId());
+        }
         return fsStoreProductAttrMapper.deleteFsStoreProductAttrById(id);
     }
 

+ 37 - 1
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreProductAttrValueScrmServiceImpl.java

@@ -3,6 +3,8 @@ package com.fs.hisStore.service.impl;
 import java.util.Collections;
 import java.util.List;
 
+import com.fs.common.constant.LiveKeysConstant;
+import com.fs.common.core.redis.RedisCache;
 import com.fs.hisStore.config.MedicalMallConfig;
 import com.fs.hisStore.param.FsProductAttrValueParam;
 import com.fs.hisStore.param.FsStoreProductAttrValueQueryParam;
@@ -10,6 +12,7 @@ import com.fs.hisStore.param.FsStoreTuiProductAttrValueParam;
 import com.fs.hisStore.vo.FsStoreProductAttrValueQueryVO;
 import com.fs.hisStore.vo.FsStoreProductAttrValueVO;
 import com.fs.hisStore.vo.FsStoreTuiProductAttrValueVO;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.fs.hisStore.mapper.FsStoreProductAttrValueScrmMapper;
@@ -23,6 +26,7 @@ import com.fs.hisStore.service.IFsStoreProductAttrValueScrmService;
  * @date 2022-03-15
  */
 @Service
+@Slf4j
 public class FsStoreProductAttrValueScrmServiceImpl implements IFsStoreProductAttrValueScrmService
 {
     @Autowired
@@ -31,6 +35,21 @@ public class FsStoreProductAttrValueScrmServiceImpl implements IFsStoreProductAt
     @Autowired
     private MedicalMallConfig config;
 
+    @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);
+        }
+    }
+
     /**
      * 查询商品属性值
      *
@@ -76,7 +95,10 @@ public class FsStoreProductAttrValueScrmServiceImpl implements IFsStoreProductAt
     @Override
     public int updateFsStoreProductAttrValue(FsStoreProductAttrValueScrm fsStoreProductAttrValue)
     {
-        return fsStoreProductAttrValueMapper.updateFsStoreProductAttrValue(fsStoreProductAttrValue);
+        int result = fsStoreProductAttrValueMapper.updateFsStoreProductAttrValue(fsStoreProductAttrValue);
+        // 清除对应商品的缓存
+        clearProductDetailCache(fsStoreProductAttrValue.getProductId());
+        return result;
     }
 
     /**
@@ -88,6 +110,15 @@ public class FsStoreProductAttrValueScrmServiceImpl implements IFsStoreProductAt
     @Override
     public int deleteFsStoreProductAttrValueByIds(Long[] ids)
     {
+        // 先查询出对应的商品ID,然后清除缓存
+        if (ids != null && ids.length > 0) {
+            for (Long id : ids) {
+                FsStoreProductAttrValueScrm attrValue = fsStoreProductAttrValueMapper.selectFsStoreProductAttrValueById(id);
+                if (attrValue != null) {
+                    clearProductDetailCache(attrValue.getProductId());
+                }
+            }
+        }
         return fsStoreProductAttrValueMapper.deleteFsStoreProductAttrValueByIds(ids);
     }
 
@@ -100,6 +131,11 @@ public class FsStoreProductAttrValueScrmServiceImpl implements IFsStoreProductAt
     @Override
     public int deleteFsStoreProductAttrValueById(Long id)
     {
+        // 先查询出对应的商品ID,然后清除缓存
+        FsStoreProductAttrValueScrm attrValue = fsStoreProductAttrValueMapper.selectFsStoreProductAttrValueById(id);
+        if (attrValue != null) {
+            clearProductDetailCache(attrValue.getProductId());
+        }
         return fsStoreProductAttrValueMapper.deleteFsStoreProductAttrValueById(id);
     }
 

+ 67 - 36
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreProductScrmServiceImpl.java

@@ -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();

+ 4 - 3
fs-service/src/main/java/com/fs/live/service/ILiveWatchUserService.java

@@ -2,6 +2,7 @@ package com.fs.live.service;
 
 
 import com.fs.common.core.domain.R;
+import com.fs.hisStore.domain.FsUserScrm;
 import com.fs.live.domain.LiveWatchUser;
 import com.fs.live.vo.LiveWatchUserVO;
 
@@ -77,9 +78,9 @@ public interface ILiveWatchUserService {
 
     Map<String, Integer> getLiveFlagWithCache(Long liveId);
 
-    LiveWatchUser join(long liveId, long userId, String location);
-    LiveWatchUser joinWithoutLocation(long liveId, long userId);
-    LiveWatchUser close(long liveId, long userId);
+    LiveWatchUser join(FsUserScrm fsUser,long liveId, long userId, String location);
+    LiveWatchUser joinWithoutLocation(FsUserScrm fsUser,long liveId, long userId);
+    LiveWatchUser close(FsUserScrm fsUser,long liveId, long userId);
 
     /**
      * 查询直播间在线用户列表

+ 50 - 65
fs-service/src/main/java/com/fs/live/service/impl/LiveAfterSalesServiceImpl.java

@@ -233,71 +233,56 @@ public class LiveAfterSalesServiceImpl implements ILiveAfterSalesService {
     @Override
     @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
     public R cancel(LiveAfterSalesCancelParam param) {
-//        LiveAfterSales storeAfterSales = baseMapper.selectLiveAfterSalesById(param.getSalesId());
-//        if (storeAfterSales == null) {
-//            throw new CustomException("未查询到售后订单信息");
-//        }
-//        if (storeAfterSales.getSalesStatus()!=0) {
-//            throw new CustomException("非法操作");
-//        }
-//
-//        LiveOrder order = liveOrderService.selectLiveOrderByOrderId(String.valueOf(storeAfterSales.getOrderId()));
-//        order.setStatus(storeAfterSales.getOrderStatus());
-//        order.setRefundStatus(String.valueOf(OrderInfoEnum.REFUND_STATUS_0.getValue()));
-//        liveOrderService.updateLiveOrder(order);
-//        storeAfterSales.setSalesStatus(2);
-//        LiveAfterSalesLogs storeAfterSalesStatus = new LiveAfterSalesLogs();
-//        storeAfterSalesStatus.setStoreAfterSalesId(storeAfterSales.getId());
-//        storeAfterSalesStatus.setChangeType(6);
-//        storeAfterSalesStatus.setChangeMessage(AfterSalesStatusEnum.STATUS_6.getDesc()+" "+param.getRemark());
-//        storeAfterSalesStatus.setChangeTime(Timestamp.valueOf(LocalDateTime.now()));
-//        storeAfterSalesStatus.setOperator(param.getOperator());
-//        liveAfterSalesLogsMapper.insertLiveAfterSalesLogs(storeAfterSalesStatus);
-//
-//        // 查询是否已经发货
-//        FsStoreDelivers byOrderCode = fsStoreDeliversMapper.findByOrderCode(order.getOrderCode());
-//        // 如果已发货走发货售后逻辑,否则直接取消
-//        if(byOrderCode!=null){
-//            if(StringUtils.isNotBlank(order.getStoreHouseCode())) {
-//                String erp = fsWarehousesMapper.selectErpByCode(order.getStoreHouseCode());
-//                if (StringUtils.equals(erp, ErpTypeConstant.JST_ERP)) {
-//
-//                    FsJstAftersalePush fsJstAftersalePush = new FsJstAftersalePush();
-//                    fsJstAftersalePush.setOrderId(order.getOrderCode());
-//                    fsJstAftersalePush.setTaskStatus(TaskStatusEnum.PENDING.getCode());
-//                    fsJstAftersalePush.setType(String.valueOf(AfterSalesOrderStatusEnum.CLOSED.getIndex()));
-//                    fsJstAftersalePush.setRetryCount(0);
-//                    fsJstAftersalePush.setAfterSaleId(String.valueOf(storeAfterSales.getId()));
-//                    fsJstAftersalePush.setOrderType(1);
-//                    fsJstAftersalePushMapper.insert(fsJstAftersalePush);
-//                }
-//            }
-//        }
-//        // 如果未发货,重新推送
-//        else {
-//            //创建新的OMS订单
-//            if (storeAfterSales.getOrderStatus().equals(2) ) {
-//                if(StringUtils.isNotEmpty(order.getExtendOrderId())){
-//                    //更新订单code
-//                    String orderSn = SnowflakeUtils.nextId();
-//                    LiveOrder orderMap=new LiveOrder();
-//                    orderMap.setOrderId(order.getOrderId());
-//                    orderMap.setOrderCode(orderSn);
-//                    liveOrderService.updateLiveOrder(orderMap);
-//                    storeAfterSales.setStoreId(Long.valueOf(orderSn));
-//                    liveOrderItemService.updateFsStoreOrderCode(order.getOrderId(),orderSn);
-//                    //生成新的订单
-//                    try {
-//                        liveOrderService.createOmsOrder(order.getOrderId());
-//                    } catch (Exception e) {
-//                        log.error("创建订单失败!",e);
-//                        throw new CustomException("创建订单失败");
-//                    }
-//                }
-//            }
-//
-//        }
-//        baseMapper.updateLiveAfterSales(storeAfterSales);
+        LiveAfterSales storeAfterSales = baseMapper.selectLiveAfterSalesById(param.getSalesId());
+        if (storeAfterSales == null) {
+            throw new CustomException("未查询到售后订单信息");
+        }
+        if (storeAfterSales.getSalesStatus()!=0) {
+            throw new CustomException("非法操作");
+        }
+
+        LiveOrder order = liveOrderService.selectLiveOrderByOrderId(String.valueOf(storeAfterSales.getOrderId()));
+        order.setStatus(storeAfterSales.getOrderStatus());
+        order.setRefundStatus(String.valueOf(OrderInfoEnum.REFUND_STATUS_0.getValue()));
+        liveOrderService.updateLiveOrder(order);
+        storeAfterSales.setSalesStatus(2);
+        LiveAfterSalesLogs storeAfterSalesStatus = new LiveAfterSalesLogs();
+        storeAfterSalesStatus.setStoreAfterSalesId(storeAfterSales.getId());
+        storeAfterSalesStatus.setChangeType(6);
+        storeAfterSalesStatus.setChangeMessage(AfterSalesStatusEnum.STATUS_6.getDesc()+" "+param.getRemark());
+        storeAfterSalesStatus.setChangeTime(Timestamp.valueOf(LocalDateTime.now()));
+        storeAfterSalesStatus.setOperator(param.getOperator());
+        liveAfterSalesLogsMapper.insertLiveAfterSalesLogs(storeAfterSalesStatus);
+        if (ObjectUtil.equal(order.getStatus(), 2)) {
+            FsJstAftersalePush fsJstAftersalePush = new FsJstAftersalePush();
+            fsJstAftersalePush.setOrderId(order.getOrderCode());
+            fsJstAftersalePush.setTaskStatus(TaskStatusEnum.PENDING.getCode());
+            fsJstAftersalePush.setType(String.valueOf(AfterSalesOrderStatusEnum.CLOSED.getIndex()));
+            fsJstAftersalePush.setRetryCount(0);
+            fsJstAftersalePush.setAfterSaleId(String.valueOf(storeAfterSales.getId()));
+            fsJstAftersalePushMapper.insert(fsJstAftersalePush);
+        } else {
+            //创建新的OMS订单
+            if (storeAfterSales.getOrderStatus().equals(OrderInfoEnum.STATUS_1.getValue()) ) {
+                if(StringUtils.isNotEmpty(order.getExtendOrderId())){
+                    //更新订单code
+                    String orderSn = IdUtil.getSnowflake(0, 0).nextIdStr();
+                    LiveOrder orderMap=new LiveOrder();
+                    orderMap.setOrderId(order.getOrderId());
+                    orderMap.setOrderCode(orderSn);
+                    liveOrderService.updateLiveOrder(orderMap);
+                    liveOrderItemMapper.updateFsStoreOrderCode(order.getOrderId(),orderSn);
+                    try {
+                        //生成新的订单
+                        liveOrderService.createOmsOrder(order.getOrderId());
+                    } catch (Exception e) {
+                        log.error("撤销售后,生成oms订单异常",e);
+                    }
+
+                }
+            }
+        }
+        baseMapper.updateLiveAfterSales(storeAfterSales);
         return R.ok();
     }
 

+ 1 - 0
fs-service/src/main/java/com/fs/live/service/impl/LiveOrderServiceImpl.java

@@ -1582,6 +1582,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
     }
 
     @Override
+    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
     public R createOmsOrder(Long orderId)  throws ParseException {
         LiveOrder order = liveOrderMapper.selectLiveOrderByOrderId(String.valueOf(orderId));
         LiveOrderPayment liveOrderPayment = liveOrderPaymentMapper.selectByBuissnessId(orderId);

+ 91 - 3
fs-service/src/main/java/com/fs/live/service/impl/LiveServiceImpl.java

@@ -137,7 +137,19 @@ public class LiveServiceImpl implements ILiveService
      */
     @Override
     public Live selectLiveByLiveId(Long liveId){
+        // 先从缓存中获取
+        String cacheKey = String.format(LiveKeysConstant.LIVE_DATA_CACHE, liveId);
+        Live cachedLive = redisCache.getCacheObject(cacheKey);
+        if (cachedLive != null) {
+            return cachedLive;
+        }
+        
+        // 缓存中没有,从数据库查询
         Live byId = baseMapper.selectLiveByLiveId(liveId);
+        if (byId == null) {
+            return null;
+        }
+        
         List<LiveVideo> videos = liveVideoService.listByLiveId(liveId, 1);
         if(!videos.isEmpty()){
             LiveVideo liveVideo = videos.get(0);
@@ -148,6 +160,10 @@ public class LiveServiceImpl implements ILiveService
             byId.setVideoFileSize(liveVideo.getFileSize());
             byId.setVideoDuration(liveVideo.getDuration());
         }
+        
+        // 将结果存入缓存
+        redisCache.setCacheObject(cacheKey, byId, LiveKeysConstant.LIVE_DATA_CACHE_EXPIRE, TimeUnit.SECONDS);
+        
         return byId;
     }
 
@@ -385,12 +401,17 @@ public class LiveServiceImpl implements ILiveService
     @Transactional
     public int updateLiveEntity(Live live) {
         log.error("updateLiveEntity:"+ live.getLiveId());
-        return baseMapper.updateLive( live);
+        int result = baseMapper.updateLive( live);
+        // 清除缓存
+        clearLiveCache(live.getLiveId());
+        return result;
     }
 
     @Override
     public void updateGlobalVisible(long liveId, Integer status) {
         baseMapper.updateGlobalVisible(liveId, status);
+        // 清除缓存
+        clearLiveCache(liveId);
     }
 
     @Override
@@ -530,6 +551,9 @@ public class LiveServiceImpl implements ILiveService
         log.error("updateLive:" + live.getLiveId());
         int result = baseMapper.updateLive(live);
         liveAutoTaskService.recalcLiveAutoTask(live);
+        
+        // 清除缓存
+        clearLiveCache(live.getLiveId());
 
         return result;
     }
@@ -542,7 +566,10 @@ public class LiveServiceImpl implements ILiveService
      */
     @Override
     public int deleteLiveByLiveIds(Long[] liveIds,Live live){
-        return baseMapper.deleteLiveByLiveIds(liveIds, live);
+        int result = baseMapper.deleteLiveByLiveIds(liveIds, live);
+        // 清除缓存
+        clearLiveCache(liveIds);
+        return result;
     }
 
     /**
@@ -554,7 +581,10 @@ public class LiveServiceImpl implements ILiveService
     @Override
     public int deleteLiveByLiveId(Long liveId)
     {
-        return baseMapper.deleteLiveByLiveId(liveId);
+        int result = baseMapper.deleteLiveByLiveId(liveId);
+        // 清除缓存
+        clearLiveCache(liveId);
+        return result;
     }
 
     @Override
@@ -599,6 +629,8 @@ public class LiveServiceImpl implements ILiveService
         live.setStatus(2);
         live.setLiveType(1);
         this.updateLive(live);
+        // 清除缓存
+        clearLiveCache(liveId);
         LiveData liveData = new LiveData();
         liveData.setLiveId(liveId);
         liveData.setPageViews(0L);
@@ -665,6 +697,8 @@ public class LiveServiceImpl implements ILiveService
         live.setLiveType(2);
         log.error("closeLiving:" + live.getLiveId());
         baseMapper.updateLive(live);
+        // 清除缓存
+        clearLiveCache(live.getLiveId());
         return R.ok();
     }
     /**
@@ -701,6 +735,8 @@ public class LiveServiceImpl implements ILiveService
 
             log.error("startLoopPlay:" + live.getLiveId());
             baseMapper.updateLive(curLive);
+            // 清除缓存
+            clearLiveCache(live.getLiveId());
 
             return R.ok();
         } catch (Exception e) {
@@ -729,6 +765,8 @@ public class LiveServiceImpl implements ILiveService
             curLive.setUpdateTime(new Date());
             log.error("stopLoopPlay:" + live.getLiveId());
             baseMapper.updateLive(curLive);
+            // 清除缓存
+            clearLiveCache(live.getLiveId());
 
             return R.ok();
         } catch (Exception e) {
@@ -740,6 +778,8 @@ public class LiveServiceImpl implements ILiveService
     public R handleShelfOrUn(LiveListVo listVo) {
         int updatedCount = baseMapper.updateBatchLiveList(listVo);
         log.error("有人下架了视频:" + listVo.getLiveIds());
+        // 清除缓存
+        clearLiveCache(listVo.getLiveIds());
         if (updatedCount > 0) {
             return R.ok("操作成功");
         }
@@ -749,6 +789,8 @@ public class LiveServiceImpl implements ILiveService
     @Override
     public R handleDeleteSelected(LiveListVo listVo) {
         int deleteCount = baseMapper.deleteBatchLiveList(listVo);
+        // 清除缓存
+        clearLiveCache(listVo.getLiveIds());
         if (deleteCount > 0) {
             return R.ok("操作成功");
         }
@@ -773,6 +815,8 @@ public class LiveServiceImpl implements ILiveService
         exist.setUpdateTime(new Date());
 
         baseMapper.updateLive(exist);
+        // 清除缓存
+        clearLiveCache(live.getLiveId());
 
         return R.ok();
     }
@@ -806,6 +850,8 @@ public class LiveServiceImpl implements ILiveService
         exist.setFinishTime( null);
         exist.setStartTime(LocalDateTime.now());
         baseMapper.updateLive(exist);
+        // 清除缓存
+        clearLiveCache(live.getLiveId());
         List<LiveAutoTask> liveAutoTasks = liveAutoTaskService.selectNoActivedByLiveId(exist.getLiveId(), new Date());
         liveAutoTasks.forEach(liveAutoTask -> {
             liveAutoTask.setCreateTime(null);
@@ -822,12 +868,16 @@ public class LiveServiceImpl implements ILiveService
     public R handleShelfOrUnAdmin(LiveListVo listVo) {
         baseMapper.handleShelfOrUnAdmin(listVo);
         log.error("有人下架了视频:" + listVo.getLiveIds());
+        // 清除缓存
+        clearLiveCache(listVo.getLiveIds());
         return R.ok();
     }
 
     @Override
     public R handleDeleteSelectedAdmin(LiveListVo listVo) {
         baseMapper.handleDeleteSelectedAdmin(listVo);
+        // 清除缓存
+        clearLiveCache(listVo.getLiveIds());
         return R.ok();
     }
 
@@ -1184,6 +1234,42 @@ public class LiveServiceImpl implements ILiveService
         return jsonObject.getLong(key);
     }
 
+    /**
+     * 清除直播间数据缓存
+     * @param liveId 直播间ID
+     */
+    private void clearLiveCache(Long liveId) {
+        if (liveId != null) {
+            String cacheKey = String.format(LiveKeysConstant.LIVE_DATA_CACHE, liveId);
+            redisCache.deleteObject(cacheKey);
+            log.debug("清除直播间缓存: liveId={}", liveId);
+        }
+    }
+
+    /**
+     * 批量清除直播间数据缓存
+     * @param liveIds 直播间ID数组
+     */
+    private void clearLiveCache(Long[] liveIds) {
+        if (liveIds != null && liveIds.length > 0) {
+            for (Long liveId : liveIds) {
+                clearLiveCache(liveId);
+            }
+        }
+    }
+
+    /**
+     * 批量清除直播间数据缓存
+     * @param liveIds 直播间ID列表
+     */
+    private void clearLiveCache(List<Long> liveIds) {
+        if (liveIds != null && !liveIds.isEmpty()) {
+            for (Long liveId : liveIds) {
+                clearLiveCache(liveId);
+            }
+        }
+    }
+
 
 
     /**
@@ -1224,6 +1310,8 @@ public class LiveServiceImpl implements ILiveService
                 live.setIdCardUrl(payload.get("idCardUrl"));
                 log.error("verifyIdInfo:" + live.getLiveId());
                 baseMapper.updateLive(live);
+                // 清除缓存
+                clearLiveCache(live.getLiveId());
                 return R.ok();
             }
         } catch (Exception e) {

+ 6 - 7
fs-service/src/main/java/com/fs/live/service/impl/LiveWatchUserServiceImpl.java

@@ -200,8 +200,7 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
     }
 
     @Override
-    public LiveWatchUser join(long liveId, long userId, String location) {
-        FsUserScrm fsUserVO = fsUserService.selectFsUserByUserId(userId);
+    public LiveWatchUser join(FsUserScrm fsUser,long liveId, long userId, String location) {
         Date now = DateUtils.getNowDate();
 
         // 查询直播间信息
@@ -231,7 +230,7 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
             liveWatchUser = new LiveWatchUser();
             liveWatchUser.setLiveId(liveId);
             liveWatchUser.setUserId(userId);
-            liveWatchUser.setAvatar(fsUserVO.getAvatar());
+            liveWatchUser.setAvatar(fsUser.getAvatar());
             liveWatchUser.setMsgStatus(0);
             liveWatchUser.setOnline(0);
             liveWatchUser.setLocation(location);
@@ -242,15 +241,15 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
             baseMapper.insertLiveWatchUser(liveWatchUser);
         }
 
-        liveWatchUser.setAvatar(fsUserVO.getAvatar());
-        liveWatchUser.setNickName(fsUserVO.getNickname());
+        liveWatchUser.setAvatar(fsUser.getAvatar());
+        liveWatchUser.setNickName(fsUser.getNickname());
         String hashKey = String.format(LiveKeysConstant.LIVE_WATCH_USERS, liveId);
         redisCache.hashPut(hashKey, String.valueOf(userId), JSON.toJSONString(liveWatchUser));
         return liveWatchUser;
     }
 
     @Override
-    public LiveWatchUser joinWithoutLocation(long liveId, long userId) {
+    public LiveWatchUser joinWithoutLocation(FsUserScrm fsUser,long liveId, long userId) {
         FsUserScrm fsUserVO = fsUserService.selectFsUserByUserId(userId);
         Date now = DateUtils.getNowDate();
 
@@ -295,7 +294,7 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
         return liveWatchUser;
     }
     @Override
-    public LiveWatchUser close(long liveId, long userId) {
+    public LiveWatchUser close(FsUserScrm fsUser,long liveId, long userId) {
 
         // 查询直播间信息
         Live live = liveMapper.selectLiveByLiveId(liveId);

+ 1 - 1
fs-user-app/src/main/java/com/fs/app/controller/live/LiveController.java

@@ -57,7 +57,7 @@ public class LiveController extends AppBaseController {
 	private LiveFacadeService liveFacadeService;
 
 	/**
-	 * 查询未结束直播间
+	 * 查询未结束直播间(销售专用)
 	 */
 	@GetMapping("/listToLiveNoEnd")
 	public TableDataInfo listToLiveNoEnd(Live live)

+ 34 - 6
fs-user-app/src/main/java/com/fs/app/controller/live/LiveGoodsController.java

@@ -2,6 +2,7 @@ package com.fs.app.controller.live;
 
 import com.fs.app.controller.AppBaseController;
 import com.fs.common.annotation.Log;
+import com.fs.common.constant.LiveKeysConstant;
 import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.redis.RedisCache;
@@ -25,7 +26,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 /**
  * 直播商品Controller
@@ -134,13 +138,37 @@ public class LiveGoodsController extends AppBaseController
     @GetMapping("/liveGoodsDetail/{productId}")
     public R liveGoodsDetail(@PathVariable Long productId)
     {
-        FsStoreProductScrm product = fsStoreProductService.selectFsStoreProductById(productId);
-        if(product==null){
-            return R.error("商品不存在或已下架");
+        // 先从缓存中获取商品详情
+        String cacheKey = String.format(LiveKeysConstant.PRODUCT_DETAIL_CACHE, productId);
+        Map<String, Object> cachedData = redisCache.getCacheObject(cacheKey);
+        
+        FsStoreProductScrm product;
+        List<FsStoreProductAttrScrm> productAttr;
+        List<FsStoreProductAttrValueScrm> productValues;
+        
+        if (cachedData != null) {
+            // 从缓存中获取数据
+            product = (FsStoreProductScrm) cachedData.get("product");
+            productAttr = (List<FsStoreProductAttrScrm>) cachedData.get("productAttr");
+            productValues = (List<FsStoreProductAttrValueScrm>) cachedData.get("productValues");
+        } else {
+            // 缓存中没有,从数据库查询
+            product = fsStoreProductService.selectFsStoreProductById(productId);
+            if(product==null){
+                return R.error("商品不存在或已下架");
+            }
+            productAttr = attrService.selectFsStoreProductAttrByProductId(productId);
+            productValues = attrValueService.selectFsStoreProductAttrValueByProductId(productId);
+            
+            // 将数据存入缓存
+            Map<String, Object> cacheData = new HashMap<>();
+            cacheData.put("product", product);
+            cacheData.put("productAttr", productAttr);
+            cacheData.put("productValues", productValues);
+            redisCache.setCacheObject(cacheKey, cacheData, LiveKeysConstant.PRODUCT_DETAIL_CACHE_EXPIRE, TimeUnit.SECONDS);
         }
-        List<FsStoreProductAttrScrm> productAttr=attrService.selectFsStoreProductAttrByProductId(productId);
-        List<FsStoreProductAttrValueScrm> productValues=attrValueService.selectFsStoreProductAttrValueByProductId(productId);
-//获取用户的TOKEN写入足迹
+        
+        // 获取用户的TOKEN写入足迹
         String userId=getUserId();
         if(userId!=null){
             FsStoreProductRelationScrm productRelation=new FsStoreProductRelationScrm();