From affc3d2170f80de7c05ba32603f092d51e934a21 Mon Sep 17 00:00:00 2001 From: LGH <1242479791@qq.com> Date: Tue, 12 Nov 2019 17:56:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=B1=BB=E5=90=8D=E7=A7=B0=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/CategoryController.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/yami-shop-admin/src/main/java/com/yami/shop/admin/controller/CategoryController.java b/yami-shop-admin/src/main/java/com/yami/shop/admin/controller/CategoryController.java index 113b2f8..6081ca6 100644 --- a/yami-shop-admin/src/main/java/com/yami/shop/admin/controller/CategoryController.java +++ b/yami-shop-admin/src/main/java/com/yami/shop/admin/controller/CategoryController.java @@ -16,6 +16,7 @@ import java.util.Objects; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.yami.shop.common.exception.YamiShopBindException; import com.yami.shop.security.util.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; @@ -51,7 +52,7 @@ public class CategoryController { @Autowired private CategoryService categoryService; - + /** * 获取菜单页面的表 * @return @@ -62,7 +63,7 @@ public class CategoryController { List categoryMenuList = categoryService.tableCategory(SecurityUtils.getSysUser().getShopId()); return ResponseEntity.ok(categoryMenuList); } - + /** * 获取分类信息 */ @@ -71,9 +72,9 @@ public class CategoryController { Category category = categoryService.getById(categoryId); return ResponseEntity.ok(category); } - - - + + + /** * 保存分类 */ @@ -83,10 +84,15 @@ public class CategoryController { public ResponseEntity save(@RequestBody Category category){ category.setShopId(SecurityUtils.getSysUser().getShopId()); category.setRecTime(new Date()); + Category categoryName = categoryService.getOne(new LambdaQueryWrapper().eq(Category::getCategoryName,category.getCategoryName()) + .eq(Category::getShopId,category.getShopId())); + if(categoryName != null){ + throw new YamiShopBindException("类目名称已存在!"); + } categoryService.saveCategroy(category); return ResponseEntity.ok().build(); } - + /** * 更新分类 */ @@ -98,10 +104,15 @@ public class CategoryController { if (Objects.equals(category.getParentId(),category.getCategoryId())) { return ResponseEntity.badRequest().body("分类的上级不能是自己本身"); } + Category categoryName = categoryService.getOne(new LambdaQueryWrapper().eq(Category::getCategoryName,category.getCategoryName()) + .eq(Category::getShopId,category.getShopId()).ne(Category::getCategoryId,category.getCategoryId())); + if(categoryName != null){ + throw new YamiShopBindException("类目名称已存在!"); + } categoryService.updateCategroy(category); return ResponseEntity.ok().build(); } - + /** * 删除分类 */ @@ -115,7 +126,7 @@ public class CategoryController { categoryService.deleteCategroy(categoryId); return ResponseEntity.ok().build(); } - + /** * 所有的 */ @@ -127,7 +138,7 @@ public class CategoryController { .eq(Category::getShopId, SecurityUtils.getSysUser().getShopId()) .orderByAsc(Category::getSeq))); } - + /** * 所有的产品分类 */