<?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="xyz.zinglizingli.books.mapper.BookIndexMapper">
    <resultMap id="BaseResultMap" type="xyz.zinglizingli.books.po.BookIndex">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="book_id" property="bookId" jdbcType="BIGINT"/>
        <result column="index_num" property="indexNum" jdbcType="INTEGER"/>
        <result column="index_name" property="indexName" jdbcType="VARCHAR"/>
    </resultMap>
    <sql id="Example_Where_Clause">
        <where>
            <foreach collection="oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" suffix=")" prefixOverrides="and">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach collection="criterion.value" item="listItem" open="(" close=")"
                                             separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Update_By_Example_Where_Clause">
        <where>
            <foreach collection="example.oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" suffix=")" prefixOverrides="and">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach collection="criterion.value" item="listItem" open="(" close=")"
                                             separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Base_Column_List">
    id, book_id, index_num, index_name
  </sql>
    <select id="selectByExample" resultMap="BaseResultMap" parameterType="xyz.zinglizingli.books.po.BookIndexExample">
        select
        <if test="distinct">
            distinct
        </if>
        <include refid="Base_Column_List"/>
        from book_index
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
        <if test="orderByClause != null">
            order by ${orderByClause}
        </if>
    </select>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List"/>
        from book_index
        where id = #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from book_index
    where id = #{id,jdbcType=BIGINT}
  </delete>
    <delete id="deleteByExample" parameterType="xyz.zinglizingli.books.po.BookIndexExample">
        delete from book_index
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </delete>
    <insert id="insert" parameterType="xyz.zinglizingli.books.po.BookIndex">
    insert into book_index (id, book_id, index_num, 
      index_name)
    values (#{id,jdbcType=BIGINT}, #{bookId,jdbcType=BIGINT}, #{indexNum,jdbcType=INTEGER}, 
      #{indexName,jdbcType=VARCHAR})
  </insert>
    <insert id="insertSelective" parameterType="xyz.zinglizingli.books.po.BookIndex" useGeneratedKeys="true"
            keyProperty="id">
        insert into book_index
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="bookId != null">
                book_id,
            </if>
            <if test="indexNum != null">
                index_num,
            </if>
            <if test="indexName != null">
                index_name,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=BIGINT},
            </if>
            <if test="bookId != null">
                #{bookId,jdbcType=BIGINT},
            </if>
            <if test="indexNum != null">
                #{indexNum,jdbcType=INTEGER},
            </if>
            <if test="indexName != null">
                #{indexName,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
    <select id="countByExample" parameterType="xyz.zinglizingli.books.po.BookIndexExample"
            resultType="java.lang.Integer">
        select count(*) from book_index
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </select>
    <update id="updateByExampleSelective" parameterType="map">
        update book_index
        <set>
            <if test="record.id != null">
                id = #{record.id,jdbcType=BIGINT},
            </if>
            <if test="record.bookId != null">
                book_id = #{record.bookId,jdbcType=BIGINT},
            </if>
            <if test="record.indexNum != null">
                index_num = #{record.indexNum,jdbcType=INTEGER},
            </if>
            <if test="record.indexName != null">
                index_name = #{record.indexName,jdbcType=VARCHAR},
            </if>
        </set>
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByExample" parameterType="map">
        update book_index
        set id = #{record.id,jdbcType=BIGINT},
        book_id = #{record.bookId,jdbcType=BIGINT},
        index_num = #{record.indexNum,jdbcType=INTEGER},
        index_name = #{record.indexName,jdbcType=VARCHAR}
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="xyz.zinglizingli.books.po.BookIndex">
        update book_index
        <set>
            <if test="bookId != null">
                book_id = #{bookId,jdbcType=BIGINT},
            </if>
            <if test="indexNum != null">
                index_num = #{indexNum,jdbcType=INTEGER},
            </if>
            <if test="indexName != null">
                index_name = #{indexName,jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKey" parameterType="xyz.zinglizingli.books.po.BookIndex">
    update book_index
    set book_id = #{bookId,jdbcType=BIGINT},
      index_num = #{indexNum,jdbcType=INTEGER},
      index_name = #{indexName,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>


    <insert id="insertBatch" parameterType="java.util.List">
        insert into book_index (book_id, index_num, index_name)
        values
        <foreach collection="list" item="item" index="index"
                 separator=",">
            <trim prefix="(" suffix=")" suffixOverrides=",">
                #{item.bookId,jdbcType=VARCHAR},
                #{item.indexNum,jdbcType=VARCHAR},
                #{item.indexName,jdbcType=VARCHAR},
            </trim>
        </foreach>
    </insert>


    <select id="queryNewstIndexName" parameterType="long" resultType="string">

        select index_name from book_index where book_id = #{bookId,jdbcType=BIGINT} order by index_num desc limit 1
    </select>
</mapper>