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

    <resultMap type="com.pcloud.book.applet.entity.AppletBookFeedback" id="AppletBookFeedbackMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="content" column="content" jdbcType="VARCHAR"/>
        <result property="pic1" column="pic1" jdbcType="VARCHAR"/>
        <result property="pic2" column="pic2" jdbcType="VARCHAR"/>
        <result property="pic3" column="pic3" jdbcType="VARCHAR"/>
        <result property="pic4" column="pic4" jdbcType="VARCHAR"/>
        <result property="wechatUserId" column="wechat_user_id" jdbcType="INTEGER"/>
        <result property="bookId" column="book_id" jdbcType="INTEGER"/>
        <result property="channelId" column="channel_id" jdbcType="INTEGER"/>
        <result property="adviserId" column="adviser_id" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="AppletBookFeedbackMap">
        select id,
               content,
               pic1,
               pic2,
               pic3,
               pic4,
               wechat_user_id,
               book_id,
               channel_id,
               adviser_id,
               create_time
        from book.applet_book_feedback
        where id = #{id}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="AppletBookFeedbackMap">
        select id,
               content,
               pic1,
               pic2,
               pic3,
               pic4,
               wechat_user_id,
               book_id,
               channel_id,
               adviser_id,
               create_time
        from book.applet_book_feedback limit #{offset}, #{limit}
    </select>

    <!--通过实体作为筛选条件查询-->
    <select id="queryAll" resultMap="AppletBookFeedbackMap">
        select
        id, content, pic1, pic2, pic3, pic4, wechat_user_id, book_id, channel_id, adviser_id, create_time
        from book.applet_book_feedback
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="content != null and content != ''">
                and content = #{content}
            </if>
            <if test="pic1 != null and pic1 != ''">
                and pic1 = #{pic1}
            </if>
            <if test="pic2 != null and pic2 != ''">
                and pic2 = #{pic2}
            </if>
            <if test="pic3 != null and pic3 != ''">
                and pic3 = #{pic3}
            </if>
            <if test="pic4 != null and pic4 != ''">
                and pic4 = #{pic4}
            </if>
            <if test="wechatUserId != null">
                and wechat_user_id = #{wechatUserId}
            </if>
            <if test="bookId != null">
                and book_id = #{bookId}
            </if>
            <if test="channelId != null">
                and channel_id = #{channelId}
            </if>
            <if test="adviserId != null">
                and adviser_id = #{adviserId}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into book.applet_book_feedback(content, pic1, pic2, pic3, pic4, wechat_user_id, book_id, channel_id,
                                              adviser_id, create_time)
        values (#{content}, #{pic1}, #{pic2}, #{pic3}, #{pic4}, #{wechatUserId}, #{bookId}, #{channelId}, #{adviserId},
                #{createTime})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into book.applet_book_feedback(content, pic1, pic2, pic3, pic4, wechat_user_id, book_id, channel_id,
        adviser_id, create_time)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.content}, #{entity.pic1}, #{entity.pic2}, #{entity.pic3}, #{entity.pic4}, #{entity.wechatUserId},
            #{entity.bookId}, #{entity.channelId}, #{entity.adviserId}, #{entity.createTime})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into book.applet_book_feedback(content, pic1, pic2, pic3, pic4, wechat_user_id, book_id, channel_id,
        adviser_id, create_time)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.content}, #{entity.pic1}, #{entity.pic2}, #{entity.pic3}, #{entity.pic4}, #{entity.wechatUserId},
            #{entity.bookId}, #{entity.channelId}, #{entity.adviserId}, #{entity.createTime})
        </foreach>
        on duplicate key update
        content = values(content) , pic1 = values(pic1) , pic2 = values(pic2) , pic3 = values(pic3) , pic4 =
        values(pic4) , wechat_user_id = values(wechat_user_id) , book_id = values(book_id) , channel_id =
        values(channel_id) , adviser_id = values(adviser_id) , create_time = values(create_time)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update book.applet_book_feedback
        <set>
            <if test="content != null and content != ''">
                content = #{content},
            </if>
            <if test="pic1 != null and pic1 != ''">
                pic1 = #{pic1},
            </if>
            <if test="pic2 != null and pic2 != ''">
                pic2 = #{pic2},
            </if>
            <if test="pic3 != null and pic3 != ''">
                pic3 = #{pic3},
            </if>
            <if test="pic4 != null and pic4 != ''">
                pic4 = #{pic4},
            </if>
            <if test="wechatUserId != null">
                wechat_user_id = #{wechatUserId},
            </if>
            <if test="bookId != null">
                book_id = #{bookId},
            </if>
            <if test="channelId != null">
                channel_id = #{channelId},
            </if>
            <if test="adviserId != null">
                adviser_id = #{adviserId},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
        </set>
        where id = #{id}
    </update>

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

</mapper>

