Skip to content

Commit 52d11d2

Browse files
author
且吟且行
committed
新增对uuid类型字段的支持;
washmore
1 parent df1cdb3 commit 52d11d2

File tree

8 files changed

+107
-7
lines changed

8 files changed

+107
-7
lines changed

autocode.core/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>autocode</artifactId>
77
<groupId>tech.washmore</groupId>
8-
<version>1.0.6-SNAPSHOT</version>
8+
<version>1.0.7-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>autocode.core</artifactId>

autocode.core/src/main/java/tech/washmore/autocode/core/generator/mysql/MysqlAbstractDaoClassGenerator.java

+30
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ private void generateBaseDao(TableModel tm) throws IOException {
115115
case selectByPrimaryKey:
116116
sb.append(appendSelectByPrimaryKey(tm));
117117
break;
118+
case selectByUuid:
119+
sb.append(appendSelectByUuid(tm));
120+
break;
118121
case selectByExample:
119122
sb.append(appendSelectByExample(tm));
120123
break;
@@ -179,6 +182,33 @@ public String appendSelectByExample(TableModel tm) {
179182
return sb.toString();
180183
}
181184

185+
public String appendSelectByUuid(TableModel tm) {
186+
Config config = ConfigManager.getConfig();
187+
Model modelConfig = config.getModel();
188+
String uuid = modelConfig.getUuid();
189+
if (uuid == null || "".equals(uuid)) {
190+
return "";
191+
}
192+
ColumnModel uuidCol = null;
193+
for (ColumnModel cl : tm.getColumns()) {
194+
if (cl.getColumnName().equals(uuid)) {
195+
uuidCol = cl;
196+
break;
197+
}
198+
}
199+
if (uuidCol == null) {
200+
return "";
201+
}
202+
203+
StringBuffer sb = new StringBuffer();
204+
sb.append("\t").append(tm.getClsName()).append(" selectByUuid(")
205+
.append(uuidCol.getFieldType()).append(" ")
206+
.append(uuidCol.getFieldName())
207+
.append(");")
208+
.append(System.lineSeparator());
209+
return sb.toString();
210+
}
211+
182212
public String appendSelectByPrimaryKey(TableModel tm) {
183213
ColumnModel pk = tm.getPrimaryKey();
184214
if (pk == null) {

autocode.core/src/main/java/tech/washmore/autocode/core/generator/mysql/MysqlAbstractMapperXmlGenerator.java

+29
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ private void generateMapper(TableModel tm) throws IOException {
116116
case selectByPrimaryKey:
117117
sb.append(appendSelectByPrimaryKey(tm));
118118
break;
119+
case selectByUuid:
120+
sb.append(appendSelectByUuid(tm));
121+
break;
119122
case selectByExample:
120123
sb.append(appendSelectByExample(tm));
121124
break;
@@ -290,7 +293,33 @@ public String appendSelectByExample(TableModel tm) {
290293
sb.append("\t</select>").append(System.lineSeparator()).append(System.lineSeparator());
291294
return sb.toString();
292295
}
296+
public String appendSelectByUuid(TableModel tm) {
297+
Config config = ConfigManager.getConfig();
298+
Model modelConfig = config.getModel();
299+
String uuid = modelConfig.getUuid();
300+
if (uuid == null || "".equals(uuid)) {
301+
return "";
302+
}
303+
ColumnModel uuidCol = null;
304+
for (ColumnModel cl : tm.getColumns()) {
305+
if (cl.getColumnName().equals(uuid)) {
306+
uuidCol = cl;
307+
break;
308+
}
309+
}
310+
if (uuidCol == null) {
311+
return "";
312+
}
313+
StringBuffer sb = new StringBuffer();
314+
sb.append("\t<select id=\"selectByUuid\" resultMap=\"BaseResultMap\" parameterType=\"").append(uuidCol.getFieldType()).append("\">").append(System.lineSeparator());
315+
sb.append("\t\tSELECT").append(System.lineSeparator());
316+
sb.append("\t\t<include refid=\"Base_Column_List\"/>").append(System.lineSeparator());
317+
sb.append("\t\tFROM ").append(tm.getTbName()).append(System.lineSeparator());
293318

319+
sb.append("\t\tWHERE ").append(uuidCol.getColumnName()).append(" = #{").append(uuidCol.getFieldName()).append(",jdbcType=").append(uuidCol.getJdbcType()).append("}").append(System.lineSeparator());
320+
sb.append("\t</select>").append(System.lineSeparator()).append(System.lineSeparator());
321+
return sb.toString();
322+
}
294323
public String appendSelectByPrimaryKey(TableModel tm) {
295324
ColumnModel pk = tm.getPrimaryKey();
296325
if (pk == null) {

autocode.core/src/main/java/tech/washmore/autocode/core/generator/mysql/MysqlAbstractServiceClassGenerator.java

+34-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
import tech.washmore.autocode.model.mysql.TableModel;
1111
import tech.washmore.autocode.util.StringUtils;
1212

13-
import java.io.File;
14-
import java.io.FileOutputStream;
1513
import java.io.IOException;
16-
import java.io.OutputStream;
1714
import java.text.SimpleDateFormat;
1815
import java.util.Date;
1916
import java.util.List;
@@ -135,9 +132,13 @@ private void generateService(TableModel tm) throws IOException {
135132
case batchUpdateByPrimaryKeySelective:
136133
sb.append(appendBatchUpdateByPrimaryKeySelective(tm));
137134
break;
135+
138136
case selectByPrimaryKey:
139137
sb.append(appendSelectByPrimaryKey(tm));
140138
break;
139+
case selectByUuid:
140+
sb.append(appendSelectByUuid(tm));
141+
break;
141142
case selectByExample:
142143
sb.append(appendSelectByExample(tm));
143144
break;
@@ -215,6 +216,36 @@ private String appendSelectByExample(TableModel tm) {
215216
sb.append("\t}").append(System.lineSeparator()).append(System.lineSeparator());
216217
return sb.toString();
217218
}
219+
private String appendSelectByUuid(TableModel tm) {
220+
Config config = ConfigManager.getConfig();
221+
Model modelConfig = config.getModel();
222+
String uuid = modelConfig.getUuid();
223+
if (uuid == null || "".equals(uuid)) {
224+
return "";
225+
}
226+
ColumnModel uuidCol = null;
227+
for (ColumnModel cl : tm.getColumns()) {
228+
if (cl.getColumnName().equals(uuid)) {
229+
uuidCol = cl;
230+
break;
231+
}
232+
}
233+
if (uuidCol == null) {
234+
return "";
235+
}
236+
Dao dao = ConfigManager.getConfig().getDataFile().getDao();
237+
StringBuffer sb = new StringBuffer();
238+
sb.append("\tpublic ").append(tm.getClsName()).append(" selectByUuid(")
239+
.append(uuidCol.getFieldType()).append(" ")
240+
.append(uuidCol.getFieldName())
241+
.append(") {")
242+
.append(System.lineSeparator());
243+
sb.append("\t\treturn ").append(underline2Camel(tm.getVirtualTbName(), false) + dao.getSuffix()).append(".").append("selectByUuid(")
244+
.append(uuidCol.getFieldName())
245+
.append(");").append(System.lineSeparator());
246+
sb.append("\t}").append(System.lineSeparator()).append(System.lineSeparator());
247+
return sb.toString();
248+
}
218249

219250
private String appendSelectByPrimaryKey(TableModel tm) {
220251
ColumnModel pk = tm.getPrimaryKey();

autocode.core/src/main/java/tech/washmore/autocode/model/config/Model.java

+9
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@
33
public class Model {
44
private String packageName;
55
private String packagePath;
6+
private String uuid;
67
private boolean visitorWithDoc = false;
78
private boolean toString = true;
89

910
private String summary;
1011

12+
public String getUuid() {
13+
return uuid;
14+
}
15+
16+
public void setUuid(String uuid) {
17+
this.uuid = uuid;
18+
}
19+
1120
public String getSummary() {
1221
return summary;
1322
}

autocode.core/src/main/java/tech/washmore/autocode/model/enums/DataFileMethod.java

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public enum DataFileMethod {
2222
updateByPrimaryKeySelective,
2323
deleteByPrimaryKey,
2424

25+
selectByUuid,
2526
selectByPrimaryKey,
2627
selectByExample,
2728
countByExample;

maven-autocode-plugin/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<artifactId>autocode</artifactId>
55
<groupId>tech.washmore</groupId>
6-
<version>1.0.6-SNAPSHOT</version>
6+
<version>1.0.7-SNAPSHOT</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99
<artifactId>maven-autocode-plugin</artifactId>
@@ -38,7 +38,7 @@
3838
<dependency>
3939
<groupId>tech.washmore</groupId>
4040
<artifactId>autocode.core</artifactId>
41-
<version>1.0.6-SNAPSHOT</version>
41+
<version>1.0.7-SNAPSHOT</version>
4242
</dependency>
4343
<dependency>
4444
<groupId>org.apache.maven</groupId>

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>tech.washmore</groupId>
55
<artifactId>autocode</artifactId>
66
<packaging>pom</packaging>
7-
<version>1.0.6-SNAPSHOT</version>
7+
<version>1.0.7-SNAPSHOT</version>
88
<modules>
99
<module>autocode.core</module>
1010
<module>autocode.test</module>

0 commit comments

Comments
 (0)