<?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.ApproveHistoryMapper">
  <resultMap id="BaseResultMap" type="com.dgtis.dorm.manager.db.domain.ApproveHistory">
    <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_news.id, zhll_news.title, zhll_news.content, `position`, enabled,
    zhll_news.create_date, zhll_news.order_index, zhll_news.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_news
      left join zhll_news an
      on zhll_news.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_news
    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_news
    <where>
      <if test="title != null and title != ''">
        and title like concat('%',#{title}, '%')
      </if>
      <if test="enabled != null">
        and enabled = #{enabled}
      </if>
    </where>
  </select>
</mapper>