article-mapper.xml
4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?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>