<?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.pcloud.book.book.dao.impl.BookLabelTrimDaoImpl">

    <resultMap type="com.pcloud.book.book.entity.BookLabelTrim" id="BookLabelTrimMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="type" column="type" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <!--查询单个-->
    <select id="getById" resultMap="BookLabelTrimMap">
        select
          id, name, type, create_time
        from book.book_label_trim
        where id = #{id}
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into book.book_label_trim(name, type, create_time)
        values (#{name}, #{type}, now())
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update book.book_label_trim
        <set>
            <if test="name != null and name != ''">
                name = #{name},
            </if>
            <if test="type != null">
                type = #{type},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from book.book_label_trim where id = #{id}
    </delete>

    <select id="getBookLabelTrimList" parameterType="map" resultMap="BookLabelTrimMap">
        SELECT
            id, `name`, type, create_time
        FROM
        book.book_label_trim
        WHERE 1=1
            <if test="type != null">
              AND type = #{type}
            </if>
    </select>

</mapper>