<?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.community.huiju.dao.ToBannerMapper" >
  <resultMap id="BaseResultMap" type="com.community.huiju.model.ToBanner" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="community_id" property="communityId" jdbcType="INTEGER" />
    <result column="banner_description" property="bannerDescription" jdbcType="VARCHAR" />
    <result column="sort" property="sort" jdbcType="INTEGER" />
    <result column="banner_cover" property="bannerCover" jdbcType="VARCHAR" />
    <result column="banner_position" property="bannerPosition" jdbcType="INTEGER" />
    <result column="eff_time" property="effTime" jdbcType="TIMESTAMP" />
    <result column="exp_time" property="expTime" jdbcType="TIMESTAMP" />
    <result column="banner_type" property="bannerType" jdbcType="CHAR" />
    <result column="external_link" property="externalLink" jdbcType="VARCHAR" />
    <result column="banner_title" property="bannerTitle" jdbcType="VARCHAR" />
    <result column="banner_content" property="bannerContent" jdbcType="VARCHAR" />
    <result column="create_user" property="createUser" jdbcType="INTEGER" />
    <result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, community_id, banner_description, sort, banner_cover, banner_position, eff_time, 
    exp_time, banner_type, external_link, banner_title, banner_content, create_user, create_date
  </sql>

  <select id="selectByCommunityId" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"></include>
    from to_banner t where id = #{bannerId}
    <![CDATA[
    AND date_format(t.eff_time,'%Y-%m-%d') <= date_format(NOW(),'%Y-%m-%d')
    AND date_format(t.exp_time,'%Y-%m-%d') >= date_format(NOW(),'%Y-%m-%d')
    ]]>
    order by t.sort, t.eff_time
  </select>

  <select id="selectAllByNum" resultMap="BaseResultMap">
    select
    id, community_id, banner_description, sort, banner_cover, banner_position, eff_time,
    exp_time, banner_type, external_link, banner_title, create_user, create_date
    <![CDATA[
    from to_banner t where date_format(t.eff_time,'%Y-%m-%d') <= date_format(NOW(),'%Y-%m-%d')
    and date_format(t.exp_time,'%Y-%m-%d') >= date_format(NOW(),'%Y-%m-%d')
    ]]>
    <if test="bannerPosition != null">
      and banner_position = #{bannerPosition,jdbcType=INTEGER}
    </if>
    order by t.sort, t.eff_time
    <if test="num != null">
      limit #{num}
    </if>

  </select>
</mapper>