From 528d2a9bca4b1aec64010b2d0b461880a3ea526d Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 2 Feb 2021 01:07:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=20do=20=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E7=9A=84=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/enums/OldCommonStatusEnum.java | 27 ------------------- .../codegen/impl/ToolCodegenBuilder.java | 15 ++++++----- .../codegen/impl/ToolCodegenEngine.java | 5 ++++ src/main/resources/application.yaml | 5 +++- src/main/resources/codegen/dal/do.vm | 18 ++++++++++--- 5 files changed, 32 insertions(+), 38 deletions(-) delete mode 100644 src/main/java/cn/iocoder/dashboard/common/enums/OldCommonStatusEnum.java diff --git a/src/main/java/cn/iocoder/dashboard/common/enums/OldCommonStatusEnum.java b/src/main/java/cn/iocoder/dashboard/common/enums/OldCommonStatusEnum.java deleted file mode 100644 index 315229f54..000000000 --- a/src/main/java/cn/iocoder/dashboard/common/enums/OldCommonStatusEnum.java +++ /dev/null @@ -1,27 +0,0 @@ -package cn.iocoder.dashboard.common.enums; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 通用状态枚举 - * - * @author 芋道源码 - */ -@Getter -@AllArgsConstructor -public enum OldCommonStatusEnum { - - ENABLE("0", "开启"), - DISABLE("1", "关闭"); - - /** - * 状态值 - */ - private final String status; - /** - * 状态名 - */ - private final String name; - -} diff --git a/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenBuilder.java b/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenBuilder.java index 4abd7349b..4250c2886 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenBuilder.java +++ b/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenBuilder.java @@ -50,6 +50,10 @@ public class ToolCodegenBuilder { .put("content", ToolCodegenColumnHtmlTypeEnum.EDITOR) .build(); + /** + * {@link BaseDO} 的字段 + */ + public static final Set BASE_DO_FIELDS = new HashSet<>(); /** * 新增操作,不需要传递的字段 */ @@ -82,14 +86,13 @@ public class ToolCodegenBuilder { .build(); static { + Arrays.stream(BaseDO.class.getDeclaredFields()).forEach(field -> BASE_DO_FIELDS.add(field.getName())); // 处理 OPERATION 相关的字段 - Arrays.stream(BaseDO.class.getDeclaredFields()).forEach(field -> { - CREATE_OPERATION_EXCLUDE_COLUMN.add(field.getName()); - UPDATE_OPERATION_EXCLUDE_COLUMN.add(field.getName()); - LIST_OPERATION_EXCLUDE_COLUMN.add(field.getName()); - LIST_OPERATION_RESULT_EXCLUDE_COLUMN.add(field.getName()); - }); + CREATE_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS); + UPDATE_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS); + LIST_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS); LIST_OPERATION_EXCLUDE_COLUMN.remove("create_time"); // 创建时间,还是可能需要传递的 + LIST_OPERATION_RESULT_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS); LIST_OPERATION_RESULT_EXCLUDE_COLUMN.remove("create_time"); // 创建时间,还是需要返回的 } diff --git a/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenEngine.java b/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenEngine.java index 8e89e4e8c..6e03d59cb 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenEngine.java +++ b/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenEngine.java @@ -3,6 +3,7 @@ package cn.iocoder.dashboard.modules.tool.service.codegen.impl; import cn.hutool.extra.template.TemplateConfig; import cn.hutool.extra.template.TemplateEngine; import cn.hutool.extra.template.TemplateUtil; +import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolCodegenColumnDO; import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolCodegenTableDO; import org.springframework.stereotype.Component; @@ -37,6 +38,10 @@ public class ToolCodegenEngine { Map bindingMap = new HashMap<>(); bindingMap.put("table", table); bindingMap.put("columns", columns); + bindingMap.put("basePackage", "cn.iocoder.dashboard.modules"); // TODO 基础包 + // DO 类,独有字段 + bindingMap.put("baseDOFields", ToolCodegenBuilder.BASE_DO_FIELDS); + bindingMap.put("baseDOClassName", BaseDO.class.getName()); String result = templateEngine.getTemplate("codegen/dal/do.vm").render(bindingMap); System.out.println(result); } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index e313d6e47..634cbd325 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -39,6 +39,9 @@ spring: write-durations-as-timestamps: true # 设置 Duration 的格式,使用时间戳 fail-on-empty-beans: false # 允许序列化无属性的 Bean + main: + lazy-initialization: true # TODO 芋艿:本地开发环境,可以配置下 lazy 延迟加载 + # 芋道配置项,设置当前项目所有自定义的配置 yudao: version: 1.0.0 @@ -79,7 +82,7 @@ apollo: mybatis-plus: configuration: map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。 - log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 打印日志 +# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 打印日志 global-config: db-config: id-type: auto # 自增 ID diff --git a/src/main/resources/codegen/dal/do.vm b/src/main/resources/codegen/dal/do.vm index 0e5db0e7b..e01778d60 100644 --- a/src/main/resources/codegen/dal/do.vm +++ b/src/main/resources/codegen/dal/do.vm @@ -1,9 +1,14 @@ +package ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName}; + import com.baomidou.mybatisplus.annotation.*; +import ${baseDOClassName}; import lombok.*; import java.util.*; /** -* ${table.description} +* ${table.classComment} DO +* +* @author ${table.author} */ @TableName("${table.tableName}") @Data @@ -12,19 +17,24 @@ import java.util.*; @Builder @NoArgsConstructor @AllArgsConstructor -public class ${table.tableName}DO extends BaseDO { +public class ${table.className}DO extends BaseDO { #foreach ($column in $columns) +#if (!${baseDOFields.contains(${column.javaField})})##排除 BaseDO 的字段 /** * ${column.columnComment} */ -#if(${column.primaryKey} && ${column.javaType} != 'String') +#if ($column.dictType != "")##处理枚举值 + // TODO 枚举 ${column.dictType} +#end +#if (${column.primaryKey} && ${column.javaType} != 'String')##处理主键 + 非 String 的情况 @TableId #end -#if(${column.primaryKey} && ${column.javaType} == 'String') +#if (${column.primaryKey} && ${column.javaType} == 'String')##处理主键 + String 的情况 @TableId(type = IdType.INPUT) #end private ${column.javaType} ${column.javaField}; #end +#end }