Commit 58f83a2bd1ca3ea8d3111bc56aa662377e4b357d

Authored by YunaiV
1 parent 67c3a62d

梳理代码生成器的表结构,优化相关字段的命名

Showing 19 changed files with 365 additions and 611 deletions
ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java
... ... @@ -81,46 +81,6 @@ public class GenConstants {
81 81 public static final String[] TREE_ENTITY = {"parentName", "parentId", "orderNum", "ancestors", "children"};
82 82  
83 83 /**
84   - * 文本框
85   - */
86   - public static final String HTML_INPUT = "input";
87   -
88   - /**
89   - * 文本域
90   - */
91   - public static final String HTML_TEXTAREA = "textarea";
92   -
93   - /**
94   - * 下拉框
95   - */
96   - public static final String HTML_SELECT = "select";
97   -
98   - /**
99   - * 单选框
100   - */
101   - public static final String HTML_RADIO = "radio";
102   -
103   - /**
104   - * 复选框
105   - */
106   - public static final String HTML_CHECKBOX = "checkbox";
107   -
108   - /**
109   - * 日期控件
110   - */
111   - public static final String HTML_DATETIME = "datetime";
112   -
113   - /**
114   - * 上传控件
115   - */
116   - public static final String HTML_UPLOAD_IMAGE = "uploadImage";
117   -
118   - /**
119   - * 富文本控件
120   - */
121   - public static final String HTML_EDITOR = "editor";
122   -
123   - /**
124 84 * 字符串类型
125 85 */
126 86 public static final String TYPE_STRING = "String";
... ... @@ -150,13 +110,4 @@ public class GenConstants {
150 110 */
151 111 public static final String TYPE_DATE = "Date";
152 112  
153   - /**
154   - * 模糊查询
155   - */
156   - public static final String QUERY_LIKE = "LIKE";
157   -
158   - /**
159   - * 需要
160   - */
161   - public static final String REQUIRE = "1";
162 113 }
... ...
ruoyi-generator/pom.xml deleted
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<project xmlns="http://maven.apache.org/POM/4.0.0"
3   - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4   - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5   - <parent>
6   - <artifactId>ruoyi</artifactId>
7   - <groupId>com.ruoyi</groupId>
8   - <version>3.3.0</version>
9   - </parent>
10   - <modelVersion>4.0.0</modelVersion>
11   -
12   - <artifactId>ruoyi-generator</artifactId>
13   -
14   - <description>
15   - generator代码生成
16   - </description>
17   -
18   - <dependencies>
19   -
20   - <!--velocity代码生成使用模板 -->
21   - <dependency>
22   - <groupId>org.apache.velocity</groupId>
23   - <artifactId>velocity</artifactId>
24   - </dependency>
25   -
26   - <!-- 通用工具-->
27   - <dependency>
28   - <groupId>com.ruoyi</groupId>
29   - <artifactId>ruoyi-common</artifactId>
30   - </dependency>
31   -
32   - </dependencies>
33   -
34   -</project>
35 0 \ No newline at end of file
ruoyi-generator/src/main/java/com/ruoyi/generator/config/GenConfig.java
... ... @@ -7,14 +7,13 @@ import org.springframework.stereotype.Component;
7 7  
8 8 /**
9 9 * 读取代码生成相关配置
10   - *
  10 + *
11 11 * @author ruoyi
12 12 */
13 13 @Component
14 14 @ConfigurationProperties(prefix = "gen")
15 15 @PropertySource(value = { "classpath:generator.yml" })
16   -public class GenConfig
17   -{
  16 +public class GenConfig {
18 17 /** 作者 */
19 18 public static String author;
20 19  
... ...
ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java
... ... @@ -23,27 +23,11 @@ public class GenTable extends BaseEntity {
23 23 private String packageName;
24 24  
25 25 /**
26   - * 生成代码方式(0zip压缩包 1自定义路径)
27   - */
28   - private String genType;
29   -
30   - /**
31   - * 生成路径(不填默认项目路径)
32   - */
33   - private String genPath;
34   -
35   - /**
36 26 * 主键信息
37 27 */
38 28 private GenTableColumn pkColumn;
39 29  
40 30 /**
41   - * 表列信息
42   - */
43   - @Valid
44   - private List<GenTableColumn> columns;
45   -
46   - /**
47 31 * 其它生成选项
48 32 */
49 33 private String options;
... ...
ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java
1 1 package com.ruoyi.generator.domain;
2 2  
3 3 import javax.validation.constraints.NotBlank;
  4 +
4 5 import com.ruoyi.common.core.domain.BaseEntity;
5 6 import com.ruoyi.common.utils.StringUtils;
6 7  
... ... @@ -9,202 +10,9 @@ import com.ruoyi.common.utils.StringUtils;
9 10 *
10 11 * @author ruoyi
11 12 */
12   -public class GenTableColumn extends BaseEntity
13   -{
14   - private static final long serialVersionUID = 1L;
15   -
16   - /** 编号 */
17   - private Long columnId;
18   -
19   - /** 归属表编号 */
20   - private Long tableId;
21   -
22   - /** 列名称 */
23   - private String columnName;
24   -
25   - /** 列描述 */
26   - private String columnComment;
27   -
28   - /** 列类型 */
29   - private String columnType;
30   -
31   - /** JAVA类型 */
32   - private String javaType;
33   -
34   - /** JAVA字段名 */
35   - @NotBlank(message = "Java属性不能为空")
36   - private String javaField;
37   -
38   - /** 是否主键(1是) */
39   - private String isPk;
40   -
41   - /** 是否自增(1是) */
42   - private String isIncrement;
43   -
44   - /** 是否必填(1是) */
45   - private String isRequired;
46   -
47   - /** 是否为插入字段(1是) */
48   - private String isInsert;
49   -
50   - /** 是否编辑字段(1是) */
51   - private String isEdit;
52   -
53   - /** 是否列表字段(1是) */
54   - private String isList;
55   -
56   - /** 是否查询字段(1是) */
57   - private String isQuery;
58   -
59   - /** 查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围) */
60   - private String queryType;
61   -
62   - /** 显示类型(input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、upload上传控件、editor富文本控件) */
63   - private String htmlType;
64   -
65   - /** 字典类型 */
66   - private String dictType;
67   -
68   - /** 排序 */
69   - private Integer sort;
70   -
71   - public boolean isPk()
72   - {
73   - return isPk(this.isPk);
74   - }
75   -
76   - public boolean isPk(String isPk)
77   - {
78   - return isPk != null && StringUtils.equals("1", isPk);
79   - }
80   -
81   - public String getIsIncrement()
82   - {
83   - return isIncrement;
84   - }
85   -
86   - public void setIsIncrement(String isIncrement)
87   - {
88   - this.isIncrement = isIncrement;
89   - }
90   -
91   - public boolean isIncrement()
92   - {
93   - return isIncrement(this.isIncrement);
94   - }
95   -
96   - public boolean isIncrement(String isIncrement)
97   - {
98   - return isIncrement != null && StringUtils.equals("1", isIncrement);
99   - }
100   -
101   - public void setIsRequired(String isRequired)
102   - {
103   - this.isRequired = isRequired;
104   - }
105   -
106   - public String getIsRequired()
107   - {
108   - return isRequired;
109   - }
110   -
111   - public boolean isRequired()
112   - {
113   - return isRequired(this.isRequired);
114   - }
  13 +public class GenTableColumn extends BaseEntity {
115 14  
116   - public boolean isRequired(String isRequired)
117   - {
118   - return isRequired != null && StringUtils.equals("1", isRequired);
119   - }
120   -
121   - public void setIsInsert(String isInsert)
122   - {
123   - this.isInsert = isInsert;
124   - }
125   -
126   - public String getIsInsert()
127   - {
128   - return isInsert;
129   - }
130   -
131   - public boolean isInsert()
132   - {
133   - return isInsert(this.isInsert);
134   - }
135   -
136   - public boolean isInsert(String isInsert)
137   - {
138   - return isInsert != null && StringUtils.equals("1", isInsert);
139   - }
140   -
141   - public void setIsEdit(String isEdit)
142   - {
143   - this.isEdit = isEdit;
144   - }
145   -
146   - public String getIsEdit()
147   - {
148   - return isEdit;
149   - }
150   -
151   - public boolean isEdit()
152   - {
153   - return isInsert(this.isEdit);
154   - }
155   -
156   - public boolean isEdit(String isEdit)
157   - {
158   - return isEdit != null && StringUtils.equals("1", isEdit);
159   - }
160   -
161   - public void setIsList(String isList)
162   - {
163   - this.isList = isList;
164   - }
165   -
166   - public String getIsList()
167   - {
168   - return isList;
169   - }
170   -
171   - public boolean isList()
172   - {
173   - return isList(this.isList);
174   - }
175   -
176   - public boolean isList(String isList)
177   - {
178   - return isList != null && StringUtils.equals("1", isList);
179   - }
180   -
181   - public void setIsQuery(String isQuery)
182   - {
183   - this.isQuery = isQuery;
184   - }
185   -
186   - public String getIsQuery()
187   - {
188   - return isQuery;
189   - }
190   -
191   - public boolean isQuery()
192   - {
193   - return isQuery(this.isQuery);
194   - }
195   -
196   - public boolean isQuery(String isQuery)
197   - {
198   - return isQuery != null && StringUtils.equals("1", isQuery);
199   - }
200   -
201   - public boolean isSuperColumn()
202   - {
203   - return isSuperColumn(this.javaField);
204   - }
205   -
206   - public static boolean isSuperColumn(String javaField)
207   - {
  15 + public static boolean isSuperColumn(String javaField) {
208 16 return StringUtils.equalsAnyIgnoreCase(javaField,
209 17 // BaseEntity
210 18 "createBy", "createTime", "updateBy", "updateTime", "remark",
... ... @@ -212,37 +20,13 @@ public class GenTableColumn extends BaseEntity
212 20 "parentName", "parentId", "orderNum", "ancestors");
213 21 }
214 22  
215   - public boolean isUsableColumn()
216   - {
  23 + public boolean isUsableColumn() {
217 24 return isUsableColumn(javaField);
218 25 }
219 26  
220   - public static boolean isUsableColumn(String javaField)
221   - {
  27 + public static boolean isUsableColumn(String javaField) {
222 28 // isSuperColumn()中的名单用于避免生成多余Domain属性,若某些属性在生成页面时需要用到不能忽略,则放在此处白名单
223 29 return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark");
224 30 }
225 31  
226   - public String readConverterExp()
227   - {
228   - String remarks = StringUtils.substringBetween(this.columnComment, "(", ")");
229   - StringBuffer sb = new StringBuffer();
230   - if (StringUtils.isNotEmpty(remarks))
231   - {
232   - for (String value : remarks.split(" "))
233   - {
234   - if (StringUtils.isNotEmpty(value))
235   - {
236   - Object startStr = value.subSequence(0, 1);
237   - String endStr = value.substring(1);
238   - sb.append("").append(startStr).append("=").append(endStr).append(",");
239   - }
240   - }
241   - return sb.deleteCharAt(sb.length() - 1).toString();
242   - }
243   - else
244   - {
245   - return this.columnComment;
246   - }
247   - }
248 32 }
... ...
ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java
1 1 package com.ruoyi.generator.mapper;
2 2  
3 3 import java.util.List;
  4 +
4 5 import com.ruoyi.generator.domain.GenTableColumn;
5 6  
6 7 /**
7 8 * 业务字段 数据层
8   - *
  9 + *
9 10 * @author ruoyi
10 11 */
11   -public interface GenTableColumnMapper
12   -{
  12 +public interface GenTableColumnMapper {
13 13 /**
14 14 * 根据表名称查询列信息
15   - *
  15 + *
16 16 * @param tableName 表名称
17 17 * @return 列信息
18 18 */
... ... @@ -20,7 +20,7 @@ public interface GenTableColumnMapper
20 20  
21 21 /**
22 22 * 查询业务字段列表
23   - *
  23 + *
24 24 * @param tableId 业务字段编号
25 25 * @return 业务字段集合
26 26 */
... ... @@ -28,7 +28,7 @@ public interface GenTableColumnMapper
28 28  
29 29 /**
30 30 * 新增业务字段
31   - *
  31 + *
32 32 * @param genTableColumn 业务字段信息
33 33 * @return 结果
34 34 */
... ... @@ -36,7 +36,7 @@ public interface GenTableColumnMapper
36 36  
37 37 /**
38 38 * 修改业务字段
39   - *
  39 + *
40 40 * @param genTableColumn 业务字段信息
41 41 * @return 结果
42 42 */
... ... @@ -44,7 +44,7 @@ public interface GenTableColumnMapper
44 44  
45 45 /**
46 46 * 删除业务字段
47   - *
  47 + *
48 48 * @param genTableColumns 列数据
49 49 * @return 结果
50 50 */
... ... @@ -52,7 +52,7 @@ public interface GenTableColumnMapper
52 52  
53 53 /**
54 54 * 批量删除业务字段
55   - *
  55 + *
56 56 * @param ids 需要删除的数据ID
57 57 * @return 结果
58 58 */
... ...
ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java
1 1 package com.ruoyi.generator.mapper;
2 2  
3 3 import java.util.List;
  4 +
4 5 import com.ruoyi.generator.domain.GenTable;
5 6  
6 7 /**
7 8 * 业务 数据层
8   - *
  9 + *
9 10 * @author ruoyi
10 11 */
11   -public interface GenTableMapper
12   -{
  12 +public interface GenTableMapper {
13 13 /**
14 14 * 查询业务列表
15   - *
  15 + *
16 16 * @param genTable 业务信息
17 17 * @return 业务集合
18 18 */
... ... @@ -20,7 +20,7 @@ public interface GenTableMapper
20 20  
21 21 /**
22 22 * 查询据库列表
23   - *
  23 + *
24 24 * @param genTable 业务信息
25 25 * @return 数据库表集合
26 26 */
... ... @@ -28,7 +28,7 @@ public interface GenTableMapper
28 28  
29 29 /**
30 30 * 查询据库列表
31   - *
  31 + *
32 32 * @param tableNames 表名称组
33 33 * @return 数据库表集合
34 34 */
... ... @@ -36,7 +36,7 @@ public interface GenTableMapper
36 36  
37 37 /**
38 38 * 查询表ID业务信息
39   - *
  39 + *
40 40 * @param id 业务ID
41 41 * @return 业务信息
42 42 */
... ... @@ -44,7 +44,7 @@ public interface GenTableMapper
44 44  
45 45 /**
46 46 * 查询表名称业务信息
47   - *
  47 + *
48 48 * @param tableName 表名称
49 49 * @return 业务信息
50 50 */
... ... @@ -52,7 +52,7 @@ public interface GenTableMapper
52 52  
53 53 /**
54 54 * 新增业务
55   - *
  55 + *
56 56 * @param genTable 业务信息
57 57 * @return 结果
58 58 */
... ... @@ -60,7 +60,7 @@ public interface GenTableMapper
60 60  
61 61 /**
62 62 * 修改业务
63   - *
  63 + *
64 64 * @param genTable 业务信息
65 65 * @return 结果
66 66 */
... ... @@ -68,7 +68,7 @@ public interface GenTableMapper
68 68  
69 69 /**
70 70 * 批量删除业务
71   - *
  71 + *
72 72 * @param ids 需要删除的数据ID
73 73 * @return 结果
74 74 */
... ...
ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java
1 1 package com.ruoyi.generator.service;
2 2  
3 3 import java.util.List;
  4 +
4 5 import org.springframework.beans.factory.annotation.Autowired;
5 6 import org.springframework.stereotype.Service;
6 7 import com.ruoyi.common.core.text.Convert;
... ... @@ -9,60 +10,55 @@ import com.ruoyi.generator.mapper.GenTableColumnMapper;
9 10  
10 11 /**
11 12 * 业务字段 服务层实现
12   - *
  13 + *
13 14 * @author ruoyi
14 15 */
15 16 @Service
16   -public class GenTableColumnServiceImpl implements IGenTableColumnService
17   -{
18   - @Autowired
19   - private GenTableColumnMapper genTableColumnMapper;
  17 +public class GenTableColumnServiceImpl implements IGenTableColumnService {
  18 + @Autowired
  19 + private GenTableColumnMapper genTableColumnMapper;
20 20  
21   - /**
  21 + /**
22 22 * 查询业务字段列表
23   - *
  23 + *
24 24 * @param tableId 业务字段编号
25 25 * @return 业务字段集合
26 26 */
27   - @Override
28   - public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId)
29   - {
30   - return genTableColumnMapper.selectGenTableColumnListByTableId(tableId);
31   - }
32   -
  27 + @Override
  28 + public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) {
  29 + return genTableColumnMapper.selectGenTableColumnListByTableId(tableId);
  30 + }
  31 +
33 32 /**
34 33 * 新增业务字段
35   - *
  34 + *
36 35 * @param genTableColumn 业务字段信息
37 36 * @return 结果
38 37 */
39   - @Override
40   - public int insertGenTableColumn(GenTableColumn genTableColumn)
41   - {
42   - return genTableColumnMapper.insertGenTableColumn(genTableColumn);
43   - }
44   -
45   - /**
  38 + @Override
  39 + public int insertGenTableColumn(GenTableColumn genTableColumn) {
  40 + return genTableColumnMapper.insertGenTableColumn(genTableColumn);
  41 + }
  42 +
  43 + /**
46 44 * 修改业务字段
47   - *
  45 + *
48 46 * @param genTableColumn 业务字段信息
49 47 * @return 结果
50 48 */
51   - @Override
52   - public int updateGenTableColumn(GenTableColumn genTableColumn)
53   - {
54   - return genTableColumnMapper.updateGenTableColumn(genTableColumn);
55   - }
  49 + @Override
  50 + public int updateGenTableColumn(GenTableColumn genTableColumn) {
  51 + return genTableColumnMapper.updateGenTableColumn(genTableColumn);
  52 + }
56 53  
57   - /**
  54 + /**
58 55 * 删除业务字段对象
59   - *
  56 + *
60 57 * @param ids 需要删除的数据ID
61 58 * @return 结果
62 59 */
63   - @Override
64   - public int deleteGenTableColumnByIds(String ids)
65   - {
66   - return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
67   - }
  60 + @Override
  61 + public int deleteGenTableColumnByIds(String ids) {
  62 + return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
  63 + }
68 64 }
... ...
ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java
... ... @@ -10,6 +10,7 @@ import java.util.Map;
10 10 import java.util.stream.Collectors;
11 11 import java.util.zip.ZipEntry;
12 12 import java.util.zip.ZipOutputStream;
  13 +
13 14 import org.apache.commons.io.IOUtils;
14 15 import org.apache.velocity.Template;
15 16 import org.apache.velocity.VelocityContext;
... ... @@ -38,12 +39,11 @@ import com.ruoyi.generator.util.VelocityUtils;
38 39  
39 40 /**
40 41 * 业务 服务层实现
41   - *
  42 + *
42 43 * @author ruoyi
43 44 */
44 45 @Service
45   -public class GenTableServiceImpl implements IGenTableService
46   -{
  46 +public class GenTableServiceImpl implements IGenTableService {
47 47 private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class);
48 48  
49 49 @Autowired
... ... @@ -54,13 +54,12 @@ public class GenTableServiceImpl implements IGenTableService
54 54  
55 55 /**
56 56 * 查询业务信息
57   - *
  57 + *
58 58 * @param id 业务ID
59 59 * @return 业务信息
60 60 */
61 61 @Override
62   - public GenTable selectGenTableById(Long id)
63   - {
  62 + public GenTable selectGenTableById(Long id) {
64 63 GenTable genTable = genTableMapper.selectGenTableById(id);
65 64 setTableFromOptions(genTable);
66 65 return genTable;
... ... @@ -68,57 +67,51 @@ public class GenTableServiceImpl implements IGenTableService
68 67  
69 68 /**
70 69 * 查询业务列表
71   - *
  70 + *
72 71 * @param genTable 业务信息
73 72 * @return 业务集合
74 73 */
75 74 @Override
76   - public List<GenTable> selectGenTableList(GenTable genTable)
77   - {
  75 + public List<GenTable> selectGenTableList(GenTable genTable) {
78 76 return genTableMapper.selectGenTableList(genTable);
79 77 }
80 78  
81 79 /**
82 80 * 查询据库列表
83   - *
  81 + *
84 82 * @param genTable 业务信息
85 83 * @return 数据库表集合
86 84 */
87 85 @Override
88   - public List<GenTable> selectDbTableList(GenTable genTable)
89   - {
  86 + public List<GenTable> selectDbTableList(GenTable genTable) {
90 87 return genTableMapper.selectDbTableList(genTable);
91 88 }
92 89  
93 90 /**
94 91 * 查询据库列表
95   - *
  92 + *
96 93 * @param tableNames 表名称组
97 94 * @return 数据库表集合
98 95 */
99 96 @Override
100   - public List<GenTable> selectDbTableListByNames(String[] tableNames)
101   - {
  97 + public List<GenTable> selectDbTableListByNames(String[] tableNames) {
102 98 return genTableMapper.selectDbTableListByNames(tableNames);
103 99 }
104 100  
105 101 /**
106 102 * 修改业务
107   - *
  103 + *
108 104 * @param genTable 业务信息
109 105 * @return 结果
110 106 */
111 107 @Override
112 108 @Transactional
113   - public void updateGenTable(GenTable genTable)
114   - {
  109 + public void updateGenTable(GenTable genTable) {
115 110 String options = JSON.toJSONString(genTable.getParams());
116 111 genTable.setOptions(options);
117 112 int row = genTableMapper.updateGenTable(genTable);
118   - if (row > 0)
119   - {
120   - for (GenTableColumn cenTableColumn : genTable.getColumns())
121   - {
  113 + if (row > 0) {
  114 + for (GenTableColumn cenTableColumn : genTable.getColumns()) {
122 115 genTableColumnMapper.updateGenTableColumn(cenTableColumn);
123 116 }
124 117 }
... ... @@ -126,62 +119,53 @@ public class GenTableServiceImpl implements IGenTableService
126 119  
127 120 /**
128 121 * 删除业务对象
129   - *
  122 + *
130 123 * @param tableIds 需要删除的数据ID
131 124 * @return 结果
132 125 */
133 126 @Override
134 127 @Transactional
135   - public void deleteGenTableByIds(Long[] tableIds)
136   - {
  128 + public void deleteGenTableByIds(Long[] tableIds) {
137 129 genTableMapper.deleteGenTableByIds(tableIds);
138 130 genTableColumnMapper.deleteGenTableColumnByIds(tableIds);
139 131 }
140 132  
141 133 /**
142 134 * 导入表结构
143   - *
  135 + *
144 136 * @param tableList 导入表列表
145 137 */
146 138 @Override
147 139 @Transactional
148   - public void importGenTable(List<GenTable> tableList)
149   - {
  140 + public void importGenTable(List<GenTable> tableList) {
150 141 String operName = SecurityUtils.getUsername();
151   - try
152   - {
153   - for (GenTable table : tableList)
154   - {
  142 + try {
  143 + for (GenTable table : tableList) {
155 144 String tableName = table.getTableName();
156 145 GenUtils.initTable(table, operName);
157 146 int row = genTableMapper.insertGenTable(table);
158   - if (row > 0)
159   - {
  147 + if (row > 0) {
160 148 // 保存列信息
161 149 List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
162   - for (GenTableColumn column : genTableColumns)
163   - {
  150 + for (GenTableColumn column : genTableColumns) {
164 151 GenUtils.initColumnField(column, table);
165 152 genTableColumnMapper.insertGenTableColumn(column);
166 153 }
167 154 }
168 155 }
169   - }
170   - catch (Exception e)
171   - {
  156 + } catch (Exception e) {
172 157 throw new CustomException("导入失败:" + e.getMessage());
173 158 }
174 159 }
175 160  
176 161 /**
177 162 * 预览代码
178   - *
  163 + *
179 164 * @param tableId 表编号
180 165 * @return 预览数据列表
181 166 */
182 167 @Override
183   - public Map<String, String> previewCode(Long tableId)
184   - {
  168 + public Map<String, String> previewCode(Long tableId) {
185 169 Map<String, String> dataMap = new LinkedHashMap<>();
186 170 // 查询表信息
187 171 GenTable table = genTableMapper.selectGenTableById(tableId);
... ... @@ -194,8 +178,7 @@ public class GenTableServiceImpl implements IGenTableService
194 178  
195 179 // 获取模板列表
196 180 List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
197   - for (String template : templates)
198   - {
  181 + for (String template : templates) {
199 182 // 渲染模板
200 183 StringWriter sw = new StringWriter();
201 184 Template tpl = Velocity.getTemplate(template, Constants.UTF8);
... ... @@ -207,13 +190,12 @@ public class GenTableServiceImpl implements IGenTableService
207 190  
208 191 /**
209 192 * 生成代码(下载方式)
210   - *
  193 + *
211 194 * @param tableName 表名称
212 195 * @return 数据
213 196 */
214 197 @Override
215   - public byte[] downloadCode(String tableName)
216   - {
  198 + public byte[] downloadCode(String tableName) {
217 199 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
218 200 ZipOutputStream zip = new ZipOutputStream(outputStream);
219 201 generatorCode(tableName, zip);
... ... @@ -223,12 +205,11 @@ public class GenTableServiceImpl implements IGenTableService
223 205  
224 206 /**
225 207 * 生成代码(自定义路径)
226   - *
  208 + *
227 209 * @param tableName 表名称
228 210 */
229 211 @Override
230   - public void generatorCode(String tableName)
231   - {
  212 + public void generatorCode(String tableName) {
232 213 // 查询表信息
233 214 GenTable table = genTableMapper.selectGenTableByName(tableName);
234 215 // 查询列信息
... ... @@ -241,21 +222,16 @@ public class GenTableServiceImpl implements IGenTableService
241 222  
242 223 // 获取模板列表
243 224 List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
244   - for (String template : templates)
245   - {
246   - if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm"))
247   - {
  225 + for (String template : templates) {
  226 + if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) {
248 227 // 渲染模板
249 228 StringWriter sw = new StringWriter();
250 229 Template tpl = Velocity.getTemplate(template, Constants.UTF8);
251 230 tpl.merge(context, sw);
252   - try
253   - {
  231 + try {
254 232 String path = getGenPath(table, template);
255 233 FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8);
256   - }
257   - catch (IOException e)
258   - {
  234 + } catch (IOException e) {
259 235 throw new CustomException("渲染模板失败,表名:" + table.getTableName());
260 236 }
261 237 }
... ... @@ -264,13 +240,12 @@ public class GenTableServiceImpl implements IGenTableService
264 240  
265 241 /**
266 242 * 同步数据库
267   - *
  243 + *
268 244 * @param tableName 表名称
269 245 */
270 246 @Override
271 247 @Transactional
272   - public void synchDb(String tableName)
273   - {
  248 + public void synchDb(String tableName) {
274 249 GenTable table = genTableMapper.selectGenTableByName(tableName);
275 250 List<GenTableColumn> tableColumns = table.getColumns();
276 251 List<String> tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
... ... @@ -279,33 +254,29 @@ public class GenTableServiceImpl implements IGenTableService
279 254 List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
280 255  
281 256 dbTableColumns.forEach(column -> {
282   - if (!tableColumnNames.contains(column.getColumnName()))
283   - {
  257 + if (!tableColumnNames.contains(column.getColumnName())) {
284 258 GenUtils.initColumnField(column, table);
285 259 genTableColumnMapper.insertGenTableColumn(column);
286 260 }
287 261 });
288 262  
289 263 List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
290   - if (StringUtils.isNotEmpty(delColumns))
291   - {
  264 + if (StringUtils.isNotEmpty(delColumns)) {
292 265 genTableColumnMapper.deleteGenTableColumns(delColumns);
293 266 }
294 267 }
295 268  
296 269 /**
297 270 * 批量生成代码(下载方式)
298   - *
  271 + *
299 272 * @param tableNames 表数组
300 273 * @return 数据
301 274 */
302 275 @Override
303   - public byte[] downloadCode(String[] tableNames)
304   - {
  276 + public byte[] downloadCode(String[] tableNames) {
305 277 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
306 278 ZipOutputStream zip = new ZipOutputStream(outputStream);
307   - for (String tableName : tableNames)
308   - {
  279 + for (String tableName : tableNames) {
309 280 generatorCode(tableName, zip);
310 281 }
311 282 IOUtils.closeQuietly(zip);
... ... @@ -315,8 +286,7 @@ public class GenTableServiceImpl implements IGenTableService
315 286 /**
316 287 * 查询表信息并生成代码
317 288 */
318   - private void generatorCode(String tableName, ZipOutputStream zip)
319   - {
  289 + private void generatorCode(String tableName, ZipOutputStream zip) {
320 290 // 查询表信息
321 291 GenTable table = genTableMapper.selectGenTableByName(tableName);
322 292 // 查询列信息
... ... @@ -329,23 +299,19 @@ public class GenTableServiceImpl implements IGenTableService
329 299  
330 300 // 获取模板列表
331 301 List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
332   - for (String template : templates)
333   - {
  302 + for (String template : templates) {
334 303 // 渲染模板
335 304 StringWriter sw = new StringWriter();
336 305 Template tpl = Velocity.getTemplate(template, Constants.UTF8);
337 306 tpl.merge(context, sw);
338   - try
339   - {
  307 + try {
340 308 // 添加到zip
341 309 zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table)));
342 310 IOUtils.write(sw.toString(), zip, Constants.UTF8);
343 311 IOUtils.closeQuietly(sw);
344   - zip.flush();
  312 + zip.flush();
345 313 zip.closeEntry();
346   - }
347   - catch (IOException e)
348   - {
  314 + } catch (IOException e) {
349 315 log.error("渲染模板失败,表名:" + table.getTableName(), e);
350 316 }
351 317 }
... ... @@ -353,26 +319,19 @@ public class GenTableServiceImpl implements IGenTableService
353 319  
354 320 /**
355 321 * 修改保存参数校验
356   - *
  322 + *
357 323 * @param genTable 业务信息
358 324 */
359 325 @Override
360   - public void validateEdit(GenTable genTable)
361   - {
362   - if (GenConstants.TPL_TREE.equals(genTable.getTplCategory()))
363   - {
  326 + public void validateEdit(GenTable genTable) {
  327 + if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) {
364 328 String options = JSON.toJSONString(genTable.getParams());
365 329 JSONObject paramsObj = JSONObject.parseObject(options);
366   - if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE)))
367   - {
  330 + if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) {
368 331 throw new CustomException("树编码字段不能为空");
369   - }
370   - else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE)))
371   - {
  332 + } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) {
372 333 throw new CustomException("树父编码字段不能为空");
373   - }
374   - else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME)))
375   - {
  334 + } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) {
376 335 throw new CustomException("树名称字段不能为空");
377 336 }
378 337 }
... ... @@ -380,42 +339,36 @@ public class GenTableServiceImpl implements IGenTableService
380 339  
381 340 /**
382 341 * 设置主键列信息
383   - *
384   - * @param table 业务表信息
  342 + *
  343 + * @param table 业务表信息
385 344 * @param columns 业务字段列表
386 345 */
387   - public void setPkColumn(GenTable table, List<GenTableColumn> columns)
388   - {
389   - for (GenTableColumn column : columns)
390   - {
391   - if (column.isPk())
392   - {
  346 + public void setPkColumn(GenTable table, List<GenTableColumn> columns) {
  347 + for (GenTableColumn column : columns) {
  348 + if (column.isPk()) {
393 349 table.setPkColumn(column);
394 350 break;
395 351 }
396 352 }
397   - if (StringUtils.isNull(table.getPkColumn()))
398   - {
  353 + if (StringUtils.isNull(table.getPkColumn())) {
399 354 table.setPkColumn(columns.get(0));
400 355 }
401 356 }
402 357  
403 358 /**
404 359 * 设置代码生成其他选项值
405   - *
  360 + *
406 361 * @param genTable 设置后的生成对象
407 362 */
408   - public void setTableFromOptions(GenTable genTable)
409   - {
  363 + public void setTableFromOptions(GenTable genTable) {
410 364 JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions());
411   - if (StringUtils.isNotNull(paramsObj))
412   - {
  365 + if (StringUtils.isNotNull(paramsObj)) {
413 366 String treeCode = paramsObj.getString(GenConstants.TREE_CODE);
414 367 String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE);
415 368 String treeName = paramsObj.getString(GenConstants.TREE_NAME);
416 369 String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID);
417 370 String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME);
418   -
  371 +
419 372 genTable.setTreeCode(treeCode);
420 373 genTable.setTreeParentCode(treeParentCode);
421 374 genTable.setTreeName(treeName);
... ... @@ -426,18 +379,16 @@ public class GenTableServiceImpl implements IGenTableService
426 379  
427 380 /**
428 381 * 获取代码生成地址
429   - *
430   - * @param table 业务表信息
  382 + *
  383 + * @param table 业务表信息
431 384 * @param template 模板文件路径
432 385 * @return 生成地址
433 386 */
434   - public static String getGenPath(GenTable table, String template)
435   - {
  387 + public static String getGenPath(GenTable table, String template) {
436 388 String genPath = table.getGenPath();
437   - if (StringUtils.equals(genPath, "/"))
438   - {
  389 + if (StringUtils.equals(genPath, "/")) {
439 390 return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
440 391 }
441 392 return genPath + File.separator + VelocityUtils.getFileName(template, table);
442 393 }
443   -}
444 394 \ No newline at end of file
  395 +}
... ...
ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableColumnService.java
1 1 package com.ruoyi.generator.service;
2 2  
3 3 import java.util.List;
  4 +
4 5 import com.ruoyi.generator.domain.GenTableColumn;
5 6  
6 7 /**
7 8 * 业务字段 服务层
8   - *
  9 + *
9 10 * @author ruoyi
10 11 */
11   -public interface IGenTableColumnService
12   -{
  12 +public interface IGenTableColumnService {
13 13 /**
14 14 * 查询业务字段列表
15   - *
  15 + *
16 16 * @param tableId 业务字段编号
17 17 * @return 业务字段集合
18 18 */
... ... @@ -20,7 +20,7 @@ public interface IGenTableColumnService
20 20  
21 21 /**
22 22 * 新增业务字段
23   - *
  23 + *
24 24 * @param genTableColumn 业务字段信息
25 25 * @return 结果
26 26 */
... ... @@ -28,7 +28,7 @@ public interface IGenTableColumnService
28 28  
29 29 /**
30 30 * 修改业务字段
31   - *
  31 + *
32 32 * @param genTableColumn 业务字段信息
33 33 * @return 结果
34 34 */
... ... @@ -36,7 +36,7 @@ public interface IGenTableColumnService
36 36  
37 37 /**
38 38 * 删除业务字段信息
39   - *
  39 + *
40 40 * @param ids 需要删除的数据ID
41 41 * @return 结果
42 42 */
... ...
ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java
... ... @@ -2,18 +2,18 @@ package com.ruoyi.generator.service;
2 2  
3 3 import java.util.List;
4 4 import java.util.Map;
  5 +
5 6 import com.ruoyi.generator.domain.GenTable;
6 7  
7 8 /**
8 9 * 业务 服务层
9   - *
  10 + *
10 11 * @author ruoyi
11 12 */
12   -public interface IGenTableService
13   -{
  13 +public interface IGenTableService {
14 14 /**
15 15 * 查询业务列表
16   - *
  16 + *
17 17 * @param genTable 业务信息
18 18 * @return 业务集合
19 19 */
... ... @@ -21,7 +21,7 @@ public interface IGenTableService
21 21  
22 22 /**
23 23 * 查询据库列表
24   - *
  24 + *
25 25 * @param genTable 业务信息
26 26 * @return 数据库表集合
27 27 */
... ... @@ -29,7 +29,7 @@ public interface IGenTableService
29 29  
30 30 /**
31 31 * 查询据库列表
32   - *
  32 + *
33 33 * @param tableNames 表名称组
34 34 * @return 数据库表集合
35 35 */
... ... @@ -37,7 +37,7 @@ public interface IGenTableService
37 37  
38 38 /**
39 39 * 查询业务信息
40   - *
  40 + *
41 41 * @param id 业务ID
42 42 * @return 业务信息
43 43 */
... ... @@ -45,7 +45,7 @@ public interface IGenTableService
45 45  
46 46 /**
47 47 * 修改业务
48   - *
  48 + *
49 49 * @param genTable 业务信息
50 50 * @return 结果
51 51 */
... ... @@ -53,7 +53,7 @@ public interface IGenTableService
53 53  
54 54 /**
55 55 * 删除业务信息
56   - *
  56 + *
57 57 * @param tableIds 需要删除的表数据ID
58 58 * @return 结果
59 59 */
... ... @@ -61,14 +61,14 @@ public interface IGenTableService
61 61  
62 62 /**
63 63 * 导入表结构
64   - *
  64 + *
65 65 * @param tableList 导入表列表
66 66 */
67 67 public void importGenTable(List<GenTable> tableList);
68 68  
69 69 /**
70 70 * 预览代码
71   - *
  71 + *
72 72 * @param tableId 表编号
73 73 * @return 预览数据列表
74 74 */
... ... @@ -76,7 +76,7 @@ public interface IGenTableService
76 76  
77 77 /**
78 78 * 生成代码(下载方式)
79   - *
  79 + *
80 80 * @param tableName 表名称
81 81 * @return 数据
82 82 */
... ... @@ -84,7 +84,7 @@ public interface IGenTableService
84 84  
85 85 /**
86 86 * 生成代码(自定义路径)
87   - *
  87 + *
88 88 * @param tableName 表名称
89 89 * @return 数据
90 90 */
... ... @@ -92,14 +92,14 @@ public interface IGenTableService
92 92  
93 93 /**
94 94 * 同步数据库
95   - *
  95 + *
96 96 * @param tableName 表名称
97 97 */
98 98 public void synchDb(String tableName);
99 99  
100 100 /**
101 101 * 批量生成代码(下载方式)
102   - *
  102 + *
103 103 * @param tableNames 表数组
104 104 * @return 数据
105 105 */
... ... @@ -107,7 +107,7 @@ public interface IGenTableService
107 107  
108 108 /**
109 109 * 修改保存参数校验
110   - *
  110 + *
111 111 * @param genTable 业务信息
112 112 */
113 113 public void validateEdit(GenTable genTable);
... ...
ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java
1 1 package com.ruoyi.generator.util;
2 2  
3 3 import java.util.Arrays;
  4 +
4 5 import org.apache.commons.lang3.RegExUtils;
5 6 import com.ruoyi.common.constant.GenConstants;
6 7 import com.ruoyi.common.utils.StringUtils;
... ... @@ -10,16 +11,14 @@ import com.ruoyi.generator.domain.GenTableColumn;
10 11  
11 12 /**
12 13 * 代码生成器 工具类
13   - *
  14 + *
14 15 * @author ruoyi
15 16 */
16   -public class GenUtils
17   -{
  17 +public class GenUtils {
18 18 /**
19 19 * 初始化表信息
20 20 */
21   - public static void initTable(GenTable genTable, String operName)
22   - {
  21 + public static void initTable(GenTable genTable, String operName) {
23 22 genTable.setClassName(convertClassName(genTable.getTableName()));
24 23 genTable.setPackageName(GenConfig.getPackageName());
25 24 genTable.setModuleName(getModuleName(GenConfig.getPackageName()));
... ... @@ -32,8 +31,7 @@ public class GenUtils
32 31 /**
33 32 * 初始化列属性字段
34 33 */
35   - public static void initColumnField(GenTableColumn column, GenTable table)
36   - {
  34 + public static void initColumnField(GenTableColumn column, GenTable table) {
37 35 String dataType = getDbType(column.getColumnType());
38 36 String columnName = column.getColumnName();
39 37 column.setTableId(table.getTableId());
... ... @@ -43,36 +41,28 @@ public class GenUtils
43 41 // 设置默认类型
44 42 column.setJavaType(GenConstants.TYPE_STRING);
45 43  
46   - if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType))
47   - {
  44 + if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) {
48 45 // 字符串长度超过500设置为文本域
49 46 Integer columnLength = getColumnLength(column.getColumnType());
50 47 String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT;
51 48 column.setHtmlType(htmlType);
52   - }
53   - else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType))
54   - {
  49 + } else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) {
55 50 column.setJavaType(GenConstants.TYPE_DATE);
56 51 column.setHtmlType(GenConstants.HTML_DATETIME);
57   - }
58   - else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType))
59   - {
  52 + } else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) {
60 53 column.setHtmlType(GenConstants.HTML_INPUT);
61 54  
62 55 // 如果是浮点型 统一用BigDecimal
63 56 String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ",");
64   - if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0)
65   - {
  57 + if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) {
66 58 column.setJavaType(GenConstants.TYPE_BIGDECIMAL);
67 59 }
68 60 // 如果是整形
69   - else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10)
70   - {
  61 + else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) {
71 62 column.setJavaType(GenConstants.TYPE_INTEGER);
72 63 }
73 64 // 长整形
74   - else
75   - {
  65 + else {
76 66 column.setJavaType(GenConstants.TYPE_LONG);
77 67 }
78 68 }
... ... @@ -81,69 +71,59 @@ public class GenUtils
81 71 column.setIsInsert(GenConstants.REQUIRE);
82 72  
83 73 // 编辑字段
84   - if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk())
85   - {
  74 + if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk()) {
86 75 column.setIsEdit(GenConstants.REQUIRE);
87 76 }
88 77 // 列表字段
89   - if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk())
90   - {
  78 + if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk()) {
91 79 column.setIsList(GenConstants.REQUIRE);
92 80 }
93 81 // 查询字段
94   - if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk())
95   - {
  82 + if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) {
96 83 column.setIsQuery(GenConstants.REQUIRE);
97 84 }
98 85  
99 86 // 查询字段类型
100   - if (StringUtils.endsWithIgnoreCase(columnName, "name"))
101   - {
  87 + if (StringUtils.endsWithIgnoreCase(columnName, "name")) {
102 88 column.setQueryType(GenConstants.QUERY_LIKE);
103 89 }
104 90 // 状态字段设置单选框
105   - if (StringUtils.endsWithIgnoreCase(columnName, "status"))
106   - {
  91 + if (StringUtils.endsWithIgnoreCase(columnName, "status")) {
107 92 column.setHtmlType(GenConstants.HTML_RADIO);
108 93 }
109 94 // 类型&性别字段设置下拉框
110 95 else if (StringUtils.endsWithIgnoreCase(columnName, "type")
111   - || StringUtils.endsWithIgnoreCase(columnName, "sex"))
112   - {
  96 + || StringUtils.endsWithIgnoreCase(columnName, "sex")) {
113 97 column.setHtmlType(GenConstants.HTML_SELECT);
114 98 }
115 99 // 文件字段设置上传控件
116   - else if (StringUtils.endsWithIgnoreCase(columnName, "image"))
117   - {
  100 + else if (StringUtils.endsWithIgnoreCase(columnName, "image")) {
118 101 column.setHtmlType(GenConstants.HTML_UPLOAD_IMAGE);
119 102 }
120 103 // 内容字段设置富文本控件
121   - else if (StringUtils.endsWithIgnoreCase(columnName, "content"))
122   - {
  104 + else if (StringUtils.endsWithIgnoreCase(columnName, "content")) {
123 105 column.setHtmlType(GenConstants.HTML_EDITOR);
124 106 }
125 107 }
126 108  
127 109 /**
128 110 * 校验数组是否包含指定值
129   - *
130   - * @param arr 数组
  111 + *
  112 + * @param arr 数组
131 113 * @param targetValue 值
132 114 * @return 是否包含
133 115 */
134   - public static boolean arraysContains(String[] arr, String targetValue)
135   - {
  116 + public static boolean arraysContains(String[] arr, String targetValue) {
136 117 return Arrays.asList(arr).contains(targetValue);
137 118 }
138 119  
139 120 /**
140 121 * 获取模块名
141   - *
  122 + *
142 123 * @param packageName 包名
143 124 * @return 模块名
144 125 */
145   - public static String getModuleName(String packageName)
146   - {
  126 + public static String getModuleName(String packageName) {
147 127 int lastIndex = packageName.lastIndexOf(".");
148 128 int nameLength = packageName.length();
149 129 String moduleName = StringUtils.substring(packageName, lastIndex + 1, nameLength);
... ... @@ -152,12 +132,11 @@ public class GenUtils
152 132  
153 133 /**
154 134 * 获取业务名
155   - *
  135 + *
156 136 * @param tableName 表名
157 137 * @return 业务名
158 138 */
159   - public static String getBusinessName(String tableName)
160   - {
  139 + public static String getBusinessName(String tableName) {
161 140 int lastIndex = tableName.lastIndexOf("_");
162 141 int nameLength = tableName.length();
163 142 String businessName = StringUtils.substring(tableName, lastIndex + 1, nameLength);
... ... @@ -166,16 +145,14 @@ public class GenUtils
166 145  
167 146 /**
168 147 * 表名转换成Java类名
169   - *
  148 + *
170 149 * @param tableName 表名称
171 150 * @return 类名
172 151 */
173   - public static String convertClassName(String tableName)
174   - {
  152 + public static String convertClassName(String tableName) {
175 153 boolean autoRemovePre = GenConfig.getAutoRemovePre();
176 154 String tablePrefix = GenConfig.getTablePrefix();
177   - if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix))
178   - {
  155 + if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) {
179 156 String[] searchList = StringUtils.split(tablePrefix, ",");
180 157 tableName = replaceFirst(tableName, searchList);
181 158 }
... ... @@ -184,18 +161,15 @@ public class GenUtils
184 161  
185 162 /**
186 163 * 批量替换前缀
187   - *
  164 + *
188 165 * @param replacementm 替换值
189   - * @param searchList 替换列表
  166 + * @param searchList 替换列表
190 167 * @return
191 168 */
192   - public static String replaceFirst(String replacementm, String[] searchList)
193   - {
  169 + public static String replaceFirst(String replacementm, String[] searchList) {
194 170 String text = replacementm;
195   - for (String searchString : searchList)
196   - {
197   - if (replacementm.startsWith(searchString))
198   - {
  171 + for (String searchString : searchList) {
  172 + if (replacementm.startsWith(searchString)) {
199 173 text = replacementm.replaceFirst(searchString, "");
200 174 break;
201 175 }
... ... @@ -205,48 +179,39 @@ public class GenUtils
205 179  
206 180 /**
207 181 * 关键字替换
208   - *
  182 + *
209 183 * @param text 需要被替换的名字
210 184 * @return 替换后的名字
211 185 */
212   - public static String replaceText(String text)
213   - {
  186 + public static String replaceText(String text) {
214 187 return RegExUtils.replaceAll(text, "(?:表|若依)", "");
215 188 }
216 189  
217 190 /**
218 191 * 获取数据库类型字段
219   - *
  192 + *
220 193 * @param columnType 列类型
221 194 * @return 截取后的列类型
222 195 */
223   - public static String getDbType(String columnType)
224   - {
225   - if (StringUtils.indexOf(columnType, "(") > 0)
226   - {
  196 + public static String getDbType(String columnType) {
  197 + if (StringUtils.indexOf(columnType, "(") > 0) {
227 198 return StringUtils.substringBefore(columnType, "(");
228   - }
229   - else
230   - {
  199 + } else {
231 200 return columnType;
232 201 }
233 202 }
234 203  
235 204 /**
236 205 * 获取字段长度
237   - *
  206 + *
238 207 * @param columnType 列类型
239 208 * @return 截取后的列类型
240 209 */
241   - public static Integer getColumnLength(String columnType)
242   - {
243   - if (StringUtils.indexOf(columnType, "(") > 0)
244   - {
  210 + public static Integer getColumnLength(String columnType) {
  211 + if (StringUtils.indexOf(columnType, "(") > 0) {
245 212 String length = StringUtils.substringBetween(columnType, "(", ")");
246 213 return Integer.valueOf(length);
247   - }
248   - else
249   - {
  214 + } else {
250 215 return 0;
251 216 }
252 217 }
... ...
ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityInitializer.java
1 1 package com.ruoyi.generator.util;
2 2  
3 3 import java.util.Properties;
  4 +
4 5 import org.apache.velocity.app.Velocity;
5 6 import com.ruoyi.common.constant.Constants;
6 7  
7 8 /**
8 9 * VelocityEngine工厂
9   - *
  10 + *
10 11 * @author RuoYi
11 12 */
12   -public class VelocityInitializer
13   -{
  13 +public class VelocityInitializer {
14 14 /**
15 15 * 初始化vm方法
16 16 */
17   - public static void initVelocity()
18   - {
  17 + public static void initVelocity() {
19 18 Properties p = new Properties();
20   - try
21   - {
  19 + try {
22 20 // 加载classpath目录下的vm文件
23 21 p.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
24 22 // 定义字符集
... ... @@ -26,9 +24,7 @@ public class VelocityInitializer
26 24 p.setProperty(Velocity.OUTPUT_ENCODING, Constants.UTF8);
27 25 // 初始化Velocity引擎,指定配置Properties
28 26 Velocity.init(p);
29   - }
30   - catch (Exception e)
31   - {
  27 + } catch (Exception e) {
32 28 throw new RuntimeException(e);
33 29 }
34 30 }
... ...
src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/dataobject/codegen/ToolCodegenColumnDO.java
1 1 package cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen;
2 2  
3 3 import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
  4 +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictTypeDO;
  5 +import cn.iocoder.dashboard.modules.tool.enums.codegen.ToolCodegenColumnHtmlTypeEnum;
  6 +import cn.iocoder.dashboard.modules.tool.enums.codegen.ToolCodegenColumnListConditionEnum;
  7 +import com.baomidou.mybatisplus.annotation.TableId;
4 8 import com.baomidou.mybatisplus.annotation.TableName;
5 9 import lombok.Builder;
6 10 import lombok.Data;
... ... @@ -17,6 +21,99 @@ import lombok.EqualsAndHashCode;
17 21 @EqualsAndHashCode(callSuper = true)
18 22 public class ToolCodegenColumnDO extends BaseDO {
19 23  
  24 + /**
  25 + * ID 编号
  26 + */
  27 + @TableId
  28 + private Long id;
  29 + /**
  30 + * 表编号
  31 + *
  32 + * 外键 {@link ToolCodegenTableDO#getId()}
  33 + */
  34 + private Long tableId;
  35 +
  36 + // ========== 表相关字段 ==========
  37 +
  38 + /**
  39 + * 字段名
  40 + */
  41 + private String columnName;
  42 + /**
  43 + * 字段类型
  44 + */
  45 + private String columnType;
  46 + /**
  47 + * 字段描述
  48 + */
  49 + private String columnComment;
  50 + /**
  51 + * 是否允许为空
  52 + */
  53 + private Boolean nullable;
  54 + /**
  55 + * 是否主键
  56 + */
  57 + private Boolean primaryKey;
  58 + /**
  59 + * 是否自增
  60 + */
  61 + private Boolean autoIncrement;
  62 + /**
  63 + * 排序字段
  64 + */
  65 + private Integer ordinalPosition;
  66 +
  67 + // ========== Java 相关字段 ==========
  68 +
  69 + /**
  70 + * Java 属性类型
  71 + *
  72 + * 例如说 String、Boolean 等等
  73 + */
  74 + private String javaType;
  75 + /**
  76 + * Java 属性名
  77 + */
  78 +// @NotBlank(message = "Java属性不能为空")
  79 + private String javaField;
  80 + /**
  81 + * 字典类型
  82 + *
  83 + * 关联 {@link SysDictTypeDO#getType()}
  84 + */
  85 + private String dictType;
  86 +
  87 + // ========== CRUD 相关字段 ==========
  88 +
  89 + /**
  90 + * 是否为 Create 创建操作的字段
  91 + */
  92 + private Boolean createOperation;
  93 + /**
  94 + * 是否为 Update 更新操作的字段
  95 + */
  96 + private Boolean updateOperation;
  97 + /**
  98 + * 是否为 List 查询操作的返回字段
  99 + */
  100 + private Boolean listOperationResult;
  101 + /**
  102 + * List 查询操作的条件类型
  103 + * 如果为空,则说明不是查询字段
  104 + *
  105 + * 枚举 {@link ToolCodegenColumnListConditionEnum}
  106 + */
  107 + private String listOperationCondition;
  108 +
  109 + // ========== UI 相关字段 ==========
  110 +
  111 + /**
  112 + * 显示类型
  113 + *
  114 + * 枚举 {@link ToolCodegenColumnHtmlTypeEnum}
  115 + */
  116 + private String htmlType;
20 117  
21 118  
22 119 }
... ...
src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/dataobject/codegen/ToolCodegenTableDO.java
1 1 package cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen;
2 2  
3 3 import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
4   -import cn.iocoder.dashboard.modules.tool.enums.codegen.ToolCodeGenTemplateTypeEnum;
  4 +import cn.iocoder.dashboard.modules.tool.enums.codegen.ToolCodegenTemplateTypeEnum;
5 5 import com.baomidou.mybatisplus.annotation.TableName;
6 6 import lombok.Builder;
7 7 import lombok.Data;
... ... @@ -18,12 +18,13 @@ import lombok.EqualsAndHashCode;
18 18 @EqualsAndHashCode(callSuper = true)
19 19 public class ToolCodegenTableDO extends BaseDO {
20 20  
21   - // ========== 表相关字段 ==========
22   -
23 21 /**
24 22 * ID 编号
25 23 */
26 24 private Long id;
  25 +
  26 + // ========== 表相关字段 ==========
  27 +
27 28 /**
28 29 * 表名称
29 30 */
... ... @@ -78,7 +79,7 @@ public class ToolCodegenTableDO extends BaseDO {
78 79 /**
79 80 * 模板类型
80 81 *
81   - * 枚举 {@link ToolCodeGenTemplateTypeEnum}
  82 + * 枚举 {@link ToolCodegenTemplateTypeEnum}
82 83 */
83 84 private Integer templateType;
84 85  
... ...
src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/dataobject/codegen/ToolInformationSchemaColumnDO.java
... ... @@ -28,6 +28,10 @@ public class ToolInformationSchemaColumnDO {
28 28 */
29 29 private String columnType;
30 30 /**
  31 + * 字段描述
  32 + */
  33 + private String columnComment;
  34 + /**
31 35 * 是否允许为空
32 36 */
33 37 @TableField("case when is_nullable = 'yes' then '1' else '0' end")
... ... @@ -38,6 +42,11 @@ public class ToolInformationSchemaColumnDO {
38 42 @TableField("case when column_key = 'PRI' then '1' else '0' end")
39 43 private Boolean primaryKey;
40 44 /**
  45 + * 是否自增
  46 + */
  47 + @TableField("case when extra = 'auto_increment' then '1' else '0' end")
  48 + private Boolean autoIncrement;
  49 + /**
41 50 * 排序字段
42 51 */
43 52 private Integer ordinalPosition;
... ...
src/main/java/cn/iocoder/dashboard/modules/tool/enums/codegen/ToolCodegenColumnHtmlTypeEnum.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.tool.enums.codegen;
  2 +
  3 +import lombok.AllArgsConstructor;
  4 +import lombok.Getter;
  5 +
  6 +/**
  7 + * 代码生成器的字段 HTML 展示枚举
  8 + */
  9 +@AllArgsConstructor
  10 +@Getter
  11 +public enum ToolCodegenColumnHtmlTypeEnum {
  12 +
  13 + INPUT("input"), // 文本框
  14 + TEXTAREA("textarea"), // 文本域
  15 + SELECT("select"), // 下拉框
  16 + RADIO("radio"), // 单选框
  17 + CHECKBOX("checkbox"), // 复选框
  18 + DATETIME("datetime"), // 日期控件
  19 + UPLOAD_IMAGE("upload_image"), // 上传控件
  20 + EDITOR("editor"), // 富文本控件
  21 + ;
  22 +
  23 + /**
  24 + * 条件
  25 + */
  26 + private final String condition;
  27 +
  28 +}
... ...
src/main/java/cn/iocoder/dashboard/modules/tool/enums/codegen/ToolCodegenColumnListConditionEnum.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.tool.enums.codegen;
  2 +
  3 +import lombok.AllArgsConstructor;
  4 +import lombok.Getter;
  5 +
  6 +/**
  7 + * 代码生成器的字段过滤条件枚举
  8 + */
  9 +@AllArgsConstructor
  10 +@Getter
  11 +public enum ToolCodegenColumnListConditionEnum {
  12 +
  13 + EQ("="),
  14 + NE("!="),
  15 + GT(">"),
  16 + GTE(">="),
  17 + LT("<"),
  18 + LTE("<="),
  19 + LIKE("LIKE"),
  20 + BETWEEN("BETWEEN");
  21 +
  22 + /**
  23 + * 条件
  24 + */
  25 + private final String condition;
  26 +
  27 +}
... ...
src/main/java/cn/iocoder/dashboard/modules/tool/enums/codegen/ToolCodeGenTemplateTypeEnum.java renamed to src/main/java/cn/iocoder/dashboard/modules/tool/enums/codegen/ToolCodegenTemplateTypeEnum.java
... ... @@ -10,7 +10,7 @@ import lombok.Getter;
10 10 */
11 11 @AllArgsConstructor
12 12 @Getter
13   -public enum ToolCodeGenTemplateTypeEnum {
  13 +public enum ToolCodegenTemplateTypeEnum {
14 14  
15 15 CRUD(1), // 基础 CRUD
16 16 TREE(2), // 树形 CRUD
... ...