Quellcode durchsuchen

直播结束 自动下架所有商品

yuhongqi vor 4 Wochen
Ursprung
Commit
358261773c

+ 9 - 0
fs-live-socket/src/main/java/com/fs/live/task/Task.java

@@ -94,6 +94,9 @@ public class Task {
     @Autowired
     private ILiveCouponIssueService liveCouponIssueService;
 
+    @Autowired
+    private ILiveGoodsService liveGoodsService;
+
     @Autowired
     public FsJstAftersalePushService fsJstAftersalePushService;
     @Autowired
@@ -210,6 +213,12 @@ public class Task {
                         redisCache.redisTemplate.opsForZSet().remove(key + live.getLiveId(), JSON.toJSONString(liveAutoTask),liveAutoTask.getAbsValue().getTime());
                     });
                 }
+                // 直播间关闭时,下架所有直播商品
+                try {
+                    liveGoodsService.unshelfAllGoodsByLiveId(live.getLiveId());
+                } catch (Exception e) {
+                    log.error("直播间关闭下架所有商品失败, liveId: {}", live.getLiveId(), e);
+                }
                 String cacheKey = String.format(LiveKeysConstant.LIVE_DATA_CACHE, live.getLiveId());
                 redisCache.deleteObject(cacheKey);
                 webSocketServer.removeLikeCountCache(live.getLiveId());

+ 7 - 0
fs-service-system/src/main/java/com/fs/live/mapper/LiveGoodsMapper.java

@@ -175,4 +175,11 @@ public interface LiveGoodsMapper {
     int updateBatchById(@Param("list") List<LiveGoods> liveGoodsList);
 
     int updateStock(@Param("goodsId") Long goodsId, @Param("goodsNum") Integer goodsNum);
+
+    /**
+     * 根据直播ID下架所有商品(status置为0,is_show置为0)
+     * @param liveId 直播ID
+     */
+    @Update("update live_goods set status = 0, is_show = 0 where live_id = #{liveId} and status = 1")
+    int unshelfAllGoodsByLiveId(@Param("liveId") Long liveId);
 }

+ 6 - 0
fs-service-system/src/main/java/com/fs/live/service/ILiveGoodsService.java

@@ -130,4 +130,10 @@ public interface ILiveGoodsService {
     List<LiveGoods> listAll();
 
     void updateBatchById(List<LiveGoods> logsToInsert);
+
+    /**
+     * 根据直播ID下架所有商品(status置为0,is_show置为0)
+     * @param liveId 直播ID
+     */
+    void unshelfAllGoodsByLiveId(Long liveId);
 }

+ 8 - 0
fs-service-system/src/main/java/com/fs/live/service/impl/LiveGoodsServiceImpl.java

@@ -504,4 +504,12 @@ public class LiveGoodsServiceImpl  implements ILiveGoodsService {
         baseMapper.handleIsShowChange(listVo);
         return R.ok().put("isShow", listVo.getIsShow());
     }
+
+    @Override
+    public void unshelfAllGoodsByLiveId(Long liveId) {
+        if (liveId == null) {
+            return;
+        }
+        baseMapper.unshelfAllGoodsByLiveId(liveId);
+    }
 }

+ 4 - 0
fs-service-system/src/main/java/com/fs/live/service/impl/LiveServiceImpl.java

@@ -477,6 +477,8 @@ public class LiveServiceImpl implements ILiveService
             } else {
                 live.setLiveType(1);
                 live.setStatus(3);
+                // 直播间状态改为3(已结束),下架所有直播商品
+                liveGoodsService.unshelfAllGoodsByLiveId(live.getLiveId());
             }
             live.setLiveConfig(JSON.toJSONString(liveReplayParam));
 
@@ -749,6 +751,8 @@ public class LiveServiceImpl implements ILiveService
         exist.setUpdateTime(new Date());
 
         baseMapper.updateLive(exist);
+        // 直播间状态改为3(已结束),下架所有直播商品
+        liveGoodsService.unshelfAllGoodsByLiveId(live.getLiveId());
         // 清除缓存
         clearLiveCache(live.getLiveId());