<?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.yiqi.app.mapper.AppBannerMapper">

    <resultMap type="AppBanner" id="AppBannerResult">
        <result property="id" column="id"/>
        <result property="bannerType" column="banner_type"/>
        <result property="imgUrl" column="img_url"/>
        <result property="clickType" column="click_type"/>
        <result property="redirectTitle" column="redirect_title"/>
        <result property="redirectContent" column="redirect_content"/>
        <result property="status" column="status"/>
        <result property="createById" column="create_by_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateById" column="update_by_id"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectAppBannerVo">
        select * from app_banner
    </sql>

    <select id="selectAppBannerList" parameterType="AppBanner" resultMap="AppBannerResult">
        select * from app_banner
        <where>
            <if test="bannerType != null  and bannerType != ''">
                and banner_type = #{bannerType}
            </if>
            <if test="imgUrl != null  and imgUrl != ''">
                and img_url = #{imgUrl}
            </if>
            <if test="clickType != null  and clickType != ''">
                and click_type = #{clickType}
            </if>
            <if test="redirectTitle != null  and redirectTitle != ''">
                and redirect_title = #{redirectTitle}
            </if>
            <if test="redirectContent != null  and redirectContent != ''">
                and redirect_content = #{redirectContent}
            </if>
            <if test="status != null  and status != ''">
                and status = #{status}
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="selectAppBannerById" parameterType="Long"
            resultMap="AppBannerResult">
        <include refid="selectAppBannerVo"/>
        where id = #{id}
    </select>

    <insert id="insertAppBanner" parameterType="AppBanner" useGeneratedKeys="true"
            keyProperty="id">
        insert into app_banner
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="bannerType != null">banner_type,
            </if>
            <if test="imgUrl != null">img_url,
            </if>
            <if test="clickType != null">click_type,
            </if>
            <if test="redirectTitle != null">redirect_title,
            </if>
            <if test="redirectContent != null">redirect_content,
            </if>
            <if test="status != null">status,
            </if>
            <if test="createById != null">create_by_id,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="remark != null">remark,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="bannerType != null">#{bannerType},
            </if>
            <if test="imgUrl != null">#{imgUrl},
            </if>
            <if test="clickType != null">#{clickType},
            </if>
            <if test="redirectTitle != null">#{redirectTitle},
            </if>
            <if test="redirectContent != null">#{redirectContent},
            </if>
            <if test="status != null">#{status},
            </if>
            <if test="createById != null">#{createById},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="remark != null">#{remark},
            </if>
        </trim>
    </insert>

    <update id="updateAppBanner" parameterType="AppBanner">
        update app_banner
        <trim prefix="SET" suffixOverrides=",">
            <if test="bannerType != null">banner_type =
                #{bannerType},
            </if>
            <if test="imgUrl != null">img_url =
                #{imgUrl},
            </if>
            <if test="clickType != null">click_type =
                #{clickType},
            </if>
            <if test="redirectTitle != null">redirect_title =
                #{redirectTitle},
            </if>
            <if test="redirectContent != null">redirect_content =
                #{redirectContent},
            </if>
            <if test="status != null">status =
                #{status},
            </if>
            <if test="updateById != null">update_by_id =
                #{updateById},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
            <if test="remark != null">remark =
                #{remark},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAppBannerById" parameterType="Long">
        delete from app_banner where id = #{id}
    </delete>

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