<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="com.pcloud.book.personalstage.dao.impl.PersonalStageReplyItemDaoImpl">

    <resultMap  id="BaseResultMap" type="com.pcloud.book.personalstage.entity.PersonalStageReplyItem">
        <id property="id" column="id" jdbcType="BIGINT"/>
        <result property="personalStageReplyId" column="personal_stage_reply_id" jdbcType="BIGINT"/>
        <result property="replyType" column="reply_type" jdbcType="INTEGER"/>
        <result property="content" column="content" jdbcType="VARCHAR"/>
        <result property="picUrl" column="pic_url" jdbcType="VARCHAR"/>
        <result property="resourceId" column="resource_id" jdbcType="BIGINT"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result column="personal_applets_id" property="personalAppletsId" jdbcType="BIGINT"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, personal_stage_reply_id, reply_type, content, pic_url, resource_id, create_time,personal_applets_id
    </sql>

    <select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List"/>
        from personal_stage_reply_item
        where id = #{id,jdbcType=BIGINT}
    </select>

    <delete id="deleteById" parameterType="long">
        delete from personal_stage_reply_item
        where id = #{id,jdbcType=BIGINT}
    </delete>

    <insert id="insert" parameterType="com.pcloud.book.personalstage.entity.PersonalStageReplyItem" useGeneratedKeys="true" keyProperty="id">
        insert into personal_stage_reply_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            personal_stage_reply_id,
            reply_type,
            content,
            pic_url,
            resource_id,
            create_time,
            personal_applets_id
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{personalStageReplyId,jdbcType=BIGINT},
            #{replyType,jdbcType=INTEGER},
            #{content,jdbcType=VARCHAR},
            #{picUrl,jdbcType=VARCHAR},
            #{resourceId,jdbcType=BIGINT},
            NOW(),
            #{personalAppletsId,jdbcType=BIGINT}
        </trim>
    </insert>

    <insert id="batchInsert"  parameterType="com.pcloud.book.personalstage.entity.PersonalStageReplyItem" useGeneratedKeys="true" keyProperty="id">
        insert into personal_stage_reply_item (
        personal_stage_reply_id,
        reply_type,
        content,
        pic_url,
        resource_id,
        create_time,
        personal_applets_id
        ) values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.personalStageReplyId,jdbcType=BIGINT},
            #{item.replyType,jdbcType=INTEGER},
            #{item.content,jdbcType=VARCHAR},
            #{item.picUrl,jdbcType=VARCHAR},
            #{item.resourceId,jdbcType=BIGINT},
            NOW(),
            #{item.personalAppletsId,jdbcType=BIGINT}
            )
        </foreach>
    </insert>

    <delete id="deleteByReplyIds" parameterType="long">
        delete from personal_stage_reply_item
        where personal_stage_reply_id in
        <foreach collection="list" item="item" open="(" separator="," close=")">
            ${item}
        </foreach>
    </delete>

    <select id="getListByReplyIds" parameterType="long" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/> from personal_stage_reply_item
        where personal_stage_reply_id in
        <foreach collection="list" item="item" open="(" separator="," close=")">
            ${item}
        </foreach>
    </select>
</mapper>