From 614492b9d0c6a0c655cdaf242eb8bde2ca704a52 Mon Sep 17 00:00:00 2001 From: lth <987594455@qq.com> Date: Mon, 2 Aug 2021 16:35:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=86=E7=B1=BB=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E6=98=AF=E5=90=A6=E9=87=8D=E5=A4=8D=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mall4j/cloud/product/mapper/CategoryMapper.java | 7 +++---- .../product/service/impl/CategoryServiceImpl.java | 12 ++++++------ .../src/main/resources/mapper/CategoryMapper.xml | 11 +++++++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/mall4cloud-product/src/main/java/com/mall4j/cloud/product/mapper/CategoryMapper.java b/mall4cloud-product/src/main/java/com/mall4j/cloud/product/mapper/CategoryMapper.java index 3b12de8c..cfe5f18b 100644 --- a/mall4cloud-product/src/main/java/com/mall4j/cloud/product/mapper/CategoryMapper.java +++ b/mall4cloud-product/src/main/java/com/mall4j/cloud/product/mapper/CategoryMapper.java @@ -89,13 +89,12 @@ public interface CategoryMapper { int updateBatchOfStatus(@Param("categoryIds") List categoryIds, @Param("status") Integer status); /** - * 根据分类名获取分类的数量 + * 查询分类名是否存在 * - * @param categoryId - * @param name + * @param category * @return */ - int getCountByName(@Param("categoryId") Long categoryId, @Param("name") String name); + int existCategoryName(@Param("category") Category category); /** * 根据分类id列表,获取分类列表 diff --git a/mall4cloud-product/src/main/java/com/mall4j/cloud/product/service/impl/CategoryServiceImpl.java b/mall4cloud-product/src/main/java/com/mall4j/cloud/product/service/impl/CategoryServiceImpl.java index 00625026..53e39d51 100644 --- a/mall4cloud-product/src/main/java/com/mall4j/cloud/product/service/impl/CategoryServiceImpl.java +++ b/mall4cloud-product/src/main/java/com/mall4j/cloud/product/service/impl/CategoryServiceImpl.java @@ -54,7 +54,7 @@ public CategoryVO getById(Long categoryId) { @Override public void save(Category category) { - checkName(null, category.getName()); + existCategoryName(category); category.setShopId(AuthUserContext.get().getTenantId()); String path = ""; if (!Objects.equals(CategoryLevel.First.value(), category.getLevel())) { @@ -76,7 +76,7 @@ public void update(Category category) { if (Objects.equals(dbCategory.getCategoryId(), category.getParentId())) { throw new Mall4cloudException("分类不能成为本身的上级分类"); } - checkName(category.getCategoryId(), category.getName()); + existCategoryName(category); int updateCount = categoryMapper.update(category); } @@ -251,11 +251,11 @@ private void setChildCategory(List categories, List chil /** * 校验分类名是否已存在 * - * @param categoryId - * @param name + * @param category */ - private void checkName(Long categoryId, String name) { - int countByName = categoryMapper.getCountByName(categoryId, name); + private void existCategoryName(Category category) { + category.setShopId(AuthUserContext.get().getTenantId()); + int countByName = categoryMapper.existCategoryName(category); if (countByName > 0) { throw new Mall4cloudException("分类名已存在,请重新输入"); } diff --git a/mall4cloud-product/src/main/resources/mapper/CategoryMapper.xml b/mall4cloud-product/src/main/resources/mapper/CategoryMapper.xml index c4ae48ef..49e92ddb 100644 --- a/mall4cloud-product/src/main/resources/mapper/CategoryMapper.xml +++ b/mall4cloud-product/src/main/resources/mapper/CategoryMapper.xml @@ -92,10 +92,13 @@ - + SELECT COUNT(*) FROM category WHERE `name` = #{category.name} AND parent_id = #{category.parentId} + + AND category_id != #{category.categoryId} + + + AND shop_id = #{category.shopId}