浏览代码

该分类如果已经有店铺占用,那分类不能删除

lyhzzz 2 年之前
父节点
当前提交
06a2260e3e

+ 2 - 1
src/main/java/com/cdf/common/ResultCode.java

@@ -28,7 +28,8 @@ public enum ResultCode {
     UPLOAD_FILE_NO_EXIST(7002,"上传文件不存在"),
     UPLOAD_FILE_TO_LONG(7003,"文件上传过大"),
 
-    MOVE_FOLDER_ERROR(7004,"移动文件夹错误");
+    MOVE_FOLDER_ERROR(8004,"移动文件夹错误"),
+    DEL_SHOP_CATEGORY_ERROR(8004,"该店铺分类存在店铺,请先删除店铺");
 
     public int code;
     public String msg;

+ 8 - 0
src/main/java/com/cdf/controller/back/ShopCategoryController.java

@@ -7,11 +7,13 @@ import com.cdf.common.LogInfoKey;
 import com.cdf.common.PageInfo;
 import com.cdf.common.ResultCode;
 import com.cdf.common.ResultData;
+import com.cdf.entity.Shop;
 import com.cdf.entity.ShopCategory;
 import com.cdf.exception.BusinessException;
 import com.cdf.request.BaseRequest;
 import com.cdf.service.ILogService;
 import com.cdf.service.IShopCategoryService;
+import com.cdf.service.IShopService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -28,6 +30,8 @@ public class ShopCategoryController extends BaseLogController{
     private IShopCategoryService shopCategoryService;
     @Autowired
     private ILogService logService;
+    @Autowired
+    private IShopService shopService;
 
     @PostMapping("/saveOrUpdate")
     public ResultData saveOrUpdate(@RequestBody ShopCategory shopCategory){
@@ -48,6 +52,10 @@ public class ShopCategoryController extends BaseLogController{
         if(shopCategory.getId() == null){
             throw new BusinessException(ResultCode.PARAM_MISS);
         }
+        List<Shop> shops = shopService.getByCategory(shopCategory.getId());
+        if(shops.size() >0){
+            throw new BusinessException(ResultCode.DEL_SHOP_CATEGORY_ERROR);
+        }
         ShopCategory shopCategory1 = shopCategoryService.getById(shopCategory.getId());
         if(shopCategory1!=null){
             shopCategoryService.removeById(shopCategory.getId());

+ 4 - 0
src/main/java/com/cdf/service/IShopService.java

@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.cdf.request.ShopRequest;
 import com.cdf.response.ShopVo;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务类
@@ -17,4 +19,6 @@ import com.cdf.response.ShopVo;
 public interface IShopService extends IService<Shop> {
 
     PageInfo pageList(ShopRequest param);
+
+    List<Shop>  getByCategory(Integer categoryId);
 }

+ 7 - 0
src/main/java/com/cdf/service/impl/ShopServiceImpl.java

@@ -78,4 +78,11 @@ public class ShopServiceImpl extends ServiceImpl<IShopMapper, Shop> implements I
         pageVo.setTotal(page.getTotal());
         return PageInfo.PageInfo(pageVo);
     }
+
+    @Override
+    public List<Shop> getByCategory(Integer categoryId) {
+        LambdaQueryWrapper<Shop> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(Shop::getCategoryId,categoryId);
+        return this.list(wrapper);
+    }
 }