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

reactor:【INFRA 基础设施】代码生成时,更严格的区分 master 还是 master-jdk17 分支
pull/195/head
YunaiV 2025-05-17 13:12:04 +08:00
parent fbf76134bc
commit 95f1410db3
3 changed files with 51 additions and 29 deletions

View File

@ -40,6 +40,7 @@ import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import lombok.Setter;
import org.springframework.stereotype.Component;
import org.springframework.util.ClassUtils;
import java.util.*;
@ -64,7 +65,7 @@ public class CodegenEngine {
* value
*/
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/listReqVO"), javaModuleImplVOFilePath("ListReqVO"))
.put(javaTemplatePath("controller/vo/respVO"), javaModuleImplVOFilePath("RespVO"))
@ -83,7 +84,7 @@ public class CodegenEngine {
javaModuleImplMainFilePath("service/${table.businessName}/${table.className}ServiceImpl"))
.put(javaTemplatePath("service/service"),
javaModuleImplMainFilePath("service/${table.businessName}/${table.className}Service"))
// Java module-biz Test
// Java module-biz(server) Test
.put(javaTemplatePath("test/serviceTest"),
javaModuleImplTestFilePath("service/${table.businessName}/${table.className}ServiceImplTest"))
// Java module-api Main
@ -194,6 +195,15 @@ public class CodegenEngine {
@Setter // 允许设置的原因,是因为单测需要手动改变
private Boolean jakartaEnable;
/**
* yudao-cloud Boot Cloud api
*
* true - yudao-module-xxx-api
* false - 使 apienum
*/
@Setter
private Boolean cloudEnable;
/**
* hutool
*/
@ -209,7 +219,11 @@ public class CodegenEngine {
config.setResourceMode(TemplateConfig.ResourceMode.CLASSPATH);
this.templateEngine = new VelocityEngine(config);
// 设置 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
@ -434,6 +448,14 @@ public class CodegenEngine {
Map<String, String> templates = new LinkedHashMap<>();
templates.putAll(SERVER_TEMPLATES);
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())) {
templates.remove(javaTemplatePath("test/serviceTest"));
@ -480,16 +502,16 @@ public class CodegenEngine {
private static String javaModuleImplVOFilePath(String path) {
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() {
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) {
return javaModuleFilePath(path, "biz", "main");
return javaModuleFilePath(path, "server", "main");
}
private static String javaModuleApiMainFilePath(String path) {
@ -497,7 +519,7 @@ public class CodegenEngine {
}
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) {
@ -508,7 +530,7 @@ public class CodegenEngine {
private static String mapperXmlFilePath() {
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";
}

View File

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

View File

@ -66,26 +66,26 @@
<!-- </dependency>-->
<!-- 商城相关模块。默认注释,保证编译速度-->
<dependency>
<groupId>cn.iocoder.cloud</groupId>
<artifactId>yudao-module-product-server</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.cloud</groupId>
<artifactId>yudao-module-promotion-server</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.cloud</groupId>
<artifactId>yudao-module-trade-server</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.cloud</groupId>
<artifactId>yudao-module-statistics-server</artifactId>
<version>${revision}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>cn.iocoder.cloud</groupId>-->
<!-- <artifactId>yudao-module-product-server</artifactId>-->
<!-- <version>${revision}</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>cn.iocoder.cloud</groupId>-->
<!-- <artifactId>yudao-module-promotion-server</artifactId>-->
<!-- <version>${revision}</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>cn.iocoder.cloud</groupId>-->
<!-- <artifactId>yudao-module-trade-server</artifactId>-->
<!-- <version>${revision}</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>cn.iocoder.cloud</groupId>-->
<!-- <artifactId>yudao-module-statistics-server</artifactId>-->
<!-- <version>${revision}</version>-->
<!-- </dependency>-->
<!-- CRM 相关模块。默认注释,保证编译速度 -->
<!-- <dependency>-->