<?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.BookGuideDaoImpl">

    <resultMap id="BaseResultMap" type="com.pcloud.book.keywords.entity.BookGuide">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="book_id" property="bookId" jdbcType="BIGINT"/>
        <result column="channel_id" property="channelId" jdbcType="BIGINT"/>
        <result column="book_group_id" property="bookGroupId" jdbcType="BIGINT"/>
        <result column="classify_id" property="classifyId" jdbcType="BIGINT"/>
        <result column="set_type" property="setType" jdbcType="TINYINT"/>
        <result column="is_recommend" property="isRecommend" jdbcType="TINYINT"/>
        <result column="recommend_language" property="recommendLanguage" jdbcType="VARCHAR"/>
        <result column="create_user" property="createUser" jdbcType="BIGINT"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
    </resultMap>
    <sql id="Base_Column_List">
        id, book_id, channel_id, book_group_id, classify_id, set_type, is_recommend,
        recommend_language, create_user, create_time
    </sql>

    <select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List"/>
        from book_guide
        where id = #{id,jdbcType=BIGINT}
    </select>


    <insert id="insert" parameterType="bookGuide" useGeneratedKeys="true"
            keyProperty="id">
        insert into book_guide
        <trim prefix="(" suffix=")" suffixOverrides=",">
            book_id,
            channel_id,
            book_group_id,
            classify_id,
            set_type,
            is_recommend,
            recommend_language,
            create_user,
            create_time,
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{bookId,jdbcType=BIGINT},
            #{channelId,jdbcType=BIGINT},
            #{bookGroupId,jdbcType=BIGINT},
            #{classifyId,jdbcType=BIGINT},
            #{setType,jdbcType=TINYINT},
            #{isRecommend,jdbcType=TINYINT},
            #{recommendLanguage,jdbcType=VARCHAR},
            #{createUser,jdbcType=BIGINT},
            NOW(),
        </trim>
    </insert>

    <update id="update" parameterType="bookGuide">
        update book_guide
        <set>
            <if test="isRecommend != null">
                is_recommend = #{isRecommend},
            </if>
            recommend_language = #{recommendLanguage},
            update_time = now()
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>

    <select id="getGuideByBookGroup" resultType="GuideVO" parameterType="Long">
        select
            id,
            book_id bookId,
            channel_id channelId,
            book_group_id bookGroupId,
            classify_id classifyId,
            set_type setType,
            is_recommend isRecommend,
            recommend_language recommendLanguage
        from
            book_guide
        where
          book_group_id = #{_parameter,jdbcType=BIGINT} and set_type = 0 limit 1
    </select>

    <select id="getGuideByClassify" resultType="GuideVO" parameterType="Long">
        select
        id,
        book_id bookId,
        channel_id channelId,
        book_group_id bookGroupId,
        classify_id classifyId,
        set_type setType,
        is_recommend isRecommend,
        recommend_language recommendLanguage
        from
        book_guide
        where
        classify_id = #{_parameter,jdbcType=BIGINT} and set_type = 1 limit 1
    </select>

    <select id="getBaseInfo" resultType="GuideDTO" parameterType="map">
        select
            id,
            book_id bookId,
            channel_id channelId,
            book_group_id bookGroupId,
            classify_id classifyId,
            set_type setType,
            is_recommend isRecommend,
            recommend_language recommendLanguage
        from
            book_guide
        where
            book_group_id = #{bookGroupId}
        and classify_id = #{classifyId}
        limit 1
    </select>

    <delete id="deleteById" parameterType="Long">
        delete from book_guide
        where id = #{_parameter,jdbcType=BIGINT}
    </delete>

</mapper>