<?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.goafanti.common.dao.NewsMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.News">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="edit_time" jdbcType="TIMESTAMP" property="editTime" />
    <result column="title" jdbcType="VARCHAR" property="title" />
    <result column="title_img" jdbcType="VARCHAR" property="titleImg" />
    <result column="author" jdbcType="VARCHAR" property="author" />
    <result column="type" jdbcType="INTEGER" property="type" />
    <result column="hot" jdbcType="INTEGER" property="hot" />
    <result column="source" jdbcType="VARCHAR" property="source" />
    <result column="source_url" jdbcType="VARCHAR" property="sourceUrl" />
    <result column="summary" jdbcType="VARCHAR" property="summary" />
    <result column="jmrh_flag" jdbcType="INTEGER" property="jmrhFlag" />
    <result column="province_id" jdbcType="INTEGER" property="provinceId" /> 
  </resultMap>
  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.goafanti.common.model.News">
    <result column="content" jdbcType="LONGVARCHAR" property="content" />
  </resultMap>
  <sql id="Base_Column_List">
    id, create_time, edit_time, title, title_img, author, type, hot, source, source_url, 
    summary,jmrh_flag,province_id
  </sql>
  <sql id="Blob_Column_List">
    content
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultType="com.goafanti.news.bo.NewsResult">
    select 
    n.id,
    n.content,
    n.create_time as createTime, 
    n.edit_time as editTime, 
    n.title, 
    n.title_img as titleImg, 
    n.author, 
    n.type, 
    n.hot,
    n.source, 
    n.source_url as sourceUrl, 
    n.summary,
    n.province_id as provinceId,
    n.audit_status as auditStatus,
    n.release_status as releaseStatus,
    n.top_number as topNumber,
    n.hotspot,
    n.release_date as releaseDate
    from news n
    where n.id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from news
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.News">
    insert into news (id, create_time, edit_time, 
      title, title_img, author, 
      type, hot, source, 
      source_url, summary, content,province_id,top_number,hotspot,audit_status,release_status,release_date
      )
    values (#{id,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, #{editTime,jdbcType=TIMESTAMP}, 
      #{title,jdbcType=VARCHAR}, #{titleImg,jdbcType=VARCHAR}, #{author,jdbcType=VARCHAR}, 
      #{type,jdbcType=INTEGER}, #{hot,jdbcType=INTEGER}, #{source,jdbcType=VARCHAR}, 
      #{sourceUrl,jdbcType=VARCHAR}, #{summary,jdbcType=VARCHAR}, #{content,jdbcType=LONGVARCHAR},
      #{provinceId,jdbcType=INTEGER}, #{topNumber,jdbcType=INTEGER}, #{hotspot,jdbcType=INTEGER},#{auditStatus,jdbcType=INTEGER},
      #{releaseStatus,jdbcType=INTEGER},#{releaseDate,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.News">
    insert into news
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="editTime != null">
        edit_time,
      </if>
      <if test="title != null">
        title,
      </if>
      <if test="titleImg != null">
        title_img,
      </if>
      <if test="author != null">
        author,
      </if>
      <if test="type != null">
        type,
      </if>
      <if test="hot != null">
        hot,
      </if>
      <if test="source != null">
        source,
      </if>
      <if test="sourceUrl != null">
        source_url,
      </if>
      <if test="summary != null">
        summary,
      </if>
      <if test="content != null">
        content,
      </if>
      <if test="jmrhFlag != null">
      	jmrh_flag,
      </if>
      <if test="provinceId != null">
      	province_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=BIGINT},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="editTime != null">
        #{editTime,jdbcType=TIMESTAMP},
      </if>
      <if test="title != null">
        #{title,jdbcType=VARCHAR},
      </if>
      <if test="titleImg != null">
        #{titleImg,jdbcType=VARCHAR},
      </if>
      <if test="author != null">
        #{author,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        #{type,jdbcType=INTEGER},
      </if>
      <if test="hot != null">
        #{hot,jdbcType=INTEGER},
      </if>
      <if test="source != null">
        #{source,jdbcType=VARCHAR},
      </if>
      <if test="sourceUrl != null">
        #{sourceUrl,jdbcType=VARCHAR},
      </if>
      <if test="summary != null">
        #{summary,jdbcType=VARCHAR},
      </if>
      <if test="content != null">
        #{content,jdbcType=LONGVARCHAR},
      </if>
       <if test="jmrhFlag != null">
        #{jmrhFlag,jdbcType=INTEGER},
      </if>
      <if test="provinceId != null">
        #{provinceId,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.News">
    update news
    <set>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="editTime != null">
        edit_time = #{editTime,jdbcType=TIMESTAMP},
      </if>
      <if test="title != null">
        title = #{title,jdbcType=VARCHAR},
      </if>
      <if test="titleImg != null">
        title_img = #{titleImg,jdbcType=VARCHAR},
      </if>
      <if test="author != null">
        author = #{author,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        type = #{type,jdbcType=INTEGER},
      </if>
      <if test="hot != null">
        hot = #{hot,jdbcType=INTEGER},
      </if>
      <if test="source != null">
        source = #{source,jdbcType=VARCHAR},
      </if>
      <if test="sourceUrl != null">
        source_url = #{sourceUrl,jdbcType=VARCHAR},
      </if>
      <if test="summary != null">
        summary = #{summary,jdbcType=VARCHAR},
      </if>
      <if test="content != null">
        content = #{content,jdbcType=LONGVARCHAR},
      </if>
      <if test="releaseDate!=null">
      release_date=#{releaseDate,jdbcType=TIMESTAMP},
      </if>
      <if test="provinceId!=null">
      province_id=#{provinceId,jdbcType=INTEGER},
      </if>
      <if test="auditStatus!=null">
      audit_status=#{auditStatus,jdbcType=INTEGER},
      </if>
      <if test="releaseStatus!=null">
      release_status=#{releaseStatus,jdbcType=INTEGER},
      </if>
      <if test="topNumber!=null">
      top_number=#{topNumber,jdbcType=INTEGER},
      </if>
      <if test="hotspot!=null">
      hotspot=#{hotspot,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.goafanti.common.model.News">
    update news
    set create_time = #{createTime,jdbcType=TIMESTAMP},
      edit_time = #{editTime,jdbcType=TIMESTAMP},
      title = #{title,jdbcType=VARCHAR},
      title_img = #{titleImg,jdbcType=VARCHAR},
      author = #{author,jdbcType=VARCHAR},
      type = #{type,jdbcType=INTEGER},
      hot = #{hot,jdbcType=INTEGER},
      source = #{source,jdbcType=VARCHAR},
      source_url = #{sourceUrl,jdbcType=VARCHAR},
      summary = #{summary,jdbcType=VARCHAR},
      content = #{content,jdbcType=LONGVARCHAR},
      jmrh_flag = #{jmrhFlag,jdbcType=INTEGER},
      province_id = #{provinceId,jdbcType=INTEGER},
      audit_status = #{auditStatus,jdbcType=INTEGER},
      release_status = #{releaseStatus,jdbcType=INTEGER},
      top_number = #{topNumber,jdbcType=INTEGER},
      hotspot = #{hotspot,jdbcType=INTEGER}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.News">
    update news
    set create_time = #{createTime,jdbcType=TIMESTAMP},
      edit_time = #{editTime,jdbcType=TIMESTAMP},
      title = #{title,jdbcType=VARCHAR},
      title_img = #{titleImg,jdbcType=VARCHAR},
      author = #{author,jdbcType=VARCHAR},
      type = #{type,jdbcType=INTEGER},
      hot = #{hot,jdbcType=INTEGER},
      source = #{source,jdbcType=VARCHAR},
      source_url = #{sourceUrl,jdbcType=VARCHAR},
      summary = #{summary,jdbcType=VARCHAR},
      jmrh_flag = #{jmrhFlag,jdbcType=INTEGER},
      province_id = #{provinceId,jdbcType=INTEGER}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <select id="portalNewsList" resultType="com.goafanti.news.bo.NewsPortalList">
		select
			a.id,
			DATE_FORMAT(a.create_time,'%Y-%m-%d') as createTime,
			a.title,
			a.title_img as titleImg,
			a.type,
			a.hot,
			a.summary,
			a.source,
			a.content,
			release_date as releaseDate
		from news a
		where 1=1
		 and (a.type = 0 or a.type = 99 or a.type =98) 
		<if test="provinceId != null">
			and a.province_id = #{provinceId,jdbcType=INTEGER}
		</if>
		<if test="type != null" >
			and a.type = #{type,jdbcType=INTEGER}
		</if>
		<!-- 
		<if test="hot != null">
			and a.hot = #{hot,jdbcType=INTEGER}
		</if> 
		-->
		<if test="keyword != null">
			and a.title like concat('%',#{keyword},'%')
		</if>
		<if test="auditStatus!=null">
		and a.audit_status=#{auditStatus,jdbcType=INTEGER}
		</if>	
		order by release_date desc
		<if test="page_sql != null">
			${page_sql}
		</if>
	</select>
	
	<select id="portalNewsCount" resultType="java.lang.Integer">
		select 
			count(0)
		from news a
		where 
		(a.type = 0 or a.type = 99 or a.type =98)
		<if test="provinceId != null">
			and a.province_id = #{provinceId,jdbcType=INTEGER}
		</if>
		<if test="type != null and type != 0 and type != 1 and type != 2" >
			and a.type = #{type,jdbcType=INTEGER}
		</if>
		<!-- 	
		<if test="hot != null">
			and a.hot = #{hot,jdbcType=INTEGER}
		</if>
		-->
		<if test="keyword != null">
			and a.title like concat('%',#{keyword},'%')
		</if>
		<if test="auditStatus!=null">
		and a.audit_status=#{auditStatus,jdbcType=INTEGER}
		</if>	
	</select>
	<select id="portalNewsPolicy" resultType="com.goafanti.news.bo.NewsPortalList">
		select
			a.id,
			DATE_FORMAT(a.create_time,'%Y-%d-%m') as createTime,
			a.title,
			a.title_img as titleImg,
			a.type,
			a.hot,
			a.summary,
			a.source,
			a.content
		from news a
		where
		a.type =5 or a.type =4
		order by create_time desc
	</select>
	<select id="portalNewsQuestion" resultType="com.goafanti.news.bo.NewsPortalList">
		select
			a.id,
			DATE_FORMAT(a.create_time,'%Y-%d-%m') as createTime,
			a.title,
			a.title_img as titleImg,
			a.type,
			a.hot,
			a.summary,
			a.source,
			a.content
		from news a
		where
		a.type =2
		order by create_time desc
	</select>
	<select id="newsInterest" resultType="com.goafanti.news.bo.newsInterestBo">
		select
		n.id,n.title ,n.create_time as createTime
	from news_interest ni
	LEFT  join news n on ni.new_id=n.id
	where uid=#{uid,jdbcType=VARCHAR}
	</select>
	
	
	<select id="appNewsList" resultType="com.goafanti.app.bo.AppDiscoveryBo">
		select
			a.id,
			DATE_FORMAT(a.release_date,'%Y-%m-%d') as releaseDate,
			a.title,
			a.content,
			a.title_img as titleImg
		from news a
		left join district_glossory d on a.province_id=d.id
		where a.type =0
		order by a.release_date desc
		<if test="page_sql != null">
			${page_sql}
		</if>
	</select>
	
	<select id="appNewsCount" resultType="java.lang.Integer">
		select 
			count(0)
		from news a
		left join district_glossory d on a.province_id=d.id
		where a.type =0	
	</select>
<select id="getNewsList" resultType="com.goafanti.common.model.News">
select
	title,
	create_time as createTime,
	id
from
	news
order by
	create_time desc limit #{0}
</select>	
<select id="getPolicyDetail" resultType="com.goafanti.common.bo.PolicyEntity">
select p.id,p.title,p.title_img as titleImg,p.summary,
p.content,dg1.name as provinceS,dg2.name as cityS,edit_time as editTime ,create_time as createTime,p.id,p.source,p.source_url as sourceUrl from policy p 
left join district_glossory dg1 on dg1.id=p.province
left join district_glossory dg2 on dg2.id=p.city
where audit_status = 2 and p.id=#{0}
</select>
	<select id="encyclopediaList" resultType="com.goafanti.app.bo.AppDiscoveryBo">
		select
			a.id,
			DATE_FORMAT(a.release_date,'%Y-%m-%d') as releaseDate,
			a.title,
			a.content,
			a.title_img as titleImg
		from news a
		left join district_glossory d on a.province_id=d.id
		where a.type =98
		order by a.release_date desc
		<if test="page_sql != null">
			${page_sql}
		</if>
	</select>
	
	<select id="encyclopediaCount" resultType="java.lang.Integer">
		select 
			count(0)
		from news a
		left join district_glossory d on a.province_id=d.id
		where a.type =98
	</select>


</mapper>