✅P206_商城业务-商品详情-销售属性组合

gong_yz小于 1 分钟谷粒商城

开篇

通过spuId获取每个skuId,通过skuId获取销售属性组合

注:group_concat函数open in new window


代码实现

cfmall-product/src/main/java/com/gyz/cfmall/product/service/impl/SkuInfoServiceImpl.java#item

    @Override
    public SkuItemVo item(Long skuId) {
        SkuItemVo skuItemVo = new SkuItemVo();
		//其它代码省略...
        
        //5、获取spu的销售属性组合
        List<SkuItemSaleAttrVo> saleAttrVos = skuSaleAttrValueService.getSaleAttrBySpuId(spuId);
        skuItemVo.setSaleAttr(saleAttrVos);

        return skuItemVo;
    }

cfmall-product/src/main/java/com/gyz/cfmall/product/service/impl/SkuSaleAttrValueServiceImpl.java

 @Override
 public List<SkuItemSaleAttrVo> getSaleAttrBySpuId(Long spuId) {
     SkuSaleAttrValueDao baseMapper = this.getBaseMapper();
     List<SkuItemSaleAttrVo> saleAttrVos = baseMapper.getSaleAttrBySpuId(spuId);
     return saleAttrVos;
 }

cfmall-product/src/main/resources/mapper/product/SkuSaleAttrValueDao.xml

<select id="getSaleAttrBySpuId" resultMap="skuItemSaleAttrVo">
    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 ssav ON ssav.sku_id = info.sku_id
    WHERE
        info.spu_id = #{spuId}
    GROUP BY
        ssav.attr_id,
        ssav.attr_name
</select>