分类与各个参数绑定后,删除关系未清理干净问题处理。
品牌删除时,与分类发生绑定,则返回分类信息,协助解除绑定。
This commit is contained in:
parent
505366d9bc
commit
4f4704ab50
@ -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, "品牌不存在"),
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
||||
|
@ -40,4 +40,10 @@ public interface CategoryParameterGroupService extends IService<CategoryParamete
|
||||
*/
|
||||
boolean updateCategoryGroup(CategoryParameterGroup categoryParameterGroup);
|
||||
|
||||
/**
|
||||
* 通过分类ID删除关联品牌
|
||||
* @param categoryId 品牌ID
|
||||
*/
|
||||
void deleteByCategoryId(String categoryId);
|
||||
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
package cn.lili.modules.goods.serviceimpl;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.modules.goods.service.CategoryService;
|
||||
import cn.lili.mybatis.util.PageUtil;
|
||||
import cn.lili.modules.goods.entity.dos.Brand;
|
||||
import cn.lili.modules.goods.entity.dos.CategoryBrand;
|
||||
@ -39,6 +41,9 @@ public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements
|
||||
@Autowired
|
||||
private CategoryBrandService categoryBrandService;
|
||||
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
@Override
|
||||
public IPage<Brand> getBrandsByPage(BrandPageDTO page) {
|
||||
LambdaQueryWrapper<Brand> queryWrapper = new LambdaQueryWrapper<>();
|
||||
@ -81,8 +86,14 @@ public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> 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<CategoryBrand> categoryBrands = categoryBrandService.getCategoryBrandListByBrandId(brandId);
|
||||
List<String> 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);
|
||||
|
@ -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<CategoryParam
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByCategoryId(String categoryId) {
|
||||
this.baseMapper.delete(new LambdaUpdateWrapper<CategoryParameterGroup>().eq(CategoryParameterGroup::getCategoryId, categoryId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼装参数组和参数的返回值
|
||||
*
|
||||
|
@ -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<CategoryMapper, Category> i
|
||||
@Autowired
|
||||
private Cache cache;
|
||||
|
||||
@Autowired
|
||||
private CategoryBrandService categoryBrandService;
|
||||
|
||||
@Autowired
|
||||
private CategoryParameterGroupService categoryParameterGroupService;
|
||||
|
||||
@Autowired
|
||||
private CategorySpecificationService categorySpecificationService;
|
||||
|
||||
@Override
|
||||
public List<Category> dbList(String parentId) {
|
||||
return this.list(new LambdaQueryWrapper<Category>().eq(Category::getParentId, parentId));
|
||||
@ -227,6 +239,10 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
|
||||
public void delete(String id) {
|
||||
this.removeById(id);
|
||||
removeCache();
|
||||
//删除关联关系
|
||||
categoryBrandService.deleteByCategoryId(id);
|
||||
categoryParameterGroupService.deleteByCategoryId(id);
|
||||
categorySpecificationService.deleteByCategoryId(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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<Object> disable(@PathVariable String brandId, @RequestParam Boolean disable) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user