From 5dfc1d9e5c891225a69ec88a74ba7f83153adaf6 Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期三, 22 五月 2024 20:00:48 +0800
Subject: [PATCH] 1.提交【管理后台】团购管理模块接口 2.延时任务部分代码

---
 ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSkuServiceImpl.java |   35 +++++++++++++++++++++++++++++++----
 1 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSkuServiceImpl.java b/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSkuServiceImpl.java
index 7503e73..41eaf12 100644
--- a/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSkuServiceImpl.java
+++ b/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSkuServiceImpl.java
@@ -4,6 +4,7 @@
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.ruoyi.common.core.enums.ListingStatusEnum;
 import com.ruoyi.common.core.exception.ServiceException;
 import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.core.utils.page.BeanUtils;
@@ -14,10 +15,14 @@
 import com.ruoyi.goods.controller.management.DTO.GoodsSkuDTO;
 import com.ruoyi.goods.controller.management.DTO.GoodsSkuQuery;
 import com.ruoyi.goods.controller.management.VO.GoodsSkuVO;
+import com.ruoyi.goods.domain.GoodsGroupPurchase;
 import com.ruoyi.goods.domain.GoodsInfoTitleValue;
+import com.ruoyi.goods.domain.GoodsSeckill;
 import com.ruoyi.goods.domain.GoodsSku;
 import com.ruoyi.goods.mapper.GoodsSkuMapper;
+import com.ruoyi.goods.service.IGoodsGroupPurchaseService;
 import com.ruoyi.goods.service.IGoodsInfoTitleValueService;
+import com.ruoyi.goods.service.IGoodsSeckillService;
 import com.ruoyi.goods.service.IGoodsSkuService;
 import com.ruoyi.system.api.domain.dto.ListStatusDTO;
 import java.util.List;
@@ -25,6 +30,7 @@
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -41,6 +47,8 @@
 public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> implements IGoodsSkuService {
 
     private final IGoodsInfoTitleValueService goodsInfoTitleValueService;
+    private final IGoodsSeckillService goodsSeckillService;
+    private final IGoodsGroupPurchaseService goodsGroupPurchaseService;
     private static final ObjectMapper objectMapper = new ObjectMapper();
 
     /**
@@ -140,8 +148,9 @@
                         query.getSkuName())
                 .eq(StringUtils.isNotNull(query.getListingStatus()
                 ), GoodsSku::getListingStatus, query.getListingStatus())
-                .page(new Page<GoodsSku>(query.getPageCurr(), query.getPageSize()));
-
+                .eq(query.getQueryType().equals(1), GoodsSku::getListingStatus,
+                        ListingStatusEnum.ON_SHELVES)
+                .page(new Page<>(query.getPageCurr(), query.getPageSize()));
         return PageDTO.of(page, GoodsSkuVO.class);
     }
 
@@ -149,13 +158,31 @@
      * 更新商品SKU的状态。
      *
      * @param dto 数据传输对象,包含需要更新的SKU的ID和新的上架状态。 其中,ID用于指定要更新的具体SKU,listingStatus用于指定新的上架状态。
-     * @return 无返回值。
      */
     @Override
-    public void updStatus(ListStatusDTO dto) {
+    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
+    public void updStatus(ListStatusDTO dto) throws Exception {
         this.lambdaUpdate()
                 .eq(GoodsSku::getId, dto.getId())
                 .set(GoodsSku::getListingStatus, dto.getListingStatus())
                 .update();
+        //关联的秒杀商品和团购商品同步下架
+        if (dto.getListingStatus().equals(ListingStatusEnum.REMOVED_FROM_THE_SHELF)) {
+            updateGoodsStatus(dto);
+        }
+    }
+
+    private void updateGoodsStatus(ListStatusDTO dto) {
+        goodsSeckillService.lambdaUpdate()
+                .set(GoodsSeckill::getListingStatus,
+                        ListingStatusEnum.REMOVED_FROM_THE_SHELF)
+                .eq(GoodsSeckill::getListingStatus, ListingStatusEnum.ON_SHELVES)
+                .eq(GoodsSeckill::getGoodsSkuId, dto.getId()).update();
+        goodsGroupPurchaseService.lambdaUpdate()
+                .set(GoodsGroupPurchase::getListingStatus,
+                        ListingStatusEnum.REMOVED_FROM_THE_SHELF)
+                .eq(GoodsGroupPurchase::getListingStatus,
+                        ListingStatusEnum.ON_SHELVES)
+                .eq(GoodsGroupPurchase::getGoodsSkuId, dto.getId()).update();
     }
 }

--
Gitblit v1.7.1