article-mapper.xml 4.87 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.cms.dao.site.ArticleDao">

	<sql id="article">
		article.id, title, top, top_sort, article.create_at, article.update_at, article.update_by,
		title_image, sign, sign_time, publish_time, summary, publish, sort_time
	</sql>

	<sql id="article_field">
		<include refid="article" />
		,category_id, keyword, summary, source, article.url, author, attachment,
		 page_url, content, article.create_by, click
	</sql>
	
     <sql id="searchCondition">
     	where 1 = 1
		<if test="title != null and title != ''">
			and title like CONCAT('%',#{title},'%')
		</if>
		<if test="categoryId != null and categoryId != ''">
			and category_id = #{categoryId}
		</if>
		<if test="publish != null and publish != ''">
			and publish = #{publish}
		</if>
		<if test="beginDate != null and endDate == null">
			and article.create_at > = #{beginDate}
		</if>
		<if test="endDate != null and beginDate == null">
			and DATE_ADD(#{endDate},INTERVAL +1 day)> =
			article.create_at
		</if>
		<if test="endDate != null and beginDate != null">
			and article.create_at between #{beginDate} and
			DATE_ADD(#{endDate}, INTERVAL +1 day)
		</if>
	</sql>

	<select id="selectArticleList" parameterType="java.util.Map" resultType="java.util.Map">
		select <include refid="article" /> ,r.name as name
		from article 
		inner join article_category r on article.category_id = r.id
		<include refid="searchCondition" />
		order by article.id desc
		<include refid="common.pageLimit" />
	</select>
	
	<select id="selectArticleCount" parameterType="java.util.Map" resultType="java.lang.Integer">
		select count(1)
		from article 
		inner join article_category r on article.category_id = r.id
		<include refid="searchCondition" />
	</select>
	
	<insert id="addArticle" parameterType="ArticleInfo" useGeneratedKeys="true" keyProperty="id">
		insert into article(category_id, title, keyword, summary, source, url, author, title_image, 
			top, top_sort, sort_time, attachment, publish_time, publish, page_url, content, 
			create_by, create_at, update_by, update_at, sign, sign_time)
		values(#{categoryId}, #{title}, #{keyword}, #{summary}, #{source}, #{url}, #{author}, #{titleImage}, 
			#{top}, #{topSort}, #{sortTime}, #{attachment}, #{publishTime}, #{publish}, #{pageUrl}, 
			#{content}, #{createBy}, now(), #{updateBy}, now(), #{sign}, #{signTime})
	</insert>

	<select id="selectArticleOne" parameterType="java.util.Map" resultType="java.util.Map">
		select <include refid="article" /> ,r.name as name
		from article inner join article_category r on article.category_id = r.id
		where category_id = #{categoryId} and id = #{id}
	</select>

	<select id="getArticleInfo" parameterType="java.lang.Integer"
		resultType="ArticleInfo">
		select
		<include refid="article_field" />
		,r.name as name,r.parent_id as parentId
		from article inner join article_category r
		on article.category_id = r.id
		where article.id = #{id}
	</select>

	<update id="updateArticle" parameterType="ArticleInfo">
		update article set
		category_id =
		#{categoryId},title=#{title},keyword=#{keyword},summary=#{summary},source=#{source},
		url=#{url},author=#{author},title_image=#{titleImage},top=#{top},top_sort=#{topSort},sort_time=#{sortTime},attachment=#{attachment},
		publish_time=#{publishTime},publish=#{publish},page_url=#{pageUrl},content=#{content},update_at=CURRENT_TIMESTAMP,
		update_by=#{updateBy},sign=#{sign},sign_time=#{signTime}
		where id= #{id}
	</update>

	<delete id="deleteArticle" parameterType="java.lang.String">
		delete from article
		where id = #{id}
	</delete>

	<select id="getCategory" parameterType="java.lang.Integer"
		resultType="java.util.Map">
		select id,name from article_category where parent_id =
		#{parentId} and enable = 1
	</select>

	<select id="getArticleById" parameterType="java.lang.Integer"
		resultType="ArticleInfo">
		select
		<include refid="article_field" />
		from article where id = #{id}
		order by id
	</select>

	<select id="serachSort" resultType="ArticleInfo">
		select sort_id,sort_name
		from sort
	</select>
	<update id="passArticle" parameterType="java.lang.Integer">
		update article set
		publish=1 where id=#{id}
	</update>

	<update id="downLine">
		update article set publish=0 where id = #{id}
	</update>

	<select id="searchById" parameterType="java.lang.Integer"
		resultType="ArticleInfo">
		select * from article where id = #{id};
	</select>

	<insert id="addArticle_entrust" parameterType="map">
		insert into article_entrust(article_id, entrust_id)
		values(#{id}, #{entrustId})
	</insert>

	<update id="deleteArticle_entrust" parameterType="int">
		delete from article_entrust where article_id = #{id}
	</update>

	<select id="selectArticle_entrust" resultType="ArticleInfo"
		parameterType="int">
		select entrust_id from article_entrust where article_id = #{id}
	</select>
</mapper>