reactor:【INFRA 基础设施】代码生成时,区分 boot 还是 cloud 项目

reactor:【INFRA 基础设施】代码生成时,更严格的区分 master 还是 master-jdk17 分支
This commit is contained in:
YunaiV 2025-05-17 13:11:54 +08:00
parent 3e2a809f26
commit fcf097847a
2 changed files with 31 additions and 9 deletions

View File

@ -40,6 +40,7 @@ import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.Setter; import lombok.Setter;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.ClassUtils;
import java.util.*; import java.util.*;
@ -64,7 +65,7 @@ public class CodegenEngine {
* value生成的路径 * value生成的路径
*/ */
private static final Map<String, String> SERVER_TEMPLATES = MapUtil.<String, String>builder(new LinkedHashMap<>()) // 有序 private static final Map<String, String> SERVER_TEMPLATES = MapUtil.<String, String>builder(new LinkedHashMap<>()) // 有序
// Java module-biz Main // Java module-biz(server) Main
.put(javaTemplatePath("controller/vo/pageReqVO"), javaModuleImplVOFilePath("PageReqVO")) .put(javaTemplatePath("controller/vo/pageReqVO"), javaModuleImplVOFilePath("PageReqVO"))
.put(javaTemplatePath("controller/vo/listReqVO"), javaModuleImplVOFilePath("ListReqVO")) .put(javaTemplatePath("controller/vo/listReqVO"), javaModuleImplVOFilePath("ListReqVO"))
.put(javaTemplatePath("controller/vo/respVO"), javaModuleImplVOFilePath("RespVO")) .put(javaTemplatePath("controller/vo/respVO"), javaModuleImplVOFilePath("RespVO"))
@ -83,7 +84,7 @@ public class CodegenEngine {
javaModuleImplMainFilePath("service/${table.businessName}/${table.className}ServiceImpl")) javaModuleImplMainFilePath("service/${table.businessName}/${table.className}ServiceImpl"))
.put(javaTemplatePath("service/service"), .put(javaTemplatePath("service/service"),
javaModuleImplMainFilePath("service/${table.businessName}/${table.className}Service")) javaModuleImplMainFilePath("service/${table.businessName}/${table.className}Service"))
// Java module-biz Test // Java module-biz(server) Test
.put(javaTemplatePath("test/serviceTest"), .put(javaTemplatePath("test/serviceTest"),
javaModuleImplTestFilePath("service/${table.businessName}/${table.className}ServiceImplTest")) javaModuleImplTestFilePath("service/${table.businessName}/${table.className}ServiceImplTest"))
// Java module-api Main // Java module-api Main
@ -194,6 +195,15 @@ public class CodegenEngine {
@Setter // 允许设置的原因是因为单测需要手动改变 @Setter // 允许设置的原因是因为单测需要手动改变
private Boolean jakartaEnable; private Boolean jakartaEnable;
/**
* 是否为 yudao-cloud 项目用于解决 Boot Cloud api 模块兼容性问题
*
* true - 需要有 yudao-module-xxx-api 模块
* false - 不需要有使用 apienum 包即可
*/
@Setter
private Boolean cloudEnable;
/** /**
* 模板引擎 hutool 实现 * 模板引擎 hutool 实现
*/ */
@ -209,7 +219,11 @@ public class CodegenEngine {
config.setResourceMode(TemplateConfig.ResourceMode.CLASSPATH); config.setResourceMode(TemplateConfig.ResourceMode.CLASSPATH);
this.templateEngine = new VelocityEngine(config); this.templateEngine = new VelocityEngine(config);
// 设置 javaxEnable按照是否使用 JDK17 来判断 // 设置 javaxEnable按照是否使用 JDK17 来判断
this.jakartaEnable = SystemUtil.getJavaInfo().isJavaVersionAtLeast(1700); // 17.00 * 100 this.jakartaEnable = SystemUtil.getJavaInfo().isJavaVersionAtLeast(1700) // 17.00 * 100
&& ClassUtils.isPresent("jakarta.annotation.Resource", ClassUtils.getDefaultClassLoader());
// 设置 cloudEnable按照是否使用 Spring Cloud 来判断
this.cloudEnable = ClassUtils.isPresent("cn.iocoder.yudao.module.infra.framework.rpc.config.RpcConfiguration",
ClassUtils.getDefaultClassLoader());
} }
@PostConstruct @PostConstruct
@ -434,6 +448,14 @@ public class CodegenEngine {
Map<String, String> templates = new LinkedHashMap<>(); Map<String, String> templates = new LinkedHashMap<>();
templates.putAll(SERVER_TEMPLATES); templates.putAll(SERVER_TEMPLATES);
templates.putAll(FRONT_TEMPLATES.row(frontType)); templates.putAll(FRONT_TEMPLATES.row(frontType));
// 如果是 Boot 项目则不使用 api/server 模块
if (Boolean.FALSE.equals(cloudEnable)) {
SERVER_TEMPLATES.forEach((templatePath, filePath) -> {
filePath = StrUtil.replace(filePath, "/yudao-module-${table.moduleName}-api", "");
filePath = StrUtil.replace(filePath, "/yudao-module-${table.moduleName}-server", "");
templates.put(templatePath, filePath);
});
}
// 如果禁用单元测试则移除对应的模版 // 如果禁用单元测试则移除对应的模版
if (Boolean.FALSE.equals(codegenProperties.getUnitTestEnable())) { if (Boolean.FALSE.equals(codegenProperties.getUnitTestEnable())) {
templates.remove(javaTemplatePath("test/serviceTest")); templates.remove(javaTemplatePath("test/serviceTest"));
@ -480,16 +502,16 @@ public class CodegenEngine {
private static String javaModuleImplVOFilePath(String path) { private static String javaModuleImplVOFilePath(String path) {
return javaModuleFilePath("controller/${sceneEnum.basePackage}/${table.businessName}/" + return javaModuleFilePath("controller/${sceneEnum.basePackage}/${table.businessName}/" +
"vo/${sceneEnum.prefixClass}${table.className}" + path, "biz", "main"); "vo/${sceneEnum.prefixClass}${table.className}" + path, "server", "main");
} }
private static String javaModuleImplControllerFilePath() { private static String javaModuleImplControllerFilePath() {
return javaModuleFilePath("controller/${sceneEnum.basePackage}/${table.businessName}/" + return javaModuleFilePath("controller/${sceneEnum.basePackage}/${table.businessName}/" +
"${sceneEnum.prefixClass}${table.className}Controller", "biz", "main"); "${sceneEnum.prefixClass}${table.className}Controller", "server", "main");
} }
private static String javaModuleImplMainFilePath(String path) { private static String javaModuleImplMainFilePath(String path) {
return javaModuleFilePath(path, "biz", "main"); return javaModuleFilePath(path, "server", "main");
} }
private static String javaModuleApiMainFilePath(String path) { private static String javaModuleApiMainFilePath(String path) {
@ -497,7 +519,7 @@ public class CodegenEngine {
} }
private static String javaModuleImplTestFilePath(String path) { private static String javaModuleImplTestFilePath(String path) {
return javaModuleFilePath(path, "biz", "test"); return javaModuleFilePath(path, "server", "test");
} }
private static String javaModuleFilePath(String path, String module, String src) { private static String javaModuleFilePath(String path, String module, String src) {
@ -508,7 +530,7 @@ public class CodegenEngine {
private static String mapperXmlFilePath() { private static String mapperXmlFilePath() {
return "yudao-module-${table.moduleName}/" + // 顶级模块 return "yudao-module-${table.moduleName}/" + // 顶级模块
"yudao-module-${table.moduleName}-biz/" + // 子模块 "yudao-module-${table.moduleName}-server/" + // 子模块
"src/main/resources/mapper/${table.businessName}/${table.className}Mapper.xml"; "src/main/resources/mapper/${table.businessName}/${table.className}Mapper.xml";
} }

View File

@ -1,4 +1,4 @@
// TODO 待办:请将下面的错误码复制到 yudao-module-${table.moduleName}-api 模块的 ErrorCodeConstants 类中。注意请给“TODO 补充编号”设置一个错误码编号!!! // TODO 待办:请将下面的错误码复制到 yudao-module-${table.moduleName} 模块的 ErrorCodeConstants 类中。注意请给“TODO 补充编号”设置一个错误码编号!!!
// ========== ${table.classComment} TODO 补充编号 ========== // ========== ${table.classComment} TODO 补充编号 ==========
ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS = new ErrorCode(TODO 补充编号, "${table.classComment}不存在"); ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS = new ErrorCode(TODO 补充编号, "${table.classComment}不存在");
## 特殊:树表专属逻辑 ## 特殊:树表专属逻辑