<?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.seer.teach.mall.mapper.GoodsSpecificationMapper">

    <resultMap id="BaseResultMap" type="com.seer.teach.mall.entity.GoodsSpecificationEntity">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="goods_id" jdbcType="INTEGER" property="goodsId"/>
        <result column="attributes" jdbcType="VARCHAR" property="attributes" typeHandler="com.seer.teach.mall.handler.GoodsSpecAttributesTypeHandler"/>
        <result column="pic_url" jdbcType="VARCHAR" property="picUrl"/>
        <result column="spuName" jdbcType="VARCHAR" property="spuName"/>
        <result column="bar_code" jdbcType="VARCHAR" property="barCode"/>
        <result column="market_price" jdbcType="DECIMAL" property="marketPrice"/>
        <result column="price" jdbcType="DECIMAL" property="price"/>
        <result column="volume" jdbcType="VARCHAR" property="volume"/>
        <result column="weight" jdbcType="VARCHAR" property="weight"/>
        <result column="cost_price" jdbcType="DECIMAL" property="costPrice"/>
        <result column="stock" jdbcType="BIGINT" property="stock"/>
        <result column="spuName" jdbcType="BIGINT" property="spuName"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, goods_id, attributes, pic_url, bar_code, market_price, price, volume, weight, cost_price, stock
    </sql>

    <select id="getGoodsSpecificationPage" resultMap="BaseResultMap">
        SELECT  a.`id`,
                a.`goods_id`,
                a.attributes,
                a.`pic_url` ,
                a.bar_code,
                a.market_price,
                a.price,a.volume,
                a.weight,
                b.name as spuName
        FROM mall_goods_specification a inner join mall_goods b on a.goods_id = b.id
        WHERE a.deleted = 0
        <if test=" id != null">
            AND a.id = #{id}
        </if>
        <if test=" spuName != null and '' != spuName ">
            AND b.name like concat('%',#{spuName},'%')
        </if>
    </select>
</mapper>