<?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="cn.iocoder.mall.product.dao.ProductAttrMapper">

    <sql id="FIELDS">
        id, name, status, create_time
    </sql>

    <!--<select id="selectList" resultType="ProductCategoryDO">-->
        <!--SELECT-->
        <!--<include refid="FIELDS" />-->
        <!--FROM product_category-->
        <!--WHERE deleted = 0-->
    <!--</select>-->

    <select id="selectById" parameterType="Integer" resultType="ProductAttrDO">
        SELECT
            <include refid="FIELDS" />
        FROM product_attr
        WHERE id = #{id}
        AND deleted = 0
    </select>

    <select id="selectByName" parameterType="String" resultType="ProductAttrDO">
        SELECT
            <include refid="FIELDS" />
        FROM product_attr
        WHERE name = #{name}
        AND deleted = 0
        LIMIT 1
    </select>

    <insert id="insert" parameterType="ProductAttrDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
        INSERT INTO product_attr (
          name, status, create_time, deleted
        ) VALUES (
          #{name}, #{status}, #{createTime}, #{deleted}
        )
    </insert>

    <update id="update" parameterType="ProductAttrDO">
        UPDATE product_attr
        <set>
            <if test="name != null">
                name = #{name},
            </if>
            <if test="status != null">
                status = #{status},
            </if>
            <if test="deleted != null">
                deleted = #{deleted}
            </if>
        </set>
        WHERE id = #{id}
    </update>

    <select id="selectListByIds" resultType="ProductAttrDO">
        SELECT
            <include refid="FIELDS" />
        FROM product_attr
        WHERE id IN
            <foreach item="id" collection="ids" separator="," open="(" close=")" index="">
                #{id}
            </foreach>
        AND deleted = 0
    </select>

    <select id="selectListByNameLike" resultType="ProductAttrDO">
        SELECT
            <include refid="FIELDS" />
        FROM product_attr
        <where>
            <if test="name != null">
                name LIKE "%"#{name}"%"
            </if>
            AND deleted = 0
        </where>
        LIMIT #{offset}, #{limit}
    </select>

    <select id="selectCountByNameLike" resultType="Integer">
        SELECT
            COUNT(1)
        FROM product_attr
        <where>
            <if test="name != null">
                name LIKE "%"#{name}"%"
            </if>
            AND deleted = 0
        </where>
    </select>

    <select id="selectListByStatus" parameterType="Integer" resultType="ProductAttrDO">
        SELECT
            <include refid="FIELDS" />
        FROM product_attr
        <where>
            <if test="status != null">
                status = #{status}
            </if>
            AND deleted = 0
        </where>
    </select>

</mapper>