article-mapper.xml 4.46 KB
<?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.cjs.site.dao.info.ArticleDao">
	
	<cache type="org.mybatis.caches.ehcache.EhcacheCache" />
	
	<sql id="article">
		article.id,title,article.create_at,article.update_at,article.sort_Time,title_image,category_id, summary, source, article.url
	</sql>
	
	<sql id="article_field">
		<include refid="article" />,category_id,keyword,summary,source,url,author,title_image,top,sort_time,attachment,
		publish_time,publish,page_url,content,article.create_by,article.update_by,click
	</sql>
	
	 <sql id="searchCondition">
	    where publish = 1
	    	and <![CDATA[UNIX_TIMESTAMP(publish_time) <= UNIX_TIMESTAMP() ]]>  
	    <if test="cids != null">
	    	and category_id in
	    	<foreach collection="cids" item="item" index="index" open="(" separator="," close=")">#{item}</foreach>
	    </if>
	    <if test="cid != null and cid != ''"> and category_id = #{cid} </if>
		<if test="title != null and title != ''"> 
			and title like CONCAT('%',#{title},'%') 
		</if>

	</sql>
	
	<!-- 目录展示  collection.jsp,article.jsp-->
	<select id="search" parameterType="map" resultType="ArticleInfo">
		select <include refid="article" />, r.name as name 
		from article 
		inner join article_category r on article.category_id = r.id 
		<include refid="searchCondition"/>
		<if test="type==0">
			<![CDATA[and article.create_at > 20190323]]>
		</if>
		order by article.sort_time desc
		limit #{start},#{limit}
	</select>
	
	<select id="searchTotal" parameterType="map" resultType="int">
		select count(*)  
		from article 
		inner join article_category r on article.category_id = r.id
		<include refid="searchCondition"/>
		<if test="type==0">
			<![CDATA[and article.create_at > 20190323]]>
		</if>
	</select>
	
	<select id="queryById" parameterType="java.lang.Integer" resultType="ArticleInfo">
		select title, content, author, sort_time, source,  r.name as name 
		from article 
		inner join article_category r on article.category_id = r.id 
	    where article.id = #{id} 
	</select>
	
	<select id="searchParentNameById" parameterType="java.lang.Integer" resultType="ArticleInfo">
		select id,name 
	    from article_category
	    where id = (select parent_id from article_category where id=#{id})
	</select>
	
	<select id="searchChilrendNameById" parameterType="java.lang.Integer" resultType="ArticleInfo">
		select id,name 
		from article_category 
		where parent_id = #{parentid} and publish = 1
	</select>
	
	<select  id="searchPreArticle"   parameterType="map" resultType="ArticleInfo">
		select article.id, article.title
		from article 
		inner join article_category r on article.category_id = r.id  
	    where <![CDATA[article.id < #{id} ]]> and r.parent_id = #{parentid} 
	    	and  publish = 1 and <![CDATA[UNIX_TIMESTAMP(publish_time) <= UNIX_TIMESTAMP() ]]>
		order by article.id desc
		limit 1
	</select>
	
	<select  id="searchNextArticle"  parameterType="map" resultType="ArticleInfo">
	    select article.id,article.title
		from article 
		inner join article_category r on article.category_id=r.id  
	    where <![CDATA[article.id > #{id} ]]> and r.parent_id = #{parentid}
	    	and publish = 1 and <![CDATA[UNIX_TIMESTAMP(publish_time) <= UNIX_TIMESTAMP() ]]>
		limit 1
	</select>
	
	<select id="searchYuantai"   parameterType="int" resultType="ArticleInfo">
	    select <include refid="article_field" /> 
		from article 
		where category_id = #{categoryId} and publish = 1
	</select>
	
	<select id="searchArticleInfo" resultType="ArticleInfo">
	    select article.id,article.title,article.sort_time 
		from article 
		where id in (select article_id from article_entrust where entrust_id = #{entrustId}) 
			and publish = 1
		order by id 
	</select>
	
	<select id="searchOneNew" resultType="ArticleInfo">
		select <include refid="article" />, r.name as name 
		from article 
		inner join article_category r on article.category_id = r.id 
		where category_id = 25 and publish = 1
		order by article.id desc
		limit 1
	</select>
	
	<select id="queryByCategoryId" parameterType="map"  resultType="ArticleInfo">
	    select <include refid="article" />
	    from article
	    where category_id = #{categoryId} and publish = 1
	    order by sort_time desc
	    <include refid="common.pageLimit" />
	</select>
	
	<select id="queryTotalByCategoryId" parameterType="map"  resultType="int">
	    select count(*)
	    from article
	    where category_id = #{categoryId} and publish = 1
	</select>
</mapper>