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

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap id="cueSeriesVOMap" type="com.tmerclub.cloud.cuerecycle.model.vo.CueSeriesVO">
        <result property="seriesId" column="series_id"/>
        <result property="brandId" column="brand_id"/>
        <result property="seriesName" column="series_name"/>
        <result property="seriesSeq" column="series_seq"/>
        <result property="seriesStatus" column="series_status"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="Vo_Column_List">
        series_id,brand_id,series_name,series_seq,series_status,deleted,create_time,update_time
    </sql>

    <select id="list" resultMap="cueSeriesVOMap">
        SELECT
        <include refid="Vo_Column_List" />
        FROM cue_series
        <where>
            deleted = 0
            <if test="dto.seriesName != null and dto.seriesName != ''">
                AND series_name LIKE CONCAT('%', #{dto.seriesName}, '%')
            </if>
            <if test="dto.seriesStatus != null">
                AND series_status = #{dto.seriesStatus}
            </if>
            <if test="dto.brandId != null">
                AND brand_id = #{dto.brandId}
            </if>
        </where>
        ORDER BY
            series_seq ASC,
            series_id DESC
    </select>

    <select id="getById" resultMap="cueSeriesVOMap">
        SELECT
            <include refid="Vo_Column_List" />
        FROM
            cue_series
        WHERE
            series_id = #{seriesId}
    </select>

    <insert id="save" useGeneratedKeys="true" keyProperty="seriesId">
        INSERT INTO cue_series
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="brandId != null">brand_id,</if>
            <if test="seriesName != null and seriesName != ''">series_name,</if>
            <if test="seriesSeq != null">series_seq,</if>
            <if test="seriesStatus != null">series_status,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="brandId != null">#{brandId},</if>
            <if test="seriesName != null and seriesName != ''">#{seriesName},</if>
            <if test="seriesSeq != null">#{seriesSeq},</if>
            <if test="seriesStatus != null">#{seriesStatus},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>

    <update id="update">
        UPDATE cue_series
        <set>
            <if test="brandId != null">
                brand_id = #{brandId},
            </if>
            <if test="seriesName != null and seriesName != ''">
                series_name = #{seriesName},
            </if>
            <if test="seriesSeq != null">
                series_seq = #{seriesSeq},
            </if>
            <if test="seriesStatus != null">
                series_status = #{seriesStatus},
            </if>
            <if test="deleted != null">
                deleted = #{deleted},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
        </set>
        where series_id = #{seriesId}
    </update>
</mapper>