<?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.recommend.dao.impl.BookRecommendDaoImpl">

    <resultMap id="BaseResultMap" type="com.pcloud.book.recommend.entity.BookRecommend">
        <result column="book_id" property="bookId" jdbcType="BIGINT"/>
        <result column="adviser_id" property="adviserId" jdbcType="BIGINT"/>
        <result column="channel_id" property="channelId" jdbcType="INTEGER"/>
        <result column="resource_limit_type" property="resourceLimitType" jdbcType="INTEGER"/>
        <result column="recommend_list" property="recommendList" jdbcType="VARCHAR"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>
    
    <sql id="Base_Column_List">
        book_id, adviser_id, channel_id, resource_limit_type, recommend_list, update_time        
    </sql>

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

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

    <select id="getBookRecommend" parameterType="map" resultType="String">
        select recommend_list
        from book_recommend
        where book_id=#{bookId}
        and adviser_id=#{adviserId}
        and channel_id=#{channelId}
        and resource_limit_type=#{fromType}
        limit 1
    </select>

</mapper>