<?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.rightsSetting.dao.impl.RightsSettingBannerDaoImpl">

    <resultMap id="BaseResultMap" type="com.pcloud.book.rightsSetting.entity.RightsSettingBanner">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="rights_setting_id" property="rightsSettingId" jdbcType="BIGINT"/>
        <result column="banner_type" property="bannerType" jdbcType="INTEGER"/>
        <result column="banner_title" property="bannerTitle" jdbcType="VARCHAR"/>
        <result column="banner_pic" property="bannerPic" jdbcType="VARCHAR"/>
        <result column="jump_type" property="jumpType" jdbcType="INTEGER"/>
        <result column="jump_url" property="jumpUrl" jdbcType="VARCHAR"/>
        <result column="serve_id" property="serveId" jdbcType="BIGINT"/>
        <result column="serve_type" property="serveType" jdbcType="INTEGER"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, rights_setting_id, banner_type, banner_title, banner_pic, jump_type, jump_url, serve_id, serve_type, create_time, update_time
    </sql>

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

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

    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        INSERT INTO rights_setting_banner(
            rights_setting_id, 
            banner_type,
            banner_title,
            banner_pic,
            jump_type,
            jump_url,
            serve_id,
            serve_type,
            create_time,
            update_time
        ) VALUES (
            #{rightsSettingId, jdbcType=BIGINT}, 
            #{bannerType, jdbcType=INTEGER},
            #{bannerTitle, jdbcType=VARCHAR},
            #{bannerPic, jdbcType=VARCHAR},
            #{jumpType, jdbcType=INTEGER},
            #{jumpUrl, jdbcType=VARCHAR},
            #{serveId, jdbcType=BIGINT},
            #{serveType, jdbcType=INTEGER},
            #{createTime, jdbcType=TIMESTAMP},
            #{updateTime, jdbcType=TIMESTAMP}
        )
    </insert>

    <insert id="batchInsert">
        INSERT INTO rights_setting_banner (
        rights_setting_id,
        banner_type,
        banner_title,
        banner_pic,
        jump_type,
        jump_url,
        serve_id,
        serve_type,
        create_time,
        update_time
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.rightsSettingId, jdbcType=BIGINT},
            #{item.bannerType, jdbcType=INTEGER},
            #{item.bannerTitle, jdbcType=VARCHAR},
            #{item.bannerPic, jdbcType=VARCHAR},
            #{item.jumpType, jdbcType=INTEGER},
            #{item.jumpUrl, jdbcType=VARCHAR},
            #{item.serveId, jdbcType=BIGINT},
            #{item.serveType, jdbcType=INTEGER},
            now(),
            now()
            )
        </foreach>
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        UPDATE rights_setting_banner
        <set>
            <if test="rightsSettingId != null">
                rights_setting_id = #{rightsSettingId},
            </if>
            <if test="bannerType != null">
                banner_type = #{bannerType},
            </if>
            <if test="bannerTitle != null and bannerTitle != ''">
                banner_title = #{bannerTitle},
            </if>
            <if test="bannerPic != null and bannerPic != ''">
                banner_pic = #{bannerPic},
            </if>
            <if test="jumpType != null">
                jump_type = #{jumpType},
            </if>
            <if test="jumpUrl != null and jumpUrl != ''">
                jump_url = #{jumpUrl},
            </if>
            <if test="serveId != null">
                serve_id = #{serveId},
            </if>
            <if test="serveType != null">
                serve_type = #{serveType},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
        </set>
        WHERE id = #{id}
    </update>

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

    <delete id="deleteByRightsSettingId">
       DELETE FROM rights_setting_banner where rights_setting_id = #{rightsSettingId}
    </delete>



    <select id="getByRightsSettingId" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM rights_setting_banner
        where
        rights_setting_id = #{id}
    </select>
</mapper>