2 Commits

Author SHA1 Message Date
cuijiawang
b366869a00 gateway 2025-10-13 16:32:54 +08:00
cuijiawang
a8e2887bbf fix 2025-10-11 09:55:31 +08:00
105 changed files with 302 additions and 130 deletions

View File

@@ -18,6 +18,7 @@
<module>wol-common-redis</module> <module>wol-common-redis</module>
<module>wol-common-json</module> <module>wol-common-json</module>
<module>wol-common-satoken</module> <module>wol-common-satoken</module>
<module>wol-common-nacos</module>
</modules> </modules>
<packaging>pom</packaging> <packaging>pom</packaging>

View File

@@ -52,7 +52,11 @@
<artifactId>wol-common-satoken</artifactId> <artifactId>wol-common-satoken</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-nacos</artifactId>
<version>${revision}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

View File

@@ -0,0 +1,21 @@
wol:
mysql:
maser:
url: ${MYSQL_URL:121.41.64.98:3306}
username: ${MYSQL_USERNAME:agileboot}
password: ${MYSQL_PASSWORD:123456}
redis:
database: ${REDIS_DATABASE:3}
host: ${REDIS_HOST:121.41.64.98}
port: ${REDIS_PORT:6379}
password: ${REDIS_PASSWORD:'Wyy123123'}
nacos:
server:
addr: ${NACOS_ADDR:192.168.110.27:8848}
username: ${NACOS_USERNAME:nacos}
password: ${NACOS_PASSWORD:nacos}
namespace: ${NACOS_NAMESPACE:public}
group: ${NACOS_GROUP:DEFAULT_GROUP}
jasypt:
encryptor:
password: ${JASYPT_ENCRYPTOR_PASSWORD:}

View File

@@ -30,3 +30,58 @@ mybatis-plus:
insertStrategy: NOT_NULL insertStrategy: NOT_NULL
updateStrategy: NOT_NULL updateStrategy: NOT_NULL
whereStrategy: NOT_NULL whereStrategy: NOT_NULL
# 数据源配置
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
druid:
webStatFilter:
enabled: true
statViewServlet:
enabled: true
# 设置白名单,不填则允许所有访问
allow:
url-pattern: /druid/*
# 控制台管理用户名和密码
login-username: agileboot
login-password: 123456
filter:
stat:
enabled: true
# 慢SQL记录
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: true
wall:
config:
multi-statement-allow: true
dynamic:
primary: master
strict: false
druid:
# 初始连接数
initialSize: 5
# 最小连接池数量
minIdle: 10
# 最大连接池数量
maxActive: 20
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 300000
# 配置一个连接在池中最大生存的时间,单位是毫秒
maxEvictableIdleTimeMillis: 900000
# 配置检测连接是否有效
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
datasource:
master:
url: jdbc:mysql://${wol.mysql.maser.url}/agileboot?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
username: ${wol.mysql.maser.username}
password: ${wol.mysql.maser.password}

View File

@@ -0,0 +1,38 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.agileboot</groupId>
<artifactId>agileboot-common</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>wol-common-nacos</artifactId>
<dependencies>
<!-- Nacos 服务注册与发现-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 配置中心 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- Spring Boot 3 + Spring Cloud 2023 默认不启用 bootstrap -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,18 @@
spring:
cloud:
nacos:
discovery:
server-addr: ${wol.nacos.server.addr}
username: ${wol.nacos.server.username}
password: ${wol.nacos.server.password}
group: ${wol.nacos.server.group}
namespace: ${wol.nacos.server.namespace}
config:
server-addr: ${wol.nacos.server.addr}
group: ${wol.nacos.server.group}
namespace: ${wol.nacos.server.namespace}
file-extension: yaml
refresh-enabled: true # 是否开启动态刷新
name: ${spring.application.name}
username: ${wol.nacos.server.username}
password: ${wol.nacos.server.password}

View File

@@ -40,6 +40,19 @@
<groupId>com.fasterxml.jackson.datatype</groupId> <groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId> <artifactId>jackson-datatype-jsr310</artifactId>
</dependency> </dependency>
<!-- JetCache -->
<!-- <dependency>-->
<!-- <groupId>com.alicp.jetcache</groupId>-->
<!-- <artifactId>jetcache-starter-redisson</artifactId>-->
<!-- <version>2.7.5</version>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-logging</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
</dependencies> </dependencies>
</project> </project>

View File

@@ -1,5 +1,6 @@
package com.agileboot.common.redis.config; package com.agileboot.common.redis.config;
import com.agileboot.common.core.factory.YmlPropertySourceFactory;
import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.annotation.PropertyAccessor;
@@ -12,6 +13,7 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
@@ -19,6 +21,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
@Slf4j @Slf4j
@AutoConfiguration @AutoConfiguration
@PropertySource(value = "classpath:common-cache.yml", factory = YmlPropertySourceFactory.class)
public class RedisConfiguration { public class RedisConfiguration {
@Bean @Bean

View File

@@ -0,0 +1,46 @@
spring:
data:
redis:
database: ${wol.redis.database}
host: ${wol.redis.host}
port: ${wol.redis.port}
password: ${wol.redis.password}
redis:
redisson:
config: |
singleServerConfig:
idleConnectionTimeout: 10000
connectTimeout: 10000
timeout: 3000
retryAttempts: 3
retryInterval: 1500
password: ${wol.redis.password}
subscriptionsPerConnection: 5
clientName: null
address: "redis://${wol.redis.host}:${wol.redis.port}"
subscriptionConnectionMinimumIdleSize: 1
subscriptionConnectionPoolSize: 50
connectionMinimumIdleSize: 24
connectionPoolSize: 64
database: 0
dnsMonitoringInterval: 5000
threads: 16
nettyThreads: 32
codec: !<org.redisson.client.codec.StringCodec> {}
transportMode: "NIO"
jetcache:
statIntervalMinutes: 1
areaInCacheName: false
local:
default:
type: caffeine
keyConvertor: fastjson2
remote:
default:
type: redisson
keyConvertor: fastjson2
broadcastChannel: ${spring.application.name}
keyPrefix: ${spring.application.name}
valueEncoder: java
valueDecoder: java
defaultExpireInMillis: 5000

View File

@@ -1,16 +1,13 @@
package com.agileboot.common.satoken.config; package com.agileboot.common.satoken.config;
import cn.dev33.satoken.SaManager;
import cn.dev33.satoken.filter.SaServletFilter; import cn.dev33.satoken.filter.SaServletFilter;
import cn.dev33.satoken.interceptor.SaInterceptor; import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter; import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.same.SaSameUtil;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult; import cn.dev33.satoken.util.SaResult;
import com.agileboot.common.core.constant.HttpStatus; import com.agileboot.common.core.constant.HttpStatus;
import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@@ -21,6 +18,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
* @author Lion Li * @author Lion Li
*/ */
@AutoConfiguration @AutoConfiguration
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
public class SaTokenMvcConfiguration implements WebMvcConfigurer { public class SaTokenMvcConfiguration implements WebMvcConfigurer {
/** /**
@@ -36,7 +34,6 @@ public class SaTokenMvcConfiguration implements WebMvcConfigurer {
* 注册 [Sa-Token全局过滤器] * 注册 [Sa-Token全局过滤器]
*/ */
@Bean @Bean
@ConditionalOnMissingClass("cn.dev33.satoken.reactor.spring.SaTokenContextRegister")
public SaServletFilter getGlobleSaServletFilter() { public SaServletFilter getGlobleSaServletFilter() {
return new SaServletFilter() return new SaServletFilter()
.addInclude("/**").addExclude("/favicon.ico") .addInclude("/**").addExclude("/favicon.ico")
@@ -47,36 +44,4 @@ public class SaTokenMvcConfiguration implements WebMvcConfigurer {
.setError(e -> SaResult.error("认证失败,无法访问系统资源").setCode(HttpStatus.UNAUTHORIZED)); .setError(e -> SaResult.error("认证失败,无法访问系统资源").setCode(HttpStatus.UNAUTHORIZED));
} }
/**
* 校验是否从网关转发
*/
@Bean
@ConditionalOnMissingBean(SaServletFilter.class)
public SaServletFilter getSaServletFilter() {
return new SaServletFilter()
.addInclude("/**")
.addExclude("/actuator", "/actuator/**")
.setAuth(obj -> {
if (SaManager.getConfig().getCheckSameToken()) {
SaSameUtil.checkCurrentRequestToken();
}
})
.setError(e -> SaResult.error("认证失败,无法访问系统资源").setCode(HttpStatus.UNAUTHORIZED));
}
/**
* 对 actuator 健康检查接口 做账号密码鉴权
*/
// @Bean
// public SaServletFilter actuatorFilter() {
// String username = SpringUtil.getProperty("spring.cloud.nacos.discovery.metadata.username");
// String password = SpringUtil.getProperty("spring.cloud.nacos.discovery.metadata.userpassword");
// return new SaServletFilter()
// .addInclude("/actuator", "/actuator/**")
// .setAuth(obj -> {
// SaHttpBasicUtil.check(username + ":" + password);
// })
// .setError(e -> SaResult.error(e.getMessage()).setCode(HttpStatus.UNAUTHORIZED));
// }
} }

View File

@@ -13,7 +13,6 @@
<module>wol-auth</module> <module>wol-auth</module>
<module>agileboot-system-base</module> <module>agileboot-system-base</module>
<module>wol-gateway</module> <module>wol-gateway</module>
<module>wol-codegenerator</module>
</modules> </modules>
<dependencyManagement> <dependencyManagement>
@@ -23,6 +22,11 @@
<artifactId>agileboot-system-base</artifactId> <artifactId>agileboot-system-base</artifactId>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-nacos</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

View File

@@ -11,6 +11,10 @@
<artifactId>wol-auth</artifactId> <artifactId>wol-auth</artifactId>
<properties>
<application.name>wol-auth</application.name>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.agileboot</groupId> <groupId>com.agileboot</groupId>

View File

@@ -1,67 +1,3 @@
# 数据源配置
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
druid:
webStatFilter:
enabled: true
statViewServlet:
enabled: true
# 设置白名单,不填则允许所有访问
allow:
url-pattern: /druid/*
# 控制台管理用户名和密码
login-username: agileboot
login-password: 123456
filter:
stat:
enabled: true
# 慢SQL记录
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: true
wall:
config:
multi-statement-allow: true
dynamic:
primary: master
strict: false
druid:
# 初始连接数
initialSize: 5
# 最小连接池数量
minIdle: 10
# 最大连接池数量
maxActive: 20
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 300000
# 配置一个连接在池中最大生存的时间,单位是毫秒
maxEvictableIdleTimeMillis: 900000
# 配置检测连接是否有效
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
datasource:
master:
url: jdbc:mysql://121.41.64.98:3306/agileboot?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&sslMode=REQUIRED
username: agileboot
password: 123456
data:
redis:
database: 3
host: 121.41.64.98
port: 6379
password: 'Wyy123123'
jasypt:
encryptor:
password: ${JASYPT_ENCRYPTOR_PASSWORD:}
# redisson 配置 # redisson 配置
#redisson: #redisson:
# # redis key前缀 # # redis key前缀

View File

@@ -4,6 +4,8 @@ server:
context-path: / context-path: /
spring: spring:
application: application:
name: agileboot-system name: @application.name@
config:
import: classpath:base.yml
profiles: profiles:
active: dev active: dev

View File

@@ -11,7 +11,17 @@
<artifactId>wol-gateway</artifactId> <artifactId>wol-gateway</artifactId>
<properties>
<application.name>wol-gateway</application.name>
</properties>
<dependencies> <dependencies>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-nacos</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.agileboot</groupId> <groupId>com.agileboot</groupId>
<artifactId>wol-common-satoken</artifactId> <artifactId>wol-common-satoken</artifactId>
@@ -27,16 +37,27 @@
<groupId>cn.dev33</groupId> <groupId>cn.dev33</groupId>
<artifactId>sa-token-reactor-spring-boot3-starter</artifactId> <artifactId>sa-token-reactor-spring-boot3-starter</artifactId>
<version>${satoken.version}</version> <version>${satoken.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId> <artifactId>spring-cloud-starter-gateway</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId> <artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@@ -9,7 +9,7 @@ import org.springframework.boot.context.metrics.buffering.BufferingApplicationSt
* *
* @author ruoyi * @author ruoyi
*/ */
@SpringBootApplication @SpringBootApplication(scanBasePackages = "com.agileboot.gateway")
public class WolGatewayApplication { public class WolGatewayApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication application = new SpringApplication(WolGatewayApplication.class); SpringApplication application = new SpringApplication(WolGatewayApplication.class);

View File

@@ -1,4 +1,4 @@
package com.agileboot.gateway.filter; package com.agileboot.gateway.config;
import cn.dev33.satoken.exception.NotLoginException; import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.reactor.context.SaReactorSyncHolder; import cn.dev33.satoken.reactor.context.SaReactorSyncHolder;
@@ -19,7 +19,7 @@ import org.springframework.http.server.reactive.ServerHttpRequest;
* @author Lion Li * @author Lion Li
*/ */
@Configuration @Configuration
public class AuthFilter { public class SaTokenConfig {
/** /**
* 注册 Sa-Token 全局过滤器 * 注册 Sa-Token 全局过滤器
@@ -29,7 +29,7 @@ public class AuthFilter {
return new SaReactorFilter() return new SaReactorFilter()
// 拦截地址 // 拦截地址
.addInclude("/**") .addInclude("/**")
.addExclude("/favicon.ico", "/actuator", "/actuator/**", "/resource/sse") .addExclude("/favicon.ico", "/actuator", "/actuator/**")
// 鉴权方法每次访问进入 // 鉴权方法每次访问进入
.setAuth(obj -> { .setAuth(obj -> {
// 登录校验 -- 拦截所有路由 // 登录校验 -- 拦截所有路由

View File

@@ -0,0 +1,6 @@
FROM amazoncorretto:17
MAINTAINER 1293433164@qq.com
ADD target/wol-gateway-1.0.0.jar /gateway.jar
EXPOSE 18080
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
ENTRYPOINT ["java", "-jar", "/gateway.jar"]

View File

@@ -1,9 +1,18 @@
# Tomcat # Tomcat
server: server:
port: 8080 port: 18080
servlet: servlet:
context-path: / context-path: /
spring: spring:
application: application:
name: wol-gateway name: @application.name@
config:
import: classpath:base.yml,classpath:nacos.yml
logging:
level:
root: INFO
org.springframework.cloud.gateway: DEBUG
com.alibaba.nacos: DEBUG
org.springframework.boot: DEBUG

View File

@@ -0,0 +1,5 @@
spring:
application:
name: @application.name@
config:
import: classpath:base.yml,classpath:nacos.yml

22
pom.xml
View File

@@ -30,8 +30,9 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version> <java.version>17</java.version>
<spring.boot.version>3.5.4</spring.boot.version> <spring.boot.version>3.4.7</spring.boot.version>
<spring-cloud.version>2024.0.0</spring-cloud.version> <spring-cloud.version>2024.0.0</spring-cloud.version>
<spring-cloud-alibaba.version>2023.0.3.3</spring-cloud-alibaba.version>
<mybatis.version>3.5.16</mybatis.version> <mybatis.version>3.5.16</mybatis.version>
<mybatis-plus.version>3.5.12</mybatis-plus.version> <mybatis-plus.version>3.5.12</mybatis-plus.version>
<dynamic-ds.version>4.3.1</dynamic-ds.version> <dynamic-ds.version>4.3.1</dynamic-ds.version>
@@ -72,6 +73,14 @@
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring-cloud-alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- SpringBoot的依赖配置--> <!-- SpringBoot的依赖配置-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
@@ -319,6 +328,17 @@
<build> <build>
<!-- 用 @application.name@ 让 Maven 替换变量,确保 pom.xml 开启 资源过滤 -->
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>*/**</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<pluginManagement> <pluginManagement>
<plugins> <plugins>

View File

@@ -10,6 +10,7 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>
<module>wol-module-codegen</module>
<module>wol-module-ai</module> <module>wol-module-ai</module>
</modules> </modules>

View File

@@ -3,14 +3,14 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.agileboot</groupId> <groupId>com.agileboot</groupId>
<artifactId>agileboot-system</artifactId> <artifactId>wol-modules</artifactId>
<version>1.0.0</version> <version>1.0.0</version>
</parent> </parent>
<artifactId>wol-codegenerator</artifactId> <artifactId>wol-module-codegen</artifactId>
<packaging>jar</packaging> <!-- <packaging>jar</packaging>-->
<name>wol-codegenerator</name> <name>wol-module-codegen</name>
<url>http://maven.apache.org</url> <url>http://maven.apache.org</url>
<properties> <properties>

View File

@@ -7,7 +7,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* @Author cuiJiaWang * @Author cuiJiaWang
* @Create 2025-08-12 18:07 * @Create 2025-08-12 18:07
*/ */
@SpringBootApplication(scanBasePackages = "com.agileboot.*") @SpringBootApplication(scanBasePackages = "com.agileboot.codegen")
public class CodeGenApplication { public class CodeGenApplication {
public static void main(String[] args) { public static void main(String[] args) {

View File

@@ -37,7 +37,7 @@ public class GeneratorServiceImpl implements IGeneratorService {
public String getTemplateConfig() { public String getTemplateConfig() {
String templateConfig = ""; String templateConfig = "";
try { try {
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("template.json"); InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("wol-module-codegen/src/main/resources/template.json");
if (inputStream != null) { if (inputStream != null) {
templateConfig = new BufferedReader(new InputStreamReader(inputStream)).lines().collect(Collectors.joining(System.lineSeparator())); templateConfig = new BufferedReader(new InputStreamReader(inputStream)).lines().collect(Collectors.joining(System.lineSeparator()));
inputStream.close(); inputStream.close();
@@ -127,7 +127,7 @@ public class GeneratorServiceImpl implements IGeneratorService {
for (Object groupObj : templateGroups) { for (Object groupObj : templateGroups) {
JSONObject group = (JSONObject) groupObj; JSONObject group = (JSONObject) groupObj;
String groupName = group.getString("group"); String groupName = group.getString("group");
JSONArray templates = group.getJSONArray("templates"); JSONArray templates = group.getJSONArray("wol-module-codegen/src/main/resources/templates");
for (Object templateObj : templates) { for (Object templateObj : templates) {
JSONObject template = (JSONObject) templateObj; JSONObject template = (JSONObject) templateObj;
@@ -213,14 +213,14 @@ public class GeneratorServiceImpl implements IGeneratorService {
for (Object groupObj : allTemplates) { for (Object groupObj : allTemplates) {
JSONObject group = (JSONObject) groupObj; JSONObject group = (JSONObject) groupObj;
String groupName = group.getString("group"); String groupName = group.getString("group");
JSONArray templates = group.getJSONArray("templates"); JSONArray templates = group.getJSONArray("wol-module-codegen/src/main/resources/templates");
for (Object templateObj : templates) { for (Object templateObj : templates) {
JSONObject template = (JSONObject) templateObj; JSONObject template = (JSONObject) templateObj;
if (templateId.equals(template.getString("id"))) { if (templateId.equals(template.getString("id"))) {
String templateName = template.getString("name"); String templateName = template.getString("name");
String templatePath = groupName + "/" + templateName + ".ftl"; String templatePath = groupName + "/" + templateName + ".ftl";
// 读取模板文件内容 // 读取模板文件内容
return FreemarkerUtil.getTemplateContent(templatePath); return FreemarkerUtil.getTemplateContent(templatePath);
} }
@@ -343,7 +343,7 @@ public class GeneratorServiceImpl implements IGeneratorService {
for (Object groupObj : templateGroups) { for (Object groupObj : templateGroups) {
JSONObject group = (JSONObject) groupObj; JSONObject group = (JSONObject) groupObj;
String groupName = group.getString("group"); String groupName = group.getString("group");
JSONArray templates = group.getJSONArray("templates"); JSONArray templates = group.getJSONArray("wol-module-codegen/src/main/resources/templates");
for (Object templateObj : templates) { for (Object templateObj : templates) {
JSONObject template = (JSONObject) templateObj; JSONObject template = (JSONObject) templateObj;

View File

@@ -149,7 +149,7 @@ public class TemplateRepositoryServiceImpl implements ITemplateRepositoryService
for (Object groupObj : systemTemplates) { for (Object groupObj : systemTemplates) {
JSONObject group = (JSONObject) groupObj; JSONObject group = (JSONObject) groupObj;
String groupName = group.getString("group"); String groupName = group.getString("group");
JSONArray templates = group.getJSONArray("templates"); JSONArray templates = group.getJSONArray("wol-module-codegen/src/main/resources/templates");
for (Object templateObj : templates) { for (Object templateObj : templates) {
JSONObject template = (JSONObject) templateObj; JSONObject template = (JSONObject) templateObj;
@@ -239,7 +239,7 @@ public class TemplateRepositoryServiceImpl implements ITemplateRepositoryService
for (Object groupObj : systemTemplates) { for (Object groupObj : systemTemplates) {
JSONObject group = (JSONObject) groupObj; JSONObject group = (JSONObject) groupObj;
String groupName = group.getString("group"); String groupName = group.getString("group");
JSONArray templates = group.getJSONArray("templates"); JSONArray templates = group.getJSONArray("wol-module-codegen/src/main/resources/templates");
for (Object templateObj : templates) { for (Object templateObj : templates) {
JSONObject template = (JSONObject) templateObj; JSONObject template = (JSONObject) templateObj;
@@ -325,7 +325,7 @@ public class TemplateRepositoryServiceImpl implements ITemplateRepositoryService
for (Object groupObj : systemTemplates) { for (Object groupObj : systemTemplates) {
JSONObject group = (JSONObject) groupObj; JSONObject group = (JSONObject) groupObj;
String groupName = group.getString("group"); String groupName = group.getString("group");
JSONArray templates = group.getJSONArray("templates"); JSONArray templates = group.getJSONArray("wol-module-codegen/src/main/resources/templates");
for (Object templateObj : templates) { for (Object templateObj : templates) {
JSONObject template = (JSONObject) templateObj; JSONObject template = (JSONObject) templateObj;

View File

@@ -20,7 +20,7 @@ public class FreemarkerUtil {
static { static {
configuration = new Configuration(Configuration.VERSION_2_3_31); configuration = new Configuration(Configuration.VERSION_2_3_31);
configuration.setClassForTemplateLoading(FreemarkerUtil.class, "/templates/code-generator"); configuration.setClassForTemplateLoading(FreemarkerUtil.class, "/wol-module-codegen/src/main/resources/templates/code-generator");
configuration.setDefaultEncoding("UTF-8"); configuration.setDefaultEncoding("UTF-8");
} }
@@ -55,7 +55,7 @@ public class FreemarkerUtil {
// 创建一个临时的Configuration用于处理字符串模板 // 创建一个临时的Configuration用于处理字符串模板
Configuration tempConfig = new Configuration(Configuration.VERSION_2_3_31); Configuration tempConfig = new Configuration(Configuration.VERSION_2_3_31);
tempConfig.setDefaultEncoding("UTF-8"); tempConfig.setDefaultEncoding("UTF-8");
// 从字符串创建模板 // 从字符串创建模板
Template template = new Template("userTemplate", new StringReader(templateContent), tempConfig); Template template = new Template("userTemplate", new StringReader(templateContent), tempConfig);
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();

Some files were not shown because too many files have changed in this diff Show More