<?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.applet.mapper.AppletBookScoreSubTagMapper">

    <resultMap type="com.pcloud.book.applet.entity.AppletBookScoreSubTag" id="AppletBookScoreSubTagMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="tagId" column="tag_id" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="AppletBookScoreSubTagMap">
        select id,
               name,
               tag_id,
               create_time,
               update_time
        from book.applet_book_score_sub_tag
        where id = #{id}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="AppletBookScoreSubTagMap">
        select id,
               name,
               tag_id,
               create_time,
               update_time
        from book.applet_book_score_sub_tag limit #{offset}, #{limit}
    </select>

    <!--通过实体作为筛选条件查询-->
    <select id="queryAll" resultMap="AppletBookScoreSubTagMap">
        select
        id, name, tag_id, create_time, update_time
        from book.applet_book_score_sub_tag
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="name != null and name != ''">
                and name = #{name}
            </if>
            <if test="tagId != null">
                and tag_id = #{tagId}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into book.applet_book_score_sub_tag(name, tag_id, create_time, update_time)
        values (#{name}, #{tagId}, #{createTime}, #{updateTime})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into book.applet_book_score_sub_tag(name, tag_id, create_time, update_time)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}, #{entity.tagId}, #{entity.createTime}, #{entity.updateTime})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into book.applet_book_score_sub_tag(name, tag_id, create_time, update_time)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}, #{entity.tagId}, #{entity.createTime}, #{entity.updateTime})
        </foreach>
        on duplicate key update
        name = values(name) , tag_id = values(tag_id) , create_time = values(create_time) , update_time =
        values(update_time)
    </insert>

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

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

</mapper>

