<?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.java2nb.novel.dao.BookContentDao">

    <select id="get" resultType="com.java2nb.novel.domain.BookContentDO">
        select `id`, `index_id`, `content`
        from book_content
        where id = #{value}
    </select>

    <select id="list" resultType="com.java2nb.novel.domain.BookContentDO">
        select `id`,`index_id`,`content` from book_content
        <where>
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="indexId != null and indexId != ''">and index_id = #{indexId}</if>
            <if test="content != null and content != ''">and content = #{content}</if>
        </where>
        <choose>
            <when test="sort != null and sort.trim() != ''">
                order by ${sort} ${order}
            </when>
            <otherwise>
                order by id desc
            </otherwise>
        </choose>
        <if test="offset != null and limit != null">
            limit #{offset}, #{limit}
        </if>
    </select>

    <select id="count" resultType="int">
        select count(*) from book_content
        <where>
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="indexId != null and indexId != ''">and index_id = #{indexId}</if>
            <if test="content != null and content != ''">and content = #{content}</if>
        </where>
    </select>

    <insert id="save" parameterType="com.java2nb.novel.domain.BookContentDO">
        insert into book_content
        (`id`,
         `index_id`,
         `content`)
        values (#{id},
                #{indexId},
                #{content})
    </insert>

    <insert id="saveSelective" parameterType="com.java2nb.novel.domain.BookContentDO">
        insert into book_content
        (
        <if test="id != null">`id`,</if>
        <if test="indexId != null">`index_id`,</if>
        <if test="content != null">`content`</if>
        )
        values
        (
        <if test="id != null">#{id},</if>
        <if test="indexId != null">#{indexId},</if>
        <if test="content != null">#{content}</if>
        )
    </insert>

    <update id="update" parameterType="com.java2nb.novel.domain.BookContentDO">
        update book_content
        <set>
            <if test="indexId != null">`index_id` = #{indexId},</if>
            <if test="content != null">`content` = #{content}</if>
        </set>
        where id = #{id}
    </update>

    <delete id="remove">
        delete
        from book_content
        where id = #{value}
    </delete>

    <delete id="batchRemove">
        delete from book_content where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="removeByIndexIds">
        delete from book_content where index_id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>