<?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.pcloud.book.applet.dao.impl.AppletNewsPoolDAOImpl" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.applet.entity.AppletNewsPool" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="news_name" property="newsName" jdbcType="VARCHAR" />
    <result column="source" property="source" jdbcType="VARCHAR" />
    <result column="content" property="content" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
    <result column="is_delete" property="isDelete" jdbcType="TINYINT" />
  </resultMap>

  <sql id="Base_Column_List" >
    id, news_name, source, content,  create_time, update_time, is_delete
  </sql>

  <select id="getById" parameterType="long" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from
    applet_news_pool
    where
    id = #{id}
  </select>

  <update id="updateSelective" parameterType="com.pcloud.book.applet.entity.AppletNewsPool">
    update
    applet_news_pool
    <set>
      <if test="newsName != null">
        news_name = #{newsName},
      </if>
      <if test="source != null">
        source = #{source},
      </if>
      <if test="content != null">
        content = #{content},
      </if>
      update_time = now()
    </set>
    where
    id = #{id}
  </update>

  <delete id="batchDelete" parameterType="list">
    update
    applet_news_pool
    set
    is_delete = 1,
    update_time = now()
    where
    id in
    <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
      #{item}
    </foreach>
  </delete>

  <select id="listNewsPage" parameterType="map" resultMap="BaseResultMap">
    select
    id,
    news_name,
    source,
    ifnull(update_time, create_time) update_time
    from
    applet_news_pool
    where
    is_delete = 0
    <if test="newsName != null">
      and news_name like concat("%", #{newsName}, "%")
    </if>
    <if test="source != null">
      and source = #{source}
    </if>
  </select>

  <select id="listSource" resultType="string">
    select
    source
    from
    applet_news_pool
    where
    is_delete = 0
    group by source
  </select>

  <select id="getMapByIds" parameterType="list" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from
    applet_news_pool
    where
    id in
    <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
      #{item}
    </foreach>
    and
    is_delete = 0
  </select>

</mapper>
