小问题解决
添加分页组件,官方文档如下:插件主体 | MyBatis-Plus
MybatisConfig
package com.example.gulimall.product.config;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@EnableTransactionManagement//开启使用
@MapperScan("com.example.gulimall.product.dao")
public class MybatisConfig {
//引入分页插件
@Bean
public PaginationInterceptor paginationInterceptor(){
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
//设置请求的页面大于最大页后操作,true调回到首页,false继续请求 默认false
paginationInterceptor.setOverflow(false);
//设置最大单页限制数据,默认500条, -1 不受限制
paginationInterceptor.setLimit(500);
return paginationInterceptor;
}
}
接下来修改品牌的模糊查询
BrandServiceImpl
package com.example.gulimall.product.service.impl;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.utils.PageUtils;
import com.example.common.utils.Query;
import com.example.gulimall.product.dao.BrandDao;
import com.example.gulimall.product.entity.BrandEntity;
import com.example.gulimall.product.service.BrandService;
import org.springframework.util.StringUtils;
@Service("brandService")
public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> implements BrandService {
@Override
public PageUtils queryPage(Map<String, Object> params) {
//获取key
String key = (String) params.get("key");
QueryWrapper<BrandEntity> queryWrapper = new QueryWrapper<>();
if (!StringUtils.isEmpty(key)){
queryWrapper.eq("brand_id", key).or().like("name", key);
IPage<BrandEntity> page = this.page(
new Query<BrandEntity>().getPage(params),
queryWrapper
);
}
IPage<BrandEntity> page = this.page(
new Query<BrandEntity>().getPage(params),
queryWrapper
);
return new PageUtils(page);
}
}
品牌分类关系关联
获取品牌关联的分类
/**
* 获取品牌关联的分类
*/
@GetMapping("/catelog/list")
public R list(@RequestParam("brandId")Long brandId){
List<CategoryBrandRelationEntity> data = categoryBrandRelationService.list(
new QueryWrapper<CategoryBrandRelationEntity>().eq("brand_id", brandId));
return R.ok().put("data", data);
}
新增品牌关联的分类
/**
* 新增品牌关联的分类
* product/categorybrandrelation/save
*/
@RequestMapping("/save")
public R save(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
categoryBrandRelationService.saveDetail(categoryBrandRelation);
return R.ok();
}
package com.example.gulimall.product.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.example.common.utils.PageUtils;
import com.example.gulimall.product.entity.CategoryBrandRelationEntity;
import java.util.Map;
/**
* 品牌分类关联
*
* @author leohams
* @email gf879543517@163.com
* @date 2022-06-14 21:22:44
*/
public interface CategoryBrandRelationService extends IService<CategoryBrandRelationEntity> {
PageUtils queryPage(Map<String, Object> params);
void saveDetail(CategoryBrandRelationEntity categoryBrandRelation);
}
package com.example.gulimall.product.service.impl;
import com.example.gulimall.product.dao.BrandDao;
import com.example.gulimall.product.dao.CategoryDao;
import com.example.gulimall.product.entity.BrandEntity;
import com.example.gulimall.product.entity.CategoryEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.utils.PageUtils;
import com.example.common.utils.Query;
import com.example.gulimall.product.dao.CategoryBrandRelationDao;
import com.example.gulimall.product.entity.CategoryBrandRelationEntity;
import com.example.gulimall.product.service.CategoryBrandRelationService;
@Service("categoryBrandRelationService")
public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationDao, CategoryBrandRelationEntity> implements CategoryBrandRelationService {
@Autowired
private BrandDao brandDao;
@Autowired
private CategoryDao categoryDao;
@Override
public PageUtils queryPage(Map<String, Object> params) {
IPage<CategoryBrandRelationEntity> page = this.page(
new Query<CategoryBrandRelationEntity>().getPage(params),
new QueryWrapper<CategoryBrandRelationEntity>()
);
return new PageUtils(page);
}
@Override
public void saveDetail(CategoryBrandRelationEntity categoryBrandRelation) {
Long brandId = categoryBrandRelation.getBrandId();
Long catelogId = categoryBrandRelation.getCatelogId();
BrandEntity brandEntity = brandDao.selectById(brandId);
String brandName = brandEntity.getName();
CategoryEntity categoryEntity = categoryDao.selectById(catelogId);
String categoryEntityName = categoryEntity.getName();
categoryBrandRelation.setBrandName(brandName);
categoryBrandRelation.setCatelogName(categoryEntityName);
this.save(categoryBrandRelation);
}
}
级联更新数据
当修改品牌名称或者分类名称时需要在关系表中也实时更新
当品牌信息更新时
BrandController
注意加上事务注解
@Transactional
/**
* 修改
*/
@Transactional
@RequestMapping("/update")
public R update(@Validated(UpdateGroup.class) @RequestBody BrandEntity brand){
brandService.updateDetail(brand);
return R.ok();
}
BrandServiceImpl
@Override
public void updateDetail(BrandEntity brand) {
this.updateById(brand);
if (!StringUtils.isEmpty(brand.getName())){
categoryBrandRelationService.updateBrand(brand.getBrandId(), brand.getName());
//TODO
}
}
CategoryBrandRelationServiceImpl
@Override
public void updateBrand(Long brandId, String name) {
CategoryBrandRelationEntity categoryBrandRelationEntity = new CategoryBrandRelationEntity();
categoryBrandRelationEntity.setBrandId(brandId);
categoryBrandRelationEntity.setBrandName(name);
this.update(categoryBrandRelationEntity, new UpdateWrapper<CategoryBrandRelationEntity>().eq("brand_id", brandId));
}
当分类数据更新时
CategoryController
/**
* 修改
*/
@Transactional
@RequestMapping("/update")
public R update(@RequestBody CategoryEntity category){
categoryService.updateCascade(category);
return R.ok();
}
CategoryServiceImpl
@Override
public void updateCascade(CategoryEntity category) {
this.updateById(category);
categoryBrandRelationService.updateCategory(category.getCatId(), category.getName());
}
CategoryBrandRelationServiceImpl
@Override
public void updateCategory(Long catId, String name) {
this.baseMapper.updateCategory(catId, name);
}
CategoryBrandRelationDao
package com.example.gulimall.product.dao;
import com.example.gulimall.product.entity.CategoryBrandRelationEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 品牌分类关联
*
* @author leohams
* @email gf879543517@163.com
* @date 2022-06-14 21:22:44
*/
@Mapper
public interface CategoryBrandRelationDao extends BaseMapper<CategoryBrandRelationEntity> {
void updateCategory(@Param("catId") Long catId, @Param("name") String name);
}
CategoryBrandRelationDao.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.gulimall.product.dao.CategoryBrandRelationDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.example.gulimall.product.entity.CategoryBrandRelationEntity" id="categoryBrandRelationMap">
<result property="id" column="id"/>
<result property="brandId" column="brand_id"/>
<result property="catelogId" column="catelog_id"/>
<result property="brandName" column="brand_name"/>
<result property="catelogName" column="catelog_name"/>
</resultMap>
<update id="updateCategory">
UPDATE 'pms_category_brand_relation' SET catelog_name=#{name} WHERE catelog_id=#{catId}?;
</update>
</mapper>
平台属性-规格参数新增与VO
package com.example.gulimall.product.vo;
import lombok.Data;
@Data
public class AttrVo {
/**
* 属性id
*/
private Long attrId;
/**
* 属性名
*/
private String attrName;
/**
* 是否需要检索[0-不需要,1-需要]
*/
private Integer searchType;
/**
* 属性图标
*/
private String icon;
/**
* 可选值列表[用逗号分隔]
*/
private String valueSelect;
/**
* 属性类型[0-销售属性,1-基本属性,2-既是销售属性又是基本属性]
*/
private Integer attrType;
/**
* 启用状态[0 - 禁用,1 - 启用]
*/
private Long enable;
/**
* 所属分类
*/
private Long catelogId;
/**
* 快速展示【是否展示在介绍上;0-否 1-是】,在sku中仍然可以调整
*/
private Integer showDesc;
private Long attrGroupId;
}
修改attr的save方法
/**
* 保存
*/
@RequestMapping("/save")
public R save(@RequestBody AttrVo attr){
attrService.saveAttr(attr);
return R.ok();
}
@Transactional
@Override
public void saveAttr(AttrVo attr) {
AttrEntity attrEntity = new AttrEntity();
BeanUtils.copyProperties(attr, attrEntity);
this.save(attrEntity);
if (attr.getAttrType() == ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode() && attr.getAttrGroupId()!=null){
AttrAttrgroupRelationEntity attrAttrgroupRelationEntity = new AttrAttrgroupRelationEntity();
Long attrGroupId = attr.getAttrGroupId();
attrAttrgroupRelationEntity.setAttrGroupId(attrGroupId);
attrAttrgroupRelationEntity.setAttrId(attrEntity.getAttrId());
attrAttrgroupRelationDao.insert(attrAttrgroupRelationEntity);
}
平台属性-规格参数列表
AttrRespVo
package com.example.gulimall.product.vo;
import lombok.Data;
@Data
public class AttrRespVo extends AttrVo{
// "catelogName": "手机/数码/手机", //所属分类名字
// "groupName": "主体", //所属分组名字
private String catelogName;
private String groupName;
}
AttrController
// /product/attr/base/list/{catelogId}
@GetMapping("/base/list/{catelogId")
public R baseAttrList(@RequestParam Map<String, Object> params,
@PathVariable("catelogId") Long catelogId){
PageUtils page = attrService.queryBaseAttrPage(params, catelogId);
return R.ok().put("page", page);
}
@Override
public PageUtils queryBaseAttrPage(Map<String, Object> params, Long catelogId) {
QueryWrapper<AttrEntity> wrapper = new QueryWrapper<>();
String key = (String) params.get("key");
if (catelogId != 0){
wrapper.eq("catelog_id", catelogId);
}
if (!StringUtils.isEmpty(key)){
wrapper.and((queryWrapper)->{
queryWrapper.eq("attr_id", key).or().like("attr_name", key);
});
// wrapper.eq("attr_id", key).or().like("attr_name", key);
}
IPage<AttrEntity> page = this.page(
new Query<AttrEntity>().getPage(params),
wrapper
);
PageUtils pageUtils = new PageUtils(page);
List<AttrEntity> records = page.getRecords();
List<AttrRespVo> respVos = records.stream().map((attrEntity) -> {
AttrRespVo attrRespVo = new AttrRespVo();
BeanUtils.copyProperties(attrEntity, attrRespVo);
//设置分类和分组的名字
AttrAttrgroupRelationEntity attr_id = attrAttrgroupRelationDao.selectOne(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attrEntity.getAttrId()));
if (attr_id != null) {
AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attr_id.getAttrGroupId());
attrRespVo.setGroupName(attrGroupEntity.getAttrGroupName());
}
CategoryEntity categoryEntity = categoryDao.selectById(attrEntity.getCatelogId());
if (categoryEntity != null) {
attrRespVo.setCatelogName(categoryEntity.getName());
}
return attrRespVo;
}).collect(Collectors.toList());
pageUtils.setList(respVos);
return pageUtils;
}
平台属性-规格修改
回显数据
AttrController
/**
* 信息
*/
// /product/attr/info/{attrId}
@RequestMapping("/info/{attrId}")
public R info(@PathVariable("attrId") Long attrId){
// AttrEntity attr = attrService.getById(attrId);
AttrRespVo attrRespVo = attrService.getAttrInfo(attrId);
return R.ok().put("attr", attrRespVo);
}
AttrRespVo
package com.example.gulimall.product.vo;
import lombok.Data;
import java.util.List;
@Data
public class AttrRespVo extends AttrVo{
// "catelogName": "手机/数码/手机", //所属分类名字
// "groupName": "主体", //所属分组名字
private String catelogName;
private String groupName;
private Long[] catelogPath;
}
AttrServiceImpl
@Override
public AttrRespVo getAttrInfo(Long attrId) {
AttrRespVo respVo = new AttrRespVo();
AttrEntity attrEntity = this.getById(attrId);
BeanUtils.copyProperties(attrEntity, respVo);
// 设置分组的信息
AttrAttrgroupRelationEntity attr_id = attrAttrgroupRelationDao.selectOne(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attrEntity.getAttrId()));
if (attr_id != null) {
respVo.setAttrGroupId(attr_id.getAttrGroupId());
AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attr_id.getAttrGroupId());
if (attrGroupEntity != null){
respVo.setGroupName(attrGroupEntity.getAttrGroupName());
}
}
//设置分类信息
Long catelogId = attrEntity.getCatelogId();
List<Long> paths = new ArrayList<>();
Long[] catelogPath = categoryService.findCatelogPath(catelogId);
respVo.setCatelogPath(catelogPath);
CategoryEntity categoryEntity = categoryDao.selectById(catelogId);
if (categoryEntity!= null){
respVo.setCatelogName(categoryEntity.getName());
}
return respVo;
}
修改数据
AttrController
// /product/attr/update
@RequestMapping("/update")
public R update(@RequestBody AttrVo attr){
attrService.updateAttr(attr);
return R.ok();
}
AttrServiceImpl
@Transactional
@Override
public void updateAttr(AttrVo attr) {
AttrEntity attrEntity = new AttrEntity();
BeanUtils.copyProperties(attr, attrEntity);
this.updateById(attrEntity);
//修改分组关联
AttrAttrgroupRelationEntity attrAttrgroupRelationEntity = new AttrAttrgroupRelationEntity();
attrAttrgroupRelationEntity.setAttrGroupId(attr.getAttrGroupId());
attrAttrgroupRelationEntity.setAttrId(attr.getAttrId());
Integer count = attrAttrgroupRelationDao.selectCount(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attr.getAttrId()));
if (count>0){
attrAttrgroupRelationDao.update(attrAttrgroupRelationEntity, new UpdateWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attr.getAttrId()));
}else {
attrAttrgroupRelationDao.insert(attrAttrgroupRelationEntity);
}
}
平台属性-销售属性维护
AttrController
/**
* 列表
*/
// /product/attr/base/list/{catelogId}
// /product/attr/sale/list/{catelogId}
@GetMapping("/{attrType}/list/{catelogId}")
public R baseAttrList(@RequestParam Map<String, Object> params,
@PathVariable("catelogId") Long catelogId,
@PathVariable("attrType") String type){
PageUtils page = attrService.queryBaseAttrPage(params, catelogId, type);
return R.ok().put("page", page);
}
queryBaseAttrPage
@Override
public PageUtils queryBaseAttrPage(Map<String, Object> params, Long catelogId, String type) {
QueryWrapper<AttrEntity> wrapper = new QueryWrapper<AttrEntity>().eq("attr_type", "base".equalsIgnoreCase(type)?1:0);
String key = (String) params.get("key");
if (catelogId != 0){
wrapper.eq("catelog_id", catelogId);
}
if (!StringUtils.isEmpty(key)){
wrapper.and((queryWrapper)->{
queryWrapper.eq("attr_id", key).or().like("attr_name", key);
});
// wrapper.eq("attr_id", key).or().like("attr_name", key);
}
IPage<AttrEntity> page = this.page(
new Query<AttrEntity>().getPage(params),
wrapper
);
PageUtils pageUtils = new PageUtils(page);
List<AttrEntity> records = page.getRecords();
List<AttrRespVo> respVos = records.stream().map((attrEntity) -> {
AttrRespVo attrRespVo = new AttrRespVo();
BeanUtils.copyProperties(attrEntity, attrRespVo);
//设置分类和分组的名字
//设置分类和分组的名字
if ("base".equalsIgnoreCase(type)){
AttrAttrgroupRelationEntity attr_id = attrAttrgroupRelationDao.selectOne(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attrEntity.getAttrId()));
if (attr_id != null) {
AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attr_id.getAttrGroupId());
attrRespVo.setGroupName(attrGroupEntity.getAttrGroupName());
}
}
CategoryEntity categoryEntity = categoryDao.selectById(attrEntity.getCatelogId());
if (categoryEntity != null) {
attrRespVo.setCatelogName(categoryEntity.getName());
}
return attrRespVo;
}).collect(Collectors.toList());
pageUtils.setList(respVos);
return pageUtils;
}
在common文件夹中创建一个枚举类ProductConstant ,用来代替1或0,并在每次设置分组信息时都判断一下是否是基本属性。
package com.example.common.constant;
public class ProductConstant {
public enum AttrEnum{
ATTR_TYPE_BASE(1, "基本属性"), ATTR_TYPE_SALE(0, "销售属性");
private int code;
private String msg;
public int getCode() {
return code;
}
public String getMsg() {
return msg;
}
AttrEnum(int code, String msg){
this.code = code;
this.msg = msg;
}
}
}
平台属性-查询分组关联属性&删除关联
AttrController
/**
* 列表
*/
// /product/attr/base/list/{catelogId}
// /product/attr/sale/list/{catelogId}
@GetMapping("/{attrType}/list/{catelogId}")
public R baseAttrList(@RequestParam Map<String, Object> params,
@PathVariable("catelogId") Long catelogId,
@PathVariable("attrType") String type){
PageUtils page = attrService.queryBaseAttrPage(params, catelogId, type);
return R.ok().put("page", page);
}
AttrServiceImpl
@Override
public List<AttrEntity> getRelationAttr(Long attrgroupId) {
List<AttrAttrgroupRelationEntity> entities = attrAttrgroupRelationDao.selectList(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_group_id", attrgroupId));
List<Long> attrIds = entities.stream().map((attr) -> {
return attr.getAttrId();
}).collect(Collectors.toList());
List<AttrEntity> attrEntities = this.listByIds(attrIds);
return attrEntities;
}
删除关联
AttrGroupController
/**
* 删除
*/
// /product/attrgroup/attr/relation/delete
@PostMapping("/attr/relation/delete")
public R deleteRelation(@RequestBody AttrGroupRelationVo[] vos){
attrService.deleteRelation(vos);
return R.ok();
}
创建一个接收体Vo
AttrGroupRelationVo
package com.example.gulimall.product.vo;
import lombok.Data;
@Data
public class AttrGroupRelationVo {
// [{"attrId":1,"attrGroupId":2}]
private Long attrId;
private Long attrGroupId;
}
AttrServiceImpl
@Override
public void deleteRelation(AttrGroupRelationVo[] vos) {
// attrAttrgroupRelationDao.delete(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", 1L).eq("attr_group_id", 1L));
List<AttrAttrgroupRelationEntity> relationEntityList = Arrays.asList(vos).stream().map((item) -> {
AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity();
BeanUtils.copyProperties(item, relationEntity);
return relationEntity;
}).collect(Collectors.toList());
attrAttrgroupRelationDao.deleteBatchRelation(relationEntityList);
}
AttrAttrgroupRelationDao
package com.example.gulimall.product.dao;
import com.example.gulimall.product.entity.AttrAttrgroupRelationEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.PathVariable;
import java.util.List;
/**
* 属性&属性分组关联
*
* @author leohams
* @email gf879543517@163.com
* @date 2022-06-14 21:22:44
*/
@Mapper
public interface AttrAttrgroupRelationDao extends BaseMapper<AttrAttrgroupRelationEntity> {
void deleteBatchRelation(@Param("relationEntityList") List<AttrAttrgroupRelationEntity> relationEntityList);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.gulimall.product.dao.AttrAttrgroupRelationDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.example.gulimall.product.entity.AttrAttrgroupRelationEntity" id="attrAttrgroupRelationMap">
<result property="id" column="id"/>
<result property="attrId" column="attr_id"/>
<result property="attrGroupId" column="attr_group_id"/>
<result property="attrSort" column="attr_sort"/>
</resultMap>
<delete id="deleteBatchRelation">
DELETE FROM 'pms_attr_attrgroup_relation' WHERE
<foreach collection="relationEntityList" separator=" OR " item="item">
attr_id=#{item.attrId} AND attr_group_id=#{item.attrGroupId}
</foreach>
</delete>
</mapper>
平台属性-查询分组未关联的属性
AttrGroupController
// /product/attrgroup/{attrgroupId}/noattr/relation
@GetMapping("/{attrgroupId}/noattr/relation")
public R attrNoRelation(@RequestParam Map<String, Object> params,
@PathVariable("attrgroupId") Long attrgroupId){
PageUtils page = attrService.getNoRelationAttr(params, attrgroupId);
return R.ok().put("data", page);
}
AttrServiceImpl
/**
* 获取当前分组没有关联的属性
* @param params
* @param attrgroupId
* @return
*/
@Override
public PageUtils getNoRelationAttr(Map<String, Object> params, Long attrgroupId) {
//1、当前分组只能关联自己所属的分类里面的所有属性
AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attrgroupId);
Long catelogId = attrGroupEntity.getCatelogId();
//2、当前分组只能关联别的分组没有引入的属性
//2.1、当前分类下的其他分组
List<AttrGroupEntity> group = attrGroupDao.selectList(
new QueryWrapper<AttrGroupEntity>().eq("catelog_id", catelogId));
List<Long> groupIds = group.stream().map((item) -> {
Long attrGroupId = item.getAttrGroupId();
return attrGroupId;
}).collect(Collectors.toList());
//2.2、这些分组关联的属性
List<AttrAttrgroupRelationEntity> entities = attrAttrgroupRelationDao.selectList(new QueryWrapper<AttrAttrgroupRelationEntity>().in("attr_group_id", groupIds));
List<Long> attrIds = entities.stream().map((item) -> {
return item.getAttrId();
}).collect(Collectors.toList());
//2.3、从当前分类的所有属性中移除这些属性
QueryWrapper<AttrEntity> wrapper = new QueryWrapper<AttrEntity>().eq("catelog_id", catelogId).eq("attr_type", ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode());
if (attrIds != null && attrIds.size()>0){
wrapper.notIn("attr_id", attrIds);
}
String key = (String) params.get("key");
if (!StringUtils.isEmpty(key)){
wrapper.and((w)->{
w.eq("attr_id", key).or().like("attr_name", key);
});
}
IPage<AttrEntity> page = this.page(new Query<AttrEntity>().getPage(params), wrapper);
PageUtils pageUtils = new PageUtils(page);
return pageUtils;
}
平台属性-新增分组和属性关联
AttrGroupController
// /product/attrgroup/attr/relation
@PostMapping("/attr/relation")
public R addRelation(@RequestBody List<AttrGroupRelationVo> vos){
relationService.saveBatch(vos);
return R.ok();
}
AttrAttrgroupRelationServiceImpl
@Override
public void saveBatch(List<AttrGroupRelationVo> vos) {
List<AttrAttrgroupRelationEntity> relationEntities = vos.stream().map((item) -> {
AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity();
BeanUtils.copyProperties(item, relationEntity);
return relationEntity;
}).collect(Collectors.toList());
this.saveBatch(relationEntities);
}
debug事务时可以在数据库中运行以下命令:
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;