forked from opentiny/tiny-engine-backend-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResourceMapper.xml
More file actions
301 lines (287 loc) · 11.1 KB
/
ResourceMapper.xml
File metadata and controls
301 lines (287 loc) · 11.1 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<?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.tinyengine.it.mapper.ResourceMapper">
<!-- 通用设置 -->
<!-- 通用查询列 -->
<sql id="Base_Column_List">
id
, app_id, platform_id, `name`, thumbnail_name, resource_url, thumbnail_url, hash, category, description, thumbnail_data, resource_data,
public_status, is_default, created_by, last_updated_by, created_time, last_updated_time, tenant_id, renter_id, site_id
</sql>
<!-- 通用条件列 -->
<sql id="ResourceByCondition">
<if test="appId!=null">
AND app_id = #{appId}
</if>
<if test="platformId!=null">
AND platform_id = #{platformId}
</if>
<if test="name!=null and name!=''">
AND `name` = #{name}
</if>
<if test="thumbnailName!=null and thumbnailName!=''">
AND thumbnail_name = #{thumbnailName}
</if>
<if test="resourceUrl!=null and resourceUrl!=''">
AND resource_url = #{resourceUrl}
</if>
<if test="hash!=null and hash!=''">
AND hash = #{hash}
</if>
<if test="thumbnailUrl!=null and thumbnailUrl!=''">
AND thumbnail_url = #{thumbnailUrl}
</if>
<if test="category!=null and category!=''">
AND category = #{category}
</if>
<if test="description!=null and description!=''">
AND description = #{description}
</if>
<if test="thumbnailData!=null and thumbnailData!=''">
AND thumbnail_data = #{thumbnailData}
</if>
<if test="resourceData!=null and resourceData!=''">
AND resource_data = #{resourceData}
</if>
<if test="publicStatus!=null">
AND public_status = #{publicStatus}
</if>
<if test="isDefault!=null">
AND is_default = #{isDefault}
</if>
<if test="createdBy!=null and createdBy!=''">
AND created_by = #{createdBy}
</if>
<if test="lastUpdatedBy!=null and lastUpdatedBy!=''">
AND last_updated_by = #{lastUpdatedBy}
</if>
<if test="createdTime!=null">
AND created_time = #{createdTime}
</if>
<if test="lastUpdatedTime!=null">
AND last_updated_time = #{lastUpdatedTime}
</if>
<if test="tenantId!=null and tenantId!=''">
AND tenant_id = #{tenantId}
</if>
<if test="renterId!=null and renterId!=''">
AND renter_id = #{renterId}
</if>
<if test="siteId!=null and siteId!=''">
AND site_id = #{siteId}
</if>
</sql>
<!-- 通用设置列 -->
<sql id="ResourceSetColumns">
<if test="appId!=null">
app_id = #{appId},
</if>
<if test="platformId!=null">
platform_id = #{platformId},
</if>
<if test="name!=null and name!=''">
`name` = #{name},
</if>
<if test="thumbnailName!=null and thumbnailName!=''">
thumbnail_name = #{thumbnailName},
</if>
<if test="resourceUrl!=null and resourceUrl!=''">
resource_url = #{resourceUrl},
</if>
<if test="thumbnailUrl!=null and thumbnailUrl!=''">
thumbnail_url = #{thumbnailUrl},
</if>
<if test="hash!=null and hash!=''">
hash = #{hash},
</if>
<if test="category!=null and category!=''">
category = #{category},
</if>
<if test="description!=null and description!=''">
description = #{description},
</if>
<if test="thumbnailData!=null and thumbnailData!=''">
thumbnail_data = #{thumbnailData},
</if>
<if test="resourceData!=null and resourceData!=''">
resource_data = #{resourceData},
</if>
<if test="publicStatus!=null">
public_status = #{publicStatus},
</if>
<if test="isDefault!=null">
is_default = #{isDefault},
</if>
<if test="createdBy!=null and createdBy!=''">
created_by = #{createdBy},
</if>
<if test="lastUpdatedBy!=null and lastUpdatedBy!=''">
last_updated_by = #{lastUpdatedBy},
</if>
<if test="createdTime!=null">
created_time = #{createdTime},
</if>
<if test="lastUpdatedTime!=null">
last_updated_time = #{lastUpdatedTime},
</if>
<if test="tenantId!=null and tenantId!=''">
tenant_id = #{tenantId},
</if>
<if test="renterId!=null and renterId!=''">
renter_id = #{renterId},
</if>
<if test="siteId!=null and siteId!=''">
site_id = #{siteId},
</if>
</sql>
<!-- 通用查询映射结果 -->
<resultMap id="ResourceMap" type="com.tinyengine.it.model.entity.Resource">
<id column="id" property="id"/>
<result column="app_id" property="appId"/>
<result column="platform_id" property="platformId"/>
<result column="name" property="name"/>
<result column="thumbnail_name" property="thumbnailName"/>
<result column="resource_url" property="resourceUrl"/>
<result column="thumbnail_url" property="thumbnailUrl"/>
<result column="hash" property="hash"/>
<result column="category" property="category"/>
<result column="description" property="description"/>
<result column="thumbnail_data" property="thumbnailData"/>
<result column="resource_data" property="resourceData"/>
<result column="public_status" property="publicStatus"/>
<result column="is_default" property="isDefault"/>
<result column="created_by" property="createdBy"/>
<result column="last_updated_by" property="lastUpdatedBy"/>
<result column="created_time" property="createdTime"/>
<result column="last_updated_time" property="lastUpdatedTime"/>
<result column="tenant_id" property="tenantId"/>
<result column="renter_id" property="renterId"/>
<result column="site_id" property="siteId"/>
</resultMap>
<!-- 查询表t_resource所有数据 -->
<select id="queryAllResource" resultMap="ResourceMap">
SELECT
<include refid="Base_Column_List"/>
FROM t_resource
</select>
<!-- 根据主键id查询表t_resource信息 -->
<select id="queryResourceById" resultMap="ResourceMap">
SELECT
<include refid="Base_Column_List"/>
FROM t_resource
<where>
id = #{id}
</where>
</select>
<!-- 根据条件查询表t_resource数据 -->
<select id="queryResourceByCondition" resultMap="ResourceMap">
SELECT
<include refid="Base_Column_List"/>
FROM t_resource
WHERE 1=1
<include refid="ResourceByCondition"/>
</select>
<!-- 根据分组appId查询表t_resource信息-->
<select id="findResourcesByAppId" resultMap="ResourceMap">
SELECT r.*
FROM t_resource r
left JOIN r_resource_group_resource rgr ON r.id = rgr.resource_id
left JOIN t_resource_group rg ON rgr.resource_group_id = rg.id
WHERE rg.app_id = #{appId}
GROUP BY r.id
</select>
<select id="findResourceByResourceGroupId" resultMap="ResourceMap">
SELECT r.* FROM t_resource r
LEFT JOIN r_resource_group_resource rgr on rgr.resource_id = r.id
LEFT JOIN t_resource_group rg ON rgr.resource_group_id = rg.id
<where>
<if test="resourceGroupId != null and resourceGroupId != ''">
AND rg.id = #{resourceGroupId}
</if>
<if test="createdBy != null and createdBy != ''">
AND r.created_by = #{createdBy}
</if>
</where>
GROUP BY r.id
</select>
<!-- 根据name或者description模糊查询表t_resource信息 -->
<select id="findResourcesByNameAndDes" resultMap="ResourceMap">
SELECT
<include refid="Base_Column_List"/>
FROM t_resource
<where>
<if test="name != null and name != ''">
name like concat('%',#{name},'%')
</if>
<if test="description != null and description != ''">
<if test="name != null and name != ''">
or description like concat('%',#{description},'%')
</if>
<if test="name == null or name == ''">
description like concat('%',#{description},'%')
</if>
</if>
</where>
</select>
<!-- 根据主键id删除表t_resource数据 -->
<delete id="deleteResourceById">
DELETE
FROM t_resource
WHERE id = #{id}
</delete>
<!-- 根据主键id更新表t_resource数据 -->
<update id="updateResourceById" parameterType="com.tinyengine.it.model.entity.Resource">
UPDATE t_resource
<set>
<include refid="ResourceSetColumns"/>
</set>
WHERE
id=#{id}
</update>
<!-- 新增表t_resource数据 -->
<insert id="createResource" useGeneratedKeys="true" keyProperty="id"
parameterType="com.tinyengine.it.model.entity.Resource">
INSERT INTO t_resource ( id
, app_id
, platform_id
, name
, thumbnail_name
, resource_url
, thumbnail_url
, hash
, category
, description
, thumbnail_data
, resource_data
, public_status
, is_default
, created_by
, last_updated_by
, created_time
, last_updated_time
, tenant_id
, renter_id
, site_id)
VALUES ( #{id}
, #{appId}
, #{platformId}
, #{name}
, #{thumbnailName}
, #{resourceUrl}
, #{thumbnailUrl}
, #{hash}
, #{category}
, #{description}
, #{thumbnailData}
, #{resourceData}
, #{publicStatus}
, #{isDefault}
, #{createdBy}
, #{lastUpdatedBy}
, #{createdTime}
, #{lastUpdatedTime}
, #{tenantId}
, #{renterId}
, #{siteId})
</insert>
</mapper>