正在显示
22 个修改的文件
包含
596 行增加
和
35 行删除
| @@ -13,6 +13,9 @@ public class GenConstants | @@ -13,6 +13,9 @@ public class GenConstants | ||
| 13 | /** 树表(增删改查) */ | 13 | /** 树表(增删改查) */ |
| 14 | public static final String TPL_TREE = "tree"; | 14 | public static final String TPL_TREE = "tree"; |
| 15 | 15 | ||
| 16 | + /** 主子表(增删改查) */ | ||
| 17 | + public static final String TPL_SUB = "sub"; | ||
| 18 | + | ||
| 16 | /** 树编码字段 */ | 19 | /** 树编码字段 */ |
| 17 | public static final String TREE_CODE = "treeCode"; | 20 | public static final String TREE_CODE = "treeCode"; |
| 18 | 21 |
| @@ -63,10 +63,12 @@ public class GenController extends BaseController | @@ -63,10 +63,12 @@ public class GenController extends BaseController | ||
| 63 | public AjaxResult getInfo(@PathVariable Long talbleId) | 63 | public AjaxResult getInfo(@PathVariable Long talbleId) |
| 64 | { | 64 | { |
| 65 | GenTable table = genTableService.selectGenTableById(talbleId); | 65 | GenTable table = genTableService.selectGenTableById(talbleId); |
| 66 | + List<GenTable> tables = genTableService.selectGenTableAll(); | ||
| 66 | List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(talbleId); | 67 | List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(talbleId); |
| 67 | Map<String, Object> map = new HashMap<String, Object>(); | 68 | Map<String, Object> map = new HashMap<String, Object>(); |
| 68 | map.put("info", table); | 69 | map.put("info", table); |
| 69 | map.put("rows", list); | 70 | map.put("rows", list); |
| 71 | + map.put("tables", tables); | ||
| 70 | return AjaxResult.success(map); | 72 | return AjaxResult.success(map); |
| 71 | } | 73 | } |
| 72 | 74 |
| @@ -28,11 +28,17 @@ public class GenTable extends BaseEntity | @@ -28,11 +28,17 @@ public class GenTable extends BaseEntity | ||
| 28 | @NotBlank(message = "表描述不能为空") | 28 | @NotBlank(message = "表描述不能为空") |
| 29 | private String tableComment; | 29 | private String tableComment; |
| 30 | 30 | ||
| 31 | + /** 关联父表的表名 */ | ||
| 32 | + private String subTableName; | ||
| 33 | + | ||
| 34 | + /** 本表关联父表的外键名 */ | ||
| 35 | + private String subTableFkName; | ||
| 36 | + | ||
| 31 | /** 实体类名称(首字母大写) */ | 37 | /** 实体类名称(首字母大写) */ |
| 32 | @NotBlank(message = "实体类名称不能为空") | 38 | @NotBlank(message = "实体类名称不能为空") |
| 33 | private String className; | 39 | private String className; |
| 34 | 40 | ||
| 35 | - /** 使用的模板(crud单表操作 tree树表操作) */ | 41 | + /** 使用的模板(crud单表操作 tree树表操作 sub主子表操作) */ |
| 36 | private String tplCategory; | 42 | private String tplCategory; |
| 37 | 43 | ||
| 38 | /** 生成包路径 */ | 44 | /** 生成包路径 */ |
| @@ -64,6 +70,9 @@ public class GenTable extends BaseEntity | @@ -64,6 +70,9 @@ public class GenTable extends BaseEntity | ||
| 64 | /** 主键信息 */ | 70 | /** 主键信息 */ |
| 65 | private GenTableColumn pkColumn; | 71 | private GenTableColumn pkColumn; |
| 66 | 72 | ||
| 73 | + /** 子表信息 */ | ||
| 74 | + private GenTable subTable; | ||
| 75 | + | ||
| 67 | /** 表列信息 */ | 76 | /** 表列信息 */ |
| 68 | @Valid | 77 | @Valid |
| 69 | private List<GenTableColumn> columns; | 78 | private List<GenTableColumn> columns; |
| @@ -116,6 +125,26 @@ public class GenTable extends BaseEntity | @@ -116,6 +125,26 @@ public class GenTable extends BaseEntity | ||
| 116 | this.tableComment = tableComment; | 125 | this.tableComment = tableComment; |
| 117 | } | 126 | } |
| 118 | 127 | ||
| 128 | + public String getSubTableName() | ||
| 129 | + { | ||
| 130 | + return subTableName; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + public void setSubTableName(String subTableName) | ||
| 134 | + { | ||
| 135 | + this.subTableName = subTableName; | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + public String getSubTableFkName() | ||
| 139 | + { | ||
| 140 | + return subTableFkName; | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + public void setSubTableFkName(String subTableFkName) | ||
| 144 | + { | ||
| 145 | + this.subTableFkName = subTableFkName; | ||
| 146 | + } | ||
| 147 | + | ||
| 119 | public String getClassName() | 148 | public String getClassName() |
| 120 | { | 149 | { |
| 121 | return className; | 150 | return className; |
| @@ -216,6 +245,16 @@ public class GenTable extends BaseEntity | @@ -216,6 +245,16 @@ public class GenTable extends BaseEntity | ||
| 216 | this.pkColumn = pkColumn; | 245 | this.pkColumn = pkColumn; |
| 217 | } | 246 | } |
| 218 | 247 | ||
| 248 | + public GenTable getSubTable() | ||
| 249 | + { | ||
| 250 | + return subTable; | ||
| 251 | + } | ||
| 252 | + | ||
| 253 | + public void setSubTable(GenTable subTable) | ||
| 254 | + { | ||
| 255 | + this.subTable = subTable; | ||
| 256 | + } | ||
| 257 | + | ||
| 219 | public List<GenTableColumn> getColumns() | 258 | public List<GenTableColumn> getColumns() |
| 220 | { | 259 | { |
| 221 | return columns; | 260 | return columns; |
| @@ -286,6 +325,16 @@ public class GenTable extends BaseEntity | @@ -286,6 +325,16 @@ public class GenTable extends BaseEntity | ||
| 286 | this.parentMenuName = parentMenuName; | 325 | this.parentMenuName = parentMenuName; |
| 287 | } | 326 | } |
| 288 | 327 | ||
| 328 | + public boolean isSub() | ||
| 329 | + { | ||
| 330 | + return isSub(this.tplCategory); | ||
| 331 | + } | ||
| 332 | + | ||
| 333 | + public static boolean isSub(String tplCategory) | ||
| 334 | + { | ||
| 335 | + return tplCategory != null && StringUtils.equals(GenConstants.TPL_SUB, tplCategory); | ||
| 336 | + } | ||
| 337 | + | ||
| 289 | public boolean isTree() | 338 | public boolean isTree() |
| 290 | { | 339 | { |
| 291 | return isTree(this.tplCategory); | 340 | return isTree(this.tplCategory); |
| @@ -138,6 +138,11 @@ public class GenTableColumn extends BaseEntity | @@ -138,6 +138,11 @@ public class GenTableColumn extends BaseEntity | ||
| 138 | return javaField; | 138 | return javaField; |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | + public String getCapJavaField() | ||
| 142 | + { | ||
| 143 | + return StringUtils.capitalize(javaField); | ||
| 144 | + } | ||
| 145 | + | ||
| 141 | public void setIsPk(String isPk) | 146 | public void setIsPk(String isPk) |
| 142 | { | 147 | { |
| 143 | this.isPk = isPk; | 148 | this.isPk = isPk; |
| @@ -35,6 +35,13 @@ public interface GenTableMapper | @@ -35,6 +35,13 @@ public interface GenTableMapper | ||
| 35 | public List<GenTable> selectDbTableListByNames(String[] tableNames); | 35 | public List<GenTable> selectDbTableListByNames(String[] tableNames); |
| 36 | 36 | ||
| 37 | /** | 37 | /** |
| 38 | + * 查询所有表信息 | ||
| 39 | + * | ||
| 40 | + * @return 表信息集合 | ||
| 41 | + */ | ||
| 42 | + public List<GenTable> selectGenTableAll(); | ||
| 43 | + | ||
| 44 | + /** | ||
| 38 | * 查询表ID业务信息 | 45 | * 查询表ID业务信息 |
| 39 | * | 46 | * |
| 40 | * @param id 业务ID | 47 | * @param id 业务ID |
| @@ -103,6 +103,17 @@ public class GenTableServiceImpl implements IGenTableService | @@ -103,6 +103,17 @@ public class GenTableServiceImpl implements IGenTableService | ||
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | /** | 105 | /** |
| 106 | + * 查询所有表信息 | ||
| 107 | + * | ||
| 108 | + * @return 表信息集合 | ||
| 109 | + */ | ||
| 110 | + @Override | ||
| 111 | + public List<GenTable> selectGenTableAll() | ||
| 112 | + { | ||
| 113 | + return genTableMapper.selectGenTableAll(); | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + /** | ||
| 106 | * 修改业务 | 117 | * 修改业务 |
| 107 | * | 118 | * |
| 108 | * @param genTable 业务信息 | 119 | * @param genTable 业务信息 |
| @@ -185,9 +196,10 @@ public class GenTableServiceImpl implements IGenTableService | @@ -185,9 +196,10 @@ public class GenTableServiceImpl implements IGenTableService | ||
| 185 | Map<String, String> dataMap = new LinkedHashMap<>(); | 196 | Map<String, String> dataMap = new LinkedHashMap<>(); |
| 186 | // 查询表信息 | 197 | // 查询表信息 |
| 187 | GenTable table = genTableMapper.selectGenTableById(tableId); | 198 | GenTable table = genTableMapper.selectGenTableById(tableId); |
| 188 | - // 查询列信息 | ||
| 189 | - List<GenTableColumn> columns = table.getColumns(); | ||
| 190 | - setPkColumn(table, columns); | 199 | + // 设置主子表信息 |
| 200 | + setSubTable(table); | ||
| 201 | + // 设置主键列信息 | ||
| 202 | + setPkColumn(table); | ||
| 191 | VelocityInitializer.initVelocity(); | 203 | VelocityInitializer.initVelocity(); |
| 192 | 204 | ||
| 193 | VelocityContext context = VelocityUtils.prepareContext(table); | 205 | VelocityContext context = VelocityUtils.prepareContext(table); |
| @@ -231,9 +243,10 @@ public class GenTableServiceImpl implements IGenTableService | @@ -231,9 +243,10 @@ public class GenTableServiceImpl implements IGenTableService | ||
| 231 | { | 243 | { |
| 232 | // 查询表信息 | 244 | // 查询表信息 |
| 233 | GenTable table = genTableMapper.selectGenTableByName(tableName); | 245 | GenTable table = genTableMapper.selectGenTableByName(tableName); |
| 234 | - // 查询列信息 | ||
| 235 | - List<GenTableColumn> columns = table.getColumns(); | ||
| 236 | - setPkColumn(table, columns); | 246 | + // 设置主子表信息 |
| 247 | + setSubTable(table); | ||
| 248 | + // 设置主键列信息 | ||
| 249 | + setPkColumn(table); | ||
| 237 | 250 | ||
| 238 | VelocityInitializer.initVelocity(); | 251 | VelocityInitializer.initVelocity(); |
| 239 | 252 | ||
| @@ -276,6 +289,10 @@ public class GenTableServiceImpl implements IGenTableService | @@ -276,6 +289,10 @@ public class GenTableServiceImpl implements IGenTableService | ||
| 276 | List<String> tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); | 289 | List<String> tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); |
| 277 | 290 | ||
| 278 | List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); | 291 | List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); |
| 292 | + if (StringUtils.isEmpty(dbTableColumns)) | ||
| 293 | + { | ||
| 294 | + throw new CustomException("同步数据失败,原表结构不存在"); | ||
| 295 | + } | ||
| 279 | List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); | 296 | List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); |
| 280 | 297 | ||
| 281 | dbTableColumns.forEach(column -> { | 298 | dbTableColumns.forEach(column -> { |
| @@ -319,9 +336,10 @@ public class GenTableServiceImpl implements IGenTableService | @@ -319,9 +336,10 @@ public class GenTableServiceImpl implements IGenTableService | ||
| 319 | { | 336 | { |
| 320 | // 查询表信息 | 337 | // 查询表信息 |
| 321 | GenTable table = genTableMapper.selectGenTableByName(tableName); | 338 | GenTable table = genTableMapper.selectGenTableByName(tableName); |
| 322 | - // 查询列信息 | ||
| 323 | - List<GenTableColumn> columns = table.getColumns(); | ||
| 324 | - setPkColumn(table, columns); | 339 | + // 设置主子表信息 |
| 340 | + setSubTable(table); | ||
| 341 | + // 设置主键列信息 | ||
| 342 | + setPkColumn(table); | ||
| 325 | 343 | ||
| 326 | VelocityInitializer.initVelocity(); | 344 | VelocityInitializer.initVelocity(); |
| 327 | 345 | ||
| @@ -375,6 +393,17 @@ public class GenTableServiceImpl implements IGenTableService | @@ -375,6 +393,17 @@ public class GenTableServiceImpl implements IGenTableService | ||
| 375 | { | 393 | { |
| 376 | throw new CustomException("树名称字段不能为空"); | 394 | throw new CustomException("树名称字段不能为空"); |
| 377 | } | 395 | } |
| 396 | + else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) | ||
| 397 | + { | ||
| 398 | + if (StringUtils.isEmpty(genTable.getSubTableName())) | ||
| 399 | + { | ||
| 400 | + throw new CustomException("关联子表的表名不能为空"); | ||
| 401 | + } | ||
| 402 | + else if (StringUtils.isEmpty(genTable.getSubTableFkName())) | ||
| 403 | + { | ||
| 404 | + throw new CustomException("子表关联的外键名不能为空"); | ||
| 405 | + } | ||
| 406 | + } | ||
| 378 | } | 407 | } |
| 379 | } | 408 | } |
| 380 | 409 | ||
| @@ -382,11 +411,10 @@ public class GenTableServiceImpl implements IGenTableService | @@ -382,11 +411,10 @@ public class GenTableServiceImpl implements IGenTableService | ||
| 382 | * 设置主键列信息 | 411 | * 设置主键列信息 |
| 383 | * | 412 | * |
| 384 | * @param table 业务表信息 | 413 | * @param table 业务表信息 |
| 385 | - * @param columns 业务字段列表 | ||
| 386 | */ | 414 | */ |
| 387 | - public void setPkColumn(GenTable table, List<GenTableColumn> columns) | 415 | + public void setPkColumn(GenTable table) |
| 388 | { | 416 | { |
| 389 | - for (GenTableColumn column : columns) | 417 | + for (GenTableColumn column : table.getColumns()) |
| 390 | { | 418 | { |
| 391 | if (column.isPk()) | 419 | if (column.isPk()) |
| 392 | { | 420 | { |
| @@ -396,7 +424,36 @@ public class GenTableServiceImpl implements IGenTableService | @@ -396,7 +424,36 @@ public class GenTableServiceImpl implements IGenTableService | ||
| 396 | } | 424 | } |
| 397 | if (StringUtils.isNull(table.getPkColumn())) | 425 | if (StringUtils.isNull(table.getPkColumn())) |
| 398 | { | 426 | { |
| 399 | - table.setPkColumn(columns.get(0)); | 427 | + table.setPkColumn(table.getColumns().get(0)); |
| 428 | + } | ||
| 429 | + if (GenConstants.TPL_SUB.equals(table.getTplCategory())) | ||
| 430 | + { | ||
| 431 | + for (GenTableColumn column : table.getSubTable().getColumns()) | ||
| 432 | + { | ||
| 433 | + if (column.isPk()) | ||
| 434 | + { | ||
| 435 | + table.getSubTable().setPkColumn(column); | ||
| 436 | + break; | ||
| 437 | + } | ||
| 438 | + } | ||
| 439 | + if (StringUtils.isNull(table.getSubTable().getPkColumn())) | ||
| 440 | + { | ||
| 441 | + table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0)); | ||
| 442 | + } | ||
| 443 | + } | ||
| 444 | + } | ||
| 445 | + | ||
| 446 | + /** | ||
| 447 | + * 设置主子表信息 | ||
| 448 | + * | ||
| 449 | + * @param table 业务表信息 | ||
| 450 | + */ | ||
| 451 | + public void setSubTable(GenTable table) | ||
| 452 | + { | ||
| 453 | + String subTableName = table.getSubTableName(); | ||
| 454 | + if (StringUtils.isNotEmpty(subTableName)) | ||
| 455 | + { | ||
| 456 | + table.setSubTable(genTableMapper.selectGenTableByName(subTableName)); | ||
| 400 | } | 457 | } |
| 401 | } | 458 | } |
| 402 | 459 |
| @@ -36,6 +36,13 @@ public interface IGenTableService | @@ -36,6 +36,13 @@ public interface IGenTableService | ||
| 36 | public List<GenTable> selectDbTableListByNames(String[] tableNames); | 36 | public List<GenTable> selectDbTableListByNames(String[] tableNames); |
| 37 | 37 | ||
| 38 | /** | 38 | /** |
| 39 | + * 查询所有表信息 | ||
| 40 | + * | ||
| 41 | + * @return 表信息集合 | ||
| 42 | + */ | ||
| 43 | + public List<GenTable> selectGenTableAll(); | ||
| 44 | + | ||
| 45 | + /** | ||
| 39 | * 查询业务信息 | 46 | * 查询业务信息 |
| 40 | * | 47 | * |
| 41 | * @param id 业务ID | 48 | * @param id 业务ID |
| @@ -7,7 +7,7 @@ import com.ruoyi.common.constant.Constants; | @@ -7,7 +7,7 @@ import com.ruoyi.common.constant.Constants; | ||
| 7 | /** | 7 | /** |
| 8 | * VelocityEngine工厂 | 8 | * VelocityEngine工厂 |
| 9 | * | 9 | * |
| 10 | - * @author RuoYi | 10 | + * @author ruoyi |
| 11 | */ | 11 | */ |
| 12 | public class VelocityInitializer | 12 | public class VelocityInitializer |
| 13 | { | 13 | { |
| @@ -54,7 +54,7 @@ public class VelocityUtils | @@ -54,7 +54,7 @@ public class VelocityUtils | ||
| 54 | velocityContext.put("author", genTable.getFunctionAuthor()); | 54 | velocityContext.put("author", genTable.getFunctionAuthor()); |
| 55 | velocityContext.put("datetime", DateUtils.getDate()); | 55 | velocityContext.put("datetime", DateUtils.getDate()); |
| 56 | velocityContext.put("pkColumn", genTable.getPkColumn()); | 56 | velocityContext.put("pkColumn", genTable.getPkColumn()); |
| 57 | - velocityContext.put("importList", getImportList(genTable.getColumns())); | 57 | + velocityContext.put("importList", getImportList(genTable)); |
| 58 | velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); | 58 | velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); |
| 59 | velocityContext.put("columns", genTable.getColumns()); | 59 | velocityContext.put("columns", genTable.getColumns()); |
| 60 | velocityContext.put("table", genTable); | 60 | velocityContext.put("table", genTable); |
| @@ -63,6 +63,10 @@ public class VelocityUtils | @@ -63,6 +63,10 @@ public class VelocityUtils | ||
| 63 | { | 63 | { |
| 64 | setTreeVelocityContext(velocityContext, genTable); | 64 | setTreeVelocityContext(velocityContext, genTable); |
| 65 | } | 65 | } |
| 66 | + if (GenConstants.TPL_SUB.equals(tplCategory)) | ||
| 67 | + { | ||
| 68 | + setSubVelocityContext(velocityContext, genTable); | ||
| 69 | + } | ||
| 66 | return velocityContext; | 70 | return velocityContext; |
| 67 | } | 71 | } |
| 68 | 72 | ||
| @@ -96,6 +100,24 @@ public class VelocityUtils | @@ -96,6 +100,24 @@ public class VelocityUtils | ||
| 96 | } | 100 | } |
| 97 | } | 101 | } |
| 98 | 102 | ||
| 103 | + public static void setSubVelocityContext(VelocityContext context, GenTable genTable) | ||
| 104 | + { | ||
| 105 | + GenTable subTable = genTable.getSubTable(); | ||
| 106 | + String subTableName = genTable.getSubTableName(); | ||
| 107 | + String subTableFkName = genTable.getSubTableFkName(); | ||
| 108 | + String subClassName = genTable.getSubTable().getClassName(); | ||
| 109 | + String subTableFkClassName = StringUtils.convertToCamelCase(subTableFkName); | ||
| 110 | + | ||
| 111 | + context.put("subTable", subTable); | ||
| 112 | + context.put("subTableName", subTableName); | ||
| 113 | + context.put("subTableFkName", subTableFkName); | ||
| 114 | + context.put("subTableFkClassName", subTableFkClassName); | ||
| 115 | + context.put("subTableFkclassName", StringUtils.uncapitalize(subTableFkClassName)); | ||
| 116 | + context.put("subClassName", subClassName); | ||
| 117 | + context.put("subclassName", StringUtils.uncapitalize(subClassName)); | ||
| 118 | + context.put("subImportList", getImportList(genTable.getSubTable())); | ||
| 119 | + } | ||
| 120 | + | ||
| 99 | /** | 121 | /** |
| 100 | * 获取模板信息 | 122 | * 获取模板信息 |
| 101 | * | 123 | * |
| @@ -120,6 +142,11 @@ public class VelocityUtils | @@ -120,6 +142,11 @@ public class VelocityUtils | ||
| 120 | { | 142 | { |
| 121 | templates.add("vm/vue/index-tree.vue.vm"); | 143 | templates.add("vm/vue/index-tree.vue.vm"); |
| 122 | } | 144 | } |
| 145 | + else if (GenConstants.TPL_SUB.equals(tplCategory)) | ||
| 146 | + { | ||
| 147 | + templates.add("vm/vue/index.vue.vm"); | ||
| 148 | + templates.add("vm/java/sub-domain.java.vm"); | ||
| 149 | + } | ||
| 123 | return templates; | 150 | return templates; |
| 124 | } | 151 | } |
| 125 | 152 | ||
| @@ -147,6 +174,10 @@ public class VelocityUtils | @@ -147,6 +174,10 @@ public class VelocityUtils | ||
| 147 | { | 174 | { |
| 148 | fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); | 175 | fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); |
| 149 | } | 176 | } |
| 177 | + if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory())) | ||
| 178 | + { | ||
| 179 | + fileName = StringUtils.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName()); | ||
| 180 | + } | ||
| 150 | else if (template.contains("mapper.java.vm")) | 181 | else if (template.contains("mapper.java.vm")) |
| 151 | { | 182 | { |
| 152 | fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); | 183 | fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); |
| @@ -202,12 +233,18 @@ public class VelocityUtils | @@ -202,12 +233,18 @@ public class VelocityUtils | ||
| 202 | /** | 233 | /** |
| 203 | * 根据列类型获取导入包 | 234 | * 根据列类型获取导入包 |
| 204 | * | 235 | * |
| 205 | - * @param columns 列集合 | 236 | + * @param genTable 业务表对象 |
| 206 | * @return 返回需要导入的包列表 | 237 | * @return 返回需要导入的包列表 |
| 207 | */ | 238 | */ |
| 208 | - public static HashSet<String> getImportList(List<GenTableColumn> columns) | 239 | + public static HashSet<String> getImportList(GenTable genTable) |
| 209 | { | 240 | { |
| 241 | + List<GenTableColumn> columns = genTable.getColumns(); | ||
| 242 | + GenTable subGenTable = genTable.getSubTable(); | ||
| 210 | HashSet<String> importList = new HashSet<String>(); | 243 | HashSet<String> importList = new HashSet<String>(); |
| 244 | + if (StringUtils.isNotNull(subGenTable)) | ||
| 245 | + { | ||
| 246 | + importList.add("java.util.List"); | ||
| 247 | + } | ||
| 211 | for (GenTableColumn column : columns) | 248 | for (GenTableColumn column : columns) |
| 212 | { | 249 | { |
| 213 | if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) | 250 | if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) |
| @@ -8,6 +8,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -8,6 +8,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 8 | <id property="tableId" column="table_id" /> | 8 | <id property="tableId" column="table_id" /> |
| 9 | <result property="tableName" column="table_name" /> | 9 | <result property="tableName" column="table_name" /> |
| 10 | <result property="tableComment" column="table_comment" /> | 10 | <result property="tableComment" column="table_comment" /> |
| 11 | + <result property="subTableName" column="sub_table_name" /> | ||
| 12 | + <result property="subTableFkName" column="sub_table_fk_name" /> | ||
| 11 | <result property="className" column="class_name" /> | 13 | <result property="className" column="class_name" /> |
| 12 | <result property="tplCategory" column="tpl_category" /> | 14 | <result property="tplCategory" column="tpl_category" /> |
| 13 | <result property="packageName" column="package_name" /> | 15 | <result property="packageName" column="package_name" /> |
| @@ -52,7 +54,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -52,7 +54,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 52 | </resultMap> | 54 | </resultMap> |
| 53 | 55 | ||
| 54 | <sql id="selectGenTableVo"> | 56 | <sql id="selectGenTableVo"> |
| 55 | - select table_id, table_name, table_comment, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table | 57 | + select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table |
| 56 | </sql> | 58 | </sql> |
| 57 | 59 | ||
| 58 | <select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult"> | 60 | <select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult"> |
| @@ -108,7 +110,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -108,7 +110,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 108 | </select> | 110 | </select> |
| 109 | 111 | ||
| 110 | <select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult"> | 112 | <select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult"> |
| 111 | - SELECT t.table_id, t.table_name, t.table_comment, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark, | 113 | + SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark, |
| 112 | c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort | 114 | c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort |
| 113 | FROM gen_table t | 115 | FROM gen_table t |
| 114 | LEFT JOIN gen_table_column c ON t.table_id = c.table_id | 116 | LEFT JOIN gen_table_column c ON t.table_id = c.table_id |
| @@ -116,13 +118,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -116,13 +118,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 116 | </select> | 118 | </select> |
| 117 | 119 | ||
| 118 | <select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult"> | 120 | <select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult"> |
| 119 | - SELECT t.table_id, t.table_name, t.table_comment, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark, | 121 | + SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark, |
| 120 | c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort | 122 | c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort |
| 121 | FROM gen_table t | 123 | FROM gen_table t |
| 122 | LEFT JOIN gen_table_column c ON t.table_id = c.table_id | 124 | LEFT JOIN gen_table_column c ON t.table_id = c.table_id |
| 123 | where t.table_name = #{tableName} order by c.sort | 125 | where t.table_name = #{tableName} order by c.sort |
| 124 | </select> | 126 | </select> |
| 125 | 127 | ||
| 128 | + <select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult"> | ||
| 129 | + SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.remark, | ||
| 130 | + c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort | ||
| 131 | + FROM gen_table t | ||
| 132 | + LEFT JOIN gen_table_column c ON t.table_id = c.table_id | ||
| 133 | + order by c.sort | ||
| 134 | + </select> | ||
| 135 | + | ||
| 126 | <insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId"> | 136 | <insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId"> |
| 127 | insert into gen_table ( | 137 | insert into gen_table ( |
| 128 | <if test="tableName != null">table_name,</if> | 138 | <if test="tableName != null">table_name,</if> |
| @@ -162,6 +172,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -162,6 +172,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 162 | <set> | 172 | <set> |
| 163 | <if test="tableName != null">table_name = #{tableName},</if> | 173 | <if test="tableName != null">table_name = #{tableName},</if> |
| 164 | <if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if> | 174 | <if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if> |
| 175 | + <if test="subTableName != null">sub_table_name = #{subTableName},</if> | ||
| 176 | + <if test="subTableFkName != null">sub_table_fk_name = #{subTableFkName},</if> | ||
| 165 | <if test="className != null and className != ''">class_name = #{className},</if> | 177 | <if test="className != null and className != ''">class_name = #{className},</if> |
| 166 | <if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if> | 178 | <if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if> |
| 167 | <if test="genType != null and genType != ''">gen_type = #{genType},</if> | 179 | <if test="genType != null and genType != ''">gen_type = #{genType},</if> |
| @@ -18,7 +18,7 @@ import com.ruoyi.common.enums.BusinessType; | @@ -18,7 +18,7 @@ import com.ruoyi.common.enums.BusinessType; | ||
| 18 | import ${packageName}.domain.${ClassName}; | 18 | import ${packageName}.domain.${ClassName}; |
| 19 | import ${packageName}.service.I${ClassName}Service; | 19 | import ${packageName}.service.I${ClassName}Service; |
| 20 | import com.ruoyi.common.utils.poi.ExcelUtil; | 20 | import com.ruoyi.common.utils.poi.ExcelUtil; |
| 21 | -#if($table.crud) | 21 | +#if($table.crud || $table.sub) |
| 22 | import com.ruoyi.common.core.page.TableDataInfo; | 22 | import com.ruoyi.common.core.page.TableDataInfo; |
| 23 | #elseif($table.tree) | 23 | #elseif($table.tree) |
| 24 | #end | 24 | #end |
| @@ -41,7 +41,7 @@ public class ${ClassName}Controller extends BaseController | @@ -41,7 +41,7 @@ public class ${ClassName}Controller extends BaseController | ||
| 41 | */ | 41 | */ |
| 42 | @PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')") | 42 | @PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')") |
| 43 | @GetMapping("/list") | 43 | @GetMapping("/list") |
| 44 | -#if($table.crud) | 44 | +#if($table.crud || $table.sub) |
| 45 | public TableDataInfo list(${ClassName} ${className}) | 45 | public TableDataInfo list(${ClassName} ${className}) |
| 46 | { | 46 | { |
| 47 | startPage(); | 47 | startPage(); |
| @@ -6,7 +6,7 @@ import ${import}; | @@ -6,7 +6,7 @@ import ${import}; | ||
| 6 | import org.apache.commons.lang3.builder.ToStringBuilder; | 6 | import org.apache.commons.lang3.builder.ToStringBuilder; |
| 7 | import org.apache.commons.lang3.builder.ToStringStyle; | 7 | import org.apache.commons.lang3.builder.ToStringStyle; |
| 8 | import com.ruoyi.common.annotation.Excel; | 8 | import com.ruoyi.common.annotation.Excel; |
| 9 | -#if($table.crud) | 9 | +#if($table.crud || $table.sub) |
| 10 | import com.ruoyi.common.core.domain.BaseEntity; | 10 | import com.ruoyi.common.core.domain.BaseEntity; |
| 11 | #elseif($table.tree) | 11 | #elseif($table.tree) |
| 12 | import com.ruoyi.common.core.domain.TreeEntity; | 12 | import com.ruoyi.common.core.domain.TreeEntity; |
| @@ -18,7 +18,7 @@ import com.ruoyi.common.core.domain.TreeEntity; | @@ -18,7 +18,7 @@ import com.ruoyi.common.core.domain.TreeEntity; | ||
| 18 | * @author ${author} | 18 | * @author ${author} |
| 19 | * @date ${datetime} | 19 | * @date ${datetime} |
| 20 | */ | 20 | */ |
| 21 | -#if($table.crud) | 21 | +#if($table.crud || $table.sub) |
| 22 | #set($Entity="BaseEntity") | 22 | #set($Entity="BaseEntity") |
| 23 | #elseif($table.tree) | 23 | #elseif($table.tree) |
| 24 | #set($Entity="TreeEntity") | 24 | #set($Entity="TreeEntity") |
| @@ -50,6 +50,11 @@ public class ${ClassName} extends ${Entity} | @@ -50,6 +50,11 @@ public class ${ClassName} extends ${Entity} | ||
| 50 | 50 | ||
| 51 | #end | 51 | #end |
| 52 | #end | 52 | #end |
| 53 | +#if($table.sub) | ||
| 54 | + /** $table.subTable.functionName信息 */ | ||
| 55 | + private List<${subClassName}> ${subclassName}List; | ||
| 56 | + | ||
| 57 | +#end | ||
| 53 | #foreach ($column in $columns) | 58 | #foreach ($column in $columns) |
| 54 | #if(!$table.isSuperColumn($column.javaField)) | 59 | #if(!$table.isSuperColumn($column.javaField)) |
| 55 | #if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) | 60 | #if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) |
| @@ -69,6 +74,18 @@ public class ${ClassName} extends ${Entity} | @@ -69,6 +74,18 @@ public class ${ClassName} extends ${Entity} | ||
| 69 | #end | 74 | #end |
| 70 | #end | 75 | #end |
| 71 | 76 | ||
| 77 | +#if($table.sub) | ||
| 78 | + public List<${subClassName}> get${subClassName}List() | ||
| 79 | + { | ||
| 80 | + return ${subclassName}List; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public void set${subClassName}List(List<${subClassName}> ${subclassName}List) | ||
| 84 | + { | ||
| 85 | + this.${subclassName}List = ${subclassName}List; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | +#end | ||
| 72 | @Override | 89 | @Override |
| 73 | public String toString() { | 90 | public String toString() { |
| 74 | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) | 91 | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
| @@ -80,6 +97,9 @@ public class ${ClassName} extends ${Entity} | @@ -80,6 +97,9 @@ public class ${ClassName} extends ${Entity} | ||
| 80 | #end | 97 | #end |
| 81 | .append("${column.javaField}", get${AttrName}()) | 98 | .append("${column.javaField}", get${AttrName}()) |
| 82 | #end | 99 | #end |
| 100 | +#if($table.sub) | ||
| 101 | + .append("${subclassName}List", get${subClassName}List()) | ||
| 102 | +#end | ||
| 83 | .toString(); | 103 | .toString(); |
| 84 | } | 104 | } |
| 85 | } | 105 | } |
| @@ -2,6 +2,9 @@ package ${packageName}.mapper; | @@ -2,6 +2,9 @@ package ${packageName}.mapper; | ||
| 2 | 2 | ||
| 3 | import java.util.List; | 3 | import java.util.List; |
| 4 | import ${packageName}.domain.${ClassName}; | 4 | import ${packageName}.domain.${ClassName}; |
| 5 | +#if($table.sub) | ||
| 6 | +import ${packageName}.domain.${subClassName}; | ||
| 7 | +#end | ||
| 5 | 8 | ||
| 6 | /** | 9 | /** |
| 7 | * ${functionName}Mapper接口 | 10 | * ${functionName}Mapper接口 |
| @@ -58,4 +61,31 @@ public interface ${ClassName}Mapper | @@ -58,4 +61,31 @@ public interface ${ClassName}Mapper | ||
| 58 | * @return 结果 | 61 | * @return 结果 |
| 59 | */ | 62 | */ |
| 60 | public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s); | 63 | public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s); |
| 64 | +#if($table.sub) | ||
| 65 | + | ||
| 66 | + /** | ||
| 67 | + * 批量删除${subTable.functionName} | ||
| 68 | + * | ||
| 69 | + * @param customerIds 需要删除的数据ID | ||
| 70 | + * @return 结果 | ||
| 71 | + */ | ||
| 72 | + public int delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaType}[] ${pkColumn.javaField}s); | ||
| 73 | + | ||
| 74 | + /** | ||
| 75 | + * 批量新增${subTable.functionName} | ||
| 76 | + * | ||
| 77 | + * @param ${subclassName}List ${subTable.functionName}列表 | ||
| 78 | + * @return 结果 | ||
| 79 | + */ | ||
| 80 | + public int batch${subClassName}(List<${subClassName}> ${subclassName}List); | ||
| 81 | + | ||
| 82 | + | ||
| 83 | + /** | ||
| 84 | + * 通过${functionName}ID删除${subTable.functionName}信息 | ||
| 85 | + * | ||
| 86 | + * @param roleId 角色ID | ||
| 87 | + * @return 结果 | ||
| 88 | + */ | ||
| 89 | + public int delete${subClassName}By${subTableFkClassName}(${pkColumn.javaType} ${pkColumn.javaField}); | ||
| 90 | +#end | ||
| 61 | } | 91 | } |
| @@ -9,6 +9,12 @@ import com.ruoyi.common.utils.DateUtils; | @@ -9,6 +9,12 @@ import com.ruoyi.common.utils.DateUtils; | ||
| 9 | #end | 9 | #end |
| 10 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 11 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 12 | +#if($table.sub) | ||
| 13 | +import java.util.ArrayList; | ||
| 14 | +import com.ruoyi.common.utils.StringUtils; | ||
| 15 | +import org.springframework.transaction.annotation.Transactional; | ||
| 16 | +import ${packageName}.domain.${subClassName}; | ||
| 17 | +#end | ||
| 12 | import ${packageName}.mapper.${ClassName}Mapper; | 18 | import ${packageName}.mapper.${ClassName}Mapper; |
| 13 | import ${packageName}.domain.${ClassName}; | 19 | import ${packageName}.domain.${ClassName}; |
| 14 | import ${packageName}.service.I${ClassName}Service; | 20 | import ${packageName}.service.I${ClassName}Service; |
| @@ -55,6 +61,9 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service | @@ -55,6 +61,9 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service | ||
| 55 | * @param ${className} ${functionName} | 61 | * @param ${className} ${functionName} |
| 56 | * @return 结果 | 62 | * @return 结果 |
| 57 | */ | 63 | */ |
| 64 | +#if($table.sub) | ||
| 65 | + @Transactional | ||
| 66 | +#end | ||
| 58 | @Override | 67 | @Override |
| 59 | public int insert${ClassName}(${ClassName} ${className}) | 68 | public int insert${ClassName}(${ClassName} ${className}) |
| 60 | { | 69 | { |
| @@ -63,7 +72,13 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service | @@ -63,7 +72,13 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service | ||
| 63 | ${className}.setCreateTime(DateUtils.getNowDate()); | 72 | ${className}.setCreateTime(DateUtils.getNowDate()); |
| 64 | #end | 73 | #end |
| 65 | #end | 74 | #end |
| 75 | +#if($table.sub) | ||
| 76 | + int rows = ${className}Mapper.insert${ClassName}(${className}); | ||
| 77 | + insert${subClassName}(${className}); | ||
| 78 | + return rows; | ||
| 79 | +#else | ||
| 66 | return ${className}Mapper.insert${ClassName}(${className}); | 80 | return ${className}Mapper.insert${ClassName}(${className}); |
| 81 | +#end | ||
| 67 | } | 82 | } |
| 68 | 83 | ||
| 69 | /** | 84 | /** |
| @@ -72,6 +87,9 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service | @@ -72,6 +87,9 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service | ||
| 72 | * @param ${className} ${functionName} | 87 | * @param ${className} ${functionName} |
| 73 | * @return 结果 | 88 | * @return 结果 |
| 74 | */ | 89 | */ |
| 90 | +#if($table.sub) | ||
| 91 | + @Transactional | ||
| 92 | +#end | ||
| 75 | @Override | 93 | @Override |
| 76 | public int update${ClassName}(${ClassName} ${className}) | 94 | public int update${ClassName}(${ClassName} ${className}) |
| 77 | { | 95 | { |
| @@ -80,6 +98,10 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service | @@ -80,6 +98,10 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service | ||
| 80 | ${className}.setUpdateTime(DateUtils.getNowDate()); | 98 | ${className}.setUpdateTime(DateUtils.getNowDate()); |
| 81 | #end | 99 | #end |
| 82 | #end | 100 | #end |
| 101 | +#if($table.sub) | ||
| 102 | + ${className}Mapper.delete${subClassName}By${subTableFkClassName}(${className}.get${pkColumn.capJavaField}()); | ||
| 103 | + insert${subClassName}(${className}); | ||
| 104 | +#end | ||
| 83 | return ${className}Mapper.update${ClassName}(${className}); | 105 | return ${className}Mapper.update${ClassName}(${className}); |
| 84 | } | 106 | } |
| 85 | 107 | ||
| @@ -89,9 +111,15 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service | @@ -89,9 +111,15 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service | ||
| 89 | * @param ${pkColumn.javaField}s 需要删除的${functionName}ID | 111 | * @param ${pkColumn.javaField}s 需要删除的${functionName}ID |
| 90 | * @return 结果 | 112 | * @return 结果 |
| 91 | */ | 113 | */ |
| 114 | +#if($table.sub) | ||
| 115 | + @Transactional | ||
| 116 | +#end | ||
| 92 | @Override | 117 | @Override |
| 93 | public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s) | 118 | public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s) |
| 94 | { | 119 | { |
| 120 | +#if($table.sub) | ||
| 121 | + ${className}Mapper.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s); | ||
| 122 | +#end | ||
| 95 | return ${className}Mapper.delete${ClassName}ByIds(${pkColumn.javaField}s); | 123 | return ${className}Mapper.delete${ClassName}ByIds(${pkColumn.javaField}s); |
| 96 | } | 124 | } |
| 97 | 125 | ||
| @@ -104,6 +132,35 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service | @@ -104,6 +132,35 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service | ||
| 104 | @Override | 132 | @Override |
| 105 | public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}) | 133 | public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}) |
| 106 | { | 134 | { |
| 135 | +#if($table.sub) | ||
| 136 | + ${className}Mapper.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField}); | ||
| 137 | +#end | ||
| 107 | return ${className}Mapper.delete${ClassName}ById(${pkColumn.javaField}); | 138 | return ${className}Mapper.delete${ClassName}ById(${pkColumn.javaField}); |
| 108 | } | 139 | } |
| 140 | +#if($table.sub) | ||
| 141 | + | ||
| 142 | + /** | ||
| 143 | + * 新增${subTable.functionName}信息 | ||
| 144 | + * | ||
| 145 | + * @param ${className} ${functionName}对象 | ||
| 146 | + */ | ||
| 147 | + public void insert${subClassName}(${ClassName} ${className}) | ||
| 148 | + { | ||
| 149 | + List<${subClassName}> ${subclassName}List = ${className}.get${subClassName}List(); | ||
| 150 | + Long ${pkColumn.javaField} = ${className}.get${pkColumn.capJavaField}(); | ||
| 151 | + if (StringUtils.isNotNull(${subclassName}List)) | ||
| 152 | + { | ||
| 153 | + List<${subClassName}> list = new ArrayList<${subClassName}>(); | ||
| 154 | + for (${subClassName} ${subclassName} : ${subclassName}List) | ||
| 155 | + { | ||
| 156 | + ${subclassName}.set${subTableFkClassName}(${pkColumn.javaField}); | ||
| 157 | + list.add(${subclassName}); | ||
| 158 | + } | ||
| 159 | + if (list.size() > 0) | ||
| 160 | + { | ||
| 161 | + ${className}Mapper.batch${subClassName}(list); | ||
| 162 | + } | ||
| 163 | + } | ||
| 164 | + } | ||
| 165 | +#end | ||
| 109 | } | 166 | } |
| 1 | +package ${packageName}.domain; | ||
| 2 | + | ||
| 3 | +#foreach ($import in $subImportList) | ||
| 4 | +import ${import}; | ||
| 5 | +#end | ||
| 6 | +import org.apache.commons.lang3.builder.ToStringBuilder; | ||
| 7 | +import org.apache.commons.lang3.builder.ToStringStyle; | ||
| 8 | +import com.ruoyi.common.annotation.Excel; | ||
| 9 | +import com.ruoyi.common.core.domain.BaseEntity; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * ${subTable.functionName}对象 ${subTableName} | ||
| 13 | + * | ||
| 14 | + * @author ${author} | ||
| 15 | + * @date ${datetime} | ||
| 16 | + */ | ||
| 17 | +public class ${subClassName} extends BaseEntity | ||
| 18 | +{ | ||
| 19 | + private static final long serialVersionUID = 1L; | ||
| 20 | + | ||
| 21 | +#foreach ($column in $subTable.columns) | ||
| 22 | +#if(!$table.isSuperColumn($column.javaField)) | ||
| 23 | + /** $column.columnComment */ | ||
| 24 | +#if($column.list) | ||
| 25 | +#set($parentheseIndex=$column.columnComment.indexOf("(")) | ||
| 26 | +#if($parentheseIndex != -1) | ||
| 27 | +#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | ||
| 28 | +#else | ||
| 29 | +#set($comment=$column.columnComment) | ||
| 30 | +#end | ||
| 31 | +#if($parentheseIndex != -1) | ||
| 32 | + @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") | ||
| 33 | +#elseif($column.javaType == 'Date') | ||
| 34 | + @JsonFormat(pattern = "yyyy-MM-dd") | ||
| 35 | + @Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd") | ||
| 36 | +#else | ||
| 37 | + @Excel(name = "${comment}") | ||
| 38 | +#end | ||
| 39 | +#end | ||
| 40 | + private $column.javaType $column.javaField; | ||
| 41 | + | ||
| 42 | +#end | ||
| 43 | +#end | ||
| 44 | +#foreach ($column in $subTable.columns) | ||
| 45 | +#if(!$table.isSuperColumn($column.javaField)) | ||
| 46 | +#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) | ||
| 47 | +#set($AttrName=$column.javaField) | ||
| 48 | +#else | ||
| 49 | +#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | ||
| 50 | +#end | ||
| 51 | + public void set${AttrName}($column.javaType $column.javaField) | ||
| 52 | + { | ||
| 53 | + this.$column.javaField = $column.javaField; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public $column.javaType get${AttrName}() | ||
| 57 | + { | ||
| 58 | + return $column.javaField; | ||
| 59 | + } | ||
| 60 | +#end | ||
| 61 | +#end | ||
| 62 | + | ||
| 63 | + @Override | ||
| 64 | + public String toString() { | ||
| 65 | + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) | ||
| 66 | +#foreach ($column in $subTable.columns) | ||
| 67 | +#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) | ||
| 68 | +#set($AttrName=$column.javaField) | ||
| 69 | +#else | ||
| 70 | +#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | ||
| 71 | +#end | ||
| 72 | + .append("${column.javaField}", get${AttrName}()) | ||
| 73 | +#end | ||
| 74 | + .toString(); | ||
| 75 | + } | ||
| 76 | +} |
| @@ -266,6 +266,38 @@ | @@ -266,6 +266,38 @@ | ||
| 266 | #end | 266 | #end |
| 267 | #end | 267 | #end |
| 268 | #end | 268 | #end |
| 269 | +#if($table.sub) | ||
| 270 | + <el-divider content-position="center">${subTable.functionName}信息</el-divider> | ||
| 271 | + <el-row :gutter="10" class="mb8"> | ||
| 272 | + <el-col :span="1.5"> | ||
| 273 | + <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd${subClassName}">添加</el-button> | ||
| 274 | + </el-col> | ||
| 275 | + <el-col :span="1.5"> | ||
| 276 | + <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDelete${subClassName}">删除</el-button> | ||
| 277 | + </el-col> | ||
| 278 | + </el-row> | ||
| 279 | + <el-table :data="${subclassName}List" :row-class-name="row${subClassName}Index" @selection-change="handle${subClassName}SelectionChange" ref="${subclassName}"> | ||
| 280 | + <el-table-column type="selection" width="50" align="center" /> | ||
| 281 | + <el-table-column label="序号" align="center" prop="index" width="50"/> | ||
| 282 | +#foreach($column in $subTable.columns) | ||
| 283 | +#set($javaField=$column.javaField) | ||
| 284 | +#set($parentheseIndex=$column.columnComment.indexOf("(")) | ||
| 285 | +#if($parentheseIndex != -1) | ||
| 286 | +#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | ||
| 287 | +#else | ||
| 288 | +#set($comment=$column.columnComment) | ||
| 289 | +#end | ||
| 290 | +#if($column.pk || $javaField == ${subTableFkclassName}) | ||
| 291 | +#elseif($column.list && "" != $javaField) | ||
| 292 | + <el-table-column label="$comment" prop="${javaField}"> | ||
| 293 | + <template slot-scope="scope"> | ||
| 294 | + <el-input v-model="scope.row.$javaField" placeholder="请输入$comment" /> | ||
| 295 | + </template> | ||
| 296 | + </el-table-column> | ||
| 297 | +#end | ||
| 298 | +#end | ||
| 299 | + </el-table> | ||
| 300 | +#end | ||
| 269 | </el-form> | 301 | </el-form> |
| 270 | <div slot="footer" class="dialog-footer"> | 302 | <div slot="footer" class="dialog-footer"> |
| 271 | <el-button type="primary" @click="submitForm">确 定</el-button> | 303 | <el-button type="primary" @click="submitForm">确 定</el-button> |
| @@ -324,6 +356,10 @@ export default { | @@ -324,6 +356,10 @@ export default { | ||
| 324 | loading: true, | 356 | loading: true, |
| 325 | // 选中数组 | 357 | // 选中数组 |
| 326 | ids: [], | 358 | ids: [], |
| 359 | +#if($table.sub) | ||
| 360 | + // 子表选中数据 | ||
| 361 | + checked${subClassName}: [], | ||
| 362 | +#end | ||
| 327 | // 非单个禁用 | 363 | // 非单个禁用 |
| 328 | single: true, | 364 | single: true, |
| 329 | // 非多个禁用 | 365 | // 非多个禁用 |
| @@ -334,6 +370,10 @@ export default { | @@ -334,6 +370,10 @@ export default { | ||
| 334 | total: 0, | 370 | total: 0, |
| 335 | // ${functionName}表格数据 | 371 | // ${functionName}表格数据 |
| 336 | ${businessName}List: [], | 372 | ${businessName}List: [], |
| 373 | +#if($table.sub) | ||
| 374 | + // ${subTable.functionName}表格数据 | ||
| 375 | + ${subclassName}List: [], | ||
| 376 | +#end | ||
| 337 | // 弹出层标题 | 377 | // 弹出层标题 |
| 338 | title: "", | 378 | title: "", |
| 339 | // 是否显示弹出层 | 379 | // 是否显示弹出层 |
| @@ -456,6 +496,9 @@ export default { | @@ -456,6 +496,9 @@ export default { | ||
| 456 | #end | 496 | #end |
| 457 | #end | 497 | #end |
| 458 | }; | 498 | }; |
| 499 | +#if($table.sub) | ||
| 500 | + this.${subclassName}List = []; | ||
| 501 | +#end | ||
| 459 | this.resetForm("form"); | 502 | this.resetForm("form"); |
| 460 | }, | 503 | }, |
| 461 | /** 搜索按钮操作 */ | 504 | /** 搜索按钮操作 */ |
| @@ -497,6 +540,9 @@ export default { | @@ -497,6 +540,9 @@ export default { | ||
| 497 | this.form.$column.javaField = this.form.${column.javaField}.split(","); | 540 | this.form.$column.javaField = this.form.${column.javaField}.split(","); |
| 498 | #end | 541 | #end |
| 499 | #end | 542 | #end |
| 543 | +#if($table.sub) | ||
| 544 | + this.${subclassName}List = response.data.${subclassName}List; | ||
| 545 | +#end | ||
| 500 | this.open = true; | 546 | this.open = true; |
| 501 | this.title = "修改${functionName}"; | 547 | this.title = "修改${functionName}"; |
| 502 | }); | 548 | }); |
| @@ -510,6 +556,9 @@ export default { | @@ -510,6 +556,9 @@ export default { | ||
| 510 | this.form.$column.javaField = this.form.${column.javaField}.join(","); | 556 | this.form.$column.javaField = this.form.${column.javaField}.join(","); |
| 511 | #end | 557 | #end |
| 512 | #end | 558 | #end |
| 559 | +#if($table.sub) | ||
| 560 | + this.form.${subclassName}List = this.${subclassName}List; | ||
| 561 | +#end | ||
| 513 | if (this.form.${pkColumn.javaField} != null) { | 562 | if (this.form.${pkColumn.javaField} != null) { |
| 514 | update${BusinessName}(this.form).then(response => { | 563 | update${BusinessName}(this.form).then(response => { |
| 515 | this.msgSuccess("修改成功"); | 564 | this.msgSuccess("修改成功"); |
| @@ -540,6 +589,40 @@ export default { | @@ -540,6 +589,40 @@ export default { | ||
| 540 | this.msgSuccess("删除成功"); | 589 | this.msgSuccess("删除成功"); |
| 541 | }) | 590 | }) |
| 542 | }, | 591 | }, |
| 592 | +#if($table.sub) | ||
| 593 | + /** ${subTable.functionName}序号 */ | ||
| 594 | + row${subClassName}Index({ row, rowIndex }) { | ||
| 595 | + row.index = rowIndex + 1; | ||
| 596 | + }, | ||
| 597 | + /** ${subTable.functionName}添加按钮操作 */ | ||
| 598 | + handleAdd${subClassName}() { | ||
| 599 | + let obj = {}; | ||
| 600 | +#foreach($column in $subTable.columns) | ||
| 601 | +#if($column.pk || $column.javaField == ${subTableFkclassName}) | ||
| 602 | +#elseif($column.list && "" != $javaField) | ||
| 603 | + obj.$column.javaField = ""; | ||
| 604 | +#end | ||
| 605 | +#end | ||
| 606 | + this.${subclassName}List.push(obj); | ||
| 607 | + }, | ||
| 608 | + /** ${subTable.functionName}删除按钮操作 */ | ||
| 609 | + handleDelete${subClassName}() { | ||
| 610 | + if (this.checked${subClassName}.length == 0) { | ||
| 611 | + this.$alert("请先选择要删除的${subTable.functionName}数据", "提示", { confirmButtonText: "确定", }); | ||
| 612 | + } else { | ||
| 613 | + this.${subclassName}List.splice(this.checked${subClassName}[0].index - 1, 1); | ||
| 614 | + } | ||
| 615 | + }, | ||
| 616 | + /** 单选框选中数据 */ | ||
| 617 | + handle${subClassName}SelectionChange(selection) { | ||
| 618 | + if (selection.length > 1) { | ||
| 619 | + this.$refs.${subclassName}.clearSelection(); | ||
| 620 | + this.$refs.${subclassName}.toggleRowSelection(selection.pop()); | ||
| 621 | + } else { | ||
| 622 | + this.checked${subClassName} = selection; | ||
| 623 | + } | ||
| 624 | + }, | ||
| 625 | +#end | ||
| 543 | /** 导出按钮操作 */ | 626 | /** 导出按钮操作 */ |
| 544 | handleExport() { | 627 | handleExport() { |
| 545 | const queryParams = this.queryParams; | 628 | const queryParams = this.queryParams; |
| @@ -9,6 +9,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -9,6 +9,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 9 | <result property="${column.javaField}" column="${column.columnName}" /> | 9 | <result property="${column.javaField}" column="${column.columnName}" /> |
| 10 | #end | 10 | #end |
| 11 | </resultMap> | 11 | </resultMap> |
| 12 | +#if($table.sub) | ||
| 13 | + | ||
| 14 | + <resultMap id="${ClassName}${subClassName}Result" type="${ClassName}" extends="${ClassName}Result"> | ||
| 15 | + <collection property="${subclassName}List" notNullColumn="${subTable.pkColumn.columnName}" javaType="java.util.List" resultMap="${subClassName}Result" /> | ||
| 16 | + </resultMap> | ||
| 17 | + | ||
| 18 | + <resultMap type="${subClassName}" id="${subClassName}Result"> | ||
| 19 | +#foreach ($column in $subTable.columns) | ||
| 20 | + <result property="${column.javaField}" column="${column.columnName}" /> | ||
| 21 | +#end | ||
| 22 | + </resultMap> | ||
| 23 | +#end | ||
| 12 | 24 | ||
| 13 | <sql id="select${ClassName}Vo"> | 25 | <sql id="select${ClassName}Vo"> |
| 14 | select#foreach($column in $columns) $column.columnName#if($velocityCount != $columns.size()),#end#end from ${tableName} | 26 | select#foreach($column in $columns) $column.columnName#if($velocityCount != $columns.size()),#end#end from ${tableName} |
| @@ -46,9 +58,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -46,9 +58,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 46 | </where> | 58 | </where> |
| 47 | </select> | 59 | </select> |
| 48 | 60 | ||
| 49 | - <select id="select${ClassName}ById" parameterType="${pkColumn.javaType}" resultMap="${ClassName}Result"> | 61 | + <select id="select${ClassName}ById" parameterType="${pkColumn.javaType}" resultMap="#if($table.sub)${ClassName}${subClassName}Result#else${ClassName}Result#end"> |
| 62 | +#if($table.crud || $table.tree) | ||
| 50 | <include refid="select${ClassName}Vo"/> | 63 | <include refid="select${ClassName}Vo"/> |
| 51 | where ${pkColumn.columnName} = #{${pkColumn.javaField}} | 64 | where ${pkColumn.columnName} = #{${pkColumn.javaField}} |
| 65 | +#elseif($table.sub) | ||
| 66 | + select#foreach($column in $columns) a.$column.columnName#if($velocityCount != $columns.size()),#end#end, | ||
| 67 | + #foreach($column in $subTable.columns) b.$column.columnName#if($velocityCount != $subTable.columns.size()),#end#end | ||
| 68 | + | ||
| 69 | + from ${tableName} a | ||
| 70 | + left join ${subTableName} b on b.${subTableFkName} = a.${pkColumn.columnName} | ||
| 71 | + where a.${pkColumn.columnName} = #{${pkColumn.javaField}} | ||
| 72 | +#end | ||
| 52 | </select> | 73 | </select> |
| 53 | 74 | ||
| 54 | <insert id="insert${ClassName}" parameterType="${ClassName}"#if($pkColumn.increment) useGeneratedKeys="true" keyProperty="$pkColumn.javaField"#end> | 75 | <insert id="insert${ClassName}" parameterType="${ClassName}"#if($pkColumn.increment) useGeneratedKeys="true" keyProperty="$pkColumn.javaField"#end> |
| @@ -91,5 +112,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -91,5 +112,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 91 | #{${pkColumn.javaField}} | 112 | #{${pkColumn.javaField}} |
| 92 | </foreach> | 113 | </foreach> |
| 93 | </delete> | 114 | </delete> |
| 115 | +#if($table.sub) | ||
| 94 | 116 | ||
| 117 | + <delete id="delete${subClassName}By${subTableFkClassName}s" parameterType="String"> | ||
| 118 | + delete from ${subTableName} where ${subTableFkName} in | ||
| 119 | + <foreach item="${subTableFkclassName}" collection="array" open="(" separator="," close=")"> | ||
| 120 | + #{${subTableFkclassName}} | ||
| 121 | + </foreach> | ||
| 122 | + </delete> | ||
| 123 | + | ||
| 124 | + <delete id="delete${subClassName}By${subTableFkClassName}" parameterType="Long"> | ||
| 125 | + delete from ${subTableName} where ${subTableFkName} = #{${subTableFkclassName}} | ||
| 126 | + </delete> | ||
| 127 | + | ||
| 128 | + <insert id="batch${subClassName}"> | ||
| 129 | + insert into ${subTableName}(#foreach($column in $subTable.columns) $column.columnName#if($velocityCount != $subTable.columns.size()),#end#end) values | ||
| 130 | + <foreach item="item" index="index" collection="list" separator=","> | ||
| 131 | + (#foreach($column in $subTable.columns) #{item.$column.javaField}#if($velocityCount != $subTable.columns.size()),#end#end) | ||
| 132 | + </foreach> | ||
| 133 | + </insert> | ||
| 134 | +#end | ||
| 95 | </mapper> | 135 | </mapper> |
| @@ -113,7 +113,7 @@ | @@ -113,7 +113,7 @@ | ||
| 113 | </el-table> | 113 | </el-table> |
| 114 | </el-tab-pane> | 114 | </el-tab-pane> |
| 115 | <el-tab-pane label="生成信息" name="genInfo"> | 115 | <el-tab-pane label="生成信息" name="genInfo"> |
| 116 | - <gen-info-form ref="genInfo" :info="info" :menus="menus"/> | 116 | + <gen-info-form ref="genInfo" :info="info" :tables="tables" :menus="menus"/> |
| 117 | </el-tab-pane> | 117 | </el-tab-pane> |
| 118 | </el-tabs> | 118 | </el-tabs> |
| 119 | <el-form label-width="100px"> | 119 | <el-form label-width="100px"> |
| @@ -144,6 +144,8 @@ export default { | @@ -144,6 +144,8 @@ export default { | ||
| 144 | activeName: "cloum", | 144 | activeName: "cloum", |
| 145 | // 表格的高度 | 145 | // 表格的高度 |
| 146 | tableHeight: document.documentElement.scrollHeight - 245 + "px", | 146 | tableHeight: document.documentElement.scrollHeight - 245 + "px", |
| 147 | + // 表信息 | ||
| 148 | + tables: [], | ||
| 147 | // 表列信息 | 149 | // 表列信息 |
| 148 | cloumns: [], | 150 | cloumns: [], |
| 149 | // 字典信息 | 151 | // 字典信息 |
| @@ -161,6 +163,7 @@ export default { | @@ -161,6 +163,7 @@ export default { | ||
| 161 | getGenTable(tableId).then(res => { | 163 | getGenTable(tableId).then(res => { |
| 162 | this.cloumns = res.data.rows; | 164 | this.cloumns = res.data.rows; |
| 163 | this.info = res.data.info; | 165 | this.info = res.data.info; |
| 166 | + this.tables = res.data.tables; | ||
| 164 | }); | 167 | }); |
| 165 | /** 查询字典下拉列表 */ | 168 | /** 查询字典下拉列表 */ |
| 166 | getDictOptionselect().then(response => { | 169 | getDictOptionselect().then(response => { |
| @@ -4,9 +4,10 @@ | @@ -4,9 +4,10 @@ | ||
| 4 | <el-col :span="12"> | 4 | <el-col :span="12"> |
| 5 | <el-form-item prop="tplCategory"> | 5 | <el-form-item prop="tplCategory"> |
| 6 | <span slot="label">生成模板</span> | 6 | <span slot="label">生成模板</span> |
| 7 | - <el-select v-model="info.tplCategory"> | 7 | + <el-select v-model="info.tplCategory" @change="tplSelectChange"> |
| 8 | <el-option label="单表(增删改查)" value="crud" /> | 8 | <el-option label="单表(增删改查)" value="crud" /> |
| 9 | <el-option label="树表(增删改查)" value="tree" /> | 9 | <el-option label="树表(增删改查)" value="tree" /> |
| 10 | + <el-option label="主子表(增删改查)" value="sub" /> | ||
| 10 | </el-select> | 11 | </el-select> |
| 11 | </el-form-item> | 12 | </el-form-item> |
| 12 | </el-col> | 13 | </el-col> |
| @@ -126,8 +127,8 @@ | @@ -126,8 +127,8 @@ | ||
| 126 | </span> | 127 | </span> |
| 127 | <el-select v-model="info.treeCode" placeholder="请选择"> | 128 | <el-select v-model="info.treeCode" placeholder="请选择"> |
| 128 | <el-option | 129 | <el-option |
| 129 | - v-for="column in info.columns" | ||
| 130 | - :key="column.columnName" | 130 | + v-for="(column, index) in info.columns" |
| 131 | + :key="index" | ||
| 131 | :label="column.columnName + ':' + column.columnComment" | 132 | :label="column.columnName + ':' + column.columnComment" |
| 132 | :value="column.columnName" | 133 | :value="column.columnName" |
| 133 | ></el-option> | 134 | ></el-option> |
| @@ -144,8 +145,8 @@ | @@ -144,8 +145,8 @@ | ||
| 144 | </span> | 145 | </span> |
| 145 | <el-select v-model="info.treeParentCode" placeholder="请选择"> | 146 | <el-select v-model="info.treeParentCode" placeholder="请选择"> |
| 146 | <el-option | 147 | <el-option |
| 147 | - v-for="column in info.columns" | ||
| 148 | - :key="column.columnName" | 148 | + v-for="(column, index) in info.columns" |
| 149 | + :key="index" | ||
| 149 | :label="column.columnName + ':' + column.columnComment" | 150 | :label="column.columnName + ':' + column.columnComment" |
| 150 | :value="column.columnName" | 151 | :value="column.columnName" |
| 151 | ></el-option> | 152 | ></el-option> |
| @@ -162,8 +163,47 @@ | @@ -162,8 +163,47 @@ | ||
| 162 | </span> | 163 | </span> |
| 163 | <el-select v-model="info.treeName" placeholder="请选择"> | 164 | <el-select v-model="info.treeName" placeholder="请选择"> |
| 164 | <el-option | 165 | <el-option |
| 165 | - v-for="column in info.columns" | ||
| 166 | - :key="column.columnName" | 166 | + v-for="(column, index) in info.columns" |
| 167 | + :key="index" | ||
| 168 | + :label="column.columnName + ':' + column.columnComment" | ||
| 169 | + :value="column.columnName" | ||
| 170 | + ></el-option> | ||
| 171 | + </el-select> | ||
| 172 | + </el-form-item> | ||
| 173 | + </el-col> | ||
| 174 | + </el-row> | ||
| 175 | + <el-row v-show="info.tplCategory == 'sub'"> | ||
| 176 | + <h4 class="form-header">关联信息</h4> | ||
| 177 | + <el-col :span="12"> | ||
| 178 | + <el-form-item> | ||
| 179 | + <span slot="label"> | ||
| 180 | + 关联子表的表名 | ||
| 181 | + <el-tooltip content="关联子表的表名, 如:sys_user" placement="top"> | ||
| 182 | + <i class="el-icon-question"></i> | ||
| 183 | + </el-tooltip> | ||
| 184 | + </span> | ||
| 185 | + <el-select v-model="info.subTableName" placeholder="请选择" @change="subSelectChange"> | ||
| 186 | + <el-option | ||
| 187 | + v-for="(table, index) in tables" | ||
| 188 | + :key="index" | ||
| 189 | + :label="table.tableName + ':' + table.tableComment" | ||
| 190 | + :value="table.tableName" | ||
| 191 | + ></el-option> | ||
| 192 | + </el-select> | ||
| 193 | + </el-form-item> | ||
| 194 | + </el-col> | ||
| 195 | + <el-col :span="12"> | ||
| 196 | + <el-form-item> | ||
| 197 | + <span slot="label"> | ||
| 198 | + 子表关联的外键名 | ||
| 199 | + <el-tooltip content="子表关联的外键名, 如:user_id" placement="top"> | ||
| 200 | + <i class="el-icon-question"></i> | ||
| 201 | + </el-tooltip> | ||
| 202 | + </span> | ||
| 203 | + <el-select v-model="info.subTableFkName" placeholder="请选择"> | ||
| 204 | + <el-option | ||
| 205 | + v-for="(column, index) in subColumns" | ||
| 206 | + :key="index" | ||
| 167 | :label="column.columnName + ':' + column.columnComment" | 207 | :label="column.columnName + ':' + column.columnComment" |
| 168 | :value="column.columnName" | 208 | :value="column.columnName" |
| 169 | ></el-option> | 209 | ></el-option> |
| @@ -185,6 +225,10 @@ export default { | @@ -185,6 +225,10 @@ export default { | ||
| 185 | type: Object, | 225 | type: Object, |
| 186 | default: null | 226 | default: null |
| 187 | }, | 227 | }, |
| 228 | + tables: { | ||
| 229 | + type: Array, | ||
| 230 | + default: null | ||
| 231 | + }, | ||
| 188 | menus: { | 232 | menus: { |
| 189 | type: Array, | 233 | type: Array, |
| 190 | default: [] | 234 | default: [] |
| @@ -192,6 +236,7 @@ export default { | @@ -192,6 +236,7 @@ export default { | ||
| 192 | }, | 236 | }, |
| 193 | data() { | 237 | data() { |
| 194 | return { | 238 | return { |
| 239 | + subColumns: [], | ||
| 195 | rules: { | 240 | rules: { |
| 196 | tplCategory: [ | 241 | tplCategory: [ |
| 197 | { required: true, message: "请选择生成模板", trigger: "blur" } | 242 | { required: true, message: "请选择生成模板", trigger: "blur" } |
| @@ -212,6 +257,11 @@ export default { | @@ -212,6 +257,11 @@ export default { | ||
| 212 | }; | 257 | }; |
| 213 | }, | 258 | }, |
| 214 | created() {}, | 259 | created() {}, |
| 260 | + watch: { | ||
| 261 | + 'info.subTableName': function(val) { | ||
| 262 | + this.setSubTableColumns(val); | ||
| 263 | + } | ||
| 264 | + }, | ||
| 215 | methods: { | 265 | methods: { |
| 216 | /** 转换菜单数据结构 */ | 266 | /** 转换菜单数据结构 */ |
| 217 | normalizer(node) { | 267 | normalizer(node) { |
| @@ -223,6 +273,27 @@ export default { | @@ -223,6 +273,27 @@ export default { | ||
| 223 | label: node.menuName, | 273 | label: node.menuName, |
| 224 | children: node.children | 274 | children: node.children |
| 225 | }; | 275 | }; |
| 276 | + }, | ||
| 277 | + /** 选择子表名触发 */ | ||
| 278 | + subSelectChange(value) { | ||
| 279 | + this.info.subTableFkName = ''; | ||
| 280 | + }, | ||
| 281 | + /** 选择生成模板触发 */ | ||
| 282 | + tplSelectChange(value) { | ||
| 283 | + if(value !== 'sub') { | ||
| 284 | + this.info.subTableName = ''; | ||
| 285 | + this.info.subTableFkName = ''; | ||
| 286 | + } | ||
| 287 | + }, | ||
| 288 | + /** 设置关联外键 */ | ||
| 289 | + setSubTableColumns(value) { | ||
| 290 | + for (var item in this.tables) { | ||
| 291 | + const name = this.tables[item].tableName; | ||
| 292 | + if (value === name) { | ||
| 293 | + this.subColumns = this.tables[item].columns; | ||
| 294 | + break; | ||
| 295 | + } | ||
| 296 | + } | ||
| 226 | } | 297 | } |
| 227 | } | 298 | } |
| 228 | }; | 299 | }; |
| @@ -84,7 +84,7 @@ | @@ -84,7 +84,7 @@ | ||
| 84 | </el-row> | 84 | </el-row> |
| 85 | 85 | ||
| 86 | <el-table v-loading="loading" :data="tableList" @selection-change="handleSelectionChange"> | 86 | <el-table v-loading="loading" :data="tableList" @selection-change="handleSelectionChange"> |
| 87 | - <el-table-column type="selection" width="55"></el-table-column> | 87 | + <el-table-column type="selection" align="center" width="55"></el-table-column> |
| 88 | <el-table-column label="序号" type="index" width="50" align="center"> | 88 | <el-table-column label="序号" type="index" width="50" align="center"> |
| 89 | <template slot-scope="scope"> | 89 | <template slot-scope="scope"> |
| 90 | <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span> | 90 | <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span> |
| @@ -633,6 +633,8 @@ create table gen_table ( | @@ -633,6 +633,8 @@ create table gen_table ( | ||
| 633 | table_id bigint(20) not null auto_increment comment '编号', | 633 | table_id bigint(20) not null auto_increment comment '编号', |
| 634 | table_name varchar(200) default '' comment '表名称', | 634 | table_name varchar(200) default '' comment '表名称', |
| 635 | table_comment varchar(500) default '' comment '表描述', | 635 | table_comment varchar(500) default '' comment '表描述', |
| 636 | + sub_table_name varchar(64) default null comment '关联子表的表名', | ||
| 637 | + sub_table_fk_name varchar(64) default null comment '子表关联的外键名', | ||
| 636 | class_name varchar(100) default '' comment '实体类名称', | 638 | class_name varchar(100) default '' comment '实体类名称', |
| 637 | tpl_category varchar(200) default 'crud' comment '使用的模板(crud单表操作 tree树表操作)', | 639 | tpl_category varchar(200) default 'crud' comment '使用的模板(crud单表操作 tree树表操作)', |
| 638 | package_name varchar(100) comment '生成包路径', | 640 | package_name varchar(100) comment '生成包路径', |
-
请 注册 或 登录 后发表评论