139f57e0eea47aae9c06990576edb5fad100967a.svn-base
6.96 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
<?xml version="1.0" encoding="utf-8"?>
<template>
<name>mapper</name>
<filePath>src/main/resources/mappings/${lastPackageName}/${moduleName}/${subModuleName}</filePath>
<fileName>${ClassName}Dao.xml</fileName>
<content><![CDATA[
<?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="${packageName}.${moduleName}.dao<#if subModuleName != "">.${subModuleName}</#if>.${ClassName}Dao">
<#-- 输出字段列 -->
<sql id="${className}Columns">
<#assign columnField>
<#list table.columnList as c>
a.${c.name} AS "${c.javaFieldId}",
</#list>
<#list table.columnList as c>
<#if c.showType?? && c.showType == "userselect">
<#list c.javaFieldAttrs as a>
u${c_index + 1}.${a[1]} AS "${c.simpleJavaField}.${a[0]}",
</#list>
<#elseif c.showType?? && c.showType == "officeselect">
<#list c.javaFieldAttrs as a>
o${c_index + 1}.${a[1]} AS "${c.simpleJavaField}.${a[0]}",
</#list>
<#elseif c.showType?? && c.showType == "areaselect">
<#list c.javaFieldAttrs as a>
a${c_index + 1}.${a[1]} AS "${c.simpleJavaField}.${a[0]}",
</#list>
</#if>
<#-- 父表关联字段 -->
<#if table.parentExists && table.parentTableFk == c.name>
<#list c.javaFieldAttrs as a>
b.${a[1]} AS "${c.simpleJavaField}.${a[0]}",
</#list>
</#if>
</#list>
</#assign>
${columnField?substring(0, columnField?last_index_of(","))}
</sql>
<#-- 输出字段关联表 -->
<sql id="${className}Joins">
<#-- 关联父表 -->
<#if table.parentExists>
LEFT JOIN ${table.parent.name} b ON b.id = a.${table.parentTableFk}
</#if>
<#-- 关联系统表 -->
<#list table.columnList as c>
<#if c.showType?? && c.showType == "userselect">
LEFT JOIN sys_user u${c_index + 1} ON u${c_index + 1}.id = a.${c.name}
<#elseif c.showType?? && c.showType == "officeselect">
LEFT JOIN sys_office o${c_index + 1} ON o${c_index + 1}.id = a.${c.name}
<#elseif c.showType?? && c.showType == "areaselect">
LEFT JOIN sys_area a${c_index + 1} ON a${c_index + 1}.id = a.${c.name}
</#if>
</#list>
</sql>
<select id="get" resultType="${ClassName}">
SELECT
<include refid="${className}Columns"/>
FROM ${table.name} a
<include refid="${className}Joins"/>
WHERE a.id = ${"#"}{id}
</select>
<select id="findList" resultType="${ClassName}">
SELECT
<include refid="${className}Columns"/>
FROM ${table.name} a
<include refid="${className}Joins"/>
<where>
<#if table.delFlagExists>a.del_flag = ${"#"}{DEL_FLAG_NORMAL}</#if>
<#list table.columnList as c>
<#if (c.isQuery?? && c.isQuery == "1") || (table.parentExists && table.parentTableFk == c.name) || c.javaFieldId == 'parent.id' || c.javaFieldId == 'parentIds'>
<#if c.queryType ?? && c.queryType == 'between'>
<if test="begin${c.simpleJavaField?cap_first} != null and end${c.simpleJavaField?cap_first} != null <#if c.simpleJavaField != c.javaFieldId>and begin${c.javaFieldId?cap_first} != null and end${c.javaFieldId?cap_first} != null </#if>and begin${c.javaFieldId?cap_first} != '' and end${c.javaFieldId?cap_first} != ''">
<#else>
<if test="${c.simpleJavaField} != null<#if c.simpleJavaField != c.javaFieldId> and ${c.javaFieldId} != null</#if> and ${c.javaFieldId} != ''">
</#if>
<#if c.queryType ?? && c.queryType == 'between'>
AND a.${c.name} BETWEEN ${"#"}{begin${c.simpleJavaField?cap_first}} AND ${"#"}{end${c.simpleJavaField?cap_first}}
<#elseif c.queryType ?? && c.queryType == 'like'>
AND a.${c.name} LIKE
<if test="dbName == 'oracle'">'%'||${"#"}{${c.javaFieldId}}||'%'</if>
<if test="dbName == 'mssql'">'%'+${"#"}{${c.javaFieldId}}+'%'</if>
<if test="dbName == 'mysql'">concat('%',${"#"}{${c.javaFieldId}},'%')</if>
<#elseif c.queryType ?? && c.queryType == 'left_like'>
AND a.${c.name} LIKE
<if test="dbName == 'oracle'">'%'||${"#"}{${c.javaFieldId}}</if>
<if test="dbName == 'mssql'">'%'+${"#"}{${c.javaFieldId}}</if>
<if test="dbName == 'mysql'">concat('%',${"#"}{${c.javaFieldId}})</if>
<#elseif c.queryType ?? && c.queryType == 'right_like'>
AND a.${c.name} LIKE
<if test="dbName == 'oracle'">${"#"}{${c.javaFieldId}}||'%'</if>
<if test="dbName == 'mssql'">${"#"}{${c.javaFieldId}}+'%'</if>
<if test="dbName == 'mysql'">concat(${"#"}{${c.javaFieldId}},'%')</if>
<#else>
AND a.${c.name} ${c.queryType} ${"#"}{${c.javaFieldId}}
</#if>
</if>
</#if>
</#list>
</where>
<#list table.columnList as c>
<#if c.name == 'sort'>
ORDER BY a.sort ASC
</#if>
</#list>
</select>
<select id="findAllList" resultType="${ClassName}">
SELECT
<include refid="${className}Columns"/>
FROM ${table.name} a
<include refid="${className}Joins"/>
<where>
<#if table.delFlagExists>a.del_flag = ${"#"}{DEL_FLAG_NORMAL}</#if>
</where>
<#list table.columnList as c>
<#if c.name == 'sort'>
ORDER BY a.sort ASC
</#if>
</#list>
</select>
<select id="findByParentIdsLike" resultType="${ClassName}">
SELECT
a.id,
a.parent_id AS "parent.id",
a.parent_ids
FROM ${table.name} a
<include refid="${className}Joins"/>
<where>
<#if table.delFlagExists>a.del_flag = ${"#"}{DEL_FLAG_NORMAL}</#if>
AND a.parent_ids LIKE ${"#"}{parentIds}
</where>
<#list table.columnList as c>
<#if c.name == 'sort'>
ORDER BY a.sort ASC
</#if>
</#list>
</select>
<insert id="insert">
INSERT INTO ${table.name}(
<#assign insertField>
<#list table.columnList as c>
<#if c.isInsert?? && c.isInsert == "1">
${c.name},
</#if>
</#list>
</#assign>
${insertField?substring(0, insertField?last_index_of(","))}
) VALUES (
<#assign insertJavaField>
<#list table.columnList as c>
<#if c.isInsert?? && c.isInsert == "1">
${"#"}{${c.javaFieldId}},
</#if>
</#list>
</#assign>
${insertJavaField?substring(0, insertJavaField?last_index_of(","))}
)
</insert>
<update id="update">
UPDATE ${table.name} SET
<#assign updateField>
<#list table.columnList as c>
<#if c.isEdit?? && c.isEdit == "1">
${c.name} = ${"#"}{${c.javaFieldId}},
</#if>
</#list>
</#assign>
${updateField?substring(0, updateField?last_index_of(","))}
WHERE id = ${"#"}{id}
</update>
<update id="updateParentIds">
UPDATE ${table.name} SET
parent_id = ${"#"}{parent.id},
parent_ids = ${"#"}{parentIds}
WHERE id = ${"#"}{id}
</update>
<update id="delete">
<#if table.delFlagExists>
UPDATE ${table.name} SET
del_flag = ${"#"}{DEL_FLAG_DELETE}
<#else>
DELETE FROM ${table.name}
</#if>
<#if table.parentExists>
<#list table.columnList as c>
<#if table.parentTableFk == c.name>
<choose>
<when test="id !=null and id != ''">
WHERE id = ${"#"}{id}
</when>
<otherwise>
WHERE ${table.parentTableFk} = ${"#"}{${c.javaFieldId}}
</otherwise>
</choose>
</#if>
</#list>
<#else>
WHERE id = ${"#"}{id} OR parent_ids LIKE '%,'||${"#"}{id}||',%'
</#if>
</update>
</mapper>]]>
</content>
</template>