You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
456 lines
24 KiB
456 lines
24 KiB
|
1 month ago
|
# 项目概览
|
||
|
|
|
||
|
|
<cite>
|
||
|
|
**本文引用的文件**
|
||
|
|
- [pom.xml](file://pom.xml)
|
||
|
|
- [CrmAppApplication.java](file://crm-app/src/main/java/com/crm/app/CrmAppApplication.java)
|
||
|
|
- [application.yml](file://crm-app/src/main/resources/application.yml)
|
||
|
|
- [AuthApplication.java](file://crm-auth/src/main/java/com/crm/auth/AuthApplication.java)
|
||
|
|
- [application.yml](file://crm-auth/src/main/resources/application.yml)
|
||
|
|
- [SecurityConfig.java](file://crm-auth/src/main/java/com/crm/auth/config/SecurityConfig.java)
|
||
|
|
- [PermissionConfig.java](file://crm-auth/src/main/java/com/crm/auth/config/PermissionConfig.java)
|
||
|
|
- [DataInitializer.java](file://crm-auth/src/main/java/com/crm/auth/config/DataInitializer.java)
|
||
|
|
- [AuthController.java](file://crm-auth/src/main/java/com/crm/auth/controller/AuthController.java)
|
||
|
|
- [SystemController.java](file://crm-auth/src/main/java/com/crm/auth/controller/SystemController.java)
|
||
|
|
- [JwtAuthenticationFilter.java](file://crm-auth/src/main/java/com/crm/auth/security/JwtAuthenticationFilter.java)
|
||
|
|
- [TokenService.java](file://crm-auth/src/main/java/com/crm/auth/security/TokenService.java)
|
||
|
|
- [AuthService.java](file://crm-auth/src/main/java/com/crm/auth/service/IAuthService.java)
|
||
|
|
- [AuthUserServiceImpl.java](file://crm-auth/src/main/java/com/crm/auth/service/impl/AuthUserServiceImpl.java)
|
||
|
|
- [SysDeptServiceImpl.java](file://crm-auth/src/main/java/com/crm/auth/service/impl/SysDeptServiceImpl.java)
|
||
|
|
- [BaseEntity.java](file://crm-base/src/main/java/com/crm/base/domain/entity/BaseEntity.java)
|
||
|
|
- [OwnedEntity.java](file://crm-base/src/main/java/com/crm/base/domain/entity/OwnedEntity.java)
|
||
|
|
- [Result.java](file://crm-base/src/main/java/com/crm/base/domain/result/Result.java)
|
||
|
|
- [PageResult.java](file://crm-base/src/main/java/com/crm/base/domain/result/PageResult.java)
|
||
|
|
- [GlobalExceptionHandlerAdvice.java](file://crm-base/src/main/java/com/crm/base/advice/GlobalExceptionHandlerAdvice.java)
|
||
|
|
- [MybatisPlusConfig.java](file://crm-base/src/main/java/com/crm/base/config/MybatisPlusConfig.java)
|
||
|
|
- [RedisConfig.java](file://crm-base/src/main/java/com/crm/base/config/RedisConfig.java)
|
||
|
|
- [JacksonConfig.java](file://crm-base/src/main/java/com/crm/base/config/JacksonConfig.java)
|
||
|
|
- [SnowflakeIdWorker.java](file://crm-base/src/main/java/com/crm/base/config/SnowflakeIdWorker.java)
|
||
|
|
- [DataScope.java](file://crm-base/src/main/java/com/crm/base/annotation/DataScope.java)
|
||
|
|
- [DataScopeHelper.java](file://crm-base/src/main/java/com/crm/base/security/DataScopeHelper.java)
|
||
|
|
- [LoginUser.java](file://crm-base/src/main/java/com/crm/base/security/LoginUser.java)
|
||
|
|
- [FileApi.java](file://crm-file/src/main/java/com/crm/file/api/FileApi.java)
|
||
|
|
- [FileController.java](file://crm-file/src/main/java/com/crm/file/controller/FileController.java)
|
||
|
|
- [MinioConfig.java](file://crm-file/src/main/java/com/crm/file/config/MinioConfig.java)
|
||
|
|
- [FileProperties.java](file://crm-file/src/main/java/com/crm/file/config/FileProperties.java)
|
||
|
|
- [FileInfoServiceImpl.java](file://crm-file/src/main/java/com/crm/file/service/impl/FileInfoServiceImpl.java)
|
||
|
|
- [FileApiImpl.java](file://crm-file/src/main/java/com/crm/file/service/impl/FileApiImpl.java)
|
||
|
|
- [KkFileViewClient.java](file://crm-file/src/main/java/com/crm/file/service/KkFileViewClient.java)
|
||
|
|
- [OrphanChunkCleanupTask.java](file://crm-file/src/main/java/com/crm/file/task/OrphanChunkCleanupTask.java)
|
||
|
|
</cite>
|
||
|
|
|
||
|
|
## 目录
|
||
|
|
1. [简介](#简介)
|
||
|
|
2. [项目结构](#项目结构)
|
||
|
|
3. [核心组件](#核心组件)
|
||
|
|
4. [架构总览](#架构总览)
|
||
|
|
5. [详细组件分析](#详细组件分析)
|
||
|
|
6. [依赖关系分析](#依赖关系分析)
|
||
|
|
7. [性能考虑](#性能考虑)
|
||
|
|
8. [故障排查指南](#故障排查指南)
|
||
|
|
9. [结论](#结论)
|
||
|
|
10. [附录](#附录)
|
||
|
|
|
||
|
|
## 简介
|
||
|
|
本文件为 CRM 后端项目的全面概览文档,面向初学者与有经验的开发者。内容涵盖整体架构、技术栈选择、模块划分与职责、微服务设计(认证服务 crm-auth、基础框架 crm-base、文件服务 crm-file)、启动方式、配置管理与部署建议。通过循序渐进的说明与图示,帮助读者快速建立对项目的整体认知,并深入理解关键实现细节。
|
||
|
|
|
||
|
|
## 项目结构
|
||
|
|
本项目采用多模块 Maven 工程组织,按领域与服务边界拆分:
|
||
|
|
- crm-app:应用入口与聚合层,负责统一装配与对外暴露能力。
|
||
|
|
- crm-auth:认证与权限服务,提供登录鉴权、用户/角色/菜单/部门管理、数据权限等。
|
||
|
|
- crm-base:公共基础库,封装通用实体、结果封装、异常处理、安全上下文、分页、序列化、数据库与缓存配置、分布式ID生成等。
|
||
|
|
- crm-file:文件服务,提供分片上传、断点续传、在线预览、清理任务等功能,底层对接 MinIO 对象存储。
|
||
|
|
|
||
|
|
```mermaid
|
||
|
|
graph TB
|
||
|
|
subgraph "应用层"
|
||
|
|
APP["crm-app<br/>应用入口"]
|
||
|
|
end
|
||
|
|
subgraph "业务服务"
|
||
|
|
AUTH["crm-auth<br/>认证与权限服务"]
|
||
|
|
FILE["crm-file<br/>文件服务"]
|
||
|
|
end
|
||
|
|
subgraph "基础库"
|
||
|
|
BASE["crm-base<br/>通用能力"]
|
||
|
|
end
|
||
|
|
APP --> AUTH
|
||
|
|
APP --> FILE
|
||
|
|
AUTH --> BASE
|
||
|
|
FILE --> BASE
|
||
|
|
```
|
||
|
|
|
||
|
|
图表来源
|
||
|
|
- [CrmAppApplication.java](file://crm-app/src/main/java/com/crm/app/CrmAppApplication.java)
|
||
|
|
- [AuthApplication.java](file://crm-auth/src/main/java/com/crm/auth/AuthApplication.java)
|
||
|
|
|
||
|
|
章节来源
|
||
|
|
- [pom.xml](file://pom.xml)
|
||
|
|
- [CrmAppApplication.java](file://crm-app/src/main/java/com/crm/app/CrmAppApplication.java)
|
||
|
|
- [AuthApplication.java](file://crm-auth/src/main/java/com/crm/auth/AuthApplication.java)
|
||
|
|
|
||
|
|
## 核心组件
|
||
|
|
- 应用入口与装配
|
||
|
|
- 应用主类负责 Spring Boot 启动与模块扫描,配置文件位于 resources/application.yml。
|
||
|
|
- 认证与权限(crm-auth)
|
||
|
|
- 控制器:登录、系统信息接口。
|
||
|
|
- 安全:JWT 过滤器、令牌服务、权限配置、数据范围拦截器。
|
||
|
|
- 服务:用户、角色、菜单、部门、身份等核心业务能力。
|
||
|
|
- 配置:安全策略、权限规则、初始化数据。
|
||
|
|
- 基础框架(crm-base)
|
||
|
|
- 通用实体与 DTO、统一返回体、分页、枚举、异常体系。
|
||
|
|
- 安全上下文、数据权限注解与辅助工具。
|
||
|
|
- MyBatis-Plus、Redis、Jackson、雪花算法等基础设施配置。
|
||
|
|
- 文件服务(crm-file)
|
||
|
|
- 控制器与 API 抽象,文件上传下载、分片会话、在线预览客户端。
|
||
|
|
- MinIO 配置与属性、定时清理孤立分片任务。
|
||
|
|
|
||
|
|
章节来源
|
||
|
|
- [application.yml](file://crm-app/src/main/resources/application.yml)
|
||
|
|
- [AuthController.java](file://crm-auth/src/main/java/com/crm/auth/controller/AuthController.java)
|
||
|
|
- [SystemController.java](file://crm-auth/src/main/java/com/crm/auth/controller/SystemController.java)
|
||
|
|
- [SecurityConfig.java](file://crm-auth/src/main/java/com/crm/auth/config/SecurityConfig.java)
|
||
|
|
- [PermissionConfig.java](file://crm-auth/src/main/java/com/crm/auth/config/PermissionConfig.java)
|
||
|
|
- [JwtAuthenticationFilter.java](file://crm-auth/src/main/java/com/crm/auth/security/JwtAuthenticationFilter.java)
|
||
|
|
- [TokenService.java](file://crm-auth/src/main/java/com/crm/auth/security/TokenService.java)
|
||
|
|
- [IAuthService.java](file://crm-auth/src/main/java/com/crm/auth/service/IAuthService.java)
|
||
|
|
- [AuthUserServiceImpl.java](file://crm-auth/src/main/java/com/crm/auth/service/impl/AuthUserServiceImpl.java)
|
||
|
|
- [SysDeptServiceImpl.java](file://crm-auth/src/main/java/com/crm/auth/service/impl/SysDeptServiceImpl.java)
|
||
|
|
- [BaseEntity.java](file://crm-base/src/main/java/com/crm/base/domain/entity/BaseEntity.java)
|
||
|
|
- [OwnedEntity.java](file://crm-base/src/main/java/com/crm/base/domain/entity/OwnedEntity.java)
|
||
|
|
- [Result.java](file://crm-base/src/main/java/com/crm/base/domain/result/Result.java)
|
||
|
|
- [PageResult.java](file://crm-base/src/main/java/com/crm/base/domain/result/PageResult.java)
|
||
|
|
- [GlobalExceptionHandlerAdvice.java](file://crm-base/src/main/java/com/crm/base/advice/GlobalExceptionHandlerAdvice.java)
|
||
|
|
- [MybatisPlusConfig.java](file://crm-base/src/main/java/com/crm/base/config/MybatisPlusConfig.java)
|
||
|
|
- [RedisConfig.java](file://crm-base/src/main/java/com/crm/base/config/RedisConfig.java)
|
||
|
|
- [JacksonConfig.java](file://crm-base/src/main/java/com/crm/base/config/JacksonConfig.java)
|
||
|
|
- [SnowflakeIdWorker.java](file://crm-base/src/main/java/com/crm/base/config/SnowflakeIdWorker.java)
|
||
|
|
- [DataScope.java](file://crm-base/src/main/java/com/crm/base/annotation/DataScope.java)
|
||
|
|
- [DataScopeHelper.java](file://crm-base/src/main/java/com/crm/base/security/DataScopeHelper.java)
|
||
|
|
- [LoginUser.java](file://crm-base/src/main/java/com/crm/base/security/LoginUser.java)
|
||
|
|
- [FileApi.java](file://crm-file/src/main/java/com/crm/file/api/FileApi.java)
|
||
|
|
- [FileController.java](file://crm-file/src/main/java/com/crm/file/controller/FileController.java)
|
||
|
|
- [MinioConfig.java](file://crm-file/src/main/java/com/crm/file/config/MinioConfig.java)
|
||
|
|
- [FileProperties.java](file://crm-file/src/main/java/com/crm/file/config/FileProperties.java)
|
||
|
|
- [FileInfoServiceImpl.java](file://crm-file/src/main/java/com/crm/file/service/impl/FileInfoServiceImpl.java)
|
||
|
|
- [FileApiImpl.java](file://crm-file/src/main/java/com/crm/file/service/impl/FileApiImpl.java)
|
||
|
|
- [KkFileViewClient.java](file://crm-file/src/main/java/com/crm/file/service/KkFileViewClient.java)
|
||
|
|
- [OrphanChunkCleanupTask.java](file://crm-file/src/main/java/com/crm/file/task/OrphanChunkCleanupTask.java)
|
||
|
|
|
||
|
|
## 架构总览
|
||
|
|
CRM 后端采用“应用聚合 + 领域服务 + 基础库”的分层与模块化架构。crm-app 作为聚合入口,按需引入 crm-auth 与 crm-file;两者均依赖 crm-base 提供的通用能力。认证服务内置 JWT 鉴权与 RBAC 权限模型,支持数据范围控制;文件服务基于 MinIO 提供对象存储能力,并通过第三方预览服务完成在线预览。
|
||
|
|
|
||
|
|
```mermaid
|
||
|
|
graph TB
|
||
|
|
Client["客户端"] --> App["crm-app<br/>应用入口"]
|
||
|
|
App --> Auth["crm-auth<br/>认证与权限服务"]
|
||
|
|
App --> File["crm-file<br/>文件服务"]
|
||
|
|
Auth --> Base["crm-base<br/>基础框架"]
|
||
|
|
File --> Base
|
||
|
|
Auth --> DB["数据库"]
|
||
|
|
File --> MinIO["MinIO 对象存储"]
|
||
|
|
File --> Preview["在线预览服务"]
|
||
|
|
```
|
||
|
|
|
||
|
|
图表来源
|
||
|
|
- [CrmAppApplication.java](file://crm-app/src/main/java/com/crm/app/CrmAppApplication.java)
|
||
|
|
- [AuthApplication.java](file://crm-auth/src/main/java/com/crm/auth/AuthApplication.java)
|
||
|
|
- [SecurityConfig.java](file://crm-auth/src/main/java/com/crm/auth/config/SecurityConfig.java)
|
||
|
|
- [MinioConfig.java](file://crm-file/src/main/java/com/crm/file/config/MinioConfig.java)
|
||
|
|
|
||
|
|
## 详细组件分析
|
||
|
|
|
||
|
|
### 认证服务(crm-auth)
|
||
|
|
- 职责
|
||
|
|
- 用户登录与令牌签发校验
|
||
|
|
- 角色、菜单、部门与用户关系管理
|
||
|
|
- 数据权限(数据范围)控制
|
||
|
|
- 第三方登录扩展(如钉钉)
|
||
|
|
- 关键流程(登录与鉴权)
|
||
|
|
```mermaid
|
||
|
|
sequenceDiagram
|
||
|
|
participant C as "客户端"
|
||
|
|
participant AC as "AuthController"
|
||
|
|
participant TS as "TokenService"
|
||
|
|
participant S as "AuthService"
|
||
|
|
participant U as "AuthUserService"
|
||
|
|
participant F as "JwtAuthenticationFilter"
|
||
|
|
participant R as "Redis"
|
||
|
|
C->>AC : "POST /auth/login"
|
||
|
|
AC->>S : "登录请求"
|
||
|
|
S->>U : "查询用户与权限"
|
||
|
|
U-->>S : "用户信息与角色菜单"
|
||
|
|
S-->>AC : "认证结果"
|
||
|
|
AC->>TS : "签发JWT"
|
||
|
|
TS->>R : "写入会话/黑名单"
|
||
|
|
TS-->>AC : "令牌"
|
||
|
|
AC-->>C : "返回令牌"
|
||
|
|
C->>F : "携带令牌访问受保护接口"
|
||
|
|
F->>TS : "解析与校验令牌"
|
||
|
|
TS-->>F : "校验结果"
|
||
|
|
F-->>C : "放行或拒绝"
|
||
|
|
```
|
||
|
|
|
||
|
|
图表来源
|
||
|
|
- [AuthController.java](file://crm-auth/src/main/java/com/crm/auth/controller/AuthController.java)
|
||
|
|
- [TokenService.java](file://crm-auth/src/main/java/com/crm/auth/security/TokenService.java)
|
||
|
|
- [IAuthService.java](file://crm-auth/src/main/java/com/crm/auth/service/IAuthService.java)
|
||
|
|
- [AuthUserServiceImpl.java](file://crm-auth/src/main/java/com/crm/auth/service/impl/AuthUserServiceImpl.java)
|
||
|
|
- [JwtAuthenticationFilter.java](file://crm-auth/src/main/java/com/crm/auth/security/JwtAuthenticationFilter.java)
|
||
|
|
|
||
|
|
- 权限与数据范围
|
||
|
|
- 使用注解与拦截器实现方法级权限控制与数据范围过滤。
|
||
|
|
- 数据范围由 crm-base 的 DataScope 注解与 DataScopeHelper 共同驱动。
|
||
|
|
|
||
|
|
```mermaid
|
||
|
|
flowchart TD
|
||
|
|
Start(["进入受保护方法"]) --> CheckAnno["检查 @DataScope 注解"]
|
||
|
|
CheckAnno --> HasScope{"存在数据范围?"}
|
||
|
|
HasScope --> |否| Proceed["直接执行业务逻辑"]
|
||
|
|
HasScope --> |是| BuildSQL["构建数据范围 SQL"]
|
||
|
|
BuildSQL --> Apply["应用到查询条件"]
|
||
|
|
Apply --> Proceed
|
||
|
|
Proceed --> End(["返回结果"])
|
||
|
|
```
|
||
|
|
|
||
|
|
图表来源
|
||
|
|
- [DataScope.java](file://crm-base/src/main/java/com/crm/base/annotation/DataScope.java)
|
||
|
|
- [DataScopeHelper.java](file://crm-base/src/main/java/com/crm/base/security/DataScopeHelper.java)
|
||
|
|
|
||
|
|
章节来源
|
||
|
|
- [AuthController.java](file://crm-auth/src/main/java/com/crm/auth/controller/AuthController.java)
|
||
|
|
- [SystemController.java](file://crm-auth/src/main/java/com/crm/auth/controller/SystemController.java)
|
||
|
|
- [SecurityConfig.java](file://crm-auth/src/main/java/com/crm/auth/config/SecurityConfig.java)
|
||
|
|
- [PermissionConfig.java](file://crm-auth/src/main/java/com/crm/auth/config/PermissionConfig.java)
|
||
|
|
- [JwtAuthenticationFilter.java](file://crm-auth/src/main/java/com/crm/auth/security/JwtAuthenticationFilter.java)
|
||
|
|
- [TokenService.java](file://crm-auth/src/main/java/com/crm/auth/security/TokenService.java)
|
||
|
|
- [IAuthService.java](file://crm-auth/src/main/java/com/crm/auth/service/IAuthService.java)
|
||
|
|
- [AuthUserServiceImpl.java](file://crm-auth/src/main/java/com/crm/auth/service/impl/AuthUserServiceImpl.java)
|
||
|
|
- [SysDeptServiceImpl.java](file://crm-auth/src/main/java/com/crm/auth/service/impl/SysDeptServiceImpl.java)
|
||
|
|
- [DataScope.java](file://crm-base/src/main/java/com/crm/base/annotation/DataScope.java)
|
||
|
|
- [DataScopeHelper.java](file://crm-base/src/main/java/com/crm/base/security/DataScopeHelper.java)
|
||
|
|
|
||
|
|
### 基础框架(crm-base)
|
||
|
|
- 职责
|
||
|
|
- 统一返回体 Result、分页 PageResult
|
||
|
|
- 全局异常处理 GlobalExceptionHandlerAdvice
|
||
|
|
- 通用实体 BaseEntity、OwnedEntity
|
||
|
|
- 安全上下文 LoginUser、数据权限工具
|
||
|
|
- MyBatis-Plus、Redis、Jackson、雪花ID等配置
|
||
|
|
- 关键类关系
|
||
|
|
```mermaid
|
||
|
|
classDiagram
|
||
|
|
class BaseEntity {
|
||
|
|
+id
|
||
|
|
+createTime
|
||
|
|
+updateTime
|
||
|
|
}
|
||
|
|
class OwnedEntity {
|
||
|
|
+ownerId
|
||
|
|
+tenantId
|
||
|
|
}
|
||
|
|
class Result {
|
||
|
|
+code
|
||
|
|
+message
|
||
|
|
+data
|
||
|
|
}
|
||
|
|
class PageResult {
|
||
|
|
+list
|
||
|
|
+total
|
||
|
|
+page
|
||
|
|
+size
|
||
|
|
}
|
||
|
|
class GlobalExceptionHandlerAdvice {
|
||
|
|
+handleException()
|
||
|
|
}
|
||
|
|
class LoginUser {
|
||
|
|
+userId
|
||
|
|
+roles
|
||
|
|
+permissions
|
||
|
|
}
|
||
|
|
class DataScopeHelper {
|
||
|
|
+buildScopeSql()
|
||
|
|
}
|
||
|
|
class SnowflakeIdWorker {
|
||
|
|
+nextId()
|
||
|
|
}
|
||
|
|
OwnedEntity --|> BaseEntity : "继承"
|
||
|
|
GlobalExceptionHandlerAdvice --> Result : "返回统一响应"
|
||
|
|
PageResult --> Result : "组合"
|
||
|
|
```
|
||
|
|
|
||
|
|
图表来源
|
||
|
|
- [BaseEntity.java](file://crm-base/src/main/java/com/crm/base/domain/entity/BaseEntity.java)
|
||
|
|
- [OwnedEntity.java](file://crm-base/src/main/java/com/crm/base/domain/entity/OwnedEntity.java)
|
||
|
|
- [Result.java](file://crm-base/src/main/java/com/crm/base/domain/result/Result.java)
|
||
|
|
- [PageResult.java](file://crm-base/src/main/java/com/crm/base/domain/result/PageResult.java)
|
||
|
|
- [GlobalExceptionHandlerAdvice.java](file://crm-base/src/main/java/com/crm/base/advice/GlobalExceptionHandlerAdvice.java)
|
||
|
|
- [LoginUser.java](file://crm-base/src/main/java/com/crm/base/security/LoginUser.java)
|
||
|
|
- [DataScopeHelper.java](file://crm-base/src/main/java/com/crm/base/security/DataScopeHelper.java)
|
||
|
|
- [SnowflakeIdWorker.java](file://crm-base/src/main/java/com/crm/base/config/SnowflakeIdWorker.java)
|
||
|
|
|
||
|
|
章节来源
|
||
|
|
- [BaseEntity.java](file://crm-base/src/main/java/com/crm/base/domain/entity/BaseEntity.java)
|
||
|
|
- [OwnedEntity.java](file://crm-base/src/main/java/com/crm/base/domain/entity/OwnedEntity.java)
|
||
|
|
- [Result.java](file://crm-base/src/main/java/com/crm/base/domain/result/Result.java)
|
||
|
|
- [PageResult.java](file://crm-base/src/main/java/com/crm/base/domain/result/PageResult.java)
|
||
|
|
- [GlobalExceptionHandlerAdvice.java](file://crm-base/src/main/java/com/crm/base/advice/GlobalExceptionHandlerAdvice.java)
|
||
|
|
- [MybatisPlusConfig.java](file://crm-base/src/main/java/com/crm/base/config/MybatisPlusConfig.java)
|
||
|
|
- [RedisConfig.java](file://crm-base/src/main/java/com/crm/base/config/RedisConfig.java)
|
||
|
|
- [JacksonConfig.java](file://crm-base/src/main/java/com/crm/base/config/JacksonConfig.java)
|
||
|
|
- [SnowflakeIdWorker.java](file://crm-base/src/main/java/com/crm/base/config/SnowflakeIdWorker.java)
|
||
|
|
- [DataScope.java](file://crm-base/src/main/java/com/crm/base/annotation/DataScope.java)
|
||
|
|
- [DataScopeHelper.java](file://crm-base/src/main/java/com/crm/base/security/DataScopeHelper.java)
|
||
|
|
- [LoginUser.java](file://crm-base/src/main/java/com/crm/base/security/LoginUser.java)
|
||
|
|
|
||
|
|
### 文件服务(crm-file)
|
||
|
|
- 职责
|
||
|
|
- 文件上传(支持分片与会话)、下载、元信息管理
|
||
|
|
- 在线预览(对接第三方预览服务)
|
||
|
|
- 对象存储(MinIO)配置与管理
|
||
|
|
- 定时清理孤立分片文件
|
||
|
|
- 典型流程(分片上传)
|
||
|
|
```mermaid
|
||
|
|
flowchart TD
|
||
|
|
A["客户端发起初始化"] --> B["创建上传会话"]
|
||
|
|
B --> C["分片上传片段"]
|
||
|
|
C --> D{"所有分片上传完成?"}
|
||
|
|
D --> |否| C
|
||
|
|
D --> |是| E["合并分片到对象存储"]
|
||
|
|
E --> F["记录文件元信息"]
|
||
|
|
F --> G["返回文件信息"]
|
||
|
|
```
|
||
|
|
|
||
|
|
图表来源
|
||
|
|
- [FileController.java](file://crm-file/src/main/java/com/crm/file/controller/FileController.java)
|
||
|
|
- [FileApiImpl.java](file://crm-file/src/main/java/com/crm/file/service/impl/FileApiImpl.java)
|
||
|
|
- [FileInfoServiceImpl.java](file://crm-file/src/main/java/com/crm/file/service/impl/FileInfoServiceImpl.java)
|
||
|
|
- [MinioConfig.java](file://crm-file/src/main/java/com/crm/file/config/MinioConfig.java)
|
||
|
|
- [FileProperties.java](file://crm-file/src/main/java/com/crm/file/config/FileProperties.java)
|
||
|
|
- [OrphanChunkCleanupTask.java](file://crm-file/src/main/java/com/crm/file/task/OrphanChunkCleanupTask.java)
|
||
|
|
|
||
|
|
章节来源
|
||
|
|
- [FileApi.java](file://crm-file/src/main/java/com/crm/file/api/FileApi.java)
|
||
|
|
- [FileController.java](file://crm-file/src/main/java/com/crm/file/controller/FileController.java)
|
||
|
|
- [MinioConfig.java](file://crm-file/src/main/java/com/crm/file/config/MinioConfig.java)
|
||
|
|
- [FileProperties.java](file://crm-file/src/main/java/com/crm/file/config/FileProperties.java)
|
||
|
|
- [FileInfoServiceImpl.java](file://crm-file/src/main/java/com/crm/file/service/impl/FileInfoServiceImpl.java)
|
||
|
|
- [FileApiImpl.java](file://crm-file/src/main/java/com/crm/file/service/impl/FileApiImpl.java)
|
||
|
|
- [KkFileViewClient.java](file://crm-file/src/main/java/com/crm/file/service/KkFileViewClient.java)
|
||
|
|
- [OrphanChunkCleanupTask.java](file://crm-file/src/main/java/com/crm/file/task/OrphanChunkCleanupTask.java)
|
||
|
|
|
||
|
|
### 概念性总览
|
||
|
|
下图展示各服务之间的调用关系与外部依赖,便于从宏观层面理解系统交互。
|
||
|
|
|
||
|
|
```mermaid
|
||
|
|
graph LR
|
||
|
|
Client["客户端"] --> Gateway["网关/聚合层"]
|
||
|
|
Gateway --> Auth["认证服务"]
|
||
|
|
Gateway --> File["文件服务"]
|
||
|
|
Auth --> DB["数据库"]
|
||
|
|
Auth --> Cache["缓存(Redis)"]
|
||
|
|
File --> Storage["对象存储(MinIO)"]
|
||
|
|
File --> Preview["在线预览服务"]
|
||
|
|
```
|
||
|
|
|
||
|
|
[此图为概念性流程图,不直接映射具体源码文件]
|
||
|
|
|
||
|
|
## 依赖关系分析
|
||
|
|
- 模块耦合
|
||
|
|
- crm-app 依赖 crm-auth 与 crm-file,二者均依赖 crm-base。
|
||
|
|
- crm-auth 内部通过 service/mapper 分层,security 层与 config 层解耦。
|
||
|
|
- crm-file 通过 api 抽象与 controller 分离,service 层对接 MinIO 与预览服务。
|
||
|
|
- 外部依赖
|
||
|
|
- 数据库:MyBatis-Plus 配置在 crm-base。
|
||
|
|
- 缓存:Redis 配置在 crm-base。
|
||
|
|
- 对象存储:MinIO 配置在 crm-file。
|
||
|
|
- 第三方预览:KkFileView 客户端在 crm-file。
|
||
|
|
|
||
|
|
```mermaid
|
||
|
|
graph TB
|
||
|
|
APP["crm-app"] --> AUTH["crm-auth"]
|
||
|
|
APP --> FILE["crm-file"]
|
||
|
|
AUTH --> BASE["crm-base"]
|
||
|
|
FILE --> BASE
|
||
|
|
AUTH --> DB["数据库(MyBatis-Plus)"]
|
||
|
|
AUTH --> REDIS["缓存(Redis)"]
|
||
|
|
FILE --> MINIO["对象存储(MinIO)"]
|
||
|
|
FILE --> PREVIEW["在线预览(KkFileView)"]
|
||
|
|
```
|
||
|
|
|
||
|
|
图表来源
|
||
|
|
- [pom.xml](file://pom.xml)
|
||
|
|
- [MybatisPlusConfig.java](file://crm-base/src/main/java/com/crm/base/config/MybatisPlusConfig.java)
|
||
|
|
- [RedisConfig.java](file://crm-base/src/main/java/com/crm/base/config/RedisConfig.java)
|
||
|
|
- [MinioConfig.java](file://crm-file/src/main/java/com/crm/file/config/MinioConfig.java)
|
||
|
|
- [KkFileViewClient.java](file://crm-file/src/main/java/com/crm/file/service/KkFileViewClient.java)
|
||
|
|
|
||
|
|
章节来源
|
||
|
|
- [pom.xml](file://pom.xml)
|
||
|
|
- [MybatisPlusConfig.java](file://crm-base/src/main/java/com/crm/base/config/MybatisPlusConfig.java)
|
||
|
|
- [RedisConfig.java](file://crm-base/src/main/java/com/crm/base/config/RedisConfig.java)
|
||
|
|
- [MinioConfig.java](file://crm-file/src/main/java/com/crm/file/config/MinioConfig.java)
|
||
|
|
- [KkFileViewClient.java](file://crm-file/src/main/java/com/crm/file/service/KkFileViewClient.java)
|
||
|
|
|
||
|
|
## 性能考虑
|
||
|
|
- 数据库
|
||
|
|
- 使用 MyBatis-Plus 简化 CRUD,合理设计索引与分页查询,避免 N+1 问题。
|
||
|
|
- 复杂查询可结合自定义 SQL 注入器优化。
|
||
|
|
- 缓存
|
||
|
|
- 热点数据(如权限、字典、部门树)可放入 Redis,降低数据库压力。
|
||
|
|
- 注意缓存一致性与过期策略。
|
||
|
|
- 文件
|
||
|
|
- 分片上传提升大文件稳定性与并发吞吐。
|
||
|
|
- 定期清理孤立分片,释放存储空间。
|
||
|
|
- 序列化
|
||
|
|
- Jackson 配置需关注时区、空值处理与字段过滤,减少无效数据传输。
|
||
|
|
- ID 生成
|
||
|
|
- 雪花算法保证分布式唯一且有序,避免自增主键瓶颈。
|
||
|
|
|
||
|
|
[本节为通用指导,不直接分析具体文件]
|
||
|
|
|
||
|
|
## 故障排查指南
|
||
|
|
- 认证失败
|
||
|
|
- 检查 JWT 过滤器与令牌服务是否正确解析与校验。
|
||
|
|
- 确认 Redis 中会话状态与黑名单配置。
|
||
|
|
- 权限不足
|
||
|
|
- 核对角色-菜单-权限配置是否完整。
|
||
|
|
- 检查 @DataScope 注解与数据范围 SQL 生成是否正确。
|
||
|
|
- 文件上传失败
|
||
|
|
- 验证 MinIO 连接与桶策略。
|
||
|
|
- 检查分片会话与会话超时设置。
|
||
|
|
- 查看孤立分片清理任务是否正常运行。
|
||
|
|
- 全局异常
|
||
|
|
- 通过全局异常处理器定位错误码与消息,结合日志输出定位根因。
|
||
|
|
|
||
|
|
章节来源
|
||
|
|
- [JwtAuthenticationFilter.java](file://crm-auth/src/main/java/com/crm/auth/security/JwtAuthenticationFilter.java)
|
||
|
|
- [TokenService.java](file://crm-auth/src/main/java/com/crm/auth/security/TokenService.java)
|
||
|
|
- [GlobalExceptionHandlerAdvice.java](file://crm-base/src/main/java/com/crm/base/advice/GlobalExceptionHandlerAdvice.java)
|
||
|
|
- [MinioConfig.java](file://crm-file/src/main/java/com/crm/file/config/MinioConfig.java)
|
||
|
|
- [OrphanChunkCleanupTask.java](file://crm-file/src/main/java/com/crm/file/task/OrphanChunkCleanupTask.java)
|
||
|
|
|
||
|
|
## 结论
|
||
|
|
本项目以清晰的模块边界与稳定的基础能力为核心,构建了可扩展的 CRM 后端体系。认证服务提供完善的鉴权与数据权限,文件服务提供稳定可靠的对象存储与预览能力,基础框架则确保一致的编码规范与通用能力复用。通过合理的配置与部署策略,可在不同环境中快速交付与运维。
|
||
|
|
|
||
|
|
[本节为总结性内容,不直接分析具体文件]
|
||
|
|
|
||
|
|
## 附录
|
||
|
|
- 启动方式
|
||
|
|
- 分别运行各服务的 Application 主类(如 CrmAppApplication、AuthApplication),或通过打包后 java -jar 启动。
|
||
|
|
- 配置文件位于各模块 resources/application.yml,可按环境覆盖。
|
||
|
|
- 配置管理
|
||
|
|
- 数据库、Redis、MinIO、JWT、序列化等均在对应模块的配置类中集中管理。
|
||
|
|
- 建议通过环境变量或配置中心进行差异化配置。
|
||
|
|
- 部署架构
|
||
|
|
- 推荐容器化部署,每个服务独立镜像,配合编排平台统一管理。
|
||
|
|
- 外部依赖(数据库、Redis、MinIO、预览服务)通过服务发现或配置中心接入。
|
||
|
|
|
||
|
|
章节来源
|
||
|
|
- [CrmAppApplication.java](file://crm-app/src/main/java/com/crm/app/CrmAppApplication.java)
|
||
|
|
- [AuthApplication.java](file://crm-auth/src/main/java/com/crm/auth/AuthApplication.java)
|
||
|
|
- [application.yml](file://crm-app/src/main/resources/application.yml)
|
||
|
|
- [application.yml](file://crm-auth/src/main/resources/application.yml)
|
||
|
|
- [MybatisPlusConfig.java](file://crm-base/src/main/java/com/crm/base/config/MybatisPlusConfig.java)
|
||
|
|
- [RedisConfig.java](file://crm-base/src/main/java/com/crm/base/config/RedisConfig.java)
|
||
|
|
- [MinioConfig.java](file://crm-file/src/main/java/com/crm/file/config/MinioConfig.java)
|
||
|
|
- [JacksonConfig.java](file://crm-base/src/main/java/com/crm/base/config/JacksonConfig.java)
|