chore(config): 将配置文件中的敏感信息替换为环境变量占位符
- 将 application.yml 中的邮件密码、token密钥、阿里云OSS等敏感配置替换为环境变量 - 将 application-dev.yml 中的数据库连接、Redis、MQTT等配置替换为环境变量占位符 - 将 application-prod.yml 中的数据库连接、Redis、MQTT、阿里云等配置替换为环境变量 - 为代码生成器添加环境变量支持和 .env 文件加载功能 - 更新 .gitignore 文件以忽略 .env 相关配置文件 - 修改 README.md 文档说明环境变量配置方式 - 修复联系邮箱地址错误
This commit is contained in:
8
.gitignore
vendored
8
.gitignore
vendored
@@ -31,6 +31,14 @@ build/
|
|||||||
.vscode/
|
.vscode/
|
||||||
/cert/
|
/cert/
|
||||||
/src/main/resources/dev/
|
/src/main/resources/dev/
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
/src/main/resources/application-local.yml
|
||||||
|
/src/main/resources/application-*-local.yml
|
||||||
|
/src/main/resources/application-secrets.yml
|
||||||
|
/src/main/resources/application-*.secrets.yml
|
||||||
|
/config/application-local.yml
|
||||||
|
/config/application-*-local.yml
|
||||||
|
|
||||||
### macOS ###
|
### macOS ###
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|||||||
30
README.md
30
README.md
@@ -87,17 +87,23 @@ CREATE DATABASE websoft_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|||||||
```
|
```
|
||||||
|
|
||||||
### 3. 配置文件
|
### 3. 配置文件
|
||||||
编辑 `src/main/resources/application-dev.yml` 文件,配置数据库连接:
|
本项目的 `application-*.yml` 已使用环境变量占位符,避免将真实密码提交到 Git。
|
||||||
```yaml
|
|
||||||
spring:
|
开发环境可通过环境变量配置数据库/Redis连接(示例):
|
||||||
datasource:
|
```bash
|
||||||
url: jdbc:mysql://localhost:3306/websoft_db?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
|
export SPRING_DATASOURCE_URL='jdbc:mysql://localhost:3306/websoft_db?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8'
|
||||||
username: your_username
|
export SPRING_DATASOURCE_USERNAME='your_username'
|
||||||
password: your_password
|
export SPRING_DATASOURCE_PASSWORD='your_password'
|
||||||
redis:
|
export SPRING_REDIS_HOST='localhost'
|
||||||
host: localhost
|
export SPRING_REDIS_PORT='6379'
|
||||||
port: 6379
|
export SPRING_REDIS_PASSWORD='your_redis_password'
|
||||||
password: your_redis_password
|
```
|
||||||
|
|
||||||
|
代码生成器(`src/test/java/com/gxwebsoft/generator/*Generator.java`)使用:
|
||||||
|
```bash
|
||||||
|
export CODEGEN_DB_URL='jdbc:mysql://localhost:3306/websoft_db?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8'
|
||||||
|
export CODEGEN_DB_USERNAME='your_username'
|
||||||
|
export CODEGEN_DB_PASSWORD='your_password'
|
||||||
```
|
```
|
||||||
|
|
||||||
### 4. 启动项目
|
### 4. 启动项目
|
||||||
@@ -278,7 +284,7 @@ docker run -d -p 9200:9200 websoft-api
|
|||||||
## 📞 联系我们
|
## 📞 联系我们
|
||||||
|
|
||||||
- 官网:https://websoft.top
|
- 官网:https://websoft.top
|
||||||
- 邮箱:170083662@qq.top
|
- 邮箱:170083662@qq.com
|
||||||
- QQ群:479713884
|
- QQ群:479713884
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -7,18 +7,18 @@ server:
|
|||||||
# 数据源配置
|
# 数据源配置
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
url: jdbc:mysql://47.119.165.234:13308/modules?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8
|
url: ${SPRING_DATASOURCE_URL:jdbc:mysql://localhost:3306/modules?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8}
|
||||||
username: modules
|
username: ${SPRING_DATASOURCE_USERNAME:modules}
|
||||||
password: P7KsAyDXG8YdLnkA
|
password: ${SPRING_DATASOURCE_PASSWORD:}
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
|
|
||||||
# redis
|
# redis
|
||||||
redis:
|
redis:
|
||||||
database: 0
|
database: 0
|
||||||
host: 47.119.165.234
|
host: ${SPRING_REDIS_HOST:localhost}
|
||||||
port: 16379
|
port: ${SPRING_REDIS_PORT:6379}
|
||||||
password: redis_WSDb88
|
password: ${SPRING_REDIS_PASSWORD:}
|
||||||
|
|
||||||
# 日志配置
|
# 日志配置
|
||||||
logging:
|
logging:
|
||||||
@@ -34,12 +34,12 @@ socketio:
|
|||||||
# MQTT配置
|
# MQTT配置
|
||||||
mqtt:
|
mqtt:
|
||||||
enabled: false # 添加开关来禁用MQTT服务
|
enabled: false # 添加开关来禁用MQTT服务
|
||||||
host: tcp://1.14.159.185:1883
|
host: ${MQTT_HOST:}
|
||||||
username: swdev
|
username: ${MQTT_USERNAME:}
|
||||||
password: Sw20250523
|
password: ${MQTT_PASSWORD:}
|
||||||
client-id-prefix: hjm_car_
|
client-id-prefix: ${MQTT_CLIENT_ID_PREFIX:hjm_car_}
|
||||||
topic: /SW_GPS/#
|
topic: ${MQTT_TOPIC:/SW_GPS/#}
|
||||||
qos: 2
|
qos: ${MQTT_QOS:2}
|
||||||
connection-timeout: 10
|
connection-timeout: 10
|
||||||
keep-alive-interval: 20
|
keep-alive-interval: 20
|
||||||
auto-reconnect: true
|
auto-reconnect: true
|
||||||
@@ -52,7 +52,7 @@ config:
|
|||||||
|
|
||||||
# JWT配置
|
# JWT配置
|
||||||
jwt:
|
jwt:
|
||||||
secret: websoft-jwt-secret-key-2025-dev-environment
|
secret: ${JWT_SECRET:}
|
||||||
expire: 86400 # token过期时间(秒) 24小时
|
expire: 86400 # token过期时间(秒) 24小时
|
||||||
|
|
||||||
# 开发环境证书配置
|
# 开发环境证书配置
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
# 数据源配置
|
# 数据源配置
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
url: jdbc:mysql://1Panel-mysql-Bqdt:3306/modules?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
|
url: ${SPRING_DATASOURCE_URL}
|
||||||
username: modules
|
username: ${SPRING_DATASOURCE_USERNAME}
|
||||||
password: 8YdLnk7KsPAyDXGA
|
password: ${SPRING_DATASOURCE_PASSWORD}
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
druid:
|
druid:
|
||||||
@@ -14,9 +14,9 @@ spring:
|
|||||||
# redis
|
# redis
|
||||||
redis:
|
redis:
|
||||||
database: 0
|
database: 0
|
||||||
host: 1Panel-redis-Q1LE
|
host: ${SPRING_REDIS_HOST}
|
||||||
port: 6379
|
port: ${SPRING_REDIS_PORT:6379}
|
||||||
password: redis_WSDb88
|
password: ${SPRING_REDIS_PASSWORD:}
|
||||||
|
|
||||||
# 日志配置
|
# 日志配置
|
||||||
logging:
|
logging:
|
||||||
@@ -33,12 +33,12 @@ socketio:
|
|||||||
# MQTT配置
|
# MQTT配置
|
||||||
mqtt:
|
mqtt:
|
||||||
enabled: false # 添加开关来禁用MQTT服务
|
enabled: false # 添加开关来禁用MQTT服务
|
||||||
host: tcp://1.14.159.185:1883
|
host: ${MQTT_HOST:}
|
||||||
username: swdev
|
username: ${MQTT_USERNAME:}
|
||||||
password: Sw20250523
|
password: ${MQTT_PASSWORD:}
|
||||||
client-id-prefix: hjm_car_
|
client-id-prefix: ${MQTT_CLIENT_ID_PREFIX:hjm_car_}
|
||||||
topic: /SW_GPS/#
|
topic: ${MQTT_TOPIC:/SW_GPS/#}
|
||||||
qos: 2
|
qos: ${MQTT_QOS:2}
|
||||||
connection-timeout: 10
|
connection-timeout: 10
|
||||||
keep-alive-interval: 20
|
keep-alive-interval: 20
|
||||||
auto-reconnect: true
|
auto-reconnect: true
|
||||||
@@ -50,12 +50,12 @@ config:
|
|||||||
upload-path: /www/wwwroot/file.ws/
|
upload-path: /www/wwwroot/file.ws/
|
||||||
|
|
||||||
# 阿里云OSS云存储
|
# 阿里云OSS云存储
|
||||||
endpoint: https://oss-cn-shenzhen.aliyuncs.com
|
endpoint: ${ALIYUN_OSS_ENDPOINT:}
|
||||||
accessKeyId: LTAI4GKGZ9Z2Z8JZ77c3GNZP
|
accessKeyId: ${ALIYUN_OSS_ACCESS_KEY_ID:}
|
||||||
accessKeySecret: BiDkpS7UXj72HWwDWaFZxiXjNFBNCM
|
accessKeySecret: ${ALIYUN_OSS_ACCESS_KEY_SECRET:}
|
||||||
bucketName: oss-gxwebsoft
|
bucketName: ${ALIYUN_OSS_BUCKET_NAME:}
|
||||||
bucketDomain: https://oss.wsdns.cn
|
bucketDomain: ${ALIYUN_OSS_BUCKET_DOMAIN:}
|
||||||
aliyunDomain: https://oss-gxwebsoft.oss-cn-shenzhen.aliyuncs.com
|
aliyunDomain: ${ALIYUN_OSS_ALIYUN_DOMAIN:}
|
||||||
|
|
||||||
# 生产环境证书配置
|
# 生产环境证书配置
|
||||||
certificate:
|
certificate:
|
||||||
@@ -72,9 +72,9 @@ payment:
|
|||||||
|
|
||||||
aliyun:
|
aliyun:
|
||||||
knowledge-base:
|
knowledge-base:
|
||||||
access-key-id: LTAI5tD5YRKuxWz6Eg7qrM4P
|
access-key-id: ${ALIYUN_KB_ACCESS_KEY_ID:}
|
||||||
access-key-secret: bO8TBDXflOwbtSKimPpG8XrJnyzgTk
|
access-key-secret: ${ALIYUN_KB_ACCESS_KEY_SECRET:}
|
||||||
workspace-id: llm-4pf5auwewoz34zqu
|
workspace-id: ${ALIYUN_KB_WORKSPACE_ID:}
|
||||||
|
|
||||||
ai:
|
ai:
|
||||||
template:
|
template:
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ spring:
|
|||||||
mail:
|
mail:
|
||||||
host: smtp.qq.com
|
host: smtp.qq.com
|
||||||
username: 170083662@qq.com
|
username: 170083662@qq.com
|
||||||
password: mnfokualhfaucaie
|
password: ${SPRING_MAIL_PASSWORD:}
|
||||||
default-encoding: UTF-8
|
default-encoding: UTF-8
|
||||||
properties:
|
properties:
|
||||||
mail:
|
mail:
|
||||||
@@ -95,7 +95,7 @@ config:
|
|||||||
swagger-title: 网宿软件 API文档
|
swagger-title: 网宿软件 API文档
|
||||||
swagger-description: websoft - 基于java spring、vue3、antd构建的前后端分离快速开发框架
|
swagger-description: websoft - 基于java spring、vue3、antd构建的前后端分离快速开发框架
|
||||||
swagger-version: 2.0
|
swagger-version: 2.0
|
||||||
token-key: WLgNsWJ8rPjRtnjzX/Gx2RGS80Kwnm/ZeLbvIL+NrBs=
|
token-key: ${APP_TOKEN_KEY:}
|
||||||
# 主服务器
|
# 主服务器
|
||||||
server-url: https://server.websoft.top/api
|
server-url: https://server.websoft.top/api
|
||||||
# 文件服务器
|
# 文件服务器
|
||||||
@@ -106,12 +106,12 @@ config:
|
|||||||
local-upload-path: /Users/gxwebsoft/Documents/uploads
|
local-upload-path: /Users/gxwebsoft/Documents/uploads
|
||||||
|
|
||||||
# 阿里云OSS云存储
|
# 阿里云OSS云存储
|
||||||
endpoint: https://oss-cn-shenzhen.aliyuncs.com
|
endpoint: ${ALIYUN_OSS_ENDPOINT:}
|
||||||
accessKeyId: LTAI4GKGZ9Z2Z8JZ77c3GNZP
|
accessKeyId: ${ALIYUN_OSS_ACCESS_KEY_ID:}
|
||||||
accessKeySecret: BiDkpS7UXj72HWwDWaFZxiXjNFBNCM
|
accessKeySecret: ${ALIYUN_OSS_ACCESS_KEY_SECRET:}
|
||||||
bucketName: oss-gxwebsoft
|
bucketName: ${ALIYUN_OSS_BUCKET_NAME:}
|
||||||
bucketDomain: https://oss.wsdns.cn
|
bucketDomain: ${ALIYUN_OSS_BUCKET_DOMAIN:}
|
||||||
aliyunDomain: https://oss-gxwebsoft.oss-cn-shenzhen.aliyuncs.com
|
aliyunDomain: ${ALIYUN_OSS_ALIYUN_DOMAIN:}
|
||||||
|
|
||||||
# 商城订单配置
|
# 商城订单配置
|
||||||
shop:
|
shop:
|
||||||
@@ -176,7 +176,7 @@ certificate:
|
|||||||
# 微信支付证书配置
|
# 微信支付证书配置
|
||||||
wechat-pay:
|
wechat-pay:
|
||||||
dev:
|
dev:
|
||||||
api-v3-key: "0kF5OlPr482EZwtn9zGufUcqa7ovgxRL"
|
api-v3-key: ${WECHATPAY_API_V3_KEY:}
|
||||||
private-key-file: "apiclient_key.pem"
|
private-key-file: "apiclient_key.pem"
|
||||||
apiclient-cert-file: "apiclient_cert.pem"
|
apiclient-cert-file: "apiclient_cert.pem"
|
||||||
wechatpay-cert-file: "wechatpay_cert.pem"
|
wechatpay-cert-file: "wechatpay_cert.pem"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
|||||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||||
import com.gxwebsoft.generator.engine.BeetlTemplateEnginePlus;
|
import com.gxwebsoft.generator.engine.BeetlTemplateEnginePlus;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -40,11 +41,24 @@ public class ClinicGenerator {
|
|||||||
private static final String AUTHOR = "科技小王子";
|
private static final String AUTHOR = "科技小王子";
|
||||||
// 是否在xml中添加二级缓存配置
|
// 是否在xml中添加二级缓存配置
|
||||||
private static final boolean ENABLE_CACHE = false;
|
private static final boolean ENABLE_CACHE = false;
|
||||||
|
|
||||||
|
static {
|
||||||
|
loadDotEnvIfPresent();
|
||||||
|
}
|
||||||
|
|
||||||
// 数据库连接配置
|
// 数据库连接配置
|
||||||
private static final String DB_URL = "jdbc:mysql://8.134.169.209:13306/modules?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8";
|
private static final String DB_URL = envOrProperty(
|
||||||
private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
|
"CODEGEN_DB_URL",
|
||||||
private static final String DB_USERNAME = "modules";
|
"SPRING_DATASOURCE_URL",
|
||||||
private static final String DB_PASSWORD = "P7KsAyDXG8YdLnkA";
|
"jdbc:mysql://localhost:3306/modules?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8"
|
||||||
|
);
|
||||||
|
private static final String DB_DRIVER = envOrProperty(
|
||||||
|
"CODEGEN_DB_DRIVER",
|
||||||
|
"SPRING_DATASOURCE_DRIVER_CLASS_NAME",
|
||||||
|
"com.mysql.cj.jdbc.Driver"
|
||||||
|
);
|
||||||
|
private static final String DB_USERNAME = envOrProperty("CODEGEN_DB_USERNAME", "SPRING_DATASOURCE_USERNAME", "modules");
|
||||||
|
private static final String DB_PASSWORD = envOrProperty("CODEGEN_DB_PASSWORD", "SPRING_DATASOURCE_PASSWORD", "");
|
||||||
// 包名
|
// 包名
|
||||||
private static final String PACKAGE_NAME = "com.gxwebsoft";
|
private static final String PACKAGE_NAME = "com.gxwebsoft";
|
||||||
// 模块名
|
// 模块名
|
||||||
@@ -99,6 +113,52 @@ public class ClinicGenerator {
|
|||||||
// 模板所在位置
|
// 模板所在位置
|
||||||
private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generator/templates";
|
private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generator/templates";
|
||||||
|
|
||||||
|
private static String envOrProperty(String primaryKey, String fallbackKey, String defaultValue) {
|
||||||
|
String value = envOrProperty(primaryKey, "");
|
||||||
|
if (value.isBlank() && fallbackKey != null && !fallbackKey.isBlank()) {
|
||||||
|
value = envOrProperty(fallbackKey, "");
|
||||||
|
}
|
||||||
|
return value.isBlank() ? defaultValue : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String envOrProperty(String key, String defaultValue) {
|
||||||
|
String value = System.getProperty(key);
|
||||||
|
if (value == null || value.isBlank()) value = System.getenv(key);
|
||||||
|
if (value == null || value.isBlank()) return defaultValue;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean shouldImportDotEnvKey(String key) {
|
||||||
|
return key.startsWith("CODEGEN_") || key.startsWith("SPRING_DATASOURCE_");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadDotEnvIfPresent() {
|
||||||
|
var envPath = Paths.get(OUTPUT_LOCATION, ".env");
|
||||||
|
if (!Files.isRegularFile(envPath)) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (String rawLine : Files.readAllLines(envPath, StandardCharsets.UTF_8)) {
|
||||||
|
String line = rawLine.trim();
|
||||||
|
if (line.isEmpty() || line.startsWith("#")) continue;
|
||||||
|
if (line.startsWith("export ")) line = line.substring("export ".length()).trim();
|
||||||
|
int equalsIndex = line.indexOf('=');
|
||||||
|
if (equalsIndex <= 0) continue;
|
||||||
|
|
||||||
|
String key = line.substring(0, equalsIndex).trim();
|
||||||
|
if (key.isEmpty() || !shouldImportDotEnvKey(key)) continue;
|
||||||
|
if (System.getProperty(key) != null || System.getenv(key) != null) continue;
|
||||||
|
|
||||||
|
String value = line.substring(equalsIndex + 1).trim();
|
||||||
|
if ((value.startsWith("\"") && value.endsWith("\"")) || (value.startsWith("'") && value.endsWith("'"))) {
|
||||||
|
value = value.substring(1, value.length() - 1);
|
||||||
|
}
|
||||||
|
System.setProperty(key, value);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("Warning: failed to load .env from " + envPath + " (" + e.getClass().getSimpleName() + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// 代码生成器
|
// 代码生成器
|
||||||
AutoGenerator mpg = new AutoGenerator();
|
AutoGenerator mpg = new AutoGenerator();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
|||||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||||
import com.gxwebsoft.generator.engine.BeetlTemplateEnginePlus;
|
import com.gxwebsoft.generator.engine.BeetlTemplateEnginePlus;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -40,11 +41,24 @@ public class CreditGenerator {
|
|||||||
private static final String AUTHOR = "科技小王子";
|
private static final String AUTHOR = "科技小王子";
|
||||||
// 是否在xml中添加二级缓存配置
|
// 是否在xml中添加二级缓存配置
|
||||||
private static final boolean ENABLE_CACHE = false;
|
private static final boolean ENABLE_CACHE = false;
|
||||||
|
|
||||||
|
static {
|
||||||
|
loadDotEnvIfPresent();
|
||||||
|
}
|
||||||
|
|
||||||
// 数据库连接配置
|
// 数据库连接配置
|
||||||
private static final String DB_URL = "jdbc:mysql://47.119.165.234:13308/modules?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8";
|
private static final String DB_URL = envOrProperty(
|
||||||
private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
|
"CODEGEN_DB_URL",
|
||||||
private static final String DB_USERNAME = "modules";
|
"SPRING_DATASOURCE_URL",
|
||||||
private static final String DB_PASSWORD = "P7KsAyDXG8YdLnkA";
|
"jdbc:mysql://localhost:3306/modules?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8"
|
||||||
|
);
|
||||||
|
private static final String DB_DRIVER = envOrProperty(
|
||||||
|
"CODEGEN_DB_DRIVER",
|
||||||
|
"SPRING_DATASOURCE_DRIVER_CLASS_NAME",
|
||||||
|
"com.mysql.cj.jdbc.Driver"
|
||||||
|
);
|
||||||
|
private static final String DB_USERNAME = envOrProperty("CODEGEN_DB_USERNAME", "SPRING_DATASOURCE_USERNAME", "modules");
|
||||||
|
private static final String DB_PASSWORD = envOrProperty("CODEGEN_DB_PASSWORD", "SPRING_DATASOURCE_PASSWORD", "");
|
||||||
// 包名
|
// 包名
|
||||||
private static final String PACKAGE_NAME = "com.gxwebsoft";
|
private static final String PACKAGE_NAME = "com.gxwebsoft";
|
||||||
// 模块名
|
// 模块名
|
||||||
@@ -71,13 +85,13 @@ public class CreditGenerator {
|
|||||||
// "credit_risk_relation",
|
// "credit_risk_relation",
|
||||||
// "credit_supplier",
|
// "credit_supplier",
|
||||||
// "credit_xgxf",
|
// "credit_xgxf",
|
||||||
"credit_administrative_license",
|
// "credit_administrative_license",
|
||||||
"credit_bankruptcy",
|
// "credit_bankruptcy",
|
||||||
"credit_branch",
|
// "credit_branch",
|
||||||
"credit_historical_legal_person",
|
// "credit_historical_legal_person",
|
||||||
"credit_nearby_company",
|
// "credit_nearby_company",
|
||||||
"credit_patent",
|
"credit_patent",
|
||||||
"credit_suspected_relationship"
|
// "credit_suspected_relationship"
|
||||||
};
|
};
|
||||||
// 需要去除的表前缀
|
// 需要去除的表前缀
|
||||||
private static final String[] TABLE_PREFIX = new String[]{
|
private static final String[] TABLE_PREFIX = new String[]{
|
||||||
@@ -111,6 +125,52 @@ public class CreditGenerator {
|
|||||||
// 模板所在位置
|
// 模板所在位置
|
||||||
private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generator/templates";
|
private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generator/templates";
|
||||||
|
|
||||||
|
private static String envOrProperty(String primaryKey, String fallbackKey, String defaultValue) {
|
||||||
|
String value = envOrProperty(primaryKey, "");
|
||||||
|
if (value.isBlank() && fallbackKey != null && !fallbackKey.isBlank()) {
|
||||||
|
value = envOrProperty(fallbackKey, "");
|
||||||
|
}
|
||||||
|
return value.isBlank() ? defaultValue : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String envOrProperty(String key, String defaultValue) {
|
||||||
|
String value = System.getProperty(key);
|
||||||
|
if (value == null || value.isBlank()) value = System.getenv(key);
|
||||||
|
if (value == null || value.isBlank()) return defaultValue;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean shouldImportDotEnvKey(String key) {
|
||||||
|
return key.startsWith("CODEGEN_") || key.startsWith("SPRING_DATASOURCE_");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadDotEnvIfPresent() {
|
||||||
|
var envPath = Paths.get(OUTPUT_LOCATION, ".env");
|
||||||
|
if (!Files.isRegularFile(envPath)) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (String rawLine : Files.readAllLines(envPath, StandardCharsets.UTF_8)) {
|
||||||
|
String line = rawLine.trim();
|
||||||
|
if (line.isEmpty() || line.startsWith("#")) continue;
|
||||||
|
if (line.startsWith("export ")) line = line.substring("export ".length()).trim();
|
||||||
|
int equalsIndex = line.indexOf('=');
|
||||||
|
if (equalsIndex <= 0) continue;
|
||||||
|
|
||||||
|
String key = line.substring(0, equalsIndex).trim();
|
||||||
|
if (key.isEmpty() || !shouldImportDotEnvKey(key)) continue;
|
||||||
|
if (System.getProperty(key) != null || System.getenv(key) != null) continue;
|
||||||
|
|
||||||
|
String value = line.substring(equalsIndex + 1).trim();
|
||||||
|
if ((value.startsWith("\"") && value.endsWith("\"")) || (value.startsWith("'") && value.endsWith("'"))) {
|
||||||
|
value = value.substring(1, value.length() - 1);
|
||||||
|
}
|
||||||
|
System.setProperty(key, value);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("Warning: failed to load .env from " + envPath + " (" + e.getClass().getSimpleName() + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// 代码生成器
|
// 代码生成器
|
||||||
AutoGenerator mpg = new AutoGenerator();
|
AutoGenerator mpg = new AutoGenerator();
|
||||||
|
|||||||
Reference in New Issue
Block a user