格式化文案

This commit is contained in:
2026-04-21 16:42:38 +08:00
parent b5119afb9f
commit 75dc1429cf

102
README.md
View File

@@ -7,7 +7,8 @@
- **项目名称**xtools-boot
- **项目版本**5.0.0
- **父POM**org.xujun:xtools-parent-boot:5.0.0
- **项目定位**低调大师工具箱SpringBoot工具模块适配JDK25。提供企业级应用开发所需的通用功能模块涵盖缓存、数据库、搜索、消息队列、任务调度、日志、存储、脱敏等核心能力以Spring Boot Starter形式封装支持按需引入。
- **项目定位**低调大师工具箱SpringBoot工具模块适配JDK25。提供企业级应用开发所需的通用功能模块涵盖缓存、数据库、搜索、消息队列、任务调度、日志、存储、脱敏等核心能力以Spring
Boot Starter形式封装支持按需引入。
### 1.2 技术特点
@@ -152,36 +153,25 @@ graph LR
Client[客户端请求] --> Web[xtools-boot-web]
Web --> Filter[请求过滤器]
Filter --> LogTrack[日志链路追踪]
LogTrack --> Log[xtools-boot-log]
Log --> LogBus[LogBus日志总线]
Web --> Controller[业务Controller]
Controller --> Cache[xtools-boot-cache]
Controller --> DB[xtools-boot-db]
Cache --> Redis[Redis]
DB --> MySQL[MySQL]
Controller --> MQ[xtools-boot-mq]
MQ --> RabbitMQ[RabbitMQ]
MQ --> Thread[xtools-boot-thread]
Thread --> VThread[虚拟线程]
Controller --> Task[xtools-boot-task]
Task --> TaskBus[TaskBus任务总线]
Job[xtools-boot-job] --> XXLJob[XXL-JOB]
Controller --> ES[xtools-boot-elasticsearch]
ES --> Elasticsearch[Elasticsearch]
Controller --> Storage[xtools-boot-storage]
Storage --> File[本地文件/S3]
Controller --> Mask[xtools-boot-mask]
Log --> Doc[xtools-boot-knife4j]
```
@@ -193,36 +183,27 @@ graph LR
graph TD
App[xtools-boot<br/>父模块] --> API[xtools-boot-api<br/>API定义模块]
App --> Core[xtools-boot-core<br/>核心工具模块]
App --> DB[xtools-boot-db<br/>数据库模块]
App --> Cache[xtools-boot-cache<br/>缓存模块]
App --> ES[xtools-boot-elasticsearch<br/>搜索引擎模块]
App --> MQ[xtools-boot-mq<br/>消息队列模块]
App --> Task[xtools-boot-task<br/>任务管理模块]
App --> Job[xtools-boot-job<br/>任务调度模块]
App --> Thread[xtools-boot-thread<br/>线程管理模块]
App --> Log[xtools-boot-log<br/>日志模块]
App --> Web[xtools-boot-web<br/>Web模块]
App --> Knife4j[xtools-boot-knife4j<br/>API文档模块]
App --> IP[xtools-boot-ip<br/>IP定位模块]
App --> Mask[xtools-boot-mask<br/>数据脱敏模块]
App --> Storage[xtools-boot-storage<br/>存储模块]
DB --> DBMybatis[xtools-boot-db-mybatis]
DB --> DBMP[xtools-boot-db-mybatis-plus]
Cache --> CacheRedis[xtools-boot-cache-redis]
MQ --> MQBase[xtools-boot-mq-base]
MQ --> MQRabbit[xtools-boot-mq-rabbit]
Job --> JobXXL[xtools-boot-job-xxl]
Web --> WebBase[xtools-boot-web-base]
Web --> WebFilter[xtools-boot-web-filter]
Storage --> StorageBase[xtools-boot-storage-base]
Storage --> StorageFile[xtools-boot-storage-file]
Storage --> StorageS3[xtools-boot-storage-s3]
@@ -278,7 +259,7 @@ flowchart TB
### 2.3 模块职责
| 模块 | 职责 | 核心类 |
|------|------|--------|
|-----------------------------|--------------------------------|-------------------------------------------|
| xtools-boot-api | API定义层提供基础实体、枚举、异常、日志链路等公共定义 | BaseEntity、BaseEnum、BizError、LogTrack |
| xtools-boot-core | 核心工具层提供Spring上下文、树形结构、枚举等通用工具 | SpringContextUtils、TreeUtils、EnumUtils |
| xtools-boot-db-mybatis | MyBatis集成提供数据库访问、监控、慢查询检测 | MyBatisConfig、MySqlMonitor |
@@ -334,42 +315,33 @@ graph LR
API --> WebCore[xtools-web]
Core[xtools-boot-core] --> API
Core --> Extend
DBMybatis[xtools-boot-db-mybatis] --> Core
DBMybatis --> Log[xtools-boot-log]
DBMybatis --> Thread[xtools-boot-thread]
DBMP[xtools-boot-db-mybatis-plus] --> Core
CacheRedis[xtools-boot-cache-redis] --> Core
ES[xtools-boot-elasticsearch] --> Extend
ES --> Core
ES --> Log
MQBase[xtools-boot-mq-base] --> Core
MQBase --> Log
MQBase --> Thread
MQRabbit[xtools-boot-mq-rabbit] --> Core
MQRabbit --> MQBase
Task[xtools-boot-task] --> Core
JobXXL[xtools-boot-job-xxl] --> Core
Log --> Core
Thread --> Core
IP[xtools-boot-ip] --> Extend
IP --> Core
Knife4j[xtools-boot-knife4j] --> Core
Mask[xtools-boot-mask] --> Core
StorageBase[xtools-boot-storage-base] --> Core
StorageFile[xtools-boot-storage-file] --> Core
StorageFile --> StorageBase
StorageS3[xtools-boot-storage-s3] --> Extend
StorageS3 --> Core
StorageS3 --> StorageBase
WebBase[xtools-boot-web-base] --> WebCore
WebBase --> Core
WebBase --> Log
@@ -393,6 +365,7 @@ flowchart TD
```
**自动配置设计**
- 每个模块通过 `META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports` 注册自动配置类
- 配置类通过 `@Import(XXXImportSelector.class)` 导入自定义选择器
- 选择器实现 `ImportBeanDefinitionRegistrar` 接口按包名扫描注册Bean
@@ -406,7 +379,6 @@ flowchart TD
A[BaseEnum接口] --> B[int code<br/>枚举编码]
A --> C[String desc<br/>枚举描述]
A --> D["BaseEnum[] all()<br/>获取所有枚举"]
B --> E[StatusEnum<br/>状态枚举]
B --> F[DeleteEnum<br/>删除枚举]
B --> G[ThreadType<br/>线程类型]
@@ -418,6 +390,7 @@ flowchart TD
```
**枚举规范**
- 所有业务枚举实现 `BaseEnum` 接口
- 提供 `code()``desc()` 方法
- 提供静态 `valueOf(int code)``valueOfDesc(String desc)` 方法
@@ -431,12 +404,10 @@ flowchart TD
A --> C[BizWarning<br/>业务警告]
A --> D[UnauthorizedError<br/>未授权异常]
A --> E[BizPublicKeyError<br/>公钥异常]
F[BootError<br/>错误码枚举] --> F1[code<br/>错误编码]
F --> F2[type<br/>错误类型]
F --> F3[module<br/>所属模块]
F --> F4[messageTemplate<br/>消息模板]
G[BootErrorModule<br/>错误模块枚举] --> G1[API<br/>API模块]
G --> G2[CORE<br/>核心模块]
G --> G3[LOG<br/>日志模块]
@@ -444,6 +415,7 @@ flowchart TD
```
**异常体系**
- `CommonException`基础异常来自xtools-core
- `BizError`:业务逻辑异常,使用错误码和消息模板
- `BizWarning`:业务警告异常
@@ -466,7 +438,6 @@ flowchart TD
C --> C6[stackTrace<br/>堆栈信息]
C --> C7[logData<br/>日志数据]
C --> C8[err<br/>异常文本]
B --> D[LogBusInterface实现类<br/>日志处理器]
D --> E[写入Elasticsearch]
D --> F[写入数据库]
@@ -487,6 +458,7 @@ flowchart LR
```
**日志功能**
- **LogBus**:日志总线,统一的日志创建和管理入口
- **LogTrack**链路追踪信息包含traceId、spanId、线程类型等
- **HolderLogTrack**:线程持有者的链路追踪,支持主子线程传递
@@ -516,6 +488,7 @@ flowchart TD
```
**消息队列功能**
- **MqBus**:消息总线,统一的消息发布入口
- **BaseMqHandle**:消息处理基类,定义消息处理模板
- **BaseErrorHandle**:错误处理基类,定义错误处理策略
@@ -542,6 +515,7 @@ flowchart TD
```
**任务管理功能**
- **TaskBus**任务总线提供Builder模式创建和管理任务
- **TaskInfo**:任务信息,包含任务类型、任务数据、状态等
- **TaskStatus**任务状态枚举ING、SUCCESS、ERROR
@@ -562,6 +536,7 @@ flowchart TD
```
**任务调度功能**
- **BootXxlJobConfiguration**XXL-JOB自动配置
- **InitXxlJob**XXL-JOB初始化自动扫描和注册任务处理器
- **JobInterface**:任务执行接口,定义任务执行契约
@@ -574,16 +549,15 @@ flowchart TD
flowchart TD
A[BootThreadConfiguration<br/>线程配置] --> B[虚拟线程支持]
A --> C[VirtualThreadTaskCallback<br/>虚拟线程任务回调]
B --> D[MQ消息消费使用虚拟线程]
B --> E[异步任务使用虚拟线程]
C --> F[任务执行前回调]
C --> G[任务执行后回调]
C --> H[异常处理回调]
```
**线程管理功能**
- **BootThreadConfiguration**线程配置注册虚拟线程相关Bean
- **VirtualThreadTaskCallback**:虚拟线程任务回调接口,提供执行前、执行后、异常处理回调
- 支持在消息消费和异步任务中使用虚拟线程
@@ -603,6 +577,7 @@ flowchart LR
```
**缓存功能**
- **BootCacheRedisConfiguration**Redis自动配置
- **RedisUtils**Redis工具类封装常用Redis操作
- **RedisMonitor**Redis监控提供缓存统计和健康检查
@@ -631,6 +606,7 @@ flowchart TD
```
**数据库功能**
- **MyBatisConfig**MyBatis核心配置
- **MybatisPlusConfig**MyBatis-Plus配置注册分页插件
- **QueryUtils**:查询工具类,提供时间范围过滤等通用查询方法
@@ -645,15 +621,12 @@ flowchart TD
flowchart TD
A[业务代码] --> B[EsUtils<br/>ES HTTP工具]
A --> C[EsQueryUtils<br/>ES查询工具]
B --> D[索引操作]
B --> E[文档操作]
B --> F[集群操作]
C --> G[构建查询]
C --> H[聚合查询]
C --> I[分页查询]
J[ElasticsearchMonitor<br/>ES监控] --> K[集群健康]
J --> L[索引状态]
J --> M[节点信息]
@@ -661,6 +634,7 @@ flowchart TD
```
**搜索引擎功能**
- **BootElasticsearchConfiguration**ES自动配置
- **EsUtils**Elasticsearch HTTP客户端工具提供索引、文档、集群操作
- **EsQueryUtils**ES查询工具提供通用查询构建
@@ -680,7 +654,6 @@ flowchart TD
B --> B6[PASSWORD<br/>密码]
B --> B7[ADDRESS<br/>地址]
B --> B8[CUSTOM<br/>自定义]
A --> C["配置参数<br/>prefixNoMaskLen<br/>suffixNoMaskLen<br/>maskChar"]
C --> D[DefaultMaskHandle<br/>默认脱敏处理]
D --> E[MaskCustom<br/>自定义脱敏接口]
@@ -688,6 +661,7 @@ flowchart TD
```
**数据脱敏功能**
- **BootMaskConfiguration**:脱敏模块自动配置
- **MaskType**脱敏类型枚举支持8种内置类型
- **DefaultMaskHandle**:默认脱敏处理器,根据类型自动脱敏
@@ -703,13 +677,10 @@ flowchart TD
A --> A2[save<br/>保存文件]
A --> A3[get<br/>获取文件]
A --> A4[del<br/>删除文件]
B[StorageServiceFileImpl<br/>文件存储实现] --> C[本地文件系统]
D[BootStorageS3Configuration<br/>S3存储配置] --> E[AWS S3]
F["@ConditionalOnProperty<br/>storage.type=file"] --> B
G["@ConditionalOnProperty<br/>storage.type=s3"] --> D
A2 --> A2a[bucket<br/>桶名称]
A2 --> A2b[fileName<br/>文件名]
A2 --> A2c[inputStream<br/>输入流]
@@ -717,6 +688,7 @@ flowchart TD
```
**存储功能**
- **StorageService**统一存储接口定义exists、save、get、del操作
- **BootStorageBaseConfiguration**:存储基础配置
- **StorageServiceFileImpl**:本地文件系统存储实现
@@ -730,15 +702,12 @@ flowchart TD
flowchart TD
A[xtools-boot-web] --> B[xtools-boot-web-base]
A --> C[xtools-boot-web-filter]
B --> B1[BootWebBaseConfiguration<br/>Web基础配置]
B --> B2[CommonFilter<br/>通用过滤器]
B --> B3[MvcConverterConfig<br/>MVC转换器配置]
B --> B4[LogTrackConfig<br/>日志链路配置]
C --> C1[BootWebFilterConfiguration<br/>过滤器配置]
C --> C2[BootWebFilterImportSelector<br/>过滤器导入选择器]
B4 --> D[生成LogTrack]
D --> E[绑定到ThreadLocal]
E --> F[请求处理]
@@ -746,6 +715,7 @@ flowchart TD
```
**Web模块功能**
- **BootWebBaseConfiguration**Web基础配置集成xtools-web
- **CommonFilter**:通用请求过滤器,处理请求上下文
- **MvcConverterConfig**MVC转换器配置
@@ -774,7 +744,7 @@ flowchart TD
**类命名**
| 类型 | 命名规则 | 示例 |
|------|----------|------|
|-------|-------------------------------------|---------------------------------------|
| 配置类 | Boot{Module}Configuration | BootCoreConfiguration |
| 导入选择器 | Boot{Module}ImportSelector | BootCoreImportSelector |
| 工具类 | {功能}Utils | SpringContextUtils |
@@ -790,7 +760,7 @@ flowchart TD
**方法命名**
| 操作 | 命名规则 | 示例 |
|------|----------|------|
|-----|-------------------------|----------------------------|
| 查询 | get / find / query | getBean、findById、queryList |
| 创建 | create / save / publish | createLog、save、publish |
| 删除 | delete / del / remove | deleteById、del |
@@ -803,7 +773,7 @@ flowchart TD
**变量命名**
| 类型 | 命名规则 | 示例 |
|------|----------|------|
|---------|------------------|--------------------------|
| 普通变量 | camelCase | logTrack、taskInfo |
| 常量 | UPPER_SNAKE_CASE | CP_NUM0、CP_NUM50 |
| Boolean | is/has前缀 | isValid、hasChildren |
@@ -881,7 +851,7 @@ private String fieldName;
### 5.1 核心框架依赖
| 依赖 | 版本 | 用途 |
|------|------|------|
|---------------------------|----------|-----------------|
| Spring Boot | 4.0.5 | 应用框架 |
| Spring Framework | 7.0.6 | 核心框架 |
| Spring Security | 7.0.4 | 安全框架 |
@@ -895,7 +865,7 @@ private String fieldName;
### 5.2 数据库相关依赖
| 依赖 | 版本 | 用途 |
|------|------|------|
|-----------------------------|--------|-----------|
| MyBatis Spring Boot Starter | 4.0.1 | MyBatis集成 |
| MyBatis-Plus | 3.5.16 | ORM增强工具 |
| Druid | 1.2.28 | 数据库连接池 |
@@ -903,26 +873,26 @@ private String fieldName;
### 5.3 搜索引擎依赖
| 依赖 | 版本 | 用途 |
|------|------|------|
|----------------------|-------|------------|
| Elasticsearch Client | 9.2.6 | ES Java客户端 |
### 5.4 消息队列依赖
| 依赖 | 版本 | 用途 |
|------|------|------|
|----------------------|--------|------------------|
| RabbitMQ AMQP Client | 5.27.1 | RabbitMQ Java客户端 |
### 5.5 缓存依赖
| 依赖 | 版本 | 用途 |
|------|------|------|
|----------|---------------|----------|
| Lettuce | 6.8.2.RELEASE | Redis客户端 |
| Caffeine | 3.2.3 | 本地缓存 |
### 5.6 工具库依赖
| 依赖 | 版本 | 用途 |
|------|------|------|
|----------------|----------|--------|
| Lombok | 1.18.44 | 代码简化 |
| MapStruct | 1.6.3 | 对象映射 |
| FastJSON2 | 2.0.60 | JSON处理 |
@@ -936,7 +906,7 @@ private String fieldName;
### 5.7 安全相关依赖
| 依赖 | 版本 | 用途 |
|------|------|------|
|--------------|-------|-------|
| BouncyCastle | 1.84 | 加密库 |
| Easy Captcha | 1.6.2 | 验证码 |
| java-jwt | 4.5.1 | JWT令牌 |
@@ -944,7 +914,7 @@ private String fieldName;
### 5.8 文档相关依赖
| 依赖 | 版本 | 用途 |
|------|------|------|
|---------------------|--------|-------------|
| Knife4j OpenAPI3 | 4.5.0 | API文档增强 |
| Springdoc OpenAPI | 3.0.3 | OpenAPI 3集成 |
| Swagger Annotations | 2.2.48 | API文档注解 |
@@ -952,33 +922,33 @@ private String fieldName;
### 5.9 任务调度依赖
| 依赖 | 版本 | 用途 |
|------|------|------|
|--------------|-------|---------|
| XXL-JOB Core | 3.4.0 | 分布式任务调度 |
### 5.10 系统监控依赖
| 依赖 | 版本 | 用途 |
|------|------|------|
|-----------|--------|--------|
| OSHI Core | 6.11.1 | 系统监控 |
| ip2region | 3.3.7 | IP地址定位 |
### 5.11 存储依赖
| 依赖 | 版本 | 用途 |
|------|------|------|
|------------|---------|--------|
| AWS S3 SDK | 2.42.34 | S3对象存储 |
### 5.12 办公工具依赖
| 依赖 | 版本 | 用途 |
|------|------|------|
|-------------|------------------|---------|
| Fesod Sheet | 2.0.1-incubating | Excel处理 |
| PDFBox | 3.0.7 | PDF处理 |
### 5.13 其他工具依赖
| 依赖 | 版本 | 用途 |
|------|------|------|
|---------------------|--------------|---------|
| UserAgentUtils | 1.21 | 浏览器标识解析 |
| Pinyin4j | 2.5.1 | 拼音转换 |
| Thumbnailator | 0.4.21 | 图片压缩 |
@@ -991,13 +961,13 @@ private String fieldName;
### 5.14 测试依赖
| 依赖 | 版本 | 用途 |
|------|------|------|
|---------------|-------|------|
| JUnit Jupiter | 6.0.3 | 单元测试 |
### 5.15 xtools内部框架依赖
| 模块 | 版本 | 用途 |
|------|------|------|
|---------------------|-------|----------|
| xtools-core | 5.0.0 | 核心工具库 |
| xtools-web | 5.0.0 | Web工具库 |
| xtools-extend | 5.0.0 | 扩展工具库 |
@@ -1088,7 +1058,7 @@ private String fieldName;
### 6.8 其他重要依赖版本
| 依赖 | 版本 | 用途 |
|------|------|------|
|--------------|---------|------------|
| FastJSON2 | 2.0.60 | 高性能JSON序列化 |
| Lombok | 1.18.44 | 代码简化 |
| MapStruct | 1.6.3 | 编译期对象映射 |