<?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.younike.system.mapper.IndexBannerMapper">
    
    <resultMap type="IndexBanner" id="IndexBannerResult">
        <result property="id"    column="id"    />
        <result property="urlImg"    column="url_img"    />
        <result property="link"    column="link"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectIndexBannerVo">
        select id, url_img, link, del_flag, create_by, create_time, update_by, update_time from index_banner
    </sql>

    <select id="selectIndexBannerList" parameterType="IndexBanner" resultMap="IndexBannerResult">
        <include refid="selectIndexBannerVo"/>
        <where>  
            <if test="urlImg != null  and urlImg != ''"> and url_img = #{urlImg}</if>
            <if test="link != null  and link != ''"> and link = #{link}</if>
             and del_flag = 0
        </where>
    </select>
    
    <select id="selectIndexBannerById" parameterType="Long" resultMap="IndexBannerResult">
        <include refid="selectIndexBannerVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertIndexBanner" parameterType="IndexBanner" useGeneratedKeys="true" keyProperty="id">
        insert into index_banner
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="urlImg != null and urlImg != ''">url_img,</if>
            <if test="link != null">link,</if>
            <if test="delFlag != null and delFlag != ''">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="urlImg != null and urlImg != ''">#{urlImg},</if>
            <if test="link != null">#{link},</if>
            <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateIndexBanner" parameterType="IndexBanner">
        update index_banner
        <trim prefix="SET" suffixOverrides=",">
            <if test="urlImg != null and urlImg != ''">url_img = #{urlImg},</if>
            <if test="link != null">link = #{link},</if>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteIndexBannerById" parameterType="Long">
        delete from index_banner where id = #{id}
    </delete>

    <delete id="deleteIndexBannerByIds" parameterType="String">
        update index_banner
        set del_flag = 2
        where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <delete id="deleteIndexBannerByIdsAndUserName">
        update index_banner
        set del_flag = 2, update_time = now()
        <if test="userName != null and userName != ''">
            , update_by = #{userName}
        </if>
        where id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>