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) {