Compare commits
2 Commits
2814a4e655
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 5c15453c97 | |||
| f1ba2cbecc |
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
|
||||||
|
|||||||
110
README.md
110
README.md
@@ -87,17 +87,28 @@ CREATE DATABASE websoft_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|||||||
```
|
```
|
||||||
|
|
||||||
### 3. 配置文件
|
### 3. 配置文件
|
||||||
编辑 `src/main/resources/application-dev.yml` 文件,配置数据库连接:
|
本项目的 `application-*.yml` 已使用环境变量占位符,避免将真实密码提交到 Git。
|
||||||
```yaml
|
|
||||||
spring:
|
推荐使用 `.env` 管理本地开发环境变量:
|
||||||
datasource:
|
- 复制模板:`cp .env.example .env`
|
||||||
url: jdbc:mysql://localhost:3306/websoft_db?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
|
- 在 `.env` 中填好值后,启动前加载(zsh/bash):
|
||||||
username: your_username
|
- `set -a; source .env; set +a`
|
||||||
password: your_password
|
|
||||||
redis:
|
开发环境可通过环境变量配置数据库/Redis 连接(示例):
|
||||||
host: localhost
|
```bash
|
||||||
port: 6379
|
export SPRING_DATASOURCE_URL='jdbc:mysql://localhost:3306/websoft_db?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8'
|
||||||
password: your_redis_password
|
export SPRING_DATASOURCE_USERNAME='your_username'
|
||||||
|
export SPRING_DATASOURCE_PASSWORD='your_password'
|
||||||
|
export SPRING_REDIS_HOST='localhost'
|
||||||
|
export SPRING_REDIS_PORT='6379'
|
||||||
|
export SPRING_REDIS_PASSWORD='your_redis_password'
|
||||||
|
```
|
||||||
|
|
||||||
|
代码生成器(`src/test/java/com/gxwebsoft/generator/*Generator.java`)使用(支持从项目根目录自动读取 `.env`;也可直接导出环境变量):
|
||||||
|
```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. 启动项目
|
||||||
@@ -118,40 +129,36 @@ mvn spring-boot:run
|
|||||||
## ⚙️ 配置说明
|
## ⚙️ 配置说明
|
||||||
|
|
||||||
### 数据库配置
|
### 数据库配置
|
||||||
在 `application-dev.yml` 中配置数据库连接:
|
`application-dev.yml` / `application-prod.yml` 里使用占位符读取以下环境变量:
|
||||||
```yaml
|
- `SPRING_DATASOURCE_URL`
|
||||||
spring:
|
- `SPRING_DATASOURCE_USERNAME`
|
||||||
datasource:
|
- `SPRING_DATASOURCE_PASSWORD`
|
||||||
url: jdbc:mysql://localhost:3306/websoft_db
|
|
||||||
username: root
|
|
||||||
password: your_password
|
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
||||||
```
|
|
||||||
|
|
||||||
### Redis配置
|
### Redis配置
|
||||||
```yaml
|
环境变量:
|
||||||
spring:
|
- `SPRING_REDIS_HOST`
|
||||||
redis:
|
- `SPRING_REDIS_PORT`
|
||||||
host: localhost
|
- `SPRING_REDIS_PASSWORD`
|
||||||
port: 6379
|
|
||||||
password: your_redis_password
|
|
||||||
database: 0
|
|
||||||
```
|
|
||||||
|
|
||||||
### 阿里云OSS配置
|
### 阿里云OSS配置
|
||||||
```yaml
|
环境变量:
|
||||||
config:
|
- `ALIYUN_OSS_ENDPOINT`
|
||||||
endpoint: https://oss-cn-shenzhen.aliyuncs.com
|
- `ALIYUN_OSS_ACCESS_KEY_ID`
|
||||||
accessKeyId: your_access_key_id
|
- `ALIYUN_OSS_ACCESS_KEY_SECRET`
|
||||||
accessKeySecret: your_access_key_secret
|
- `ALIYUN_OSS_BUCKET_NAME`
|
||||||
bucketName: your_bucket_name
|
- `ALIYUN_OSS_BUCKET_DOMAIN`
|
||||||
bucketDomain: https://your-domain.com
|
- `ALIYUN_OSS_ALIYUN_DOMAIN`
|
||||||
```
|
|
||||||
|
|
||||||
### 其他配置
|
### 其他配置
|
||||||
- **JWT密钥**:`config.token-key` 用于JWT令牌加密
|
- **JWT密钥**:`JWT_SECRET`(`application-dev.yml`)
|
||||||
|
- **令牌加密Key**:`APP_TOKEN_KEY`(`application.yml` 的 `config.token-key`)
|
||||||
- **文件上传路径**:`config.upload-path` 本地文件存储路径
|
- **文件上传路径**:`config.upload-path` 本地文件存储路径
|
||||||
- **邮件服务**:配置SMTP服务器用于发送邮件
|
- **邮件服务**:配置SMTP服务器用于发送邮件
|
||||||
|
- **微信支付**:`WECHATPAY_API_V3_KEY`
|
||||||
|
|
||||||
|
### 开源注意事项
|
||||||
|
- 不要把数据库/Redis/MQTT/云服务密钥等写入 `application-*.yml` 或代码里;用环境变量或部署平台的 Secret 管理。
|
||||||
|
- 如果历史上曾提交过真实密钥,需要在对应平台轮换/作废,并清理 Git 历史(否则旧提交仍可被检出)。
|
||||||
|
|
||||||
## 🎯 核心功能
|
## 🎯 核心功能
|
||||||
|
|
||||||
@@ -245,7 +252,7 @@ src/main/java/com/gxwebsoft/
|
|||||||
```bash
|
```bash
|
||||||
# 1. 启动MySQL和Redis服务
|
# 1. 启动MySQL和Redis服务
|
||||||
# 2. 创建数据库并导入初始数据
|
# 2. 创建数据库并导入初始数据
|
||||||
# 3. 修改配置文件
|
# 3. 配置环境变量(推荐:cp .env.example .env,然后 set -a; source .env; set +a)
|
||||||
# 4. 启动应用
|
# 4. 启动应用
|
||||||
mvn spring-boot:run
|
mvn spring-boot:run
|
||||||
```
|
```
|
||||||
@@ -255,12 +262,29 @@ mvn spring-boot:run
|
|||||||
# 1. 打包应用
|
# 1. 打包应用
|
||||||
mvn clean package -Dmaven.test.skip=true
|
mvn clean package -Dmaven.test.skip=true
|
||||||
|
|
||||||
# 2. 运行jar包
|
# 2. 配置生产环境变量(示例)
|
||||||
java -jar target/com-gxwebsoft-modules-1.5.0.jar --spring.profiles.active=prod
|
export SPRING_PROFILES_ACTIVE=prod
|
||||||
|
export SPRING_DATASOURCE_URL='jdbc:mysql://<host>:3306/<db>?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai'
|
||||||
|
export SPRING_DATASOURCE_USERNAME='<user>'
|
||||||
|
export SPRING_DATASOURCE_PASSWORD='<password>'
|
||||||
|
export SPRING_REDIS_HOST='<host>'
|
||||||
|
export SPRING_REDIS_PORT='6379'
|
||||||
|
export SPRING_REDIS_PASSWORD='<password>'
|
||||||
|
|
||||||
# 3. 使用Docker部署(可选)
|
# 3. 运行jar包
|
||||||
|
java -jar target/com-gxwebsoft-modules-1.5.0.jar
|
||||||
|
|
||||||
|
# 4. 使用Docker部署(可选)
|
||||||
docker build -t websoft-api .
|
docker build -t websoft-api .
|
||||||
docker run -d -p 9200:9200 websoft-api
|
docker run -d -p 9200:9200 \
|
||||||
|
-e SPRING_PROFILES_ACTIVE=prod \
|
||||||
|
-e SPRING_DATASOURCE_URL='jdbc:mysql://<host>:3306/<db>?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai' \
|
||||||
|
-e SPRING_DATASOURCE_USERNAME='<user>' \
|
||||||
|
-e SPRING_DATASOURCE_PASSWORD='<password>' \
|
||||||
|
-e SPRING_REDIS_HOST='<host>' \
|
||||||
|
-e SPRING_REDIS_PORT='6379' \
|
||||||
|
-e SPRING_REDIS_PASSWORD='<password>' \
|
||||||
|
websoft-api
|
||||||
```
|
```
|
||||||
|
|
||||||
## 🤝 贡献指南
|
## 🤝 贡献指南
|
||||||
@@ -278,7 +302,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