<?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.BannerInfoMapper">
  <resultMap type="BannerInfo" id="BannerInfoResult">
    <result property="id"    column="id"    />
    <result property="name"    column="name"    />
    <result property="bannerAddr"    column="banner_addr"    />
    <result property="sort"    column="sort"    />
    <result property="jumpUrl"    column="jump_url"    />
    <result property="createTime"    column="create_time"    />
    <result property="updateTime"    column="update_time"    />
  </resultMap>

  <sql id="selectBannerInfoVo">
    select id, name, banner_addr, sort, jump_url, create_time, update_time from banner_info
  </sql>

  <select id="selectBannerInfoList" parameterType="BannerInfo" resultMap="BannerInfoResult">
    <include refid="selectBannerInfoVo"/>
    <where>
      <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
      <if test="bannerAddr != null  and bannerAddr != ''"> and banner_addr = #{bannerAddr}</if>
      <if test="sort != null "> and sort = #{sort}</if>
      <if test="jumpUrl != null  and jumpUrl != ''"> and jump_url = #{jumpUrl}</if>
    </where>
    order by id desc
  </select>

  <select id="selectBannerInfoById" parameterType="String" resultMap="BannerInfoResult">
    <include refid="selectBannerInfoVo"/>
    where id = #{id}
  </select>

  <insert id="insertBannerInfo" parameterType="BannerInfo" useGeneratedKeys="true" keyProperty="id">
    insert into banner_info
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="name != null">name,</if>
      <if test="bannerAddr != null">banner_addr,</if>
      <if test="sort != null">sort,</if>
      <if test="jumpUrl != null">jump_url,</if>
      <if test="createTime != null">create_time,</if>
      <if test="updateTime != null">update_time,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="name != null">#{name},</if>
      <if test="bannerAddr != null">#{bannerAddr},</if>
      <if test="sort != null">#{sort},</if>
      <if test="jumpUrl != null">#{jumpUrl},</if>
      <if test="createTime != null">#{createTime},</if>
      <if test="updateTime != null">#{updateTime},</if>
    </trim>
  </insert>

  <update id="updateBannerInfo" parameterType="BannerInfo">
    update banner_info
    <trim prefix="SET" suffixOverrides=",">
      <if test="name != null">name = #{name},</if>
      <if test="bannerAddr != null">banner_addr = #{bannerAddr},</if>
      <if test="sort != null">sort = #{sort},</if>
      <if test="jumpUrl != null">jump_url = #{jumpUrl},</if>
      <if test="createTime != null">create_time = #{createTime},</if>
      <if test="updateTime != null">update_time = #{updateTime},</if>
    </trim>
    where id = #{id}
  </update>

  <delete id="deleteBannerInfoById" parameterType="String">
    delete from banner_info where id = #{id}
  </delete>

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

  <select id="selectEnableBanner" resultMap="BannerInfoResult">
    <include refid="selectBannerInfoVo"/>   where enable=1
  </select>
</mapper>