<?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.group.dao.impl.BookGroupFriendGuideDaoImpl">
    <resultMap id="BaseResultMap" type="com.pcloud.book.group.entity.BookGroupFriendGuide">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="book_group_id" property="bookGroupId" 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, book_group_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.group.entity.BookGroupFriendGuide" useGeneratedKeys="true"
            keyProperty="id">
        insert into book_group_friend_guide
        <trim prefix="(" suffix=")" suffixOverrides=",">
            book_group_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=",">
            #{bookGroupId,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.group.entity.BookGroupFriendGuide" useGeneratedKeys="true" keyProperty="id">
        insert into book_group_friend_guide (
        book_group_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.bookGroupId,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="deleteById" parameterType="long">
        delete from book_group_friend_guide
        where id=#{id}
    </delete>

    <!--根据社群码id集合删除-->
    <delete id="deleteByBookGroupId" parameterType="long">
        delete from book_group_friend_guide
        where book_group_id = #{bookGroupId}
    </delete>

    <!--根据社群书id获取-->
    <select id="getListByBookGroupId" parameterType="long" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from book_group_friend_guide
        where book_group_id = #{bookGroupId}
        order by seq_num
    </select>


</mapper>