-
Notifications
You must be signed in to change notification settings - Fork 232
Expand file tree
/
Copy pathAppBuilderAppMapper.xml
More file actions
343 lines (326 loc) · 12.9 KB
/
AppBuilderAppMapper.xml
File metadata and controls
343 lines (326 loc) · 12.9 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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<?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="modelengine.fit.jober.aipp.mapper.AppBuilderAppMapper">
<resultMap id="BaseResultMap" type="modelengine.fit.jober.aipp.po.AppBuilderAppPo">
<result column="id" property="id"/>
<result column="name" property="name"/>
<result column="app_suite_id" property="appSuiteId"/>
<result column="config_id" property="configId"/>
<result column="flow_graph_id" property="flowGraphId"/>
<result column="tenant_id" property="tenantId"/>
<result column="type" property="type"/>
<result column="version" property="version"/>
<result column="create_by" property="createBy"/>
<result column="create_at" property="createAt"/>
<result column="update_by" property="updateBy"/>
<result column="update_at" property="updateAt"/>
<result column="attributes" property="attributes"/>
<result column="state" property="state"/>
<result column="app_built_type" property="appBuiltType"/>
<result column="app_category" property="appCategory"/>
<result column="app_type" property="appType"/>
<result column="is_active" property="isActive"/>
<result column="status" property="status"/>
<result column="unique_name" property="uniqueName"/>
<result column="publish_at" property="publishAt"/>
<result column="app_id" property="appId"/>
<result column="user_group_id" property="userGroupId"/>
</resultMap>
<sql id="Base_Column_List">
id
, name, app_id, app_suite_id, config_id, flow_graph_id, tenant_id, type, version, attributes, path, state, app_built_type, app_category, create_by, create_at, update_by, update_at, is_active, status, unique_name, publish_at, app_type, user_group_id
</sql>
<sql id="appTypeCondition">
<choose>
<when test="cond.appType != null and cond.appType != ''">
app_type = #{cond.appType}
</when>
<when test="cond.type != null and cond.type == 'template'">
app_type is not null and app_type != ''
</when>
<otherwise>
1=1
</otherwise>
</choose>
</sql>
<select id="selectWithId" resultMap="BaseResultMap"
resultType="modelengine.fit.jober.aipp.po.AppBuilderAppPo">
select
<include refid="Base_Column_List"/>
from app_builder_app
where id = #{id}
and is_deleted = 0
</select>
<select id="selectWithPath" resultMap="BaseResultMap"
resultType="modelengine.fit.jober.aipp.po.AppBuilderAppPo">
select
<include refid="Base_Column_List"/>
from app_builder_app
where path = #{path}
and state = 'active'
and is_deleted = 0
order by update_at desc
limit 1
</select>
<select id="selectByAppSuiteId" resultMap="BaseResultMap"
resultType="modelengine.fit.jober.aipp.po.AppBuilderAppPo">
select
<include refid="Base_Column_List"/>
from app_builder_app
where app_suite_id = #{appSuiteId}
and is_deleted = 0
</select>
<select id="selectWithTenantId" resultMap="BaseResultMap"
resultType="modelengine.fit.jober.aipp.po.AppBuilderAppPo">
select
<include refid="Base_Column_List"/>
from app_builder_app
where tenant_id = #{tenantId}
and is_deleted = 0
</select>
<select id="selectByTenantIdWithPage" resultMap="BaseResultMap"
resultType="modelengine.fit.jober.aipp.po.AppBuilderAppPo">
select
<include refid="Base_Column_List"/>
from (
SELECT DISTINCT ON ( "app_suite_id" ) * FROM app_builder_app where tenant_id = #{tenantId} and is_deleted = 0
<if test="cond.type != null">
and type = #{cond.type}
</if>
<if test="cond.appCategory != null">
and app_category = #{cond.appCategory}
</if>
<if test="cond.state != null">
<choose>
<when test="cond.state == 'active'">
and state = #{cond.state}
</when>
<when test="cond.state == 'inactive'">
and state = #{cond.state}
</when>
</choose>
</if>
<if test="cond != null and cond.name != null and cond.name != ''">
and name ilike '%\' || #{cond.name} || '%' ESCAPE '\'
</if>
<if test="cond.ids != null and cond.ids.size() > 0">
and id in
<foreach collection="cond.ids" item="id" index="index" open="(" separator="," close=")">
#{id}
</foreach>
</if>
<if test="cond.excludeNames != null and !cond.excludeNames.isEmpty()">
AND name NOT IN
<foreach item="excludeName" collection="cond.excludeNames" open="(" separator="," close=")">
#{excludeName}
</foreach>
</if>
<if test="cond.userGroupId == null and cond.createBy != null">
and create_by = #{cond.createBy}
</if>
<if test='cond.userGroupId != null'>
and (user_group_id = #{cond.userGroupId} or user_group_id = '*')
</if>
ORDER BY
"app_suite_id", update_at DESC
) as sub
WHERE <include refid="appTypeCondition"/>
ORDER BY update_at DESC offset #{offset} limit #{limit}
</select>
<select id="selectWithCondition" resultMap="BaseResultMap"
resultType="modelengine.fit.jober.aipp.po.AppBuilderAppPo">
select
<include refid="Base_Column_List"/>
from app_builder_app
<where>
true and is_deleted = 0
<if test="tenantId!=null">
and tenant_id = #{tenantId}
</if>
<if test="name!=null">
and name = #{name}
</if>
<if test="appSuiteId!=null">
and app_suite_id = #{appSuiteId}
</if>
<if test="type!=null">
and type = #{type}
</if>
<if test="ids != null and ids.size() > 0">
and id in
<foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
#{id}
</foreach>
</if>
<if test="appType != null and appType != ''">
and app_type = #{appType}
</if>
<if test="orderBy!=null and sort!=null">
ORDER BY ${orderBy} ${sort}
</if>
<if test="offset!=null and limit!=null">
offset #{offset} limit #{limit}
</if>
</where>
</select>
<select id="countByTenantId" resultType="long">
select count(*) from (
select
DISTINCT ON (app_suite_id) *
from app_builder_app
where tenant_id = #{tenantId} and is_deleted = 0
<if test="cond.type != null">
and type = #{cond.type}
</if>
<if test="cond.state != null">
<choose>
<when test="cond.state == 'active'">
and state = #{cond.state}
</when>
<when test="cond.state == 'inactive'">
and state != 'active'
</when>
</choose>
</if>
<if test="cond.name != null and cond.name != ''">
and name ilike '%\' || #{cond.name} || '%' ESCAPE '\'
</if>
<if test="cond.excludeNames != null and !cond.excludeNames.isEmpty()">
AND name NOT IN
<foreach item="excludeName" collection="cond.excludeNames" open="(" separator="," close=")">
#{excludeName}
</foreach>
</if>
<if test="cond.appCategory != null">
and app_category = #{cond.appCategory}
</if>
<if test="cond.userGroupId == null and cond.createBy != null">
and create_by = #{cond.createBy}
</if>
<if test='cond.userGroupId != null'>
and (user_group_id = #{cond.userGroupId} or user_group_id = '*')
</if>
ORDER BY app_suite_id, update_at DESC
) as latest_records WHERE <include refid="appTypeCondition"/>;
</select>
<insert id="insertOne" parameterType="modelengine.fit.jober.aipp.po.AppBuilderAppPo">
insert into app_builder_app (
<include refid="Base_Column_List"/>
)
values (#{id}, #{name}, #{appId}, #{appSuiteId}, #{configId}, #{flowGraphId}, #{tenantId}, #{type}, #{version}, #{attributes}::jsonb,
#{path}, #{state}, #{appBuiltType}, #{appCategory}, #{createBy}, #{createAt}, #{updateBy}, #{updateAt}, #{isActive}, #{status}, #{uniqueName}, #{publishAt}, #{appType}, #{userGroupId})
</insert>
<update id="updateOne" parameterType="modelengine.fit.jober.aipp.po.AppBuilderAppPo">
update app_builder_app
<set>
<if test="name != null">
name = #{name},
</if>
<if test="appId != null">
app_id = #{appId},
</if>
<if test="appSuiteId != null">
app_suite_id = #{appSuiteId},
</if>
<if test="configId != null">
config_id = #{configId},
</if>
<if test="flowGraphId != null">
flow_graph_id = #{flowGraphId},
</if>
<if test="tenantId != null">
tenant_id = #{tenantId},
</if>
<if test="type != null">
type = #{type},
</if>
<if test="version != null">
version = #{version},
</if>
<if test="attributes != null">
attributes = #{attributes}::jsonb,
</if>
<if test="state != null">
state = #{state},
</if>
<if test="appBuiltType != null">
app_built_type = #{appBuiltType},
</if>
<if test="createBy != null">
create_by = #{createBy},
</if>
<if test="createAt != null">
create_at = #{createAt},
</if>
<if test="updateBy != null">
update_by = #{updateBy},
</if>
<if test="updateAt != null">
update_at = #{updateAt},
</if>
<if test="path != null">
path = #{path},
</if>
<if test="appType != null">
app_type = #{appType},
</if>
<if test="isActive != null">
is_active = #{isActive},
</if>
<if test="status != null">
status = #{status},
</if>
<if test="uniqueName != null">
unique_name = #{uniqueName},
</if>
<if test="publishAt != null">
publish_at = #{publishAt}
</if>
</set>
where id = #{id}
</update>
<select id="selectWithStoreId" resultMap="BaseResultMap"
resultType="modelengine.fit.jober.aipp.po.AppBuilderAppPo">
select
<include refid="Base_Column_List"/>
from app_builder_app
where attributes ->> 'store_id' in
<foreach collection="storeIds" item="id" index="index" open="(" close=")" separator=",">
#{id}
</foreach>
and is_deleted = 0
</select>
<update id="updateAppWithStoreId" parameterType="modelengine.fit.jober.aipp.po.AppBuilderAppPo">
update app_builder_app
set attributes = jsonb_set(attributes::jsonb, '{store_id}',to_jsonb(#{uniqueName}), true)
where id = #{id} and version = #{version}
</update>
<update id="delete" parameterType="java.util.List">
UPDATE app_builder_app
set is_deleted = 1
where id in
<foreach collection="appIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<select id="selectWithSimilarName" resultType="java.lang.String">
SELECT DISTINCT name FROM app_builder_app WHERE name LIKE #{target}||'%' AND is_deleted = 0
ORDER BY name ASC
</select>
<select id="checkPathExists" resultType="boolean">
select count(*) > 0
from app_builder_app
where path = #{path}
and is_deleted = 0
</select>
<update id="updateGuestMode">
UPDATE app_builder_app
SET attributes = jsonb_set(
COALESCE(attributes::jsonb, '{}'::jsonb),
'{allow_guest}',
to_jsonb(#{isGuest}),
true
)::json
WHERE path = #{path}
</update>
</mapper>