From 58f83a2bd1ca3ea8d3111bc56aa662377e4b357d Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 30 Jan 2021 21:36:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A2=B3=E7=90=86=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=99=A8=E7=9A=84=E8=A1=A8=E7=BB=93=E6=9E=84=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=9B=B8=E5=85=B3=E5=AD=97=E6=AE=B5=E7=9A=84?= =?UTF-8?q?=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/constant/GenConstants.java | 49 ---- ruoyi-generator/pom.xml | 34 --- .../com/ruoyi/generator/config/GenConfig.java | 5 +- .../com/ruoyi/generator/domain/GenTable.java | 16 -- .../generator/domain/GenTableColumn.java | 226 +----------------- .../mapper/GenTableColumnMapper.java | 18 +- .../generator/mapper/GenTableMapper.java | 22 +- .../service/GenTableColumnServiceImpl.java | 72 +++--- .../service/GenTableServiceImpl.java | 185 ++++++-------- .../service/IGenTableColumnService.java | 14 +- .../generator/service/IGenTableService.java | 32 +-- .../com/ruoyi/generator/util/GenUtils.java | 123 ++++------ .../generator/util/VelocityInitializer.java | 16 +- .../codegen/ToolCodegenColumnDO.java | 97 ++++++++ .../codegen/ToolCodegenTableDO.java | 9 +- .../ToolInformationSchemaColumnDO.java | 9 + .../ToolCodegenColumnHtmlTypeEnum.java | 28 +++ .../ToolCodegenColumnListConditionEnum.java | 27 +++ ....java => ToolCodegenTemplateTypeEnum.java} | 2 +- 19 files changed, 369 insertions(+), 615 deletions(-) delete mode 100644 ruoyi-generator/pom.xml create mode 100644 src/main/java/cn/iocoder/dashboard/modules/tool/enums/codegen/ToolCodegenColumnHtmlTypeEnum.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/tool/enums/codegen/ToolCodegenColumnListConditionEnum.java rename src/main/java/cn/iocoder/dashboard/modules/tool/enums/codegen/{ToolCodeGenTemplateTypeEnum.java => ToolCodegenTemplateTypeEnum.java} (89%) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java index 78afc5c9e..a1bc70846 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java @@ -80,46 +80,6 @@ public class GenConstants { */ public static final String[] TREE_ENTITY = {"parentName", "parentId", "orderNum", "ancestors", "children"}; - /** - * 文本框 - */ - public static final String HTML_INPUT = "input"; - - /** - * 文本域 - */ - public static final String HTML_TEXTAREA = "textarea"; - - /** - * 下拉框 - */ - public static final String HTML_SELECT = "select"; - - /** - * 单选框 - */ - public static final String HTML_RADIO = "radio"; - - /** - * 复选框 - */ - public static final String HTML_CHECKBOX = "checkbox"; - - /** - * 日期控件 - */ - public static final String HTML_DATETIME = "datetime"; - - /** - * 上传控件 - */ - public static final String HTML_UPLOAD_IMAGE = "uploadImage"; - - /** - * 富文本控件 - */ - public static final String HTML_EDITOR = "editor"; - /** * 字符串类型 */ @@ -150,13 +110,4 @@ public class GenConstants { */ public static final String TYPE_DATE = "Date"; - /** - * 模糊查询 - */ - public static final String QUERY_LIKE = "LIKE"; - - /** - * 需要 - */ - public static final String REQUIRE = "1"; } diff --git a/ruoyi-generator/pom.xml b/ruoyi-generator/pom.xml deleted file mode 100644 index 8a768f259..000000000 --- a/ruoyi-generator/pom.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - ruoyi - com.ruoyi - 3.3.0 - - 4.0.0 - - ruoyi-generator - - - generator代码生成 - - - - - - - org.apache.velocity - velocity - - - - - com.ruoyi - ruoyi-common - - - - - \ No newline at end of file diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/config/GenConfig.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/config/GenConfig.java index 1b144deb9..e6351984d 100644 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/config/GenConfig.java +++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/config/GenConfig.java @@ -7,14 +7,13 @@ import org.springframework.stereotype.Component; /** * 读取代码生成相关配置 - * + * * @author ruoyi */ @Component @ConfigurationProperties(prefix = "gen") @PropertySource(value = { "classpath:generator.yml" }) -public class GenConfig -{ +public class GenConfig { /** 作者 */ public static String author; diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java index 9344aa151..287faa55e 100644 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java +++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java @@ -22,27 +22,11 @@ public class GenTable extends BaseEntity { @NotBlank(message = "生成包路径不能为空") private String packageName; - /** - * 生成代码方式(0zip压缩包 1自定义路径) - */ - private String genType; - - /** - * 生成路径(不填默认项目路径) - */ - private String genPath; - /** * 主键信息 */ private GenTableColumn pkColumn; - /** - * 表列信息 - */ - @Valid - private List columns; - /** * 其它生成选项 */ diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java index 4209a3859..62f91782b 100644 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java +++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java @@ -1,6 +1,7 @@ package com.ruoyi.generator.domain; import javax.validation.constraints.NotBlank; + import com.ruoyi.common.core.domain.BaseEntity; import com.ruoyi.common.utils.StringUtils; @@ -9,202 +10,9 @@ import com.ruoyi.common.utils.StringUtils; * * @author ruoyi */ -public class GenTableColumn extends BaseEntity -{ - private static final long serialVersionUID = 1L; +public class GenTableColumn extends BaseEntity { - /** 编号 */ - private Long columnId; - - /** 归属表编号 */ - private Long tableId; - - /** 列名称 */ - private String columnName; - - /** 列描述 */ - private String columnComment; - - /** 列类型 */ - private String columnType; - - /** JAVA类型 */ - private String javaType; - - /** JAVA字段名 */ - @NotBlank(message = "Java属性不能为空") - private String javaField; - - /** 是否主键(1是) */ - private String isPk; - - /** 是否自增(1是) */ - private String isIncrement; - - /** 是否必填(1是) */ - private String isRequired; - - /** 是否为插入字段(1是) */ - private String isInsert; - - /** 是否编辑字段(1是) */ - private String isEdit; - - /** 是否列表字段(1是) */ - private String isList; - - /** 是否查询字段(1是) */ - private String isQuery; - - /** 查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围) */ - private String queryType; - - /** 显示类型(input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、upload上传控件、editor富文本控件) */ - private String htmlType; - - /** 字典类型 */ - private String dictType; - - /** 排序 */ - private Integer sort; - - public boolean isPk() - { - return isPk(this.isPk); - } - - public boolean isPk(String isPk) - { - return isPk != null && StringUtils.equals("1", isPk); - } - - public String getIsIncrement() - { - return isIncrement; - } - - public void setIsIncrement(String isIncrement) - { - this.isIncrement = isIncrement; - } - - public boolean isIncrement() - { - return isIncrement(this.isIncrement); - } - - public boolean isIncrement(String isIncrement) - { - return isIncrement != null && StringUtils.equals("1", isIncrement); - } - - public void setIsRequired(String isRequired) - { - this.isRequired = isRequired; - } - - public String getIsRequired() - { - return isRequired; - } - - public boolean isRequired() - { - return isRequired(this.isRequired); - } - - public boolean isRequired(String isRequired) - { - return isRequired != null && StringUtils.equals("1", isRequired); - } - - public void setIsInsert(String isInsert) - { - this.isInsert = isInsert; - } - - public String getIsInsert() - { - return isInsert; - } - - public boolean isInsert() - { - return isInsert(this.isInsert); - } - - public boolean isInsert(String isInsert) - { - return isInsert != null && StringUtils.equals("1", isInsert); - } - - public void setIsEdit(String isEdit) - { - this.isEdit = isEdit; - } - - public String getIsEdit() - { - return isEdit; - } - - public boolean isEdit() - { - return isInsert(this.isEdit); - } - - public boolean isEdit(String isEdit) - { - return isEdit != null && StringUtils.equals("1", isEdit); - } - - public void setIsList(String isList) - { - this.isList = isList; - } - - public String getIsList() - { - return isList; - } - - public boolean isList() - { - return isList(this.isList); - } - - public boolean isList(String isList) - { - return isList != null && StringUtils.equals("1", isList); - } - - public void setIsQuery(String isQuery) - { - this.isQuery = isQuery; - } - - public String getIsQuery() - { - return isQuery; - } - - public boolean isQuery() - { - return isQuery(this.isQuery); - } - - public boolean isQuery(String isQuery) - { - return isQuery != null && StringUtils.equals("1", isQuery); - } - - public boolean isSuperColumn() - { - return isSuperColumn(this.javaField); - } - - public static boolean isSuperColumn(String javaField) - { + public static boolean isSuperColumn(String javaField) { return StringUtils.equalsAnyIgnoreCase(javaField, // BaseEntity "createBy", "createTime", "updateBy", "updateTime", "remark", @@ -212,37 +20,13 @@ public class GenTableColumn extends BaseEntity "parentName", "parentId", "orderNum", "ancestors"); } - public boolean isUsableColumn() - { + public boolean isUsableColumn() { return isUsableColumn(javaField); } - public static boolean isUsableColumn(String javaField) - { + public static boolean isUsableColumn(String javaField) { // isSuperColumn()中的名单用于避免生成多余Domain属性,若某些属性在生成页面时需要用到不能忽略,则放在此处白名单 return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark"); } - public String readConverterExp() - { - String remarks = StringUtils.substringBetween(this.columnComment, "(", ")"); - StringBuffer sb = new StringBuffer(); - if (StringUtils.isNotEmpty(remarks)) - { - for (String value : remarks.split(" ")) - { - if (StringUtils.isNotEmpty(value)) - { - Object startStr = value.subSequence(0, 1); - String endStr = value.substring(1); - sb.append("").append(startStr).append("=").append(endStr).append(","); - } - } - return sb.deleteCharAt(sb.length() - 1).toString(); - } - else - { - return this.columnComment; - } - } } diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java index 0dc342895..3e71d14ee 100644 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java +++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java @@ -1,18 +1,18 @@ package com.ruoyi.generator.mapper; import java.util.List; + import com.ruoyi.generator.domain.GenTableColumn; /** * 业务字段 数据层 - * + * * @author ruoyi */ -public interface GenTableColumnMapper -{ +public interface GenTableColumnMapper { /** * 根据表名称查询列信息 - * + * * @param tableName 表名称 * @return 列信息 */ @@ -20,7 +20,7 @@ public interface GenTableColumnMapper /** * 查询业务字段列表 - * + * * @param tableId 业务字段编号 * @return 业务字段集合 */ @@ -28,7 +28,7 @@ public interface GenTableColumnMapper /** * 新增业务字段 - * + * * @param genTableColumn 业务字段信息 * @return 结果 */ @@ -36,7 +36,7 @@ public interface GenTableColumnMapper /** * 修改业务字段 - * + * * @param genTableColumn 业务字段信息 * @return 结果 */ @@ -44,7 +44,7 @@ public interface GenTableColumnMapper /** * 删除业务字段 - * + * * @param genTableColumns 列数据 * @return 结果 */ @@ -52,7 +52,7 @@ public interface GenTableColumnMapper /** * 批量删除业务字段 - * + * * @param ids 需要删除的数据ID * @return 结果 */ diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java index 4288d889b..cc59bd2f4 100644 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java +++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java @@ -1,18 +1,18 @@ package com.ruoyi.generator.mapper; import java.util.List; + import com.ruoyi.generator.domain.GenTable; /** * 业务 数据层 - * + * * @author ruoyi */ -public interface GenTableMapper -{ +public interface GenTableMapper { /** * 查询业务列表 - * + * * @param genTable 业务信息 * @return 业务集合 */ @@ -20,7 +20,7 @@ public interface GenTableMapper /** * 查询据库列表 - * + * * @param genTable 业务信息 * @return 数据库表集合 */ @@ -28,7 +28,7 @@ public interface GenTableMapper /** * 查询据库列表 - * + * * @param tableNames 表名称组 * @return 数据库表集合 */ @@ -36,7 +36,7 @@ public interface GenTableMapper /** * 查询表ID业务信息 - * + * * @param id 业务ID * @return 业务信息 */ @@ -44,7 +44,7 @@ public interface GenTableMapper /** * 查询表名称业务信息 - * + * * @param tableName 表名称 * @return 业务信息 */ @@ -52,7 +52,7 @@ public interface GenTableMapper /** * 新增业务 - * + * * @param genTable 业务信息 * @return 结果 */ @@ -60,7 +60,7 @@ public interface GenTableMapper /** * 修改业务 - * + * * @param genTable 业务信息 * @return 结果 */ @@ -68,7 +68,7 @@ public interface GenTableMapper /** * 批量删除业务 - * + * * @param ids 需要删除的数据ID * @return 结果 */ diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java index 3a2d66a59..ac144794e 100644 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java +++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java @@ -1,6 +1,7 @@ package com.ruoyi.generator.service; import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.common.core.text.Convert; @@ -9,60 +10,55 @@ import com.ruoyi.generator.mapper.GenTableColumnMapper; /** * 业务字段 服务层实现 - * + * * @author ruoyi */ @Service -public class GenTableColumnServiceImpl implements IGenTableColumnService -{ - @Autowired - private GenTableColumnMapper genTableColumnMapper; +public class GenTableColumnServiceImpl implements IGenTableColumnService { + @Autowired + private GenTableColumnMapper genTableColumnMapper; - /** + /** * 查询业务字段列表 - * + * * @param tableId 业务字段编号 * @return 业务字段集合 */ - @Override - public List selectGenTableColumnListByTableId(Long tableId) - { - return genTableColumnMapper.selectGenTableColumnListByTableId(tableId); - } - + @Override + public List selectGenTableColumnListByTableId(Long tableId) { + return genTableColumnMapper.selectGenTableColumnListByTableId(tableId); + } + /** * 新增业务字段 - * + * * @param genTableColumn 业务字段信息 * @return 结果 */ - @Override - public int insertGenTableColumn(GenTableColumn genTableColumn) - { - return genTableColumnMapper.insertGenTableColumn(genTableColumn); - } - - /** - * 修改业务字段 - * - * @param genTableColumn 业务字段信息 - * @return 结果 - */ - @Override - public int updateGenTableColumn(GenTableColumn genTableColumn) - { - return genTableColumnMapper.updateGenTableColumn(genTableColumn); - } + @Override + public int insertGenTableColumn(GenTableColumn genTableColumn) { + return genTableColumnMapper.insertGenTableColumn(genTableColumn); + } - /** + /** + * 修改业务字段 + * + * @param genTableColumn 业务字段信息 + * @return 结果 + */ + @Override + public int updateGenTableColumn(GenTableColumn genTableColumn) { + return genTableColumnMapper.updateGenTableColumn(genTableColumn); + } + + /** * 删除业务字段对象 - * + * * @param ids 需要删除的数据ID * @return 结果 */ - @Override - public int deleteGenTableColumnByIds(String ids) - { - return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids)); - } + @Override + public int deleteGenTableColumnByIds(String ids) { + return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids)); + } } diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java index 4f663021d..de1a41990 100644 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java +++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java @@ -10,6 +10,7 @@ import java.util.Map; import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; + import org.apache.commons.io.IOUtils; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; @@ -38,12 +39,11 @@ import com.ruoyi.generator.util.VelocityUtils; /** * 业务 服务层实现 - * + * * @author ruoyi */ @Service -public class GenTableServiceImpl implements IGenTableService -{ +public class GenTableServiceImpl implements IGenTableService { private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class); @Autowired @@ -54,13 +54,12 @@ public class GenTableServiceImpl implements IGenTableService /** * 查询业务信息 - * + * * @param id 业务ID * @return 业务信息 */ @Override - public GenTable selectGenTableById(Long id) - { + public GenTable selectGenTableById(Long id) { GenTable genTable = genTableMapper.selectGenTableById(id); setTableFromOptions(genTable); return genTable; @@ -68,57 +67,51 @@ public class GenTableServiceImpl implements IGenTableService /** * 查询业务列表 - * + * * @param genTable 业务信息 * @return 业务集合 */ @Override - public List selectGenTableList(GenTable genTable) - { + public List selectGenTableList(GenTable genTable) { return genTableMapper.selectGenTableList(genTable); } /** * 查询据库列表 - * + * * @param genTable 业务信息 * @return 数据库表集合 */ @Override - public List selectDbTableList(GenTable genTable) - { + public List selectDbTableList(GenTable genTable) { return genTableMapper.selectDbTableList(genTable); } /** * 查询据库列表 - * + * * @param tableNames 表名称组 * @return 数据库表集合 */ @Override - public List selectDbTableListByNames(String[] tableNames) - { + public List selectDbTableListByNames(String[] tableNames) { return genTableMapper.selectDbTableListByNames(tableNames); } /** * 修改业务 - * + * * @param genTable 业务信息 * @return 结果 */ @Override @Transactional - public void updateGenTable(GenTable genTable) - { + public void updateGenTable(GenTable genTable) { String options = JSON.toJSONString(genTable.getParams()); genTable.setOptions(options); int row = genTableMapper.updateGenTable(genTable); - if (row > 0) - { - for (GenTableColumn cenTableColumn : genTable.getColumns()) - { + if (row > 0) { + for (GenTableColumn cenTableColumn : genTable.getColumns()) { genTableColumnMapper.updateGenTableColumn(cenTableColumn); } } @@ -126,62 +119,53 @@ public class GenTableServiceImpl implements IGenTableService /** * 删除业务对象 - * + * * @param tableIds 需要删除的数据ID * @return 结果 */ @Override @Transactional - public void deleteGenTableByIds(Long[] tableIds) - { + public void deleteGenTableByIds(Long[] tableIds) { genTableMapper.deleteGenTableByIds(tableIds); genTableColumnMapper.deleteGenTableColumnByIds(tableIds); } /** * 导入表结构 - * + * * @param tableList 导入表列表 */ @Override @Transactional - public void importGenTable(List tableList) - { + public void importGenTable(List tableList) { String operName = SecurityUtils.getUsername(); - try - { - for (GenTable table : tableList) - { + try { + for (GenTable table : tableList) { String tableName = table.getTableName(); GenUtils.initTable(table, operName); int row = genTableMapper.insertGenTable(table); - if (row > 0) - { + if (row > 0) { // 保存列信息 List genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); - for (GenTableColumn column : genTableColumns) - { + for (GenTableColumn column : genTableColumns) { GenUtils.initColumnField(column, table); genTableColumnMapper.insertGenTableColumn(column); } } } - } - catch (Exception e) - { + } catch (Exception e) { throw new CustomException("导入失败:" + e.getMessage()); } } /** * 预览代码 - * + * * @param tableId 表编号 * @return 预览数据列表 */ @Override - public Map previewCode(Long tableId) - { + public Map previewCode(Long tableId) { Map dataMap = new LinkedHashMap<>(); // 查询表信息 GenTable table = genTableMapper.selectGenTableById(tableId); @@ -194,8 +178,7 @@ public class GenTableServiceImpl implements IGenTableService // 获取模板列表 List templates = VelocityUtils.getTemplateList(table.getTplCategory()); - for (String template : templates) - { + for (String template : templates) { // 渲染模板 StringWriter sw = new StringWriter(); Template tpl = Velocity.getTemplate(template, Constants.UTF8); @@ -207,13 +190,12 @@ public class GenTableServiceImpl implements IGenTableService /** * 生成代码(下载方式) - * + * * @param tableName 表名称 * @return 数据 */ @Override - public byte[] downloadCode(String tableName) - { + public byte[] downloadCode(String tableName) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(outputStream); generatorCode(tableName, zip); @@ -223,12 +205,11 @@ public class GenTableServiceImpl implements IGenTableService /** * 生成代码(自定义路径) - * + * * @param tableName 表名称 */ @Override - public void generatorCode(String tableName) - { + public void generatorCode(String tableName) { // 查询表信息 GenTable table = genTableMapper.selectGenTableByName(tableName); // 查询列信息 @@ -241,21 +222,16 @@ public class GenTableServiceImpl implements IGenTableService // 获取模板列表 List templates = VelocityUtils.getTemplateList(table.getTplCategory()); - for (String template : templates) - { - if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) - { + for (String template : templates) { + if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) { // 渲染模板 StringWriter sw = new StringWriter(); Template tpl = Velocity.getTemplate(template, Constants.UTF8); tpl.merge(context, sw); - try - { + try { String path = getGenPath(table, template); FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8); - } - catch (IOException e) - { + } catch (IOException e) { throw new CustomException("渲染模板失败,表名:" + table.getTableName()); } } @@ -264,13 +240,12 @@ public class GenTableServiceImpl implements IGenTableService /** * 同步数据库 - * + * * @param tableName 表名称 */ @Override @Transactional - public void synchDb(String tableName) - { + public void synchDb(String tableName) { GenTable table = genTableMapper.selectGenTableByName(tableName); List tableColumns = table.getColumns(); List tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); @@ -279,33 +254,29 @@ public class GenTableServiceImpl implements IGenTableService List dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); dbTableColumns.forEach(column -> { - if (!tableColumnNames.contains(column.getColumnName())) - { + if (!tableColumnNames.contains(column.getColumnName())) { GenUtils.initColumnField(column, table); genTableColumnMapper.insertGenTableColumn(column); } }); List delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList()); - if (StringUtils.isNotEmpty(delColumns)) - { + if (StringUtils.isNotEmpty(delColumns)) { genTableColumnMapper.deleteGenTableColumns(delColumns); } } /** * 批量生成代码(下载方式) - * + * * @param tableNames 表数组 * @return 数据 */ @Override - public byte[] downloadCode(String[] tableNames) - { + public byte[] downloadCode(String[] tableNames) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(outputStream); - for (String tableName : tableNames) - { + for (String tableName : tableNames) { generatorCode(tableName, zip); } IOUtils.closeQuietly(zip); @@ -315,8 +286,7 @@ public class GenTableServiceImpl implements IGenTableService /** * 查询表信息并生成代码 */ - private void generatorCode(String tableName, ZipOutputStream zip) - { + private void generatorCode(String tableName, ZipOutputStream zip) { // 查询表信息 GenTable table = genTableMapper.selectGenTableByName(tableName); // 查询列信息 @@ -329,23 +299,19 @@ public class GenTableServiceImpl implements IGenTableService // 获取模板列表 List templates = VelocityUtils.getTemplateList(table.getTplCategory()); - for (String template : templates) - { + for (String template : templates) { // 渲染模板 StringWriter sw = new StringWriter(); Template tpl = Velocity.getTemplate(template, Constants.UTF8); tpl.merge(context, sw); - try - { + try { // 添加到zip zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table))); IOUtils.write(sw.toString(), zip, Constants.UTF8); IOUtils.closeQuietly(sw); - zip.flush(); + zip.flush(); zip.closeEntry(); - } - catch (IOException e) - { + } catch (IOException e) { log.error("渲染模板失败,表名:" + table.getTableName(), e); } } @@ -353,26 +319,19 @@ public class GenTableServiceImpl implements IGenTableService /** * 修改保存参数校验 - * + * * @param genTable 业务信息 */ @Override - public void validateEdit(GenTable genTable) - { - if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) - { + public void validateEdit(GenTable genTable) { + if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) { String options = JSON.toJSONString(genTable.getParams()); JSONObject paramsObj = JSONObject.parseObject(options); - if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) - { + if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) { throw new CustomException("树编码字段不能为空"); - } - else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) - { + } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) { throw new CustomException("树父编码字段不能为空"); - } - else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) - { + } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) { throw new CustomException("树名称字段不能为空"); } } @@ -380,42 +339,36 @@ public class GenTableServiceImpl implements IGenTableService /** * 设置主键列信息 - * - * @param table 业务表信息 + * + * @param table 业务表信息 * @param columns 业务字段列表 */ - public void setPkColumn(GenTable table, List columns) - { - for (GenTableColumn column : columns) - { - if (column.isPk()) - { + public void setPkColumn(GenTable table, List columns) { + for (GenTableColumn column : columns) { + if (column.isPk()) { table.setPkColumn(column); break; } } - if (StringUtils.isNull(table.getPkColumn())) - { + if (StringUtils.isNull(table.getPkColumn())) { table.setPkColumn(columns.get(0)); } } /** * 设置代码生成其他选项值 - * + * * @param genTable 设置后的生成对象 */ - public void setTableFromOptions(GenTable genTable) - { + public void setTableFromOptions(GenTable genTable) { JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions()); - if (StringUtils.isNotNull(paramsObj)) - { + if (StringUtils.isNotNull(paramsObj)) { String treeCode = paramsObj.getString(GenConstants.TREE_CODE); String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE); String treeName = paramsObj.getString(GenConstants.TREE_NAME); String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID); String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME); - + genTable.setTreeCode(treeCode); genTable.setTreeParentCode(treeParentCode); genTable.setTreeName(treeName); @@ -426,18 +379,16 @@ public class GenTableServiceImpl implements IGenTableService /** * 获取代码生成地址 - * - * @param table 业务表信息 + * + * @param table 业务表信息 * @param template 模板文件路径 * @return 生成地址 */ - public static String getGenPath(GenTable table, String template) - { + public static String getGenPath(GenTable table, String template) { String genPath = table.getGenPath(); - if (StringUtils.equals(genPath, "/")) - { + if (StringUtils.equals(genPath, "/")) { return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table); } return genPath + File.separator + VelocityUtils.getFileName(template, table); } -} \ No newline at end of file +} diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableColumnService.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableColumnService.java index 2130d0431..d4aa88693 100644 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableColumnService.java +++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableColumnService.java @@ -1,18 +1,18 @@ package com.ruoyi.generator.service; import java.util.List; + import com.ruoyi.generator.domain.GenTableColumn; /** * 业务字段 服务层 - * + * * @author ruoyi */ -public interface IGenTableColumnService -{ +public interface IGenTableColumnService { /** * 查询业务字段列表 - * + * * @param tableId 业务字段编号 * @return 业务字段集合 */ @@ -20,7 +20,7 @@ public interface IGenTableColumnService /** * 新增业务字段 - * + * * @param genTableColumn 业务字段信息 * @return 结果 */ @@ -28,7 +28,7 @@ public interface IGenTableColumnService /** * 修改业务字段 - * + * * @param genTableColumn 业务字段信息 * @return 结果 */ @@ -36,7 +36,7 @@ public interface IGenTableColumnService /** * 删除业务字段信息 - * + * * @param ids 需要删除的数据ID * @return 结果 */ diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java index cb2f04373..f342cfa7e 100644 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java +++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java @@ -2,18 +2,18 @@ package com.ruoyi.generator.service; import java.util.List; import java.util.Map; + import com.ruoyi.generator.domain.GenTable; /** * 业务 服务层 - * + * * @author ruoyi */ -public interface IGenTableService -{ +public interface IGenTableService { /** * 查询业务列表 - * + * * @param genTable 业务信息 * @return 业务集合 */ @@ -21,7 +21,7 @@ public interface IGenTableService /** * 查询据库列表 - * + * * @param genTable 业务信息 * @return 数据库表集合 */ @@ -29,7 +29,7 @@ public interface IGenTableService /** * 查询据库列表 - * + * * @param tableNames 表名称组 * @return 数据库表集合 */ @@ -37,7 +37,7 @@ public interface IGenTableService /** * 查询业务信息 - * + * * @param id 业务ID * @return 业务信息 */ @@ -45,7 +45,7 @@ public interface IGenTableService /** * 修改业务 - * + * * @param genTable 业务信息 * @return 结果 */ @@ -53,7 +53,7 @@ public interface IGenTableService /** * 删除业务信息 - * + * * @param tableIds 需要删除的表数据ID * @return 结果 */ @@ -61,14 +61,14 @@ public interface IGenTableService /** * 导入表结构 - * + * * @param tableList 导入表列表 */ public void importGenTable(List tableList); /** * 预览代码 - * + * * @param tableId 表编号 * @return 预览数据列表 */ @@ -76,7 +76,7 @@ public interface IGenTableService /** * 生成代码(下载方式) - * + * * @param tableName 表名称 * @return 数据 */ @@ -84,7 +84,7 @@ public interface IGenTableService /** * 生成代码(自定义路径) - * + * * @param tableName 表名称 * @return 数据 */ @@ -92,14 +92,14 @@ public interface IGenTableService /** * 同步数据库 - * + * * @param tableName 表名称 */ public void synchDb(String tableName); /** * 批量生成代码(下载方式) - * + * * @param tableNames 表数组 * @return 数据 */ @@ -107,7 +107,7 @@ public interface IGenTableService /** * 修改保存参数校验 - * + * * @param genTable 业务信息 */ public void validateEdit(GenTable genTable); diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java index 612ae30d0..1aee0196c 100644 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java +++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java @@ -1,6 +1,7 @@ package com.ruoyi.generator.util; import java.util.Arrays; + import org.apache.commons.lang3.RegExUtils; import com.ruoyi.common.constant.GenConstants; import com.ruoyi.common.utils.StringUtils; @@ -10,16 +11,14 @@ import com.ruoyi.generator.domain.GenTableColumn; /** * 代码生成器 工具类 - * + * * @author ruoyi */ -public class GenUtils -{ +public class GenUtils { /** * 初始化表信息 */ - public static void initTable(GenTable genTable, String operName) - { + public static void initTable(GenTable genTable, String operName) { genTable.setClassName(convertClassName(genTable.getTableName())); genTable.setPackageName(GenConfig.getPackageName()); genTable.setModuleName(getModuleName(GenConfig.getPackageName())); @@ -32,8 +31,7 @@ public class GenUtils /** * 初始化列属性字段 */ - public static void initColumnField(GenTableColumn column, GenTable table) - { + public static void initColumnField(GenTableColumn column, GenTable table) { String dataType = getDbType(column.getColumnType()); String columnName = column.getColumnName(); column.setTableId(table.getTableId()); @@ -43,36 +41,28 @@ public class GenUtils // 设置默认类型 column.setJavaType(GenConstants.TYPE_STRING); - if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) - { + if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) { // 字符串长度超过500设置为文本域 Integer columnLength = getColumnLength(column.getColumnType()); String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT; column.setHtmlType(htmlType); - } - else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) - { + } else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) { column.setJavaType(GenConstants.TYPE_DATE); column.setHtmlType(GenConstants.HTML_DATETIME); - } - else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) - { + } else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) { column.setHtmlType(GenConstants.HTML_INPUT); // 如果是浮点型 统一用BigDecimal String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ","); - if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) - { + if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) { column.setJavaType(GenConstants.TYPE_BIGDECIMAL); } // 如果是整形 - else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) - { + else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) { column.setJavaType(GenConstants.TYPE_INTEGER); } // 长整形 - else - { + else { column.setJavaType(GenConstants.TYPE_LONG); } } @@ -81,69 +71,59 @@ public class GenUtils column.setIsInsert(GenConstants.REQUIRE); // 编辑字段 - if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk()) - { + if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk()) { column.setIsEdit(GenConstants.REQUIRE); } // 列表字段 - if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk()) - { + if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk()) { column.setIsList(GenConstants.REQUIRE); } // 查询字段 - if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) - { + if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) { column.setIsQuery(GenConstants.REQUIRE); } // 查询字段类型 - if (StringUtils.endsWithIgnoreCase(columnName, "name")) - { + if (StringUtils.endsWithIgnoreCase(columnName, "name")) { column.setQueryType(GenConstants.QUERY_LIKE); } // 状态字段设置单选框 - if (StringUtils.endsWithIgnoreCase(columnName, "status")) - { + if (StringUtils.endsWithIgnoreCase(columnName, "status")) { column.setHtmlType(GenConstants.HTML_RADIO); } // 类型&性别字段设置下拉框 else if (StringUtils.endsWithIgnoreCase(columnName, "type") - || StringUtils.endsWithIgnoreCase(columnName, "sex")) - { + || StringUtils.endsWithIgnoreCase(columnName, "sex")) { column.setHtmlType(GenConstants.HTML_SELECT); } // 文件字段设置上传控件 - else if (StringUtils.endsWithIgnoreCase(columnName, "image")) - { + else if (StringUtils.endsWithIgnoreCase(columnName, "image")) { column.setHtmlType(GenConstants.HTML_UPLOAD_IMAGE); } // 内容字段设置富文本控件 - else if (StringUtils.endsWithIgnoreCase(columnName, "content")) - { + else if (StringUtils.endsWithIgnoreCase(columnName, "content")) { column.setHtmlType(GenConstants.HTML_EDITOR); } } /** * 校验数组是否包含指定值 - * - * @param arr 数组 + * + * @param arr 数组 * @param targetValue 值 * @return 是否包含 */ - public static boolean arraysContains(String[] arr, String targetValue) - { + public static boolean arraysContains(String[] arr, String targetValue) { return Arrays.asList(arr).contains(targetValue); } /** * 获取模块名 - * + * * @param packageName 包名 * @return 模块名 */ - public static String getModuleName(String packageName) - { + public static String getModuleName(String packageName) { int lastIndex = packageName.lastIndexOf("."); int nameLength = packageName.length(); String moduleName = StringUtils.substring(packageName, lastIndex + 1, nameLength); @@ -152,12 +132,11 @@ public class GenUtils /** * 获取业务名 - * + * * @param tableName 表名 * @return 业务名 */ - public static String getBusinessName(String tableName) - { + public static String getBusinessName(String tableName) { int lastIndex = tableName.lastIndexOf("_"); int nameLength = tableName.length(); String businessName = StringUtils.substring(tableName, lastIndex + 1, nameLength); @@ -166,16 +145,14 @@ public class GenUtils /** * 表名转换成Java类名 - * + * * @param tableName 表名称 * @return 类名 */ - public static String convertClassName(String tableName) - { + public static String convertClassName(String tableName) { boolean autoRemovePre = GenConfig.getAutoRemovePre(); String tablePrefix = GenConfig.getTablePrefix(); - if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) - { + if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) { String[] searchList = StringUtils.split(tablePrefix, ","); tableName = replaceFirst(tableName, searchList); } @@ -184,18 +161,15 @@ public class GenUtils /** * 批量替换前缀 - * + * * @param replacementm 替换值 - * @param searchList 替换列表 + * @param searchList 替换列表 * @return */ - public static String replaceFirst(String replacementm, String[] searchList) - { + public static String replaceFirst(String replacementm, String[] searchList) { String text = replacementm; - for (String searchString : searchList) - { - if (replacementm.startsWith(searchString)) - { + for (String searchString : searchList) { + if (replacementm.startsWith(searchString)) { text = replacementm.replaceFirst(searchString, ""); break; } @@ -205,48 +179,39 @@ public class GenUtils /** * 关键字替换 - * + * * @param text 需要被替换的名字 * @return 替换后的名字 */ - public static String replaceText(String text) - { + public static String replaceText(String text) { return RegExUtils.replaceAll(text, "(?:表|若依)", ""); } /** * 获取数据库类型字段 - * + * * @param columnType 列类型 * @return 截取后的列类型 */ - public static String getDbType(String columnType) - { - if (StringUtils.indexOf(columnType, "(") > 0) - { + public static String getDbType(String columnType) { + if (StringUtils.indexOf(columnType, "(") > 0) { return StringUtils.substringBefore(columnType, "("); - } - else - { + } else { return columnType; } } /** * 获取字段长度 - * + * * @param columnType 列类型 * @return 截取后的列类型 */ - public static Integer getColumnLength(String columnType) - { - if (StringUtils.indexOf(columnType, "(") > 0) - { + public static Integer getColumnLength(String columnType) { + if (StringUtils.indexOf(columnType, "(") > 0) { String length = StringUtils.substringBetween(columnType, "(", ")"); return Integer.valueOf(length); - } - else - { + } else { return 0; } } diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityInitializer.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityInitializer.java index 8f9ee07b8..08fe390ff 100644 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityInitializer.java +++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityInitializer.java @@ -1,24 +1,22 @@ package com.ruoyi.generator.util; import java.util.Properties; + import org.apache.velocity.app.Velocity; import com.ruoyi.common.constant.Constants; /** * VelocityEngine工厂 - * + * * @author RuoYi */ -public class VelocityInitializer -{ +public class VelocityInitializer { /** * 初始化vm方法 */ - public static void initVelocity() - { + public static void initVelocity() { Properties p = new Properties(); - try - { + try { // 加载classpath目录下的vm文件 p.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); // 定义字符集 @@ -26,9 +24,7 @@ public class VelocityInitializer p.setProperty(Velocity.OUTPUT_ENCODING, Constants.UTF8); // 初始化Velocity引擎,指定配置Properties Velocity.init(p); - } - catch (Exception e) - { + } catch (Exception e) { throw new RuntimeException(e); } } diff --git a/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/dataobject/codegen/ToolCodegenColumnDO.java b/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/dataobject/codegen/ToolCodegenColumnDO.java index c9100460b..cebb37343 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/dataobject/codegen/ToolCodegenColumnDO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/dataobject/codegen/ToolCodegenColumnDO.java @@ -1,6 +1,10 @@ package cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen; import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictTypeDO; +import cn.iocoder.dashboard.modules.tool.enums.codegen.ToolCodegenColumnHtmlTypeEnum; +import cn.iocoder.dashboard.modules.tool.enums.codegen.ToolCodegenColumnListConditionEnum; +import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Builder; import lombok.Data; @@ -17,6 +21,99 @@ import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) public class ToolCodegenColumnDO extends BaseDO { + /** + * ID 编号 + */ + @TableId + private Long id; + /** + * 表编号 + * + * 外键 {@link ToolCodegenTableDO#getId()} + */ + private Long tableId; + + // ========== 表相关字段 ========== + + /** + * 字段名 + */ + private String columnName; + /** + * 字段类型 + */ + private String columnType; + /** + * 字段描述 + */ + private String columnComment; + /** + * 是否允许为空 + */ + private Boolean nullable; + /** + * 是否主键 + */ + private Boolean primaryKey; + /** + * 是否自增 + */ + private Boolean autoIncrement; + /** + * 排序字段 + */ + private Integer ordinalPosition; + + // ========== Java 相关字段 ========== + + /** + * Java 属性类型 + * + * 例如说 String、Boolean 等等 + */ + private String javaType; + /** + * Java 属性名 + */ +// @NotBlank(message = "Java属性不能为空") + private String javaField; + /** + * 字典类型 + * + * 关联 {@link SysDictTypeDO#getType()} + */ + private String dictType; + + // ========== CRUD 相关字段 ========== + + /** + * 是否为 Create 创建操作的字段 + */ + private Boolean createOperation; + /** + * 是否为 Update 更新操作的字段 + */ + private Boolean updateOperation; + /** + * 是否为 List 查询操作的返回字段 + */ + private Boolean listOperationResult; + /** + * List 查询操作的条件类型 + * 如果为空,则说明不是查询字段 + * + * 枚举 {@link ToolCodegenColumnListConditionEnum} + */ + private String listOperationCondition; + + // ========== UI 相关字段 ========== + + /** + * 显示类型 + * + * 枚举 {@link ToolCodegenColumnHtmlTypeEnum} + */ + private String htmlType; } diff --git a/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/dataobject/codegen/ToolCodegenTableDO.java b/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/dataobject/codegen/ToolCodegenTableDO.java index 518528f92..4ad146ecc 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/dataobject/codegen/ToolCodegenTableDO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/dataobject/codegen/ToolCodegenTableDO.java @@ -1,7 +1,7 @@ package cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen; import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.dashboard.modules.tool.enums.codegen.ToolCodeGenTemplateTypeEnum; +import cn.iocoder.dashboard.modules.tool.enums.codegen.ToolCodegenTemplateTypeEnum; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Builder; import lombok.Data; @@ -18,12 +18,13 @@ import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) public class ToolCodegenTableDO extends BaseDO { - // ========== 表相关字段 ========== - /** * ID 编号 */ private Long id; + + // ========== 表相关字段 ========== + /** * 表名称 */ @@ -78,7 +79,7 @@ public class ToolCodegenTableDO extends BaseDO { /** * 模板类型 * - * 枚举 {@link ToolCodeGenTemplateTypeEnum} + * 枚举 {@link ToolCodegenTemplateTypeEnum} */ private Integer templateType; diff --git a/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/dataobject/codegen/ToolInformationSchemaColumnDO.java b/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/dataobject/codegen/ToolInformationSchemaColumnDO.java index 2cbf10219..adcc61b27 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/dataobject/codegen/ToolInformationSchemaColumnDO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/dataobject/codegen/ToolInformationSchemaColumnDO.java @@ -27,6 +27,10 @@ public class ToolInformationSchemaColumnDO { * 字段类型 */ private String columnType; + /** + * 字段描述 + */ + private String columnComment; /** * 是否允许为空 */ @@ -37,6 +41,11 @@ public class ToolInformationSchemaColumnDO { */ @TableField("case when column_key = 'PRI' then '1' else '0' end") private Boolean primaryKey; + /** + * 是否自增 + */ + @TableField("case when extra = 'auto_increment' then '1' else '0' end") + private Boolean autoIncrement; /** * 排序字段 */ diff --git a/src/main/java/cn/iocoder/dashboard/modules/tool/enums/codegen/ToolCodegenColumnHtmlTypeEnum.java b/src/main/java/cn/iocoder/dashboard/modules/tool/enums/codegen/ToolCodegenColumnHtmlTypeEnum.java new file mode 100644 index 000000000..f1f791034 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/tool/enums/codegen/ToolCodegenColumnHtmlTypeEnum.java @@ -0,0 +1,28 @@ +package cn.iocoder.dashboard.modules.tool.enums.codegen; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 代码生成器的字段 HTML 展示枚举 + */ +@AllArgsConstructor +@Getter +public enum ToolCodegenColumnHtmlTypeEnum { + + INPUT("input"), // 文本框 + TEXTAREA("textarea"), // 文本域 + SELECT("select"), // 下拉框 + RADIO("radio"), // 单选框 + CHECKBOX("checkbox"), // 复选框 + DATETIME("datetime"), // 日期控件 + UPLOAD_IMAGE("upload_image"), // 上传控件 + EDITOR("editor"), // 富文本控件 + ; + + /** + * 条件 + */ + private final String condition; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/tool/enums/codegen/ToolCodegenColumnListConditionEnum.java b/src/main/java/cn/iocoder/dashboard/modules/tool/enums/codegen/ToolCodegenColumnListConditionEnum.java new file mode 100644 index 000000000..bfa76a84b --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/tool/enums/codegen/ToolCodegenColumnListConditionEnum.java @@ -0,0 +1,27 @@ +package cn.iocoder.dashboard.modules.tool.enums.codegen; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 代码生成器的字段过滤条件枚举 + */ +@AllArgsConstructor +@Getter +public enum ToolCodegenColumnListConditionEnum { + + EQ("="), + NE("!="), + GT(">"), + GTE(">="), + LT("<"), + LTE("<="), + LIKE("LIKE"), + BETWEEN("BETWEEN"); + + /** + * 条件 + */ + private final String condition; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/tool/enums/codegen/ToolCodeGenTemplateTypeEnum.java b/src/main/java/cn/iocoder/dashboard/modules/tool/enums/codegen/ToolCodegenTemplateTypeEnum.java similarity index 89% rename from src/main/java/cn/iocoder/dashboard/modules/tool/enums/codegen/ToolCodeGenTemplateTypeEnum.java rename to src/main/java/cn/iocoder/dashboard/modules/tool/enums/codegen/ToolCodegenTemplateTypeEnum.java index 7939b84e8..30394544e 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/tool/enums/codegen/ToolCodeGenTemplateTypeEnum.java +++ b/src/main/java/cn/iocoder/dashboard/modules/tool/enums/codegen/ToolCodegenTemplateTypeEnum.java @@ -10,7 +10,7 @@ import lombok.Getter; */ @AllArgsConstructor @Getter -public enum ToolCodeGenTemplateTypeEnum { +public enum ToolCodegenTemplateTypeEnum { CRUD(1), // 基础 CRUD TREE(2), // 树形 CRUD