<?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.ProductBrandMapper">

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

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

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


    <insert id="insert" parameterType="ProductBrandDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
        INSERT INTO product_brand (
          name, description, pic_url, status, create_time, deleted
        ) VALUES (
          #{name}, #{description}, #{picUrl}, #{status}, #{createTime}, #{deleted}
        )
    </insert>

    <update id="update" parameterType="ProductBrandDO">
        UPDATE product_brand
        <set>
            <if test="name != null">
                name = #{name},
            </if>
            <if test="description != null">
                description = #{description},
            </if>
            <if test="picUrl != null">
                pic_url = #{picUrl},
            </if>
            <if test="status != null">
                status = #{status},
            </if>
            <if test="deleted != null">
                deleted = #{deleted}
            </if>
        </set>
        WHERE id = #{id}
    </update>



    <select id="selectListByParams" resultType="ProductBrandDO">
        SELECT
            <include refid="FIELDS" />
        FROM product_brand
        <where>
            deleted = 0
            <if test="name != null">
                AND name LIKE "%"#{name}"%"
            </if>
            <if test="description != null">
                AND description LIKE "%"#{description}"%"
            </if>
            <if test="status != null">
                AND status = #{status}
            </if>
        </where>
        LIMIT #{offset}, #{limit}
    </select>

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

</mapper>