<?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.dao.impl.BuyBookRequestReplyDaoImpl">

    <resultMap id="BaseResultMap" type="com.pcloud.book.applet.entity.BuyBookRequestReply">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="request_id" property="requestId" jdbcType="BIGINT"/>
        <result column="reply_message" property="replyMessage" jdbcType="VARCHAR"/>
        <result column="channel_id" property="channelId" jdbcType="BIGINT"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <resultMap id="BaseResultMap4DTO" type="com.pcloud.book.applet.dto.BuyBookRequestReplyDTO">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="request_id" property="requestId" jdbcType="BIGINT"/>
        <result column="reply_message" property="replyMessage" jdbcType="VARCHAR"/>
        <result column="channel_id" property="channelId" jdbcType="BIGINT"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id = "Base_Column_List">
        id, request_id, reply_message, channel_id, create_time, update_time
    </sql>

    <insert id="insert" keyProperty="id" useGeneratedKeys="true" >
        INSERT INTO buy_book_request_reply(
             request_id,
             reply_message,
             channel_id,
             create_time,
             update_time
        ) VALUES (
             #{requestId, jdbcType=BIGINT},
             #{replyMessage, jdbcType=VARCHAR},
             #{channelId, jdbcType=BIGINT},
             now(),
             now()
        )
    </insert>

    <select id="getByRequestId" resultMap="BaseResultMap4DTO" parameterType="long">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        buy_book_request_reply
        where
        request_id = #{requestId, jdbcType=BIGINT}
    </select>

    <delete id="deleteById" parameterType="long">
        Delete
        FROM
        buy_book_request_reply
        where
        id=#{id, jdbcType=BIGINT}
    </delete>

    <!-- 批量获取回复信息 -->
    <select id="listBaseMapByIds" resultMap="BaseResultMap4DTO" parameterType="list">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        buy_book_request_reply
        WHERE
        request_id IN
        <foreach collection="list" index="i" item="item" open="(" separator="," close=")">
            ${item}
        </foreach>
    </select>
</mapper>