<?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.backendsys.mapper.B2c.B2cGoodSpecMapper">

    <sql id="includeGoodsSpec">
        id,
        id good_spec_id,
        spec_name,
        spec_value,
        sort
    </sql>

    <resultMap id="resultMapGoodsSpec" type="java.util.LinkedHashMap">
        <id property="id" column="id" jdbcType="BIGINT" />
        <result property="good_spec_id" column="good_spec_id" javaType="java.lang.Long"/>
        <result property="spec_name" column="spec_name" />
        <result property="spec_value" column="spec_value" />
        <result property="sort" column="sort" />
    </resultMap>

    <select id="queryGoodSpecList" resultMap="resultMapGoodsSpec">
        SELECT
        <include refid="includeGoodsSpec" />
        FROM b2c_goods_spec
        <where>
            <if test="spec_name != null and spec_name != ''">
                AND spec_name LIKE CONCAT('%', #{spec_name}, '%')
            </if>
        </where>
        ORDER BY sort DESC
    </select>

    <select id="queryGoodSpecByIds" resultMap="resultMapGoodsSpec">
        SELECT
            <include refid="includeGoodsSpec" />
        FROM b2c_goods_spec
        WHERE id IN
        <foreach collection="spec_ids" item="spec_id" open="(" separator="," close=")">
            #{spec_id}
        </foreach>
    </select>

    <select id="queryGoodSpecDetail" resultMap="resultMapGoodsSpec">
        SELECT
        <include refid="includeGoodsSpec" />
        FROM b2c_goods_spec
        WHERE id = #{good_spec_id}
    </select>

    <insert id="insertGoodSpec" parameterType="com.backendsys.entity.B2c.B2cGoodSpecDTO"
        useGeneratedKeys="true" keyProperty="good_spec_id">
        INSERT INTO b2c_goods_spec (spec_name, spec_value, sort)
        VALUES (#{spec_name}, #{spec_value}, #{sort})
    </insert>

    <update id="updateGoodSpec" parameterType="com.backendsys.entity.B2c.B2cGoodSpecDTO"
        useGeneratedKeys="true" keyProperty="good_spec_id">
        UPDATE b2c_goods_spec
        SET spec_name = #{spec_name}, spec_value = #{spec_value}, sort = #{sort}
        WHERE id = #{good_spec_id}
    </update>

    <delete id="deleteGoodSpec">
        DELETE FROM b2c_goods_spec WHERE id = #{good_spec_id}
    </delete>

</mapper>