<?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.dgtly.wxportal.mapper.WxBannerMapper">
    
    <resultMap type="WxBanner" id="WxBannerResult">
        <result property="bannerId"    column="banner_id"    />
        <result property="imgUrl"    column="img_url"    />
        <result property="title"    column="title"    />
        <result property="contextUrl"    column="context_url"    />
        <result property="des"    column="des"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectWxBannerVo">
        select banner_id, img_url, title, context_url, des, create_by, create_time, update_by, update_time, remark from wx_banner
    </sql>

    <select id="selectWxBannerList" parameterType="WxBanner" resultMap="WxBannerResult">
        <include refid="selectWxBannerVo"/>
        <where>  
            <if test="title != null  and title != ''">
                and title like concat('%', #{title}, '%')
            </if>
            <if test="params.beginCreateTime != null and params.beginCreateTime != ''"><!-- 开始时间检索 -->
                AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginCreateTime},'%y%m%d')
            </if>
            <if test="params.endCreateTime != null and params.endCreateTime != ''"><!-- 结束时间检索 -->
                AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endCreateTime},'%y%m%d')
            </if>
        </where>
    </select>
    
    <select id="selectWxBannerById" parameterType="Long" resultMap="WxBannerResult">
        <include refid="selectWxBannerVo"/>
        where banner_id = #{bannerId}
    </select>
        
    <insert id="insertWxBanner" parameterType="WxBanner">
        insert into wx_banner
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="bannerId != null ">banner_id,</if>
            <if test="imgUrl != null  and imgUrl != ''">img_url,</if>
            <if test="title != null  and title != ''">title,</if>
            <if test="contextUrl != null  and contextUrl != ''">context_url,</if>
            <if test="des != null  and des != ''">des,</if>
            <if test="createBy != null  and createBy != ''">create_by,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="updateBy != null  and updateBy != ''">update_by,</if>
            <if test="updateTime != null ">update_time,</if>
            <if test="remark != null  and remark != ''">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="bannerId != null ">#{bannerId},</if>
            <if test="imgUrl != null  and imgUrl != ''">#{imgUrl},</if>
            <if test="title != null  and title != ''">#{title},</if>
            <if test="contextUrl != null  and contextUrl != ''">#{contextUrl},</if>
            <if test="des != null  and des != ''">#{des},</if>
            <if test="createBy != null  and createBy != ''">#{createBy},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null ">#{updateTime},</if>
            <if test="remark != null  and remark != ''">#{remark},</if>
         </trim>
    </insert>

    <update id="updateWxBanner" parameterType="WxBanner">
        update wx_banner
        <trim prefix="SET" suffixOverrides=",">
            <if test="imgUrl != null  and imgUrl != ''">img_url = #{imgUrl},</if>
            <if test="title != null  and title != ''">title = #{title},</if>
            <if test="contextUrl != null  and contextUrl != ''">context_url = #{contextUrl},</if>
            <if test="des != null  and des != ''">des = #{des},</if>
            <if test="createBy != null  and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null ">update_time = #{updateTime},</if>
            <if test="remark != null  and remark != ''">remark = #{remark},</if>
        </trim>
        where banner_id = #{bannerId}
    </update>

    <delete id="deleteWxBannerById" parameterType="Long">
        delete from wx_banner where banner_id = #{bannerId}
    </delete>

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