-
Notifications
You must be signed in to change notification settings - Fork 232
Expand file tree
/
Copy pathMetaMapper.xml
More file actions
161 lines (149 loc) · 6.16 KB
/
MetaMapper.xml
File metadata and controls
161 lines (149 loc) · 6.16 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
<?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.task_new.mapper.MetaMapper">
<resultMap id="BaseResultMap" type="modelengine.fit.task_new.po.MetaPo">
<result column="id" property="id"/>
<result column="name" property="name"/>
<result column="version" property="version"/>
<result column="template_id" property="templateId"/>
<result column="tenant_id" property="tenantId"/>
<result column="attributes" property="attributes"/>
<result column="created_by" property="createdBy"/>
<result column="created_at" property="createdAt"/>
<result column="updated_by" property="updatedBy"/>
<result column="updated_at" property="updatedAt"/>
</resultMap>
<sql id="Base_Column_List">
id, name, version, template_id, tenant_id, attributes, created_by, created_at, updated_by, updated_at
</sql>
<insert id="insertOne" parameterType="modelengine.fit.task_new.po.MetaPo">
insert into task_new
(<include refid="Base_Column_List"/>)
values (#{id}, #{name}, #{version}, #{templateId}, #{tenantId}, #{attributes}::jsonb, #{createdBy},
#{createdAt},
#{updatedBy}, #{updatedAt})
</insert>
<update id="updateOne" parameterType="modelengine.fit.task_new.po.MetaPo">
update task_new
<set>
<if test="name != null">
name = #{name},
</if>
<if test="version != null">
version = #{version},
</if>
<if test="attributes != null">
attributes = #{attributes}::jsonb,
</if>
<if test="updatedBy != null">
updated_by = #{updatedBy},
</if>
<if test="updatedAt != null">
updated_at = #{updatedAt}
</if>
</set>
where id = #{id}
</update>
<update id="deleteOne">
update task_new
set is_deleted = 1
where id = #{id}
</update>
<select id="retrieveByName" resultMap="BaseResultMap" resultType="modelengine.fit.task_new.po.MetaPo">
select <include refid="Base_Column_List"/>
from task_new
where name = #{name}
and is_deleted = 0
limit 1
</select>
<select id="retrieve" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from task_new
where id = #{id}
and is_deleted = 0
</select>
<sql id="whereCondition">
<where>
is_deleted = 0
<if test="metaFilter.metaIds != null and !metaFilter.metaIds.isEmpty()">
and template_id in
<foreach item="metaId" collection="metaFilter.metaIds" open="(" separator="," close=")">
#{metaId}
</foreach>
</if>
<if test="metaFilter.versionIds != null and !metaFilter.versionIds.isEmpty()">
and id in
<foreach item="versionId" collection="metaFilter.versionIds" open="(" separator="," close=")">
#{versionId}
</foreach>
</if>
<if test="metaFilter.names != null and !metaFilter.names.isEmpty()">
and name in
<foreach item="name" collection="metaFilter.names" open="(" separator="," close=")">
#{name}
</foreach>
</if>
<if test="metaFilter.creators != null and !metaFilter.creators.isEmpty()">
and created_by in
<foreach item="creator" collection="metaFilter.creators" open="(" separator="," close=")">
#{creator}
</foreach>
</if>
<if test="metaFilter.versions != null and !metaFilter.versions.isEmpty()">
and version in
<foreach item="version" collection="metaFilter.versions" open="(" separator="," close=")">
#{version}
</foreach>
</if>
<if test="attributes != null and attributes.size() > 0">
<foreach collection="attributes" item="value" index="key" separator=" AND " open=" AND ">
attributes ->> '${key}' = #{value}
</foreach>
</if>
</where>
</sql>
<sql id="orderBySql">
<if test="orderBy != null">
order by
<choose>
<when test="orderBy.field == 'created_at'">created_at</when>
<when test="orderBy.field == 'updated_at'">updated_at</when>
</choose>
<choose>
<when test="orderBy.direction == 'desc'">DESC</when>
<otherwise>ASC</otherwise>
</choose>
</if>
</sql>
<select id="list" resultMap="BaseResultMap" resultType="modelengine.fit.task_new.po.MetaPo">
select <include refid="Base_Column_List"/>
from task_new
<include refid="whereCondition"/>
<include refid="orderBySql"/>
offset #{offset} limit #{limit}
</select>
<select id="getCount" resultType="int">
select count(*)
from task_new
<include refid="whereCondition"/>
</select>
<select id="listLatest" resultMap="BaseResultMap" resultType="modelengine.fit.task_new.po.MetaPo">
select s.id, s.name, s.version, s.template_id, s.tenant_id, s.attributes, s.created_by, s.created_at, s.updated_by, s.updated_at
from
(select <include refid="Base_Column_List"/>, row_number()
over (partition by template_id <include refid="orderBySql"/>) as group_idx
from task_new
<include refid="whereCondition"/>) s
where s.group_idx=1
offset #{offset} limit #{limit}
</select>
<select id="getLatestCount" resultType="int">
select count(*)
from
(select <include refid="Base_Column_List"/>, row_number()
over (partition by template_id <include refid="orderBySql"/>) as group_idx
from task_new
<include refid="whereCondition"/>) s
where s.group_idx=1
</select>
</mapper>