SELECT ssav.`attr_id`,ssav.`attr_name`,GROUP_CONCAT(DISTINCT ssav.`attr_value`) FROM pms_sku_info info LEFT JOIN pms_sku_sale_attr_value AS ssav ON info.`sku_id` = ssav.`sku_id` WHERE info.`spu_id` = 16 GROUP BY ssav.`attr_id`,ssav.`attr_name`
SELECT ssav.`attr_id`,ssav.`attr_name`,GROUP_CONCAT(DISTINCT ssav.`attr_value`) FROM pms_sku_info info
LEFT JOIN pms_sku_sale_attr_value AS ssav ON info.`sku_id` = ssav.`sku_id`
WHERE info.`spu_id` = 16 GROUP BY ssav.`attr_id`,ssav.`attr_name`
package com.alatus.mall.product.web; import com.alatus.mall.product.service.SkuInfoService; import com.alatus.mall.product.vo.SkuItemVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @Controller public class ItemController { @Autowired private SkuInfoService skuInfoService; @GetMapping("/{skuId}.html") public String skuItem(@PathVariable("skuId") Long skuId, Model model){ SkuItemVo skuItemVo = skuInfoService.item(skuId); model.addAttribute("item",skuItemVo); return "item"; } }
package com.alatus.mall.product.web; import com.alatus.mall.product.service.SkuInfoService; import com.alatus.mall.product.vo.SkuItemVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @Controller public class ItemController { @Autowired private SkuInfoService skuInfoService; @GetMapping("/{skuId}.html") public String skuItem(@PathVariable("skuId") Long skuId, Model model){ SkuItemVo skuItemVo = skuInfoService.item(skuId); model.addAttribute("item",skuItemVo); return "item"; } }
/** * Copyright 2024 bejson.com */ package com.alatus.mall.product.vo; import lombok.Data; /** * Auto-generated: 2024-06-27 16:17:50 * * @author bejson.com (i@bejson.com) * @website http://www.bejson.com/java2pojo/ */ @Data public class Attr { private Long attrId; private String attrName; private String attrValue; }
/** * Copyright 2024 bejson.com */ package com.alatus.mall.product.vo; import lombok.Data; /** * Auto-generated: 2024-06-27 16:17:50 * * @author bejson.com (i@bejson.com) * @website http://www.bejson.com/java2pojo/ */ @Data public class Attr { private Long attrId; private String attrName; private String attrValue; }
package com.alatus.mall.product.vo; import lombok.Data; import java.util.List; @Data public class SpuItemAttrGroupVo{ private String groupName; private List<Attr> attrs; }
package com.alatus.mall.product.vo; import lombok.Data; import java.util.List; @Data public class SpuItemAttrGroupVo{ private String groupName; private List<Attr> attrs; }
package com.alatus.mall.product.service.impl; import com.alatus.mall.product.dao.SkuInfoDao; import com.alatus.mall.product.entity.SkuImagesEntity; import com.alatus.mall.product.entity.SkuInfoEntity; import com.alatus.mall.product.entity.SpuInfoDescEntity; import com.alatus.mall.product.service.*; import com.alatus.mall.product.vo.Attr; import com.alatus.mall.product.vo.SkuItemVo; import com.alatus.mall.product.vo.SpuItemAttrGroupVo; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.List; 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.alatus.common.utils.PageUtils; import com.alatus.common.utils.Query; @Service("pmsSkuInfoService") public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoDao, SkuInfoEntity> implements SkuInfoService { @Autowired private SkuImagesService skuImagesService; @Autowired private SpuInfoDescService spuInfoDescService; @Autowired private AttrGroupService attrGroupService; @Autowired private SkuSaleAttrValueService skuSaleAttrValueService; @Override public PageUtils queryPage(Map<String, Object> params) { QueryWrapper<SkuInfoEntity> queryWrapper = new QueryWrapper<>(); String key = (String) params.get("key"); if(!StringUtils.isEmpty(key) && !"0".equalsIgnoreCase(key)){ queryWrapper.and((wrapper) -> { wrapper.eq("sku_id",key).or().like("sku_name",key); }); } String catelogId = (String) params.get("catelogId"); if(!StringUtils.isEmpty(catelogId) && !"0".equalsIgnoreCase(catelogId)){ queryWrapper.eq("catalog_id",catelogId); } String brandId = (String) params.get("brandId"); if(!StringUtils.isEmpty(brandId) && !"0".equalsIgnoreCase(brandId)){ queryWrapper.eq("brand_id",brandId); } String min = (String) params.get("min"); if(!StringUtils.isEmpty(min) && !"0".equalsIgnoreCase(min)){ queryWrapper.ge("price",min); } String max = (String) params.get("max"); if(!StringUtils.isEmpty(max) && !"0".equalsIgnoreCase(max)){ try{ BigDecimal maxPrice = new BigDecimal(max); if(maxPrice.compareTo(new BigDecimal("0")) == 1){ queryWrapper.le("price",max); } } catch (Exception e){ e.printStackTrace(); } } IPage<SkuInfoEntity> page = this.page( new Query<SkuInfoEntity>().getPage(params), queryWrapper ); return new PageUtils(page); } @Override public void saveSkuInfo(SkuInfoEntity skuInfoEntity) { this.baseMapper.insert(skuInfoEntity); } @Override public List<SkuInfoEntity> getSkusBySpuId(Long spuId) { return this.list(new QueryWrapper<SkuInfoEntity>().eq("spu_id",spuId)); } @Override public SkuItemVo item(Long skuId) { SkuItemVo skuItemVo = new SkuItemVo(); // 设置基本信息 SkuInfoEntity skuInfoEntity = getById(skuId); Long catalogId = skuInfoEntity.getCatalogId(); Long spuId = skuInfoEntity.getSpuId(); skuItemVo.setInfo(skuInfoEntity); // 设置spu的销售属性组合 List<Attr> skuItemSaleAttrVos = skuSaleAttrValueService.getSaleAttrsBySpuId(spuId); skuItemVo.setSaleAttr(skuItemSaleAttrVos); // 设置sku的图片信息 List<SkuImagesEntity> images = skuImagesService.getBySkuId(skuId); skuItemVo.setImages(images); // 获取spu的介绍 SpuInfoDescEntity spuInfoDesc = spuInfoDescService.getById(spuId); skuItemVo.setDesc(spuInfoDesc); // 获取SPU的规格参数信息 List<SpuItemAttrGroupVo> attrGroupVos = attrGroupService.getAttrGroupWithAttrsBySpuId(spuId,catalogId); skuItemVo.setGroupAttrs(attrGroupVos); return skuItemVo; } }
package com.alatus.mall.product.service.impl; import com.alatus.mall.product.dao.SkuInfoDao; import com.alatus.mall.product.entity.SkuImagesEntity; import com.alatus.mall.product.entity.SkuInfoEntity; import com.alatus.mall.product.entity.SpuInfoDescEntity; import com.alatus.mall.product.service.*; import com.alatus.mall.product.vo.Attr; import com.alatus.mall.product.vo.SkuItemVo; import com.alatus.mall.product.vo.SpuItemAttrGroupVo; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.List; 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.alatus.common.utils.PageUtils; import com.alatus.common.utils.Query; @Service("pmsSkuInfoService") public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoDao, SkuInfoEntity> implements SkuInfoService { @Autowired private SkuImagesService skuImagesService; @Autowired private SpuInfoDescService spuInfoDescService; @Autowired private AttrGroupService attrGroupService; @Autowired private SkuSaleAttrValueService skuSaleAttrValueService; @Override public PageUtils queryPage(Map<String, Object> params) { QueryWrapper<SkuInfoEntity> queryWrapper = new QueryWrapper<>(); String key = (String) params.get("key"); if(!StringUtils.isEmpty(key) && !"0".equalsIgnoreCase(key)){ queryWrapper.and((wrapper) -> { wrapper.eq("sku_id",key).or().like("sku_name",key); }); } String catelogId = (String) params.get("catelogId"); if(!StringUtils.isEmpty(catelogId) && !"0".equalsIgnoreCase(catelogId)){ queryWrapper.eq("catalog_id",catelogId); } String brandId = (String) params.get("brandId"); if(!StringUtils.isEmpty(brandId) && !"0".equalsIgnoreCase(brandId)){ queryWrapper.eq("brand_id",brandId); } String min = (String) params.get("min"); if(!StringUtils.isEmpty(min) && !"0".equalsIgnoreCase(min)){ queryWrapper.ge("price",min); } String max = (String) params.get("max"); if(!StringUtils.isEmpty(max) && !"0".equalsIgnoreCase(max)){ try{ BigDecimal maxPrice = new BigDecimal(max); if(maxPrice.compareTo(new BigDecimal("0")) == 1){ queryWrapper.le("price",max); } } catch (Exception e){ e.printStackTrace(); } } IPage<SkuInfoEntity> page = this.page( new Query<SkuInfoEntity>().getPage(params), queryWrapper ); return new PageUtils(page); } @Override public void saveSkuInfo(SkuInfoEntity skuInfoEntity) { this.baseMapper.insert(skuInfoEntity); } @Override public List<SkuInfoEntity> getSkusBySpuId(Long spuId) { return this.list(new QueryWrapper<SkuInfoEntity>().eq("spu_id",spuId)); } @Override public SkuItemVo item(Long skuId) { SkuItemVo skuItemVo = new SkuItemVo(); // 设置基本信息 SkuInfoEntity skuInfoEntity = getById(skuId); Long catalogId = skuInfoEntity.getCatalogId(); Long spuId = skuInfoEntity.getSpuId(); skuItemVo.setInfo(skuInfoEntity); // 设置spu的销售属性组合 List<Attr> skuItemSaleAttrVos = skuSaleAttrValueService.getSaleAttrsBySpuId(spuId); skuItemVo.setSaleAttr(skuItemSaleAttrVos); // 设置sku的图片信息 List<SkuImagesEntity> images = skuImagesService.getBySkuId(skuId); skuItemVo.setImages(images); // 获取spu的介绍 SpuInfoDescEntity spuInfoDesc = spuInfoDescService.getById(spuId); skuItemVo.setDesc(spuInfoDesc); // 获取SPU的规格参数信息 List<SpuItemAttrGroupVo> attrGroupVos = attrGroupService.getAttrGroupWithAttrsBySpuId(spuId,catalogId); skuItemVo.setGroupAttrs(attrGroupVos); return skuItemVo; } }
package com.alatus.mall.product.service; import com.alatus.mall.product.vo.AttrGroupWithAttrsVo; import com.alatus.mall.product.vo.SpuItemAttrGroupVo; import com.baomidou.mybatisplus.extension.service.IService; import com.alatus.common.utils.PageUtils; import com.alatus.mall.product.entity.AttrGroupEntity; import java.util.List; import java.util.Map; /** * 属性分组 * * @author alatus * @email 1571345941@qq.com * @date 2024-03-12 13:05:34 */ public interface AttrGroupService extends IService<AttrGroupEntity> { PageUtils queryPage(Map<String, Object> params); PageUtils queryPage(Map<String, Object>params,Long catelogId); List<AttrGroupWithAttrsVo> getAttrGroupWithAttrsByCatelogId(Long catelogId); List<SpuItemAttrGroupVo> getAttrGroupWithAttrsBySpuId(Long spuId, Long catalogId); }
package com.alatus.mall.product.service; import com.alatus.mall.product.vo.AttrGroupWithAttrsVo; import com.alatus.mall.product.vo.SpuItemAttrGroupVo; import com.baomidou.mybatisplus.extension.service.IService; import com.alatus.common.utils.PageUtils; import com.alatus.mall.product.entity.AttrGroupEntity; import java.util.List; import java.util.Map; /** * 属性分组 * * @author alatus * @email 1571345941@qq.com * @date 2024-03-12 13:05:34 */ public interface AttrGroupService extends IService<AttrGroupEntity> { PageUtils queryPage(Map<String, Object> params); PageUtils queryPage(Map<String, Object>params,Long catelogId); List<AttrGroupWithAttrsVo> getAttrGroupWithAttrsByCatelogId(Long catelogId); List<SpuItemAttrGroupVo> getAttrGroupWithAttrsBySpuId(Long spuId, Long catalogId); }
package com.alatus.mall.product.service.impl; import com.alatus.mall.product.dao.SkuSaleAttrValueDao; import com.alatus.mall.product.entity.SkuSaleAttrValueEntity; import com.alatus.mall.product.service.SkuSaleAttrValueService; import com.alatus.mall.product.vo.Attr; import org.springframework.stereotype.Service; import java.util.List; 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.alatus.common.utils.PageUtils; import com.alatus.common.utils.Query; @Service("pmsSkuSaleAttrValueService") public class SkuSaleAttrValueServiceImpl extends ServiceImpl<SkuSaleAttrValueDao, SkuSaleAttrValueEntity> implements SkuSaleAttrValueService { @Override public PageUtils queryPage(Map<String, Object> params) { IPage<SkuSaleAttrValueEntity> page = this.page( new Query<SkuSaleAttrValueEntity>().getPage(params), new QueryWrapper<SkuSaleAttrValueEntity>() ); return new PageUtils(page); } @Override public List<Attr> getSaleAttrsBySpuId(Long spuId) { List<Attr> skuItemSaleAttrVos = this.baseMapper.getSaleAttrsBySpuId(spuId); return skuItemSaleAttrVos; } }
package com.alatus.mall.product.service.impl; import com.alatus.mall.product.dao.SkuSaleAttrValueDao; import com.alatus.mall.product.entity.SkuSaleAttrValueEntity; import com.alatus.mall.product.service.SkuSaleAttrValueService; import com.alatus.mall.product.vo.Attr; import org.springframework.stereotype.Service; import java.util.List; 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.alatus.common.utils.PageUtils; import com.alatus.common.utils.Query; @Service("pmsSkuSaleAttrValueService") public class SkuSaleAttrValueServiceImpl extends ServiceImpl<SkuSaleAttrValueDao, SkuSaleAttrValueEntity> implements SkuSaleAttrValueService { @Override public PageUtils queryPage(Map<String, Object> params) { IPage<SkuSaleAttrValueEntity> page = this.page( new Query<SkuSaleAttrValueEntity>().getPage(params), new QueryWrapper<SkuSaleAttrValueEntity>() ); return new PageUtils(page); } @Override public List<Attr> getSaleAttrsBySpuId(Long spuId) { List<Attr> skuItemSaleAttrVos = this.baseMapper.getSaleAttrsBySpuId(spuId); return skuItemSaleAttrVos; } }
package com.alatus.mall.product.dao; import com.alatus.mall.product.entity.SkuSaleAttrValueEntity; import com.alatus.mall.product.vo.Attr; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.util.List; /** * sku销售属性&值 * * @author Alatus * @email 1571345941@qq.com * @date 2024-06-08 16:06:24 */ @Mapper public interface SkuSaleAttrValueDao extends BaseMapper<SkuSaleAttrValueEntity> { List<Attr> getSaleAttrsBySpuId(@Param("spuId") Long spuId); }
package com.alatus.mall.product.dao; import com.alatus.mall.product.entity.SkuSaleAttrValueEntity; import com.alatus.mall.product.vo.Attr; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.util.List; /** * sku销售属性&值 * * @author Alatus * @email 1571345941@qq.com * @date 2024-06-08 16:06:24 */ @Mapper public interface SkuSaleAttrValueDao extends BaseMapper<SkuSaleAttrValueEntity> { List<Attr> getSaleAttrsBySpuId(@Param("spuId") Long spuId); }
<?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.alatus.mall.product.dao.SkuSaleAttrValueDao"> <!-- 可根据自己的需求,是否要使用 --> <resultMap type="com.alatus.mall.product.entity.SkuSaleAttrValueEntity" id="skuSaleAttrValueMap"> <result property="id" column="id"/> <result property="skuId" column="sku_id"/> <result property="attrId" column="attr_id"/> <result property="attrName" column="attr_name"/> <result property="attrValue" column="attr_value"/> <result property="attrSort" column="attr_sort"/> </resultMap> <select id="getSaleAttrsBySpuId" resultType="com.alatus.mall.product.vo.Attr"> SELECT ssav.`attr_id` attr_id,ssav.`attr_name` attr_name,GROUP_CONCAT(DISTINCT ssav.`attr_value`) attr_value FROM pms_sku_info info LEFT JOIN pms_sku_sale_attr_value AS ssav ON info.`sku_id` = ssav.`sku_id` WHERE info.`spu_id` = #{spuId} GROUP BY ssav.`attr_id`,ssav.`attr_name` </select> </mapper>
<?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.alatus.mall.product.dao.SkuSaleAttrValueDao"> <!-- 可根据自己的需求,是否要使用 --> <resultMap type="com.alatus.mall.product.entity.SkuSaleAttrValueEntity" id="skuSaleAttrValueMap"> <result property="id" column="id"/> <result property="skuId" column="sku_id"/> <result property="attrId" column="attr_id"/> <result property="attrName" column="attr_name"/> <result property="attrValue" column="attr_value"/> <result property="attrSort" column="attr_sort"/> </resultMap> <select id="getSaleAttrsBySpuId" resultType="com.alatus.mall.product.vo.Attr"> SELECT ssav.`attr_id` attr_id,ssav.`attr_name` attr_name,GROUP_CONCAT(DISTINCT ssav.`attr_value`) attr_value FROM pms_sku_info info LEFT JOIN pms_sku_sale_attr_value AS ssav ON info.`sku_id` = ssav.`sku_id` WHERE info.`spu_id` = #{spuId} GROUP BY ssav.`attr_id`,ssav.`attr_name` </select> </mapper>
package com.alatus.mall.product.service.impl; import com.alatus.mall.product.service.AttrService; import com.alatus.mall.product.vo.AttrGroupWithAttrsVo; import com.alatus.mall.product.vo.SpuItemAttrGroupVo; import org.apache.commons.lang.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; import java.util.Map; import java.util.stream.Collectors; 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.alatus.common.utils.PageUtils; import com.alatus.common.utils.Query; import com.alatus.mall.product.dao.AttrGroupDao; import com.alatus.mall.product.entity.AttrGroupEntity; import com.alatus.mall.product.service.AttrGroupService; @Service("attrGroupService") public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupDao, AttrGroupEntity> implements AttrGroupService { @Autowired private AttrService attrService; @Override public PageUtils queryPage(Map<String, Object> params) { IPage<AttrGroupEntity> page = this.page( new Query<AttrGroupEntity>().getPage(params), new QueryWrapper<AttrGroupEntity>() ); return new PageUtils(page); } @Override public PageUtils queryPage(Map<String, Object> params, Long catelogId) { String key = (String) params.get("key"); QueryWrapper<AttrGroupEntity> wrapper = new QueryWrapper<AttrGroupEntity>(); if (!StringUtils.isEmpty(key)){ wrapper.and((obj) -> { obj.eq("attr_group_id",key).or().like("attr_group_name",key); }); } if(catelogId == 0){ IPage<AttrGroupEntity> page = this.page(new Query<AttrGroupEntity>().getPage(params), wrapper); return new PageUtils(page); } else{ wrapper.eq("catelog_id",catelogId); IPage<AttrGroupEntity> page = this.page(new Query<AttrGroupEntity>().getPage(params),wrapper); return new PageUtils(page); } } // 根据分类ID查出所有的分组以及组里面的属性 @Override public List<AttrGroupWithAttrsVo> getAttrGroupWithAttrsByCatelogId(Long catelogId) { // 查询分组信息 List<AttrGroupEntity> list = this.list(new QueryWrapper<AttrGroupEntity>().eq("catelog_id", catelogId)); List<AttrGroupWithAttrsVo> voList = list.stream().map(item -> { AttrGroupWithAttrsVo attrGroupWithAttrsVo = new AttrGroupWithAttrsVo(); BeanUtils.copyProperties(item, attrGroupWithAttrsVo); attrGroupWithAttrsVo.setAttrs(attrService.getRelationAttr(attrGroupWithAttrsVo.getAttrGroupId())); return attrGroupWithAttrsVo; }).collect(Collectors.toList()); return voList; } @Override public List<SpuItemAttrGroupVo> getAttrGroupWithAttrsBySpuId(Long spuId, Long catalogId) { // 查出当前SPU对应的所有属性的分组信息以及当前分组下的所有属性对应的值 List<SpuItemAttrGroupVo> vos = this.getBaseMapper().getAttrGroupWithAttrsBySpuId(spuId,catalogId); return vos; } }
package com.alatus.mall.product.service.impl; import com.alatus.mall.product.service.AttrService; import com.alatus.mall.product.vo.AttrGroupWithAttrsVo; import com.alatus.mall.product.vo.SpuItemAttrGroupVo; import org.apache.commons.lang.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; import java.util.Map; import java.util.stream.Collectors; 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.alatus.common.utils.PageUtils; import com.alatus.common.utils.Query; import com.alatus.mall.product.dao.AttrGroupDao; import com.alatus.mall.product.entity.AttrGroupEntity; import com.alatus.mall.product.service.AttrGroupService; @Service("attrGroupService") public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupDao, AttrGroupEntity> implements AttrGroupService { @Autowired private AttrService attrService; @Override public PageUtils queryPage(Map<String, Object> params) { IPage<AttrGroupEntity> page = this.page( new Query<AttrGroupEntity>().getPage(params), new QueryWrapper<AttrGroupEntity>() ); return new PageUtils(page); } @Override public PageUtils queryPage(Map<String, Object> params, Long catelogId) { String key = (String) params.get("key"); QueryWrapper<AttrGroupEntity> wrapper = new QueryWrapper<AttrGroupEntity>(); if (!StringUtils.isEmpty(key)){ wrapper.and((obj) -> { obj.eq("attr_group_id",key).or().like("attr_group_name",key); }); } if(catelogId == 0){ IPage<AttrGroupEntity> page = this.page(new Query<AttrGroupEntity>().getPage(params), wrapper); return new PageUtils(page); } else{ wrapper.eq("catelog_id",catelogId); IPage<AttrGroupEntity> page = this.page(new Query<AttrGroupEntity>().getPage(params),wrapper); return new PageUtils(page); } } // 根据分类ID查出所有的分组以及组里面的属性 @Override public List<AttrGroupWithAttrsVo> getAttrGroupWithAttrsByCatelogId(Long catelogId) { // 查询分组信息 List<AttrGroupEntity> list = this.list(new QueryWrapper<AttrGroupEntity>().eq("catelog_id", catelogId)); List<AttrGroupWithAttrsVo> voList = list.stream().map(item -> { AttrGroupWithAttrsVo attrGroupWithAttrsVo = new AttrGroupWithAttrsVo(); BeanUtils.copyProperties(item, attrGroupWithAttrsVo); attrGroupWithAttrsVo.setAttrs(attrService.getRelationAttr(attrGroupWithAttrsVo.getAttrGroupId())); return attrGroupWithAttrsVo; }).collect(Collectors.toList()); return voList; } @Override public List<SpuItemAttrGroupVo> getAttrGroupWithAttrsBySpuId(Long spuId, Long catalogId) { // 查出当前SPU对应的所有属性的分组信息以及当前分组下的所有属性对应的值 List<SpuItemAttrGroupVo> vos = this.getBaseMapper().getAttrGroupWithAttrsBySpuId(spuId,catalogId); return vos; } }
package com.alatus.mall.product.service; import com.alatus.mall.product.entity.SkuSaleAttrValueEntity; import com.alatus.mall.product.vo.Attr; import com.baomidou.mybatisplus.extension.service.IService; import com.alatus.common.utils.PageUtils; import java.util.List; import java.util.Map; /** * sku销售属性&值 * * @author Alatus * @email 1571345941@qq.com * @date 2024-06-08 16:06:24 */ public interface SkuSaleAttrValueService extends IService<SkuSaleAttrValueEntity> { PageUtils queryPage(Map<String, Object> params); List<Attr> getSaleAttrsBySpuId(Long spuId); }
package com.alatus.mall.product.service; import com.alatus.mall.product.entity.SkuSaleAttrValueEntity; import com.alatus.mall.product.vo.Attr; import com.baomidou.mybatisplus.extension.service.IService; import com.alatus.common.utils.PageUtils; import java.util.List; import java.util.Map; /** * sku销售属性&值 * * @author Alatus * @email 1571345941@qq.com * @date 2024-06-08 16:06:24 */ public interface SkuSaleAttrValueService extends IService<SkuSaleAttrValueEntity> { PageUtils queryPage(Map<String, Object> params); List<Attr> getSaleAttrsBySpuId(Long spuId); }