Compare commits

..

No commits in common. "f95331541b5089c04ab169ec9a947ba384e27408" and "509a1a95f7d9462e0ba8a574738265cde3642cfa" have entirely different histories.

21 changed files with 33 additions and 198 deletions

View File

@ -49,8 +49,8 @@ public class ${classUppercaseName}Controller {
@Operation(summary = "添加${comment}", description = "添加${comment}") @Operation(summary = "添加${comment}", description = "添加${comment}")
@PostMapping() @PostMapping()
public Result<String> save${classUppercaseName}(@Valid @RequestBody ${classUppercaseName}Dto dto) { public Result<String> add${classUppercaseName}(@Valid @RequestBody ${classUppercaseName}Dto dto) {
${classLowercaseName}Service.save${classUppercaseName}(dto); ${classLowercaseName}Service.add${classUppercaseName}(dto);
return Result.success(ResultCodeEnum.ADD_SUCCESS); return Result.success(ResultCodeEnum.ADD_SUCCESS);
} }

View File

@ -31,11 +31,11 @@ import java.util.List;
public class ${classUppercaseName}ServiceImpl extends ServiceImpl<${classUppercaseName}Mapper, ${classUppercaseName}> implements ${classUppercaseName}Service { public class ${classUppercaseName}ServiceImpl extends ServiceImpl<${classUppercaseName}Mapper, ${classUppercaseName}> implements ${classUppercaseName}Service {
/** /**
* 分页查询${comment} * * ${comment} 服务实现类
* *
* @param pageParams ${comment}分页查询page对象 * @param pageParams ${comment}分页查询page对象
* @param dto ${comment}分页查询对象 * @param dto ${comment}分页查询对象
* @return {@link ${classUppercaseName}Vo} * @return 查询分页${comment}返回对象
*/ */
@Override @Override
public PageResult<${classUppercaseName}Vo> get${classUppercaseName}Page(Page<${classUppercaseName}> pageParams, ${classUppercaseName}Dto dto) { public PageResult<${classUppercaseName}Vo> get${classUppercaseName}Page(Page<${classUppercaseName}> pageParams, ${classUppercaseName}Dto dto) {
@ -52,10 +52,10 @@ public class ${classUppercaseName}ServiceImpl extends ServiceImpl<${classUpperca
/** /**
* 添加${comment} * 添加${comment}
* *
* @param dto {@link ${classUppercaseName}Dto} 添加表单 * @param dto ${comment}添加
*/ */
@Override @Override
public void save${classUppercaseName}(${classUppercaseName}Dto dto) { public void add${classUppercaseName}(${classUppercaseName}Dto dto) {
${classUppercaseName} ${classLowercaseName} =new ${classUppercaseName}(); ${classUppercaseName} ${classLowercaseName} =new ${classUppercaseName}();
BeanUtils.copyProperties(dto, ${classLowercaseName}); BeanUtils.copyProperties(dto, ${classLowercaseName});
save(${classLowercaseName}); save(${classLowercaseName});
@ -64,7 +64,7 @@ public class ${classUppercaseName}ServiceImpl extends ServiceImpl<${classUpperca
/** /**
* 更新${comment} * 更新${comment}
* *
* @param dto {@link ${classUppercaseName}Dto} 更新表单 * @param dto ${comment}更新
*/ */
@Override @Override
public void update${classUppercaseName}(${classUppercaseName}Dto dto) { public void update${classUppercaseName}(${classUppercaseName}Dto dto) {
@ -74,7 +74,7 @@ public class ${classUppercaseName}ServiceImpl extends ServiceImpl<${classUpperca
} }
/** /**
* 删除|批量删除${comment}类型 * 删除|批量删除${comment}
* *
* @param ids 删除id列表 * @param ids 删除id列表
*/ */

View File

@ -25,8 +25,6 @@ public interface ${classUppercaseName}Service extends IService<${classUppercaseN
/** /**
* 分页查询${comment} * 分页查询${comment}
* *
* @param pageParams ${comment}分页查询page对象
* @param dto ${comment}分页查询对象
* @return {@link ${classUppercaseName}Vo} * @return {@link ${classUppercaseName}Vo}
*/ */
PageResult<${classUppercaseName}Vo> get${classUppercaseName}Page(Page<${classUppercaseName}> pageParams, ${classUppercaseName}Dto dto); PageResult<${classUppercaseName}Vo> get${classUppercaseName}Page(Page<${classUppercaseName}> pageParams, ${classUppercaseName}Dto dto);
@ -36,7 +34,7 @@ public interface ${classUppercaseName}Service extends IService<${classUppercaseN
* *
* @param dto {@link ${classUppercaseName}Dto} 添加表单 * @param dto {@link ${classUppercaseName}Dto} 添加表单
*/ */
void save${classUppercaseName}(${classUppercaseName}Dto dto); void add${classUppercaseName}(${classUppercaseName}Dto dto);
/** /**
* 更新${comment} * 更新${comment}

View File

@ -48,8 +48,8 @@ public class AttrController {
@Operation(summary = "添加商品属性", description = "添加商品属性") @Operation(summary = "添加商品属性", description = "添加商品属性")
@PostMapping() @PostMapping()
public Result<String> saveAttr(@Valid @RequestBody AttrDto dto) { public Result<String> addAttr(@Valid @RequestBody AttrDto dto) {
attrService.saveAttr(dto); attrService.addAttr(dto);
return Result.success(ResultCodeEnum.ADD_SUCCESS); return Result.success(ResultCodeEnum.ADD_SUCCESS);
} }

View File

@ -46,17 +46,10 @@ public class CategoryBrandRelationController {
return Result.success(pageResult); return Result.success(pageResult);
} }
@Operation(summary = "返回分类列表", description = "返回分类列表")
@GetMapping("category-list")
public Result<List<CategoryBrandRelationVo>> getCategoryList(Long brandId) {
List<CategoryBrandRelationVo> voList = categoryBrandRelationService.getCategoryList(brandId);
return Result.success(voList);
}
@Operation(summary = "添加品牌分类关联", description = "添加品牌分类关联") @Operation(summary = "添加品牌分类关联", description = "添加品牌分类关联")
@PostMapping() @PostMapping()
public Result<String> saveCategoryBrandRelation(@Valid @RequestBody CategoryBrandRelationDto dto) { public Result<String> addCategoryBrandRelation(@Valid @RequestBody CategoryBrandRelationDto dto) {
categoryBrandRelationService.saveCategoryBrandRelation(dto); categoryBrandRelationService.addCategoryBrandRelation(dto);
return Result.success(ResultCodeEnum.ADD_SUCCESS); return Result.success(ResultCodeEnum.ADD_SUCCESS);
} }

View File

@ -55,8 +55,8 @@ public class CategoryController {
@Operation(summary = "添加商品三级分类", description = "添加商品三级分类") @Operation(summary = "添加商品三级分类", description = "添加商品三级分类")
@PostMapping() @PostMapping()
public Result<String> saveCategory(@Valid @RequestBody CategoryDto dto) { public Result<String> addCategory(@Valid @RequestBody CategoryDto dto) {
categoryService.saveCategory(dto); categoryService.addCategory(dto);
return Result.success(ResultCodeEnum.ADD_SUCCESS); return Result.success(ResultCodeEnum.ADD_SUCCESS);
} }

View File

@ -43,7 +43,4 @@ public class AttrDto {
@Schema(name = "showDesc", title = "快速展示【是否展示在介绍上0-否 1-是】在sku中仍然可以调整") @Schema(name = "showDesc", title = "快速展示【是否展示在介绍上0-否 1-是】在sku中仍然可以调整")
private Integer showDesc; private Integer showDesc;
@Schema(name = "attrGroupId", title = "属性分组id")
private Long attrGroupId;
} }

View File

@ -22,10 +22,10 @@ public class CategoryBrandRelationDto {
@Schema(name = "catelogId", title = "分类id") @Schema(name = "catelogId", title = "分类id")
private Long catelogId; private Long catelogId;
@Schema(name = "brandName", title = "品牌名称") @Schema(name = "brandName", title = "")
private String brandName; private String brandName;
@Schema(name = "catelogName", title = "分类名称") @Schema(name = "catelogName", title = "")
private String catelogName; private String catelogName;
} }

View File

@ -1,7 +1,5 @@
package com.mall.product.domain.dto; package com.mall.product.domain.dto;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
@ -16,7 +14,6 @@ import lombok.NoArgsConstructor;
public class CategoryDto { public class CategoryDto {
@Schema(name = "catId", title = "分类id") @Schema(name = "catId", title = "分类id")
@TableId(type = IdType.ASSIGN_ID)
private Long catId; private Long catId;
@Schema(name = "name", title = "分类名称") @Schema(name = "name", title = "分类名称")

View File

@ -25,10 +25,10 @@ public class CategoryBrandRelationEntity {
@Schema(name = "catelogId", title = "分类id") @Schema(name = "catelogId", title = "分类id")
private Long catelogId; private Long catelogId;
@Schema(name = "brandName", title = "品牌名称") @Schema(name = "brandName", title = "")
private String brandName; private String brandName;
@Schema(name = "catelogName", title = "分类名称") @Schema(name = "catelogName", title = "")
private String catelogName; private String catelogName;
} }

View File

@ -2,6 +2,7 @@ package com.mall.product.domain.vo;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -20,10 +21,10 @@ public class CategoryBrandRelationVo {
@Schema(name = "catelogId", title = "分类id") @Schema(name = "catelogId", title = "分类id")
private Long catelogId; private Long catelogId;
@Schema(name = "brandName", title = "品牌名称") @Schema(name = "brandName", title = "")
private String brandName; private String brandName;
@Schema(name = "catelogName", title = "分类名称") @Schema(name = "catelogName", title = "")
private String catelogName; private String catelogName;
} }

View File

@ -29,11 +29,4 @@ public interface CategoryBrandRelationMapper extends BaseMapper<CategoryBrandRel
*/ */
IPage<CategoryBrandRelationVo> selectListByPage(@Param("page") Page<CategoryBrandRelationEntity> pageParams, @Param("dto") CategoryBrandRelationDto dto); IPage<CategoryBrandRelationVo> selectListByPage(@Param("page") Page<CategoryBrandRelationEntity> pageParams, @Param("dto") CategoryBrandRelationDto dto);
/**
* 根据品牌id更新 品牌分类关系表
* 根据分类id跟新更新分类时同时更新品牌和分类关系表
*
* @param dto 品牌分类关联的DTO对象
*/
void updateByBrandIdAndCatId(CategoryBrandRelationDto dto);
} }

View File

@ -31,7 +31,7 @@ public interface AttrService extends IService<AttrEntity> {
* *
* @param dto {@link AttrDto} 添加表单 * @param dto {@link AttrDto} 添加表单
*/ */
void saveAttr(AttrDto dto); void addAttr(AttrDto dto);
/** /**
* 更新商品属性 * 更新商品属性

View File

@ -35,8 +35,6 @@ public interface BrandService extends IService<BrandEntity> {
/** /**
* 更新品牌 * 更新品牌
* 先更新自己的品牌数据
* 之后更新冗余表中的数据
* *
* @param dto {@link BrandDto} 更新表单 * @param dto {@link BrandDto} 更新表单
*/ */

View File

@ -27,20 +27,11 @@ public interface CategoryBrandRelationService extends IService<CategoryBrandRela
PageResult<CategoryBrandRelationVo> getCategoryBrandRelationPage(Page<CategoryBrandRelationEntity> pageParams, CategoryBrandRelationDto dto); PageResult<CategoryBrandRelationVo> getCategoryBrandRelationPage(Page<CategoryBrandRelationEntity> pageParams, CategoryBrandRelationDto dto);
/** /**
* 添加品牌分类关联关系 * 添加品牌分类关联
* *
* <p>实现逻辑 * @param dto {@link CategoryBrandRelationDto} 添加表单
* 1. 根据品牌ID查询品牌信息获取品牌名称
* 2. 根据分类ID查询分类信息获取分类名称
* 3. 将品牌和分类的关联关系及冗余信息保存到关联表中
*
* <p>设计说明
* 采用冗余存储设计在关联表中同时存储品牌名称和分类名称
* 避免多表关联查询提升电商系统在大数据量场景下的查询性能
*
* @param dto 品牌分类关联数据 {@link CategoryBrandRelationDto}
*/ */
void saveCategoryBrandRelation(CategoryBrandRelationDto dto); void addCategoryBrandRelation(CategoryBrandRelationDto dto);
/** /**
* 更新品牌分类关联 * 更新品牌分类关联
@ -55,13 +46,4 @@ public interface CategoryBrandRelationService extends IService<CategoryBrandRela
* @param ids 删除id列表 * @param ids 删除id列表
*/ */
void deleteCategoryBrandRelation(List<Long> ids); void deleteCategoryBrandRelation(List<Long> ids);
/**
* 返回分类列表
*
* @param brandId 品牌id
* @return 品牌关联所有分类列表
*/
List<CategoryBrandRelationVo> getCategoryList(Long brandId);
} }

View File

@ -28,11 +28,10 @@ public interface CategoryService extends IService<CategoryEntity> {
/** /**
* 添加商品三级分类 * 添加商品三级分类
* 添加分类需要同时更新品牌和分类关联关系
* *
* @param dto {@link CategoryDto} 添加表单 * @param dto {@link CategoryDto} 添加表单
*/ */
void saveCategory(CategoryDto dto); void addCategory(CategoryDto dto);
/** /**
* 更新商品三级分类 * 更新商品三级分类

View File

@ -5,13 +5,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.common.domain.vo.result.PageResult; import com.mall.common.domain.vo.result.PageResult;
import com.mall.product.domain.dto.AttrDto; import com.mall.product.domain.dto.AttrDto;
import com.mall.product.domain.entity.AttrAttrgroupRelationEntity;
import com.mall.product.domain.entity.AttrEntity; import com.mall.product.domain.entity.AttrEntity;
import com.mall.product.domain.vo.AttrVo; import com.mall.product.domain.vo.AttrVo;
import com.mall.product.mapper.AttrAttrgroupRelationMapper;
import com.mall.product.mapper.AttrMapper; import com.mall.product.mapper.AttrMapper;
import com.mall.product.service.AttrService; import com.mall.product.service.AttrService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -28,11 +25,8 @@ import java.util.List;
*/ */
@Service @Service
@Transactional @Transactional
@RequiredArgsConstructor
public class AttrServiceImpl extends ServiceImpl<AttrMapper, AttrEntity> implements AttrService { public class AttrServiceImpl extends ServiceImpl<AttrMapper, AttrEntity> implements AttrService {
private final AttrAttrgroupRelationMapper attrAttrgroupRelationMapper;
/** /**
* * 商品属性 服务实现类 * * 商品属性 服务实现类
* *
@ -58,17 +52,10 @@ public class AttrServiceImpl extends ServiceImpl<AttrMapper, AttrEntity> impleme
* @param dto 商品属性添加 * @param dto 商品属性添加
*/ */
@Override @Override
public void saveAttr(AttrDto dto) { public void addAttr(AttrDto dto) {
AttrEntity attrEntity = new AttrEntity(); AttrEntity attrEntity = new AttrEntity();
BeanUtils.copyProperties(dto, attrEntity); BeanUtils.copyProperties(dto, attrEntity);
// 保存基本数据
save(attrEntity); save(attrEntity);
// 保存关联关系
AttrAttrgroupRelationEntity attrAttrgroupRelationEntity = new AttrAttrgroupRelationEntity();
attrAttrgroupRelationEntity.setAttrGroupId(dto.getAttrGroupId());
attrAttrgroupRelationMapper.insert(attrAttrgroupRelationEntity);
} }
/** /**

View File

@ -5,14 +5,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.common.domain.vo.result.PageResult; import com.mall.common.domain.vo.result.PageResult;
import com.mall.product.domain.dto.BrandDto; import com.mall.product.domain.dto.BrandDto;
import com.mall.product.domain.dto.CategoryBrandRelationDto;
import com.mall.product.domain.entity.BrandEntity; import com.mall.product.domain.entity.BrandEntity;
import com.mall.product.domain.vo.BrandVo; import com.mall.product.domain.vo.BrandVo;
import com.mall.product.mapper.BrandMapper; import com.mall.product.mapper.BrandMapper;
import com.mall.product.mapper.CategoryBrandRelationMapper;
import com.mall.product.service.BrandService; import com.mall.product.service.BrandService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -29,11 +25,8 @@ import java.util.List;
*/ */
@Service @Service
@Transactional @Transactional
@RequiredArgsConstructor
public class BrandServiceImpl extends ServiceImpl<BrandMapper, BrandEntity> implements BrandService { public class BrandServiceImpl extends ServiceImpl<BrandMapper, BrandEntity> implements BrandService {
private final CategoryBrandRelationMapper categoryBrandRelationMapper;
/** /**
* * 品牌 服务实现类 * * 品牌 服务实现类
* *
@ -67,27 +60,14 @@ public class BrandServiceImpl extends ServiceImpl<BrandMapper, BrandEntity> impl
/** /**
* 更新品牌 * 更新品牌
* 先更新自己的品牌数据
* 之后更新冗余表中的数据
* *
* @param dto {@link BrandDto} 更新表单 * @param dto 品牌更新
*/ */
@Override @Override
public void updateBrand(BrandDto dto) { public void updateBrand(BrandDto dto) {
BrandEntity brandEntity = new BrandEntity(); BrandEntity brandEntity = new BrandEntity();
BeanUtils.copyProperties(dto, brandEntity); BeanUtils.copyProperties(dto, brandEntity);
updateById(brandEntity); updateById(brandEntity);
// 品牌名不为空保存品牌名
String name = brandEntity.getName();
if (StringUtils.isNotBlank(name)) {
// 根据品牌id更新 品牌分类关系表
CategoryBrandRelationDto categoryBrandRelationDto = CategoryBrandRelationDto.builder()
.brandId(dto.getBrandId())
.brandName(name)
.build();
categoryBrandRelationMapper.updateByBrandIdAndCatId(categoryBrandRelationDto);
}
} }
/** /**

View File

@ -1,20 +1,14 @@
package com.mall.product.service.impl; package com.mall.product.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.common.domain.vo.result.PageResult; import com.mall.common.domain.vo.result.PageResult;
import com.mall.product.domain.dto.CategoryBrandRelationDto; import com.mall.product.domain.dto.CategoryBrandRelationDto;
import com.mall.product.domain.entity.BrandEntity;
import com.mall.product.domain.entity.CategoryBrandRelationEntity; import com.mall.product.domain.entity.CategoryBrandRelationEntity;
import com.mall.product.domain.entity.CategoryEntity;
import com.mall.product.domain.vo.CategoryBrandRelationVo; import com.mall.product.domain.vo.CategoryBrandRelationVo;
import com.mall.product.mapper.BrandMapper;
import com.mall.product.mapper.CategoryBrandRelationMapper; import com.mall.product.mapper.CategoryBrandRelationMapper;
import com.mall.product.mapper.CategoryMapper;
import com.mall.product.service.CategoryBrandRelationService; import com.mall.product.service.CategoryBrandRelationService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -31,12 +25,8 @@ import java.util.List;
*/ */
@Service @Service
@Transactional @Transactional
@RequiredArgsConstructor
public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationMapper, CategoryBrandRelationEntity> implements CategoryBrandRelationService { public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationMapper, CategoryBrandRelationEntity> implements CategoryBrandRelationService {
private final CategoryMapper categoryMapper;
private final BrandMapper brandMapper;
/** /**
* * 品牌分类关联 服务实现类 * * 品牌分类关联 服务实现类
* *
@ -57,34 +47,14 @@ public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandR
} }
/** /**
* 添加品牌分类关联关系 * 添加品牌分类关联
* *
* <p>实现逻辑 * @param dto 品牌分类关联添加
* 1. 根据品牌ID查询品牌信息获取品牌名称
* 2. 根据分类ID查询分类信息获取分类名称
* 3. 将品牌和分类的关联关系及冗余信息保存到关联表中
*
* <p>设计说明
* 采用冗余存储设计在关联表中同时存储品牌名称和分类名称
* 避免多表关联查询提升电商系统在大数据量场景下的查询性能
*
* @param dto 品牌分类关联数据 {@link CategoryBrandRelationDto}
*/ */
@Override @Override
public void saveCategoryBrandRelation(CategoryBrandRelationDto dto) { public void addCategoryBrandRelation(CategoryBrandRelationDto dto) {
// 根据品牌id查询品牌信息
Long brandId = dto.getBrandId();
BrandEntity brandEntity = brandMapper.selectById(brandId);
// 根据分类id查询分类信息
Long catelogId = dto.getCatelogId();
CategoryEntity categoryEntity = categoryMapper.selectById(catelogId);
// 将查询到的
CategoryBrandRelationEntity categoryBrandRelationEntity = new CategoryBrandRelationEntity(); CategoryBrandRelationEntity categoryBrandRelationEntity = new CategoryBrandRelationEntity();
BeanUtils.copyProperties(dto, categoryBrandRelationEntity); BeanUtils.copyProperties(dto, categoryBrandRelationEntity);
categoryBrandRelationEntity.setBrandName(brandEntity.getName());
categoryBrandRelationEntity.setCatelogName(categoryEntity.getName());
save(categoryBrandRelationEntity); save(categoryBrandRelationEntity);
} }
@ -109,27 +79,4 @@ public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandR
public void deleteCategoryBrandRelation(List<Long> ids) { public void deleteCategoryBrandRelation(List<Long> ids) {
removeByIds(ids); removeByIds(ids);
} }
/**
* 返回分类列表
*
* @param brandId 品牌id
* @return 品牌关联所有分类列表
*/
@Override
public List<CategoryBrandRelationVo> getCategoryList(Long brandId) {
// 构建查询条件
QueryWrapper<CategoryBrandRelationEntity> wrapper = new QueryWrapper<>();
wrapper.lambda().eq(CategoryBrandRelationEntity::getBrandId, brandId);
// 查询品牌分类关联的实体类对象
List<CategoryBrandRelationEntity> list = list(wrapper);
return list.stream().map(categoryBrandRelationEntity -> {
CategoryBrandRelationVo vo = new CategoryBrandRelationVo();
BeanUtils.copyProperties(categoryBrandRelationEntity, vo);
return vo;
})
.toList();
}
} }

View File

@ -4,16 +4,13 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.common.domain.vo.result.PageResult; import com.mall.common.domain.vo.result.PageResult;
import com.mall.product.domain.dto.CategoryBrandRelationDto;
import com.mall.product.domain.dto.CategoryDto; import com.mall.product.domain.dto.CategoryDto;
import com.mall.product.domain.entity.CategoryEntity; import com.mall.product.domain.entity.CategoryEntity;
import com.mall.product.domain.vo.CategoryVo; import com.mall.product.domain.vo.CategoryVo;
import com.mall.product.mapper.CategoryBrandRelationMapper;
import com.mall.product.mapper.CategoryMapper; import com.mall.product.mapper.CategoryMapper;
import com.mall.product.service.CategoryService; import com.mall.product.service.CategoryService;
import com.mall.product.service.ext.CategoryServiceImplExt; import com.mall.product.service.ext.CategoryServiceImplExt;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -39,7 +36,6 @@ import static com.mall.product.service.ext.CategoryServiceImplExt.getCategoryTre
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, CategoryEntity> implements CategoryService { public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, CategoryEntity> implements CategoryService {
private final CategoryServiceImplExt categoryServiceImplExt; private final CategoryServiceImplExt categoryServiceImplExt;
private final CategoryBrandRelationMapper categoryBrandRelationMapper;
/** /**
* * 商品三级分类 服务实现类 * * 商品三级分类 服务实现类
@ -66,7 +62,7 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, CategoryEnt
* @param dto 商品三级分类添加 * @param dto 商品三级分类添加
*/ */
@Override @Override
public void saveCategory(CategoryDto dto) { public void addCategory(CategoryDto dto) {
CategoryEntity categoryEntity = new CategoryEntity(); CategoryEntity categoryEntity = new CategoryEntity();
BeanUtils.copyProperties(dto, categoryEntity); BeanUtils.copyProperties(dto, categoryEntity);
save(categoryEntity); save(categoryEntity);
@ -82,15 +78,6 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, CategoryEnt
CategoryEntity categoryEntity = new CategoryEntity(); CategoryEntity categoryEntity = new CategoryEntity();
BeanUtils.copyProperties(dto, categoryEntity); BeanUtils.copyProperties(dto, categoryEntity);
updateById(categoryEntity); updateById(categoryEntity);
// 根据分类id跟新更新分类时同时更新品牌和分类关系表
String name = categoryEntity.getName();
if (StringUtils.isNotBlank(name)) {
CategoryBrandRelationDto categoryBrandRelationDto = CategoryBrandRelationDto.builder()
.catelogId(dto.getCatId())
.catelogName(name).build();
categoryBrandRelationMapper.updateByBrandIdAndCatId(categoryBrandRelationDto);
}
} }
/** /**

View File

@ -16,30 +16,6 @@
id,brand_id,catelog_id,brand_name,catelog_name id,brand_id,catelog_id,brand_name,catelog_name
</sql> </sql>
<update id="updateByBrandIdAndCatId">
update pms_category_brand_relation
<set>
<if test="name != null and brandId != null">
brand_name = #{name},
</if>
<if test="name != null and catId != null">
catelog_name = #{name},
</if>
</set>
where
<choose>
<when test="brandId != null">
brand_id = #{brandId}
</when>
<when test="catId != null">
catelog_id = #{catId}
</when>
<otherwise>
1=0 <!-- 如果没有提供任何ID条件则不更新任何记录 -->
</otherwise>
</choose>
</update>
<!-- 分页查询品牌分类关联内容 --> <!-- 分页查询品牌分类关联内容 -->
<select id="selectListByPage" resultType="com.mall.product.domain.vo.CategoryBrandRelationVo"> <select id="selectListByPage" resultType="com.mall.product.domain.vo.CategoryBrandRelationVo">
select select