From 4f4704ab50db18f160cade34e34ae08e57cfe2e4 Mon Sep 17 00:00:00 2001 From: Chopper Date: Wed, 22 Sep 2021 11:10:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=B1=BB=E4=B8=8E=E5=90=84=E4=B8=AA?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E7=BB=91=E5=AE=9A=E5=90=8E=EF=BC=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=85=B3=E7=B3=BB=E6=9C=AA=E6=B8=85=E7=90=86=E5=B9=B2?= =?UTF-8?q?=E5=87=80=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86=E3=80=82=20?= =?UTF-8?q?=E5=93=81=E7=89=8C=E5=88=A0=E9=99=A4=E6=97=B6=EF=BC=8C=E4=B8=8E?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E5=8F=91=E7=94=9F=E7=BB=91=E5=AE=9A=EF=BC=8C?= =?UTF-8?q?=E5=88=99=E8=BF=94=E5=9B=9E=E5=88=86=E7=B1=BB=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=EF=BC=8C=E5=8D=8F=E5=8A=A9=E8=A7=A3=E9=99=A4=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/lili/common/enums/ResultCode.java | 2 +- .../cn/lili/modules/goods/entity/dos/Brand.java | 11 +++++------ .../service/CategoryParameterGroupService.java | 8 +++++++- .../goods/serviceimpl/BrandServiceImpl.java | 15 +++++++++++++-- .../CategoryParameterGroupServiceImpl.java | 7 +++++++ .../goods/serviceimpl/CategoryServiceImpl.java | 16 ++++++++++++++++ .../controller/goods/BrandManagerController.java | 2 +- 7 files changed, 50 insertions(+), 11 deletions(-) diff --git a/framework/src/main/java/cn/lili/common/enums/ResultCode.java b/framework/src/main/java/cn/lili/common/enums/ResultCode.java index 4ba61c93..7ec859f7 100644 --- a/framework/src/main/java/cn/lili/common/enums/ResultCode.java +++ b/framework/src/main/java/cn/lili/common/enums/ResultCode.java @@ -97,7 +97,7 @@ public enum ResultCode { BRAND_DISABLE_ERROR(14003, "品牌禁用失败"), BRAND_DELETE_ERROR(14004, "品牌删除失败"), BRAND_NAME_EXIST_ERROR(20002, "品牌名称重复!"), - BRAND_USE_DISABLE_ERROR(20003, "当前品牌下存在分类不可禁用"), + BRAND_USE_DISABLE_ERROR(20003, "分类已经绑定此品牌,请先解除关联"), BRAND_NOT_EXIST(20004, "品牌不存在"), /** diff --git a/framework/src/main/java/cn/lili/modules/goods/entity/dos/Brand.java b/framework/src/main/java/cn/lili/modules/goods/entity/dos/Brand.java index 9fd66c05..777dec34 100644 --- a/framework/src/main/java/cn/lili/modules/goods/entity/dos/Brand.java +++ b/framework/src/main/java/cn/lili/modules/goods/entity/dos/Brand.java @@ -7,6 +7,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Size; /** * 商品品牌 @@ -21,16 +22,14 @@ public class Brand extends BaseEntity { private static final long serialVersionUID = -8236865838438521426L; - /** - * 品牌名称 - */ + @NotEmpty(message = "品牌名称不能为空") + @Size(max = 20, message = "品牌名称应该小于20长度字符") @ApiModelProperty(value = "品牌名称", required = true) private String name; - /** - * 品牌图标 - */ + @NotEmpty(message = "品牌图标不能为空") + @Size(max = 255, message = "品牌图标地址长度超过255字符") @ApiModelProperty(value = "品牌图标", required = true) private String logo; diff --git a/framework/src/main/java/cn/lili/modules/goods/service/CategoryParameterGroupService.java b/framework/src/main/java/cn/lili/modules/goods/service/CategoryParameterGroupService.java index cee22438..f114195a 100644 --- a/framework/src/main/java/cn/lili/modules/goods/service/CategoryParameterGroupService.java +++ b/framework/src/main/java/cn/lili/modules/goods/service/CategoryParameterGroupService.java @@ -39,5 +39,11 @@ public interface CategoryParameterGroupService extends IService implements @Autowired private CategoryBrandService categoryBrandService; + @Autowired + private CategoryService categoryService; + @Override public IPage getBrandsByPage(BrandPageDTO page) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); @@ -81,8 +86,14 @@ public class BrandServiceImpl extends ServiceImpl implements @Override public boolean brandDisable(String brandId, boolean disable) { Brand brand = this.checkExist(brandId); - if (Boolean.TRUE.equals(disable) && !categoryBrandService.getCategoryBrandListByBrandId(brandId).isEmpty()) { - throw new ServiceException(ResultCode.BRAND_USE_DISABLE_ERROR); + if (Boolean.TRUE.equals(disable)) { + List categoryBrands = categoryBrandService.getCategoryBrandListByBrandId(brandId); + List brandIds = categoryBrands.stream().map(categoryBrand -> { + return categoryBrand.getCategoryId(); + }).collect(Collectors.toList()); + + throw new ServiceException(ResultCode.BRAND_USE_DISABLE_ERROR, + JSONUtil.toJsonStr(categoryService.getCategoryNameByIds(brandIds))); } brand.setDeleteFlag(disable); return updateById(brand); diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/CategoryParameterGroupServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/CategoryParameterGroupServiceImpl.java index 180e17c5..1e3161ac 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/CategoryParameterGroupServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/CategoryParameterGroupServiceImpl.java @@ -2,6 +2,7 @@ package cn.lili.modules.goods.serviceimpl; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; +import cn.lili.modules.goods.entity.dos.CategoryBrand; import cn.lili.modules.goods.entity.dos.CategoryParameterGroup; import cn.lili.modules.goods.entity.dos.Parameters; import cn.lili.modules.goods.entity.vos.ParameterGroupVO; @@ -9,6 +10,7 @@ import cn.lili.modules.goods.mapper.CategoryParameterGroupMapper; import cn.lili.modules.goods.service.CategoryParameterGroupService; import cn.lili.modules.goods.service.ParametersService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -67,6 +69,11 @@ public class CategoryParameterGroupServiceImpl extends ServiceImpl().eq(CategoryParameterGroup::getCategoryId, categoryId)); + } + /** * 拼装参数组和参数的返回值 * diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/CategoryServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/CategoryServiceImpl.java index 46c8ceb4..ab31d983 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/CategoryServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/CategoryServiceImpl.java @@ -11,7 +11,10 @@ import cn.lili.modules.goods.entity.vos.CategoryVO; import cn.lili.modules.goods.entity.vos.GoodsParamsGroupVO; import cn.lili.modules.goods.entity.vos.GoodsParamsVO; import cn.lili.modules.goods.mapper.CategoryMapper; +import cn.lili.modules.goods.service.CategoryBrandService; +import cn.lili.modules.goods.service.CategoryParameterGroupService; import cn.lili.modules.goods.service.CategoryService; +import cn.lili.modules.goods.service.CategorySpecificationService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; @@ -43,6 +46,15 @@ public class CategoryServiceImpl extends ServiceImpl i @Autowired private Cache cache; + @Autowired + private CategoryBrandService categoryBrandService; + + @Autowired + private CategoryParameterGroupService categoryParameterGroupService; + + @Autowired + private CategorySpecificationService categorySpecificationService; + @Override public List dbList(String parentId) { return this.list(new LambdaQueryWrapper().eq(Category::getParentId, parentId)); @@ -227,6 +239,10 @@ public class CategoryServiceImpl extends ServiceImpl i public void delete(String id) { this.removeById(id); removeCache(); + //删除关联关系 + categoryBrandService.deleteByCategoryId(id); + categoryParameterGroupService.deleteByCategoryId(id); + categorySpecificationService.deleteByCategoryId(id); } @Override diff --git a/manager-api/src/main/java/cn/lili/controller/goods/BrandManagerController.java b/manager-api/src/main/java/cn/lili/controller/goods/BrandManagerController.java index 4b187583..169a0e7d 100644 --- a/manager-api/src/main/java/cn/lili/controller/goods/BrandManagerController.java +++ b/manager-api/src/main/java/cn/lili/controller/goods/BrandManagerController.java @@ -83,7 +83,7 @@ public class BrandManagerController { @ApiOperation(value = "后台禁用品牌") @ApiImplicitParams({ @ApiImplicitParam(name = "brandId", value = "品牌ID", required = true, dataType = "String", paramType = "path"), - @ApiImplicitParam(name = "id", value = "是否不可用", required = true, dataType = "String", paramType = "query") + @ApiImplicitParam(name = "disable", value = "是否可用", required = true, dataType = "boolean", paramType = "query") }) @PutMapping(value = "/disable/{brandId}") public ResultMessage disable(@PathVariable String brandId, @RequestParam Boolean disable) {