<?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.dgtis.dorm.manager.db.dao.BannerMapper">
  <resultMap id="BaseResultMap" type="com.dgtis.dorm.manager.db.domain.Banner">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="title" jdbcType="VARCHAR" property="title" />
    <result column="content" jdbcType="VARCHAR" property="content" />
    <result column="position" jdbcType="INTEGER" property="position" />
    <result column="enabled" jdbcType="BIT" property="enabled" />
    <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
    <result column="order_index" jdbcType="INTEGER" property="orderIndex" />
    <result column="creator_id" jdbcType="INTEGER" property="creatorId" />
    <result column="image" jdbcType="VARCHAR" property="image" />
    <result column="newsId" jdbcType="INTEGER" property="newsId" />
    <result column="url" jdbcType="VARCHAR" property="url" />

    <result column="activityType" jdbcType="VARCHAR" property="activityType" />
  </resultMap>

  <sql id="Base_Column_List">
    zhll_banner.id, zhll_banner.title, zhll_banner.content, `position`, enabled,
    zhll_banner.create_date, zhll_banner.order_index, zhll_banner.creator_id,
    image, newsId, url
  </sql>

  <select id="selectByExample" parameterType="com.dgtis.dorm.manager.db.domain.Banner" resultMap="BaseResultMap">
    select distinct
    <include refid="Base_Column_List" />
      ,an.news_type as activityType
    from zhll_banner
      left join zhll_news an
      on zhll_banner.newsId = an.id
    <where>
      <if test="title != null and title != ''">
          and title like concat('%',#{title}, '%')
      </if>
      <if test="enabled != false">
          and enabled = #{enabled}
      </if>
    </where>
      order by create_date DESC, order_index DESC
  </select>

  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from zhll_banner
    where id = #{id,jdbcType=INTEGER}
  </select>

  <select id="countByExample" parameterType="com.dgtis.dorm.manager.db.domain.Banner" resultType="java.lang.Long">
    select count(*) from zhll_banner
    <where>
      <if test="title != null and title != ''">
        and title like concat('%',#{title}, '%')
      </if>
      <if test="enabled != null">
        and enabled = #{enabled}
      </if>
    </where>
  </select>

  <insert id="insertSelective" parameterType="com.dgtis.dorm.manager.db.domain.Banner">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into zhll_banner
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="title != null">
          title,
      </if>
      <if test="content != null">
          content,
      </if>
      <if test="position != null">
          position,
      </if>
      <if test="enabled != null">
          enabled,
      </if>
      <if test="createDate != null">
          create_date,
      </if>
      <if test="orderIndex != null">
          order_index,
      </if>
      <if test="creatorId != null">
          creator_id,
      </if>
      <if test="image != null">
          image,
      </if>
      <if test="newsId != null">
          newsId,
      </if>
      <if test="url != null">
          url,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="title != null">
        #{title,jdbcType=VARCHAR},
      </if>
      <if test="content != null">
        #{content,jdbcType=VARCHAR},
      </if>
      <if test="position != null">
        #{position,jdbcType=INTEGER},
      </if>
      <if test="enabled != null">
        #{enabled,jdbcType=BIT},
      </if>
      <if test="createDate != null">
        #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="orderIndex != null">
        #{orderIndex,jdbcType=INTEGER},
      </if>
      <if test="creatorId != null">
        #{creatorId,jdbcType=INTEGER},
      </if>
      <if test="image != null">
        #{image,jdbcType=VARCHAR},
      </if>
      <if test="newsId != null">
        #{newsId,jdbcType=INTEGER},
      </if>
      <if test="url != null">
        #{url,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

  <update id="updateByPrimaryKeySelective" parameterType="com.dgtis.dorm.manager.db.domain.Banner">
    update zhll_banner
    <set>
        <if test="title != null">
          title = #{title, jdbcType=VARCHAR},
        </if>
        <if test="content != null">
          content = #{content, jdbcType=VARCHAR},
        </if>
        <if test="position != null">
          position = #{position, jdbcType=INTEGER},
        </if>
        <if test="enabled != null">
          enabled = #{enabled, jdbcType=BIT},
        </if>
        <if test="createDate != null">
          create_date = #{createDate, jdbcType=TIMESTAMP},
        </if>
        <if test="orderIndex != null">
          order_index = #{orderIndex, jdbcType=INTEGER},
        </if>
        <if test="creatorId != null">
          creator_id = #{creatorId, jdbcType=INTEGER},
        </if>
        <if test="image != null">
          image = #{image, jdbcType=VARCHAR},
        </if>
        <if test="newsId != null">
          newsId = #{newsId, jdbcType=INTEGER},
        </if>
        <if test="url != null">
          url = #{url, jdbcType=VARCHAR},
        </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from zhll_banner
    where id = #{id,jdbcType=INTEGER}
  </delete>
</mapper>