<?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.ruoyi.framework.recovery.mapper.RecBrandMapper">

    <resultMap type="RecBrand" id="RecBrandResult">
        <result property="id"    column="id"    />
        <result property="brand"    column="brand"    />
        <result property="parentId"    column="parent_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createDate"    column="create_date"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateDate"    column="update_date"    />
    </resultMap>

    <sql id="selectRecBrandVo">
        select id, brand, parent_id, create_by, create_date, update_by, update_date from rec_brand
    </sql>

    <select id="selectRecBrandList" parameterType="RecBrand" resultMap="RecBrandResult">
        <include refid="selectRecBrandVo"/>
        <where>
            <if test="brand != null  and brand != ''"> and brand = #{brand}</if>
            <if test="parentId != null"> and parent_id = #{parentId}</if>
            <if test="createDate != null "> and create_date = #{createDate}</if>
            <if test="updateDate != null "> and update_date = #{updateDate}</if>
        </where>
        order by parent_id, id
    </select>

    <select id="selectRecBrandById" parameterType="Long" resultMap="RecBrandResult">
        <include refid="selectRecBrandVo"/>
        where id = #{id}
    </select>

    <insert id="insertRecBrand" parameterType="RecBrand" useGeneratedKeys="true" keyProperty="id">
        insert into rec_brand
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="brand != null">brand,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createDate != null">create_date,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateDate != null">update_date,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="brand != null">#{brand},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createDate != null">#{createDate},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateDate != null">#{updateDate},</if>
         </trim>
    </insert>

    <update id="updateRecBrand" parameterType="RecBrand">
        update rec_brand
        <trim prefix="SET" suffixOverrides=",">
            <if test="brand != null">brand = #{brand},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createDate != null">create_date = #{createDate},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateDate != null">update_date = #{updateDate},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRecBrandById" parameterType="Long">
        delete from rec_brand where id = #{id}
    </delete>

    <delete id="deleteRecBrandByIds" parameterType="String">
        delete from rec_brand where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
