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