<?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.SelfRobotGuideDaoImpl">
    <resultMap id="BaseResultMap" type="com.pcloud.book.keywords.entity.SelfRobotGuide">
        <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="pic_url" property="picUrl" jdbcType="VARCHAR"/>
        <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, pic_url, seq_num, create_user, create_time
    </sql>

    <insert id="insert" parameterType="com.pcloud.book.keywords.entity.SelfRobotGuide" useGeneratedKeys="true"
            keyProperty="id">
        insert into self_robot_guide
        <trim prefix="(" suffix=")" suffixOverrides=",">
            keyword_id,
            type,
            content,
            pic_url,
            seq_num,
            create_user,
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{keywordId,jdbcType=BIGINT},
            #{type,jdbcType=INTEGER},
            #{content,jdbcType=VARCHAR},
            #{picUrl,jdbcType=VARCHAR},
            #{seqNum,jdbcType=INTEGER},
            #{createUser,jdbcType=BIGINT},
            NOW()
        </trim>
    </insert>

    <!--批量插入-->
    <insert id="batchInsert"  parameterType="com.pcloud.book.keywords.entity.SelfRobotGuide" useGeneratedKeys="true" keyProperty="id">
        insert into self_robot_guide (
        keyword_id,
        type,
        content,
        pic_url,
        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.picUrl,jdbcType=VARCHAR},
            #{item.seqNum,jdbcType=INTEGER},
            #{item.createUser,jdbcType=BIGINT},
            NOW()
            )
        </foreach>
    </insert>

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

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

</mapper>