<?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.xjs.mall.product.dao.SkuSaleAttrValueDao">

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.xjs.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>

    <resultMap id="skuItemSaleAttrVo" type="com.xjs.mall.product.vo.sku.SkuItemSaleAttrVo">
        <result column="attr_id" property="attrId"></result>
        <result column="attr_name" property="attrName"></result>
        <collection property="attrValues" ofType="com.xjs.mall.product.vo.sku.AttrValueWithSkuIdVO">
            <result column="attr_value" property="attrValue"></result>
            <result column="sku_ids" property="skuIds"></result>
        </collection>
    </resultMap>

    <select id="getSaleAttrsBySpuId" resultMap="skuItemSaleAttrVo">
        SELECT ssav.attr_id                        attr_id,
               ssav.attr_name                      attr_name,
               ssav.attr_value,
               group_concat(DISTINCT info.sku_id ) sku_ids
        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,
                 ssav.attr_value
    </select>


</mapper>
