Compare commits
4 Commits
509a1a95f7
...
f95331541b
Author | SHA1 | Date |
---|---|---|
|
f95331541b | |
|
8a7844fcd8 | |
|
14d77a07af | |
|
85f90b2042 |
|
@ -49,8 +49,8 @@ public class ${classUppercaseName}Controller {
|
|||
|
||||
@Operation(summary = "添加${comment}", description = "添加${comment}")
|
||||
@PostMapping()
|
||||
public Result<String> add${classUppercaseName}(@Valid @RequestBody ${classUppercaseName}Dto dto) {
|
||||
${classLowercaseName}Service.add${classUppercaseName}(dto);
|
||||
public Result<String> save${classUppercaseName}(@Valid @RequestBody ${classUppercaseName}Dto dto) {
|
||||
${classLowercaseName}Service.save${classUppercaseName}(dto);
|
||||
return Result.success(ResultCodeEnum.ADD_SUCCESS);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,11 +31,11 @@ import java.util.List;
|
|||
public class ${classUppercaseName}ServiceImpl extends ServiceImpl<${classUppercaseName}Mapper, ${classUppercaseName}> implements ${classUppercaseName}Service {
|
||||
|
||||
/**
|
||||
* * ${comment} 服务实现类
|
||||
* 分页查询${comment}
|
||||
*
|
||||
* @param pageParams ${comment}分页查询page对象
|
||||
* @param dto ${comment}分页查询对象
|
||||
* @return 查询分页${comment}返回对象
|
||||
* @return {@link ${classUppercaseName}Vo}
|
||||
*/
|
||||
@Override
|
||||
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}
|
||||
*
|
||||
* @param dto ${comment}添加
|
||||
* @param dto {@link ${classUppercaseName}Dto} 添加表单
|
||||
*/
|
||||
@Override
|
||||
public void add${classUppercaseName}(${classUppercaseName}Dto dto) {
|
||||
public void save${classUppercaseName}(${classUppercaseName}Dto dto) {
|
||||
${classUppercaseName} ${classLowercaseName} =new ${classUppercaseName}();
|
||||
BeanUtils.copyProperties(dto, ${classLowercaseName});
|
||||
save(${classLowercaseName});
|
||||
|
@ -64,7 +64,7 @@ public class ${classUppercaseName}ServiceImpl extends ServiceImpl<${classUpperca
|
|||
/**
|
||||
* 更新${comment}
|
||||
*
|
||||
* @param dto ${comment}更新
|
||||
* @param dto {@link ${classUppercaseName}Dto} 更新表单
|
||||
*/
|
||||
@Override
|
||||
public void update${classUppercaseName}(${classUppercaseName}Dto dto) {
|
||||
|
@ -74,7 +74,7 @@ public class ${classUppercaseName}ServiceImpl extends ServiceImpl<${classUpperca
|
|||
}
|
||||
|
||||
/**
|
||||
* 删除|批量删除${comment}
|
||||
* 删除|批量删除${comment}类型
|
||||
*
|
||||
* @param ids 删除id列表
|
||||
*/
|
||||
|
|
|
@ -25,6 +25,8 @@ public interface ${classUppercaseName}Service extends IService<${classUppercaseN
|
|||
/**
|
||||
* 分页查询${comment}
|
||||
*
|
||||
* @param pageParams ${comment}分页查询page对象
|
||||
* @param dto ${comment}分页查询对象
|
||||
* @return {@link ${classUppercaseName}Vo}
|
||||
*/
|
||||
PageResult<${classUppercaseName}Vo> get${classUppercaseName}Page(Page<${classUppercaseName}> pageParams, ${classUppercaseName}Dto dto);
|
||||
|
@ -34,7 +36,7 @@ public interface ${classUppercaseName}Service extends IService<${classUppercaseN
|
|||
*
|
||||
* @param dto {@link ${classUppercaseName}Dto} 添加表单
|
||||
*/
|
||||
void add${classUppercaseName}(${classUppercaseName}Dto dto);
|
||||
void save${classUppercaseName}(${classUppercaseName}Dto dto);
|
||||
|
||||
/**
|
||||
* 更新${comment}
|
||||
|
|
|
@ -48,8 +48,8 @@ public class AttrController {
|
|||
|
||||
@Operation(summary = "添加商品属性", description = "添加商品属性")
|
||||
@PostMapping()
|
||||
public Result<String> addAttr(@Valid @RequestBody AttrDto dto) {
|
||||
attrService.addAttr(dto);
|
||||
public Result<String> saveAttr(@Valid @RequestBody AttrDto dto) {
|
||||
attrService.saveAttr(dto);
|
||||
return Result.success(ResultCodeEnum.ADD_SUCCESS);
|
||||
}
|
||||
|
||||
|
|
|
@ -46,10 +46,17 @@ public class CategoryBrandRelationController {
|
|||
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 = "添加品牌分类关联")
|
||||
@PostMapping()
|
||||
public Result<String> addCategoryBrandRelation(@Valid @RequestBody CategoryBrandRelationDto dto) {
|
||||
categoryBrandRelationService.addCategoryBrandRelation(dto);
|
||||
public Result<String> saveCategoryBrandRelation(@Valid @RequestBody CategoryBrandRelationDto dto) {
|
||||
categoryBrandRelationService.saveCategoryBrandRelation(dto);
|
||||
return Result.success(ResultCodeEnum.ADD_SUCCESS);
|
||||
}
|
||||
|
||||
|
|
|
@ -55,8 +55,8 @@ public class CategoryController {
|
|||
|
||||
@Operation(summary = "添加商品三级分类", description = "添加商品三级分类")
|
||||
@PostMapping()
|
||||
public Result<String> addCategory(@Valid @RequestBody CategoryDto dto) {
|
||||
categoryService.addCategory(dto);
|
||||
public Result<String> saveCategory(@Valid @RequestBody CategoryDto dto) {
|
||||
categoryService.saveCategory(dto);
|
||||
return Result.success(ResultCodeEnum.ADD_SUCCESS);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,4 +43,7 @@ public class AttrDto {
|
|||
@Schema(name = "showDesc", title = "快速展示【是否展示在介绍上;0-否 1-是】,在sku中仍然可以调整")
|
||||
private Integer showDesc;
|
||||
|
||||
@Schema(name = "attrGroupId", title = "属性分组id")
|
||||
private Long attrGroupId;
|
||||
|
||||
}
|
|
@ -22,10 +22,10 @@ public class CategoryBrandRelationDto {
|
|||
@Schema(name = "catelogId", title = "分类id")
|
||||
private Long catelogId;
|
||||
|
||||
@Schema(name = "brandName", title = "")
|
||||
@Schema(name = "brandName", title = "品牌名称")
|
||||
private String brandName;
|
||||
|
||||
@Schema(name = "catelogName", title = "")
|
||||
@Schema(name = "catelogName", title = "分类名称")
|
||||
private String catelogName;
|
||||
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
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 lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
|
@ -14,6 +16,7 @@ import lombok.NoArgsConstructor;
|
|||
public class CategoryDto {
|
||||
|
||||
@Schema(name = "catId", title = "分类id")
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long catId;
|
||||
|
||||
@Schema(name = "name", title = "分类名称")
|
||||
|
|
|
@ -25,10 +25,10 @@ public class CategoryBrandRelationEntity {
|
|||
@Schema(name = "catelogId", title = "分类id")
|
||||
private Long catelogId;
|
||||
|
||||
@Schema(name = "brandName", title = "")
|
||||
@Schema(name = "brandName", title = "品牌名称")
|
||||
private String brandName;
|
||||
|
||||
@Schema(name = "catelogName", title = "")
|
||||
@Schema(name = "catelogName", title = "分类名称")
|
||||
private String catelogName;
|
||||
|
||||
}
|
|
@ -2,7 +2,6 @@ package com.mall.product.domain.vo;
|
|||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
@ -21,10 +20,10 @@ public class CategoryBrandRelationVo {
|
|||
@Schema(name = "catelogId", title = "分类id")
|
||||
private Long catelogId;
|
||||
|
||||
@Schema(name = "brandName", title = "")
|
||||
@Schema(name = "brandName", title = "品牌名称")
|
||||
private String brandName;
|
||||
|
||||
@Schema(name = "catelogName", title = "")
|
||||
@Schema(name = "catelogName", title = "分类名称")
|
||||
private String catelogName;
|
||||
|
||||
}
|
||||
|
|
|
@ -29,4 +29,11 @@ public interface CategoryBrandRelationMapper extends BaseMapper<CategoryBrandRel
|
|||
*/
|
||||
IPage<CategoryBrandRelationVo> selectListByPage(@Param("page") Page<CategoryBrandRelationEntity> pageParams, @Param("dto") CategoryBrandRelationDto dto);
|
||||
|
||||
/**
|
||||
* 根据品牌id更新 品牌分类关系表
|
||||
* 根据分类id跟新,更新分类时同时更新品牌和分类关系表
|
||||
*
|
||||
* @param dto 品牌分类关联的DTO对象
|
||||
*/
|
||||
void updateByBrandIdAndCatId(CategoryBrandRelationDto dto);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public interface AttrService extends IService<AttrEntity> {
|
|||
*
|
||||
* @param dto {@link AttrDto} 添加表单
|
||||
*/
|
||||
void addAttr(AttrDto dto);
|
||||
void saveAttr(AttrDto dto);
|
||||
|
||||
/**
|
||||
* 更新商品属性
|
||||
|
|
|
@ -35,6 +35,8 @@ public interface BrandService extends IService<BrandEntity> {
|
|||
|
||||
/**
|
||||
* 更新品牌
|
||||
* 先更新自己的品牌数据
|
||||
* 之后更新冗余表中的数据
|
||||
*
|
||||
* @param dto {@link BrandDto} 更新表单
|
||||
*/
|
||||
|
|
|
@ -27,11 +27,20 @@ public interface CategoryBrandRelationService extends IService<CategoryBrandRela
|
|||
PageResult<CategoryBrandRelationVo> getCategoryBrandRelationPage(Page<CategoryBrandRelationEntity> pageParams, CategoryBrandRelationDto dto);
|
||||
|
||||
/**
|
||||
* 添加品牌分类关联
|
||||
* 添加品牌与分类的关联关系
|
||||
*
|
||||
* @param dto {@link CategoryBrandRelationDto} 添加表单
|
||||
* <p>实现逻辑:
|
||||
* 1. 根据品牌ID查询品牌信息,获取品牌名称
|
||||
* 2. 根据分类ID查询分类信息,获取分类名称
|
||||
* 3. 将品牌和分类的关联关系及冗余信息保存到关联表中
|
||||
*
|
||||
* <p>设计说明:
|
||||
* 采用冗余存储设计,在关联表中同时存储品牌名称和分类名称,
|
||||
* 避免多表关联查询,提升电商系统在大数据量场景下的查询性能
|
||||
*
|
||||
* @param dto 品牌分类关联数据 {@link CategoryBrandRelationDto}
|
||||
*/
|
||||
void addCategoryBrandRelation(CategoryBrandRelationDto dto);
|
||||
void saveCategoryBrandRelation(CategoryBrandRelationDto dto);
|
||||
|
||||
/**
|
||||
* 更新品牌分类关联
|
||||
|
@ -46,4 +55,13 @@ public interface CategoryBrandRelationService extends IService<CategoryBrandRela
|
|||
* @param ids 删除id列表
|
||||
*/
|
||||
void deleteCategoryBrandRelation(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 返回分类列表
|
||||
*
|
||||
* @param brandId 品牌id
|
||||
* @return 品牌关联所有分类列表
|
||||
*/
|
||||
List<CategoryBrandRelationVo> getCategoryList(Long brandId);
|
||||
|
||||
}
|
||||
|
|
|
@ -28,10 +28,11 @@ public interface CategoryService extends IService<CategoryEntity> {
|
|||
|
||||
/**
|
||||
* 添加商品三级分类
|
||||
* 添加分类需要同时更新:品牌和分类关联关系
|
||||
*
|
||||
* @param dto {@link CategoryDto} 添加表单
|
||||
*/
|
||||
void addCategory(CategoryDto dto);
|
||||
void saveCategory(CategoryDto dto);
|
||||
|
||||
/**
|
||||
* 更新商品三级分类
|
||||
|
|
|
@ -5,10 +5,13 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mall.common.domain.vo.result.PageResult;
|
||||
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.vo.AttrVo;
|
||||
import com.mall.product.mapper.AttrAttrgroupRelationMapper;
|
||||
import com.mall.product.mapper.AttrMapper;
|
||||
import com.mall.product.service.AttrService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -25,8 +28,11 @@ import java.util.List;
|
|||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
@RequiredArgsConstructor
|
||||
public class AttrServiceImpl extends ServiceImpl<AttrMapper, AttrEntity> implements AttrService {
|
||||
|
||||
private final AttrAttrgroupRelationMapper attrAttrgroupRelationMapper;
|
||||
|
||||
/**
|
||||
* * 商品属性 服务实现类
|
||||
*
|
||||
|
@ -52,10 +58,17 @@ public class AttrServiceImpl extends ServiceImpl<AttrMapper, AttrEntity> impleme
|
|||
* @param dto 商品属性添加
|
||||
*/
|
||||
@Override
|
||||
public void addAttr(AttrDto dto) {
|
||||
public void saveAttr(AttrDto dto) {
|
||||
AttrEntity attrEntity = new AttrEntity();
|
||||
BeanUtils.copyProperties(dto, attrEntity);
|
||||
|
||||
// 保存基本数据
|
||||
save(attrEntity);
|
||||
|
||||
// 保存关联关系
|
||||
AttrAttrgroupRelationEntity attrAttrgroupRelationEntity = new AttrAttrgroupRelationEntity();
|
||||
attrAttrgroupRelationEntity.setAttrGroupId(dto.getAttrGroupId());
|
||||
attrAttrgroupRelationMapper.insert(attrAttrgroupRelationEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,10 +5,14 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mall.common.domain.vo.result.PageResult;
|
||||
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.vo.BrandVo;
|
||||
import com.mall.product.mapper.BrandMapper;
|
||||
import com.mall.product.mapper.CategoryBrandRelationMapper;
|
||||
import com.mall.product.service.BrandService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -25,8 +29,11 @@ import java.util.List;
|
|||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
@RequiredArgsConstructor
|
||||
public class BrandServiceImpl extends ServiceImpl<BrandMapper, BrandEntity> implements BrandService {
|
||||
|
||||
private final CategoryBrandRelationMapper categoryBrandRelationMapper;
|
||||
|
||||
/**
|
||||
* * 品牌 服务实现类
|
||||
*
|
||||
|
@ -60,14 +67,27 @@ public class BrandServiceImpl extends ServiceImpl<BrandMapper, BrandEntity> impl
|
|||
|
||||
/**
|
||||
* 更新品牌
|
||||
* 先更新自己的品牌数据
|
||||
* 之后更新冗余表中的数据
|
||||
*
|
||||
* @param dto 品牌更新
|
||||
* @param dto {@link BrandDto} 更新表单
|
||||
*/
|
||||
@Override
|
||||
public void updateBrand(BrandDto dto) {
|
||||
BrandEntity brandEntity = new BrandEntity();
|
||||
BeanUtils.copyProperties(dto, 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,14 +1,20 @@
|
|||
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.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mall.common.domain.vo.result.PageResult;
|
||||
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.CategoryEntity;
|
||||
import com.mall.product.domain.vo.CategoryBrandRelationVo;
|
||||
import com.mall.product.mapper.BrandMapper;
|
||||
import com.mall.product.mapper.CategoryBrandRelationMapper;
|
||||
import com.mall.product.mapper.CategoryMapper;
|
||||
import com.mall.product.service.CategoryBrandRelationService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -25,8 +31,12 @@ import java.util.List;
|
|||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
@RequiredArgsConstructor
|
||||
public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationMapper, CategoryBrandRelationEntity> implements CategoryBrandRelationService {
|
||||
|
||||
private final CategoryMapper categoryMapper;
|
||||
private final BrandMapper brandMapper;
|
||||
|
||||
/**
|
||||
* * 品牌分类关联 服务实现类
|
||||
*
|
||||
|
@ -47,14 +57,34 @@ public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandR
|
|||
}
|
||||
|
||||
/**
|
||||
* 添加品牌分类关联
|
||||
* 添加品牌与分类的关联关系
|
||||
*
|
||||
* @param dto 品牌分类关联添加
|
||||
* <p>实现逻辑:
|
||||
* 1. 根据品牌ID查询品牌信息,获取品牌名称
|
||||
* 2. 根据分类ID查询分类信息,获取分类名称
|
||||
* 3. 将品牌和分类的关联关系及冗余信息保存到关联表中
|
||||
*
|
||||
* <p>设计说明:
|
||||
* 采用冗余存储设计,在关联表中同时存储品牌名称和分类名称,
|
||||
* 避免多表关联查询,提升电商系统在大数据量场景下的查询性能
|
||||
*
|
||||
* @param dto 品牌分类关联数据 {@link CategoryBrandRelationDto}
|
||||
*/
|
||||
@Override
|
||||
public void addCategoryBrandRelation(CategoryBrandRelationDto dto) {
|
||||
public void saveCategoryBrandRelation(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();
|
||||
BeanUtils.copyProperties(dto, categoryBrandRelationEntity);
|
||||
categoryBrandRelationEntity.setBrandName(brandEntity.getName());
|
||||
categoryBrandRelationEntity.setCatelogName(categoryEntity.getName());
|
||||
save(categoryBrandRelationEntity);
|
||||
}
|
||||
|
||||
|
@ -79,4 +109,27 @@ public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandR
|
|||
public void deleteCategoryBrandRelation(List<Long> 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();
|
||||
}
|
||||
|
||||
}
|
|
@ -4,13 +4,16 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
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.entity.CategoryEntity;
|
||||
import com.mall.product.domain.vo.CategoryVo;
|
||||
import com.mall.product.mapper.CategoryBrandRelationMapper;
|
||||
import com.mall.product.mapper.CategoryMapper;
|
||||
import com.mall.product.service.CategoryService;
|
||||
import com.mall.product.service.ext.CategoryServiceImplExt;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -36,6 +39,7 @@ import static com.mall.product.service.ext.CategoryServiceImplExt.getCategoryTre
|
|||
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, CategoryEntity> implements CategoryService {
|
||||
|
||||
private final CategoryServiceImplExt categoryServiceImplExt;
|
||||
private final CategoryBrandRelationMapper categoryBrandRelationMapper;
|
||||
|
||||
/**
|
||||
* * 商品三级分类 服务实现类
|
||||
|
@ -62,7 +66,7 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, CategoryEnt
|
|||
* @param dto 商品三级分类添加
|
||||
*/
|
||||
@Override
|
||||
public void addCategory(CategoryDto dto) {
|
||||
public void saveCategory(CategoryDto dto) {
|
||||
CategoryEntity categoryEntity = new CategoryEntity();
|
||||
BeanUtils.copyProperties(dto, categoryEntity);
|
||||
save(categoryEntity);
|
||||
|
@ -78,6 +82,15 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, CategoryEnt
|
|||
CategoryEntity categoryEntity = new CategoryEntity();
|
||||
BeanUtils.copyProperties(dto, 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,30 @@
|
|||
id,brand_id,catelog_id,brand_name,catelog_name
|
||||
</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
|
||||
|
|
Loading…
Reference in New Issue