Ver código fonte

代码生成模板支持主子表

RuoYi 5 anos atrás
pai
commit
5891960756
22 arquivos alterados com 1326 adições e 658 exclusões
  1. 3 0
      ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/GenConstants.java
  2. 2 0
      ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/controller/GenController.java
  3. 48 1
      ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java
  4. 5 0
      ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTableColumn.java
  5. 7 0
      ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableMapper.java
  6. 70 13
      ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java
  7. 7 0
      ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableService.java
  8. 1 1
      ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/GenUtils.java
  9. 51 14
      ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java
  10. 39 21
      ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml
  11. 2 2
      ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/controller.java.vm
  12. 22 2
      ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/domain.java.vm
  13. 30 0
      ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/mapper.java.vm
  14. 57 0
      ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/serviceImpl.java.vm
  15. 76 0
      ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/sub-domain.java.vm
  16. 1 1
      ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm
  17. 87 4
      ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm
  18. 41 1
      ruoyi-modules/ruoyi-gen/src/main/resources/vm/xml/mapper.xml.vm
  19. 4 1
      ruoyi-ui/src/views/tool/gen/editTable.vue
  20. 79 8
      ruoyi-ui/src/views/tool/gen/genInfoForm.vue
  21. 1 1
      ruoyi-ui/src/views/tool/gen/index.vue
  22. 693 588
      sql/ry_20201128.sql

+ 3 - 0
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/GenConstants.java

@@ -13,6 +13,9 @@ public class GenConstants
13 13
     /** 树表(增删改查) */
14 14
     public static final String TPL_TREE = "tree";
15 15
 
16
+    /** 主子表(增删改查) */
17
+    public static final String TPL_SUB = "sub";
18
+
16 19
     /** 树编码字段 */
17 20
     public static final String TREE_CODE = "treeCode";
18 21
 

+ 2 - 0
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/controller/GenController.java

@@ -63,10 +63,12 @@ public class GenController extends BaseController
63 63
     public AjaxResult getInfo(@PathVariable Long talbleId)
64 64
     {
65 65
         GenTable table = genTableService.selectGenTableById(talbleId);
66
+        List<GenTable> tables = genTableService.selectGenTableAll();
66 67
         List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(talbleId);
67 68
         Map<String, Object> map = new HashMap<String, Object>();
68 69
         map.put("info", table);
69 70
         map.put("rows", list);
71
+        map.put("tables", tables);
70 72
         return AjaxResult.success(map);
71 73
     }
72 74
 

+ 48 - 1
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java

@@ -28,11 +28,17 @@ public class GenTable extends BaseEntity
28 28
     @NotBlank(message = "表描述不能为空")
29 29
     private String tableComment;
30 30
 
31
+    /** 关联父表的表名 */
32
+    private String subTableName;
33
+
34
+    /** 本表关联父表的外键名 */
35
+    private String subTableFkName;
36
+
31 37
     /** 实体类名称(首字母大写) */
32 38
     @NotBlank(message = "实体类名称不能为空")
33 39
     private String className;
34 40
 
35
-    /** 使用的模板(crud单表操作 tree树表操作) */
41
+    /** 使用的模板(crud单表操作 tree树表操作 sub主子表操作) */
36 42
     private String tplCategory;
37 43
 
38 44
     /** 生成包路径 */
@@ -64,6 +70,9 @@ public class GenTable extends BaseEntity
64 70
     /** 主键信息 */
65 71
     private GenTableColumn pkColumn;
66 72
 
73
+    /** 子表信息 */
74
+    private GenTable subTable;
75
+
67 76
     /** 表列信息 */
68 77
     @Valid
69 78
     private List<GenTableColumn> columns;
@@ -116,6 +125,26 @@ public class GenTable extends BaseEntity
116 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 148
     public String getClassName()
120 149
     {
121 150
         return className;
@@ -216,6 +245,15 @@ public class GenTable extends BaseEntity
216 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
+    }
219 257
     public List<GenTableColumn> getColumns()
220 258
     {
221 259
         return columns;
@@ -286,6 +324,15 @@ public class GenTable extends BaseEntity
286 324
         this.parentMenuName = parentMenuName;
287 325
     }
288 326
 
327
+    public boolean isSub()
328
+    {
329
+        return isSub(this.tplCategory);
330
+    }
331
+
332
+    public static boolean isSub(String tplCategory)
333
+    {
334
+        return tplCategory != null && StringUtils.equals(GenConstants.TPL_SUB, tplCategory);
335
+    }
289 336
     public boolean isTree()
290 337
     {
291 338
         return isTree(this.tplCategory);

+ 5 - 0
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTableColumn.java

@@ -139,6 +139,11 @@ public class GenTableColumn extends BaseEntity
139 139
         return javaField;
140 140
     }
141 141
 
142
+    public String getCapJavaField()
143
+    {
144
+        return StringUtils.capitalize(javaField);
145
+    }
146
+
142 147
     public void setIsPk(String isPk)
143 148
     {
144 149
         this.isPk = isPk;

+ 7 - 0
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableMapper.java

@@ -35,6 +35,13 @@ public interface GenTableMapper
35 35
     public List<GenTable> selectDbTableListByNames(String[] tableNames);
36 36
 
37 37
     /**
38
+     * 查询所有表信息
39
+     * 
40
+     * @return 表信息集合
41
+     */
42
+    public List<GenTable> selectGenTableAll();
43
+
44
+    /**
38 45
      * 查询表ID业务信息
39 46
      * 
40 47
      * @param id 业务ID

+ 70 - 13
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java

@@ -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 119
      * @param genTable 业务信息
@@ -179,14 +190,16 @@ public class GenTableServiceImpl implements IGenTableService
179 190
      * @param tableId 表编号
180 191
      * @return 预览数据列表
181 192
      */
193
+    @Override
182 194
     public Map<String, String> previewCode(Long tableId)
183 195
     {
184 196
         Map<String, String> dataMap = new LinkedHashMap<>();
185 197
         // 查询表信息
186 198
         GenTable table = genTableMapper.selectGenTableById(tableId);
187
-        // 查询列信息
188
-        List<GenTableColumn> columns = table.getColumns();
189
-        setPkColumn(table, columns);
199
+        // 设置主子表信息
200
+        setSubTable(table);
201
+        // 设置主键列信息
202
+        setPkColumn(table);
190 203
         VelocityInitializer.initVelocity();
191 204
 
192 205
         VelocityContext context = VelocityUtils.prepareContext(table);
@@ -230,9 +243,10 @@ public class GenTableServiceImpl implements IGenTableService
230 243
     {
231 244
         // 查询表信息
232 245
         GenTable table = genTableMapper.selectGenTableByName(tableName);
233
-        // 查询列信息
234
-        List<GenTableColumn> columns = table.getColumns();
235
-        setPkColumn(table, columns);
246
+        // 设置主子表信息
247
+        setSubTable(table);
248
+        // 设置主键列信息
249
+        setPkColumn(table);
236 250
 
237 251
         VelocityInitializer.initVelocity();
238 252
 
@@ -275,6 +289,10 @@ public class GenTableServiceImpl implements IGenTableService
275 289
         List<String> tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
276 290
 
277 291
         List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
292
+        if (StringUtils.isEmpty(dbTableColumns))
293
+        {
294
+            throw new CustomException("同步数据失败,原表结构不存在");
295
+        }
278 296
         List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
279 297
 
280 298
         dbTableColumns.forEach(column -> {
@@ -318,9 +336,10 @@ public class GenTableServiceImpl implements IGenTableService
318 336
     {
319 337
         // 查询表信息
320 338
         GenTable table = genTableMapper.selectGenTableByName(tableName);
321
-        // 查询列信息
322
-        List<GenTableColumn> columns = table.getColumns();
323
-        setPkColumn(table, columns);
339
+        // 设置主子表信息
340
+        setSubTable(table);
341
+        // 设置主键列信息
342
+        setPkColumn(table);
324 343
 
325 344
         VelocityInitializer.initVelocity();
326 345
 
@@ -374,6 +393,17 @@ public class GenTableServiceImpl implements IGenTableService
374 393
             {
375 394
                 throw new CustomException("树名称字段不能为空");
376 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
+            }
377 407
         }
378 408
     }
379 409
 
@@ -381,11 +411,10 @@ public class GenTableServiceImpl implements IGenTableService
381 411
      * 设置主键列信息
382 412
      * 
383 413
      * @param table 业务表信息
384
-     * @param columns 业务字段列表
385 414
      */
386
-    public void setPkColumn(GenTable table, List<GenTableColumn> columns)
415
+    public void setPkColumn(GenTable table)
387 416
     {
388
-        for (GenTableColumn column : columns)
417
+        for (GenTableColumn column : table.getColumns())
389 418
         {
390 419
             if (column.isPk())
391 420
             {
@@ -395,7 +424,35 @@ public class GenTableServiceImpl implements IGenTableService
395 424
         }
396 425
         if (StringUtils.isNull(table.getPkColumn()))
397 426
         {
398
-            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
+     * @param table 业务表信息
449
+     */
450
+    public void setSubTable(GenTable table)
451
+    {
452
+        String subTableName = table.getSubTableName();
453
+        if (StringUtils.isNotEmpty(subTableName))
454
+        {
455
+            table.setSubTable(genTableMapper.selectGenTableByName(subTableName));
399 456
         }
400 457
     }
401 458
 

+ 7 - 0
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableService.java

@@ -36,6 +36,13 @@ public interface IGenTableService
36 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 48
      * @param id 业务ID

+ 1 - 1
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/GenUtils.java

@@ -59,7 +59,7 @@ public class GenUtils
59 59
         {
60 60
             column.setHtmlType(GenConstants.HTML_INPUT);
61 61
 
62
-            // 如果是浮点型
62
+            // 如果是浮点型 统一用BigDecimal
63 63
             String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ",");
64 64
             if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0)
65 65
             {

+ 51 - 14
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java

@@ -23,13 +23,13 @@ public class VelocityUtils
23 23
 
24 24
     /** mybatis空间路径 */
25 25
     private static final String MYBATIS_PATH = "main/resources/mapper";
26
-    
26
+
27 27
     /** 默认上级菜单,系统工具 */
28 28
     private static final String DEFAULT_PARENT_MENU_ID = "3";
29 29
 
30 30
     /**
31 31
      * 设置模板变量信息
32
-     * 
32
+     *
33 33
      * @return 模板列表
34 34
      */
35 35
     public static VelocityContext prepareContext(GenTable genTable)
@@ -54,7 +54,7 @@ public class VelocityUtils
54 54
         velocityContext.put("author", genTable.getFunctionAuthor());
55 55
         velocityContext.put("datetime", DateUtils.getDate());
56 56
         velocityContext.put("pkColumn", genTable.getPkColumn());
57
-        velocityContext.put("importList", getImportList(genTable.getColumns()));
57
+        velocityContext.put("importList", getImportList(genTable));
58 58
         velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName));
59 59
         velocityContext.put("columns", genTable.getColumns());
60 60
         velocityContext.put("table", genTable);
@@ -63,9 +63,13 @@ public class VelocityUtils
63 63
         {
64 64
             setTreeVelocityContext(velocityContext, genTable);
65 65
         }
66
+        if (GenConstants.TPL_SUB.equals(tplCategory))
67
+        {
68
+            setSubVelocityContext(velocityContext, genTable);
69
+        }
66 70
         return velocityContext;
67 71
     }
68
-    
72
+
69 73
     public static void setMenuVelocityContext(VelocityContext context, GenTable genTable)
70 74
     {
71 75
         String options = genTable.getOptions();
@@ -96,9 +100,27 @@ 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
+     *
102 124
      * @return 模板列表
103 125
      */
104 126
     public static List<String> getTemplateList(String tplCategory)
@@ -120,6 +142,11 @@ public class VelocityUtils
120 142
         {
121 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 150
         return templates;
124 151
     }
125 152
 
@@ -147,6 +174,10 @@ public class VelocityUtils
147 174
         {
148 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 181
         else if (template.contains("mapper.java.vm"))
151 182
         {
152 183
             fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className);
@@ -188,7 +219,7 @@ public class VelocityUtils
188 219
 
189 220
     /**
190 221
      * 获取包前缀
191
-     * 
222
+     *
192 223
      * @param packageName 包名称
193 224
      * @return 包前缀名称
194 225
      */
@@ -202,12 +233,18 @@ public class VelocityUtils
202 233
     /**
203 234
      * 根据列类型获取导入包
204 235
      * 
205
-     * @param columns 列集合
236
+     * @param genTable 业务表对象
206 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 243
         HashSet<String> importList = new HashSet<String>();
244
+        if (StringUtils.isNotNull(subGenTable))
245
+        {
246
+            importList.add("java.util.List");
247
+        }
211 248
         for (GenTableColumn column : columns)
212 249
         {
213 250
             if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType()))
@@ -225,7 +262,7 @@ public class VelocityUtils
225 262
 
226 263
     /**
227 264
      * 获取权限前缀
228
-     * 
265
+     *
229 266
      * @param moduleName 模块名称
230 267
      * @param businessName 业务名称
231 268
      * @return 返回权限前缀
@@ -237,7 +274,7 @@ public class VelocityUtils
237 274
 
238 275
     /**
239 276
      * 获取上级菜单ID字段
240
-     * 
277
+     *
241 278
      * @param paramsObj 生成其他选项
242 279
      * @return 上级菜单ID字段
243 280
      */
@@ -252,7 +289,7 @@ public class VelocityUtils
252 289
 
253 290
     /**
254 291
      * 获取树编码
255
-     * 
292
+     *
256 293
      * @param paramsObj 生成其他选项
257 294
      * @return 树编码
258 295
      */
@@ -267,7 +304,7 @@ public class VelocityUtils
267 304
 
268 305
     /**
269 306
      * 获取树父编码
270
-     * 
307
+     *
271 308
      * @param paramsObj 生成其他选项
272 309
      * @return 树父编码
273 310
      */
@@ -282,7 +319,7 @@ public class VelocityUtils
282 319
 
283 320
     /**
284 321
      * 获取树名称
285
-     * 
322
+     *
286 323
      * @param paramsObj 生成其他选项
287 324
      * @return 树名称
288 325
      */
@@ -297,7 +334,7 @@ public class VelocityUtils
297 334
 
298 335
     /**
299 336
      * 获取需要在哪一列上面显示展开按钮
300
-     * 
337
+     *
301 338
      * @param genTable 业务表对象
302 339
      * @return 展开按钮列序号
303 340
      */

+ 39 - 21
ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml

@@ -5,24 +5,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
5 5
 <mapper namespace="com.ruoyi.gen.mapper.GenTableMapper">
6 6
 
7 7
 	<resultMap type="GenTable" id="GenTableResult">
8
-	    <id     property="tableId"        column="table_id"        />
9
-		<result property="tableName"      column="table_name"      />
10
-		<result property="tableComment"   column="table_comment"   />
11
-		<result property="className"      column="class_name"      />
12
-		<result property="tplCategory"    column="tpl_category"    />
13
-		<result property="packageName"    column="package_name"    />
14
-		<result property="moduleName"     column="module_name"     />
15
-		<result property="businessName"   column="business_name"   />
16
-		<result property="functionName"   column="function_name"   />
17
-		<result property="functionAuthor" column="function_author" />
18
-		<result property="genType"        column="gen_type"        />
19
-		<result property="genPath"        column="gen_path"        />
20
-		<result property="options"        column="options"         />
21
-		<result property="createBy"       column="create_by"       />
22
-		<result property="createTime"     column="create_time"     />
23
-		<result property="updateBy"       column="update_by"       />
24
-		<result property="updateTime"     column="update_time"     />
25
-		<result property="remark"         column="remark"          />
8
+	    <id     property="tableId"        column="table_id"          />
9
+		<result property="tableName"      column="table_name"        />
10
+		<result property="tableComment"   column="table_comment"     />
11
+		<result property="subTableName"   column="sub_table_name"    />
12
+		<result property="subTableFkName" column="sub_table_fk_name" />
13
+		<result property="className"      column="class_name"        />
14
+		<result property="tplCategory"    column="tpl_category"      />
15
+		<result property="packageName"    column="package_name"      />
16
+		<result property="moduleName"     column="module_name"       />
17
+		<result property="businessName"   column="business_name"     />
18
+		<result property="functionName"   column="function_name"     />
19
+		<result property="functionAuthor" column="function_author"   />
20
+		<result property="genType"        column="gen_type"          />
21
+		<result property="genPath"        column="gen_path"          />
22
+		<result property="options"        column="options"           />
23
+		<result property="createBy"       column="create_by"         />
24
+		<result property="createTime"     column="create_time"       />
25
+		<result property="updateBy"       column="update_by"         />
26
+		<result property="updateTime"     column="update_time"       />
27
+		<result property="remark"         column="remark"            />
26 28
 		<collection  property="columns"  javaType="java.util.List"  resultMap="GenTableColumnResult" />
27 29
 	</resultMap>
28 30
 	
@@ -52,7 +54,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
52 54
     </resultMap>
53 55
 	
54 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 58
     </sql>
57 59
     
58 60
     <select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult">
@@ -84,6 +86,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
84 86
 		<if test="tableComment != null and tableComment != ''">
85 87
 			AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
86 88
 		</if>
89
+		<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
90
+			AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
91
+		</if>
92
+		<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
93
+			AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
94
+		</if>
87 95
 	</select>
88 96
 	
89 97
 	<select id="selectDbTableListByNames" resultMap="GenTableResult">
@@ -102,7 +110,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
102 110
 	</select>
103 111
 	
104 112
 	<select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
105
-	    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,
106 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
107 115
 		FROM gen_table t
108 116
 			 LEFT JOIN gen_table_column c ON t.table_id = c.table_id
@@ -110,13 +118,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
110 118
 	</select>
111 119
 	
112 120
 	<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
113
-	    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,
114 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
115 123
 		FROM gen_table t
116 124
 			 LEFT JOIN gen_table_column c ON t.table_id = c.table_id
117 125
 		where t.table_name = #{tableName} order by c.sort
118 126
 	</select>
119 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
+	
120 136
 	<insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId">
121 137
         insert into gen_table (
122 138
 			<if test="tableName != null">table_name,</if>
@@ -156,6 +172,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
156 172
         <set>
157 173
             <if test="tableName != null">table_name = #{tableName},</if>
158 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>
159 177
             <if test="className != null and className != ''">class_name = #{className},</if>
160 178
             <if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if>
161 179
             <if test="genType != null and genType != ''">gen_type = #{genType},</if>

+ 2 - 2
ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/controller.java.vm

@@ -20,7 +20,7 @@ import ${packageName}.service.I${ClassName}Service;
20 20
 import com.ruoyi.common.core.web.controller.BaseController;
21 21
 import com.ruoyi.common.core.web.domain.AjaxResult;
22 22
 import com.ruoyi.common.core.utils.poi.ExcelUtil;
23
-#if($table.crud)
23
+#if($table.crud || $table.sub)
24 24
 import com.ruoyi.common.core.web.page.TableDataInfo;
25 25
 #elseif($table.tree)
26 26
 #end
@@ -43,7 +43,7 @@ public class ${ClassName}Controller extends BaseController
43 43
      */
44 44
     @PreAuthorize(hasPermi = "${permissionPrefix}:list")
45 45
     @GetMapping("/list")
46
-#if($table.crud)
46
+#if($table.crud || $table.sub)
47 47
     public TableDataInfo list(${ClassName} ${className})
48 48
     {
49 49
         startPage();

+ 22 - 2
ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/domain.java.vm

@@ -6,7 +6,7 @@ import ${import};
6 6
 import org.apache.commons.lang3.builder.ToStringBuilder;
7 7
 import org.apache.commons.lang3.builder.ToStringStyle;
8 8
 import com.ruoyi.common.core.annotation.Excel;
9
-#if($table.crud)
9
+#if($table.crud || $table.sub)
10 10
 import com.ruoyi.common.core.web.domain.BaseEntity;
11 11
 #elseif($table.tree)
12 12
 import com.ruoyi.common.core.web.domain.TreeEntity;
@@ -18,7 +18,7 @@ import com.ruoyi.common.core.web.domain.TreeEntity;
18 18
  * @author ${author}
19 19
  * @date ${datetime}
20 20
  */
21
-#if($table.crud)
21
+#if($table.crud || $table.sub)
22 22
 #set($Entity="BaseEntity")
23 23
 #elseif($table.tree)
24 24
 #set($Entity="TreeEntity")
@@ -50,6 +50,11 @@ public class ${ClassName} extends ${Entity}
50 50
 
51 51
 #end
52 52
 #end
53
+#if($table.sub)
54
+    /** $table.subTable.functionName信息 */
55
+    private List<${subClassName}> ${subclassName}List;
56
+
57
+#end
53 58
 #foreach ($column in $columns)
54 59
 #if(!$table.isSuperColumn($column.javaField))
55 60
 #if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]"))
@@ -69,6 +74,18 @@ public class ${ClassName} extends ${Entity}
69 74
 #end
70 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 89
     @Override
73 90
     public String toString() {
74 91
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
@@ -80,6 +97,9 @@ public class ${ClassName} extends ${Entity}
80 97
 #end
81 98
             .append("${column.javaField}", get${AttrName}())
82 99
 #end
100
+#if($table.sub)
101
+            .append("${subclassName}List", get${subClassName}List())
102
+#end
83 103
             .toString();
84 104
     }
85 105
 }

+ 30 - 0
ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/mapper.java.vm

@@ -2,6 +2,9 @@ package ${packageName}.mapper;
2 2
 
3 3
 import java.util.List;
4 4
 import ${packageName}.domain.${ClassName};
5
+#if($table.sub)
6
+import ${packageName}.domain.${subClassName};
7
+#end
5 8
 
6 9
 /**
7 10
  * ${functionName}Mapper接口
@@ -58,4 +61,31 @@ public interface ${ClassName}Mapper
58 61
      * @return 结果
59 62
      */
60 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
 }

+ 57 - 0
ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/serviceImpl.java.vm

@@ -9,6 +9,12 @@ import com.ruoyi.common.core.utils.DateUtils;
9 9
 #end
10 10
 import org.springframework.beans.factory.annotation.Autowired;
11 11
 import org.springframework.stereotype.Service;
12
+#if($table.sub)
13
+import java.util.ArrayList;
14
+import com.ruoyi.common.core.utils.StringUtils;
15
+import org.springframework.transaction.annotation.Transactional;
16
+import ${packageName}.domain.${subClassName};
17
+#end
12 18
 import ${packageName}.mapper.${ClassName}Mapper;
13 19
 import ${packageName}.domain.${ClassName};
14 20
 import ${packageName}.service.I${ClassName}Service;
@@ -55,6 +61,9 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
55 61
      * @param ${className} ${functionName}
56 62
      * @return 结果
57 63
      */
64
+#if($table.sub)
65
+    @Transactional
66
+#end
58 67
     @Override
59 68
     public int insert${ClassName}(${ClassName} ${className})
60 69
     {
@@ -63,7 +72,13 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
63 72
         ${className}.setCreateTime(DateUtils.getNowDate());
64 73
 #end
65 74
 #end
75
+#if($table.sub)
76
+        int rows = ${className}Mapper.insert${ClassName}(${className});
77
+        insert${subClassName}(${className});
78
+        return rows;
79
+#else
66 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 87
      * @param ${className} ${functionName}
73 88
      * @return 结果
74 89
      */
90
+#if($table.sub)
91
+    @Transactional
92
+#end
75 93
     @Override
76 94
     public int update${ClassName}(${ClassName} ${className})
77 95
     {
@@ -80,6 +98,10 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
80 98
         ${className}.setUpdateTime(DateUtils.getNowDate());
81 99
 #end
82 100
 #end
101
+#if($table.sub)
102
+        ${className}Mapper.delete${subClassName}By${subTableFkClassName}(${className}.get${pkColumn.capJavaField}());
103
+        insert${subClassName}(${className});
104
+#end
83 105
         return ${className}Mapper.update${ClassName}(${className});
84 106
     }
85 107
 
@@ -89,9 +111,15 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
89 111
      * @param ${pkColumn.javaField}s 需要删除的${functionName}ID
90 112
      * @return 结果
91 113
      */
114
+#if($table.sub)
115
+    @Transactional
116
+#end
92 117
     @Override
93 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 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 132
     @Override
105 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 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
 }

+ 76 - 0
ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/sub-domain.java.vm

@@ -0,0 +1,76 @@
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.core.annotation.Excel;
9
+import com.ruoyi.common.core.web.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
+}

+ 1 - 1
ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm

@@ -73,7 +73,7 @@
73 73
       <el-col :span="1.5">
74 74
         <el-button
75 75
           type="primary"
76
-		  plain
76
+          plain
77 77
           icon="el-icon-plus"
78 78
           size="mini"
79 79
           @click="handleAdd"

+ 87 - 4
ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm

@@ -73,7 +73,7 @@
73 73
       <el-col :span="1.5">
74 74
         <el-button
75 75
           type="primary"
76
-		  plain
76
+          plain
77 77
           icon="el-icon-plus"
78 78
           size="mini"
79 79
           @click="handleAdd"
@@ -83,7 +83,7 @@
83 83
       <el-col :span="1.5">
84 84
         <el-button
85 85
           type="success"
86
-		  plain
86
+          plain
87 87
           icon="el-icon-edit"
88 88
           size="mini"
89 89
           :disabled="single"
@@ -94,7 +94,7 @@
94 94
       <el-col :span="1.5">
95 95
         <el-button
96 96
           type="danger"
97
-		  plain
97
+          plain
98 98
           icon="el-icon-delete"
99 99
           size="mini"
100 100
           :disabled="multiple"
@@ -105,7 +105,7 @@
105 105
       <el-col :span="1.5">
106 106
         <el-button
107 107
           type="warning"
108
-		  plain
108
+          plain
109 109
           icon="el-icon-download"
110 110
           size="mini"
111 111
           @click="handleExport"
@@ -266,6 +266,38 @@
266 266
 #end
267 267
 #end
268 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 301
       </el-form>
270 302
       <div slot="footer" class="dialog-footer">
271 303
         <el-button type="primary" @click="submitForm">确 定</el-button>
@@ -324,6 +356,10 @@ export default {
324 356
       loading: true,
325 357
       // 选中数组
326 358
       ids: [],
359
+#if($table.sub)
360
+      // 子表选中数据
361
+      checked${subClassName}: [],
362
+#end
327 363
       // 非单个禁用
328 364
       single: true,
329 365
       // 非多个禁用
@@ -334,6 +370,10 @@ export default {
334 370
       total: 0,
335 371
       // ${functionName}表格数据
336 372
       ${businessName}List: [],
373
+#if($table.sub)
374
+      // ${subTable.functionName}表格数据
375
+      ${subclassName}List: [],
376
+#end
337 377
       // 弹出层标题
338 378
       title: "",
339 379
       // 是否显示弹出层
@@ -456,6 +496,9 @@ export default {
456 496
 #end
457 497
 #end
458 498
       };
499
+#if($table.sub)
500
+      this.${subclassName}List = [];
501
+#end
459 502
       this.resetForm("form");
460 503
     },
461 504
     /** 搜索按钮操作 */
@@ -497,6 +540,9 @@ export default {
497 540
         this.form.$column.javaField = this.form.${column.javaField}.split(",");
498 541
 #end
499 542
 #end
543
+#if($table.sub)
544
+        this.${subclassName}List = response.data.${subclassName}List;
545
+#end
500 546
         this.open = true;
501 547
         this.title = "修改${functionName}";
502 548
       });
@@ -510,6 +556,9 @@ export default {
510 556
           this.form.$column.javaField = this.form.${column.javaField}.join(",");
511 557
 #end
512 558
 #end
559
+#if($table.sub)
560
+          this.form.${subclassName}List = this.${subclassName}List;
561
+#end
513 562
           if (this.form.${pkColumn.javaField} != null) {
514 563
             update${BusinessName}(this.form).then(response => {
515 564
               this.msgSuccess("修改成功");
@@ -540,6 +589,40 @@ export default {
540 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 627
     handleExport() {
545 628
       this.download('${moduleName}/${businessName}/export', {

+ 41 - 1
ruoyi-modules/ruoyi-gen/src/main/resources/vm/xml/mapper.xml.vm

@@ -9,6 +9,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
9 9
         <result property="${column.javaField}"    column="${column.columnName}"    />
10 10
 #end
11 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 25
     <sql id="select${ClassName}Vo">
14 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 58
         </where>
47 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 63
         <include refid="select${ClassName}Vo"/>
51 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 73
     </select>
53 74
         
54 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 112
             #{${pkColumn.javaField}}
92 113
         </foreach>
93 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 135
 </mapper>

+ 4 - 1
ruoyi-ui/src/views/tool/gen/editTable.vue

@@ -113,7 +113,7 @@
113 113
         </el-table>
114 114
       </el-tab-pane>
115 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 117
       </el-tab-pane>
118 118
     </el-tabs>
119 119
     <el-form label-width="100px">
@@ -144,6 +144,8 @@ export default {
144 144
       activeName: "cloum",
145 145
       // 表格的高度
146 146
       tableHeight: document.documentElement.scrollHeight - 245 + "px",
147
+      // 表信息
148
+      tables: [],
147 149
       // 表列信息
148 150
       cloumns: [],
149 151
       // 字典信息
@@ -161,6 +163,7 @@ export default {
161 163
       getGenTable(tableId).then(res => {
162 164
         this.cloumns = res.data.rows;
163 165
         this.info = res.data.info;
166
+        this.tables = res.data.tables;
164 167
       });
165 168
       /** 查询字典下拉列表 */
166 169
       getDictOptionselect().then(response => {

+ 79 - 8
ruoyi-ui/src/views/tool/gen/genInfoForm.vue

@@ -4,9 +4,10 @@
4 4
       <el-col :span="12">
5 5
         <el-form-item prop="tplCategory">
6 6
           <span slot="label">生成模板</span>
7
-          <el-select v-model="info.tplCategory">
7
+          <el-select v-model="info.tplCategory" @change="tplSelectChange">
8 8
             <el-option label="单表(增删改查)" value="crud" />
9 9
             <el-option label="树表(增删改查)" value="tree" />
10
+            <el-option label="主子表(增删改查)" value="sub" />
10 11
           </el-select>
11 12
         </el-form-item>
12 13
       </el-col>
@@ -126,8 +127,8 @@
126 127
           </span>
127 128
           <el-select v-model="info.treeCode" placeholder="请选择">
128 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 132
               :label="column.columnName + ':' + column.columnComment"
132 133
               :value="column.columnName"
133 134
             ></el-option>
@@ -144,8 +145,8 @@
144 145
           </span>
145 146
           <el-select v-model="info.treeParentCode" placeholder="请选择">
146 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 150
               :label="column.columnName + ':' + column.columnComment"
150 151
               :value="column.columnName"
151 152
             ></el-option>
@@ -162,8 +163,47 @@
162 163
           </span>
163 164
           <el-select v-model="info.treeName" placeholder="请选择">
164 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 207
               :label="column.columnName + ':' + column.columnComment"
168 208
               :value="column.columnName"
169 209
             ></el-option>
@@ -185,6 +225,10 @@ export default {
185 225
       type: Object,
186 226
       default: null
187 227
     },
228
+    tables: {
229
+      type: Array,
230
+      default: null
231
+    },
188 232
     menus: {
189 233
       type: Array,
190 234
       default: []
@@ -192,6 +236,7 @@ export default {
192 236
   },
193 237
   data() {
194 238
     return {
239
+      subColumns: [],
195 240
       rules: {
196 241
         tplCategory: [
197 242
           { required: true, message: "请选择生成模板", trigger: "blur" }
@@ -207,11 +252,16 @@ export default {
207 252
         ],
208 253
         functionName: [
209 254
           { required: true, message: "请输入生成功能名", trigger: "blur" }
210
-        ]
255
+        ],
211 256
       }
212 257
     };
213 258
   },
214 259
   created() {},
260
+  watch: {
261
+    'info.subTableName': function(val) {
262
+      this.setSubTableColumns(val);
263
+    }
264
+  },
215 265
   methods: {
216 266
     /** 转换菜单数据结构 */
217 267
     normalizer(node) {
@@ -223,6 +273,27 @@ export default {
223 273
         label: node.menuName,
224 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
 };

+ 1 - 1
ruoyi-ui/src/views/tool/gen/index.vue

@@ -84,7 +84,7 @@
84 84
     </el-row>
85 85
 
86 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 88
       <el-table-column label="序号" type="index" width="50" align="center">
89 89
         <template slot-scope="scope">
90 90
           <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>

Diferenças do arquivo suprimidas por serem muito extensas
+ 693 - 588
sql/ry_20201128.sql