<?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="SummaryResultMap" type="com.goafanti.news.bo.NewsSummary">
		<id column="id" jdbcType="BIGINT" property="id" />
		<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
		<result column="title" jdbcType="VARCHAR" property="title" />
		<result column="title_img" jdbcType="VARCHAR" property="titleImg" />
		<result column="type" jdbcType="INTEGER" property="type" />
		<result column="hot" jdbcType="INTEGER" property="hot" />
		<result column="summary" jdbcType="VARCHAR" property="summary" />
		<result column="source" jdbcType="VARCHAR" property="source" />
		<result column="audit_status" jdbcType="INTEGER" property="auditStatus" />
		<result column="release_status" jdbcType="INTEGER" property="releaseStatus" />
	</resultMap>
	<sql id="Summary_Column_List">
		id, create_time, title, title_img, type, hot, summary, source,audit_status,release_status
	</sql>
	<select id="findList" resultType="com.goafanti.news.bo.NewsSummary">
		select
			a.id,
			a.create_time as createTime,
			a.title,
			a.title_img as titleImg,
			a.type,
			a.hot,
			a.summary,
			a.source
		from news a
		join branch_office_info b
		on a.province_id = b.province_id
		where 1=1
		<if test="type != null">
			and a.type = #{type,jdbcType=INTEGER}
		</if>
		<if test="website != null">
			and b.website = #{website,jdbcType=VARCHAR}
		</if>
		<if test="picRequired != null">
			and a.title_img is not null and a.title_img != ''
		</if>
		
		order by create_time desc
		limit #{pageNo,jdbcType=INTEGER}, #{pageSize,jdbcType=INTEGER}
	</select>
	
	<select id="findIndexNewsList" resultMap="SummaryResultMap">
		select
		<include refid="Summary_Column_List" />
		from news
		where hot = 1 
		<if test=" type != null">
			and type = #{type,jdbcType=INTEGER}
		</if>
		order by create_time desc
		limit #{pageNo,jdbcType=INTEGER}, #{pageSize,jdbcType=INTEGER}
	</select>
	
	<select id="findNewsListByPage" parameterType="String" resultMap="BaseResultMap">
  	select
  		id,
  		create_time,
  		title,
  		author,
  		type,
  		hot,
  		source,
  		summary,
  		audit_status as auditStatus,
  		release_status as releaseStatus,
  		top_number as topNumber,
    	hotspot
  	from news
  	where 1 =1
  	<if test="auditStatus != null">
  		and audit_status = #{auditStatus,jdbcType=INTEGER}
  	</if>
  	<if test="releaseStatus != null">
  		and release_status = #{releaseStatus,jdbcType=INTEGER}
  	</if>
  	<if test="type != null">
  		and type = #{type,jdbcType=INTEGER}
  	</if>
  	<if test="title != null">
  		and title like CONCAT('%',#{title,jdbcType=VARCHAR},'%')
  	</if>
  	<if test="author != null">
  		and author like CONCAT('%',#{author,jdbcType=VARCHAR},'%')
  	</if>
  	<if test="sDate != null">
  	    and create_time <![CDATA[ >= ]]>  #{sDate,jdbcType=TIMESTAMP}
  	</if>
  	<if test="eDate != null">
  		and create_time <![CDATA[ < ]]>  #{eDate,jdbcType=TIMESTAMP}
  	</if>
  	<if test="source != null">
  		and source like CONCAT('%',#{source,jdbcType=VARCHAR},'%')
  	</if>
  	<if test="hot != null">
  		and hot = #{hot,jdbcType=INTEGER}
  	</if>
  	order by create_time desc
  	<if test="page_sql!=null">
			${page_sql}
	</if>
  </select>
  
   <select id="findNewsCount" parameterType="String" resultType="java.lang.Integer">
  	select
  		count(1)
  	from news
  	where 1 =1
  	<if test="auditStatus != null">
  		and audit_status = #{auditStatus,jdbcType=INTEGER}
  	</if>
  	<if test="type != null">
  		and type = #{type,jdbcType=INTEGER}
  	</if>
  	<if test="title != null">
  		and title like CONCAT('%',#{title,jdbcType=VARCHAR},'%')
  	</if>
  	<if test="author != null">
  		and author like CONCAT('%',#{author,jdbcType=VARCHAR},'%')
  	</if>
  	<if test="sDate != null">
  	    and create_time <![CDATA[ >= ]]>  #{sDate,jdbcType=TIMESTAMP}
  	</if>
  	<if test="eDate != null">
  		and create_time <![CDATA[ < ]]>  #{eDate,jdbcType=TIMESTAMP}
  	</if>
  	<if test="source != null">
  		and source like CONCAT('%',#{source,jdbcType=VARCHAR},'%')
  	</if>
  	<if test="hot != null">
  		and hot = #{hot,jdbcType=INTEGER}
  	</if>
  </select>
  
  <delete id="batchDeleteByPrimaryKey" parameterType="java.util.List">
  	delete
  		from news
  	where id in
  	<foreach item="item" index="index" collection="list" open="("
			separator="," close=")">
			#{item}
	</foreach>
  </delete>
  
  <select id="findPortalList" resultType="com.goafanti.news.bo.NewsPortalList">
		select
			a.id,
			a.create_time as createTime,
			a.title,
			a.title_img as titleImg,
			a.type,
			a.hot,
			a.summary,
			a.source
		from news a
		join branch_office_info b
		on a.province_id = b.province_id
		where 1 =1
		<if test="type != null and type != 0" >
			and a.type = #{type,jdbcType=INTEGER}
		</if>
		<if test="website != null">
			and b.website = #{website,jdbcType=VARCHAR}
		</if>
		order by create_time desc
		limit #{pageNo,jdbcType=INTEGER}, #{pageSize,jdbcType=INTEGER}
	</select>
	
	<select id="findJmrhNewsList" parameterType="String" resultMap="SummaryResultMap">
		select 
			id,title,create_time 
		from 
			news
		where 
			jmrh_flag = 1 and type = #{type,jdbcType=INTEGER}
		order by 
			create_time desc
		limit 3;
  </select>
  <select id="findIndexNewsLists" resultMap="SummaryResultMap">
		select
		<include refid="Summary_Column_List" />
		from news
		where 
		type = 1
		order by create_time desc
		limit #{pageNo,jdbcType=INTEGER}, #{pageSize,jdbcType=INTEGER}
  </select>
</mapper>