From d8f7b49d9cb77f29a7830523f006fb1dc8ee849e Mon Sep 17 00:00:00 2001 From: hupeng Date: Wed, 27 May 2020 18:35:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=86=E7=B1=BB=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=9C=80=E5=A4=9A=E5=8F=AA=E8=83=BD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?2=E7=BA=A7=E7=9A=84=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/rest/StoreCategoryController.java | 12 +++++++++ .../shop/service/YxStoreCategoryService.java | 3 +++ .../impl/YxStoreCategoryServiceImpl.java | 27 +++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/yshop-shop/src/main/java/co/yixiang/modules/shop/rest/StoreCategoryController.java b/yshop-shop/src/main/java/co/yixiang/modules/shop/rest/StoreCategoryController.java index 90a587ab..22c6b8f2 100644 --- a/yshop-shop/src/main/java/co/yixiang/modules/shop/rest/StoreCategoryController.java +++ b/yshop-shop/src/main/java/co/yixiang/modules/shop/rest/StoreCategoryController.java @@ -14,6 +14,7 @@ import co.yixiang.modules.shop.service.YxStoreCategoryService; import co.yixiang.modules.shop.service.dto.YxStoreCategoryDto; import co.yixiang.modules.shop.service.dto.YxStoreCategoryQueryCriteria; import co.yixiang.utils.OrderUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.cache.annotation.CacheEvict; @@ -33,6 +34,7 @@ import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.sql.Wrapper; import java.util.List; /** @@ -82,6 +84,12 @@ public class StoreCategoryController { throw new BadRequestException("子分类图片必传"); } + + boolean checkResult = yxStoreCategoryService.checkCategory(resources.getPid()); + + if(!checkResult) throw new BadRequestException("分类最多能添加2级哦"); + + resources.setAddTime(OrderUtil.getSecondTimestampTwo()); return new ResponseEntity(yxStoreCategoryService.save(resources),HttpStatus.CREATED); } @@ -96,6 +104,10 @@ public class StoreCategoryController { if(resources.getPid() > 0 && StrUtil.isBlank(resources.getPic())) { throw new BadRequestException("子分类图片必传"); } + boolean checkResult = yxStoreCategoryService.checkCategory(resources.getPid()); + + if(!checkResult) throw new BadRequestException("分类最多能添加2级哦"); + yxStoreCategoryService.saveOrUpdate(resources); return new ResponseEntity(HttpStatus.NO_CONTENT); } diff --git a/yshop-shop/src/main/java/co/yixiang/modules/shop/service/YxStoreCategoryService.java b/yshop-shop/src/main/java/co/yixiang/modules/shop/service/YxStoreCategoryService.java index f3ac761d..3c5f9cfa 100644 --- a/yshop-shop/src/main/java/co/yixiang/modules/shop/service/YxStoreCategoryService.java +++ b/yshop-shop/src/main/java/co/yixiang/modules/shop/service/YxStoreCategoryService.java @@ -46,4 +46,7 @@ public interface YxStoreCategoryService extends BaseService{ void download(List all, HttpServletResponse response) throws IOException; Object buildTree(List categoryDTOList); + + + boolean checkCategory(int pid); } diff --git a/yshop-shop/src/main/java/co/yixiang/modules/shop/service/impl/YxStoreCategoryServiceImpl.java b/yshop-shop/src/main/java/co/yixiang/modules/shop/service/impl/YxStoreCategoryServiceImpl.java index 578606f6..76a13b74 100644 --- a/yshop-shop/src/main/java/co/yixiang/modules/shop/service/impl/YxStoreCategoryServiceImpl.java +++ b/yshop-shop/src/main/java/co/yixiang/modules/shop/service/impl/YxStoreCategoryServiceImpl.java @@ -5,6 +5,7 @@ */ package co.yixiang.modules.shop.service.impl; +import cn.hutool.core.date.DateUtil; import co.yixiang.common.service.impl.BaseServiceImpl; import co.yixiang.common.utils.QueryHelpPlus; import co.yixiang.dozer.service.IGenerator; @@ -14,6 +15,7 @@ import co.yixiang.modules.shop.service.dto.YxStoreCategoryDto; import co.yixiang.modules.shop.service.dto.YxStoreCategoryQueryCriteria; import co.yixiang.modules.shop.service.mapper.StoreCategoryMapper; import co.yixiang.utils.FileUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.github.pagehelper.PageInfo; import lombok.AllArgsConstructor; import org.springframework.data.domain.Pageable; @@ -134,4 +136,29 @@ public class YxStoreCategoryServiceImpl extends BaseServiceImpllambdaQuery() + .eq(YxStoreCategory::getId,pid)); + if(yxStoreCategory.getPid() > 0) return false; + + return true; + } + +// public boolean checkCategory(int id,int pid){ +// YxStoreCategory yxStoreCategory = this.getOne(Wrappers.lambdaQuery() +// .eq(YxStoreCategory::getPid,pid)); +// +// // DateUtil.format() +// +// return true; +// } + }