<?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.ruoyi.system.mapper.SysAdsMapper">

    <resultMap type="SysAds" id="SysAdsResult">
        <result property="id"    column="id"    />
        <result property="poster"    column="poster"    />
        <result property="redirect"    column="redirect"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="deleted"    column="deleted"    />
        <result property="remark"    column="remark"    />
        <result property="sort"    column="sort"    />
    </resultMap>

    <sql id="selectSysAdsVo">
        select id, poster, redirect, status, create_time, update_time, deleted, remark,sort from sys_ads
    </sql>

    <select id="selectSysAdsList" parameterType="SysAds" resultMap="SysAdsResult">
        <include refid="selectSysAdsVo"/>
        <where>
            <if test="poster != null  and poster != ''"> and poster = #{poster}</if>
            <if test="redirect != null  and redirect != ''"> and redirect = #{redirect}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="deleted != null  and deleted != ''"> and deleted = #{deleted}</if>
        </where>
    </select>

    <select id="selectSysAdsById" parameterType="Long" resultMap="SysAdsResult">
        <include refid="selectSysAdsVo"/>
        where id = #{id}
    </select>

    <insert id="insertSysAds" parameterType="SysAds">
        insert into sys_ads
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="poster != null and poster != ''">poster,</if>
            <if test="redirect != null">redirect,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="deleted != null and deleted != ''">deleted,</if>
            <if test="remark != null">remark,</if>
            <if test="sort != null">sort,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="poster != null and poster != ''">#{poster},</if>
            <if test="redirect != null">#{redirect},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="deleted != null and deleted != ''">#{deleted},</if>
            <if test="remark != null">#{remark},</if>
            <if test="sort != null">#{sort},</if>
        </trim>
    </insert>

    <update id="updateSysAds" parameterType="SysAds">
        update sys_ads
        <trim prefix="SET" suffixOverrides=",">
            <if test="poster != null and poster != ''">poster = #{poster},</if>
            <if test="redirect != null">redirect = #{redirect},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="deleted != null and deleted != ''">deleted = #{deleted},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="sort != null">sort = #{sort},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysAdsById" parameterType="Long">
        update sys_ads set deleted = '1' where id = #{id}
    </delete>

    <delete id="deleteSysAdsByIds" parameterType="String">
        update sys_ads set deleted = '1' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
        delete from sys_ads where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
