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

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap id="cueTypeVOMap" type="com.tmerclub.cloud.cuerecycle.model.vo.CueTypeVO">
        <result property="typeId" column="type_id"/>
        <result property="typeName" column="type_name"/>
        <result property="typeImage" column="type_image"/>
        <result property="typeSeq" column="type_seq"/>
        <result property="typeStatus" column="type_status"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="Vo_Column_List">
        type_id,type_name,type_image,type_seq,type_status,deleted,create_time,update_time
    </sql>

    <select id="list" resultMap="cueTypeVOMap">
        SELECT
            <include refid="Vo_Column_List" />
        FROM cue_type
        <where>
            deleted = 0
            <if test="dto.typeStatus != null">
                AND type_status = #{dto.typeStatus}
            </if>
            <if test="dto.typeName != null and dto.typeName != ''">
                AND type_name like CONCAT('%', #{dto.typeName}, '%')
            </if>
        </where>
        ORDER BY
            type_seq asc,
            type_id desc
    </select>

    <select id="getById" resultMap="cueTypeVOMap">
        SELECT
            <include refid="Vo_Column_List" />
        FROM
            cue_type
        WHERE
            type_id = #{typeId}
    </select>

    <insert id="save" useGeneratedKeys="true" keyProperty="typeId">
        INSERT INTO cue_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="typeName != null and typeName != ''">type_name,</if>
            <if test="typeImage != null and typeImage != ''">type_image,</if>
            <if test="typeSeq != null">type_seq,</if>
            <if test="typeStatus != null">type_status,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="typeName != null and typeName != ''">#{typeName},</if>
            <if test="typeImage != null and typeImage != ''">#{typeImage},</if>
            <if test="typeSeq != null">#{typeSeq},</if>
            <if test="typeStatus != null">#{typeStatus},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>

    <update id="update">
        UPDATE cue_type
        <set>
            <if test="typeName != null and typeName != ''">
                type_name = #{typeName},
            </if>
            <if test="typeImage != null and typeImage != ''">
                type_image = #{typeImage},
            </if>
            <if test="typeSeq != null">
                type_seq = #{typeSeq},
            </if>
            <if test="typeStatus != null">
                type_status = #{typeStatus},
            </if>
            <if test="deleted != null">
                deleted = #{deleted},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
        </set>
        where type_id = #{typeId}
    </update>
</mapper>