<?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.keywords.dao.impl.SelfRobotKeywordReplyDaoImpl">
    <resultMap id="BaseResultMap" type="com.pcloud.book.keywords.entity.SelfRobotKeywordReply">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="keyword_id" property="keywordId" jdbcType="BIGINT"/>
        <result column="type" property="type" jdbcType="INTEGER"/>
        <result column="content" property="content" jdbcType="VARCHAR"/>
        <result column="description" property="description" jdbcType="VARCHAR"/>
        <result column="link_url" property="linkUrl" jdbcType="VARCHAR"/>
        <result column="pic_url" property="picUrl" jdbcType="VARCHAR"/>
        <result column="serve_id" property="serveId" jdbcType="BIGINT"/>
        <result column="serve_type" property="serveType" jdbcType="VARCHAR"/>
        <result column="resource_id" property="resourceId" jdbcType="BIGINT"/>
        <result column="seq_num" property="seqNum" jdbcType="INTEGER"/>
        <result column="create_user" property="createUser" jdbcType="BIGINT"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, keyword_id, type, content, description, link_url, pic_url, serve_id,
        serve_type, resource_id, seq_num, create_user, create_time
    </sql>

    <insert id="insert" parameterType="com.pcloud.book.keywords.entity.SelfRobotKeywordReply" useGeneratedKeys="true"
            keyProperty="id">
        insert into self_robot_keyword_reply
        <trim prefix="(" suffix=")" suffixOverrides=",">
            keyword_id,
            type,
            content,
            description,
            link_url,
            pic_url,
            serve_id,
            serve_type,
            resource_id,
            seq_num,
            create_user,
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{keywordId,jdbcType=BIGINT},
            #{type,jdbcType=INTEGER},
            #{content,jdbcType=VARCHAR},
            #{description,jdbcType=VARCHAR},
            #{linkUrl,jdbcType=VARCHAR},
            #{picUrl,jdbcType=VARCHAR},
            #{serveId,jdbcType=BIGINT},
            #{serveType,jdbcType=VARCHAR},
            #{resourceId,jdbcType=BIGINT},
            #{seqNum,jdbcType=INTEGER},
            #{createUser,jdbcType=BIGINT},
            NOW()
        </trim>
    </insert>

    <!--批量插入-->
    <insert id="batchInsert"  parameterType="com.pcloud.book.keywords.entity.SelfRobotKeywordReply" useGeneratedKeys="true" keyProperty="id">
        insert into self_robot_keyword_reply (
        keyword_id,
        type,
        content,
        description,
        link_url,
        pic_url,
        serve_id,
        serve_type,
        resource_id,
        seq_num,
        create_user,
        create_time
        ) values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.keywordId,jdbcType=BIGINT},
            #{item.type,jdbcType=INTEGER},
            #{item.content,jdbcType=VARCHAR},
            #{item.description,jdbcType=VARCHAR},
            #{item.linkUrl,jdbcType=VARCHAR},
            #{item.picUrl,jdbcType=VARCHAR},
            #{item.serveId,jdbcType=BIGINT},
            #{item.serveType,jdbcType=VARCHAR},
            #{item.resourceId,jdbcType=BIGINT},
            #{item.seqNum,jdbcType=INTEGER},
            #{item.createUser,jdbcType=BIGINT},
            NOW()
            )
        </foreach>
    </insert>

    <delete id="deleteByKeywordId" parameterType="map">
        delete from self_robot_keyword_reply
        where keyword_id = #{keywordId}
    </delete>

    <select id="getListByKeywordId" parameterType="long" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from self_robot_keyword_reply
        where keyword_id = #{keywordId}
        order by seq_num, id
    </select>

</mapper>