b355cfb264e0849151e1b63205706cf8bcbb1cd6.svn-base
6.21 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<?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.thinkgem.jeesite.modules.cms.dao.ArticleDao">
<sql id="cmsArticleColumns">
a.id AS "id",
a.category_id AS "category.id",
a.title AS "title",
a.link AS "link",
a.color AS "color",
a.image AS "image",
a.keywords AS "keywords",
a.description AS "description",
a.weight AS "weight",
a.weight_date AS "weightDate",
a.hits AS "hits",
a.posid AS "posid",
a.custom_content_view AS "customContentView",
a.view_config AS "viewConfig",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag",
c.name AS "category.name",
u.name AS "user.name"
</sql>
<sql id="cmsArticleJoins">
JOIN cms_category c ON c.id = a.category_id
JOIN sys_office o ON o.id = c.office_id
JOIN sys_user u ON u.id = a.create_by
</sql>
<select id="get" resultType="Article">
SELECT
<include refid="cmsArticleColumns"/>
FROM cms_article a
<include refid="cmsArticleJoins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="Article">
SELECT
<include refid="cmsArticleColumns"/>
FROM cms_article a
<include refid="cmsArticleJoins"/>
<where>
a.del_flag = #{delFlag}
<if test="title != null and title != ''">
AND a.title LIKE
<if test="dbName == 'oracle'">'%'||#{title}||'%'</if>
<if test="dbName == 'mysql'">CONCAT('%', #{title}, '%')</if>
</if>
<if test="posid != null and posid != ''">
AND a.posid LIKE
<if test="dbName == 'oracle'">'%'||#{posid}||'%'</if>
<if test="dbName == 'mysql'">CONCAT('%', #{posid}, '%')</if>
</if>
<if test="category.id != null and category.id != ''">
AND (a.category_id = #{category.id}
<if test="category.parentIds != null and category.parentIds != ''">
or c.parent_ids like
<if test="dbName == 'oracle'">'%'||#{category.id}||'%'</if>
<if test="dbName == 'mysql'">CONCAT('%,', #{category.id}, ',%')</if>
</if>)
</if>
<if test="image != null and image != ''">
AND a.image = #{image}
</if>
<if test="createBy != null and createBy.id != null and createBy.id != ''">
AND a.create_by = #{createBy.id}
</if>
<!-- ${sqlMap.dsf}-->
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.weight DESC, a.update_date DESC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="Article">
SELECT
<include refid="cmsArticleColumns"/>
FROM cms_article a
<include refid="cmsArticleJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.weight DESC, a.update_date DESC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO cms_article(
id,
category_id,
title,
link,
color,
image,
keywords,
description,
weight,
weight_date,
hits,
posid,
custom_content_view,
view_config,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{category.id},
#{title},
#{link},
#{color},
#{image},
#{keywords},
#{description},
#{weight},
#{weightDate},
#{hits},
#{posid},
#{customContentView},
#{viewConfig},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE cms_article SET
category_id = #{category.id},
title = #{title},
link = #{link},
color = #{color},
image = #{image},
keywords = #{keywords},
description = #{description},
weight = #{weight},
weight_date = #{weightDate},
hits = #{hits},
posid = #{posid},
custom_content_view = #{customContentView},
view_config = #{viewConfig},
create_date = #{createDate},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks},
del_flag = #{delFlag}
WHERE id = #{id}
</update>
<update id="delete">
UPDATE cms_article SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id}
</update>
<select id="findByIdIn" resultType="Article">
SELECT
<include refid="cmsArticleColumns"/>
from cms_article a where
<where>
id in (${id});
</where>
</select>
<update id="updateExpiredWeight">
update cms_article SET
weight = 0
WHERE weight > 0 AND weight_date <
<if test="dbName == 'oracle'">sysdate</if>
<if test="dbName == 'mysql'">CURDATE()</if>
</update>
<update id="updateHitsAddOne">
update cms_article set
hits = hits+1
WHERE id = #{id}
</update>
<select id="findStats" resultType="Category">
select max(c.id) AS "id",
max(c.name) AS "name",
max(cp.id) AS "parent.id",
max(cp.name) AS "parent.name",
count(*) AS "cnt",
sum(a.hits) AS "hits",
max(a.update_date) as "updateDate",
max(o.id) AS "office.id",
max(o.name) AS "office.name"
FROM cms_article a
RIGHT JOIN cms_category c ON c.id = a.category_id
JOIN cms_category cp ON c.parent_id = cp.id
JOIN sys_office o ON o.id = c.office_id
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
AND c.site_id = #{site.id}
<if test="office.id != null and office.id != ''">
AND (c.office_id = #{office.id} OR o.parent_ids like
<if test="dbName == 'oracle'">'%'||#{office.id}||'%'</if>
<if test="dbName == 'mysql'">CONCAT('%', #{office.id}, '%')</if>)
</if>
<if test="beginDate != null and beginDate != ''">
AND a.update_date <![CDATA[ >= #{beginDate} ]]>
</if>
<if test="endDate != null and endDate != ''">
AND a.update_date <![CDATA[ <= #{endDate} ]]>
</if>
<if test="id != null and id != ''">
AND (c.id = #{id} OR c.parent_ids LIKE
<if test="dbName == 'oracle'">'%'||#{id}||'%'</if>
<if test="dbName == 'mysql'">CONCAT('%', #{id}, '%')</if>)
</if>
group by cp.sort, cp.id, c.sort, c.id
order by cp.sort, cp.id, c.sort, c.id
</where>
</select>
</mapper>