Sfoglia il codice sorgente

商家过期或关店 自动下架商品

guomengjiao 1 mese fa
parent
commit
f345c8a0a4

+ 2 - 1
ruoyi-business/src/main/java/com/ruoyi/business/exception/BusinessExceptionEnum.java

@@ -23,7 +23,8 @@ public enum BusinessExceptionEnum implements IIntegerEnum {
     BUSINESS_NOT_CLOSE( 500010, "当前商户未关闭"),
     BUSINESS_NOT_VALID( 500011, "目标已被关闭或已过期"),
     BUSINESS_NOT_MOVE_SELF( 500012, "不能移动到同样的商户家"),
-    QUEUE_COMPLETE( 500013, "排队已完成");
+    QUEUE_COMPLETE( 500013, "排队已完成"),
+    BUSINESS_PRODUCT_DOWN_SHELF_FAIL(500014, "该商户商品下架失败");
 
     private Integer code;
 

+ 21 - 0
ruoyi-business/src/main/java/com/ruoyi/business/service/impl/BusinessServiceImpl.java

@@ -57,6 +57,7 @@ import com.ruoyi.system.service.ISysOssService;
 import com.ruoyi.tool.service.JzqService;
 import com.ruoyi.user.service.IUserService;
 import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
@@ -79,6 +80,7 @@ import java.util.stream.Collectors;
  */
 @RequiredArgsConstructor
 @Service
+@Slf4j
 public class BusinessServiceImpl implements IBusinessService {
 
     private final BusinessMapper baseMapper;
@@ -646,6 +648,22 @@ public class BusinessServiceImpl implements IBusinessService {
     public void autoExpires(Business business) {
         business.setExpiresStatus(true);
         baseMapper.updateById(business);
+        //下架商品 下架失败暂不处理
+        downShelfProduct(business.getBusinessId(), false);
+    }
+
+    //下架商品
+    private void downShelfProduct(Long businessId, Boolean tw) {
+        try {
+            //查商户下处于上架的商品id
+            List<Long> productIds = iProductInnerApi.queryShelvedProductIdsByBusinessId(businessId);
+            iProductInnerApi.downShelfProduct(businessId, productIds);
+        } catch (Exception e) {
+            log.error("下架商品异常{}", businessId, e);
+            if (tw) {
+                throw new ServiceException(BusinessExceptionEnum.BUSINESS_PRODUCT_DOWN_SHELF_FAIL);
+            }
+        }
     }
 
     @Override
@@ -667,6 +685,7 @@ public class BusinessServiceImpl implements IBusinessService {
         return baseMapper.updateById(business) > 0;
     }
 
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public void close(Long businessId) {
         Business business = loadById(businessId, true);
@@ -675,6 +694,8 @@ public class BusinessServiceImpl implements IBusinessService {
         }
         business.setCloseStatus(true);
         baseMapper.updateById(business);
+        //下架商品
+        downShelfProduct(businessId, true);
     }
 
     @Transactional(rollbackFor = Exception.class)

+ 14 - 1
ruoyi-shop-api/src/main/java/com/ruoyi/shop/product/IProductInnerApi.java

@@ -1,6 +1,8 @@
 package com.ruoyi.shop.product;
 
 
+import java.util.List;
+
 public interface IProductInnerApi {
 
     /**
@@ -24,6 +26,17 @@ public interface IProductInnerApi {
      */
     void batchUpdate(Long businessId, String businessName);
 
+    /**
+     * 查询已上架商品
+     * @param businessId
+     * @return
+     */
+    List<Long> queryShelvedProductIdsByBusinessId(Long businessId);
 
-
+    /**
+     * 下架商品
+     * @param businessId
+     * @param productIds
+     */
+    void downShelfProduct(Long businessId, List<Long> productIds);
 }

+ 14 - 0
ruoyi-shop/src/main/java/com/ruoyi/shop/product/service/IProductService.java

@@ -162,4 +162,18 @@ public interface IProductService {
      * @return Product
      */
     Product getByBusinessIdAndId(Long businessId, Long productId);
+
+    /**
+     *
+     * 获取商家上架产品
+     * @return Product
+     */
+    List<Long> queryShelvedProductIdsByBusinessId(Long businessId);
+
+    /**
+     *
+     * 获取商家下架产品
+     * @return Product
+     */
+    void downShelfProduct(Long businessId, List<Long> productIds);
 }

+ 12 - 1
ruoyi-shop/src/main/java/com/ruoyi/shop/product/service/impl/ProductInnerApiImpl.java

@@ -8,16 +8,18 @@ import com.ruoyi.shop.config.service.IShopSaleConfigService;
 import com.ruoyi.shop.product.IProductInnerApi;
 import com.ruoyi.shop.product.domain.Product;
 import com.ruoyi.shop.product.mapper.ProductMapper;
+import com.ruoyi.shop.product.service.IProductService;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 
-import java.math.BigDecimal;
+import java.util.List;
 
 @RequiredArgsConstructor
 @Service
 public class ProductInnerApiImpl implements IProductInnerApi {
 
     private final ProductMapper baseMapper;
+    private final IProductService productService;
 
     private final IShopSaleConfigService shopSaleConfigService;
 
@@ -48,6 +50,15 @@ public class ProductInnerApiImpl implements IProductInnerApi {
         );
     }
 
+    @Override
+    public List<Long> queryShelvedProductIdsByBusinessId(Long businessId) {
+        return productService.queryShelvedProductIdsByBusinessId(businessId);
+    }
+
+    @Override
+    public void downShelfProduct(Long businessId, List<Long> productIds) {
+        productService.downShelfProduct(businessId, productIds);
+    }
 
 
 }

+ 24 - 0
ruoyi-shop/src/main/java/com/ruoyi/shop/product/service/impl/ProductServiceImpl.java

@@ -593,5 +593,29 @@ public class ProductServiceImpl implements IProductService {
         return product;
     }
 
+    @Override
+    public List<Long> queryShelvedProductIdsByBusinessId(Long businessId) {
+        return baseMapper.selectList(new LambdaQueryWrapper<Product>()
+            .select(Product::getProductId)
+            .eq(Product::getBusinessId, businessId)
+            .eq(Product::getShelvedStatus, true)
+            .eq(Product::getAuditStatus, AuditStatus.AUDIT_PASS)
+        ).stream().map(Product::getProductId).collect(Collectors.toList());
+    }
+
+    @Override
+    public void downShelfProduct(Long businessId, List<Long> productIds) {
+        baseMapper.update(null, new LambdaUpdateWrapper<Product>()
+            .set(Product::getShelvedStatus, false)
+            .in(Product::getProductId, productIds)
+        );
+        userShoppingCartMapper.update(null, new LambdaUpdateWrapper<UserShoppingCart>()
+            .eq(UserShoppingCart::getBusinessId, businessId)
+            .in(UserShoppingCart::getProductId, productIds)
+            .eq(UserShoppingCart::getEffectiveStatus, CartEffectiveStatus.NORMAL)
+            .set(UserShoppingCart::getEffectiveStatus, CartEffectiveStatus.UNDER_CARRIAGE)
+        );
+    }
+
 
 }