<?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.xingxi.business.Banner.mapper.BannerMapper">
    <resultMap type="Banner" id="BannerResult">
        <result property="bannerId"    column="bannerId"    />
        <result property="bannerUrl"    column="bannerUrl"    />
        <result property="bannerType"    column="bannerType"    />
        <result property="prodId"    column="prodId"    />
        <result property="newsId"    column="newsId"    />
        <result property="sort"    column="sort"    />
        <result property="delFlag"    column="delFlag"    />
        <result property="createUser"    column="createUser"    />
        <result property="createTime"    column="createTime"    />
        <result property="updateUser"    column="updateUser"    />
        <result property="updateTime"    column="updateTime"    />
    </resultMap>

    <sql id="selectBanner">
        select bannerId, bannerUrl, bannerType, prodId, newsId, sort, delFlag, createUser, createTime, updateUser, updateTime from t_banner
    </sql>

    <sql id="selectBannerExt">
        select
            ${tableAlias}.bannerId,
            ${tableAlias}.bannerUrl,
            ${tableAlias}.bannerType,
            ${tableAlias}.prodId,
            ${tableAlias}.newsId,
            ${tableAlias}.sort,
            ${tableAlias}.delFlag,
            ${tableAlias}.createUser,
            ${tableAlias}.createTime,
            ${tableAlias}.updateUser,
            ${tableAlias}.updateTime
        from t_banner ${tableAlias}
    </sql>

    <select id="selectBannerList" parameterType="Banner" resultMap="BannerResult">
        <include refid="selectBanner"/>
        <where>  
            <if test="bannerUrl != null  and bannerUrl != ''"> and bannerUrl = #{bannerUrl}</if>
            <if test="bannerType != null  and bannerType != ''"> and bannerType = #{bannerType}</if>
            <if test="prodId != null "> and prodId = #{prodId}</if>
            <if test="newsId != null "> and newsId = #{newsId}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
    </select>

    <select id="selectBannerByBannerId" parameterType="Long" resultMap="BannerResult">
        <include refid="selectBanner"/>
        where bannerId = #{bannerId}
    </select>
        
    <insert id="insertBanner" parameterType="Banner" useGeneratedKeys="true" keyProperty="bannerId">
        insert into t_banner
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="bannerUrl != null">bannerUrl,</if>
            <if test="bannerType != null">bannerType,</if>
            <if test="prodId != null">prodId,</if>
            <if test="newsId != null">newsId,</if>
            <if test="sort != null">sort,</if>
            <if test="delFlag != null">delFlag,</if>
            <if test="createUser != null">createUser,</if>
            <if test="createTime != null">createTime,</if>
            <if test="updateUser != null">updateUser,</if>
            <if test="updateTime != null">updateTime,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="bannerUrl != null">#{bannerUrl},</if>
            <if test="bannerType != null">#{bannerType},</if>
            <if test="prodId != null">#{prodId},</if>
            <if test="newsId != null">#{newsId},</if>
            <if test="sort != null">#{sort},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createUser != null">#{createUser},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateUser != null">#{updateUser},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <insert id="batchInsertBanner">
        insert into t_banner( bannerUrl, bannerType, prodId, newsId, sort, delFlag, createUser, createTime, updateUser, updateTime) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.bannerUrl}, #{item.bannerType}, #{item.prodId}, #{item.newsId}, #{item.sort}, #{item.delFlag}, #{item.createUser}, #{item.createTime}, #{item.updateUser}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="updateBanner" parameterType="Banner">
        update t_banner
        <trim prefix="SET" suffixOverrides=",">
            <if test="bannerUrl != null">bannerUrl = #{bannerUrl},</if>
            <if test="bannerType != null">bannerType = #{bannerType},</if>
            <if test="prodId != null">prodId = #{prodId},</if>
            <if test="newsId != null">newsId = #{newsId},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="delFlag != null">delFlag = #{delFlag},</if>
            <if test="createUser != null">createUser = #{createUser},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="updateUser != null">updateUser = #{updateUser},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
        </trim>
        where bannerId = #{bannerId}
    </update>

    <delete id="deleteBannerByBannerId" parameterType="Long">
        delete from t_banner where bannerId = #{bannerId}
    </delete>

    <delete id="deleteBannerByBannerIds" parameterType="String">
        delete from t_banner where bannerId in 
        <foreach item="bannerId" collection="array" open="(" separator="," close=")">
            #{bannerId}
        </foreach>
    </delete>

    <update id="logicDeleteBannerByBannerId" parameterType="Long">
        update t_banner
            set delFlag = '1'
        where bannerId = #{bannerId}
    </update>

    <update id="logicDeleteBannerByBannerIds" parameterType="String">
        update t_banner
        set delFlag = '1'
        where bannerId in
        <foreach item="bannerId" collection="array" open="(" separator="," close=")">
            #{bannerId}
        </foreach>
    </update>

    <update id="logicDeleteBannerByCondition" parameterType="Banner">
        update t_banner
        set delFlag = '1'
        <where>
            <if test="bannerUrl != null  and bannerUrl != ''"> and bannerUrl = #{bannerUrl}</if>
            <if test="bannerType != null  and bannerType != ''"> and bannerType = #{bannerType}</if>
            <if test="prodId != null "> and prodId = #{prodId}</if>
            <if test="newsId != null "> and newsId = #{newsId}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
    </update>
</mapper>