品牌删除导致商品没有品牌,前端es有空品牌问题处理
This commit is contained in:
parent
44e36f0bcd
commit
585e2c4ccc
@ -99,7 +99,8 @@ 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_BIND_GOODS_ERROR(20005, "品牌已经绑定商品,请先解除关联"),
|
||||
BRAND_NOT_EXIST(20004, "品牌不存在"),
|
||||
|
||||
/**
|
||||
|
@ -35,7 +35,7 @@ public interface CategoryBrandService extends IService<CategoryBrand> {
|
||||
* @param brandId 品牌ID
|
||||
* @return 分类品牌关联信息
|
||||
*/
|
||||
List<CategoryBrand> getCategoryBrandListByBrandId(String brandId);
|
||||
List<CategoryBrand> getCategoryBrandListByBrandId(List<String> brandId);
|
||||
|
||||
/**
|
||||
* 保存分类品牌关系
|
||||
|
@ -20,6 +20,13 @@ import java.util.List;
|
||||
public interface GoodsService extends IService<Goods> {
|
||||
|
||||
|
||||
/**
|
||||
* 根据品牌获取商品
|
||||
*
|
||||
* @param brandIds 品牌ids
|
||||
*/
|
||||
List<Goods> getByBrandIds(List<String> brandIds);
|
||||
|
||||
/**
|
||||
* 下架所有商家商品
|
||||
*
|
||||
|
@ -5,12 +5,14 @@ import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.modules.goods.entity.dos.Brand;
|
||||
import cn.lili.modules.goods.entity.dos.CategoryBrand;
|
||||
import cn.lili.modules.goods.entity.dos.Goods;
|
||||
import cn.lili.modules.goods.entity.dto.BrandPageDTO;
|
||||
import cn.lili.modules.goods.entity.vos.BrandVO;
|
||||
import cn.lili.modules.goods.mapper.BrandMapper;
|
||||
import cn.lili.modules.goods.service.BrandService;
|
||||
import cn.lili.modules.goods.service.CategoryBrandService;
|
||||
import cn.lili.modules.goods.service.CategoryService;
|
||||
import cn.lili.modules.goods.service.GoodsService;
|
||||
import cn.lili.mybatis.util.PageUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@ -21,6 +23,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -44,6 +47,9 @@ public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
@Autowired
|
||||
private GoodsService goodsService;
|
||||
|
||||
@Override
|
||||
public IPage<Brand> getBrandsByPage(BrandPageDTO page) {
|
||||
LambdaQueryWrapper<Brand> queryWrapper = new LambdaQueryWrapper<>();
|
||||
@ -88,7 +94,9 @@ public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements
|
||||
Brand brand = this.checkExist(brandId);
|
||||
//如果是要禁用,则需要先判定绑定关系
|
||||
if (Boolean.TRUE.equals(disable)) {
|
||||
checkoutCategory(brandId);
|
||||
List<String> ids = new ArrayList<>();
|
||||
ids.add(brandId);
|
||||
checkBind(ids);
|
||||
}
|
||||
brand.setDeleteFlag(disable);
|
||||
return updateById(brand);
|
||||
@ -96,7 +104,7 @@ public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements
|
||||
|
||||
@Override
|
||||
public void deleteBrands(List<String> ids) {
|
||||
ids.forEach(this::checkoutCategory);
|
||||
checkBind(ids);
|
||||
this.removeByIds(ids);
|
||||
}
|
||||
|
||||
@ -104,16 +112,32 @@ public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements
|
||||
/**
|
||||
* 校验绑定关系
|
||||
*
|
||||
* @param brandId
|
||||
* @param brandIds
|
||||
*/
|
||||
private void checkoutCategory(String brandId) {
|
||||
private void checkBind(List<String> brandIds) {
|
||||
//分了绑定关系查询
|
||||
List<CategoryBrand> categoryBrands = categoryBrandService.getCategoryBrandListByBrandId(brandId);
|
||||
List<CategoryBrand> categoryBrands = categoryBrandService.getCategoryBrandListByBrandId(brandIds);
|
||||
if (!categoryBrands.isEmpty()) {
|
||||
List<String> brandIds = categoryBrands.stream().map(CategoryBrand::getCategoryId).collect(Collectors.toList());
|
||||
List<String> categoryIds = categoryBrands.stream().map(CategoryBrand::getCategoryId).collect(Collectors.toList());
|
||||
throw new ServiceException(ResultCode.BRAND_USE_DISABLE_ERROR,
|
||||
JSONUtil.toJsonStr(categoryService.getCategoryNameByIds(brandIds)));
|
||||
JSONUtil.toJsonStr(categoryService.getCategoryNameByIds(categoryIds)));
|
||||
}
|
||||
|
||||
//分了商品绑定关系查询
|
||||
List<Goods> goods = goodsService.getByBrandIds(brandIds);
|
||||
if (!goods.isEmpty()) {
|
||||
List<String> goodsNames = goods.stream().map(Goods::getGoodsName).collect(Collectors.toList());
|
||||
throw new ServiceException(ResultCode.BRAND_BIND_GOODS_ERROR,
|
||||
JSONUtil.toJsonStr(goodsNames));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验绑定关系
|
||||
*
|
||||
* @param brandIds
|
||||
*/
|
||||
private void checkoutGoods(List<String> brandIds) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,8 +36,8 @@ public class CategoryBrandServiceImpl extends ServiceImpl<CategoryBrandMapper, C
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CategoryBrand> getCategoryBrandListByBrandId(String brandId) {
|
||||
return this.list(new LambdaQueryWrapper<CategoryBrand>().eq(CategoryBrand::getBrandId, brandId));
|
||||
public List<CategoryBrand> getCategoryBrandListByBrandId(List<String> brandId) {
|
||||
return this.list(new LambdaQueryWrapper<CategoryBrand>().in(CategoryBrand::getBrandId, brandId));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -119,6 +119,13 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
||||
@Autowired
|
||||
private Cache<GoodsVO> cache;
|
||||
|
||||
@Override
|
||||
public List<Goods> getByBrandIds(List<String> brandIds) {
|
||||
LambdaQueryWrapper<Goods> lambdaQueryWrapper = new LambdaQueryWrapper<Goods> ();
|
||||
lambdaQueryWrapper.in(Goods::getBrandId,brandIds);
|
||||
return list(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void underStoreGoods(String storeId) {
|
||||
//获取商品ID列表
|
||||
|
Loading…
x
Reference in New Issue
Block a user