<?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.tmerclub.cloud.cuerecycle.mapper.CueBrandMapper">

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap id="cueBrandVOMap" type="com.tmerclub.cloud.cuerecycle.model.vo.CueBrandVO">
        <result property="brandId" column="brand_id"/>
        <result property="brandName" column="brand_name"/>
        <result property="brandLogo" column="brand_logo"/>
        <result property="brandSeq" column="brand_seq"/>
        <result property="brandStatus" column="brand_status"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="Vo_Column_List">
        brand_id,brand_name,brand_logo,brand_seq,brand_status,deleted,create_time,update_time
    </sql>

    <select id="list" resultMap="cueBrandVOMap">
        SELECT
            <include refid="Vo_Column_List" />
        FROM cue_brand
        <where>
            deleted = 0
            <if test="dto.brandName != null and dto.brandName != ''">
                AND brand_name LIKE CONCAT('%', #{dto.brandName}, '%')
            </if>
            <if test="dto.brandStatus != null">
                AND brand_status = #{dto.brandStatus}
            </if>
        </where>
        ORDER BY
            brand_seq ASC,
            brand_id DESC
    </select>

    <select id="getById" resultMap="cueBrandVOMap">
        SELECT
        <include refid="Vo_Column_List" />
        FROM cue_brand
        WHERE brand_id = #{brandId}
    </select>

    <insert id="save" useGeneratedKeys="true" keyProperty="brandId">
        INSERT INTO cue_brand
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="brandName != null and brandName != ''">brand_name,</if>
            <if test="brandLogo != null and brandLogo != ''">brand_logo,</if>
            <if test="brandSeq != null">brand_seq,</if>
            <if test="brandStatus != null">brand_status,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="brandName != null and brandName != ''">#{brandName},</if>
            <if test="brandLogo != null and brandLogo != ''">#{brandLogo},</if>
            <if test="brandSeq != null">#{brandSeq},</if>
            <if test="brandStatus != null">#{brandStatus},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>

    <update id="update">
        UPDATE cue_brand
        <set>
            <if test="brandName != null and brandName != ''">
                brand_name = #{brandName},
            </if>
            <if test="brandLogo != null and brandLogo != ''">
                brand_logo = #{brandLogo},
            </if>
            <if test="brandSeq != null">
                brand_seq = #{brandSeq},
            </if>
            <if test="brandStatus != null">
                brand_status = #{brandStatus},
            </if>
            <if test="deleted != null">
                deleted = #{deleted},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
        </set>
        where brand_id = #{brandId}
    </update>
</mapper>