article-mapper.xml
4.87 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?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>