|
10 | 10 | import tech.washmore.autocode.model.mysql.TableModel;
|
11 | 11 | import tech.washmore.autocode.util.StringUtils;
|
12 | 12 |
|
13 |
| -import java.io.File; |
14 |
| -import java.io.FileOutputStream; |
15 | 13 | import java.io.IOException;
|
16 |
| -import java.io.OutputStream; |
17 | 14 | import java.text.SimpleDateFormat;
|
18 | 15 | import java.util.Date;
|
19 | 16 | import java.util.List;
|
@@ -135,9 +132,13 @@ private void generateService(TableModel tm) throws IOException {
|
135 | 132 | case batchUpdateByPrimaryKeySelective:
|
136 | 133 | sb.append(appendBatchUpdateByPrimaryKeySelective(tm));
|
137 | 134 | break;
|
| 135 | + |
138 | 136 | case selectByPrimaryKey:
|
139 | 137 | sb.append(appendSelectByPrimaryKey(tm));
|
140 | 138 | break;
|
| 139 | + case selectByUuid: |
| 140 | + sb.append(appendSelectByUuid(tm)); |
| 141 | + break; |
141 | 142 | case selectByExample:
|
142 | 143 | sb.append(appendSelectByExample(tm));
|
143 | 144 | break;
|
@@ -215,6 +216,36 @@ private String appendSelectByExample(TableModel tm) {
|
215 | 216 | sb.append("\t}").append(System.lineSeparator()).append(System.lineSeparator());
|
216 | 217 | return sb.toString();
|
217 | 218 | }
|
| 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 | + } |
218 | 249 |
|
219 | 250 | private String appendSelectByPrimaryKey(TableModel tm) {
|
220 | 251 | ColumnModel pk = tm.getPrimaryKey();
|
|
0 commit comments