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

    <resultMap id="BaseResultMap" type="com.pcloud.book.group.entity.ResourcePageBookstore">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="resource_page_id" property="resourcePageId" jdbcType="BIGINT"/>
        <result column="serve_id" property="serveId" jdbcType="BIGINT"/>
        <result column="serve_type" property="serveType" jdbcType="VARCHAR"/>
        <result column="link_url" property="linkUrl" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <resultMap id="BaseDtoResultMap" extends="BaseResultMap" type="com.pcloud.book.group.vo.ResourcePageBookstoreVO">
    </resultMap>
    
    <sql id="Base_Column_List">
        id, resource_page_id, serve_id, serve_type, link_url, create_time
    </sql>

    <select id="getById" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM resource_page_bookstore
        WHERE id = #{id}
    </select>

    <select id="getByResourcePageId" resultMap="BaseDtoResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM resource_page_bookstore
        WHERE resource_page_id = #{resourcePageId}
    </select>

    <select id="getList" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM resource_page_bookstore
    </select>

    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        INSERT INTO resource_page_bookstore(
            resource_page_id,
            serve_id,
            serve_type,
            link_url,
            create_time
        ) VALUES (
            #{resourcePageId, jdbcType=BIGINT},
            #{serveId, jdbcType=BIGINT},
            #{serveType, jdbcType=VARCHAR},
            #{linkUrl, jdbcType=VARCHAR},
            NOW()
        )
    </insert>
    
    <insert id="batchInsert" keyProperty="id" useGeneratedKeys="true">
        INSERT INTO resource_page_bookstore (
            resource_page_id,
            serve_id,
            serve_type,
            link_url,
            create_time
        ) VALUES 
        <foreach collection="list" item="item" separator=",">
        (
            #{item.resourcePageId, jdbcType=BIGINT},
            #{item.serveId, jdbcType=BIGINT},
            #{item.serveType, jdbcType=VARCHAR},
            #{item.linkUrl, jdbcType=VARCHAR},
            NOW()
        )
        </foreach>
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        UPDATE resource_page_bookstore
        <set>
            <if test="resourcePageId != null">
                resource_page_id = #{resourcePageId},
            </if>
            <if test="serveId != null">
                serve_id = #{serveId},
            </if>
            <if test="serveType != null and serveType != ''">
                serve_type = #{serveType},
            </if>
            <if test="linkUrl != null and linkUrl != ''">
                link_url = #{linkUrl},
            </if>
        </set>
        WHERE id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        DELETE FROM resource_page_bookstore WHERE id = #{id}
    </delete>

    <!--通过主键删除-->
    <delete id="deleteByResourcePageId">
        DELETE FROM resource_page_bookstore WHERE resource_page_id = #{resourcePageId}
    </delete>

</mapper>
