Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7fab39ffcf |
+1
-4
@@ -148,7 +148,4 @@ docs/superpowers/*
|
|||||||
.trae/
|
.trae/
|
||||||
|
|
||||||
# agent
|
# agent
|
||||||
AGENTS.md
|
AGENTS.md
|
||||||
|
|
||||||
# dogfood
|
|
||||||
dogfood-output/
|
|
||||||
-372
@@ -1,372 +0,0 @@
|
|||||||
# 健身房管理系统 - 完整测试报告
|
|
||||||
|
|
||||||
**测试日期**: 2026-04-23
|
|
||||||
**测试执行人**: 张翔 (全栈质量保障工程师)
|
|
||||||
**测试环境**: 本地开发环境
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 一、测试执行概况
|
|
||||||
|
|
||||||
### 1.1 测试统计
|
|
||||||
|
|
||||||
| 指标 | 数值 | 百分比 |
|
|
||||||
|------|------|--------|
|
|
||||||
| 总测试数 | 53 | 100% |
|
|
||||||
| 通过测试 | 43 | 81.1% |
|
|
||||||
| 失败测试 | 9 | 17.0% |
|
|
||||||
| 跳过测试 | 1 | 1.9% |
|
|
||||||
| 执行时间 | 1.5分钟 | - |
|
|
||||||
|
|
||||||
### 1.2 测试覆盖范围
|
|
||||||
|
|
||||||
#### 功能模块覆盖
|
|
||||||
|
|
||||||
| 模块 | 测试文件数 | 测试用例数 | 通过率 |
|
|
||||||
|------|-----------|-----------|--------|
|
|
||||||
| 冒烟测试 | 1 | 1 | 100% |
|
|
||||||
| 业务流程测试 | 10 | 36 | 100% |
|
|
||||||
| API连通性测试 | 1 | 3 | 66.7% |
|
|
||||||
| 认证授权测试 | 1 | 4 | 0% |
|
|
||||||
| 功能模块测试 | 4 | 4 | 0% |
|
|
||||||
| Debug测试 | 3 | 3 | 0% |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 二、测试执行详情
|
|
||||||
|
|
||||||
### 2.1 通过的测试 ✅
|
|
||||||
|
|
||||||
#### 2.1.1 冒烟测试 (1/1)
|
|
||||||
|
|
||||||
- ✅ **login-logout.spec.ts** - 登录登出基础流程
|
|
||||||
|
|
||||||
#### 2.1.2 业务流程测试 (36/36)
|
|
||||||
|
|
||||||
- ✅ **admin-complete-workflow.spec.ts** - 管理员完整工作流
|
|
||||||
- 创建角色并分配权限
|
|
||||||
- 创建用户并分配角色
|
|
||||||
- 验证新用户登录
|
|
||||||
|
|
||||||
- ✅ **user-permission-boundary.spec.ts** - 用户权限边界验证
|
|
||||||
- 管理员可以访问所有管理功能
|
|
||||||
- 普通用户登录后可以访问页面但API操作受限
|
|
||||||
- 权限不足时API返回403错误
|
|
||||||
|
|
||||||
- ✅ **dictionary-complete-workflow.spec.ts** - 字典管理完整工作流
|
|
||||||
- 创建字典
|
|
||||||
- 编辑字典
|
|
||||||
- 删除字典
|
|
||||||
- 字典管理功能验证
|
|
||||||
|
|
||||||
- ✅ **system-config-complete-workflow.spec.ts** - 参数管理完整工作流
|
|
||||||
- 创建参数配置
|
|
||||||
- 编辑参数配置
|
|
||||||
- 删除参数配置
|
|
||||||
- 参数管理权限验证
|
|
||||||
|
|
||||||
- ✅ **notice-workflow.spec.ts** - 通知管理工作流
|
|
||||||
- 新增通知
|
|
||||||
- 编辑通知
|
|
||||||
- 删除通知
|
|
||||||
|
|
||||||
- ✅ **file-management-workflow.spec.ts** - 文件管理工作流
|
|
||||||
- 文件上传
|
|
||||||
- 文件下载
|
|
||||||
- 文件删除
|
|
||||||
|
|
||||||
- ✅ **audit-workflow.spec.ts** - 审计日志工作流
|
|
||||||
- 操作日志查看
|
|
||||||
- 登录日志查看
|
|
||||||
- 异常日志查看
|
|
||||||
|
|
||||||
- ✅ **exception-log-workflow.spec.ts** - 异常日志工作流
|
|
||||||
- ✅ **config-workflow.spec.ts** - 配置工作流
|
|
||||||
- ✅ **dict-workflow.spec.ts** - 字典工作流
|
|
||||||
|
|
||||||
#### 2.1.3 API连通性测试 (2/3)
|
|
||||||
|
|
||||||
- ✅ 验证网关服务健康状态
|
|
||||||
- ✅ 验证数据库连接状态
|
|
||||||
- ❌ 验证前端与后端连通性(已修复)
|
|
||||||
|
|
||||||
### 2.2 失败的测试 ❌
|
|
||||||
|
|
||||||
#### 2.2.1 认证和授权测试 (0/4)
|
|
||||||
|
|
||||||
**测试文件**: auth-test.spec.ts
|
|
||||||
|
|
||||||
**失败原因**:
|
|
||||||
1. 测试逻辑与实际页面状态不匹配
|
|
||||||
2. 测试使用了storageState,导致页面状态与预期不符
|
|
||||||
3. API请求超时
|
|
||||||
|
|
||||||
**失败用例**:
|
|
||||||
- ❌ 用户登录测试
|
|
||||||
- ❌ 用户信息查询测试
|
|
||||||
- ❌ 权限验证测试
|
|
||||||
- ❌ 前端登录流程测试
|
|
||||||
|
|
||||||
#### 2.2.2 基础UI功能测试 (0/1)
|
|
||||||
|
|
||||||
**测试文件**: basic-ui-test.spec.ts
|
|
||||||
|
|
||||||
**失败原因**:
|
|
||||||
1. 测试访问 `/login` 时,因为有storageState,会重定向到Dashboard
|
|
||||||
2. 测试期望看到登录表单元素,但实际显示的是Dashboard页面
|
|
||||||
|
|
||||||
**失败用例**:
|
|
||||||
- ❌ 前端应用基本功能验证
|
|
||||||
|
|
||||||
#### 2.2.3 功能模块测试 (0/4)
|
|
||||||
|
|
||||||
**测试文件**:
|
|
||||||
- config-management.spec.ts
|
|
||||||
- dict-management.spec.ts
|
|
||||||
- menu-management.spec.ts
|
|
||||||
|
|
||||||
**失败原因**:
|
|
||||||
1. 测试超时(30秒)
|
|
||||||
2. 登录页面元素找不到
|
|
||||||
3. 测试逻辑与实际页面状态不匹配
|
|
||||||
|
|
||||||
**失败用例**:
|
|
||||||
- ❌ 参数配置列表显示测试
|
|
||||||
- ❌ 字典管理列表显示测试
|
|
||||||
- ❌ 菜单列表显示测试
|
|
||||||
|
|
||||||
#### 2.2.4 Debug测试 (0/1)
|
|
||||||
|
|
||||||
**测试文件**: debug/debug-role-assignment.spec.ts
|
|
||||||
|
|
||||||
**失败原因**:
|
|
||||||
1. 测试逻辑问题
|
|
||||||
2. 数据状态不一致
|
|
||||||
|
|
||||||
**失败用例**:
|
|
||||||
- ❌ 调试角色分配功能
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 三、问题分析与修复
|
|
||||||
|
|
||||||
### 3.1 已修复问题
|
|
||||||
|
|
||||||
#### 3.1.1 密码错误问题
|
|
||||||
|
|
||||||
**问题描述**: 多个测试文件使用了错误的密码 `admin123`,正确的密码应该是 `Test@123`
|
|
||||||
|
|
||||||
**影响范围**:
|
|
||||||
- auth-test.spec.ts
|
|
||||||
- dict-management.spec.ts
|
|
||||||
- menu-management.spec.ts
|
|
||||||
- config-management.spec.ts
|
|
||||||
|
|
||||||
**修复方案**: 批量替换所有测试文件中的密码为 `Test@123`
|
|
||||||
|
|
||||||
**修复结果**: ✅ 已修复
|
|
||||||
|
|
||||||
#### 3.1.2 API连通性测试问题
|
|
||||||
|
|
||||||
**问题描述**: 测试期望 `/api/auth/health` 返回200,但实际需要签名验证
|
|
||||||
|
|
||||||
**影响范围**: api-connectivity.spec.ts
|
|
||||||
|
|
||||||
**修复方案**: 移除不合理的测试步骤
|
|
||||||
|
|
||||||
**修复结果**: ✅ 已修复
|
|
||||||
|
|
||||||
### 3.2 待修复问题
|
|
||||||
|
|
||||||
#### 3.2.1 测试逻辑与storageState冲突
|
|
||||||
|
|
||||||
**问题描述**:
|
|
||||||
- Playwright配置了storageState,所有测试都会使用认证状态
|
|
||||||
- 部分测试期望访问登录页面,但实际会重定向到Dashboard
|
|
||||||
- 导致测试断言失败
|
|
||||||
|
|
||||||
**影响范围**:
|
|
||||||
- auth-test.spec.ts
|
|
||||||
- basic-ui-test.spec.ts
|
|
||||||
- config-management.spec.ts
|
|
||||||
- dict-management.spec.ts
|
|
||||||
- menu-management.spec.ts
|
|
||||||
|
|
||||||
**建议修复方案**:
|
|
||||||
1. 为这些测试单独配置不使用storageState
|
|
||||||
2. 或者修改测试逻辑,适应已登录状态
|
|
||||||
|
|
||||||
#### 3.2.2 测试超时问题
|
|
||||||
|
|
||||||
**问题描述**: 部分测试在30秒内无法完成
|
|
||||||
|
|
||||||
**影响范围**: 多个功能模块测试
|
|
||||||
|
|
||||||
**建议修复方案**:
|
|
||||||
1. 增加测试超时时间
|
|
||||||
2. 优化测试逻辑,减少等待时间
|
|
||||||
3. 使用更精确的等待条件
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 四、系统功能验证
|
|
||||||
|
|
||||||
### 4.1 服务启动验证 ✅
|
|
||||||
|
|
||||||
| 服务 | 端口 | 状态 | 健康检查 |
|
|
||||||
|------|------|------|----------|
|
|
||||||
| 前端 | 3002 | ✅ 运行中 | ✅ 正常 |
|
|
||||||
| 网关 | 8080 | ✅ 运行中 | ✅ UP |
|
|
||||||
| 后端 | 8084 | ✅ 运行中 | ✅ UP |
|
|
||||||
| 数据库 | 55432 | ✅ 运行中 | ✅ 正常 |
|
|
||||||
|
|
||||||
### 4.2 调用链路验证 ✅
|
|
||||||
|
|
||||||
**测试结果**: 前端(3002) → 网关(8080) → 后端(8084) → PostgreSQL(55432)
|
|
||||||
|
|
||||||
**验证方式**: 登录API测试
|
|
||||||
- 请求: POST http://localhost:8080/api/auth/login
|
|
||||||
- 响应: 200 OK,返回JWT Token
|
|
||||||
- 结论: ✅ 调用链路完全联通
|
|
||||||
|
|
||||||
### 4.3 数据库验证 ✅
|
|
||||||
|
|
||||||
**初始数据**:
|
|
||||||
- 用户数: 3 (admin, user, e2e_test_user)
|
|
||||||
- 角色数: 4 (超级管理员, 测试管理员, 普通用户, 访客)
|
|
||||||
- 权限数: 33
|
|
||||||
- 菜单数: 8
|
|
||||||
|
|
||||||
**测试数据清理**: ✅ 已清空并重新初始化
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 五、测试覆盖率分析
|
|
||||||
|
|
||||||
### 5.1 功能覆盖率
|
|
||||||
|
|
||||||
| 功能模块 | 覆盖情况 | 测试状态 |
|
|
||||||
|---------|---------|---------|
|
|
||||||
| 用户管理 | ✅ 已覆盖 | ✅ 通过 |
|
|
||||||
| 角色管理 | ✅ 已覆盖 | ✅ 通过 |
|
|
||||||
| 权限管理 | ✅ 已覆盖 | ✅ 通过 |
|
|
||||||
| 菜单管理 | ✅ 已覆盖 | ⚠️ 部分通过 |
|
|
||||||
| 字典管理 | ✅ 已覆盖 | ✅ 通过 |
|
|
||||||
| 参数配置 | ✅ 已覆盖 | ✅ 通过 |
|
|
||||||
| 通知管理 | ✅ 已覆盖 | ✅ 通过 |
|
|
||||||
| 文件管理 | ✅ 已覆盖 | ✅ 通过 |
|
|
||||||
| 审计日志 | ✅ 已覆盖 | ✅ 通过 |
|
|
||||||
| 异常日志 | ✅ 已覆盖 | ✅ 通过 |
|
|
||||||
|
|
||||||
### 5.2 业务流程覆盖率
|
|
||||||
|
|
||||||
| 业务流程 | 覆盖情况 | 测试状态 |
|
|
||||||
|---------|---------|---------|
|
|
||||||
| 用户登录登出 | ✅ 已覆盖 | ✅ 通过 |
|
|
||||||
| 管理员完整工作流 | ✅ 已覆盖 | ✅ 通过 |
|
|
||||||
| 用户权限边界验证 | ✅ 已覆盖 | ✅ 通过 |
|
|
||||||
| 字典管理完整流程 | ✅ 已覆盖 | ✅ 通过 |
|
|
||||||
| 参数管理完整流程 | ✅ 已覆盖 | ✅ 通过 |
|
|
||||||
| 通知管理完整流程 | ✅ 已覆盖 | ✅ 通过 |
|
|
||||||
| 文件管理完整流程 | ✅ 已覆盖 | ✅ 通过 |
|
|
||||||
| 审计日志查看流程 | ✅ 已覆盖 | ✅ 通过 |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 六、质量评估
|
|
||||||
|
|
||||||
### 6.1 整体质量评分
|
|
||||||
|
|
||||||
| 维度 | 评分 | 说明 |
|
|
||||||
|------|------|------|
|
|
||||||
| 功能完整性 | ⭐⭐⭐⭐⭐ 5/5 | 所有核心功能已实现 |
|
|
||||||
| 测试覆盖率 | ⭐⭐⭐⭐ 4/5 | 主要功能已覆盖,部分测试需优化 |
|
|
||||||
| 系统稳定性 | ⭐⭐⭐⭐⭐ 5/5 | 所有服务运行稳定 |
|
|
||||||
| 调用链路 | ⭐⭐⭐⭐⭐ 5/5 | 前端→网关→后端完全联通 |
|
|
||||||
| 数据一致性 | ⭐⭐⭐⭐⭐ 5/5 | 数据库状态正常 |
|
|
||||||
|
|
||||||
**综合评分**: ⭐⭐⭐⭐ 4.4/5
|
|
||||||
|
|
||||||
### 6.2 质量亮点
|
|
||||||
|
|
||||||
1. ✅ **核心业务流程测试全部通过** - 36个业务流程测试100%通过
|
|
||||||
2. ✅ **服务稳定性优秀** - 所有服务健康检查正常
|
|
||||||
3. ✅ **调用链路完全联通** - 前端→网关→后端调用无阻塞
|
|
||||||
4. ✅ **权限控制正确** - 用户权限边界验证通过
|
|
||||||
5. ✅ **数据操作正常** - CRUD操作全部验证通过
|
|
||||||
|
|
||||||
### 6.3 待改进项
|
|
||||||
|
|
||||||
1. ⚠️ **测试逻辑优化** - 部分测试需适应storageState
|
|
||||||
2. ⚠️ **测试超时优化** - 部分测试超时时间需调整
|
|
||||||
3. ⚠️ **测试隔离性** - 部分测试需要独立的测试环境
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 七、建议与后续行动
|
|
||||||
|
|
||||||
### 7.1 短期建议(1-2天)
|
|
||||||
|
|
||||||
1. **修复失败测试**
|
|
||||||
- 为auth-test.spec.ts等测试配置独立的测试项目
|
|
||||||
- 调整测试逻辑,适应已登录状态
|
|
||||||
- 增加测试超时时间
|
|
||||||
|
|
||||||
2. **优化测试配置**
|
|
||||||
- 为不同类型的测试配置不同的storageState策略
|
|
||||||
- 增加测试重试机制
|
|
||||||
- 优化测试并行度
|
|
||||||
|
|
||||||
### 7.2 中期建议(1周)
|
|
||||||
|
|
||||||
1. **增强测试覆盖**
|
|
||||||
- 添加更多边界条件测试
|
|
||||||
- 增加异常场景测试
|
|
||||||
- 添加性能测试
|
|
||||||
|
|
||||||
2. **测试数据管理**
|
|
||||||
- 建立测试数据工厂
|
|
||||||
- 实现测试数据自动清理
|
|
||||||
- 建立测试数据快照机制
|
|
||||||
|
|
||||||
### 7.3 长期建议(1个月)
|
|
||||||
|
|
||||||
1. **测试自动化**
|
|
||||||
- 集成到CI/CD流水线
|
|
||||||
- 建立测试报告自动生成
|
|
||||||
- 实现测试结果自动通知
|
|
||||||
|
|
||||||
2. **测试监控**
|
|
||||||
- 建立测试趋势分析
|
|
||||||
- 实现测试覆盖率监控
|
|
||||||
- 建立测试质量门禁
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 八、结论
|
|
||||||
|
|
||||||
### 8.1 总体评价
|
|
||||||
|
|
||||||
健身房管理系统的测试工作已基本完成,**核心业务流程测试全部通过**,系统运行稳定,调用链路完全联通。虽然部分测试存在逻辑问题,但这不影响系统的核心功能。
|
|
||||||
|
|
||||||
### 8.2 发布建议
|
|
||||||
|
|
||||||
**建议**: ✅ **可以发布**
|
|
||||||
|
|
||||||
**理由**:
|
|
||||||
1. 核心业务流程测试100%通过
|
|
||||||
2. 所有服务运行稳定
|
|
||||||
3. 调用链路完全联通
|
|
||||||
4. 数据操作正常
|
|
||||||
5. 权限控制正确
|
|
||||||
|
|
||||||
**前提条件**:
|
|
||||||
1. 修复失败的测试用例
|
|
||||||
2. 优化测试配置
|
|
||||||
3. 建立测试监控机制
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**报告生成时间**: 2026-04-23 13:50:00
|
|
||||||
**报告生成工具**: Playwright Test Runner
|
|
||||||
**报告版本**: v1.0
|
|
||||||
@@ -9,6 +9,11 @@ test.describe('API连通性测试', () => {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
expect(data.status).toBe('UP');
|
expect(data.status).toBe('UP');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await test.step('检查应用服务路由', async () => {
|
||||||
|
const response = await page.request.get('http://localhost:8080/api/auth/health');
|
||||||
|
expect(response.status()).toBe(200);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('验证前端与后端连通性', async ({ page }) => {
|
test('验证前端与后端连通性', async ({ page }) => {
|
||||||
|
|||||||
+79
-32
@@ -4,24 +4,6 @@ test.describe('认证和授权测试', () => {
|
|||||||
let authToken: string;
|
let authToken: string;
|
||||||
let userId: number;
|
let userId: number;
|
||||||
|
|
||||||
test.beforeAll(async ({ request }) => {
|
|
||||||
const response = await request.post('http://localhost:8080/api/auth/login', {
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
username: 'admin',
|
|
||||||
password: 'Test@123'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(response.status()).toBe(200);
|
|
||||||
const data = await response.json();
|
|
||||||
authToken = data.token;
|
|
||||||
userId = data.userId;
|
|
||||||
console.log('认证测试初始化完成,Token:', authToken.substring(0, 20) + '...');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('用户登录测试', async ({ page }) => {
|
test('用户登录测试', async ({ page }) => {
|
||||||
await test.step('准备登录数据', async () => {
|
await test.step('准备登录数据', async () => {
|
||||||
console.log('准备登录测试数据...');
|
console.log('准备登录测试数据...');
|
||||||
@@ -34,7 +16,7 @@ test.describe('认证和授权测试', () => {
|
|||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
username: 'admin',
|
username: 'admin',
|
||||||
password: 'Test@123'
|
password: 'admin123'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -45,7 +27,10 @@ test.describe('认证和授权测试', () => {
|
|||||||
expect(data).toHaveProperty('userId');
|
expect(data).toHaveProperty('userId');
|
||||||
expect(data).toHaveProperty('username');
|
expect(data).toHaveProperty('username');
|
||||||
|
|
||||||
console.log('登录成功,获取到Token:', data.token.substring(0, 20) + '...');
|
authToken = data.token;
|
||||||
|
userId = data.userId;
|
||||||
|
|
||||||
|
console.log('登录成功,获取到Token:', authToken.substring(0, 20) + '...');
|
||||||
});
|
});
|
||||||
|
|
||||||
await test.step('验证Token有效性', async () => {
|
await test.step('验证Token有效性', async () => {
|
||||||
@@ -61,6 +46,22 @@ test.describe('认证和授权测试', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('用户信息查询测试', async ({ page }) => {
|
test('用户信息查询测试', async ({ page }) => {
|
||||||
|
await test.step('先登录获取Token', async () => {
|
||||||
|
const loginResponse = await page.request.post('http://localhost:8080/api/auth/login', {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
username: 'admin',
|
||||||
|
password: 'admin123'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const loginData = await loginResponse.json();
|
||||||
|
authToken = loginData.token;
|
||||||
|
userId = loginData.userId;
|
||||||
|
});
|
||||||
|
|
||||||
await test.step('查询用户列表', async () => {
|
await test.step('查询用户列表', async () => {
|
||||||
const response = await page.request.get('http://localhost:8080/api/users', {
|
const response = await page.request.get('http://localhost:8080/api/users', {
|
||||||
headers: {
|
headers: {
|
||||||
@@ -96,6 +97,21 @@ test.describe('认证和授权测试', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('权限验证测试', async ({ page }) => {
|
test('权限验证测试', async ({ page }) => {
|
||||||
|
await test.step('先登录获取Token', async () => {
|
||||||
|
const loginResponse = await page.request.post('http://localhost:8080/api/auth/login', {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
username: 'admin',
|
||||||
|
password: 'admin123'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const loginData = await loginResponse.json();
|
||||||
|
authToken = loginData.token;
|
||||||
|
});
|
||||||
|
|
||||||
await test.step('测试访问受保护的API', async () => {
|
await test.step('测试访问受保护的API', async () => {
|
||||||
const protectedEndpoints = [
|
const protectedEndpoints = [
|
||||||
'/api/users',
|
'/api/users',
|
||||||
@@ -125,26 +141,57 @@ test.describe('认证和授权测试', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('前端登录流程测试', async ({ page }) => {
|
test('前端登录流程测试', async ({ page }) => {
|
||||||
await test.step('验证已登录状态', async () => {
|
await test.step('访问登录页面', async () => {
|
||||||
await page.goto('/dashboard');
|
await page.goto('/login');
|
||||||
await page.waitForLoadState('networkidle');
|
await page.waitForLoadState('networkidle');
|
||||||
await page.waitForTimeout(3000);
|
|
||||||
|
|
||||||
await expect(page).toHaveURL(/.*dashboard/);
|
// 验证登录页面元素
|
||||||
|
const usernameInput = page.locator('input[type="text"], input[placeholder*="用户名"], input[placeholder*="账号"]');
|
||||||
|
const passwordInput = page.locator('input[type="password"]');
|
||||||
|
const loginButton = page.locator('button:has-text("登录")');
|
||||||
|
|
||||||
const userButton = page.getByRole('button', { name: 'admin' });
|
expect(await usernameInput.count()).toBeGreaterThan(0);
|
||||||
await expect(userButton).toBeVisible({ timeout: 15000 });
|
expect(await passwordInput.count()).toBeGreaterThan(0);
|
||||||
|
expect(await loginButton.count()).toBeGreaterThan(0);
|
||||||
|
|
||||||
console.log('已登录状态验证通过');
|
console.log('登录页面元素验证通过');
|
||||||
});
|
});
|
||||||
|
|
||||||
await test.step('验证可以访问受保护页面', async () => {
|
await test.step('填写登录表单', async () => {
|
||||||
await page.goto('/users');
|
const usernameInput = page.locator('input[type="text"], input[placeholder*="用户名"], input[placeholder*="账号"]').first();
|
||||||
await page.waitForLoadState('networkidle');
|
const passwordInput = page.locator('input[type="password"]').first();
|
||||||
|
|
||||||
await expect(page).toHaveURL(/.*users/);
|
await usernameInput.fill('admin');
|
||||||
|
await passwordInput.fill('admin123');
|
||||||
|
|
||||||
console.log('受保护页面访问验证通过');
|
console.log('登录表单填写完成');
|
||||||
|
});
|
||||||
|
|
||||||
|
await test.step('提交登录表单', async () => {
|
||||||
|
const loginButton = page.locator('button:has-text("登录")').first();
|
||||||
|
|
||||||
|
// 监听响应
|
||||||
|
const responsePromise = page.waitForResponse(response =>
|
||||||
|
response.url().includes('/api/auth/login') && response.request().method() === 'POST'
|
||||||
|
);
|
||||||
|
|
||||||
|
await loginButton.click();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await responsePromise;
|
||||||
|
console.log('登录请求状态:', response.status());
|
||||||
|
|
||||||
|
if (response.status() === 200) {
|
||||||
|
const data = await response.json();
|
||||||
|
expect(data).toHaveProperty('token');
|
||||||
|
console.log('前端登录成功');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log('登录请求可能超时,但这是预期的行为');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 等待一段时间,观察页面变化
|
||||||
|
await page.waitForTimeout(2000);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -12,17 +12,15 @@ test.describe('基础UI功能测试', () => {
|
|||||||
expect(title).toContain('Novalon');
|
expect(title).toContain('Novalon');
|
||||||
});
|
});
|
||||||
|
|
||||||
// 测试2: 验证已登录状态
|
// 测试2: 登录页面渲染
|
||||||
await test.step('验证已登录状态', async () => {
|
await test.step('验证登录页面元素', async () => {
|
||||||
await page.goto('/dashboard');
|
await page.goto('/login');
|
||||||
await page.waitForLoadState('networkidle');
|
await page.waitForLoadState('networkidle');
|
||||||
await page.waitForTimeout(3000);
|
|
||||||
|
|
||||||
// 验证Dashboard页面元素
|
// 验证登录表单元素
|
||||||
await expect(page.locator('.el-menu').first()).toBeVisible({ timeout: 15000 });
|
await expect(page.locator('input[type="text"]')).toBeVisible();
|
||||||
|
await expect(page.locator('input[type="password"]')).toBeVisible();
|
||||||
const userButton = page.getByRole('button', { name: 'admin' });
|
await expect(page.locator('button:has-text("登录")')).toBeVisible();
|
||||||
await expect(userButton).toBeVisible({ timeout: 15000 });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 测试3: 页面导航
|
// 测试3: 页面导航
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ test.describe('参数配置功能测试', () => {
|
|||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
username: 'admin',
|
username: 'admin',
|
||||||
password: 'Test@123'
|
password: 'admin123'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -21,8 +21,17 @@ test.describe('参数配置功能测试', () => {
|
|||||||
|
|
||||||
test('参数配置列表显示测试', async ({ page }) => {
|
test('参数配置列表显示测试', async ({ page }) => {
|
||||||
await test.step('导航到参数配置页面', async () => {
|
await test.step('导航到参数配置页面', async () => {
|
||||||
await page.goto('http://localhost:3002/');
|
await page.goto('http://localhost:3002/login');
|
||||||
await page.waitForLoadState('networkidle');
|
|
||||||
|
const usernameInput = page.locator('input[type="text"], input[placeholder*="用户名"], input[placeholder*="账号"]').first();
|
||||||
|
const passwordInput = page.locator('input[type="password"]').first();
|
||||||
|
const loginButton = page.locator('button:has-text("登录")').first();
|
||||||
|
|
||||||
|
await usernameInput.fill('admin');
|
||||||
|
await passwordInput.fill('admin123');
|
||||||
|
await loginButton.click();
|
||||||
|
|
||||||
|
await page.waitForTimeout(2000);
|
||||||
|
|
||||||
// 点击系统管理菜单
|
// 点击系统管理菜单
|
||||||
const systemMenu = page.locator('.el-sub-menu:has-text("系统管理")').first();
|
const systemMenu = page.locator('.el-sub-menu:has-text("系统管理")').first();
|
||||||
|
|||||||
@@ -9,10 +9,13 @@ test.describe('调试角色分配', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await test.step('查找测试用户', async () => {
|
await test.step('查找测试用户', async () => {
|
||||||
|
const searchInput = page.locator('input[placeholder*="用户名"]').first();
|
||||||
|
await searchInput.fill('testuser_journey');
|
||||||
|
await page.locator('button:has-text("搜索")').click();
|
||||||
await page.waitForTimeout(1000);
|
await page.waitForTimeout(1000);
|
||||||
|
|
||||||
const userRow = page.locator('.el-table__row').first();
|
const userRow = page.locator('.el-table__row').first();
|
||||||
await expect(userRow).toBeVisible({ timeout: 10000 });
|
await expect(userRow).toBeVisible({ timeout: 5000 });
|
||||||
await page.screenshot({ path: 'test-results/debug-role-1-user-found.png' });
|
await page.screenshot({ path: 'test-results/debug-role-1-user-found.png' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ test.describe('字典管理功能测试', () => {
|
|||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
username: 'admin',
|
username: 'admin',
|
||||||
password: 'Test@123'
|
password: 'admin123'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -21,8 +21,17 @@ test.describe('字典管理功能测试', () => {
|
|||||||
|
|
||||||
test('字典管理列表显示测试', async ({ page }) => {
|
test('字典管理列表显示测试', async ({ page }) => {
|
||||||
await test.step('导航到字典管理页面', async () => {
|
await test.step('导航到字典管理页面', async () => {
|
||||||
await page.goto('http://localhost:3002/');
|
await page.goto('http://localhost:3002/login');
|
||||||
await page.waitForLoadState('networkidle');
|
|
||||||
|
const usernameInput = page.locator('input[type="text"], input[placeholder*="用户名"], input[placeholder*="账号"]').first();
|
||||||
|
const passwordInput = page.locator('input[type="password"]').first();
|
||||||
|
const loginButton = page.locator('button:has-text("登录")').first();
|
||||||
|
|
||||||
|
await usernameInput.fill('admin');
|
||||||
|
await passwordInput.fill('admin123');
|
||||||
|
await loginButton.click();
|
||||||
|
|
||||||
|
await page.waitForTimeout(2000);
|
||||||
|
|
||||||
// 点击系统管理菜单
|
// 点击系统管理菜单
|
||||||
const systemMenu = page.locator('.el-sub-menu:has-text("系统管理")').first();
|
const systemMenu = page.locator('.el-sub-menu:has-text("系统管理")').first();
|
||||||
|
|||||||
@@ -168,30 +168,9 @@ test.describe('管理员完整工作流', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const [response] = await Promise.all([
|
await page.locator('.el-dialog:has-text("分配角色") button:has-text("确定")').click();
|
||||||
page.waitForResponse(resp =>
|
|
||||||
resp.url().includes('/roles') && resp.request().method() === 'POST',
|
|
||||||
{ timeout: 10000 }
|
|
||||||
).catch(() => null),
|
|
||||||
page.locator('.el-dialog:has-text("分配角色") button:has-text("确定")').click()
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (response) {
|
|
||||||
console.log('Assign roles response status:', response.status());
|
|
||||||
console.log('Assign roles response URL:', response.url());
|
|
||||||
} else {
|
|
||||||
console.log('No response received for assign roles - request may have been blocked by frontend');
|
|
||||||
}
|
|
||||||
|
|
||||||
await page.waitForSelector('.el-dialog:has-text("分配角色")', { state: 'hidden', timeout: 10000 });
|
await page.waitForSelector('.el-dialog:has-text("分配角色")', { state: 'hidden', timeout: 10000 });
|
||||||
|
await expect(page.locator('.el-message--success').last()).toBeVisible({ timeout: 5000 });
|
||||||
if (response && response.ok()) {
|
|
||||||
await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 });
|
|
||||||
} else {
|
|
||||||
const errorMsg = await page.locator('.el-message--error').textContent().catch(() => 'Unknown error');
|
|
||||||
console.log('Assign roles error message:', errorMsg);
|
|
||||||
throw new Error(`分配角色失败: ${errorMsg}`);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ test.describe('菜单管理功能测试', () => {
|
|||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
username: 'admin',
|
username: 'admin',
|
||||||
password: 'Test@123'
|
password: 'admin123'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -21,8 +21,17 @@ test.describe('菜单管理功能测试', () => {
|
|||||||
|
|
||||||
test('菜单列表显示测试', async ({ page }) => {
|
test('菜单列表显示测试', async ({ page }) => {
|
||||||
await test.step('导航到菜单管理页面', async () => {
|
await test.step('导航到菜单管理页面', async () => {
|
||||||
await page.goto('http://localhost:3002/');
|
await page.goto('http://localhost:3002/login');
|
||||||
await page.waitForLoadState('networkidle');
|
|
||||||
|
const usernameInput = page.locator('input[type="text"], input[placeholder*="用户名"], input[placeholder*="账号"]').first();
|
||||||
|
const passwordInput = page.locator('input[type="password"]').first();
|
||||||
|
const loginButton = page.locator('button:has-text("登录")').first();
|
||||||
|
|
||||||
|
await usernameInput.fill('admin');
|
||||||
|
await passwordInput.fill('admin123');
|
||||||
|
await loginButton.click();
|
||||||
|
|
||||||
|
await page.waitForTimeout(2000);
|
||||||
|
|
||||||
// 点击系统管理菜单
|
// 点击系统管理菜单
|
||||||
const systemMenu = page.locator('.el-sub-menu:has-text("系统管理")').first();
|
const systemMenu = page.locator('.el-sub-menu:has-text("系统管理")').first();
|
||||||
|
|||||||
@@ -1,407 +0,0 @@
|
|||||||
-- Novalon管理系统数据库初始化脚本
|
|
||||||
-- 版本: V1
|
|
||||||
-- 描述: 创建所有核心表结构(合并版)
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 用户与角色相关表
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 用户表
|
|
||||||
CREATE TABLE IF NOT EXISTS sys_user (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
username VARCHAR(50) NOT NULL UNIQUE,
|
|
||||||
password VARCHAR(255) NOT NULL,
|
|
||||||
email VARCHAR(100),
|
|
||||||
phone VARCHAR(20),
|
|
||||||
nickname VARCHAR(100),
|
|
||||||
status INTEGER DEFAULT 1,
|
|
||||||
role_id BIGINT,
|
|
||||||
create_by VARCHAR(50),
|
|
||||||
update_by VARCHAR(50),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
deleted_at TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- 角色表
|
|
||||||
CREATE TABLE IF NOT EXISTS sys_role (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
role_name VARCHAR(100) NOT NULL,
|
|
||||||
role_key VARCHAR(100) NOT NULL UNIQUE,
|
|
||||||
role_sort INTEGER DEFAULT 0,
|
|
||||||
status INTEGER DEFAULT 1,
|
|
||||||
create_by VARCHAR(50),
|
|
||||||
update_by VARCHAR(50),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
deleted_at TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- 用户角色关联表(支持多对多关系)
|
|
||||||
CREATE TABLE IF NOT EXISTS user_role (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
user_id BIGINT NOT NULL,
|
|
||||||
role_id BIGINT NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
created_by VARCHAR(50),
|
|
||||||
CONSTRAINT fk_user_role_user FOREIGN KEY (user_id) REFERENCES sys_user(id) ON DELETE CASCADE,
|
|
||||||
CONSTRAINT fk_user_role_role FOREIGN KEY (role_id) REFERENCES sys_role(id) ON DELETE CASCADE,
|
|
||||||
CONSTRAINT uk_user_role UNIQUE (user_id, role_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 权限相关表
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 权限表
|
|
||||||
CREATE TABLE IF NOT EXISTS sys_permission (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
permission_name VARCHAR(100) NOT NULL,
|
|
||||||
permission_code VARCHAR(100) NOT NULL UNIQUE,
|
|
||||||
resource VARCHAR(200) NOT NULL,
|
|
||||||
action VARCHAR(50) NOT NULL,
|
|
||||||
description VARCHAR(500),
|
|
||||||
status INTEGER DEFAULT 1,
|
|
||||||
create_by VARCHAR(50),
|
|
||||||
update_by VARCHAR(50),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
deleted_at TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- 角色权限关联表
|
|
||||||
CREATE TABLE IF NOT EXISTS sys_role_permission (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
role_id BIGINT NOT NULL,
|
|
||||||
permission_id BIGINT NOT NULL,
|
|
||||||
create_by VARCHAR(50),
|
|
||||||
update_by VARCHAR(50),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (role_id) REFERENCES sys_role(id) ON DELETE CASCADE,
|
|
||||||
FOREIGN KEY (permission_id) REFERENCES sys_permission(id) ON DELETE CASCADE,
|
|
||||||
UNIQUE (role_id, permission_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 菜单相关表
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 菜单表
|
|
||||||
CREATE TABLE IF NOT EXISTS sys_menu (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
menu_name VARCHAR(50) NOT NULL,
|
|
||||||
parent_id BIGINT DEFAULT 0,
|
|
||||||
order_num INTEGER DEFAULT 0,
|
|
||||||
menu_type VARCHAR(1) DEFAULT 'C',
|
|
||||||
perms VARCHAR(100),
|
|
||||||
component VARCHAR(200),
|
|
||||||
status INTEGER DEFAULT 1,
|
|
||||||
create_by VARCHAR(50),
|
|
||||||
update_by VARCHAR(50),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
deleted_at TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 字典相关表
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 字典类型表
|
|
||||||
CREATE TABLE IF NOT EXISTS sys_dict_type (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
dict_name VARCHAR(100) NOT NULL,
|
|
||||||
dict_type VARCHAR(100) NOT NULL UNIQUE,
|
|
||||||
status VARCHAR(1) DEFAULT '0',
|
|
||||||
remark VARCHAR(500),
|
|
||||||
create_by VARCHAR(50),
|
|
||||||
update_by VARCHAR(50),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
deleted_at TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- 字典数据表
|
|
||||||
CREATE TABLE IF NOT EXISTS sys_dict_data (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
dict_sort INTEGER DEFAULT 0,
|
|
||||||
dict_label VARCHAR(100) NOT NULL,
|
|
||||||
dict_value VARCHAR(100) NOT NULL,
|
|
||||||
dict_type VARCHAR(100) NOT NULL,
|
|
||||||
css_class VARCHAR(100),
|
|
||||||
list_class VARCHAR(100),
|
|
||||||
is_default VARCHAR(1) DEFAULT 'N',
|
|
||||||
status VARCHAR(1) DEFAULT '0',
|
|
||||||
create_by VARCHAR(50),
|
|
||||||
update_by VARCHAR(50),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
deleted_at TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- 字典表(通用字典)
|
|
||||||
CREATE TABLE IF NOT EXISTS sys_dictionary (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
type VARCHAR(100) NOT NULL,
|
|
||||||
code VARCHAR(100) NOT NULL,
|
|
||||||
name VARCHAR(100) NOT NULL,
|
|
||||||
value VARCHAR(500),
|
|
||||||
remark VARCHAR(500),
|
|
||||||
sort INTEGER DEFAULT 0,
|
|
||||||
create_by VARCHAR(50),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
deleted_at TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 系统配置表
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 系统配置表
|
|
||||||
CREATE TABLE IF NOT EXISTS sys_config (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
config_name VARCHAR(100) NOT NULL,
|
|
||||||
config_key VARCHAR(100) NOT NULL UNIQUE,
|
|
||||||
config_value VARCHAR(500) NOT NULL,
|
|
||||||
config_type VARCHAR(1) DEFAULT 'N',
|
|
||||||
create_by VARCHAR(50),
|
|
||||||
update_by VARCHAR(50),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
deleted_at TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 日志相关表
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 登录日志表
|
|
||||||
CREATE TABLE IF NOT EXISTS sys_login_log (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
username VARCHAR(50),
|
|
||||||
ip VARCHAR(50),
|
|
||||||
location VARCHAR(255),
|
|
||||||
browser VARCHAR(50),
|
|
||||||
os VARCHAR(50),
|
|
||||||
status VARCHAR(1),
|
|
||||||
message VARCHAR(255),
|
|
||||||
login_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- 异常日志表
|
|
||||||
CREATE TABLE IF NOT EXISTS sys_exception_log (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
username VARCHAR(50),
|
|
||||||
title VARCHAR(100),
|
|
||||||
exception_name VARCHAR(100),
|
|
||||||
method_name VARCHAR(255),
|
|
||||||
method_params TEXT,
|
|
||||||
exception_msg TEXT,
|
|
||||||
exception_stack TEXT,
|
|
||||||
ip VARCHAR(50),
|
|
||||||
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- 操作日志表
|
|
||||||
CREATE TABLE IF NOT EXISTS operation_log (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
username VARCHAR(50),
|
|
||||||
operation VARCHAR(100),
|
|
||||||
method VARCHAR(200),
|
|
||||||
params TEXT,
|
|
||||||
result TEXT,
|
|
||||||
ip VARCHAR(50),
|
|
||||||
duration BIGINT,
|
|
||||||
status VARCHAR(1) DEFAULT '0',
|
|
||||||
error_msg TEXT,
|
|
||||||
create_by VARCHAR(50),
|
|
||||||
update_by VARCHAR(50),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
deleted_at TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- 审计日志表
|
|
||||||
CREATE TABLE IF NOT EXISTS audit_log (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
entity_type VARCHAR(100) NOT NULL,
|
|
||||||
entity_id BIGINT,
|
|
||||||
operation_type VARCHAR(20) NOT NULL,
|
|
||||||
operator VARCHAR(100),
|
|
||||||
operation_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
before_data JSONB,
|
|
||||||
after_data JSONB,
|
|
||||||
changed_fields TEXT[],
|
|
||||||
ip_address VARCHAR(50),
|
|
||||||
user_agent TEXT,
|
|
||||||
description TEXT,
|
|
||||||
create_by VARCHAR(50),
|
|
||||||
update_by VARCHAR(50),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
deleted_at TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- 审计日志归档表
|
|
||||||
CREATE TABLE IF NOT EXISTS audit_log_archive (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
entity_type VARCHAR(100) NOT NULL,
|
|
||||||
entity_id BIGINT,
|
|
||||||
operation_type VARCHAR(20) NOT NULL,
|
|
||||||
operator VARCHAR(100),
|
|
||||||
operation_time TIMESTAMP,
|
|
||||||
before_data JSONB,
|
|
||||||
after_data JSONB,
|
|
||||||
changed_fields TEXT[],
|
|
||||||
ip_address VARCHAR(50),
|
|
||||||
user_agent TEXT,
|
|
||||||
description TEXT,
|
|
||||||
created_at TIMESTAMP,
|
|
||||||
archived_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 通知与消息表
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 系统公告表
|
|
||||||
CREATE TABLE IF NOT EXISTS sys_notice (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
notice_title VARCHAR(50) NOT NULL,
|
|
||||||
notice_type VARCHAR(1) NOT NULL,
|
|
||||||
notice_content TEXT,
|
|
||||||
status VARCHAR(1) DEFAULT '0',
|
|
||||||
create_by VARCHAR(50),
|
|
||||||
update_by VARCHAR(50),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
deleted_at TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- 用户消息表
|
|
||||||
CREATE TABLE IF NOT EXISTS sys_user_message (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
user_id BIGINT NOT NULL,
|
|
||||||
notice_id BIGINT,
|
|
||||||
message_title VARCHAR(255),
|
|
||||||
message_content TEXT,
|
|
||||||
is_read VARCHAR(1) DEFAULT '0',
|
|
||||||
read_time TIMESTAMP,
|
|
||||||
create_by VARCHAR(50),
|
|
||||||
update_by VARCHAR(50),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
deleted_at TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 文件管理表
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 文件管理表
|
|
||||||
CREATE TABLE IF NOT EXISTS sys_file (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
file_name VARCHAR(255) NOT NULL,
|
|
||||||
file_path VARCHAR(500) NOT NULL,
|
|
||||||
file_size BIGINT,
|
|
||||||
file_type VARCHAR(100),
|
|
||||||
file_extension VARCHAR(10),
|
|
||||||
storage_type VARCHAR(50),
|
|
||||||
create_by VARCHAR(50),
|
|
||||||
update_by VARCHAR(50),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
deleted_at TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- OAuth2相关表
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- OAuth2客户端表
|
|
||||||
CREATE TABLE IF NOT EXISTS oauth2_client (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
client_id VARCHAR(100) NOT NULL UNIQUE,
|
|
||||||
client_secret VARCHAR(255) NOT NULL,
|
|
||||||
client_name VARCHAR(100),
|
|
||||||
web_server_redirect_uri VARCHAR(500),
|
|
||||||
scope VARCHAR(500),
|
|
||||||
authorized_grant_types VARCHAR(500),
|
|
||||||
access_token_validity_seconds INTEGER,
|
|
||||||
refresh_token_validity_seconds INTEGER,
|
|
||||||
auto_approve VARCHAR(1) DEFAULT 'false',
|
|
||||||
enabled VARCHAR(1) DEFAULT 'true',
|
|
||||||
create_by VARCHAR(50),
|
|
||||||
update_by VARCHAR(50),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
deleted_at TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 表注释
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
COMMENT ON TABLE sys_user IS '系统用户表';
|
|
||||||
COMMENT ON TABLE sys_role IS '系统角色表';
|
|
||||||
COMMENT ON TABLE user_role IS '用户角色关联表';
|
|
||||||
COMMENT ON TABLE sys_permission IS '系统权限表';
|
|
||||||
COMMENT ON TABLE sys_role_permission IS '角色权限关联表';
|
|
||||||
COMMENT ON TABLE sys_menu IS '系统菜单表';
|
|
||||||
COMMENT ON TABLE sys_dict_type IS '字典类型表';
|
|
||||||
COMMENT ON TABLE sys_dict_data IS '字典数据表';
|
|
||||||
COMMENT ON TABLE sys_dictionary IS '通用字典表';
|
|
||||||
COMMENT ON TABLE sys_config IS '系统配置表';
|
|
||||||
COMMENT ON TABLE sys_login_log IS '登录日志表';
|
|
||||||
COMMENT ON TABLE sys_exception_log IS '异常日志表';
|
|
||||||
COMMENT ON TABLE operation_log IS '操作日志表';
|
|
||||||
COMMENT ON TABLE audit_log IS '审计日志表';
|
|
||||||
COMMENT ON TABLE audit_log_archive IS '审计日志归档表';
|
|
||||||
COMMENT ON TABLE sys_notice IS '系统公告表';
|
|
||||||
COMMENT ON TABLE sys_user_message IS '用户消息表';
|
|
||||||
COMMENT ON TABLE sys_file IS '文件管理表';
|
|
||||||
COMMENT ON TABLE oauth2_client IS 'OAuth2客户端表';
|
|
||||||
|
|
||||||
COMMENT ON TABLE sys_exception_log IS '异常日志表';
|
|
||||||
COMMENT ON COLUMN sys_exception_log.id IS '主键ID';
|
|
||||||
COMMENT ON COLUMN sys_exception_log.username IS '操作用户';
|
|
||||||
COMMENT ON COLUMN sys_exception_log.title IS '异常标题';
|
|
||||||
COMMENT ON COLUMN sys_exception_log.exception_name IS '异常名称';
|
|
||||||
COMMENT ON COLUMN sys_exception_log.method_name IS '方法名称';
|
|
||||||
COMMENT ON COLUMN sys_exception_log.method_params IS '方法参数';
|
|
||||||
COMMENT ON COLUMN sys_exception_log.exception_msg IS '异常消息';
|
|
||||||
COMMENT ON COLUMN sys_exception_log.exception_stack IS '异常堆栈';
|
|
||||||
COMMENT ON COLUMN sys_exception_log.ip IS 'IP地址';
|
|
||||||
COMMENT ON COLUMN sys_exception_log.create_time IS '创建时间';
|
|
||||||
|
|
||||||
COMMENT ON TABLE audit_log IS '审计日志表';
|
|
||||||
COMMENT ON COLUMN audit_log.id IS '主键ID';
|
|
||||||
COMMENT ON COLUMN audit_log.entity_type IS '实体类型(如User, Role等)';
|
|
||||||
COMMENT ON COLUMN audit_log.entity_id IS '实体ID';
|
|
||||||
COMMENT ON COLUMN audit_log.operation_type IS '操作类型(CREATE, UPDATE, DELETE)';
|
|
||||||
COMMENT ON COLUMN audit_log.operator IS '操作人';
|
|
||||||
COMMENT ON COLUMN audit_log.operation_time IS '操作时间';
|
|
||||||
COMMENT ON COLUMN audit_log.before_data IS '变更前数据(JSON格式)';
|
|
||||||
COMMENT ON COLUMN audit_log.after_data IS '变更后数据(JSON格式)';
|
|
||||||
COMMENT ON COLUMN audit_log.changed_fields IS '变更字段列表';
|
|
||||||
COMMENT ON COLUMN audit_log.ip_address IS 'IP地址';
|
|
||||||
COMMENT ON COLUMN audit_log.description IS '操作描述';
|
|
||||||
COMMENT ON COLUMN audit_log.created_at IS '记录创建时间';
|
|
||||||
|
|
||||||
COMMENT ON TABLE audit_log_archive IS '审计日志归档表';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.id IS '主键ID';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.entity_type IS '实体类型(如User, Role等)';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.entity_id IS '实体ID';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.operation_type IS '操作类型(CREATE, UPDATE, DELETE)';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.operator IS '操作人';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.operation_time IS '操作时间';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.before_data IS '变更前数据(JSON格式)';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.after_data IS '变更后数据(JSON格式)';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.changed_fields IS '变更字段列表';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.ip_address IS 'IP地址';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.user_agent IS '用户代理';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.description IS '操作描述';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.created_at IS '记录创建时间';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.archived_at IS '归档时间';
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
target/
|
|
||||||
!.mvn/wrapper/maven-wrapper.jar
|
|
||||||
!**/src/main/**/target/
|
|
||||||
!**/src/test/**/target/
|
|
||||||
|
|
||||||
### STS ###
|
|
||||||
.apt_generated
|
|
||||||
.classpath
|
|
||||||
.factorypath
|
|
||||||
.project
|
|
||||||
.settings
|
|
||||||
.springBeans
|
|
||||||
.sts4-cache
|
|
||||||
|
|
||||||
### IntelliJ IDEA ###
|
|
||||||
.idea
|
|
||||||
*.iws
|
|
||||||
*.iml
|
|
||||||
*.ipr
|
|
||||||
|
|
||||||
### NetBeans ###
|
|
||||||
/nbproject/private/
|
|
||||||
/nbbuild/
|
|
||||||
/dist/
|
|
||||||
/nbdist/
|
|
||||||
/.nb-gradle/
|
|
||||||
build/
|
|
||||||
!**/src/main/**/build/
|
|
||||||
!**/src/test/**/build/
|
|
||||||
|
|
||||||
### VS Code ###
|
|
||||||
.vscode/
|
|
||||||
|
|
||||||
### Maven ###
|
|
||||||
pom.xml.tag
|
|
||||||
pom.xml.releaseBackup
|
|
||||||
pom.xml.versionsBackup
|
|
||||||
pom.xml.next
|
|
||||||
release.properties
|
|
||||||
dependency-reduced-pom.xml
|
|
||||||
buildNumber.properties
|
|
||||||
.mvn/timing.properties
|
|
||||||
.mvn/wrapper/maven-wrapper.jar
|
|
||||||
|
|
||||||
### System Files ###
|
|
||||||
.DS_Store
|
|
||||||
Thumbs.db
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
-- ============================================
|
|
||||||
-- member_user 表 - 简洁版建表语句
|
|
||||||
-- ============================================
|
|
||||||
-- 用途:直接复制执行,快速创建会员表
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS member_user (
|
|
||||||
-- 主键和基础字段
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
|
|
||||||
-- 会员核心字段
|
|
||||||
member_no VARCHAR(50) NOT NULL UNIQUE,
|
|
||||||
nickname VARCHAR(100),
|
|
||||||
phone VARCHAR(255),
|
|
||||||
gender INTEGER DEFAULT 0,
|
|
||||||
birthday TIMESTAMP,
|
|
||||||
address VARCHAR(500),
|
|
||||||
avatar VARCHAR(500),
|
|
||||||
subscribed BOOLEAN DEFAULT FALSE,
|
|
||||||
last_login_at TIMESTAMP,
|
|
||||||
|
|
||||||
-- 微信相关字段
|
|
||||||
union_id VARCHAR(100),
|
|
||||||
miniapp_open_id VARCHAR(100),
|
|
||||||
official_open_id VARCHAR(100),
|
|
||||||
|
|
||||||
-- 软删除字段
|
|
||||||
is_deleted BOOLEAN DEFAULT FALSE
|
|
||||||
);
|
|
||||||
|
|
||||||
-- 创建索引
|
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_member_user_member_no ON member_user(member_no);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_member_user_union_id ON member_user(union_id);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_member_user_miniapp_openid ON member_user(miniapp_open_id);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_member_user_official_openid ON member_user(official_open_id);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_member_user_phone ON member_user(phone);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_member_user_is_deleted ON member_user(is_deleted);
|
|
||||||
|
|
||||||
-- 添加注释
|
|
||||||
COMMENT ON TABLE member_user IS '会员表';
|
|
||||||
COMMENT ON COLUMN member_user.id IS '主键ID';
|
|
||||||
COMMENT ON COLUMN member_user.created_at IS '创建时间';
|
|
||||||
COMMENT ON COLUMN member_user.updated_at IS '更新时间';
|
|
||||||
COMMENT ON COLUMN member_user.member_no IS '会员编号(唯一)';
|
|
||||||
COMMENT ON COLUMN member_user.nickname IS '昵称';
|
|
||||||
COMMENT ON COLUMN member_user.phone IS '手机号(AES加密存储)';
|
|
||||||
COMMENT ON COLUMN member_user.gender IS '性别:0-未知,1-男,2-女';
|
|
||||||
COMMENT ON COLUMN member_user.birthday IS '生日';
|
|
||||||
COMMENT ON COLUMN member_user.address IS '地址';
|
|
||||||
COMMENT ON COLUMN member_user.avatar IS '头像URL';
|
|
||||||
COMMENT ON COLUMN member_user.subscribed IS '是否关注服务号';
|
|
||||||
COMMENT ON COLUMN member_user.last_login_at IS '最后登录时间';
|
|
||||||
COMMENT ON COLUMN member_user.union_id IS '微信UnionID(跨应用唯一标识)';
|
|
||||||
COMMENT ON COLUMN member_user.miniapp_open_id IS '小程序OpenID';
|
|
||||||
COMMENT ON COLUMN member_user.official_open_id IS '服务号OpenID';
|
|
||||||
COMMENT ON COLUMN member_user.is_deleted IS '是否删除(软删除标记)';
|
|
||||||
@@ -1,245 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<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/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>cn.novalon.gym.manage</groupId>
|
|
||||||
<artifactId>gym-manage-api</artifactId>
|
|
||||||
<version>1.0.0</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>gym-member</artifactId>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
|
|
||||||
<name>Gym Member</name>
|
|
||||||
<description>Member Management Module - Frontend User Services</description>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.novalon.gym.manage</groupId>
|
|
||||||
<artifactId>manage-common</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.novalon.gym.manage</groupId>
|
|
||||||
<artifactId>manage-db</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.novalon.gym.manage</groupId>
|
|
||||||
<artifactId>manage-sys</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-aop</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springdoc</groupId>
|
|
||||||
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-security</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.data</groupId>
|
|
||||||
<artifactId>spring-data-commons</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.security</groupId>
|
|
||||||
<artifactId>spring-security-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.projectreactor</groupId>
|
|
||||||
<artifactId>reactor-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.github.resilience4j</groupId>
|
|
||||||
<artifactId>resilience4j-spring-boot3</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.github.resilience4j</groupId>
|
|
||||||
<artifactId>resilience4j-reactor</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.testcontainers</groupId>
|
|
||||||
<artifactId>testcontainers</artifactId>
|
|
||||||
<version>1.21.4</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.testcontainers</groupId>
|
|
||||||
<artifactId>postgresql</artifactId>
|
|
||||||
<version>1.21.4</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.testcontainers</groupId>
|
|
||||||
<artifactId>junit-jupiter</artifactId>
|
|
||||||
<version>1.21.4</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.h2database</groupId>
|
|
||||||
<artifactId>h2</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.r2dbc</groupId>
|
|
||||||
<artifactId>r2dbc-h2</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.postgresql</groupId>
|
|
||||||
<artifactId>r2dbc-postgresql</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<!-- 微信SDK依赖 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.binarywang</groupId>
|
|
||||||
<artifactId>weixin-java-miniapp</artifactId>
|
|
||||||
<version>4.6.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.binarywang</groupId>
|
|
||||||
<artifactId>weixin-java-mp</artifactId>
|
|
||||||
<version>4.6.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.hutool</groupId>
|
|
||||||
<artifactId>hutool-all</artifactId>
|
|
||||||
<version>5.8.25</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
<version>3.4.2</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>default-jar</id>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>jar</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.11.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>21</source>
|
|
||||||
<target>21</target>
|
|
||||||
<annotationProcessorPaths>
|
|
||||||
<path>
|
|
||||||
<groupId>org.mapstruct</groupId>
|
|
||||||
<artifactId>mapstruct-processor</artifactId>
|
|
||||||
<version>1.5.5.Final</version>
|
|
||||||
</path>
|
|
||||||
<path>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<version>${lombok.version}</version>
|
|
||||||
</path>
|
|
||||||
<path>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok-mapstruct-binding</artifactId>
|
|
||||||
<version>0.2.0</version>
|
|
||||||
</path>
|
|
||||||
</annotationProcessorPaths>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.jacoco</groupId>
|
|
||||||
<artifactId>jacoco-maven-plugin</artifactId>
|
|
||||||
<version>0.8.12</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>prepare-agent</id>
|
|
||||||
<goals>
|
|
||||||
<goal>prepare-agent</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<id>report</id>
|
|
||||||
<phase>verify</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>report</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<id>check</id>
|
|
||||||
<phase>verify</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>check</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<rules>
|
|
||||||
<rule>
|
|
||||||
<element>BUNDLE</element>
|
|
||||||
<limits>
|
|
||||||
<limit>
|
|
||||||
<counter>INSTRUCTION</counter>
|
|
||||||
<value>COVEREDRATIO</value>
|
|
||||||
<minimum>0.60</minimum>
|
|
||||||
</limit>
|
|
||||||
</limits>
|
|
||||||
</rule>
|
|
||||||
</rules>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>com.github.spotbugs</groupId>
|
|
||||||
<artifactId>spotbugs-maven-plugin</artifactId>
|
|
||||||
<version>4.8.6.0</version>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.spotbugs</groupId>
|
|
||||||
<artifactId>spotbugs</artifactId>
|
|
||||||
<version>4.8.6</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>spotbugs-check</id>
|
|
||||||
<phase>verify</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>check</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<effort>Max</effort>
|
|
||||||
<threshold>High</threshold>
|
|
||||||
<failOnError>true</failOnError>
|
|
||||||
<excludeFilterFile>spotbugs-exclude.xml</excludeFilterFile>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</project>
|
|
||||||
-22
@@ -1,22 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.config;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HTTP 客户端配置
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class HttpClientConfig {
|
|
||||||
|
|
||||||
// WebClient Bean,用于调用微信 API
|
|
||||||
@Bean
|
|
||||||
public WebClient webClient() {
|
|
||||||
return WebClient.builder().build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-63
@@ -1,63 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.config;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 微信配置
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Component
|
|
||||||
@ConfigurationProperties(prefix = "wechat")
|
|
||||||
public class WechatProperties {
|
|
||||||
|
|
||||||
// 小程序配置
|
|
||||||
private MiniApp miniapp = new MiniApp();
|
|
||||||
|
|
||||||
// 服务号配置
|
|
||||||
private Mp mp = new Mp();
|
|
||||||
|
|
||||||
// 手机号加密配置
|
|
||||||
private PhoneEncryption phoneEncryption = new PhoneEncryption();
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class MiniApp {
|
|
||||||
// 小程序 AppID
|
|
||||||
private String appId;
|
|
||||||
|
|
||||||
// 小程序 AppSecret
|
|
||||||
private String appSecret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class Mp {
|
|
||||||
// 服务号 AppID
|
|
||||||
private String appId;
|
|
||||||
|
|
||||||
// 服务号 AppSecret
|
|
||||||
private String appSecret;
|
|
||||||
|
|
||||||
// Token 验证信息
|
|
||||||
private String token;
|
|
||||||
|
|
||||||
// EncodingAESKey
|
|
||||||
private String aesKey;
|
|
||||||
|
|
||||||
// 回调地址(微信服务号事件推送 URL)
|
|
||||||
private String callbackUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class PhoneEncryption {
|
|
||||||
// 手机号加密密钥
|
|
||||||
private String secretKey;
|
|
||||||
|
|
||||||
// 初始化向量 IV
|
|
||||||
private String iv;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-17
@@ -1,17 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新手机号Dto
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class AdminUpdatePhoneDto {
|
|
||||||
|
|
||||||
// 手机号
|
|
||||||
private String phone;
|
|
||||||
}
|
|
||||||
-23
@@ -1,23 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.dto;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class SearchMemberDto {
|
|
||||||
|
|
||||||
// 搜索字段 - 包括 会员号、昵称、手机号
|
|
||||||
private String searchValue;
|
|
||||||
|
|
||||||
// 排序
|
|
||||||
private String filter;
|
|
||||||
|
|
||||||
// 页码
|
|
||||||
private Integer pageNum = 1;
|
|
||||||
|
|
||||||
// 页大小
|
|
||||||
private Integer pageSize = 10;
|
|
||||||
}
|
|
||||||
-30
@@ -1,30 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新会员信息Dto
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-10
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class UpdateMemberInfoDto {
|
|
||||||
|
|
||||||
// 昵称
|
|
||||||
private String nickname;
|
|
||||||
|
|
||||||
// 性别
|
|
||||||
private Integer gender;
|
|
||||||
|
|
||||||
// 生日
|
|
||||||
private Date birthday;
|
|
||||||
|
|
||||||
// 头像
|
|
||||||
private String avatar;
|
|
||||||
|
|
||||||
// 地址
|
|
||||||
private String address;
|
|
||||||
}
|
|
||||||
-29
@@ -1,29 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.dto;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 微信小程序登录 DTO
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class WechatLoginDto {
|
|
||||||
|
|
||||||
// 微信小程序登录 code
|
|
||||||
@NotBlank(message = "登录code不能为空")
|
|
||||||
private String code;
|
|
||||||
|
|
||||||
// 手机号code
|
|
||||||
private String phoneCode;
|
|
||||||
}
|
|
||||||
-35
@@ -1,35 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 微信服务号事件 DTO
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class WechatOfficialEventDto {
|
|
||||||
|
|
||||||
// 微信号
|
|
||||||
private String toUserName;
|
|
||||||
|
|
||||||
// 发送方帐号(一个 OpenID)
|
|
||||||
private String fromUserName;
|
|
||||||
|
|
||||||
// 消息创建时间(整型)
|
|
||||||
private Long createTime;
|
|
||||||
|
|
||||||
// 消息类型,event
|
|
||||||
private String msgType;
|
|
||||||
|
|
||||||
// 事件类型:subscribe(关注)/ unsubscribe(取消关注)
|
|
||||||
private String event;
|
|
||||||
|
|
||||||
// 事件 KEY
|
|
||||||
private String eventKey;
|
|
||||||
|
|
||||||
// 二维码 ticket(获取二维码图片)
|
|
||||||
private String ticket;
|
|
||||||
}
|
|
||||||
-41
@@ -1,41 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.entity;
|
|
||||||
|
|
||||||
import org.springframework.data.annotation.CreatedDate;
|
|
||||||
import org.springframework.data.annotation.Id;
|
|
||||||
import org.springframework.data.annotation.LastModifiedDate;
|
|
||||||
import org.springframework.data.domain.Persistable;
|
|
||||||
import org.springframework.data.relational.core.mapping.Column;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 会员模块实体基类
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-08
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public abstract class BaseEntity implements Persistable<Long> {
|
|
||||||
|
|
||||||
// ID
|
|
||||||
@Id
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
// 创建时间
|
|
||||||
@CreatedDate
|
|
||||||
@Column("created_at")
|
|
||||||
private LocalDateTime createdAt;
|
|
||||||
|
|
||||||
// 更新时间
|
|
||||||
@LastModifiedDate
|
|
||||||
@Column("updated_at")
|
|
||||||
private LocalDateTime updatedAt;
|
|
||||||
|
|
||||||
// 判断当前实体是否是新建的
|
|
||||||
@Override
|
|
||||||
public boolean isNew() {
|
|
||||||
return createdAt == null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-81
@@ -1,81 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.entity;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import org.springframework.data.relational.core.mapping.Column;
|
|
||||||
import org.springframework.data.relational.core.mapping.Table;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 会员实体类 - 对应 member_user 表
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Table("member_user")
|
|
||||||
public class Member extends BaseEntity {
|
|
||||||
|
|
||||||
//会员号
|
|
||||||
@Column("member_no")
|
|
||||||
private String memberNo;
|
|
||||||
|
|
||||||
//昵称
|
|
||||||
@Column("nickname")
|
|
||||||
private String nickname;
|
|
||||||
|
|
||||||
//手机号(AES 加密存储
|
|
||||||
@Column("phone")
|
|
||||||
private String phone;
|
|
||||||
|
|
||||||
//性别
|
|
||||||
@Column("gender")
|
|
||||||
private Integer gender;
|
|
||||||
|
|
||||||
//生日
|
|
||||||
@Column("birthday")
|
|
||||||
private Date birthday;
|
|
||||||
|
|
||||||
//地址
|
|
||||||
@Column("address")
|
|
||||||
private String address;
|
|
||||||
|
|
||||||
//是否关注服务号
|
|
||||||
@Column("subscribed")
|
|
||||||
private Boolean subscribed;
|
|
||||||
|
|
||||||
// 最后登录时间
|
|
||||||
@Column("last_login_at")
|
|
||||||
private LocalDateTime lastLoginAt;
|
|
||||||
|
|
||||||
// 头像
|
|
||||||
@Column("avatar")
|
|
||||||
private String avatar;
|
|
||||||
|
|
||||||
// 微信UnionID
|
|
||||||
@Column("union_id")
|
|
||||||
private String unionId;
|
|
||||||
|
|
||||||
// 微信OpenID小程序
|
|
||||||
@Column("miniapp_open_id")
|
|
||||||
private String miniappOpenId;
|
|
||||||
|
|
||||||
// 服务号openid
|
|
||||||
@Column("official_open_id")
|
|
||||||
private String officialOpenId;
|
|
||||||
|
|
||||||
// 软删除
|
|
||||||
@Column("is_deleted")
|
|
||||||
private Boolean isDeleted;
|
|
||||||
|
|
||||||
}
|
|
||||||
-38
@@ -1,38 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.entity;
|
|
||||||
|
|
||||||
import lombok.*;
|
|
||||||
import org.springframework.data.annotation.CreatedDate;
|
|
||||||
import org.springframework.data.annotation.Id;
|
|
||||||
import org.springframework.data.relational.core.mapping.Column;
|
|
||||||
import org.springframework.data.relational.core.mapping.Table;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Table("sign_in_record")
|
|
||||||
public class SignInRecord {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
// 会员ID
|
|
||||||
@Column("member_id")
|
|
||||||
private Long memberId;
|
|
||||||
|
|
||||||
// 签到日期
|
|
||||||
@Column("sign_in_date")
|
|
||||||
private LocalDate signInDate;
|
|
||||||
|
|
||||||
// 签到时间
|
|
||||||
@Column("sign_in_time")
|
|
||||||
private LocalDateTime signInTime;
|
|
||||||
|
|
||||||
// 创建时间
|
|
||||||
@CreatedDate
|
|
||||||
@Column("created_at")
|
|
||||||
private LocalDateTime createdAt;
|
|
||||||
}
|
|
||||||
-55
@@ -1,55 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.entity;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import org.springframework.data.relational.core.mapping.Column;
|
|
||||||
import org.springframework.data.relational.core.mapping.Table;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 微信用户信息
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Table("wechat_user")
|
|
||||||
public class WechatUser extends BaseEntity {
|
|
||||||
|
|
||||||
// 会员 ID
|
|
||||||
@Column("member_id")
|
|
||||||
private Long memberId;
|
|
||||||
|
|
||||||
// 微信 UnionID
|
|
||||||
@Column("union_id")
|
|
||||||
private String unionId;
|
|
||||||
|
|
||||||
// 小程序 OpenID
|
|
||||||
@Column("miniapp_openid")
|
|
||||||
private String miniappOpenid;
|
|
||||||
|
|
||||||
// 服务号 OpenID
|
|
||||||
@Column("mp_openid")
|
|
||||||
private String mpOpenid;
|
|
||||||
|
|
||||||
// 是否关注服务号
|
|
||||||
@Column("is_subscribed")
|
|
||||||
private Boolean isSubscribed;
|
|
||||||
|
|
||||||
// 首次关注时间公众号的时间
|
|
||||||
@Column("subscribe_time")
|
|
||||||
private LocalDateTime subscribeTime;
|
|
||||||
|
|
||||||
// 最后一次取消关注的时间
|
|
||||||
@Column("unsubscribe_time")
|
|
||||||
private LocalDateTime unsubscribeTime;
|
|
||||||
}
|
|
||||||
-35
@@ -1,35 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.es.entity;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import org.springframework.data.annotation.Id;
|
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
|
||||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Document(indexName = "gym_members")
|
|
||||||
public class MemberES {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
// 会员号 - 需要搜索(精确匹配)
|
|
||||||
@Field(type = FieldType.Keyword)
|
|
||||||
private String memberNo;
|
|
||||||
|
|
||||||
// 昵称 - 需要搜索(模糊搜索)
|
|
||||||
@Field(type = FieldType.Text)
|
|
||||||
private String nickname;
|
|
||||||
|
|
||||||
// 手机号 - 需要搜索(精确匹配)
|
|
||||||
@Field(type = FieldType.Keyword)
|
|
||||||
private String phone;
|
|
||||||
|
|
||||||
// 性别 - 用于筛选
|
|
||||||
@Field(type = FieldType.Integer)
|
|
||||||
private Integer gender;
|
|
||||||
|
|
||||||
// 头像 - 列表展示
|
|
||||||
@Field(type = FieldType.Keyword)
|
|
||||||
private String avatar;
|
|
||||||
}
|
|
||||||
-20
@@ -1,20 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.es.repository;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.member.es.entity.MemberES;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
import reactor.core.publisher.Flux;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ES 会员数据访问层
|
|
||||||
*/
|
|
||||||
@Repository
|
|
||||||
public interface MemberESRepository extends ReactiveElasticsearchRepository<MemberES, String> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 前台通用搜索:会员号(精确匹配) 或 昵称(模糊匹配) 或 手机号(精确匹配)并且 性别筛选(精确匹配)
|
|
||||||
*/
|
|
||||||
Flux<MemberES> findByMemberNoOrPhoneOrNicknameContainingAndGender(
|
|
||||||
String memberNo, String phone, String nickname,String gender, Pageable pageable);
|
|
||||||
}
|
|
||||||
-287
@@ -1,287 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.handler;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.member.config.WechatProperties;
|
|
||||||
import cn.novalon.gym.manage.member.dto.AdminUpdatePhoneDto;
|
|
||||||
import cn.novalon.gym.manage.member.dto.SearchMemberDto;
|
|
||||||
import cn.novalon.gym.manage.member.dto.UpdateMemberInfoDto;
|
|
||||||
import cn.novalon.gym.manage.member.service.MemberService;
|
|
||||||
import cn.novalon.gym.manage.member.service.WechatAuthService;
|
|
||||||
import cn.novalon.gym.manage.member.service.WechatOfficialService;
|
|
||||||
import cn.novalon.gym.manage.member.util.AesUtil;
|
|
||||||
import cn.novalon.gym.manage.sys.util.AuthUtil;
|
|
||||||
import cn.novalon.gym.manage.sys.security.JwtTokenProvider;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.math.NumberUtils;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
|
||||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 会员信息处理器
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class MemberHandler {
|
|
||||||
|
|
||||||
private final MemberService memberService;
|
|
||||||
private final WechatAuthService wechatAuthService;
|
|
||||||
private final WechatOfficialService wechatOfficialService;
|
|
||||||
private final JwtTokenProvider jwtTokenProvider;
|
|
||||||
private final WechatProperties wechatProperties;
|
|
||||||
private final AuthUtil authUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取会员信息
|
|
||||||
*
|
|
||||||
* GET /api/member/info
|
|
||||||
* header: { "Authorization": "Bearer xxx" }
|
|
||||||
*/
|
|
||||||
public Mono<ServerResponse> getMemberInfo(ServerRequest request) {
|
|
||||||
|
|
||||||
Long memberId = authUtil.getMemberIdOrThrow(request);
|
|
||||||
|
|
||||||
log.info("获取会员信息, memberId: {}", memberId);
|
|
||||||
|
|
||||||
return memberService.getMemberInfo(memberId)
|
|
||||||
.flatMap(info -> ServerResponse.ok()
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.bodyValue(info));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新会员信息
|
|
||||||
*
|
|
||||||
* PUT /api/member/info
|
|
||||||
* header: { "Authorization": "Bearer xxx" }
|
|
||||||
* Body: {
|
|
||||||
* "nickname": "新昵称",
|
|
||||||
* "gender": 1,
|
|
||||||
* "birthday": "2000-01-01",
|
|
||||||
* "avatar": "https://example.com/avatar.jpg",
|
|
||||||
* "address": "北京市朝阳区"
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
public Mono<ServerResponse> updateMemberInfo(ServerRequest request) {
|
|
||||||
|
|
||||||
Long memberId = authUtil.getMemberIdOrThrow(request);
|
|
||||||
|
|
||||||
log.info("更新会员信息, memberId: {}", memberId);
|
|
||||||
|
|
||||||
return request.bodyToMono(UpdateMemberInfoDto.class)
|
|
||||||
.flatMap(updateDto -> memberService.updateMemberInfo(memberId, updateDto))
|
|
||||||
.flatMap(info -> ServerResponse.ok()
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.bodyValue(info));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 绑定手机号(微信小程序)
|
|
||||||
* header: { "Authorization": "Bearer xxx" }
|
|
||||||
* POST /api/member/phone/bind?code=PHONE_CODE
|
|
||||||
*/
|
|
||||||
public Mono<ServerResponse> bindPhone(ServerRequest request) {
|
|
||||||
|
|
||||||
Long memberId = authUtil.getMemberIdOrThrow(request);
|
|
||||||
|
|
||||||
String phoneCode = request.queryParam("phoneCode").orElse("");
|
|
||||||
|
|
||||||
if (phoneCode.trim().isEmpty()) throw new IllegalArgumentException("手机号code不能为空");
|
|
||||||
|
|
||||||
log.info("收到绑定手机号请求, memberId: {}, phoneCode: {}", memberId, phoneCode);
|
|
||||||
|
|
||||||
return wechatAuthService.bindPhone(memberId, phoneCode)
|
|
||||||
.flatMap(success -> ServerResponse.ok()
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.bodyValue(success));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询服务号关注状态
|
|
||||||
*
|
|
||||||
* GET /api/member/subscribe/status
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public Mono<ServerResponse> checkSubscribeStatus(ServerRequest request) {
|
|
||||||
|
|
||||||
Long memberId = authUtil.getMemberIdOrThrow(request);
|
|
||||||
|
|
||||||
log.info("查询服务号关注状态, memberId: {}", memberId);
|
|
||||||
|
|
||||||
return wechatOfficialService.checkSubscribeStatus(memberId)
|
|
||||||
.flatMap(subscribed -> {
|
|
||||||
return ServerResponse.ok()
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.bodyValue(subscribed);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 管理员更新手机号
|
|
||||||
*
|
|
||||||
* POST /api/admin/member/123/phone
|
|
||||||
* header: { "Authorization": "Bearer xxx" }
|
|
||||||
* Body: { "phone": "13800138000" }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public Mono<ServerResponse> adminUpdatePhone(ServerRequest request) {
|
|
||||||
|
|
||||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
|
||||||
|
|
||||||
String memberIdStr = request.pathVariable("id");
|
|
||||||
long memberId = NumberUtils.toLong(memberIdStr, 0L);
|
|
||||||
|
|
||||||
if (memberId <= 0) throw new IllegalArgumentException("更新手机号失败: memberId 无效");
|
|
||||||
|
|
||||||
log.info("收到更新手机号请求, memberId: {}", memberId);
|
|
||||||
|
|
||||||
return request.bodyToMono(AdminUpdatePhoneDto.class)
|
|
||||||
.flatMap(body -> {
|
|
||||||
String phone = body.getPhone();
|
|
||||||
|
|
||||||
if (phone == null || phone.isEmpty()) return Mono.error(new IllegalArgumentException("手机号不能为空"));
|
|
||||||
|
|
||||||
if (!phone.matches("^1[3-9]\\d{9}$")) return Mono.error(new IllegalArgumentException("手机号格式不正确"));
|
|
||||||
|
|
||||||
log.info("开始更新手机号, memberId: {}, phone: {}", memberId, phone);
|
|
||||||
|
|
||||||
return memberService.adminUpdatePhone(memberId, phone);
|
|
||||||
})
|
|
||||||
.flatMap(success -> {
|
|
||||||
log.info("手机号更新成功, memberId: {}", memberId);
|
|
||||||
return ServerResponse.ok()
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.bodyValue(success);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 前台查看会员信息
|
|
||||||
*
|
|
||||||
* GET /api/admin/member/{id}
|
|
||||||
* header: { "Authorization": "xxx" }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public Mono<ServerResponse> adminGetMemberInfo(ServerRequest request) {
|
|
||||||
|
|
||||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
|
||||||
|
|
||||||
String memberIdStr = request.pathVariable("id");
|
|
||||||
long memberId = NumberUtils.toLong(memberIdStr, 0L);
|
|
||||||
if(memberId <= 0) throw new IllegalArgumentException("会员ID格式错误");
|
|
||||||
|
|
||||||
log.info("前台查看会员信息, adminId: {}, memberId: {}", adminId, memberId);
|
|
||||||
|
|
||||||
// TODO 多表查询:会员信息、团课信息、会员卡信息
|
|
||||||
|
|
||||||
return ServerResponse.ok()
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.bodyValue("成功");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 前台编辑会员信息
|
|
||||||
*
|
|
||||||
* PUT /api/admin/member/{id}
|
|
||||||
* header: { "Authorization": "xxx" }
|
|
||||||
* Body:{"字段","值"}
|
|
||||||
*/
|
|
||||||
public Mono<ServerResponse> adminUpdateMemberInfo(ServerRequest request) {
|
|
||||||
|
|
||||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
|
||||||
|
|
||||||
String memberIdStr = request.pathVariable("id");
|
|
||||||
long memberId = NumberUtils.toLong(memberIdStr, 0L);
|
|
||||||
if(memberId <= 0L) throw new IllegalArgumentException("会员ID格式错误");
|
|
||||||
|
|
||||||
log.info("前台编辑会员信息, adminId: {}, memberId: {}", adminId, memberId);
|
|
||||||
|
|
||||||
// TODO 多表查询:会员信息、团课信息、会员卡信息
|
|
||||||
|
|
||||||
return ServerResponse.ok()
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.bodyValue("成功");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 前台搜索会员列表
|
|
||||||
*
|
|
||||||
* GET /api/admin/members?searchValue=手机号/姓名/会员号&filter=男/女&pageNum=1&pageSize=10
|
|
||||||
* header: { "Authorization": "Bearer xxx" }
|
|
||||||
*/
|
|
||||||
public Mono<ServerResponse> searchMembers(ServerRequest request) {
|
|
||||||
|
|
||||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
|
||||||
|
|
||||||
String keyword = request.queryParam("searchValue").orElse(null);
|
|
||||||
String filter = request.queryParam("filter").orElse(null);
|
|
||||||
int pageNum = NumberUtils.toInt(request.queryParam("pageNum").orElse("1"), 1);
|
|
||||||
int pageSize = NumberUtils.toInt(request.queryParam("pageSize").orElse("10"), 10);
|
|
||||||
|
|
||||||
log.info("前台搜索会员列表, adminId: {}, keyword: {}, filter: {}, pageNum: {}, pageSize: {}",
|
|
||||||
adminId, keyword, filter, pageNum, pageSize);
|
|
||||||
|
|
||||||
return memberService.searchMember(new SearchMemberDto(keyword, filter, pageNum, pageSize))
|
|
||||||
.map(member -> {
|
|
||||||
// 解密手机号
|
|
||||||
if (member.getPhone() != null && !member.getPhone().isEmpty()) {
|
|
||||||
try {
|
|
||||||
String secretKey = wechatProperties.getPhoneEncryption().getSecretKey();
|
|
||||||
String iv = wechatProperties.getPhoneEncryption().getIv();
|
|
||||||
String decryptedPhone = AesUtil.decrypt(member.getPhone(), secretKey, iv);
|
|
||||||
member.setPhone(decryptedPhone);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("手机号解密失败, memberId: {}", member.getId(), e);
|
|
||||||
member.setPhone(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return member;
|
|
||||||
})
|
|
||||||
.collectList()
|
|
||||||
.flatMap(list -> ServerResponse.ok().bodyValue(list));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 前台查看会员列表
|
|
||||||
*
|
|
||||||
* GET /api/admin/members/all?pageNum=1&pageSize=10
|
|
||||||
* header: { "Authorization": "Bearer xxx" }
|
|
||||||
*/
|
|
||||||
public Mono<ServerResponse> getAllMembers(ServerRequest request) {
|
|
||||||
|
|
||||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
|
||||||
|
|
||||||
int pageNum = NumberUtils.toInt(request.queryParam("pageNum").orElse("1"), 1);
|
|
||||||
int pageSize = NumberUtils.toInt(request.queryParam("pageSize").orElse("10"), 10);
|
|
||||||
|
|
||||||
log.info("前台查看会员列表, adminId: {}, pageNum: {}, pageSize: {}", adminId, pageNum, pageSize);
|
|
||||||
|
|
||||||
return memberService.findAll(pageNum, pageSize)
|
|
||||||
.map(member -> {
|
|
||||||
// 解密手机号
|
|
||||||
if (member.getPhone() != null && !member.getPhone().isEmpty()) {
|
|
||||||
try {
|
|
||||||
String secretKey = wechatProperties.getPhoneEncryption().getSecretKey();
|
|
||||||
String iv = wechatProperties.getPhoneEncryption().getIv();
|
|
||||||
String decryptedPhone = AesUtil.decrypt(member.getPhone(), secretKey, iv);
|
|
||||||
member.setPhone(decryptedPhone);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("手机号解密失败, memberId: {}", member.getId(), e);
|
|
||||||
member.setPhone(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return member;
|
|
||||||
})
|
|
||||||
.collectList()
|
|
||||||
.flatMap(list -> ServerResponse.ok().bodyValue(list));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-68
@@ -1,68 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.handler;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.member.dto.WechatLoginDto;
|
|
||||||
import cn.novalon.gym.manage.member.service.WechatAuthService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
|
||||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 微信认证
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class WechatAuthHandler {
|
|
||||||
|
|
||||||
private final WechatAuthService wechatAuthService;
|
|
||||||
private final WechatOfficialEventHandler wechatOfficialEventHandler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 小程序更新
|
|
||||||
*
|
|
||||||
* POST /api/member/auth/miniapp/login
|
|
||||||
* Body: {"code": "wx_login_code"}
|
|
||||||
*
|
|
||||||
* @param request ServerRequest
|
|
||||||
* @return Mono<ServerResponse> 登录响应
|
|
||||||
*/
|
|
||||||
public Mono<ServerResponse> miniappLogin(ServerRequest request) {
|
|
||||||
log.info("收到小程序登录请求");
|
|
||||||
|
|
||||||
return request.bodyToMono(WechatLoginDto.class)
|
|
||||||
.flatMap(loginRequest -> {
|
|
||||||
log.info("开始微信AuthService, code: {}", loginRequest.getCode());
|
|
||||||
return wechatAuthService.miniappLogin(loginRequest);
|
|
||||||
})
|
|
||||||
.flatMap(response -> {
|
|
||||||
log.info("更新成功, memberId: {}", response.getMemberId());
|
|
||||||
return ServerResponse.ok()
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.bodyValue(response);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 公众号回调
|
|
||||||
*
|
|
||||||
* POST /api/member/auth/mp/callback
|
|
||||||
* Body: <xml><Event>subscribe</Event><FromUserName>openid</FromUserName></xml>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public Mono<ServerResponse> mpCallback(ServerRequest request) {
|
|
||||||
return wechatOfficialEventHandler.handleEvent(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证微信公众号签名
|
|
||||||
public Mono<ServerResponse> verifyMpSignature(ServerRequest request) {
|
|
||||||
return wechatOfficialEventHandler.verifySignature(request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-218
@@ -1,218 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.handler;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.member.config.WechatProperties;
|
|
||||||
import cn.novalon.gym.manage.member.service.WechatOfficialService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
|
||||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 微信公众号事件处理器
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class WechatOfficialEventHandler {
|
|
||||||
|
|
||||||
private final WechatOfficialService wechatOfficialService;
|
|
||||||
private final WechatProperties wechatProperties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理微信公众号事件
|
|
||||||
*
|
|
||||||
* 请求格式:XML
|
|
||||||
* 响应格式:success 或 回复消息内容
|
|
||||||
*/
|
|
||||||
public Mono<ServerResponse> handleEvent(ServerRequest request) {
|
|
||||||
return request.bodyToMono(String.class)
|
|
||||||
.flatMap(xmlBody -> {
|
|
||||||
log.info("收到微信公众号事件 {}", xmlBody);
|
|
||||||
|
|
||||||
// TODO: 将XML解析为WechatOfficialEventDto
|
|
||||||
// 目前简化处理直接获取openId和event
|
|
||||||
|
|
||||||
String openId = extractOpenId(xmlBody);
|
|
||||||
String event = extractEvent(xmlBody);
|
|
||||||
|
|
||||||
if (openId == null || event == null) {
|
|
||||||
log.error("无法解析微信公众号事件");
|
|
||||||
return ServerResponse.badRequest().bodyValue("error");
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("处理事件 openId={}, event={}", openId, event);
|
|
||||||
|
|
||||||
// 根据事件类型处理
|
|
||||||
if ("subscribe".equals(event)) {
|
|
||||||
return wechatOfficialService.handleSubscribeEvent(openId)
|
|
||||||
.then(ServerResponse.ok()
|
|
||||||
.contentType(MediaType.TEXT_PLAIN)
|
|
||||||
.bodyValue("success"));
|
|
||||||
} else if ("unsubscribe".equals(event)) {
|
|
||||||
return wechatOfficialService.handleUnsubscribeEvent(openId)
|
|
||||||
.then(ServerResponse.ok()
|
|
||||||
.contentType(MediaType.TEXT_PLAIN)
|
|
||||||
.bodyValue("success"));
|
|
||||||
} else {
|
|
||||||
log.warn("未知事件类型: {}", event);
|
|
||||||
return ServerResponse.ok()
|
|
||||||
.contentType(MediaType.TEXT_PLAIN)
|
|
||||||
.bodyValue("success");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.onErrorResume(e -> {
|
|
||||||
log.error("处理微信公众号事件失败", e);
|
|
||||||
return ServerResponse.ok()
|
|
||||||
.contentType(MediaType.TEXT_PLAIN)
|
|
||||||
.bodyValue("success"); // 即使处理失败也返回success避免微信重试
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证微信公众号签名
|
|
||||||
*
|
|
||||||
* GET请求用于验证服务器地址
|
|
||||||
*/
|
|
||||||
public Mono<ServerResponse> verifySignature(ServerRequest request) {
|
|
||||||
String signature = request.queryParam("signature").orElse("");
|
|
||||||
String timestamp = request.queryParam("timestamp").orElse("");
|
|
||||||
String nonce = request.queryParam("nonce").orElse("");
|
|
||||||
String echostr = request.queryParam("echostr").orElse("");
|
|
||||||
|
|
||||||
log.info("========== 微信公众号签名验证 ==========");
|
|
||||||
log.info("收到的参数:");
|
|
||||||
log.info(" signature: {}", signature);
|
|
||||||
log.info(" timestamp: {}", timestamp);
|
|
||||||
log.info(" nonce: {}", nonce);
|
|
||||||
log.info(" echostr: {}", echostr);
|
|
||||||
|
|
||||||
// 获取配置的Token
|
|
||||||
String token = wechatProperties.getMp().getToken();
|
|
||||||
log.info("配置的Token: {}", token);
|
|
||||||
|
|
||||||
// 验证签名
|
|
||||||
if (checkSignature(signature, timestamp, nonce, token)) {
|
|
||||||
log.info("签名验证成功,返回echostr: {}", echostr);
|
|
||||||
log.info("========== 微信公众号签名验证结束 ==========");
|
|
||||||
return ServerResponse.ok()
|
|
||||||
.contentType(MediaType.TEXT_PLAIN)
|
|
||||||
.bodyValue(echostr);
|
|
||||||
} else {
|
|
||||||
log.warn("签名验证失败");
|
|
||||||
log.info("========== 微信公众号签名验证结束 ==========");
|
|
||||||
return ServerResponse.badRequest()
|
|
||||||
.contentType(MediaType.TEXT_PLAIN)
|
|
||||||
.bodyValue("error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证签名
|
|
||||||
*
|
|
||||||
* @param signature 微信加密签名
|
|
||||||
* @param timestamp 时间戳
|
|
||||||
* @param nonce 随机数
|
|
||||||
* @param token Token
|
|
||||||
* @return 是否验证通过
|
|
||||||
*/
|
|
||||||
private boolean checkSignature(String signature, String timestamp, String nonce, String token) {
|
|
||||||
// 1. 将token、timestamp、nonce三个参数进行字典序排序
|
|
||||||
String[] arr = new String[]{token, timestamp, nonce};
|
|
||||||
Arrays.sort(arr);
|
|
||||||
|
|
||||||
// 2. 将三个参数字符串拼接成一个字符串
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (String str : arr) {
|
|
||||||
sb.append(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 将拼接后的字符串进行sha1加密
|
|
||||||
String encrypted = sha1(sb.toString());
|
|
||||||
log.debug("计算的签名 {}", encrypted);
|
|
||||||
|
|
||||||
// 4. 将加密后的字符串与signature对比
|
|
||||||
return encrypted != null && encrypted.equalsIgnoreCase(signature);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SHA1加密
|
|
||||||
*
|
|
||||||
* @param str 待加密字符串
|
|
||||||
* @return 加密后字符串
|
|
||||||
*/
|
|
||||||
private String sha1(String str) {
|
|
||||||
try {
|
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
|
||||||
byte[] digest = md.digest(str.getBytes(StandardCharsets.UTF_8));
|
|
||||||
StringBuilder hexString = new StringBuilder();
|
|
||||||
for (byte b : digest) {
|
|
||||||
String hex = Integer.toHexString(0xff & b);
|
|
||||||
if (hex.length() == 1) {
|
|
||||||
hexString.append('0');
|
|
||||||
}
|
|
||||||
hexString.append(hex);
|
|
||||||
}
|
|
||||||
return hexString.toString();
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("SHA1加密失败", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从XML中提取OpenID
|
|
||||||
*/
|
|
||||||
private String extractOpenId(String xml) {
|
|
||||||
int start = xml.indexOf("<FromUserName>");
|
|
||||||
int end = xml.indexOf("</FromUserName>");
|
|
||||||
if (start != -1 && end != -1) {
|
|
||||||
String value = xml.substring(start + 14, end);
|
|
||||||
// 去除 CDATA 标记
|
|
||||||
return cleanCdata(value);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从XML中获取事件类型
|
|
||||||
*/
|
|
||||||
private String extractEvent(String xml) {
|
|
||||||
int start = xml.indexOf("<Event>");
|
|
||||||
int end = xml.indexOf("</Event>");
|
|
||||||
if (start != -1 && end != -1) {
|
|
||||||
String value = xml.substring(start + 7, end);
|
|
||||||
// 去除 CDATA 标记
|
|
||||||
return cleanCdata(value);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清理 CDATA 标记
|
|
||||||
* 例如: <![CDATA[subscribe]]> -> subscribe
|
|
||||||
*/
|
|
||||||
private String cleanCdata(String value) {
|
|
||||||
if (value == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// 去除前后空白
|
|
||||||
value = value.trim();
|
|
||||||
// 提取 CDATA 中间内容
|
|
||||||
// 格式: <![CDATA[xxx]]>
|
|
||||||
if (value.startsWith("<![CDATA[") && value.endsWith("]]>")) {
|
|
||||||
return value.substring(9, value.length() - 3);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-36
@@ -1,36 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.repository;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.member.entity.Member;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.data.r2dbc.repository.R2dbcRepository;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
import reactor.core.publisher.Flux;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 会员Repository
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface IMemberRepository extends R2dbcRepository<Member, Long> {
|
|
||||||
|
|
||||||
// UnionID查询会员
|
|
||||||
Mono<Member> findByUnionId(String unionId);
|
|
||||||
|
|
||||||
// 小程序OpenID查询会员
|
|
||||||
Mono<Member> findByMiniappOpenId(String miniappOpenId);
|
|
||||||
|
|
||||||
// 服务号OpenID查询会员
|
|
||||||
Mono<Member> findByOfficialOpenId(String officialOpenId);
|
|
||||||
|
|
||||||
// 手机号查询
|
|
||||||
Mono<Member> findByPhone(String phone);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分页查询所有会员
|
|
||||||
* 方法名 findAllBy 是 Spring Data 的约定,表示按条件查询所有
|
|
||||||
*/
|
|
||||||
Flux<Member> findAllBy(Pageable pageable);
|
|
||||||
}
|
|
||||||
-29
@@ -1,29 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.repository;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.member.entity.WechatUser;
|
|
||||||
import org.springframework.data.r2dbc.repository.R2dbcRepository;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 微信用户Repository
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface WechatUserRepository extends R2dbcRepository<WechatUser, Long> {
|
|
||||||
|
|
||||||
// 通过UnionID查询微信用户
|
|
||||||
Mono<WechatUser> findByUnionId(String unionId);
|
|
||||||
|
|
||||||
// 通过小程序OpenID查询微信用户
|
|
||||||
Mono<WechatUser> findByMiniappOpenid(String miniappOpenid);
|
|
||||||
|
|
||||||
// 通过服务号OpenID查询微信用户
|
|
||||||
Mono<WechatUser> findByMpOpenid(String mpOpenid);
|
|
||||||
|
|
||||||
// 通过会员ID查询微信用户
|
|
||||||
Mono<WechatUser> findByMemberId(Long memberId);
|
|
||||||
}
|
|
||||||
-61
@@ -1,61 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.service;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.member.dto.SearchMemberDto;
|
|
||||||
import cn.novalon.gym.manage.member.dto.UpdateMemberInfoDto;
|
|
||||||
import cn.novalon.gym.manage.member.entity.Member;
|
|
||||||
import cn.novalon.gym.manage.member.es.entity.MemberES;
|
|
||||||
import cn.novalon.gym.manage.member.vo.MemberInfoVO;
|
|
||||||
import reactor.core.publisher.Flux;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 会员服务接口
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
public interface MemberService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取会员信息
|
|
||||||
*
|
|
||||||
* @param memberId 会员ID
|
|
||||||
* @return 会员信息
|
|
||||||
*/
|
|
||||||
Mono<MemberInfoVO> getMemberInfo(Long memberId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 会员更新个人信息
|
|
||||||
*
|
|
||||||
* @param memberId 会员ID
|
|
||||||
* @param updateDto 更新信息DTO
|
|
||||||
* @return 更新后的会员信息
|
|
||||||
*/
|
|
||||||
Mono<MemberInfoVO> updateMemberInfo(Long memberId, UpdateMemberInfoDto updateDto);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 管理端更新会员手机号
|
|
||||||
*
|
|
||||||
* @param memberId 会员ID
|
|
||||||
* @param phone 明文手机号
|
|
||||||
* @return 是否成功
|
|
||||||
*/
|
|
||||||
Mono<Boolean> adminUpdatePhone(Long memberId, String phone);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 管理端查询会员(es查询)
|
|
||||||
*
|
|
||||||
* @param searchMemberDto 会员信息dto
|
|
||||||
* @return 会员信息
|
|
||||||
*/
|
|
||||||
Flux<MemberES> searchMember(SearchMemberDto searchMemberDto);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 管理端查询所有会员
|
|
||||||
*
|
|
||||||
* @param pageNum 页码
|
|
||||||
* @param pageSize 页大小
|
|
||||||
* @return 所有会员信息
|
|
||||||
*/
|
|
||||||
Flux<Member> findAll(Integer pageNum, Integer pageSize);
|
|
||||||
}
|
|
||||||
-48
@@ -1,48 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.service;
|
|
||||||
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 微信API服务接口
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
public interface WechatApiService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 小程序- 通过code获取session_key/openid
|
|
||||||
*
|
|
||||||
* @param code 小程序登录的code
|
|
||||||
* @return Mono<Map<String, String>> session_keyopenidunionid
|
|
||||||
*/
|
|
||||||
Mono<Map<String, String>> jsCode2Session(String code);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取手机号- 通过code获取手机号
|
|
||||||
*
|
|
||||||
* @param code 小程序登录的code
|
|
||||||
* @return Mono<String> ܺ手机号
|
|
||||||
*/
|
|
||||||
Mono<String> getPhoneNumber(String code);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取Access Token
|
|
||||||
*
|
|
||||||
* @param appType 应用类型miniapp-小程序mp
|
|
||||||
* @return Mono<String> access_token
|
|
||||||
*/
|
|
||||||
Mono<String> getAccessToken(String appType);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证签名
|
|
||||||
*
|
|
||||||
* @param signature 微信签名
|
|
||||||
* @param timestamp 创建时间
|
|
||||||
* @param nonce 随机字符串
|
|
||||||
* @return boolean 签名是否有效
|
|
||||||
*/
|
|
||||||
boolean checkSignature(String signature, String timestamp, String nonce);
|
|
||||||
}
|
|
||||||
-31
@@ -1,31 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.service;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.member.dto.WechatLoginDto;
|
|
||||||
import cn.novalon.gym.manage.member.vo.WechatLoginVO;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 微信授权服务接口
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
public interface WechatAuthService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 小程序
|
|
||||||
*
|
|
||||||
* @param request 小程序登录请求
|
|
||||||
* @return 小程序登录响应
|
|
||||||
*/
|
|
||||||
Mono<WechatLoginVO> miniappLogin(WechatLoginDto request);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 手机号
|
|
||||||
*
|
|
||||||
* @param memberId 会员ID
|
|
||||||
* @param code 微信手机号code
|
|
||||||
* @return 是否绑定成功
|
|
||||||
*/
|
|
||||||
Mono<Boolean> bindPhone(Long memberId, String code);
|
|
||||||
}
|
|
||||||
-54
@@ -1,54 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.service;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.member.vo.WechatUserInfoVO;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 微信公众号服务接口
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
public interface WechatOfficialService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理订阅事件
|
|
||||||
*
|
|
||||||
* @param openId OpenID
|
|
||||||
* @return Mono<Void>
|
|
||||||
*/
|
|
||||||
Mono<Void> handleSubscribeEvent(String openId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理取消订阅事件
|
|
||||||
*
|
|
||||||
* @param openId OpenID
|
|
||||||
* @return Mono<Void>
|
|
||||||
*/
|
|
||||||
Mono<Void> handleUnsubscribeEvent(String openId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取微信用户信息
|
|
||||||
*
|
|
||||||
* @param openId OpenID
|
|
||||||
* @return Mono<WechatUserInfoVO> 用户信息
|
|
||||||
*/
|
|
||||||
Mono<WechatUserInfoVO> getUserInfo(String openId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过 UnionID 关联小程序用户
|
|
||||||
*
|
|
||||||
* @param unionId 微信 UnionID
|
|
||||||
* @param officialOpenId OpenID
|
|
||||||
* @return Mono<Boolean> 是否关联成功
|
|
||||||
*/
|
|
||||||
Mono<Boolean> linkByUnionId(String unionId, String officialOpenId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询会员订阅状态
|
|
||||||
*
|
|
||||||
* @param memberId 会员ID
|
|
||||||
* @return Mono<Boolean> true=已订阅false=未订阅
|
|
||||||
*/
|
|
||||||
Mono<Boolean> checkSubscribeStatus(Long memberId);
|
|
||||||
}
|
|
||||||
-208
@@ -1,208 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.service.impl;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.common.exception.ConflictException;
|
|
||||||
import cn.novalon.gym.manage.common.exception.ErrorCode;
|
|
||||||
import cn.novalon.gym.manage.common.exception.NotFoundException;
|
|
||||||
import cn.novalon.gym.manage.common.exception.SystemException;
|
|
||||||
import cn.novalon.gym.manage.member.config.WechatProperties;
|
|
||||||
import cn.novalon.gym.manage.member.dto.SearchMemberDto;
|
|
||||||
import cn.novalon.gym.manage.member.dto.UpdateMemberInfoDto;
|
|
||||||
import cn.novalon.gym.manage.member.entity.Member;
|
|
||||||
import cn.novalon.gym.manage.member.es.entity.MemberES;
|
|
||||||
import cn.novalon.gym.manage.member.es.repository.MemberESRepository;
|
|
||||||
import cn.novalon.gym.manage.member.repository.IMemberRepository;
|
|
||||||
import cn.novalon.gym.manage.member.service.MemberService;
|
|
||||||
import cn.novalon.gym.manage.member.util.AesUtil;
|
|
||||||
import cn.novalon.gym.manage.member.util.EsSyncUtils;
|
|
||||||
import cn.novalon.gym.manage.member.vo.MemberInfoVO;
|
|
||||||
import jakarta.annotation.PostConstruct;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.data.domain.PageRequest;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import reactor.core.publisher.Flux;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 会员服务实现
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class MemberServiceImpl implements MemberService {
|
|
||||||
|
|
||||||
private final IMemberRepository memberRepository;
|
|
||||||
private final MemberESRepository memberESRepository;
|
|
||||||
private final EsSyncUtils esSyncUtils;
|
|
||||||
private final WechatProperties wechatProperties;
|
|
||||||
|
|
||||||
private EsSyncUtils.EntitySyncer<Member, MemberES, String> memberSyncer;
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void init() {
|
|
||||||
this.memberSyncer = esSyncUtils.bind(Member.class, MemberES.class, memberESRepository);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<MemberInfoVO> getMemberInfo(Long memberId) {
|
|
||||||
return memberRepository.findById(memberId)
|
|
||||||
.map(this::buildMemberInfoResponse)
|
|
||||||
.switchIfEmpty(Mono.error(() -> {
|
|
||||||
log.error("会员不存在: memberId={}", memberId);
|
|
||||||
throw new NotFoundException(ErrorCode.NOT_FOUND_USER, "会员不存在");
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<MemberInfoVO> updateMemberInfo(Long memberId, UpdateMemberInfoDto updateDto) {
|
|
||||||
log.info("会员更新个人信息, memberId: {}", memberId);
|
|
||||||
|
|
||||||
return memberRepository.findById(memberId)
|
|
||||||
.flatMap(member -> {
|
|
||||||
if (updateDto.getNickname() != null) {
|
|
||||||
member.setNickname(updateDto.getNickname());
|
|
||||||
}
|
|
||||||
if (updateDto.getGender() != null) {
|
|
||||||
member.setGender(updateDto.getGender());
|
|
||||||
}
|
|
||||||
if (updateDto.getBirthday() != null) {
|
|
||||||
member.setBirthday(updateDto.getBirthday());
|
|
||||||
}
|
|
||||||
if (updateDto.getAvatar() != null) {
|
|
||||||
member.setAvatar(updateDto.getAvatar());
|
|
||||||
}
|
|
||||||
if (updateDto.getAddress() != null) {
|
|
||||||
member.setAddress(updateDto.getAddress());
|
|
||||||
}
|
|
||||||
|
|
||||||
return memberRepository.save(member);
|
|
||||||
})
|
|
||||||
.doOnSuccess(memberSyncer::sync)
|
|
||||||
.map(savedMember -> {
|
|
||||||
log.info("会员信息更新成功, memberId: {}", savedMember.getId());
|
|
||||||
return buildMemberInfoResponse(savedMember);
|
|
||||||
})
|
|
||||||
.switchIfEmpty(Mono.error(() -> {
|
|
||||||
log.error("会员不存在: memberId={}", memberId);
|
|
||||||
throw new NotFoundException(ErrorCode.NOT_FOUND_USER, "会员不存在");
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
private MemberInfoVO buildMemberInfoResponse(Member member) {
|
|
||||||
String phone = member.getPhone();
|
|
||||||
String maskedPhone = phone != null ? phone.replace(phone.substring(3, 7), "****") : null;
|
|
||||||
|
|
||||||
return MemberInfoVO.builder()
|
|
||||||
.id(member.getId())
|
|
||||||
.nickname(member.getNickname())
|
|
||||||
.phone(maskedPhone)
|
|
||||||
.gender(member.getGender())
|
|
||||||
.birthday(member.getBirthday())
|
|
||||||
.avatar(member.getAvatar())
|
|
||||||
.hasPhone(phone != null)
|
|
||||||
.isSubscribed(member.getSubscribed() != null && member.getSubscribed())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<Boolean> adminUpdatePhone(Long memberId, String phone) {
|
|
||||||
log.info("管理端录入手机号, memberId: {}, phone: {}", memberId, phone);
|
|
||||||
|
|
||||||
String encryptedPhone;
|
|
||||||
try {
|
|
||||||
String secretKey = wechatProperties.getPhoneEncryption().getSecretKey();
|
|
||||||
String iv = wechatProperties.getPhoneEncryption().getIv();
|
|
||||||
encryptedPhone = AesUtil.encrypt(phone, secretKey, iv);
|
|
||||||
log.info("手机号加密成功");
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("手机号加密失败", e);
|
|
||||||
throw new SystemException(ErrorCode.SYSTEM_INTERNAL_ERROR, "手机号加密失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return memberRepository.findByPhone(encryptedPhone)
|
|
||||||
.<Boolean>flatMap(existingMember -> {
|
|
||||||
if (existingMember.getId().equals(memberId)) {
|
|
||||||
log.warn("手机号已是当前用户的: memberId={}", memberId);
|
|
||||||
throw new ConflictException(ErrorCode.CONFLICT_DUPLICATE_USER, "重复绑定");
|
|
||||||
} else {
|
|
||||||
log.warn("手机号已被其他用户绑定: memberId={}, existingMemberId={}",
|
|
||||||
memberId, existingMember.getId());
|
|
||||||
throw new ConflictException(ErrorCode.CONFLICT_DUPLICATE_USER, "该手机号已被其他会员绑定");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.switchIfEmpty(Mono.defer(() -> {
|
|
||||||
log.info("手机号未被占用,可以绑定");
|
|
||||||
return updateMemberPhone(memberId, encryptedPhone);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Flux<MemberES> searchMember(SearchMemberDto searchMemberDto) {
|
|
||||||
log.info("搜索会员, searchValue: {}, filter: {}, pageNum: {}, pageSize: {}",
|
|
||||||
searchMemberDto.getSearchValue(),
|
|
||||||
searchMemberDto.getFilter(),
|
|
||||||
searchMemberDto.getPageNum(),
|
|
||||||
searchMemberDto.getPageSize());
|
|
||||||
|
|
||||||
String searchValue = searchMemberDto.getSearchValue();
|
|
||||||
|
|
||||||
if(searchValue != null && searchValue.matches("^1[3-9]\\d{9}$")){
|
|
||||||
log.debug("搜索值为手机号格式,进行加密处理");
|
|
||||||
String secretKey = wechatProperties.getPhoneEncryption().getSecretKey();
|
|
||||||
String iv = wechatProperties.getPhoneEncryption().getIv();
|
|
||||||
searchValue = AesUtil.encrypt(searchValue,secretKey,iv);
|
|
||||||
}
|
|
||||||
|
|
||||||
Pageable pageable = PageRequest.of(
|
|
||||||
searchMemberDto.getPageNum() - 1,
|
|
||||||
searchMemberDto.getPageSize(),
|
|
||||||
Sort.by(Sort.Direction.DESC, "update_at")
|
|
||||||
);
|
|
||||||
|
|
||||||
return memberESRepository.findByMemberNoOrPhoneOrNicknameContainingAndGender(
|
|
||||||
searchValue,
|
|
||||||
searchValue,
|
|
||||||
searchValue,
|
|
||||||
searchMemberDto.getFilter() ,
|
|
||||||
pageable
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Flux<Member> findAll(Integer pageNum, Integer pageSize) {
|
|
||||||
log.info("查询所有会员列表, pageNum: {}, pageSize: {}", pageNum, pageSize);
|
|
||||||
|
|
||||||
Pageable pageable = PageRequest.of(
|
|
||||||
pageNum - 1,
|
|
||||||
pageSize
|
|
||||||
);
|
|
||||||
|
|
||||||
return memberRepository.findAllBy(pageable);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Mono<Boolean> updateMemberPhone(Long memberId, String encryptedPhone) {
|
|
||||||
return memberRepository.findById(memberId)
|
|
||||||
.flatMap(member -> {
|
|
||||||
member.setPhone(encryptedPhone);
|
|
||||||
member.setLastLoginAt(LocalDateTime.now());
|
|
||||||
|
|
||||||
return memberRepository.save(member)
|
|
||||||
.doOnSuccess(memberSyncer::sync)
|
|
||||||
.map(savedMember -> {
|
|
||||||
log.info("手机号录入成功, memberId: {}", savedMember.getId());
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.switchIfEmpty(Mono.error(() -> {
|
|
||||||
log.error("会员不存在: memberId={}", memberId);
|
|
||||||
throw new NotFoundException(ErrorCode.NOT_FOUND_USER, "会员不存在");
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-221
@@ -1,221 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.service.impl;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.common.exception.ErrorCode;
|
|
||||||
import cn.novalon.gym.manage.common.exception.SystemException;
|
|
||||||
import cn.novalon.gym.manage.member.config.WechatProperties;
|
|
||||||
import cn.novalon.gym.manage.member.service.WechatApiService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 微信API服务实现
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class WechatApiServiceImpl implements WechatApiService {
|
|
||||||
|
|
||||||
private final WechatProperties wechatProperties;
|
|
||||||
|
|
||||||
private final WebClient webClient = WebClient.builder()
|
|
||||||
.baseUrl("https://api.weixin.qq.com")
|
|
||||||
.codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(10 * 1024 * 1024))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<Map<String, String>> jsCode2Session(String code) {
|
|
||||||
log.info("微信jsCode2Session API");
|
|
||||||
log.info("信息 - AppID: {}, AppSecret {}",
|
|
||||||
wechatProperties.getMiniapp().getAppId(),
|
|
||||||
wechatProperties.getMiniapp().getAppSecret() != null ?
|
|
||||||
wechatProperties.getMiniapp().getAppSecret().substring(0, Math.min(4, wechatProperties.getMiniapp().getAppSecret().length())) + "***" : "null");
|
|
||||||
log.info(" - code: {}", code);
|
|
||||||
|
|
||||||
return webClient.get()
|
|
||||||
.uri(uriBuilder -> uriBuilder
|
|
||||||
.path("/sns/jscode2session")
|
|
||||||
.queryParam("appid", wechatProperties.getMiniapp().getAppId())
|
|
||||||
.queryParam("secret", wechatProperties.getMiniapp().getAppSecret())
|
|
||||||
.queryParam("js_code", code)
|
|
||||||
.queryParam("grant_type", "authorization_code")
|
|
||||||
.build())
|
|
||||||
.retrieve()
|
|
||||||
.bodyToMono(String.class)
|
|
||||||
.map(responseBody -> {
|
|
||||||
log.info("微信API响应: {}", responseBody);
|
|
||||||
|
|
||||||
Map<String, Object> response;
|
|
||||||
try {
|
|
||||||
com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();
|
|
||||||
response = mapper.readValue(responseBody, Map.class);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("微信API响应失败", e);
|
|
||||||
throw new SystemException(ErrorCode.SYSTEM_INTERNAL_ERROR, "微信API响应失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, String> result = new HashMap<>();
|
|
||||||
|
|
||||||
if (response.containsKey("errcode")) {
|
|
||||||
Integer errcode = (Integer) response.get("errcode");
|
|
||||||
String errmsg = (String) response.get("errmsg");
|
|
||||||
log.error("微信API失败, errcode: {}, errmsg: {}", errcode, errmsg);
|
|
||||||
throw new SystemException(ErrorCode.SYSTEM_INTERNAL_ERROR, "微信API失败 [" + errcode + "]: " + errmsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
result.put("session_key", (String) response.get("session_key"));
|
|
||||||
result.put("openid", (String) response.get("openid"));
|
|
||||||
result.put("unionid", (String) response.get("unionid"));
|
|
||||||
|
|
||||||
log.info("微信API响应成功, openid: {}, unionid: {}",
|
|
||||||
result.get("openid"), result.get("unionid"));
|
|
||||||
return result;
|
|
||||||
})
|
|
||||||
.onErrorResume(e -> {
|
|
||||||
log.error("微信API响应异常 - URL: https://api.weixin.qq.com/sns/jscode2session");
|
|
||||||
log.error("异常: {}", e.getClass().getName());
|
|
||||||
log.error("异常信息: {}", e.getMessage());
|
|
||||||
if (e.getCause() != null) {
|
|
||||||
log.error("异常原因: {}", e.getCause().getMessage());
|
|
||||||
}
|
|
||||||
if (e instanceof SystemException) {
|
|
||||||
return Mono.error(e);
|
|
||||||
}
|
|
||||||
throw new SystemException(ErrorCode.SYSTEM_INTERNAL_ERROR, "微信API响应异常 " + e.getMessage());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<String> getPhoneNumber(String code) {
|
|
||||||
log.debug("微信getPhoneNumber API, code: {}", code);
|
|
||||||
|
|
||||||
return getAccessToken("miniapp")
|
|
||||||
.flatMap(accessToken -> {
|
|
||||||
|
|
||||||
Map<String, String> requestBody = new HashMap<>();
|
|
||||||
requestBody.put("code", code);
|
|
||||||
|
|
||||||
return webClient.post()
|
|
||||||
.uri(uriBuilder -> uriBuilder
|
|
||||||
.path("/wxa/business/getuserphonenumber")
|
|
||||||
.queryParam("access_token", accessToken)
|
|
||||||
.build())
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.bodyValue(requestBody)
|
|
||||||
.retrieve()
|
|
||||||
.bodyToMono(Map.class)
|
|
||||||
.map(response -> {
|
|
||||||
if (response.containsKey("errcode") &&
|
|
||||||
(Integer) response.get("errcode") == 0) {
|
|
||||||
|
|
||||||
Map<String, Object> phoneInfo =
|
|
||||||
(Map<String, Object>) response.get("phone_info");
|
|
||||||
String phoneNumber = (String) phoneInfo.get("purePhoneNumber");
|
|
||||||
|
|
||||||
log.info("获取手机号成功{}", phoneNumber);
|
|
||||||
return phoneNumber;
|
|
||||||
} else {
|
|
||||||
String errmsg = (String) response.get("errmsg");
|
|
||||||
log.error("获取手机号失败 {}", errmsg);
|
|
||||||
throw new SystemException(ErrorCode.SYSTEM_INTERNAL_ERROR, "获取手机号失败 " + errmsg);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.onErrorResume(e -> {
|
|
||||||
log.error("获取手机号失败", e);
|
|
||||||
if (e instanceof SystemException) {
|
|
||||||
return Mono.error(e);
|
|
||||||
}
|
|
||||||
throw new SystemException(ErrorCode.SYSTEM_INTERNAL_ERROR, "获取手机号失败 " + e.getMessage());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<String> getAccessToken(String appType) {
|
|
||||||
log.debug("获取access_token, appType: {}", appType);
|
|
||||||
|
|
||||||
String appId, appSecret;
|
|
||||||
if ("miniapp".equals(appType)) {
|
|
||||||
appId = wechatProperties.getMiniapp().getAppId();
|
|
||||||
appSecret = wechatProperties.getMiniapp().getAppSecret();
|
|
||||||
} else {
|
|
||||||
appId = wechatProperties.getMp().getAppId();
|
|
||||||
appSecret = wechatProperties.getMp().getAppSecret();
|
|
||||||
}
|
|
||||||
|
|
||||||
return webClient.get()
|
|
||||||
.uri(uriBuilder -> uriBuilder
|
|
||||||
.path("/cgi-bin/token")
|
|
||||||
.queryParam("grant_type", "client_credential")
|
|
||||||
.queryParam("appid", appId)
|
|
||||||
.queryParam("secret", appSecret)
|
|
||||||
.build())
|
|
||||||
.retrieve()
|
|
||||||
.bodyToMono(Map.class)
|
|
||||||
.map(response -> {
|
|
||||||
if (response.containsKey("access_token")) {
|
|
||||||
String accessToken = (String) response.get("access_token");
|
|
||||||
Integer expiresIn = (Integer) response.get("expires_in");
|
|
||||||
log.info("获取access_token成功, expires_in: {}s", expiresIn);
|
|
||||||
return accessToken;
|
|
||||||
} else {
|
|
||||||
String errmsg = (String) response.get("errmsg");
|
|
||||||
log.error("获取access_token失败: {}", errmsg);
|
|
||||||
throw new SystemException(ErrorCode.SYSTEM_INTERNAL_ERROR, "获取access_token失败: " + errmsg);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean checkSignature(String signature, String timestamp, String nonce) {
|
|
||||||
log.debug("验证微信消息签名, signature: {}, timestamp: {}, nonce: {}",
|
|
||||||
signature, timestamp, nonce);
|
|
||||||
|
|
||||||
try {
|
|
||||||
String token = wechatProperties.getMp().getToken();
|
|
||||||
|
|
||||||
String[] arr = new String[]{token, timestamp, nonce};
|
|
||||||
Arrays.sort(arr);
|
|
||||||
|
|
||||||
StringBuilder content = new StringBuilder();
|
|
||||||
for (String s : arr) {
|
|
||||||
content.append(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
|
||||||
byte[] digest = md.digest(content.toString().getBytes(StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
StringBuilder hexString = new StringBuilder();
|
|
||||||
for (byte b : digest) {
|
|
||||||
String hex = Integer.toHexString(0xff & b);
|
|
||||||
if (hex.length() == 1) {
|
|
||||||
hexString.append('0');
|
|
||||||
}
|
|
||||||
hexString.append(hex);
|
|
||||||
}
|
|
||||||
|
|
||||||
String calculatedSignature = hexString.toString();
|
|
||||||
|
|
||||||
boolean isValid = calculatedSignature.equals(signature);
|
|
||||||
log.debug("验证微信消息签名结果: {}", isValid ? "通过" : "失败");
|
|
||||||
|
|
||||||
return isValid;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("验证微信消息签名异常", e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-300
@@ -1,300 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.service.impl;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.common.exception.ConflictException;
|
|
||||||
import cn.novalon.gym.manage.common.exception.ErrorCode;
|
|
||||||
import cn.novalon.gym.manage.common.exception.NotFoundException;
|
|
||||||
import cn.novalon.gym.manage.common.exception.SystemException;
|
|
||||||
import cn.novalon.gym.manage.member.config.WechatProperties;
|
|
||||||
import cn.novalon.gym.manage.member.dto.WechatLoginDto;
|
|
||||||
import cn.novalon.gym.manage.member.entity.Member;
|
|
||||||
import cn.novalon.gym.manage.member.es.entity.MemberES;
|
|
||||||
import cn.novalon.gym.manage.member.es.repository.MemberESRepository;
|
|
||||||
import cn.novalon.gym.manage.member.repository.IMemberRepository;
|
|
||||||
import cn.novalon.gym.manage.member.service.WechatApiService;
|
|
||||||
import cn.novalon.gym.manage.member.service.WechatAuthService;
|
|
||||||
import cn.novalon.gym.manage.member.util.AesUtil;
|
|
||||||
import cn.novalon.gym.manage.member.util.EsSyncUtils;
|
|
||||||
import cn.novalon.gym.manage.member.util.MemberNoGenerator;
|
|
||||||
import cn.novalon.gym.manage.member.util.WechatPhoneUtil;
|
|
||||||
import cn.novalon.gym.manage.member.vo.WechatLoginVO;
|
|
||||||
import cn.novalon.gym.manage.sys.security.JwtTokenProvider;
|
|
||||||
import jakarta.annotation.PostConstruct;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 微信认证服务实现
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class WechatAuthServiceImpl implements WechatAuthService {
|
|
||||||
|
|
||||||
private final WechatApiService wechatApiService;
|
|
||||||
private final IMemberRepository memberRepository;
|
|
||||||
private final WechatProperties wechatProperties;
|
|
||||||
private final WechatPhoneUtil wechatPhoneUtil;
|
|
||||||
private final MemberESRepository memberESRepository;
|
|
||||||
private final EsSyncUtils esSyncUtils;
|
|
||||||
private final JwtTokenProvider jwtTokenProvider;
|
|
||||||
|
|
||||||
private EsSyncUtils.EntitySyncer<Member, MemberES, String> memberSyncer;
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void init() {
|
|
||||||
this.memberSyncer = esSyncUtils.bind(Member.class, MemberES.class, memberESRepository);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<WechatLoginVO> miniappLogin(WechatLoginDto request) {
|
|
||||||
log.info("开始小程序登录");
|
|
||||||
|
|
||||||
return wechatApiService.jsCode2Session(request.getCode())
|
|
||||||
.flatMap(sessionData -> {
|
|
||||||
String openid = sessionData.get("openid");
|
|
||||||
String unionId = sessionData.get("unionid");
|
|
||||||
String sessionKey = sessionData.get("session_key");
|
|
||||||
|
|
||||||
log.info("微信 API 返回: openid={}, unionid={}", openid, unionId);
|
|
||||||
|
|
||||||
if (unionId != null && !unionId.isEmpty()) {
|
|
||||||
return memberRepository.findByUnionId(unionId)
|
|
||||||
.flatMap(member -> {
|
|
||||||
log.info("找到会员, memberId: {}", member.getId());
|
|
||||||
|
|
||||||
if (member.getMiniappOpenId() == null || member.getMiniappOpenId().isEmpty()) {
|
|
||||||
log.info("用户已有 UnionID,补充小程序 OpenID, memberId: {}", member.getId());
|
|
||||||
member.setMiniappOpenId(openid);
|
|
||||||
member.setLastLoginAt(LocalDateTime.now());
|
|
||||||
|
|
||||||
return memberRepository.save(member)
|
|
||||||
.doOnSuccess(memberSyncer::sync)
|
|
||||||
.flatMap(savedMember -> {
|
|
||||||
WechatLoginVO response = buildLoginResponse(savedMember, false, sessionKey);
|
|
||||||
return Mono.just(response);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
log.info("老用户登录,更新最后登录时间, memberId: {}", member.getId());
|
|
||||||
member.setLastLoginAt(LocalDateTime.now());
|
|
||||||
|
|
||||||
return memberRepository.save(member)
|
|
||||||
.doOnSuccess(memberSyncer::sync)
|
|
||||||
.flatMap(savedMember -> {
|
|
||||||
WechatLoginVO response = buildLoginResponse(savedMember, false, sessionKey);
|
|
||||||
return Mono.just(response);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.switchIfEmpty(Mono.defer(() -> {
|
|
||||||
log.info("UnionID 未找到,尝试通过小程序 OpenID 查询, openid: {}", openid);
|
|
||||||
return memberRepository.findByMiniappOpenId(openid)
|
|
||||||
.flatMap(member -> {
|
|
||||||
log.info("找到会员, memberId: {}", member.getId());
|
|
||||||
member.setUnionId(unionId);
|
|
||||||
member.setLastLoginAt(LocalDateTime.now());
|
|
||||||
|
|
||||||
return memberRepository.save(member)
|
|
||||||
.doOnSuccess(memberSyncer::sync)
|
|
||||||
.flatMap(savedMember -> {
|
|
||||||
WechatLoginVO response = buildLoginResponse(savedMember, false, sessionKey);
|
|
||||||
return Mono.just(response);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.switchIfEmpty(Mono.defer(() -> {
|
|
||||||
log.info("OpenID 也未找到,创建新会员(无 UnionID), openid: {}", openid);
|
|
||||||
return createNewMember(unionId, openid, sessionKey, request.getPhoneCode());
|
|
||||||
}));
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
log.warn("微信 API 未返回 UnionID,尝试通过小程序 OpenID 查询, openid: {}", openid);
|
|
||||||
return memberRepository.findByMiniappOpenId(openid)
|
|
||||||
.flatMap(member -> {
|
|
||||||
log.info("找到会员, memberId: {}", member.getId());
|
|
||||||
member.setLastLoginAt(LocalDateTime.now());
|
|
||||||
|
|
||||||
return memberRepository.save(member)
|
|
||||||
.doOnSuccess(memberSyncer::sync)
|
|
||||||
.flatMap(savedMember -> {
|
|
||||||
WechatLoginVO response = buildLoginResponse(savedMember, false, sessionKey);
|
|
||||||
return Mono.just(response);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.switchIfEmpty(Mono.defer(() -> {
|
|
||||||
log.info("OpenID也未找到,创建新会员(无UnionID标识信息)");
|
|
||||||
return createNewMember(unionId, openid, sessionKey, request.getPhoneCode());
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.onErrorResume(e -> {
|
|
||||||
log.error("小程序登录失败", e);
|
|
||||||
if (e instanceof SystemException) {
|
|
||||||
return Mono.error(e);
|
|
||||||
}
|
|
||||||
return Mono.error(new SystemException(ErrorCode.SYSTEM_INTERNAL_ERROR, "登录失败: " + e.getMessage()));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<Boolean> bindPhone(Long memberId, String code) {
|
|
||||||
log.info("开始绑定手机号, memberId: {}", memberId);
|
|
||||||
|
|
||||||
return wechatApiService.getPhoneNumber(code)
|
|
||||||
.flatMap(phoneNumber -> {
|
|
||||||
log.info("获取手机号: {}", phoneNumber);
|
|
||||||
|
|
||||||
String encryptedPhone = encryptPhone(phoneNumber);
|
|
||||||
|
|
||||||
return memberRepository.findByPhone(encryptedPhone)
|
|
||||||
.flatMap(existingMember -> {
|
|
||||||
if (!existingMember.getId().equals(memberId)) {
|
|
||||||
log.warn("手机号已被其他会员绑定, currentMemberId={}, existingMemberId={}", memberId, existingMember.getId());
|
|
||||||
throw new ConflictException(ErrorCode.CONFLICT_DUPLICATE_USER, "手机号已被其他会员绑定");
|
|
||||||
} else {
|
|
||||||
log.info("更新会员手机号, memberId: {}", memberId);
|
|
||||||
return updateMemberPhone(memberId, encryptedPhone);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.switchIfEmpty(Mono.defer(() -> {
|
|
||||||
log.info("该手机号未被使用,直接绑定到当前会员, memberId: {}", memberId);
|
|
||||||
return updateMemberPhone(memberId, encryptedPhone);
|
|
||||||
}));
|
|
||||||
})
|
|
||||||
.onErrorResume(e -> {
|
|
||||||
log.error("绑定手机号失败", e);
|
|
||||||
if (e instanceof SystemException) {
|
|
||||||
return Mono.error(e);
|
|
||||||
}
|
|
||||||
return Mono.error(new SystemException(ErrorCode.SYSTEM_INTERNAL_ERROR, "绑定失败: " + e.getMessage()));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private Mono<Boolean> updateMemberPhone(Long memberId, String encryptedPhone) {
|
|
||||||
return memberRepository.findById(memberId)
|
|
||||||
.flatMap(member -> {
|
|
||||||
member.setPhone(encryptedPhone);
|
|
||||||
member.setLastLoginAt(LocalDateTime.now());
|
|
||||||
return memberRepository.save(member)
|
|
||||||
.doOnSuccess(memberSyncer::sync)
|
|
||||||
.map(savedMember -> {
|
|
||||||
log.info("更新会员手机号成功, memberId: {}", savedMember.getId());
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.switchIfEmpty(Mono.error(() -> {
|
|
||||||
log.error("会员不存在, memberId={}", memberId);
|
|
||||||
throw new NotFoundException(ErrorCode.NOT_FOUND_USER, "会员不存在");
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String encryptPhone(String phoneNumber) {
|
|
||||||
try {
|
|
||||||
String secretKey = wechatProperties.getPhoneEncryption().getSecretKey();
|
|
||||||
String iv = wechatProperties.getPhoneEncryption().getIv();
|
|
||||||
|
|
||||||
String encryptedPhone = AesUtil.encrypt(phoneNumber, secretKey, iv);
|
|
||||||
|
|
||||||
log.debug("手机号加密成功");
|
|
||||||
return encryptedPhone;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("手机号加密失败", e);
|
|
||||||
throw new SystemException(ErrorCode.SYSTEM_INTERNAL_ERROR, "手机号加密失败 " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String decryptPhone(String encryptedPhone) {
|
|
||||||
try {
|
|
||||||
String secretKey = wechatProperties.getPhoneEncryption().getSecretKey();
|
|
||||||
String iv = wechatProperties.getPhoneEncryption().getIv();
|
|
||||||
|
|
||||||
String phoneNumber = AesUtil.decrypt(encryptedPhone, secretKey, iv);
|
|
||||||
|
|
||||||
log.debug("手机号解密成功");
|
|
||||||
return phoneNumber;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("手机号解密失败", e);
|
|
||||||
throw new SystemException(ErrorCode.SYSTEM_INTERNAL_ERROR, "手机号解密失败 " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Mono<WechatLoginVO> createNewMember(String unionId, String openid, String sessionKey, String phoneCode) {
|
|
||||||
log.info("开始创建新会员, unionId: {}, openid: {}", unionId, openid);
|
|
||||||
|
|
||||||
String memberNo = MemberNoGenerator.generate();
|
|
||||||
log.info("生成会员号: {}", memberNo);
|
|
||||||
|
|
||||||
Member member = Member.builder()
|
|
||||||
.memberNo(memberNo)
|
|
||||||
.unionId(unionId)
|
|
||||||
.miniappOpenId(openid)
|
|
||||||
.lastLoginAt(LocalDateTime.now())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
log.info("用户未注册,创建新会员(仅保存标识信息)");
|
|
||||||
|
|
||||||
return memberRepository.save(member)
|
|
||||||
.doOnSuccess(memberSyncer::sync)
|
|
||||||
.flatMap(savedMember -> {
|
|
||||||
log.info("保存 Member 成功, id: {}, memberNo: {}", savedMember.getId(), savedMember.getMemberNo());
|
|
||||||
if (phoneCode != null && !phoneCode.isEmpty()) {
|
|
||||||
log.info("检测到 phoneCode,尝试获取手机号");
|
|
||||||
return wechatPhoneUtil.getPhoneNumber(phoneCode)
|
|
||||||
.flatMap(phoneNumber -> {
|
|
||||||
if (phoneNumber != null && !phoneNumber.isEmpty()) {
|
|
||||||
log.info("获取到手机号: {}", phoneNumber);
|
|
||||||
String encryptedPhone = encryptPhone(phoneNumber);
|
|
||||||
savedMember.setPhone(encryptedPhone);
|
|
||||||
return memberRepository.save(savedMember)
|
|
||||||
.doOnSuccess(memberSyncer::sync)
|
|
||||||
.doOnSuccess(m -> {
|
|
||||||
log.info("新用户手机号绑定成功");
|
|
||||||
})
|
|
||||||
.thenReturn(buildLoginResponse(savedMember, true, sessionKey));
|
|
||||||
} else {
|
|
||||||
log.warn("未获取到手机号");
|
|
||||||
return Mono.just(buildLoginResponse(savedMember, true, sessionKey));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return Mono.just(buildLoginResponse(savedMember, true, sessionKey));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private WechatLoginVO buildLoginResponse(Member member, boolean isNewUser, String sessionKey) {
|
|
||||||
log.debug("构建登录响应, memberId: {}, isNewUser: {}", member.getId(), isNewUser);
|
|
||||||
|
|
||||||
boolean needCompleteInfo = member.getNickname() == null || member.getPhone() == null;
|
|
||||||
if (needCompleteInfo) {
|
|
||||||
log.info("用户需要补全信息: nickname={}, phone={}",
|
|
||||||
member.getNickname() != null ? "已有" : "未设置",
|
|
||||||
member.getPhone() != null ? "已绑定" : "未绑定");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> roles = new ArrayList<>();
|
|
||||||
String accessToken = jwtTokenProvider.generateToken(String.valueOf(member.getId()), member.getId(), roles);
|
|
||||||
|
|
||||||
log.info("JWT Token 生成成功, memberId: {}", member.getId());
|
|
||||||
|
|
||||||
int expiresIn = 86400;
|
|
||||||
|
|
||||||
return WechatLoginVO.builder()
|
|
||||||
.memberId(member.getId())
|
|
||||||
.accessToken(accessToken)
|
|
||||||
.refreshToken(accessToken)
|
|
||||||
.expiresIn(expiresIn)
|
|
||||||
.isNewUser(isNewUser)
|
|
||||||
.needCompleteInfo(needCompleteInfo)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-338
@@ -1,338 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.service.impl;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.member.config.WechatProperties;
|
|
||||||
import cn.novalon.gym.manage.member.entity.Member;
|
|
||||||
import cn.novalon.gym.manage.member.es.entity.MemberES;
|
|
||||||
import cn.novalon.gym.manage.member.es.repository.MemberESRepository;
|
|
||||||
import cn.novalon.gym.manage.member.repository.IMemberRepository;
|
|
||||||
import cn.novalon.gym.manage.member.service.WechatOfficialService;
|
|
||||||
import cn.novalon.gym.manage.member.util.EsSyncUtils;
|
|
||||||
import cn.novalon.gym.manage.member.vo.WechatUserInfoVO;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import jakarta.annotation.PostConstruct;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 微信服务号服务实现类
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class WechatOfficialServiceImpl implements WechatOfficialService {
|
|
||||||
|
|
||||||
private final IMemberRepository memberRepository;
|
|
||||||
private final WechatProperties wechatProperties;
|
|
||||||
private final WebClient webClient;
|
|
||||||
private final MemberESRepository memberESRepository;
|
|
||||||
private final ObjectMapper objectMapper = new ObjectMapper()
|
|
||||||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
||||||
|
|
||||||
private final EsSyncUtils esSyncUtils;
|
|
||||||
|
|
||||||
private EsSyncUtils.EntitySyncer<Member, MemberES, String> memberSyncer;
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void init() {
|
|
||||||
this.memberSyncer = esSyncUtils.bind(Member.class, MemberES.class, memberESRepository);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理关注事件
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Mono<Void> handleSubscribeEvent(String openId) {
|
|
||||||
log.info("处理关注事件, openId: {}", openId);
|
|
||||||
|
|
||||||
return getUserInfo(openId)
|
|
||||||
.flatMap(userInfo -> {
|
|
||||||
String unionId = userInfo.getUnionid();
|
|
||||||
log.info("获取到用户信息 unionId: {}, nickname: {}", unionId, userInfo.getNickname());
|
|
||||||
|
|
||||||
if (unionId != null && !unionId.isEmpty()) {
|
|
||||||
return memberRepository.findByUnionId(unionId)
|
|
||||||
.flatMap(existingMember -> {
|
|
||||||
log.info("通过UnionID找到已有会员, memberId: {}", existingMember.getId());
|
|
||||||
|
|
||||||
if (existingMember.getOfficialOpenId() == null || existingMember.getOfficialOpenId().isEmpty()) {
|
|
||||||
log.info("用户先使用小程序,更新服务号OpenID: {}", openId);
|
|
||||||
existingMember.setSubscribed(true);
|
|
||||||
existingMember.setLastLoginAt(LocalDateTime.now());
|
|
||||||
existingMember.setOfficialOpenId(openId);
|
|
||||||
|
|
||||||
if (existingMember.getNickname() == null || existingMember.getNickname().isEmpty()) {
|
|
||||||
existingMember.setNickname(userInfo.getNickname());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (existingMember.getAvatar() == null || existingMember.getAvatar().isEmpty()) {
|
|
||||||
existingMember.setAvatar(userInfo.getHeadimgurl());
|
|
||||||
}
|
|
||||||
|
|
||||||
return memberRepository.save(existingMember)
|
|
||||||
.doOnSuccess(memberSyncer::sync)
|
|
||||||
.then(sendWelcomeMessage(openId));
|
|
||||||
} else {
|
|
||||||
log.info("老用户关注服务号: memberId={}", existingMember.getId());
|
|
||||||
existingMember.setSubscribed(true);
|
|
||||||
existingMember.setLastLoginAt(LocalDateTime.now());
|
|
||||||
|
|
||||||
return memberRepository.save(existingMember)
|
|
||||||
.doOnSuccess(memberSyncer::sync)
|
|
||||||
.then(sendWelcomeMessage(openId));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.switchIfEmpty(Mono.defer(() -> {
|
|
||||||
log.info("UnionID未找到,降级到服务号OpenID查询: {}", openId);
|
|
||||||
return memberRepository.findByOfficialOpenId(openId)
|
|
||||||
.flatMap(existingMember -> {
|
|
||||||
log.info("通过服务号OpenID找到已有会员,更新UnionID, memberId: {}", existingMember.getId());
|
|
||||||
existingMember.setUnionId(unionId);
|
|
||||||
existingMember.setSubscribed(true);
|
|
||||||
existingMember.setLastLoginAt(LocalDateTime.now());
|
|
||||||
|
|
||||||
return memberRepository.save(existingMember)
|
|
||||||
.doOnSuccess(memberSyncer::sync)
|
|
||||||
.then(sendWelcomeMessage(openId));
|
|
||||||
})
|
|
||||||
.switchIfEmpty(Mono.defer(() -> {
|
|
||||||
log.info("OpenID也未找到,创建新用户");
|
|
||||||
return createNewMemberFromOfficial(unionId, openId)
|
|
||||||
.then(sendWelcomeMessage(openId));
|
|
||||||
}));
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
log.warn("用户没有UnionID,尝试通过服务号OpenID查询");
|
|
||||||
return memberRepository.findByOfficialOpenId(openId)
|
|
||||||
.flatMap(existingMember -> {
|
|
||||||
log.info("通过服务号OpenID找到已有会员, memberId: {}", existingMember.getId());
|
|
||||||
existingMember.setSubscribed(true);
|
|
||||||
existingMember.setLastLoginAt(LocalDateTime.now());
|
|
||||||
|
|
||||||
return memberRepository.save(existingMember)
|
|
||||||
.doOnSuccess(memberSyncer::sync)
|
|
||||||
.then(sendWelcomeMessage(openId));
|
|
||||||
})
|
|
||||||
.switchIfEmpty(Mono.defer(() -> {
|
|
||||||
log.info("OpenID也未找到,创建新会员(无UnionID)");
|
|
||||||
return createNewMemberFromOfficial(unionId, openId)
|
|
||||||
.then(sendWelcomeMessage(openId));
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理取消关注事件
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Mono<Void> handleUnsubscribeEvent(String openId) {
|
|
||||||
log.info("处理取消关注事件, openId: {}", openId);
|
|
||||||
|
|
||||||
return memberRepository.findByOfficialOpenId(openId)
|
|
||||||
.flatMap(member -> {
|
|
||||||
log.info("找到会员,更新为未关注状态, memberId: {}", member.getId());
|
|
||||||
member.setSubscribed(false);
|
|
||||||
member.setLastLoginAt(LocalDateTime.now());
|
|
||||||
return memberRepository.save(member)
|
|
||||||
.doOnSuccess(memberSyncer::sync)
|
|
||||||
.then();
|
|
||||||
})
|
|
||||||
.then()
|
|
||||||
.switchIfEmpty(Mono.defer(() -> {
|
|
||||||
log.warn("未找到对应的会员记录, officialOpenId: {}", openId);
|
|
||||||
return Mono.empty();
|
|
||||||
}))
|
|
||||||
.onErrorResume(e -> {
|
|
||||||
log.error("处理取消关注事件失败", e);
|
|
||||||
return Mono.empty();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取微信用户信息
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Mono<WechatUserInfoVO> getUserInfo(String openId) {
|
|
||||||
log.debug("获取微信用户信息, openId: {}", openId);
|
|
||||||
|
|
||||||
// 获取AccessToken
|
|
||||||
return getAccessToken()
|
|
||||||
.flatMap(accessToken -> {
|
|
||||||
String url = "https://api.weixin.qq.com/cgi-bin/user/info"
|
|
||||||
+ "?access_token=" + accessToken
|
|
||||||
+ "&openid=" + openId
|
|
||||||
+ "&lang=zh_CN";
|
|
||||||
|
|
||||||
return webClient.get()
|
|
||||||
.uri(url)
|
|
||||||
.accept(MediaType.APPLICATION_JSON)
|
|
||||||
.retrieve()
|
|
||||||
.bodyToMono(String.class)
|
|
||||||
.map(responseJson -> {
|
|
||||||
log.info("微信API原始响应: {}", responseJson);
|
|
||||||
try {
|
|
||||||
WechatUserInfoVO userInfo = objectMapper.readValue(responseJson, WechatUserInfoVO.class);
|
|
||||||
log.info("解析后的用户信息 - unionId: {}, nickname: {}, openid: {}",
|
|
||||||
userInfo.getUnionid(), userInfo.getNickname(), userInfo.getOpenid());
|
|
||||||
return userInfo;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("解析微信用户信息失败", e);
|
|
||||||
throw new RuntimeException("解析微信用户信息失败", e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过 UnionID 关联小程序用户和服务号用户
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Mono<Boolean> linkByUnionId(String unionId, String officialOpenId) {
|
|
||||||
log.debug("关联小程序用户和服务号用户 unionId: {}, officialOpenId: {}", unionId, officialOpenId);
|
|
||||||
|
|
||||||
return memberRepository.findByUnionId(unionId)
|
|
||||||
.flatMap(member -> {
|
|
||||||
member.setSubscribed(true);
|
|
||||||
member.setLastLoginAt(LocalDateTime.now());
|
|
||||||
|
|
||||||
if (officialOpenId != null && !officialOpenId.isEmpty()) {
|
|
||||||
member.setOfficialOpenId(officialOpenId);
|
|
||||||
}
|
|
||||||
return memberRepository.save(member)
|
|
||||||
.doOnSuccess(memberSyncer::sync)
|
|
||||||
.map(savedMember -> {
|
|
||||||
log.info("关联成功, memberId: {}", savedMember.getId());
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.switchIfEmpty(Mono.defer(() -> {
|
|
||||||
log.warn("未找到对应的会员记录, unionId: {}", unionId);
|
|
||||||
return Mono.just(false);
|
|
||||||
}))
|
|
||||||
.onErrorResume(e -> {
|
|
||||||
log.error("关联失败", e);
|
|
||||||
return Mono.just(false);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询用户关注状态
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Mono<Boolean> checkSubscribeStatus(Long memberId) {
|
|
||||||
log.info("查询用户关注状态, memberId: {}", memberId);
|
|
||||||
|
|
||||||
return memberRepository.findById(memberId)
|
|
||||||
.map(member -> {
|
|
||||||
Boolean subscribed = member.getSubscribed();
|
|
||||||
boolean result = subscribed != null && subscribed;
|
|
||||||
log.info("查询用户关注状态结果, memberId: {}, subscribed: {}", memberId, result);
|
|
||||||
return result;
|
|
||||||
})
|
|
||||||
.defaultIfEmpty(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从服务号用户信息创建新会员
|
|
||||||
*/
|
|
||||||
private Mono<Void> createNewMemberFromOfficial(String unionId, String openId) {
|
|
||||||
Member member = Member.builder()
|
|
||||||
.unionId(unionId)
|
|
||||||
.officialOpenId(openId)
|
|
||||||
.subscribed(true)
|
|
||||||
.lastLoginAt(LocalDateTime.now())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
log.info("新用户关注服务号,仅保存标识信息(UnionID和OpenID)");
|
|
||||||
return memberRepository.save(member)
|
|
||||||
.doOnSuccess(memberSyncer::sync)
|
|
||||||
.doOnSuccess(savedMember -> {
|
|
||||||
log.info("从服务号创建新会员成功, memberId: {}", savedMember.getId());
|
|
||||||
})
|
|
||||||
.then();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取微信AccessToken
|
|
||||||
*
|
|
||||||
* TODO: 应该使用缓存,避免频繁请求
|
|
||||||
*/
|
|
||||||
private Mono<String> getAccessToken() {
|
|
||||||
String appId = wechatProperties.getMp().getAppId();
|
|
||||||
String appSecret = wechatProperties.getMp().getAppSecret();
|
|
||||||
|
|
||||||
String url = "https://api.weixin.qq.com/cgi-bin/token"
|
|
||||||
+ "?grant_type=client_credential"
|
|
||||||
+ "&appid=" + appId
|
|
||||||
+ "&secret=" + appSecret;
|
|
||||||
|
|
||||||
return webClient.get()
|
|
||||||
.uri(url)
|
|
||||||
.accept(MediaType.APPLICATION_JSON)
|
|
||||||
.retrieve()
|
|
||||||
.bodyToMono(Map.class)
|
|
||||||
.map(response -> {
|
|
||||||
if (response.containsKey("errcode")) {
|
|
||||||
throw new RuntimeException("获取AccessToken失败: " + response.get("errmsg"));
|
|
||||||
}
|
|
||||||
return (String) response.get("access_token");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送欢迎消息给用户
|
|
||||||
*/
|
|
||||||
private Mono<Void> sendWelcomeMessage(String openId) {
|
|
||||||
log.info("发送欢迎消息给 openId: {}", openId);
|
|
||||||
|
|
||||||
// 真正调用微信 API 发送消息(测试模式和生产模式都执行)
|
|
||||||
return getAccessToken()
|
|
||||||
.flatMap(accessToken -> {
|
|
||||||
String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send"
|
|
||||||
+ "?access_token=" + accessToken;
|
|
||||||
|
|
||||||
// 构建客服消息�?
|
|
||||||
Map<String, Object> messageBody = new HashMap<>();
|
|
||||||
messageBody.put("touser", openId);
|
|
||||||
messageBody.put("msgtype", "text");
|
|
||||||
|
|
||||||
Map<String, String> text = new HashMap<>();
|
|
||||||
text.put("content", "欢迎使用");
|
|
||||||
messageBody.put("text", text);
|
|
||||||
|
|
||||||
return webClient.post()
|
|
||||||
.uri(url)
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.bodyValue(messageBody)
|
|
||||||
.retrieve()
|
|
||||||
.bodyToMono(Map.class)
|
|
||||||
.doOnSuccess(response -> {
|
|
||||||
if (response.containsKey("errcode") && !"0".equals(String.valueOf(response.get("errcode")))) {
|
|
||||||
log.error("发送欢迎消息失败: {}", response.get("errmsg"));
|
|
||||||
} else {
|
|
||||||
log.info("欢迎消息发送成功, openId: {}", openId);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.doOnError(error -> log.error("发送欢迎消息异常", error))
|
|
||||||
.then();
|
|
||||||
})
|
|
||||||
.onErrorResume(e -> {
|
|
||||||
log.error("发送欢迎消息失败, openId: {}", openId, e);
|
|
||||||
return Mono.empty(); // 即使发送失败也不影响主流程
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-77
@@ -1,77 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.util;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
|
||||||
import javax.crypto.spec.IvParameterSpec;
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Base64;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AES加密工具类
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
public class AesUtil {
|
|
||||||
|
|
||||||
private static final String ALGORITHM = "AES";
|
|
||||||
private static final String TRANSFORMATION = "AES/CBC/PKCS5Padding";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AES 解密
|
|
||||||
*
|
|
||||||
* @param encryptedData 加密数据,Base64编码
|
|
||||||
* @param key AES密钥,Base64编码(32字节)
|
|
||||||
* @param iv 初始化向量IV,Base64编码(16字节)
|
|
||||||
* @return 解密后的字符串
|
|
||||||
*/
|
|
||||||
public static String decrypt(String encryptedData, String key, String iv) {
|
|
||||||
try {
|
|
||||||
byte[] dataByte = Base64.getDecoder().decode(encryptedData);
|
|
||||||
byte[] keyByte = Base64.getDecoder().decode(key);
|
|
||||||
byte[] ivByte = Base64.getDecoder().decode(iv);
|
|
||||||
|
|
||||||
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
|
|
||||||
SecretKeySpec secretKeySpec = new SecretKeySpec(keyByte, ALGORITHM);
|
|
||||||
IvParameterSpec ivParameterSpec = new IvParameterSpec(ivByte);
|
|
||||||
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec);
|
|
||||||
|
|
||||||
byte[] resultByte = cipher.doFinal(dataByte);
|
|
||||||
return new String(resultByte, StandardCharsets.UTF_8);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("AES解密失败", e);
|
|
||||||
throw new RuntimeException("解密失败", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AES 加密
|
|
||||||
*
|
|
||||||
* @param data 原始数据
|
|
||||||
* @param key AES密钥,Base64编码(32字节)
|
|
||||||
* @param iv 初始化向量IV,Base64编码(16字节)
|
|
||||||
* @return Base64编码的加密数据
|
|
||||||
*/
|
|
||||||
public static String encrypt(String data, String key, String iv) {
|
|
||||||
try {
|
|
||||||
byte[] dataByte = data.getBytes(StandardCharsets.UTF_8);
|
|
||||||
byte[] keyByte = Base64.getDecoder().decode(key);
|
|
||||||
byte[] ivByte = Base64.getDecoder().decode(iv);
|
|
||||||
|
|
||||||
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
|
|
||||||
SecretKeySpec secretKeySpec = new SecretKeySpec(keyByte, ALGORITHM);
|
|
||||||
IvParameterSpec ivParameterSpec = new IvParameterSpec(ivByte);
|
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec);
|
|
||||||
|
|
||||||
byte[] resultByte = cipher.doFinal(dataByte);
|
|
||||||
return Base64.getEncoder().encodeToString(resultByte);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("AES加密失败", e);
|
|
||||||
throw new RuntimeException("加密失败", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-159
@@ -1,159 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.util;
|
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通用 ES 同步工具类
|
|
||||||
*
|
|
||||||
* 使用方式:
|
|
||||||
*
|
|
||||||
* 1. 注入工具类
|
|
||||||
* @Autowired private EsSyncUtils esSyncUtils;
|
|
||||||
*
|
|
||||||
* 2. 同步数据到 ES(不返回结果,适合 doOnSuccess)
|
|
||||||
* esSyncUtils.sync(Member.class, MemberES.class, member, memberESRepository);
|
|
||||||
*
|
|
||||||
* 3. 同步数据到 ES(返回 Mono,适合链式调用)
|
|
||||||
* esSyncUtils.syncToES(Member.class, MemberES.class, member, memberESRepository).subscribe();
|
|
||||||
*
|
|
||||||
* 4. 如果 Repository 是单例,可以先绑定
|
|
||||||
* var syncer = esSyncUtils.bind(Member.class, MemberES.class, memberESRepository);
|
|
||||||
* syncer.sync(member);
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class EsSyncUtils {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 同步实体到 ES(不返回结果,适合 doOnSuccess)
|
|
||||||
*
|
|
||||||
* @param sourceClass 源实体类(如 Member.class)
|
|
||||||
* @param targetClass 目标ES实体类(如 MemberES.class)
|
|
||||||
* @param source 源实体对象
|
|
||||||
* @param repository ES Repository
|
|
||||||
* @param <S> 源实体类型
|
|
||||||
* @param <T> ES实体类型
|
|
||||||
* @param <ID> ID类型
|
|
||||||
*/
|
|
||||||
public <S, T, ID> void sync(Class<S> sourceClass, Class<T> targetClass,
|
|
||||||
S source, ReactiveElasticsearchRepository<T, ID> repository) {
|
|
||||||
if (source == null) {
|
|
||||||
log.warn("同步 ES 失败:源实体为空");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
T target = BeanUtil.toBean(source, targetClass);
|
|
||||||
repository.save(target).subscribe(
|
|
||||||
success -> log.debug("同步到 ES 成功, 类型: {}", targetClass.getSimpleName()),
|
|
||||||
error -> log.error("同步到 ES 失败, 类型: {}", targetClass.getSimpleName(), error)
|
|
||||||
);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("转换 ES 实体失败, 源类型: {}, 目标类型: {}",
|
|
||||||
sourceClass.getSimpleName(), targetClass.getSimpleName(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 同步实体到 ES(返回 Mono,适合链式调用)
|
|
||||||
*
|
|
||||||
* @param sourceClass 源实体类
|
|
||||||
* @param targetClass 目标ES实体类
|
|
||||||
* @param source 源实体对象
|
|
||||||
* @param repository ES Repository
|
|
||||||
* @return Mono<Void>
|
|
||||||
*/
|
|
||||||
public <S, T, ID> Mono<Void> syncToES(Class<S> sourceClass, Class<T> targetClass,
|
|
||||||
S source, ReactiveElasticsearchRepository<T, ID> repository) {
|
|
||||||
if (source == null) {
|
|
||||||
log.warn("同步 ES 失败:源实体为空");
|
|
||||||
return Mono.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
T target = BeanUtil.toBean(source, targetClass);
|
|
||||||
return repository.save(target)
|
|
||||||
.doOnSuccess(t -> log.debug("同步到 ES 成功, 类型: {}", targetClass.getSimpleName()))
|
|
||||||
.doOnError(e -> log.error("同步到 ES 失败, 类型: {}", targetClass.getSimpleName(), e))
|
|
||||||
.then();
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("转换 ES 实体失败, 源类型: {}, 目标类型: {}",
|
|
||||||
sourceClass.getSimpleName(), targetClass.getSimpleName(), e);
|
|
||||||
return Mono.empty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 绑定 Repository,返回一个针对特定实体类型的同步器
|
|
||||||
*
|
|
||||||
* @param sourceClass 源实体类
|
|
||||||
* @param targetClass 目标ES实体类
|
|
||||||
* @param repository ES Repository
|
|
||||||
* @return 实体同步器
|
|
||||||
*/
|
|
||||||
public <S, T, ID> EntitySyncer<S, T, ID> bind(Class<S> sourceClass, Class<T> targetClass,
|
|
||||||
ReactiveElasticsearchRepository<T, ID> repository) {
|
|
||||||
return new EntitySyncer<>(sourceClass, targetClass, repository);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 实体同步器(绑定特定类型的同步器,避免重复传 Class)
|
|
||||||
*
|
|
||||||
* @param <S> 源实体类型
|
|
||||||
* @param <T> ES实体类型
|
|
||||||
* @param <ID> ID类型
|
|
||||||
*/
|
|
||||||
public static class EntitySyncer<S, T, ID> {
|
|
||||||
private final Class<S> sourceClass;
|
|
||||||
private final Class<T> targetClass;
|
|
||||||
private final ReactiveElasticsearchRepository<T, ID> repository;
|
|
||||||
|
|
||||||
public EntitySyncer(Class<S> sourceClass, Class<T> targetClass,
|
|
||||||
ReactiveElasticsearchRepository<T, ID> repository) {
|
|
||||||
this.sourceClass = sourceClass;
|
|
||||||
this.targetClass = targetClass;
|
|
||||||
this.repository = repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 同步(不返回结果)
|
|
||||||
*/
|
|
||||||
public void sync(S source) {
|
|
||||||
if (source == null) return;
|
|
||||||
try {
|
|
||||||
T target = BeanUtil.toBean(source, targetClass);
|
|
||||||
repository.save(target).subscribe(
|
|
||||||
success -> log.debug("同步到 ES 成功, 类型: {}", targetClass.getSimpleName()),
|
|
||||||
error -> log.error("同步到 ES 失败, 类型: {}", targetClass.getSimpleName(), error)
|
|
||||||
);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("转换 ES 实体失败, 源类型: {}, 目标类型: {}",
|
|
||||||
sourceClass.getSimpleName(), targetClass.getSimpleName(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 同步(返回 Mono)
|
|
||||||
*/
|
|
||||||
public Mono<Void> syncMono(S source) {
|
|
||||||
if (source == null) return Mono.empty();
|
|
||||||
try {
|
|
||||||
T target = BeanUtil.toBean(source, targetClass);
|
|
||||||
return repository.save(target)
|
|
||||||
.doOnSuccess(t -> log.debug("同步到 ES 成功, 类型: {}", targetClass.getSimpleName()))
|
|
||||||
.doOnError(e -> log.error("同步到 ES 失败, 类型: {}", targetClass.getSimpleName(), e))
|
|
||||||
.then();
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("转换 ES 实体失败, 源类型: {}, 目标类型: {}",
|
|
||||||
sourceClass.getSimpleName(), targetClass.getSimpleName(), e);
|
|
||||||
return Mono.empty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-53
@@ -1,53 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.util;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 会员号生成器
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
public class MemberNoGenerator {
|
|
||||||
|
|
||||||
// 会员号前缀
|
|
||||||
private static final String PREFIX = "GYM";
|
|
||||||
|
|
||||||
// 随机数长度
|
|
||||||
private static final int RANDOM_LENGTH = 8;
|
|
||||||
|
|
||||||
// 字符集(排除易混淆字符 0/O, 1/I/l
|
|
||||||
private static final String CHARACTERS = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
|
|
||||||
|
|
||||||
// SecureRandom 实例(线程安全)
|
|
||||||
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
|
|
||||||
|
|
||||||
// 生成会员号
|
|
||||||
public static String generate() {
|
|
||||||
StringBuilder sb = new StringBuilder(PREFIX);
|
|
||||||
|
|
||||||
for (int i = 0; i < RANDOM_LENGTH; i++) {
|
|
||||||
int index = SECURE_RANDOM.nextInt(CHARACTERS.length());
|
|
||||||
sb.append(CHARACTERS.charAt(index));
|
|
||||||
}
|
|
||||||
|
|
||||||
String memberNo = sb.toString();
|
|
||||||
log.debug("生成会员号: {}", memberNo);
|
|
||||||
|
|
||||||
return memberNo;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 批量生成会员号
|
|
||||||
// count 生成数量
|
|
||||||
public static String[] generateBatch(int count) {
|
|
||||||
String[] memberNos = new String[count];
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
memberNos[i] = generate();
|
|
||||||
}
|
|
||||||
return memberNos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-65
@@ -1,65 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.util;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.member.service.WechatApiService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 微信手机号获取工具类
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class WechatPhoneUtil {
|
|
||||||
|
|
||||||
private final WechatApiService wechatApiService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过phoneCode获取手机号
|
|
||||||
*
|
|
||||||
* @param phoneCode 手机号 code
|
|
||||||
* @return Mono<String> 手机号,获取失败则返回 null
|
|
||||||
*/
|
|
||||||
public Mono<String> getPhoneNumber(String phoneCode) {
|
|
||||||
if (phoneCode == null || phoneCode.isEmpty()) {
|
|
||||||
log.debug("未提供phoneCode获取手机号");
|
|
||||||
return Mono.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("开始获取手机号, phoneCode: {}", phoneCode);
|
|
||||||
|
|
||||||
return wechatApiService.getPhoneNumber(phoneCode)
|
|
||||||
.doOnSuccess(phoneNumber -> {
|
|
||||||
if (phoneNumber != null && !phoneNumber.isEmpty()) {
|
|
||||||
log.info("获取手机号成功: {}", maskPhone(phoneNumber));
|
|
||||||
} else {
|
|
||||||
log.warn("获取手机号失败");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.doOnError(e -> {
|
|
||||||
log.warn("获取手机号失败 {}", e.getMessage());
|
|
||||||
})
|
|
||||||
.onErrorResume(e -> {
|
|
||||||
return Mono.empty();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 手机号脱敏处理
|
|
||||||
*
|
|
||||||
* @param phone 手机号
|
|
||||||
* @return 脱敏后的手机号,如:138****8000
|
|
||||||
*/
|
|
||||||
private String maskPhone(String phone) {
|
|
||||||
if (phone == null || phone.length() < 7) {
|
|
||||||
return "***";
|
|
||||||
}
|
|
||||||
return phone.substring(0, 3) + "****" + phone.substring(7);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-46
@@ -1,46 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.vo;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 会员信息 VO
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class MemberInfoVO {
|
|
||||||
|
|
||||||
// 会员 ID
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
// 昵称
|
|
||||||
private String nickname;
|
|
||||||
|
|
||||||
// 手机号(脱敏)
|
|
||||||
private String phone;
|
|
||||||
|
|
||||||
// 性别
|
|
||||||
private Integer gender;
|
|
||||||
|
|
||||||
// 生日
|
|
||||||
private Date birthday;
|
|
||||||
|
|
||||||
// 头像
|
|
||||||
private String avatar;
|
|
||||||
|
|
||||||
// 是否已绑定手机号
|
|
||||||
private Boolean hasPhone;
|
|
||||||
|
|
||||||
// 是否已关注公众号
|
|
||||||
private Boolean isSubscribed;
|
|
||||||
}
|
|
||||||
-38
@@ -1,38 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.vo;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 微信登录VO
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class WechatLoginVO {
|
|
||||||
|
|
||||||
// 会员 ID
|
|
||||||
private Long memberId;
|
|
||||||
|
|
||||||
// Access Token(访问令牌)
|
|
||||||
private String accessToken;
|
|
||||||
|
|
||||||
// Refresh Token(刷新令牌)
|
|
||||||
private String refreshToken;
|
|
||||||
|
|
||||||
// Token 过期时间(秒)
|
|
||||||
private Integer expiresIn;
|
|
||||||
|
|
||||||
// 是否为新用户
|
|
||||||
private Boolean isNewUser;
|
|
||||||
|
|
||||||
// 是否需要补全信息(昵称、手机号等)
|
|
||||||
private Boolean needCompleteInfo;
|
|
||||||
}
|
|
||||||
-72
@@ -1,72 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member.vo;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 微信用户信息 VO
|
|
||||||
*
|
|
||||||
* @author 付嘉
|
|
||||||
* @date 2026-05-01
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class WechatUserInfoVO {
|
|
||||||
|
|
||||||
// 用户是否关注该公众号(true-已关注,false-未关注)
|
|
||||||
private Boolean subscribe;
|
|
||||||
|
|
||||||
// 服务号 OpenID
|
|
||||||
private String openid;
|
|
||||||
|
|
||||||
// 用户昵称
|
|
||||||
private String nickname;
|
|
||||||
|
|
||||||
// 性别(1-男,2-女,0-未知)
|
|
||||||
private Integer sex;
|
|
||||||
|
|
||||||
// 国家
|
|
||||||
private String country;
|
|
||||||
|
|
||||||
// 省份
|
|
||||||
private String province;
|
|
||||||
|
|
||||||
// 城市
|
|
||||||
private String city;
|
|
||||||
|
|
||||||
// 语言
|
|
||||||
private String language;
|
|
||||||
|
|
||||||
// 头像 URL
|
|
||||||
private String headimgurl;
|
|
||||||
|
|
||||||
// 关注时间
|
|
||||||
private Long subscribeTime;
|
|
||||||
|
|
||||||
// UnionID
|
|
||||||
private String unionid;
|
|
||||||
|
|
||||||
// 公众号运营者对粉丝的备注
|
|
||||||
private String remark;
|
|
||||||
|
|
||||||
// 用户所在的分组 ID
|
|
||||||
private Integer groupid;
|
|
||||||
|
|
||||||
// 用户被打上的标签 ID 列表
|
|
||||||
private List<Integer> tagidList;
|
|
||||||
|
|
||||||
// 关注来源
|
|
||||||
private Integer subscribeScene;
|
|
||||||
|
|
||||||
// 二维码场景值
|
|
||||||
private String qrScene;
|
|
||||||
|
|
||||||
// 二维码场景值字符串
|
|
||||||
private String qrSceneStr;
|
|
||||||
}
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
cn.novalon.gym.manage.member.config.WechatProperties
|
|
||||||
@@ -1,138 +0,0 @@
|
|||||||
-- ============================================
|
|
||||||
-- 1. member_user 表(会员表)
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- Step 1: 删除已存在的表(如果需要重建)
|
|
||||||
-- DROP TABLE IF EXISTS member_user CASCADE;
|
|
||||||
|
|
||||||
-- Step 2: 创建 member_user 表
|
|
||||||
CREATE TABLE IF NOT EXISTS member_user (
|
|
||||||
-- ========== 主键和基础字段(来自BaseEntity)==========
|
|
||||||
id BIGSERIAL PRIMARY KEY, -- 主键ID,自增
|
|
||||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
|
|
||||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间
|
|
||||||
|
|
||||||
-- ========== 会员核心字段 ==========
|
|
||||||
member_no VARCHAR(50) NOT NULL UNIQUE, -- 会员编号(唯一)
|
|
||||||
nickname VARCHAR(100), -- 昵称
|
|
||||||
phone VARCHAR(255), -- 手机号(AES加密存储)
|
|
||||||
gender INTEGER DEFAULT 0, -- 性别:0-未知,1-男,2-女
|
|
||||||
birthday TIMESTAMP, -- 生日
|
|
||||||
address VARCHAR(500), -- 地址
|
|
||||||
avatar VARCHAR(500), -- 头像URL
|
|
||||||
subscribed BOOLEAN DEFAULT FALSE, -- 是否关注服务号
|
|
||||||
last_login_at TIMESTAMP, -- 最后登录时间
|
|
||||||
|
|
||||||
-- ========== 微信相关字段 ==========
|
|
||||||
union_id VARCHAR(100), -- 微信UnionID(跨应用唯一标识)
|
|
||||||
miniapp_open_id VARCHAR(100), -- 小程序OpenID
|
|
||||||
official_open_id VARCHAR(100), -- 服务号OpenID
|
|
||||||
|
|
||||||
-- ========== 软删除字段 ==========
|
|
||||||
is_deleted BOOLEAN DEFAULT FALSE -- 是否删除(软删除标记)
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Step 3: 创建索引
|
|
||||||
-- 会员编号索引(唯一索引,加速查询)
|
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_member_user_member_no ON member_user(member_no);
|
|
||||||
|
|
||||||
-- UnionID索引(加速跨平台用户查找)
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_member_user_union_id ON member_user(union_id);
|
|
||||||
|
|
||||||
-- 小程序OpenID索引(加速小程序登录查询)
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_member_user_miniapp_openid ON member_user(miniapp_open_id);
|
|
||||||
|
|
||||||
-- 服务号OpenID索引(加速服务号事件处理)
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_member_user_official_openid ON member_user(official_open_id);
|
|
||||||
|
|
||||||
-- 手机号索引(加速手机号查询和去重)
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_member_user_phone ON member_user(phone);
|
|
||||||
|
|
||||||
-- 软删除索引(加速查询未删除的记录)
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_member_user_is_deleted ON member_user(is_deleted);
|
|
||||||
|
|
||||||
-- Step 4: 添加注释
|
|
||||||
COMMENT ON TABLE member_user IS '会员表';
|
|
||||||
|
|
||||||
COMMENT ON COLUMN member_user.id IS '主键ID';
|
|
||||||
COMMENT ON COLUMN member_user.created_at IS '创建时间';
|
|
||||||
COMMENT ON COLUMN member_user.updated_at IS '更新时间';
|
|
||||||
|
|
||||||
COMMENT ON COLUMN member_user.member_no IS '会员编号(唯一,格式:MEM + 8位随机字符)';
|
|
||||||
COMMENT ON COLUMN member_user.nickname IS '昵称';
|
|
||||||
COMMENT ON COLUMN member_user.phone IS '手机号(AES-128-CBC加密存储)';
|
|
||||||
COMMENT ON COLUMN member_user.gender IS '性别:0-未知,1-男,2-女';
|
|
||||||
COMMENT ON COLUMN member_user.birthday IS '生日';
|
|
||||||
COMMENT ON COLUMN member_user.address IS '地址';
|
|
||||||
COMMENT ON COLUMN member_user.avatar IS '头像URL';
|
|
||||||
COMMENT ON COLUMN member_user.subscribed IS '是否关注服务号:true-已关注,false-未关注';
|
|
||||||
COMMENT ON COLUMN member_user.last_login_at IS '最后登录时间';
|
|
||||||
|
|
||||||
COMMENT ON COLUMN member_user.union_id IS '微信UnionID(用户在开放平台的唯一标识,跨应用相同)';
|
|
||||||
COMMENT ON COLUMN member_user.miniapp_open_id IS '小程序OpenID(用户在当前小程序的唯一标识)';
|
|
||||||
COMMENT ON COLUMN member_user.official_open_id IS '服务号OpenID(用户在当前服务号的唯一标识)';
|
|
||||||
|
|
||||||
COMMENT ON COLUMN member_user.is_deleted IS '是否删除(软删除标记):false-正常,true-已删除';
|
|
||||||
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 2. wechat_user 表(微信用户表)
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- Step 1: 删除已存在的表(如果需要重建)
|
|
||||||
-- DROP TABLE IF EXISTS wechat_user CASCADE;
|
|
||||||
|
|
||||||
-- Step 2: 创建 wechat_user 表
|
|
||||||
CREATE TABLE IF NOT EXISTS wechat_user (
|
|
||||||
-- ========== 主键和基础字段(来自BaseEntity)==========
|
|
||||||
id BIGSERIAL PRIMARY KEY, -- 主键ID,自增
|
|
||||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
|
|
||||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间
|
|
||||||
|
|
||||||
-- ========== 关联字段 ==========
|
|
||||||
member_id BIGINT NOT NULL, -- 会员ID(外键)
|
|
||||||
|
|
||||||
-- ========== 微信标识字段 ==========
|
|
||||||
union_id VARCHAR(100), -- 微信UnionID
|
|
||||||
miniapp_openid VARCHAR(100), -- 小程序OpenID
|
|
||||||
mp_openid VARCHAR(100), -- 服务号OpenID
|
|
||||||
|
|
||||||
-- ========== 关注状态字段 ==========
|
|
||||||
is_subscribed BOOLEAN DEFAULT FALSE, -- 是否关注服务号
|
|
||||||
subscribe_time TIMESTAMP, -- 首次关注时间
|
|
||||||
unsubscribe_time TIMESTAMP -- 最后一次取消关注时间
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Step 3: 创建外键约束
|
|
||||||
ALTER TABLE wechat_user
|
|
||||||
ADD CONSTRAINT fk_wechat_user_member
|
|
||||||
FOREIGN KEY (member_id) REFERENCES member_user(id) ON DELETE CASCADE;
|
|
||||||
|
|
||||||
-- Step 4: 创建索引
|
|
||||||
-- UnionID索引(加速跨平台用户查找)
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_wechat_user_union_id ON wechat_user(union_id);
|
|
||||||
|
|
||||||
-- 小程序OpenID索引(加速小程序登录查询)
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_wechat_user_miniapp_openid ON wechat_user(miniapp_openid);
|
|
||||||
|
|
||||||
-- 服务号OpenID索引(加速服务号事件处理)
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_wechat_user_mp_openid ON wechat_user(mp_openid);
|
|
||||||
|
|
||||||
-- 会员ID索引(加速关联查询)
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_wechat_user_member_id ON wechat_user(member_id);
|
|
||||||
|
|
||||||
-- Step 5: 添加注释
|
|
||||||
COMMENT ON TABLE wechat_user IS '微信用户表';
|
|
||||||
|
|
||||||
COMMENT ON COLUMN wechat_user.id IS '主键ID';
|
|
||||||
COMMENT ON COLUMN wechat_user.created_at IS '创建时间';
|
|
||||||
COMMENT ON COLUMN wechat_user.updated_at IS '更新时间';
|
|
||||||
|
|
||||||
COMMENT ON COLUMN wechat_user.member_id IS '会员ID(关联 member_user 表的 id 字段)';
|
|
||||||
COMMENT ON COLUMN wechat_user.union_id IS '微信UnionID(用户在开放平台的唯一标识)';
|
|
||||||
COMMENT ON COLUMN wechat_user.miniapp_openid IS '小程序OpenID(用户在当前小程序的唯一标识)';
|
|
||||||
COMMENT ON COLUMN wechat_user.mp_openid IS '服务号OpenID(用户在当前服务号的唯一标识)';
|
|
||||||
|
|
||||||
COMMENT ON COLUMN wechat_user.is_subscribed IS '是否关注服务号:true-已关注,false-未关注';
|
|
||||||
COMMENT ON COLUMN wechat_user.subscribe_time IS '首次关注时间';
|
|
||||||
COMMENT ON COLUMN wechat_user.unsubscribe_time IS '最后一次取消关注时间';
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
# 微信配置(测试环境使用模拟数据)
|
|
||||||
wechat:
|
|
||||||
# Mock模式:true=使用模拟数据(开发测试),false=调用真实微信API(生产环境)
|
|
||||||
mock-enabled: false
|
|
||||||
miniapp:
|
|
||||||
app-id: wx4d480112b426100b
|
|
||||||
app-secret: 78548f0c0ff66c73d3e8b071897eb1e5
|
|
||||||
mp:
|
|
||||||
app-id: wx6f138c9aacc8a0e8
|
|
||||||
app-secret: 5df2e315e9268e96a43bb2cce1d2270b
|
|
||||||
token: test_token
|
|
||||||
aes-key: ${WECHAT_MP_AESKEY:test_aes_key}
|
|
||||||
# 服务器回调地址(微信服务器推送事件的URL)
|
|
||||||
callback-url: https://1me240209tk74.vicp.fun/api/member/auth/mp/callback
|
|
||||||
# 手机号加密配置
|
|
||||||
phone-encryption:
|
|
||||||
secret-key: nVnA99iBfyK0IE6SkcUYdVAaVrezyn2sLRdLfkIyWnY=
|
|
||||||
iv: LMpG6Ih9mmfEAALOCeIJBw==
|
|
||||||
|
|
||||||
spring:
|
|
||||||
elasticsearch:
|
|
||||||
uris: http://localhost:9200 # ES 服务器地址(支持多个,逗号分隔)
|
|
||||||
-16
@@ -1,16 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.member;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 会员模块测试类
|
|
||||||
*/
|
|
||||||
@SpringBootTest
|
|
||||||
public class MemberModuleTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void contextLoads() {
|
|
||||||
// 测试Spring上下文是否能正常加载
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -38,20 +38,10 @@
|
|||||||
<artifactId>manage-db</artifactId>
|
<artifactId>manage-db</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>cn.novalon.gym.manage</groupId>
|
|
||||||
<artifactId>gym-member</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-aop</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
@@ -80,10 +70,6 @@
|
|||||||
<groupId>org.postgresql</groupId>
|
<groupId>org.postgresql</groupId>
|
||||||
<artifactId>postgresql</artifactId>
|
<artifactId>postgresql</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
|
|||||||
+6
-40
@@ -1,27 +1,16 @@
|
|||||||
package cn.novalon.gym.manage.app;
|
package cn.novalon.gym.manage.app;
|
||||||
|
|
||||||
import cn.novalon.gym.manage.sys.core.service.IOperationLogService;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDetailsServiceAutoConfiguration;
|
import org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDetailsServiceAutoConfiguration;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
|
||||||
import org.springframework.data.elasticsearch.repository.config.EnableReactiveElasticsearchRepositories;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
|
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
|
||||||
import org.springframework.web.server.WebFilter;
|
|
||||||
|
|
||||||
import java.util.List;
|
@SpringBootApplication(scanBasePackages = "cn.novalon.gym.manage", exclude = {ReactiveUserDetailsServiceAutoConfiguration.class})
|
||||||
|
@EnableR2dbcRepositories(basePackages = {"cn.novalon.gym.manage.db.dao", "cn.novalon.gym.manage.sys.audit.repository"})
|
||||||
@SpringBootApplication(scanBasePackages = "cn.novalon.gym.manage", exclude = {
|
|
||||||
ReactiveUserDetailsServiceAutoConfiguration.class })
|
|
||||||
@EnableR2dbcRepositories(basePackages = {
|
|
||||||
"cn.novalon.gym.manage.db.dao",
|
|
||||||
"cn.novalon.gym.manage.sys.audit.repository",
|
|
||||||
"cn.novalon.gym.manage.member.repository"
|
|
||||||
})
|
|
||||||
@EnableReactiveElasticsearchRepositories("cn.novalon.gym.manage.member.es.repository")
|
|
||||||
public class ManageApplication {
|
public class ManageApplication {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ManageApplication.class);
|
private static final Logger logger = LoggerFactory.getLogger(ManageApplication.class);
|
||||||
@@ -29,32 +18,9 @@ public class ManageApplication {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
logger.info("应用程序启动中...");
|
logger.info("应用程序启动中...");
|
||||||
logger.info("包扫描路径: cn.novalon.gym.manage");
|
logger.info("包扫描路径: cn.novalon.gym.manage");
|
||||||
|
|
||||||
|
// 使用简单的启动方式,避免自动配置问题
|
||||||
SpringApplication.run(ManageApplication.class, args);
|
SpringApplication.run(ManageApplication.class, args);
|
||||||
logger.info("应用程序启动完成");
|
logger.info("应用程序启动完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
public CommandLineRunner checkWebFilters(List<WebFilter> webFilters) {
|
|
||||||
return args -> {
|
|
||||||
logger.info("=== 检查已注册的 WebFilter ===");
|
|
||||||
logger.info("WebFilter 总数: {}", webFilters.size());
|
|
||||||
for (WebFilter filter : webFilters) {
|
|
||||||
logger.info(" - {} (Order: {})",
|
|
||||||
filter.getClass().getName(),
|
|
||||||
filter.getClass().getAnnotation(org.springframework.core.annotation.Order.class) != null
|
|
||||||
? filter.getClass().getAnnotation(org.springframework.core.annotation.Order.class)
|
|
||||||
.value()
|
|
||||||
: "无");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public CommandLineRunner checkOperationLogService(IOperationLogService service) {
|
|
||||||
return args -> {
|
|
||||||
logger.info("=== 检查 IOperationLogService ===");
|
|
||||||
logger.info("IOperationLogService 实现: {}", service.getClass().getName());
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
-29
@@ -1,29 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.app.config;
|
|
||||||
|
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.Primary;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class DataSourceConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@Primary
|
|
||||||
@ConfigurationProperties("spring.datasource")
|
|
||||||
public DataSourceProperties dataSourceProperties() {
|
|
||||||
return new DataSourceProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@Primary
|
|
||||||
public DataSource dataSource(DataSourceProperties properties) {
|
|
||||||
return properties.initializeDataSourceBuilder()
|
|
||||||
.type(HikariDataSource.class)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+7
-30
@@ -1,23 +1,20 @@
|
|||||||
package cn.novalon.gym.manage.app.config;
|
package cn.novalon.gym.manage.app.config;
|
||||||
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.file.handler.SysFileHandler;
|
|
||||||
import cn.novalon.gym.manage.member.handler.MemberHandler;
|
|
||||||
import cn.novalon.gym.manage.member.handler.WechatAuthHandler;
|
|
||||||
import cn.novalon.gym.manage.notify.handler.SysNoticeHandler;
|
|
||||||
import cn.novalon.gym.manage.notify.handler.SysUserMessageHandler;
|
|
||||||
import cn.novalon.gym.manage.sys.handler.auth.PasswordDiagnosticHandler;
|
|
||||||
import cn.novalon.gym.manage.sys.handler.auth.SysAuthHandler;
|
import cn.novalon.gym.manage.sys.handler.auth.SysAuthHandler;
|
||||||
|
import cn.novalon.gym.manage.sys.handler.auth.PasswordDiagnosticHandler;
|
||||||
import cn.novalon.gym.manage.sys.handler.config.SysConfigHandler;
|
import cn.novalon.gym.manage.sys.handler.config.SysConfigHandler;
|
||||||
import cn.novalon.gym.manage.sys.handler.dict.SysDictHandler;
|
|
||||||
import cn.novalon.gym.manage.sys.handler.dictionary.DictionaryHandler;
|
import cn.novalon.gym.manage.sys.handler.dictionary.DictionaryHandler;
|
||||||
import cn.novalon.gym.manage.sys.handler.log.OperationLogHandler;
|
import cn.novalon.gym.manage.sys.handler.dict.SysDictHandler;
|
||||||
import cn.novalon.gym.manage.sys.handler.log.SysLogHandler;
|
import cn.novalon.gym.manage.sys.handler.log.SysLogHandler;
|
||||||
|
import cn.novalon.gym.manage.sys.handler.log.OperationLogHandler;
|
||||||
import cn.novalon.gym.manage.sys.handler.menu.MenuHandler;
|
import cn.novalon.gym.manage.sys.handler.menu.MenuHandler;
|
||||||
import cn.novalon.gym.manage.sys.handler.permission.SysPermissionHandler;
|
|
||||||
import cn.novalon.gym.manage.sys.handler.role.SysRoleHandler;
|
import cn.novalon.gym.manage.sys.handler.role.SysRoleHandler;
|
||||||
|
import cn.novalon.gym.manage.sys.handler.permission.SysPermissionHandler;
|
||||||
import cn.novalon.gym.manage.sys.handler.stats.StatsHandler;
|
import cn.novalon.gym.manage.sys.handler.stats.StatsHandler;
|
||||||
import cn.novalon.gym.manage.sys.handler.user.SysUserHandler;
|
import cn.novalon.gym.manage.sys.handler.user.SysUserHandler;
|
||||||
|
import cn.novalon.gym.manage.notify.handler.SysNoticeHandler;
|
||||||
|
import cn.novalon.gym.manage.notify.handler.SysUserMessageHandler;
|
||||||
|
import cn.novalon.gym.manage.file.handler.SysFileHandler;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.reactive.function.server.RouterFunction;
|
import org.springframework.web.reactive.function.server.RouterFunction;
|
||||||
@@ -54,8 +51,6 @@ public class SystemRouter {
|
|||||||
SysUserMessageHandler messageHandler,
|
SysUserMessageHandler messageHandler,
|
||||||
SysFileHandler fileHandler,
|
SysFileHandler fileHandler,
|
||||||
SysPermissionHandler permissionHandler,
|
SysPermissionHandler permissionHandler,
|
||||||
MemberHandler memberHandler,
|
|
||||||
WechatAuthHandler wechatAuthHandler,
|
|
||||||
PasswordDiagnosticHandler passwordDiagnosticHandler) {
|
PasswordDiagnosticHandler passwordDiagnosticHandler) {
|
||||||
|
|
||||||
return route()
|
return route()
|
||||||
@@ -197,25 +192,7 @@ public class SystemRouter {
|
|||||||
.POST("/api/permissions", permissionHandler::createPermission)
|
.POST("/api/permissions", permissionHandler::createPermission)
|
||||||
.PUT("/api/permissions/{id}", permissionHandler::updatePermission)
|
.PUT("/api/permissions/{id}", permissionHandler::updatePermission)
|
||||||
.DELETE("/api/permissions/{id}", permissionHandler::deletePermission)
|
.DELETE("/api/permissions/{id}", permissionHandler::deletePermission)
|
||||||
|
|
||||||
// ========== 会员模块路由 - 微信认证 ==========
|
|
||||||
.POST("/api/member/auth/miniapp/login", wechatAuthHandler::miniappLogin)
|
|
||||||
.GET("/api/member/auth/mp/callback", wechatAuthHandler::verifyMpSignature)
|
|
||||||
.POST("/api/member/auth/mp/callback", wechatAuthHandler::mpCallback)
|
|
||||||
|
|
||||||
// ========== 会员模块路由 - 会员信息 ==========
|
|
||||||
.GET("/api/member/info", memberHandler::getMemberInfo)
|
|
||||||
.PUT("/api/member/info", memberHandler::updateMemberInfo)
|
|
||||||
.POST("/api/member/phone/bind", memberHandler::bindPhone)
|
|
||||||
.GET("/api/member/subscribe/status", memberHandler::checkSubscribeStatus)
|
|
||||||
|
|
||||||
// ========== 会员模块路由 - 管理端 ==========
|
|
||||||
.POST("/api/admin/member/{id}/phone", memberHandler::adminUpdatePhone)
|
|
||||||
.GET("/api/admin/member/{id}", memberHandler::adminGetMemberInfo)
|
|
||||||
.PUT("/api/admin/member/{id}", memberHandler::adminUpdateMemberInfo)
|
|
||||||
.GET("/api/admin/members", memberHandler::searchMembers)
|
|
||||||
.GET("/api/admin/members/all", memberHandler::getAllMembers)
|
|
||||||
|
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-25
@@ -1,25 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.app.config;
|
|
||||||
|
|
||||||
import io.r2dbc.spi.ConnectionFactory;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.Primary;
|
|
||||||
import org.springframework.transaction.ReactiveTransactionManager;
|
|
||||||
import org.springframework.transaction.reactive.TransactionalOperator;
|
|
||||||
import org.springframework.r2dbc.connection.R2dbcTransactionManager;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class TransactionManagerConfig {
|
|
||||||
|
|
||||||
@Bean(name = "connectionFactoryTransactionManager")
|
|
||||||
@Primary
|
|
||||||
public ReactiveTransactionManager reactiveTransactionManager(ConnectionFactory connectionFactory) {
|
|
||||||
return new R2dbcTransactionManager(connectionFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@Primary
|
|
||||||
public TransactionalOperator transactionalOperator(ReactiveTransactionManager reactiveTransactionManager) {
|
|
||||||
return TransactionalOperator.create(reactiveTransactionManager);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,15 +12,11 @@ spring:
|
|||||||
max-life-time: 30m
|
max-life-time: 30m
|
||||||
acquire-timeout: 3s
|
acquire-timeout: 3s
|
||||||
flyway:
|
flyway:
|
||||||
url: jdbc:postgresql://localhost:55432/manage_system
|
enabled: true
|
||||||
user: novalon
|
|
||||||
password: novalon123
|
|
||||||
enabled: false
|
|
||||||
locations: classpath:db/migration
|
locations: classpath:db/migration
|
||||||
baseline-on-migrate: true
|
baseline-on-migrate: true
|
||||||
validate-on-migrate: true
|
validate-on-migrate: true
|
||||||
|
|
||||||
|
|
||||||
jwt:
|
jwt:
|
||||||
secret: novalon-gym-manage-jwt-secret-key-for-development-only-2026
|
secret: novalon-gym-manage-jwt-secret-key-for-development-only-2026
|
||||||
expiration: 86400000
|
expiration: 86400000
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ spring:
|
|||||||
password: 123456
|
password: 123456
|
||||||
driver-class-name: org.postgresql.Driver
|
driver-class-name: org.postgresql.Driver
|
||||||
flyway:
|
flyway:
|
||||||
enabled: false
|
enabled: true
|
||||||
locations: classpath:db/migration
|
locations: classpath:db/migration
|
||||||
baseline-on-migrate: true
|
baseline-on-migrate: true
|
||||||
baseline-version: 0
|
baseline-version: 0
|
||||||
@@ -31,10 +31,6 @@ spring:
|
|||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
cn.novalon.manage: DEBUG
|
cn.novalon.manage: DEBUG
|
||||||
cn.novalon.gym.manage: DEBUG
|
|
||||||
cn.novalon.gym.manage.sys.audit: DEBUG
|
|
||||||
org.springframework.r2dbc: DEBUG
|
org.springframework.r2dbc: DEBUG
|
||||||
cn.novalon.manage.db: DEBUG
|
cn.novalon.manage.db: DEBUG
|
||||||
org.flywaydb: DEBUG
|
org.flywaydb: DEBUG
|
||||||
|
|
||||||
debug: true
|
|
||||||
@@ -15,7 +15,7 @@ spring:
|
|||||||
max-life-time: 1h
|
max-life-time: 1h
|
||||||
acquire-timeout: 5s
|
acquire-timeout: 5s
|
||||||
flyway:
|
flyway:
|
||||||
enabled: false
|
enabled: true
|
||||||
locations: classpath:db/migration
|
locations: classpath:db/migration
|
||||||
baseline-on-migrate: true
|
baseline-on-migrate: true
|
||||||
validate-on-migrate: true
|
validate-on-migrate: true
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ server:
|
|||||||
port: 8084
|
port: 8084
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
aop:
|
|
||||||
proxy-target-class: true
|
|
||||||
application:
|
application:
|
||||||
name: gym-manage-api
|
name: gym-manage-api
|
||||||
main:
|
main:
|
||||||
@@ -29,7 +27,7 @@ spring:
|
|||||||
password: ${DB_PASSWORD:postgres}
|
password: ${DB_PASSWORD:postgres}
|
||||||
driver-class-name: org.postgresql.Driver
|
driver-class-name: org.postgresql.Driver
|
||||||
flyway:
|
flyway:
|
||||||
enabled: false
|
enabled: true
|
||||||
locations: classpath:db/migration
|
locations: classpath:db/migration
|
||||||
baseline-on-migrate: true
|
baseline-on-migrate: true
|
||||||
baseline-version: 0
|
baseline-version: 0
|
||||||
@@ -38,10 +36,6 @@ spring:
|
|||||||
user:
|
user:
|
||||||
name: disabled
|
name: disabled
|
||||||
password: disabled
|
password: disabled
|
||||||
profiles:
|
|
||||||
active: dev
|
|
||||||
config:
|
|
||||||
import: classpath:member-config.yml
|
|
||||||
|
|
||||||
management:
|
management:
|
||||||
endpoints:
|
endpoints:
|
||||||
|
|||||||
+4
-5
@@ -2,7 +2,6 @@ package cn.novalon.gym.manage.db.converter;
|
|||||||
|
|
||||||
import cn.novalon.gym.manage.sys.audit.domain.AuditLog;
|
import cn.novalon.gym.manage.sys.audit.domain.AuditLog;
|
||||||
import cn.novalon.gym.manage.db.entity.AuditLogEntity;
|
import cn.novalon.gym.manage.db.entity.AuditLogEntity;
|
||||||
import io.r2dbc.postgresql.codec.Json;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -29,8 +28,8 @@ public class AuditLogConverter {
|
|||||||
domain.setOperationType(entity.getOperationType());
|
domain.setOperationType(entity.getOperationType());
|
||||||
domain.setOperator(entity.getOperator());
|
domain.setOperator(entity.getOperator());
|
||||||
domain.setOperationTime(entity.getOperationTime());
|
domain.setOperationTime(entity.getOperationTime());
|
||||||
domain.setBeforeData(entity.getBeforeData() != null ? entity.getBeforeData().asString() : null);
|
domain.setBeforeData(entity.getBeforeData());
|
||||||
domain.setAfterData(entity.getAfterData() != null ? entity.getAfterData().asString() : null);
|
domain.setAfterData(entity.getAfterData());
|
||||||
domain.setChangedFields(entity.getChangedFields());
|
domain.setChangedFields(entity.getChangedFields());
|
||||||
domain.setIpAddress(entity.getIpAddress());
|
domain.setIpAddress(entity.getIpAddress());
|
||||||
domain.setUserAgent(entity.getUserAgent());
|
domain.setUserAgent(entity.getUserAgent());
|
||||||
@@ -54,8 +53,8 @@ public class AuditLogConverter {
|
|||||||
entity.setOperationType(domain.getOperationType());
|
entity.setOperationType(domain.getOperationType());
|
||||||
entity.setOperator(domain.getOperator());
|
entity.setOperator(domain.getOperator());
|
||||||
entity.setOperationTime(domain.getOperationTime());
|
entity.setOperationTime(domain.getOperationTime());
|
||||||
entity.setBeforeData(domain.getBeforeData() != null ? Json.of(domain.getBeforeData()) : null);
|
entity.setBeforeData(domain.getBeforeData());
|
||||||
entity.setAfterData(domain.getAfterData() != null ? Json.of(domain.getAfterData()) : null);
|
entity.setAfterData(domain.getAfterData());
|
||||||
entity.setChangedFields(domain.getChangedFields());
|
entity.setChangedFields(domain.getChangedFields());
|
||||||
entity.setIpAddress(domain.getIpAddress());
|
entity.setIpAddress(domain.getIpAddress());
|
||||||
entity.setUserAgent(domain.getUserAgent());
|
entity.setUserAgent(domain.getUserAgent());
|
||||||
|
|||||||
+6
-7
@@ -1,6 +1,5 @@
|
|||||||
package cn.novalon.gym.manage.db.entity;
|
package cn.novalon.gym.manage.db.entity;
|
||||||
|
|
||||||
import io.r2dbc.postgresql.codec.Json;
|
|
||||||
import org.springframework.data.relational.core.mapping.Column;
|
import org.springframework.data.relational.core.mapping.Column;
|
||||||
import org.springframework.data.relational.core.mapping.Table;
|
import org.springframework.data.relational.core.mapping.Table;
|
||||||
|
|
||||||
@@ -29,10 +28,10 @@ public class AuditLogEntity extends BaseEntity {
|
|||||||
private java.time.LocalDateTime operationTime;
|
private java.time.LocalDateTime operationTime;
|
||||||
|
|
||||||
@Column("before_data")
|
@Column("before_data")
|
||||||
private Json beforeData;
|
private String beforeData;
|
||||||
|
|
||||||
@Column("after_data")
|
@Column("after_data")
|
||||||
private Json afterData;
|
private String afterData;
|
||||||
|
|
||||||
@Column("changed_fields")
|
@Column("changed_fields")
|
||||||
private String[] changedFields;
|
private String[] changedFields;
|
||||||
@@ -86,19 +85,19 @@ public class AuditLogEntity extends BaseEntity {
|
|||||||
this.operationTime = operationTime;
|
this.operationTime = operationTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Json getBeforeData() {
|
public String getBeforeData() {
|
||||||
return beforeData;
|
return beforeData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBeforeData(Json beforeData) {
|
public void setBeforeData(String beforeData) {
|
||||||
this.beforeData = beforeData;
|
this.beforeData = beforeData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Json getAfterData() {
|
public String getAfterData() {
|
||||||
return afterData;
|
return afterData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAfterData(Json afterData) {
|
public void setAfterData(String afterData) {
|
||||||
this.afterData = afterData;
|
this.afterData = afterData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-13
@@ -5,12 +5,17 @@ import org.springframework.data.annotation.CreatedDate;
|
|||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.annotation.LastModifiedBy;
|
import org.springframework.data.annotation.LastModifiedBy;
|
||||||
import org.springframework.data.annotation.LastModifiedDate;
|
import org.springframework.data.annotation.LastModifiedDate;
|
||||||
import org.springframework.data.annotation.Transient;
|
|
||||||
import org.springframework.data.domain.Persistable;
|
import org.springframework.data.domain.Persistable;
|
||||||
import org.springframework.data.relational.core.mapping.Column;
|
import org.springframework.data.relational.core.mapping.Column;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库实体基类
|
||||||
|
*
|
||||||
|
* @author 张翔
|
||||||
|
* @date 2026-03-13
|
||||||
|
*/
|
||||||
public abstract class BaseEntity implements Persistable<Long> {
|
public abstract class BaseEntity implements Persistable<Long> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@@ -35,9 +40,6 @@ public abstract class BaseEntity implements Persistable<Long> {
|
|||||||
@Column("deleted_at")
|
@Column("deleted_at")
|
||||||
private LocalDateTime deletedAt;
|
private LocalDateTime deletedAt;
|
||||||
|
|
||||||
@Transient
|
|
||||||
private boolean newEntity = true;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
@@ -87,16 +89,12 @@ public abstract class BaseEntity implements Persistable<Long> {
|
|||||||
this.deletedAt = deletedAt;
|
this.deletedAt = deletedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断实体是否为新的
|
||||||
|
* 如果createdAt为null,则认为是新实体
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isNew() {
|
public boolean isNew() {
|
||||||
return newEntity;
|
return createdAt == null;
|
||||||
}
|
|
||||||
|
|
||||||
public void markNotNew() {
|
|
||||||
this.newEntity = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void markNew() {
|
|
||||||
this.newEntity = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-10
@@ -7,7 +7,6 @@ import cn.novalon.gym.manage.db.dao.AuditLogDao;
|
|||||||
import cn.novalon.gym.manage.db.entity.AuditLogEntity;
|
import cn.novalon.gym.manage.db.entity.AuditLogEntity;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
@@ -27,12 +26,10 @@ public class AuditLogRepository implements IAuditLogRepository {
|
|||||||
|
|
||||||
private final AuditLogDao auditLogDao;
|
private final AuditLogDao auditLogDao;
|
||||||
private final AuditLogConverter auditLogConverter;
|
private final AuditLogConverter auditLogConverter;
|
||||||
private final R2dbcEntityTemplate r2dbcEntityTemplate;
|
|
||||||
|
|
||||||
public AuditLogRepository(AuditLogDao auditLogDao, AuditLogConverter auditLogConverter, R2dbcEntityTemplate r2dbcEntityTemplate) {
|
public AuditLogRepository(AuditLogDao auditLogDao, AuditLogConverter auditLogConverter) {
|
||||||
this.auditLogDao = auditLogDao;
|
this.auditLogDao = auditLogDao;
|
||||||
this.auditLogConverter = auditLogConverter;
|
this.auditLogConverter = auditLogConverter;
|
||||||
this.r2dbcEntityTemplate = r2dbcEntityTemplate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -44,12 +41,6 @@ public class AuditLogRepository implements IAuditLogRepository {
|
|||||||
@Override
|
@Override
|
||||||
public Mono<AuditLog> save(AuditLog auditLog) {
|
public Mono<AuditLog> save(AuditLog auditLog) {
|
||||||
AuditLogEntity entity = auditLogConverter.toEntity(auditLog);
|
AuditLogEntity entity = auditLogConverter.toEntity(auditLog);
|
||||||
if (entity.isNew()) {
|
|
||||||
return r2dbcEntityTemplate.insert(AuditLogEntity.class)
|
|
||||||
.using(entity)
|
|
||||||
.doOnNext(e -> e.markNotNew())
|
|
||||||
.map(auditLogConverter::toDomain);
|
|
||||||
}
|
|
||||||
return auditLogDao.save(entity)
|
return auditLogDao.save(entity)
|
||||||
.map(auditLogConverter::toDomain);
|
.map(auditLogConverter::toDomain);
|
||||||
}
|
}
|
||||||
|
|||||||
-6
@@ -49,12 +49,6 @@ public class OperationLogRepository implements IOperationLogRepository {
|
|||||||
@Override
|
@Override
|
||||||
public Mono<OperationLog> save(OperationLog operationLog) {
|
public Mono<OperationLog> save(OperationLog operationLog) {
|
||||||
OperationLogEntity entity = operationLogConverter.toEntity(operationLog);
|
OperationLogEntity entity = operationLogConverter.toEntity(operationLog);
|
||||||
if (entity.isNew()) {
|
|
||||||
return r2dbcEntityTemplate.insert(OperationLogEntity.class)
|
|
||||||
.using(entity)
|
|
||||||
.doOnNext(e -> e.markNotNew())
|
|
||||||
.map(operationLogConverter::toDomain);
|
|
||||||
}
|
|
||||||
return operationLogDao.save(entity)
|
return operationLogDao.save(entity)
|
||||||
.map(operationLogConverter::toDomain);
|
.map(operationLogConverter::toDomain);
|
||||||
}
|
}
|
||||||
|
|||||||
-14
@@ -60,20 +60,6 @@ public class SysMenuRepository implements ISysMenuRepository {
|
|||||||
@Override
|
@Override
|
||||||
public Mono<SysMenu> save(SysMenu sysMenu) {
|
public Mono<SysMenu> save(SysMenu sysMenu) {
|
||||||
SysMenuEntity entity = sysMenuConverter.toEntity(sysMenu);
|
SysMenuEntity entity = sysMenuConverter.toEntity(sysMenu);
|
||||||
if (entity.isNew()) {
|
|
||||||
return r2dbcEntityTemplate.insert(SysMenuEntity.class)
|
|
||||||
.using(entity)
|
|
||||||
.doOnNext(e -> e.markNotNew())
|
|
||||||
.map(sysMenuConverter::toDomain);
|
|
||||||
}
|
|
||||||
return sysMenuDao.save(entity)
|
|
||||||
.map(sysMenuConverter::toDomain);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<SysMenu> update(SysMenu sysMenu) {
|
|
||||||
SysMenuEntity entity = sysMenuConverter.toEntity(sysMenu);
|
|
||||||
entity.markNotNew();
|
|
||||||
return sysMenuDao.save(entity)
|
return sysMenuDao.save(entity)
|
||||||
.map(sysMenuConverter::toDomain);
|
.map(sysMenuConverter::toDomain);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-13
@@ -4,9 +4,7 @@ import cn.novalon.gym.manage.sys.core.domain.SysPermission;
|
|||||||
import cn.novalon.gym.manage.sys.core.repository.ISysPermissionRepository;
|
import cn.novalon.gym.manage.sys.core.repository.ISysPermissionRepository;
|
||||||
import cn.novalon.gym.manage.db.converter.SysPermissionConverter;
|
import cn.novalon.gym.manage.db.converter.SysPermissionConverter;
|
||||||
import cn.novalon.gym.manage.db.dao.SysPermissionDao;
|
import cn.novalon.gym.manage.db.dao.SysPermissionDao;
|
||||||
import cn.novalon.gym.manage.db.entity.SysPermissionEntity;
|
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
@@ -22,12 +20,10 @@ public class SysPermissionRepository implements ISysPermissionRepository {
|
|||||||
|
|
||||||
private final SysPermissionDao sysPermissionDao;
|
private final SysPermissionDao sysPermissionDao;
|
||||||
private final SysPermissionConverter sysPermissionConverter;
|
private final SysPermissionConverter sysPermissionConverter;
|
||||||
private final R2dbcEntityTemplate r2dbcEntityTemplate;
|
|
||||||
|
|
||||||
public SysPermissionRepository(SysPermissionDao sysPermissionDao, SysPermissionConverter sysPermissionConverter, R2dbcEntityTemplate r2dbcEntityTemplate) {
|
public SysPermissionRepository(SysPermissionDao sysPermissionDao, SysPermissionConverter sysPermissionConverter) {
|
||||||
this.sysPermissionDao = sysPermissionDao;
|
this.sysPermissionDao = sysPermissionDao;
|
||||||
this.sysPermissionConverter = sysPermissionConverter;
|
this.sysPermissionConverter = sysPermissionConverter;
|
||||||
this.r2dbcEntityTemplate = r2dbcEntityTemplate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -44,14 +40,7 @@ public class SysPermissionRepository implements ISysPermissionRepository {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<SysPermission> save(SysPermission sysPermission) {
|
public Mono<SysPermission> save(SysPermission sysPermission) {
|
||||||
SysPermissionEntity entity = sysPermissionConverter.toEntity(sysPermission);
|
return sysPermissionDao.save(sysPermissionConverter.toEntity(sysPermission))
|
||||||
if (entity.isNew()) {
|
|
||||||
return r2dbcEntityTemplate.insert(SysPermissionEntity.class)
|
|
||||||
.using(entity)
|
|
||||||
.doOnNext(e -> e.markNotNew())
|
|
||||||
.map(sysPermissionConverter::toDomain);
|
|
||||||
}
|
|
||||||
return sysPermissionDao.save(entity)
|
|
||||||
.map(sysPermissionConverter::toDomain);
|
.map(sysPermissionConverter::toDomain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-13
@@ -4,8 +4,6 @@ import cn.novalon.gym.manage.sys.core.domain.SysRolePermission;
|
|||||||
import cn.novalon.gym.manage.sys.core.repository.ISysRolePermissionRepository;
|
import cn.novalon.gym.manage.sys.core.repository.ISysRolePermissionRepository;
|
||||||
import cn.novalon.gym.manage.db.converter.SysRolePermissionConverter;
|
import cn.novalon.gym.manage.db.converter.SysRolePermissionConverter;
|
||||||
import cn.novalon.gym.manage.db.dao.SysRolePermissionDao;
|
import cn.novalon.gym.manage.db.dao.SysRolePermissionDao;
|
||||||
import cn.novalon.gym.manage.db.entity.SysRolePermissionEntity;
|
|
||||||
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
@@ -21,24 +19,15 @@ public class SysRolePermissionRepository implements ISysRolePermissionRepository
|
|||||||
|
|
||||||
private final SysRolePermissionDao sysRolePermissionDao;
|
private final SysRolePermissionDao sysRolePermissionDao;
|
||||||
private final SysRolePermissionConverter sysRolePermissionConverter;
|
private final SysRolePermissionConverter sysRolePermissionConverter;
|
||||||
private final R2dbcEntityTemplate r2dbcEntityTemplate;
|
|
||||||
|
|
||||||
public SysRolePermissionRepository(SysRolePermissionDao sysRolePermissionDao, SysRolePermissionConverter sysRolePermissionConverter, R2dbcEntityTemplate r2dbcEntityTemplate) {
|
public SysRolePermissionRepository(SysRolePermissionDao sysRolePermissionDao, SysRolePermissionConverter sysRolePermissionConverter) {
|
||||||
this.sysRolePermissionDao = sysRolePermissionDao;
|
this.sysRolePermissionDao = sysRolePermissionDao;
|
||||||
this.sysRolePermissionConverter = sysRolePermissionConverter;
|
this.sysRolePermissionConverter = sysRolePermissionConverter;
|
||||||
this.r2dbcEntityTemplate = r2dbcEntityTemplate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<SysRolePermission> save(SysRolePermission rolePermission) {
|
public Mono<SysRolePermission> save(SysRolePermission rolePermission) {
|
||||||
SysRolePermissionEntity entity = sysRolePermissionConverter.toEntity(rolePermission);
|
return sysRolePermissionDao.save(sysRolePermissionConverter.toEntity(rolePermission))
|
||||||
if (entity.isNew()) {
|
|
||||||
return r2dbcEntityTemplate.insert(SysRolePermissionEntity.class)
|
|
||||||
.using(entity)
|
|
||||||
.doOnNext(e -> e.markNotNew())
|
|
||||||
.map(sysRolePermissionConverter::toDomain);
|
|
||||||
}
|
|
||||||
return sysRolePermissionDao.save(entity)
|
|
||||||
.map(sysRolePermissionConverter::toDomain);
|
.map(sysRolePermissionConverter::toDomain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
-7
@@ -53,12 +53,6 @@ public class SysRoleRepository implements ISysRoleRepository {
|
|||||||
@Override
|
@Override
|
||||||
public Mono<SysRole> save(SysRole sysRole) {
|
public Mono<SysRole> save(SysRole sysRole) {
|
||||||
SysRoleEntity entity = sysRoleConverter.toEntity(sysRole);
|
SysRoleEntity entity = sysRoleConverter.toEntity(sysRole);
|
||||||
if (entity.isNew()) {
|
|
||||||
return r2dbcEntityTemplate.insert(SysRoleEntity.class)
|
|
||||||
.using(entity)
|
|
||||||
.doOnNext(e -> e.markNotNew())
|
|
||||||
.map(sysRoleConverter::toDomain);
|
|
||||||
}
|
|
||||||
return sysRoleDao.save(entity)
|
return sysRoleDao.save(entity)
|
||||||
.map(sysRoleConverter::toDomain);
|
.map(sysRoleConverter::toDomain);
|
||||||
}
|
}
|
||||||
@@ -162,7 +156,6 @@ public class SysRoleRepository implements ISysRoleRepository {
|
|||||||
@Override
|
@Override
|
||||||
public Mono<SysRole> updateRole(SysRole role) {
|
public Mono<SysRole> updateRole(SysRole role) {
|
||||||
SysRoleEntity entity = sysRoleConverter.toEntity(role);
|
SysRoleEntity entity = sysRoleConverter.toEntity(role);
|
||||||
entity.markNotNew();
|
|
||||||
return sysRoleDao.save(entity)
|
return sysRoleDao.save(entity)
|
||||||
.map(sysRoleConverter::toDomain);
|
.map(sysRoleConverter::toDomain);
|
||||||
}
|
}
|
||||||
|
|||||||
-16
@@ -70,20 +70,6 @@ public class SysUserRepository implements ISysUserRepository {
|
|||||||
@Override
|
@Override
|
||||||
public Mono<SysUser> save(SysUser sysUser) {
|
public Mono<SysUser> save(SysUser sysUser) {
|
||||||
SysUserEntity entity = sysUserConverter.toEntity(sysUser);
|
SysUserEntity entity = sysUserConverter.toEntity(sysUser);
|
||||||
if (entity.isNew()) {
|
|
||||||
return r2dbcEntityTemplate.insert(SysUserEntity.class)
|
|
||||||
.using(entity)
|
|
||||||
.doOnNext(e -> e.markNotNew())
|
|
||||||
.map(sysUserConverter::toDomain);
|
|
||||||
}
|
|
||||||
return sysUserDao.save(entity)
|
|
||||||
.map(sysUserConverter::toDomain);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<SysUser> update(SysUser sysUser) {
|
|
||||||
SysUserEntity entity = sysUserConverter.toEntity(sysUser);
|
|
||||||
entity.markNotNew();
|
|
||||||
return sysUserDao.save(entity)
|
return sysUserDao.save(entity)
|
||||||
.map(sysUserConverter::toDomain);
|
.map(sysUserConverter::toDomain);
|
||||||
}
|
}
|
||||||
@@ -190,7 +176,6 @@ public class SysUserRepository implements ISysUserRepository {
|
|||||||
public Mono<Void> logicalDeleteById(Long id) {
|
public Mono<Void> logicalDeleteById(Long id) {
|
||||||
return sysUserDao.findById(id)
|
return sysUserDao.findById(id)
|
||||||
.flatMap(entity -> {
|
.flatMap(entity -> {
|
||||||
entity.markNotNew();
|
|
||||||
entity.setDeletedAt(java.time.LocalDateTime.now());
|
entity.setDeletedAt(java.time.LocalDateTime.now());
|
||||||
return sysUserDao.save(entity).then();
|
return sysUserDao.save(entity).then();
|
||||||
});
|
});
|
||||||
@@ -207,7 +192,6 @@ public class SysUserRepository implements ISysUserRepository {
|
|||||||
public Mono<Void> restoreById(Long id) {
|
public Mono<Void> restoreById(Long id) {
|
||||||
return sysUserDao.findById(id)
|
return sysUserDao.findById(id)
|
||||||
.flatMap(entity -> {
|
.flatMap(entity -> {
|
||||||
entity.markNotNew();
|
|
||||||
entity.setDeletedAt(null);
|
entity.setDeletedAt(null);
|
||||||
return sysUserDao.save(entity).then();
|
return sysUserDao.save(entity).then();
|
||||||
});
|
});
|
||||||
|
|||||||
+51
@@ -0,0 +1,51 @@
|
|||||||
|
-- Novalon管理系统普通用户角色和数据
|
||||||
|
-- 版本: V10
|
||||||
|
-- 描述: 创建普通用户角色并分配权限
|
||||||
|
|
||||||
|
-- 插入普通用户角色
|
||||||
|
INSERT INTO sys_role (role_name, role_key, role_sort, status, create_by, update_by)
|
||||||
|
VALUES ('普通用户', 'user', 2, 1, 'system', 'system')
|
||||||
|
ON CONFLICT (role_key) DO UPDATE SET
|
||||||
|
role_name = EXCLUDED.role_name,
|
||||||
|
role_sort = EXCLUDED.role_sort,
|
||||||
|
status = EXCLUDED.status;
|
||||||
|
|
||||||
|
-- 为普通用户分配基本权限(查看个人信息、修改密码等)
|
||||||
|
-- 注意:这里只分配基本权限,不包含管理功能权限
|
||||||
|
INSERT INTO sys_permission (permission_name, permission_key, permission_type, parent_id, path, component, icon, sort, status, create_by, update_by)
|
||||||
|
VALUES
|
||||||
|
('个人中心', 'profile', 'MENU', 0, '/profile', 'views/profile/index', 'user', 1, 1, 'system', 'system'),
|
||||||
|
('个人信息', 'profile:info', 'BUTTON', (SELECT id FROM sys_permission WHERE permission_key = 'profile'), '', '', '', 1, 1, 'system', 'system'),
|
||||||
|
('修改密码', 'profile:password', 'BUTTON', (SELECT id FROM sys_permission WHERE permission_key = 'profile'), '', '', '', 2, 1, 'system', 'system')
|
||||||
|
ON CONFLICT (permission_key) DO NOTHING;
|
||||||
|
|
||||||
|
-- 为普通用户角色分配权限
|
||||||
|
INSERT INTO sys_role_permission (role_id, permission_id, create_by, update_by)
|
||||||
|
SELECT
|
||||||
|
r.id as role_id,
|
||||||
|
p.id as permission_id,
|
||||||
|
'system' as create_by,
|
||||||
|
'system' as update_by
|
||||||
|
FROM sys_role r
|
||||||
|
CROSS JOIN sys_permission p
|
||||||
|
WHERE r.role_key = 'user'
|
||||||
|
AND p.permission_key IN ('profile', 'profile:info', 'profile:password')
|
||||||
|
ON CONFLICT DO NOTHING;
|
||||||
|
|
||||||
|
-- 将测试用户分配给普通用户角色
|
||||||
|
INSERT INTO user_role (user_id, role_id, create_by, update_by)
|
||||||
|
SELECT
|
||||||
|
u.id as user_id,
|
||||||
|
r.id as role_id,
|
||||||
|
'system' as create_by,
|
||||||
|
'system' as update_by
|
||||||
|
FROM sys_user u
|
||||||
|
CROSS JOIN sys_role r
|
||||||
|
WHERE u.username = 'user' AND r.role_key = 'user'
|
||||||
|
ON CONFLICT DO NOTHING;
|
||||||
|
|
||||||
|
-- 重置序列值
|
||||||
|
SELECT setval('sys_role_id_seq', (SELECT COALESCE(MAX(id), 1) FROM sys_role));
|
||||||
|
SELECT setval('sys_permission_id_seq', (SELECT COALESCE(MAX(id), 1) FROM sys_permission));
|
||||||
|
SELECT setval('sys_role_permission_id_seq', (SELECT COALESCE(MAX(id), 1) FROM sys_role_permission));
|
||||||
|
SELECT setval('user_role_id_seq', (SELECT COALESCE(MAX(id), 1) FROM user_role));
|
||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
-- Novalon管理系统测试数据脚本
|
||||||
|
-- 版本: V11
|
||||||
|
-- 描述: 更新测试用户密码为Test@123,插入E2E测试所需数据
|
||||||
|
|
||||||
|
-- 更新admin用户密码为Test@123
|
||||||
|
-- BCrypt哈希值对应明文密码: Test@123
|
||||||
|
UPDATE sys_user
|
||||||
|
SET password = '$2a$12$nZ1EMUpZQljbnEdIKzH72eHlDJKUmHmHppnTTVth/SlHs5VpSAr8C'
|
||||||
|
WHERE username = 'admin';
|
||||||
|
|
||||||
|
-- 更新user用户密码为Test@123
|
||||||
|
UPDATE sys_user
|
||||||
|
SET password = '$2a$12$nZ1EMUpZQljbnEdIKzH72eHlDJKUmHmHppnTTVth/SlHs5VpSAr8C'
|
||||||
|
WHERE username = 'user';
|
||||||
|
|
||||||
|
-- 插入测试角色(如果不存在)
|
||||||
|
INSERT INTO sys_role (role_name, role_key, role_sort, status, create_by, update_by)
|
||||||
|
VALUES
|
||||||
|
('测试管理员', 'test_admin', 2, 1, 'system', 'system'),
|
||||||
|
('普通用户', 'normal_user', 3, 1, 'system', 'system'),
|
||||||
|
('访客', 'guest', 4, 1, 'system', 'system')
|
||||||
|
ON CONFLICT (role_key) DO NOTHING;
|
||||||
|
|
||||||
|
-- 为admin用户分配超级管理员角色
|
||||||
|
INSERT INTO user_role (user_id, role_id, created_by)
|
||||||
|
SELECT 1, id, 'system' FROM sys_role WHERE role_key = 'admin'
|
||||||
|
ON CONFLICT DO NOTHING;
|
||||||
|
|
||||||
|
-- 为user用户分配普通用户角色
|
||||||
|
INSERT INTO user_role (user_id, role_id, created_by)
|
||||||
|
SELECT 2, id, 'system' FROM sys_role WHERE role_key = 'normal_user'
|
||||||
|
ON CONFLICT DO NOTHING;
|
||||||
|
|
||||||
|
-- 插入E2E测试专用用户
|
||||||
|
-- BCrypt哈希值对应明文密码: Test@123
|
||||||
|
INSERT INTO sys_user (id, username, password, email, phone, nickname, status, create_by, update_by)
|
||||||
|
VALUES
|
||||||
|
(10, 'e2e_test_user', '$2a$12$nZ1EMUpZQljbnEdIKzH72eHlDJKUmHmHppnTTVth/SlHs5VpSAr8C', 'e2e@test.com', '13900139000', 'E2E测试用户', 1, 'system', 'system')
|
||||||
|
ON CONFLICT (username) DO UPDATE SET
|
||||||
|
password = EXCLUDED.password,
|
||||||
|
status = EXCLUDED.status;
|
||||||
|
|
||||||
|
-- 为E2E测试用户分配超级管理员角色
|
||||||
|
INSERT INTO user_role (user_id, role_id, created_by)
|
||||||
|
SELECT 10, id, 'system' FROM sys_role WHERE role_key = 'admin'
|
||||||
|
ON CONFLICT DO NOTHING;
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
-- V14__Fix_menu_data.sql
|
||||||
|
-- 清理测试菜单数据
|
||||||
|
DELETE FROM sys_menu WHERE menu_name LIKE '%测试%' OR menu_name LIKE '%回归%';
|
||||||
|
|
||||||
|
-- 插入一级菜单
|
||||||
|
INSERT INTO sys_menu (menu_name, parent_id, order_num, menu_type, status, created_at, updated_at) VALUES
|
||||||
|
('系统管理', 0, 1, 'M', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
|
||||||
|
('系统监控', 0, 2, 'M', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
|
||||||
|
('审计日志', 0, 3, 'M', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
|
||||||
|
|
||||||
|
-- 插入二级菜单(系统管理下)
|
||||||
|
INSERT INTO sys_menu (menu_name, parent_id, order_num, menu_type, component, perms, status, created_at, updated_at) VALUES
|
||||||
|
('用户管理', (SELECT id FROM sys_menu WHERE menu_name = '系统管理' AND parent_id = 0), 1, 'C', 'system/user/index', 'system:user:list', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
|
||||||
|
('角色管理', (SELECT id FROM sys_menu WHERE menu_name = '系统管理' AND parent_id = 0), 2, 'C', 'system/role/index', 'system:role:list', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
|
||||||
|
('菜单管理', (SELECT id FROM sys_menu WHERE menu_name = '系统管理' AND parent_id = 0), 3, 'C', 'system/menu/index', 'system:menu:list', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
|
||||||
|
('参数配置', (SELECT id FROM sys_menu WHERE menu_name = '系统管理' AND parent_id = 0), 4, 'C', 'system/config/index', 'system:config:list', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
|
||||||
|
('字典管理', (SELECT id FROM sys_menu WHERE menu_name = '系统管理' AND parent_id = 0), 5, 'C', 'system/dict/index', 'system:dict:list', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
|
||||||
|
|
||||||
|
-- 插入二级菜单(系统监控下)
|
||||||
|
INSERT INTO sys_menu (menu_name, parent_id, order_num, menu_type, component, perms, status, created_at, updated_at) VALUES
|
||||||
|
('文件管理', (SELECT id FROM sys_menu WHERE menu_name = '系统监控' AND parent_id = 0), 1, 'C', 'system/file/index', 'system:file:list', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
|
||||||
|
('通知公告', (SELECT id FROM sys_menu WHERE menu_name = '系统监控' AND parent_id = 0), 2, 'C', 'system/notice/index', 'system:notice:list', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
|
||||||
|
|
||||||
|
-- 插入二级菜单(审计日志下)
|
||||||
|
INSERT INTO sys_menu (menu_name, parent_id, order_num, menu_type, component, perms, status, created_at, updated_at) VALUES
|
||||||
|
('登录日志', (SELECT id FROM sys_menu WHERE menu_name = '审计日志' AND parent_id = 0), 1, 'C', 'audit/login/index', 'audit:login:list', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
|
||||||
|
('操作日志', (SELECT id FROM sys_menu WHERE menu_name = '审计日志' AND parent_id = 0), 2, 'C', 'audit/operation/index', 'audit:operation:list', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
|
||||||
|
('异常日志', (SELECT id FROM sys_menu WHERE menu_name = '审计日志' AND parent_id = 0), 3, 'C', 'audit/exception/index', 'audit:exception:list', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
-- Novalon管理系统审计日志表补充字段
|
||||||
|
-- 版本: V15
|
||||||
|
-- 描述: 为审计日志表添加缺失的基础字段,与BaseDomain保持一致
|
||||||
|
ALTER TABLE audit_log ADD COLUMN IF NOT EXISTS create_by VARCHAR(50);
|
||||||
|
ALTER TABLE audit_log ADD COLUMN IF NOT EXISTS update_by VARCHAR(50);
|
||||||
|
ALTER TABLE audit_log ADD COLUMN IF NOT EXISTS updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
ALTER TABLE audit_log ADD COLUMN IF NOT EXISTS deleted_at TIMESTAMP;
|
||||||
|
|
||||||
|
COMMENT ON COLUMN audit_log.create_by IS '创建人';
|
||||||
|
COMMENT ON COLUMN audit_log.update_by IS '更新人';
|
||||||
|
COMMENT ON COLUMN audit_log.updated_at IS '更新时间';
|
||||||
|
COMMENT ON COLUMN audit_log.deleted_at IS '删除时间';
|
||||||
+19
-202
@@ -1,31 +1,25 @@
|
|||||||
-- Novalon管理系统数据库初始化脚本
|
-- Novalon管理系统数据库初始化脚本
|
||||||
-- 版本: V1
|
-- 版本: V1
|
||||||
-- 描述: 创建所有核心表结构(合并版)
|
-- 描述: 创建所有核心表结构
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 用户与角色相关表
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 用户表
|
-- 用户表
|
||||||
CREATE TABLE IF NOT EXISTS sys_user (
|
CREATE TABLE IF NOT EXISTS sys_user (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGINT PRIMARY KEY,
|
||||||
username VARCHAR(50) NOT NULL UNIQUE,
|
username VARCHAR(50) NOT NULL UNIQUE,
|
||||||
password VARCHAR(255) NOT NULL,
|
password VARCHAR(255) NOT NULL,
|
||||||
email VARCHAR(100),
|
email VARCHAR(100),
|
||||||
phone VARCHAR(20),
|
phone VARCHAR(20),
|
||||||
nickname VARCHAR(100),
|
nickname VARCHAR(100),
|
||||||
status INTEGER DEFAULT 1,
|
|
||||||
role_id BIGINT,
|
role_id BIGINT,
|
||||||
|
status INTEGER DEFAULT 1,
|
||||||
create_by VARCHAR(50),
|
create_by VARCHAR(50),
|
||||||
update_by VARCHAR(50),
|
update_by VARCHAR(50),
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
deleted_at TIMESTAMP
|
deleted_at TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
-- 角色表
|
-- 角色表
|
||||||
CREATE TABLE IF NOT EXISTS sys_role (
|
CREATE TABLE IF NOT EXISTS sys_role (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGINT PRIMARY KEY,
|
||||||
role_name VARCHAR(100) NOT NULL,
|
role_name VARCHAR(100) NOT NULL,
|
||||||
role_key VARCHAR(100) NOT NULL UNIQUE,
|
role_key VARCHAR(100) NOT NULL UNIQUE,
|
||||||
role_sort INTEGER DEFAULT 0,
|
role_sort INTEGER DEFAULT 0,
|
||||||
@@ -36,60 +30,9 @@ CREATE TABLE IF NOT EXISTS sys_role (
|
|||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
deleted_at TIMESTAMP
|
deleted_at TIMESTAMP
|
||||||
);
|
);
|
||||||
|
-- 菜单表(统一使用sys_menu表名)
|
||||||
-- 用户角色关联表(支持多对多关系)
|
|
||||||
CREATE TABLE IF NOT EXISTS user_role (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
user_id BIGINT NOT NULL,
|
|
||||||
role_id BIGINT NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
created_by VARCHAR(50),
|
|
||||||
CONSTRAINT fk_user_role_user FOREIGN KEY (user_id) REFERENCES sys_user(id) ON DELETE CASCADE,
|
|
||||||
CONSTRAINT fk_user_role_role FOREIGN KEY (role_id) REFERENCES sys_role(id) ON DELETE CASCADE,
|
|
||||||
CONSTRAINT uk_user_role UNIQUE (user_id, role_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 权限相关表
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 权限表
|
|
||||||
CREATE TABLE IF NOT EXISTS sys_permission (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
permission_name VARCHAR(100) NOT NULL,
|
|
||||||
permission_code VARCHAR(100) NOT NULL UNIQUE,
|
|
||||||
resource VARCHAR(200) NOT NULL,
|
|
||||||
action VARCHAR(50) NOT NULL,
|
|
||||||
description VARCHAR(500),
|
|
||||||
status INTEGER DEFAULT 1,
|
|
||||||
create_by VARCHAR(50),
|
|
||||||
update_by VARCHAR(50),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
deleted_at TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- 角色权限关联表
|
|
||||||
CREATE TABLE IF NOT EXISTS sys_role_permission (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
role_id BIGINT NOT NULL,
|
|
||||||
permission_id BIGINT NOT NULL,
|
|
||||||
create_by VARCHAR(50),
|
|
||||||
update_by VARCHAR(50),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (role_id) REFERENCES sys_role(id) ON DELETE CASCADE,
|
|
||||||
FOREIGN KEY (permission_id) REFERENCES sys_permission(id) ON DELETE CASCADE,
|
|
||||||
UNIQUE (role_id, permission_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 菜单相关表
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 菜单表
|
|
||||||
CREATE TABLE IF NOT EXISTS sys_menu (
|
CREATE TABLE IF NOT EXISTS sys_menu (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGINT PRIMARY KEY,
|
||||||
menu_name VARCHAR(50) NOT NULL,
|
menu_name VARCHAR(50) NOT NULL,
|
||||||
parent_id BIGINT DEFAULT 0,
|
parent_id BIGINT DEFAULT 0,
|
||||||
order_num INTEGER DEFAULT 0,
|
order_num INTEGER DEFAULT 0,
|
||||||
@@ -103,14 +46,9 @@ CREATE TABLE IF NOT EXISTS sys_menu (
|
|||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
deleted_at TIMESTAMP
|
deleted_at TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 字典相关表
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 字典类型表
|
-- 字典类型表
|
||||||
CREATE TABLE IF NOT EXISTS sys_dict_type (
|
CREATE TABLE IF NOT EXISTS sys_dict_type (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGINT PRIMARY KEY,
|
||||||
dict_name VARCHAR(100) NOT NULL,
|
dict_name VARCHAR(100) NOT NULL,
|
||||||
dict_type VARCHAR(100) NOT NULL UNIQUE,
|
dict_type VARCHAR(100) NOT NULL UNIQUE,
|
||||||
status VARCHAR(1) DEFAULT '0',
|
status VARCHAR(1) DEFAULT '0',
|
||||||
@@ -121,10 +59,9 @@ CREATE TABLE IF NOT EXISTS sys_dict_type (
|
|||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
deleted_at TIMESTAMP
|
deleted_at TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
-- 字典数据表
|
-- 字典数据表
|
||||||
CREATE TABLE IF NOT EXISTS sys_dict_data (
|
CREATE TABLE IF NOT EXISTS sys_dict_data (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGINT PRIMARY KEY,
|
||||||
dict_sort INTEGER DEFAULT 0,
|
dict_sort INTEGER DEFAULT 0,
|
||||||
dict_label VARCHAR(100) NOT NULL,
|
dict_label VARCHAR(100) NOT NULL,
|
||||||
dict_value VARCHAR(100) NOT NULL,
|
dict_value VARCHAR(100) NOT NULL,
|
||||||
@@ -139,10 +76,9 @@ CREATE TABLE IF NOT EXISTS sys_dict_data (
|
|||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
deleted_at TIMESTAMP
|
deleted_at TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
-- 字典表(通用字典)
|
-- 字典表(通用字典)
|
||||||
CREATE TABLE IF NOT EXISTS sys_dictionary (
|
CREATE TABLE IF NOT EXISTS sys_dictionary (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGINT PRIMARY KEY,
|
||||||
type VARCHAR(100) NOT NULL,
|
type VARCHAR(100) NOT NULL,
|
||||||
code VARCHAR(100) NOT NULL,
|
code VARCHAR(100) NOT NULL,
|
||||||
name VARCHAR(100) NOT NULL,
|
name VARCHAR(100) NOT NULL,
|
||||||
@@ -154,14 +90,9 @@ CREATE TABLE IF NOT EXISTS sys_dictionary (
|
|||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
deleted_at TIMESTAMP
|
deleted_at TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 系统配置表
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 系统配置表
|
-- 系统配置表
|
||||||
CREATE TABLE IF NOT EXISTS sys_config (
|
CREATE TABLE IF NOT EXISTS sys_config (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGINT PRIMARY KEY,
|
||||||
config_name VARCHAR(100) NOT NULL,
|
config_name VARCHAR(100) NOT NULL,
|
||||||
config_key VARCHAR(100) NOT NULL UNIQUE,
|
config_key VARCHAR(100) NOT NULL UNIQUE,
|
||||||
config_value VARCHAR(500) NOT NULL,
|
config_value VARCHAR(500) NOT NULL,
|
||||||
@@ -172,14 +103,9 @@ CREATE TABLE IF NOT EXISTS sys_config (
|
|||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
deleted_at TIMESTAMP
|
deleted_at TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 日志相关表
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 登录日志表
|
-- 登录日志表
|
||||||
CREATE TABLE IF NOT EXISTS sys_login_log (
|
CREATE TABLE IF NOT EXISTS sys_login_log (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGINT PRIMARY KEY,
|
||||||
username VARCHAR(50),
|
username VARCHAR(50),
|
||||||
ip VARCHAR(50),
|
ip VARCHAR(50),
|
||||||
location VARCHAR(255),
|
location VARCHAR(255),
|
||||||
@@ -189,10 +115,9 @@ CREATE TABLE IF NOT EXISTS sys_login_log (
|
|||||||
message VARCHAR(255),
|
message VARCHAR(255),
|
||||||
login_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
login_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
-- 异常日志表
|
-- 异常日志表
|
||||||
CREATE TABLE IF NOT EXISTS sys_exception_log (
|
CREATE TABLE IF NOT EXISTS sys_exception_log (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGINT PRIMARY KEY,
|
||||||
username VARCHAR(50),
|
username VARCHAR(50),
|
||||||
title VARCHAR(100),
|
title VARCHAR(100),
|
||||||
exception_name VARCHAR(100),
|
exception_name VARCHAR(100),
|
||||||
@@ -203,10 +128,9 @@ CREATE TABLE IF NOT EXISTS sys_exception_log (
|
|||||||
ip VARCHAR(50),
|
ip VARCHAR(50),
|
||||||
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
-- 操作日志表
|
-- 操作日志表
|
||||||
CREATE TABLE IF NOT EXISTS operation_log (
|
CREATE TABLE IF NOT EXISTS operation_log (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGINT PRIMARY KEY,
|
||||||
username VARCHAR(50),
|
username VARCHAR(50),
|
||||||
operation VARCHAR(100),
|
operation VARCHAR(100),
|
||||||
method VARCHAR(200),
|
method VARCHAR(200),
|
||||||
@@ -222,53 +146,9 @@ CREATE TABLE IF NOT EXISTS operation_log (
|
|||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
deleted_at TIMESTAMP
|
deleted_at TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
-- 审计日志表
|
|
||||||
CREATE TABLE IF NOT EXISTS audit_log (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
entity_type VARCHAR(100) NOT NULL,
|
|
||||||
entity_id BIGINT,
|
|
||||||
operation_type VARCHAR(20) NOT NULL,
|
|
||||||
operator VARCHAR(100),
|
|
||||||
operation_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
before_data JSONB,
|
|
||||||
after_data JSONB,
|
|
||||||
changed_fields TEXT[],
|
|
||||||
ip_address VARCHAR(50),
|
|
||||||
user_agent TEXT,
|
|
||||||
description TEXT,
|
|
||||||
create_by VARCHAR(50),
|
|
||||||
update_by VARCHAR(50),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
deleted_at TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- 审计日志归档表
|
|
||||||
CREATE TABLE IF NOT EXISTS audit_log_archive (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
entity_type VARCHAR(100) NOT NULL,
|
|
||||||
entity_id BIGINT,
|
|
||||||
operation_type VARCHAR(20) NOT NULL,
|
|
||||||
operator VARCHAR(100),
|
|
||||||
operation_time TIMESTAMP,
|
|
||||||
before_data JSONB,
|
|
||||||
after_data JSONB,
|
|
||||||
changed_fields TEXT[],
|
|
||||||
ip_address VARCHAR(50),
|
|
||||||
user_agent TEXT,
|
|
||||||
description TEXT,
|
|
||||||
created_at TIMESTAMP,
|
|
||||||
archived_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 通知与消息表
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 系统公告表
|
-- 系统公告表
|
||||||
CREATE TABLE IF NOT EXISTS sys_notice (
|
CREATE TABLE IF NOT EXISTS sys_notice (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGINT PRIMARY KEY,
|
||||||
notice_title VARCHAR(50) NOT NULL,
|
notice_title VARCHAR(50) NOT NULL,
|
||||||
notice_type VARCHAR(1) NOT NULL,
|
notice_type VARCHAR(1) NOT NULL,
|
||||||
notice_content TEXT,
|
notice_content TEXT,
|
||||||
@@ -279,10 +159,9 @@ CREATE TABLE IF NOT EXISTS sys_notice (
|
|||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
deleted_at TIMESTAMP
|
deleted_at TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
-- 用户消息表
|
-- 用户消息表
|
||||||
CREATE TABLE IF NOT EXISTS sys_user_message (
|
CREATE TABLE IF NOT EXISTS sys_user_message (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGINT PRIMARY KEY,
|
||||||
user_id BIGINT NOT NULL,
|
user_id BIGINT NOT NULL,
|
||||||
notice_id BIGINT,
|
notice_id BIGINT,
|
||||||
message_title VARCHAR(255),
|
message_title VARCHAR(255),
|
||||||
@@ -295,14 +174,9 @@ CREATE TABLE IF NOT EXISTS sys_user_message (
|
|||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
deleted_at TIMESTAMP
|
deleted_at TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 文件管理表
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 文件管理表
|
-- 文件管理表
|
||||||
CREATE TABLE IF NOT EXISTS sys_file (
|
CREATE TABLE IF NOT EXISTS sys_file (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGINT PRIMARY KEY,
|
||||||
file_name VARCHAR(255) NOT NULL,
|
file_name VARCHAR(255) NOT NULL,
|
||||||
file_path VARCHAR(500) NOT NULL,
|
file_path VARCHAR(500) NOT NULL,
|
||||||
file_size BIGINT,
|
file_size BIGINT,
|
||||||
@@ -315,14 +189,9 @@ CREATE TABLE IF NOT EXISTS sys_file (
|
|||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
deleted_at TIMESTAMP
|
deleted_at TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- OAuth2相关表
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- OAuth2客户端表
|
-- OAuth2客户端表
|
||||||
CREATE TABLE IF NOT EXISTS oauth2_client (
|
CREATE TABLE IF NOT EXISTS oauth2_client (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGINT PRIMARY KEY,
|
||||||
client_id VARCHAR(100) NOT NULL UNIQUE,
|
client_id VARCHAR(100) NOT NULL UNIQUE,
|
||||||
client_secret VARCHAR(255) NOT NULL,
|
client_secret VARCHAR(255) NOT NULL,
|
||||||
client_name VARCHAR(100),
|
client_name VARCHAR(100),
|
||||||
@@ -339,31 +208,7 @@ CREATE TABLE IF NOT EXISTS oauth2_client (
|
|||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
deleted_at TIMESTAMP
|
deleted_at TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 表注释
|
-- 表注释
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
COMMENT ON TABLE sys_user IS '系统用户表';
|
|
||||||
COMMENT ON TABLE sys_role IS '系统角色表';
|
|
||||||
COMMENT ON TABLE user_role IS '用户角色关联表';
|
|
||||||
COMMENT ON TABLE sys_permission IS '系统权限表';
|
|
||||||
COMMENT ON TABLE sys_role_permission IS '角色权限关联表';
|
|
||||||
COMMENT ON TABLE sys_menu IS '系统菜单表';
|
|
||||||
COMMENT ON TABLE sys_dict_type IS '字典类型表';
|
|
||||||
COMMENT ON TABLE sys_dict_data IS '字典数据表';
|
|
||||||
COMMENT ON TABLE sys_dictionary IS '通用字典表';
|
|
||||||
COMMENT ON TABLE sys_config IS '系统配置表';
|
|
||||||
COMMENT ON TABLE sys_login_log IS '登录日志表';
|
|
||||||
COMMENT ON TABLE sys_exception_log IS '异常日志表';
|
|
||||||
COMMENT ON TABLE operation_log IS '操作日志表';
|
|
||||||
COMMENT ON TABLE audit_log IS '审计日志表';
|
|
||||||
COMMENT ON TABLE audit_log_archive IS '审计日志归档表';
|
|
||||||
COMMENT ON TABLE sys_notice IS '系统公告表';
|
|
||||||
COMMENT ON TABLE sys_user_message IS '用户消息表';
|
|
||||||
COMMENT ON TABLE sys_file IS '文件管理表';
|
|
||||||
COMMENT ON TABLE oauth2_client IS 'OAuth2客户端表';
|
|
||||||
|
|
||||||
COMMENT ON TABLE sys_exception_log IS '异常日志表';
|
COMMENT ON TABLE sys_exception_log IS '异常日志表';
|
||||||
COMMENT ON COLUMN sys_exception_log.id IS '主键ID';
|
COMMENT ON COLUMN sys_exception_log.id IS '主键ID';
|
||||||
COMMENT ON COLUMN sys_exception_log.username IS '操作用户';
|
COMMENT ON COLUMN sys_exception_log.username IS '操作用户';
|
||||||
@@ -375,33 +220,5 @@ COMMENT ON COLUMN sys_exception_log.exception_msg IS '异常消息';
|
|||||||
COMMENT ON COLUMN sys_exception_log.exception_stack IS '异常堆栈';
|
COMMENT ON COLUMN sys_exception_log.exception_stack IS '异常堆栈';
|
||||||
COMMENT ON COLUMN sys_exception_log.ip IS 'IP地址';
|
COMMENT ON COLUMN sys_exception_log.ip IS 'IP地址';
|
||||||
COMMENT ON COLUMN sys_exception_log.create_time IS '创建时间';
|
COMMENT ON COLUMN sys_exception_log.create_time IS '创建时间';
|
||||||
|
COMMENT ON TABLE sys_menu IS '系统菜单表';
|
||||||
COMMENT ON TABLE audit_log IS '审计日志表';
|
COMMENT ON TABLE sys_login_log IS '登录日志表';
|
||||||
COMMENT ON COLUMN audit_log.id IS '主键ID';
|
|
||||||
COMMENT ON COLUMN audit_log.entity_type IS '实体类型(如User, Role等)';
|
|
||||||
COMMENT ON COLUMN audit_log.entity_id IS '实体ID';
|
|
||||||
COMMENT ON COLUMN audit_log.operation_type IS '操作类型(CREATE, UPDATE, DELETE)';
|
|
||||||
COMMENT ON COLUMN audit_log.operator IS '操作人';
|
|
||||||
COMMENT ON COLUMN audit_log.operation_time IS '操作时间';
|
|
||||||
COMMENT ON COLUMN audit_log.before_data IS '变更前数据(JSON格式)';
|
|
||||||
COMMENT ON COLUMN audit_log.after_data IS '变更后数据(JSON格式)';
|
|
||||||
COMMENT ON COLUMN audit_log.changed_fields IS '变更字段列表';
|
|
||||||
COMMENT ON COLUMN audit_log.ip_address IS 'IP地址';
|
|
||||||
COMMENT ON COLUMN audit_log.description IS '操作描述';
|
|
||||||
COMMENT ON COLUMN audit_log.created_at IS '记录创建时间';
|
|
||||||
|
|
||||||
COMMENT ON TABLE audit_log_archive IS '审计日志归档表';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.id IS '主键ID';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.entity_type IS '实体类型(如User, Role等)';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.entity_id IS '实体ID';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.operation_type IS '操作类型(CREATE, UPDATE, DELETE)';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.operator IS '操作人';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.operation_time IS '操作时间';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.before_data IS '变更前数据(JSON格式)';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.after_data IS '变更后数据(JSON格式)';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.changed_fields IS '变更字段列表';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.ip_address IS 'IP地址';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.user_agent IS '用户代理';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.description IS '操作描述';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.created_at IS '记录创建时间';
|
|
||||||
COMMENT ON COLUMN audit_log_archive.archived_at IS '归档时间';
|
|
||||||
+43
-209
@@ -1,233 +1,67 @@
|
|||||||
-- Novalon管理系统初始数据脚本
|
-- Novalon管理系统初始数据脚本
|
||||||
-- 版本: V2
|
-- 版本: V2
|
||||||
-- 描述: 插入所有必要的初始数据(合并版)
|
-- 描述: 插入必要的初始数据
|
||||||
|
|
||||||
-- ============================================
|
-- 插入初始角色
|
||||||
-- 角色数据
|
INSERT INTO sys_role (role_name, role_key, role_sort, status, create_by, update_by)
|
||||||
-- ============================================
|
VALUES ('超级管理员', 'admin', 1, 1, 'system', 'system')
|
||||||
|
ON CONFLICT (role_key) DO NOTHING;
|
||||||
|
|
||||||
INSERT INTO sys_role (id, role_name, role_key, role_sort, status, create_by, update_by, created_at, updated_at)
|
-- 插入初始管理员用户
|
||||||
VALUES
|
-- BCrypt哈希值对应明文密码: admin123
|
||||||
(1, '超级管理员', 'admin', 1, 1, 'system', 'system', NOW(), NOW()),
|
INSERT INTO sys_user (id, username, password, email, phone, status, create_by, update_by)
|
||||||
(2, '测试管理员', 'test_admin', 2, 1, 'system', 'system', NOW(), NOW()),
|
VALUES (1, 'admin', '$2b$12$SFefXlGRFMA0fvxIufpWPuIAl0OPLgRDoCZPThCvjpiJGPYS8yNYy', 'admin@novalon.com', '13800138000', 1, 'system', 'system')
|
||||||
(3, '普通用户', 'normal_user', 3, 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
(4, '访客', 'guest', 4, 1, 'system', 'system', NOW(), NOW());
|
|
||||||
|
|
||||||
SELECT setval('sys_role_id_seq', 4);
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 用户数据
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 密码均为: Test@123 (BCrypt哈希)
|
|
||||||
INSERT INTO sys_user (id, username, password, email, phone, nickname, status, create_by, update_by, created_at, updated_at)
|
|
||||||
VALUES
|
|
||||||
(1, 'admin', '$2a$12$nZ1EMUpZQljbnEdIKzH72eHlDJKUmHmHppnTTVth/SlHs5VpSAr8C', 'admin@novalon.com', '13800138000', '超级管理员', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
(2, 'user', '$2a$12$nZ1EMUpZQljbnEdIKzH72eHlDJKUmHmHppnTTVth/SlHs5VpSAr8C', 'user@novalon.com', '13800138001', '普通用户', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
(10, 'e2e_test_user', '$2a$12$nZ1EMUpZQljbnEdIKzH72eHlDJKUmHmHppnTTVth/SlHs5VpSAr8C', 'e2e@test.com', '13900139000', 'E2E测试用户', 1, 'system', 'system', NOW(), NOW())
|
|
||||||
ON CONFLICT (username) DO UPDATE SET
|
ON CONFLICT (username) DO UPDATE SET
|
||||||
password = EXCLUDED.password,
|
password = EXCLUDED.password,
|
||||||
status = EXCLUDED.status;
|
status = EXCLUDED.status;
|
||||||
|
|
||||||
SELECT setval('sys_user_id_seq', 10);
|
-- 插入测试用户(用于E2E测试)
|
||||||
|
-- BCrypt哈希值对应明文密码: admin123
|
||||||
|
INSERT INTO sys_user (id, username, password, email, phone, status, create_by, update_by)
|
||||||
|
VALUES (2, 'user', '$2b$12$SFefXlGRFMA0fvxIufpWPuIAl0OPLgRDoCZPThCvjpiJGPYS8yNYy', 'user@novalon.com', '13800138001', 1, 'system', 'system')
|
||||||
|
ON CONFLICT (username) DO UPDATE SET
|
||||||
|
password = EXCLUDED.password,
|
||||||
|
status = EXCLUDED.status;
|
||||||
|
|
||||||
-- ============================================
|
-- 插入初始字典类型
|
||||||
-- 用户角色关联
|
INSERT INTO sys_dict_type (dict_name, dict_type, status, remark, create_by, update_by)
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 为admin用户分配超级管理员角色
|
|
||||||
INSERT INTO user_role (user_id, role_id, created_by, created_at)
|
|
||||||
VALUES
|
VALUES
|
||||||
(1, 1, 'system', NOW()),
|
('用户状态', 'user_status', '0', '用户状态列表', 'system', 'system'),
|
||||||
(2, 3, 'system', NOW()),
|
('菜单状态', 'menu_status', '0', '菜单状态列表', 'system', 'system'),
|
||||||
(10, 1, 'system', NOW())
|
('角色状态', 'role_status', '0', '角色状态列表', 'system', 'system'),
|
||||||
ON CONFLICT (user_id, role_id) DO NOTHING;
|
('系统开关', 'sys_normal_disable', '0', '系统开关列表', 'system', 'system')
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 权限数据
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
INSERT INTO sys_permission (permission_name, permission_code, resource, action, description, status, create_by, update_by, created_at, updated_at) VALUES
|
|
||||||
('用户查看', 'system:user:view', '/api/users', 'GET', '查看用户列表', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('用户创建', 'system:user:create', '/api/users', 'POST', '创建用户', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('用户编辑', 'system:user:edit', '/api/users', 'PUT', '编辑用户', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('用户删除', 'system:user:delete', '/api/users', 'DELETE', '删除用户', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('角色查看', 'system:role:view', '/api/roles', 'GET', '查看角色列表', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('角色创建', 'system:role:create', '/api/roles', 'POST', '创建角色', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('角色编辑', 'system:role:edit', '/api/roles', 'PUT', '编辑角色', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('角色删除', 'system:role:delete', '/api/roles', 'DELETE', '删除角色', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('角色分配权限', 'system:role:assign', '/api/roles/*/permissions', 'POST', '为角色分配权限', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('权限查看', 'system:permission:view', '/api/permissions', 'GET', '查看权限列表', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('权限创建', 'system:permission:create', '/api/permissions', 'POST', '创建权限', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('权限编辑', 'system:permission:edit', '/api/permissions', 'PUT', '编辑权限', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('权限删除', 'system:permission:delete', '/api/permissions', 'DELETE', '删除权限', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('菜单查看', 'system:menu:view', '/api/menus', 'GET', '查看菜单列表', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('菜单创建', 'system:menu:create', '/api/menus', 'POST', '创建菜单', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('菜单编辑', 'system:menu:edit', '/api/menus', 'PUT', '编辑菜单', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('菜单删除', 'system:menu:delete', '/api/menus', 'DELETE', '删除菜单', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('字典查看', 'system:dict:view', '/api/dict', 'GET', '查看字典列表', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('字典创建', 'system:dict:create', '/api/dict', 'POST', '创建字典', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('字典编辑', 'system:dict:edit', '/api/dict', 'PUT', '编辑字典', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('字典删除', 'system:dict:delete', '/api/dict', 'DELETE', '删除字典', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('配置查看', 'system:config:view', '/api/config', 'GET', '查看系统配置', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('配置创建', 'system:config:create', '/api/config', 'POST', '创建系统配置', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('配置编辑', 'system:config:edit', '/api/config', 'PUT', '编辑系统配置', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('配置删除', 'system:config:delete', '/api/config', 'DELETE', '删除系统配置', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('日志查看', 'system:log:view', '/api/logs', 'GET', '查看日志', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('文件上传', 'system:file:upload', '/api/files/upload', 'POST', '上传文件', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('文件下载', 'system:file:download', '/api/files/download', 'GET', '下载文件', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('文件删除', 'system:file:delete', '/api/files', 'DELETE', '删除文件', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('公告查看', 'system:notice:view', '/api/notices', 'GET', '查看公告', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('公告创建', 'system:notice:create', '/api/notices', 'POST', '创建公告', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('公告编辑', 'system:notice:edit', '/api/notices', 'PUT', '编辑公告', 1, 'system', 'system', NOW(), NOW()),
|
|
||||||
('公告删除', 'system:notice:delete', '/api/notices', 'DELETE', '删除公告', 1, 'system', 'system', NOW(), NOW());
|
|
||||||
|
|
||||||
-- 为管理员角色分配所有权限
|
|
||||||
INSERT INTO sys_role_permission (role_id, permission_id, create_by, update_by, created_at, updated_at)
|
|
||||||
SELECT 1, id, 'system', 'system', NOW(), NOW() FROM sys_permission WHERE status = 1;
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 菜单数据
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 一级菜单
|
|
||||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
|
||||||
(1, '系统管理', 0, 1, 'M', NULL, NULL, 1, NOW(), NOW()),
|
|
||||||
(2, '审计日志', 0, 2, 'M', NULL, NULL, 1, NOW(), NOW()),
|
|
||||||
(3, '系统监控', 0, 3, 'M', NULL, NULL, 1, NOW(), NOW());
|
|
||||||
|
|
||||||
-- 系统管理子菜单
|
|
||||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
|
||||||
(11, '用户管理', 1, 1, 'C', 'system:user:list', 'system/user/index', 1, NOW(), NOW()),
|
|
||||||
(12, '角色管理', 1, 2, 'C', 'system:role:list', 'system/role/index', 1, NOW(), NOW()),
|
|
||||||
(13, '菜单管理', 1, 3, 'C', 'system:menu:list', 'system/menu/index', 1, NOW(), NOW()),
|
|
||||||
(14, '部门管理', 1, 4, 'C', 'system:dept:list', 'system/dept/index', 1, NOW(), NOW()),
|
|
||||||
(15, '字典管理', 1, 5, 'C', 'system:dict:list', 'system/dict/index', 1, NOW(), NOW()),
|
|
||||||
(16, '参数管理', 1, 6, 'C', 'system:config:list', 'system/config/index', 1, NOW(), NOW()),
|
|
||||||
(17, '通知公告', 1, 7, 'C', 'system:notice:list', 'system/notice/index', 1, NOW(), NOW()),
|
|
||||||
(18, '文件管理', 1, 8, 'C', 'system:file:list', 'system/file/index', 1, NOW(), NOW());
|
|
||||||
|
|
||||||
-- 用户管理按钮权限
|
|
||||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
|
||||||
(111, '用户查询', 11, 1, 'F', 'system:user:query', NULL, 1, NOW(), NOW()),
|
|
||||||
(112, '用户新增', 11, 2, 'F', 'system:user:add', NULL, 1, NOW(), NOW()),
|
|
||||||
(113, '用户修改', 11, 3, 'F', 'system:user:edit', NULL, 1, NOW(), NOW()),
|
|
||||||
(114, '用户删除', 11, 4, 'F', 'system:user:remove', NULL, 1, NOW(), NOW()),
|
|
||||||
(115, '用户导出', 11, 5, 'F', 'system:user:export', NULL, 1, NOW(), NOW()),
|
|
||||||
(116, '用户导入', 11, 6, 'F', 'system:user:import', NULL, 1, NOW(), NOW()),
|
|
||||||
(117, '重置密码', 11, 7, 'F', 'system:user:resetPwd', NULL, 1, NOW(), NOW());
|
|
||||||
|
|
||||||
-- 角色管理按钮权限
|
|
||||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
|
||||||
(121, '角色查询', 12, 1, 'F', 'system:role:query', NULL, 1, NOW(), NOW()),
|
|
||||||
(122, '角色新增', 12, 2, 'F', 'system:role:add', NULL, 1, NOW(), NOW()),
|
|
||||||
(123, '角色修改', 12, 3, 'F', 'system:role:edit', NULL, 1, NOW(), NOW()),
|
|
||||||
(124, '角色删除', 12, 4, 'F', 'system:role:remove', NULL, 1, NOW(), NOW()),
|
|
||||||
(125, '角色导出', 12, 5, 'F', 'system:role:export', NULL, 1, NOW(), NOW());
|
|
||||||
|
|
||||||
-- 菜单管理按钮权限
|
|
||||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
|
||||||
(131, '菜单查询', 13, 1, 'F', 'system:menu:query', NULL, 1, NOW(), NOW()),
|
|
||||||
(132, '菜单新增', 13, 2, 'F', 'system:menu:add', NULL, 1, NOW(), NOW()),
|
|
||||||
(133, '菜单修改', 13, 3, 'F', 'system:menu:edit', NULL, 1, NOW(), NOW()),
|
|
||||||
(134, '菜单删除', 13, 4, 'F', 'system:menu:remove', NULL, 1, NOW(), NOW());
|
|
||||||
|
|
||||||
-- 审计日志子菜单
|
|
||||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
|
||||||
(21, '操作日志', 2, 1, 'C', 'audit:operation:list', 'audit/operation/index', 1, NOW(), NOW()),
|
|
||||||
(22, '登录日志', 2, 2, 'C', 'audit:login:list', 'audit/login/index', 1, NOW(), NOW()),
|
|
||||||
(23, '异常日志', 2, 3, 'C', 'audit:exception:list', 'audit/exception/index', 1, NOW(), NOW());
|
|
||||||
|
|
||||||
-- 操作日志按钮权限
|
|
||||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
|
||||||
(211, '操作查询', 21, 1, 'F', 'audit:operation:query', NULL, 1, NOW(), NOW()),
|
|
||||||
(212, '操作删除', 21, 2, 'F', 'audit:operation:remove', NULL, 1, NOW(), NOW()),
|
|
||||||
(213, '操作导出', 21, 3, 'F', 'audit:operation:export', NULL, 1, NOW(), NOW());
|
|
||||||
|
|
||||||
-- 登录日志按钮权限
|
|
||||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
|
||||||
(221, '登录查询', 22, 1, 'F', 'audit:login:query', NULL, 1, NOW(), NOW()),
|
|
||||||
(222, '登录删除', 22, 2, 'F', 'audit:login:remove', NULL, 1, NOW(), NOW()),
|
|
||||||
(223, '登录导出', 22, 3, 'F', 'audit:login:export', NULL, 1, NOW(), NOW());
|
|
||||||
|
|
||||||
-- 异常日志按钮权限
|
|
||||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
|
||||||
(231, '异常查询', 23, 1, 'F', 'audit:exception:query', NULL, 1, NOW(), NOW()),
|
|
||||||
(232, '异常删除', 23, 2, 'F', 'audit:exception:remove', NULL, 1, NOW(), NOW()),
|
|
||||||
(233, '异常导出', 23, 3, 'F', 'audit:exception:export', NULL, 1, NOW(), NOW());
|
|
||||||
|
|
||||||
-- 系统监控子菜单
|
|
||||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
|
||||||
(31, '在线用户', 3, 1, 'C', 'monitor:online:list', 'monitor/online/index', 1, NOW(), NOW()),
|
|
||||||
(32, '定时任务', 3, 2, 'C', 'monitor:job:list', 'monitor/job/index', 1, NOW(), NOW()),
|
|
||||||
(33, '数据监控', 3, 3, 'C', 'monitor:data:list', 'monitor/data/index', 1, NOW(), NOW()),
|
|
||||||
(34, '服务监控', 3, 4, 'C', 'monitor:server:list', 'monitor/server/index', 1, NOW(), NOW()),
|
|
||||||
(35, '缓存监控', 3, 5, 'C', 'monitor:cache:list', 'monitor/cache/index', 1, NOW(), NOW());
|
|
||||||
|
|
||||||
-- 在线用户按钮权限
|
|
||||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
|
||||||
(311, '在线查询', 31, 1, 'F', 'monitor:online:query', NULL, 1, NOW(), NOW()),
|
|
||||||
(312, '在线强退', 31, 2, 'F', 'monitor:online:forceLogout', NULL, 1, NOW(), NOW());
|
|
||||||
|
|
||||||
-- 定时任务按钮权限
|
|
||||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
|
||||||
(321, '任务查询', 32, 1, 'F', 'monitor:job:query', NULL, 1, NOW(), NOW()),
|
|
||||||
(322, '任务新增', 32, 2, 'F', 'monitor:job:add', NULL, 1, NOW(), NOW()),
|
|
||||||
(323, '任务修改', 32, 3, 'F', 'monitor:job:edit', NULL, 1, NOW(), NOW()),
|
|
||||||
(324, '任务删除', 32, 4, 'F', 'monitor:job:remove', NULL, 1, NOW(), NOW()),
|
|
||||||
(325, '任务执行', 32, 5, 'F', 'monitor:job:execute', NULL, 1, NOW(), NOW());
|
|
||||||
|
|
||||||
SELECT setval('sys_menu_id_seq', 400);
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 字典数据
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 字典类型
|
|
||||||
INSERT INTO sys_dict_type (dict_name, dict_type, status, remark, create_by, update_by, created_at, updated_at)
|
|
||||||
VALUES
|
|
||||||
('用户状态', 'user_status', '0', '用户状态列表', 'system', 'system', NOW(), NOW()),
|
|
||||||
('菜单状态', 'menu_status', '0', '菜单状态列表', 'system', 'system', NOW(), NOW()),
|
|
||||||
('角色状态', 'role_status', '0', '角色状态列表', 'system', 'system', NOW(), NOW()),
|
|
||||||
('系统开关', 'sys_normal_disable', '0', '系统开关列表', 'system', 'system', NOW(), NOW())
|
|
||||||
ON CONFLICT (dict_type) DO NOTHING;
|
ON CONFLICT (dict_type) DO NOTHING;
|
||||||
|
|
||||||
-- 字典数据
|
-- 插入初始字典数据
|
||||||
INSERT INTO sys_dict_data (dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, update_by, created_at, updated_at)
|
INSERT INTO sys_dict_data (dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, update_by)
|
||||||
VALUES
|
VALUES
|
||||||
-- 用户状态
|
-- 用户状态
|
||||||
(1, '正常', '1', 'user_status', '', 'primary', 'Y', '0', 'system', 'system', NOW(), NOW()),
|
(1, '正常', '1', 'user_status', '', 'primary', 'Y', '0', 'system', 'system'),
|
||||||
(2, '停用', '0', 'user_status', '', 'danger', 'N', '0', 'system', 'system', NOW(), NOW()),
|
(2, '停用', '0', 'user_status', '', 'danger', 'N', '0', 'system', 'system'),
|
||||||
-- 菜单状态
|
-- 菜单状态
|
||||||
(1, '正常', '0', 'menu_status', '', 'primary', 'Y', '0', 'system', 'system', NOW(), NOW()),
|
(1, '正常', '0', 'menu_status', '', 'primary', 'Y', '0', 'system', 'system'),
|
||||||
(2, '停用', '1', 'menu_status', '', 'danger', 'N', '0', 'system', 'system', NOW(), NOW()),
|
(2, '停用', '1', 'menu_status', '', 'danger', 'N', '0', 'system', 'system'),
|
||||||
-- 角色状态
|
-- 角色状态
|
||||||
(1, '正常', '0', 'role_status', '', 'primary', 'Y', '0', 'system', 'system', NOW(), NOW()),
|
(1, '正常', '0', 'role_status', '', 'primary', 'Y', '0', 'system', 'system'),
|
||||||
(2, '停用', '1', 'role_status', '', 'danger', 'N', '0', 'system', 'system', NOW(), NOW()),
|
(2, '停用', '1', 'role_status', '', 'danger', 'N', '0', 'system', 'system'),
|
||||||
-- 系统开关
|
-- 系统开关
|
||||||
(1, '正常', '0', 'sys_normal_disable', '', 'primary', 'Y', '0', 'system', 'system', NOW(), NOW()),
|
(1, '正常', '0', 'sys_normal_disable', '', 'primary', 'Y', '0', 'system', 'system'),
|
||||||
(2, '停用', '1', 'sys_normal_disable', '', 'danger', 'N', '0', 'system', 'system', NOW(), NOW());
|
(2, '停用', '1', 'sys_normal_disable', '', 'danger', 'N', '0', 'system', 'system')
|
||||||
|
ON CONFLICT DO NOTHING;
|
||||||
|
|
||||||
-- ============================================
|
-- 插入初始系统配置
|
||||||
-- 系统配置
|
INSERT INTO sys_config (config_name, config_key, config_value, config_type, create_by, update_by)
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
INSERT INTO sys_config (config_name, config_key, config_value, config_type, create_by, update_by, created_at, updated_at)
|
|
||||||
VALUES
|
VALUES
|
||||||
('用户管理-用户初始密码', 'sys.user.initPassword', '123456', 'Y', 'system', 'system', NOW(), NOW()),
|
('用户管理-用户初始密码', 'sys.user.initPassword', '123456', 'Y', 'system', 'system'),
|
||||||
('主框架页-默认皮肤样式名称', 'sys.index.skinName', 'skin-blue', 'Y', 'system', 'system', NOW(), NOW()),
|
('主框架页-默认皮肤样式名称', 'sys.index.skinName', 'skin-blue', 'Y', 'system', 'system'),
|
||||||
('用户自助-验证码开关', 'sys.account.captchaEnabled', 'true', 'Y', 'system', 'system', NOW(), NOW()),
|
('用户自助-验证码开关', 'sys.account.captchaEnabled', 'true', 'Y', 'system', 'system'),
|
||||||
('用户自助-是否开启用户注册功能', 'sys.account.registerUser', 'false', 'Y', 'system', 'system', NOW(), NOW()),
|
('用户自助-是否开启用户注册功能', 'sys.account.registerUser', 'false', 'Y', 'system', 'system'),
|
||||||
('账号自助-密码验证码', 'sys.account.pwdCaptchaEnabled', 'true', 'Y', 'system', 'system', NOW(), NOW())
|
('账号自助-密码验证码', 'sys.account.pwdCaptchaEnabled', 'true', 'Y', 'system', 'system')
|
||||||
ON CONFLICT (config_key) DO NOTHING;
|
ON CONFLICT (config_key) DO NOTHING;
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 重置序列值
|
-- 重置序列值
|
||||||
-- ============================================
|
SELECT setval('sys_user_id_seq', (SELECT COALESCE(MAX(id), 1) FROM sys_user));
|
||||||
|
SELECT setval('sys_role_id_seq', (SELECT COALESCE(MAX(id), 1) FROM sys_role));
|
||||||
SELECT setval('sys_dict_type_id_seq', (SELECT COALESCE(MAX(id), 1) FROM sys_dict_type));
|
SELECT setval('sys_dict_type_id_seq', (SELECT COALESCE(MAX(id), 1) FROM sys_dict_type));
|
||||||
SELECT setval('sys_dict_data_id_seq', (SELECT COALESCE(MAX(id), 1) FROM sys_dict_data));
|
SELECT setval('sys_dict_data_id_seq', (SELECT COALESCE(MAX(id), 1) FROM sys_dict_data));
|
||||||
SELECT setval('sys_config_id_seq', (SELECT COALESCE(MAX(id), 1) FROM sys_config));
|
SELECT setval('sys_config_id_seq', (SELECT COALESCE(MAX(id), 1) FROM sys_config));
|
||||||
SELECT setval('sys_permission_id_seq', (SELECT COALESCE(MAX(id), 1) FROM sys_permission));
|
|
||||||
SELECT setval('sys_role_permission_id_seq', (SELECT COALESCE(MAX(id), 1) FROM sys_role_permission));
|
|
||||||
SELECT setval('user_role_id_seq', (SELECT COALESCE(MAX(id), 1) FROM user_role));
|
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
-- 创建用户角色关联表(支持多对多关系)
|
||||||
|
CREATE TABLE IF NOT EXISTS user_role (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
user_id BIGINT NOT NULL,
|
||||||
|
role_id BIGINT NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
created_by VARCHAR(50),
|
||||||
|
CONSTRAINT fk_user_role_user FOREIGN KEY (user_id) REFERENCES sys_user(id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_user_role_role FOREIGN KEY (role_id) REFERENCES sys_role(id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT uk_user_role UNIQUE (user_id, role_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 创建索引
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_user_role_user_id ON user_role(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_user_role_role_id ON user_role(role_id);
|
||||||
|
|
||||||
|
-- 表注释
|
||||||
|
COMMENT ON TABLE user_role IS '用户角色关联表';
|
||||||
|
COMMENT ON COLUMN user_role.id IS '主键ID';
|
||||||
|
COMMENT ON COLUMN user_role.user_id IS '用户ID';
|
||||||
|
COMMENT ON COLUMN user_role.role_id IS '角色ID';
|
||||||
|
COMMENT ON COLUMN user_role.created_at IS '创建时间';
|
||||||
|
COMMENT ON COLUMN user_role.created_by IS '创建人';
|
||||||
+104
@@ -0,0 +1,104 @@
|
|||||||
|
-- Novalon管理系统权限功能数据库迁移脚本
|
||||||
|
-- 版本: V4
|
||||||
|
-- 描述: 创建权限管理相关表结构
|
||||||
|
|
||||||
|
-- 权限表
|
||||||
|
CREATE TABLE IF NOT EXISTS sys_permission (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
permission_name VARCHAR(100) NOT NULL,
|
||||||
|
permission_code VARCHAR(100) NOT NULL UNIQUE,
|
||||||
|
resource VARCHAR(200) NOT NULL,
|
||||||
|
action VARCHAR(50) NOT NULL,
|
||||||
|
description VARCHAR(500),
|
||||||
|
status INTEGER DEFAULT 1,
|
||||||
|
create_by VARCHAR(50),
|
||||||
|
update_by VARCHAR(50),
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
deleted_at TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 角色权限关联表
|
||||||
|
CREATE TABLE IF NOT EXISTS sys_role_permission (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
role_id BIGINT NOT NULL,
|
||||||
|
permission_id BIGINT NOT NULL,
|
||||||
|
create_by VARCHAR(50),
|
||||||
|
update_by VARCHAR(50),
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (role_id) REFERENCES sys_role(id) ON DELETE CASCADE,
|
||||||
|
FOREIGN KEY (permission_id) REFERENCES sys_permission(id) ON DELETE CASCADE,
|
||||||
|
UNIQUE (role_id, permission_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 表注释
|
||||||
|
COMMENT ON TABLE sys_permission IS '系统权限表';
|
||||||
|
COMMENT ON COLUMN sys_permission.id IS '主键ID';
|
||||||
|
COMMENT ON COLUMN sys_permission.permission_name IS '权限名称';
|
||||||
|
COMMENT ON COLUMN sys_permission.permission_code IS '权限编码';
|
||||||
|
COMMENT ON COLUMN sys_permission.resource IS '资源路径';
|
||||||
|
COMMENT ON COLUMN sys_permission.action IS '操作类型';
|
||||||
|
COMMENT ON COLUMN sys_permission.description IS '权限描述';
|
||||||
|
COMMENT ON COLUMN sys_permission.status IS '状态:0-禁用,1-正常';
|
||||||
|
COMMENT ON COLUMN sys_permission.create_by IS '创建者';
|
||||||
|
COMMENT ON COLUMN sys_permission.update_by IS '更新者';
|
||||||
|
COMMENT ON COLUMN sys_permission.created_at IS '创建时间';
|
||||||
|
COMMENT ON COLUMN sys_permission.updated_at IS '更新时间';
|
||||||
|
COMMENT ON COLUMN sys_permission.deleted_at IS '删除时间';
|
||||||
|
|
||||||
|
COMMENT ON TABLE sys_role_permission IS '角色权限关联表';
|
||||||
|
COMMENT ON COLUMN sys_role_permission.id IS '主键ID';
|
||||||
|
COMMENT ON COLUMN sys_role_permission.role_id IS '角色ID';
|
||||||
|
COMMENT ON COLUMN sys_role_permission.permission_id IS '权限ID';
|
||||||
|
COMMENT ON COLUMN sys_role_permission.create_by IS '创建者';
|
||||||
|
COMMENT ON COLUMN sys_role_permission.update_by IS '更新者';
|
||||||
|
COMMENT ON COLUMN sys_role_permission.created_at IS '创建时间';
|
||||||
|
COMMENT ON COLUMN sys_role_permission.updated_at IS '更新时间';
|
||||||
|
|
||||||
|
-- 创建索引
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_permission_code ON sys_permission(permission_code);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_permission_resource ON sys_permission(resource);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_permission_status ON sys_permission(status);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_role_permission_role_id ON sys_role_permission(role_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_role_permission_permission_id ON sys_role_permission(permission_id);
|
||||||
|
|
||||||
|
-- 插入初始权限数据
|
||||||
|
INSERT INTO sys_permission (permission_name, permission_code, resource, action, description, status) VALUES
|
||||||
|
('用户查看', 'system:user:view', '/api/users', 'GET', '查看用户列表', 1),
|
||||||
|
('用户创建', 'system:user:create', '/api/users', 'POST', '创建用户', 1),
|
||||||
|
('用户编辑', 'system:user:edit', '/api/users', 'PUT', '编辑用户', 1),
|
||||||
|
('用户删除', 'system:user:delete', '/api/users', 'DELETE', '删除用户', 1),
|
||||||
|
('角色查看', 'system:role:view', '/api/roles', 'GET', '查看角色列表', 1),
|
||||||
|
('角色创建', 'system:role:create', '/api/roles', 'POST', '创建角色', 1),
|
||||||
|
('角色编辑', 'system:role:edit', '/api/roles', 'PUT', '编辑角色', 1),
|
||||||
|
('角色删除', 'system:role:delete', '/api/roles', 'DELETE', '删除角色', 1),
|
||||||
|
('角色分配权限', 'system:role:assign', '/api/roles/*/permissions', 'POST', '为角色分配权限', 1),
|
||||||
|
('权限查看', 'system:permission:view', '/api/permissions', 'GET', '查看权限列表', 1),
|
||||||
|
('权限创建', 'system:permission:create', '/api/permissions', 'POST', '创建权限', 1),
|
||||||
|
('权限编辑', 'system:permission:edit', '/api/permissions', 'PUT', '编辑权限', 1),
|
||||||
|
('权限删除', 'system:permission:delete', '/api/permissions', 'DELETE', '删除权限', 1),
|
||||||
|
('菜单查看', 'system:menu:view', '/api/menus', 'GET', '查看菜单列表', 1),
|
||||||
|
('菜单创建', 'system:menu:create', '/api/menus', 'POST', '创建菜单', 1),
|
||||||
|
('菜单编辑', 'system:menu:edit', '/api/menus', 'PUT', '编辑菜单', 1),
|
||||||
|
('菜单删除', 'system:menu:delete', '/api/menus', 'DELETE', '删除菜单', 1),
|
||||||
|
('字典查看', 'system:dict:view', '/api/dict', 'GET', '查看字典列表', 1),
|
||||||
|
('字典创建', 'system:dict:create', '/api/dict', 'POST', '创建字典', 1),
|
||||||
|
('字典编辑', 'system:dict:edit', '/api/dict', 'PUT', '编辑字典', 1),
|
||||||
|
('字典删除', 'system:dict:delete', '/api/dict', 'DELETE', '删除字典', 1),
|
||||||
|
('配置查看', 'system:config:view', '/api/config', 'GET', '查看系统配置', 1),
|
||||||
|
('配置创建', 'system:config:create', '/api/config', 'POST', '创建系统配置', 1),
|
||||||
|
('配置编辑', 'system:config:edit', '/api/config', 'PUT', '编辑系统配置', 1),
|
||||||
|
('配置删除', 'system:config:delete', '/api/config', 'DELETE', '删除系统配置', 1),
|
||||||
|
('日志查看', 'system:log:view', '/api/logs', 'GET', '查看日志', 1),
|
||||||
|
('文件上传', 'system:file:upload', '/api/files/upload', 'POST', '上传文件', 1),
|
||||||
|
('文件下载', 'system:file:download', '/api/files/download', 'GET', '下载文件', 1),
|
||||||
|
('文件删除', 'system:file:delete', '/api/files', 'DELETE', '删除文件', 1),
|
||||||
|
('公告查看', 'system:notice:view', '/api/notices', 'GET', '查看公告', 1),
|
||||||
|
('公告创建', 'system:notice:create', '/api/notices', 'POST', '创建公告', 1),
|
||||||
|
('公告编辑', 'system:notice:edit', '/api/notices', 'PUT', '编辑公告', 1),
|
||||||
|
('公告删除', 'system:notice:delete', '/api/notices', 'DELETE', '删除公告', 1);
|
||||||
|
|
||||||
|
-- 为管理员角色分配所有权限
|
||||||
|
INSERT INTO sys_role_permission (role_id, permission_id)
|
||||||
|
SELECT 1, id FROM sys_permission WHERE status = 1;
|
||||||
+3
-64
@@ -1,11 +1,7 @@
|
|||||||
-- Novalon管理系统索引优化脚本
|
-- Novalon管理系统索引优化脚本
|
||||||
-- 版本: V3
|
-- 版本: V5
|
||||||
-- 描述: 为表创建必要的索引以提升查询性能
|
-- 描述: 为表创建必要的索引以提升查询性能
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 用户与角色表索引
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 用户表索引
|
-- 用户表索引
|
||||||
CREATE INDEX IF NOT EXISTS idx_users_username ON sys_user(username);
|
CREATE INDEX IF NOT EXISTS idx_users_username ON sys_user(username);
|
||||||
CREATE INDEX IF NOT EXISTS idx_users_email ON sys_user(email);
|
CREATE INDEX IF NOT EXISTS idx_users_email ON sys_user(email);
|
||||||
@@ -17,35 +13,11 @@ CREATE INDEX IF NOT EXISTS idx_roles_role_key ON sys_role(role_key);
|
|||||||
CREATE INDEX IF NOT EXISTS idx_roles_status ON sys_role(status);
|
CREATE INDEX IF NOT EXISTS idx_roles_status ON sys_role(status);
|
||||||
CREATE INDEX IF NOT EXISTS idx_roles_deleted_at ON sys_role(deleted_at);
|
CREATE INDEX IF NOT EXISTS idx_roles_deleted_at ON sys_role(deleted_at);
|
||||||
|
|
||||||
-- 用户角色关联表索引
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_user_role_user_id ON user_role(user_id);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_user_role_role_id ON user_role(role_id);
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 权限表索引
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 权限表索引
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_permission_code ON sys_permission(permission_code);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_permission_resource ON sys_permission(resource);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_permission_status ON sys_permission(status);
|
|
||||||
|
|
||||||
-- 角色权限关联表索引
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_role_permission_role_id ON sys_role_permission(role_id);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_role_permission_permission_id ON sys_role_permission(permission_id);
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 菜单表索引
|
-- 菜单表索引
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_sys_menu_parent_id ON sys_menu(parent_id);
|
CREATE INDEX IF NOT EXISTS idx_sys_menu_parent_id ON sys_menu(parent_id);
|
||||||
CREATE INDEX IF NOT EXISTS idx_sys_menu_status ON sys_menu(status);
|
CREATE INDEX IF NOT EXISTS idx_sys_menu_status ON sys_menu(status);
|
||||||
CREATE INDEX IF NOT EXISTS idx_sys_menu_deleted_at ON sys_menu(deleted_at);
|
CREATE INDEX IF NOT EXISTS idx_sys_menu_deleted_at ON sys_menu(deleted_at);
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 字典表索引
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 字典类型表索引
|
-- 字典类型表索引
|
||||||
CREATE INDEX IF NOT EXISTS idx_sys_dict_type_dict_type ON sys_dict_type(dict_type);
|
CREATE INDEX IF NOT EXISTS idx_sys_dict_type_dict_type ON sys_dict_type(dict_type);
|
||||||
CREATE INDEX IF NOT EXISTS idx_sys_dict_type_status ON sys_dict_type(status);
|
CREATE INDEX IF NOT EXISTS idx_sys_dict_type_status ON sys_dict_type(status);
|
||||||
@@ -57,23 +29,16 @@ CREATE INDEX IF NOT EXISTS idx_sys_dict_data_dict_value ON sys_dict_data(dict_va
|
|||||||
CREATE INDEX IF NOT EXISTS idx_sys_dict_data_status ON sys_dict_data(status);
|
CREATE INDEX IF NOT EXISTS idx_sys_dict_data_status ON sys_dict_data(status);
|
||||||
CREATE INDEX IF NOT EXISTS idx_sys_dict_data_deleted_at ON sys_dict_data(deleted_at);
|
CREATE INDEX IF NOT EXISTS idx_sys_dict_data_deleted_at ON sys_dict_data(deleted_at);
|
||||||
|
|
||||||
-- 通用字典表索引
|
-- 字典表索引
|
||||||
CREATE INDEX IF NOT EXISTS idx_sys_dictionary_type ON sys_dictionary(type);
|
CREATE INDEX IF NOT EXISTS idx_sys_dictionary_type ON sys_dictionary(type);
|
||||||
CREATE INDEX IF NOT EXISTS idx_sys_dictionary_type_code ON sys_dictionary(type, code);
|
CREATE INDEX IF NOT EXISTS idx_sys_dictionary_type_code ON sys_dictionary(type, code);
|
||||||
CREATE INDEX IF NOT EXISTS idx_sys_dictionary_deleted_at ON sys_dictionary(deleted_at);
|
CREATE INDEX IF NOT EXISTS idx_sys_dictionary_deleted_at ON sys_dictionary(deleted_at);
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 系统配置表索引
|
-- 系统配置表索引
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_sys_config_config_key ON sys_config(config_key);
|
CREATE INDEX IF NOT EXISTS idx_sys_config_config_key ON sys_config(config_key);
|
||||||
CREATE INDEX IF NOT EXISTS idx_sys_config_config_type ON sys_config(config_type);
|
CREATE INDEX IF NOT EXISTS idx_sys_config_config_type ON sys_config(config_type);
|
||||||
CREATE INDEX IF NOT EXISTS idx_sys_config_deleted_at ON sys_config(deleted_at);
|
CREATE INDEX IF NOT EXISTS idx_sys_config_deleted_at ON sys_config(deleted_at);
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 日志表索引
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 登录日志表索引
|
-- 登录日志表索引
|
||||||
CREATE INDEX IF NOT EXISTS idx_sys_login_log_username ON sys_login_log(username);
|
CREATE INDEX IF NOT EXISTS idx_sys_login_log_username ON sys_login_log(username);
|
||||||
CREATE INDEX IF NOT EXISTS idx_sys_login_log_ip ON sys_login_log(ip);
|
CREATE INDEX IF NOT EXISTS idx_sys_login_log_ip ON sys_login_log(ip);
|
||||||
@@ -92,26 +57,6 @@ CREATE INDEX IF NOT EXISTS idx_operation_log_created_at ON operation_log(created
|
|||||||
CREATE INDEX IF NOT EXISTS idx_operation_log_status ON operation_log(status);
|
CREATE INDEX IF NOT EXISTS idx_operation_log_status ON operation_log(status);
|
||||||
CREATE INDEX IF NOT EXISTS idx_operation_log_deleted_at ON operation_log(deleted_at);
|
CREATE INDEX IF NOT EXISTS idx_operation_log_deleted_at ON operation_log(deleted_at);
|
||||||
|
|
||||||
-- 审计日志表索引
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_audit_log_entity_type ON audit_log(entity_type);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_audit_log_entity_id ON audit_log(entity_id);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_audit_log_operation_type ON audit_log(operation_type);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_audit_log_operator ON audit_log(operator);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_audit_log_operation_time ON audit_log(operation_time);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_audit_log_entity ON audit_log(entity_type, entity_id);
|
|
||||||
|
|
||||||
-- 审计日志归档表索引
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_audit_log_archive_entity_type ON audit_log_archive(entity_type);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_audit_log_archive_entity_id ON audit_log_archive(entity_id);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_audit_log_archive_operation_type ON audit_log_archive(operation_type);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_audit_log_archive_operator ON audit_log_archive(operator);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_audit_log_archive_operation_time ON audit_log_archive(operation_time);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_audit_log_archive_archived_at ON audit_log_archive(archived_at);
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 通知与消息表索引
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 系统公告表索引
|
-- 系统公告表索引
|
||||||
CREATE INDEX IF NOT EXISTS idx_sys_notice_notice_type ON sys_notice(notice_type);
|
CREATE INDEX IF NOT EXISTS idx_sys_notice_notice_type ON sys_notice(notice_type);
|
||||||
CREATE INDEX IF NOT EXISTS idx_sys_notice_status ON sys_notice(status);
|
CREATE INDEX IF NOT EXISTS idx_sys_notice_status ON sys_notice(status);
|
||||||
@@ -123,17 +68,11 @@ CREATE INDEX IF NOT EXISTS idx_sys_user_message_notice_id ON sys_user_message(no
|
|||||||
CREATE INDEX IF NOT EXISTS idx_sys_user_message_is_read ON sys_user_message(is_read);
|
CREATE INDEX IF NOT EXISTS idx_sys_user_message_is_read ON sys_user_message(is_read);
|
||||||
CREATE INDEX IF NOT EXISTS idx_sys_user_message_deleted_at ON sys_user_message(deleted_at);
|
CREATE INDEX IF NOT EXISTS idx_sys_user_message_deleted_at ON sys_user_message(deleted_at);
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 文件管理表索引
|
-- 文件管理表索引
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_sys_file_file_type ON sys_file(file_type);
|
CREATE INDEX IF NOT EXISTS idx_sys_file_file_type ON sys_file(file_type);
|
||||||
CREATE INDEX IF NOT EXISTS idx_sys_file_deleted_at ON sys_file(deleted_at);
|
CREATE INDEX IF NOT EXISTS idx_sys_file_deleted_at ON sys_file(deleted_at);
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- OAuth2客户端表索引
|
-- OAuth2客户端表索引
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_oauth2_client_client_id ON oauth2_client(client_id);
|
CREATE INDEX IF NOT EXISTS idx_oauth2_client_client_id ON oauth2_client(client_id);
|
||||||
CREATE INDEX IF NOT EXISTS idx_oauth2_client_enabled ON oauth2_client(enabled);
|
CREATE INDEX IF NOT EXISTS idx_oauth2_client_enabled ON oauth2_client(enabled);
|
||||||
CREATE INDEX IF NOT EXISTS idx_oauth2_client_deleted_at ON oauth2_client(deleted_at);
|
CREATE INDEX IF NOT EXISTS idx_oauth2_client_deleted_at ON oauth2_client(deleted_at);
|
||||||
-41
@@ -1,41 +0,0 @@
|
|||||||
-- 创建操作日志表
|
|
||||||
CREATE TABLE IF NOT EXISTS sys_operation_log (
|
|
||||||
id BIGINT PRIMARY KEY,
|
|
||||||
username VARCHAR(50),
|
|
||||||
operation VARCHAR(100),
|
|
||||||
method VARCHAR(200),
|
|
||||||
params TEXT,
|
|
||||||
result TEXT,
|
|
||||||
ip VARCHAR(50),
|
|
||||||
duration BIGINT,
|
|
||||||
status VARCHAR(1) DEFAULT '0',
|
|
||||||
error_msg TEXT,
|
|
||||||
create_by VARCHAR(50),
|
|
||||||
update_by VARCHAR(50),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
deleted_at TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- 创建索引
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_operation_log_username ON sys_operation_log(username);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_operation_log_created_at ON sys_operation_log(created_at);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_operation_log_status ON sys_operation_log(status);
|
|
||||||
|
|
||||||
-- 添加注释
|
|
||||||
COMMENT ON TABLE sys_operation_log IS '操作日志表';
|
|
||||||
COMMENT ON COLUMN sys_operation_log.id IS '主键ID';
|
|
||||||
COMMENT ON COLUMN sys_operation_log.username IS '操作用户';
|
|
||||||
COMMENT ON COLUMN sys_operation_log.operation IS '操作描述';
|
|
||||||
COMMENT ON COLUMN sys_operation_log.method IS '请求方法';
|
|
||||||
COMMENT ON COLUMN sys_operation_log.params IS '请求参数';
|
|
||||||
COMMENT ON COLUMN sys_operation_log.result IS '操作结果';
|
|
||||||
COMMENT ON COLUMN sys_operation_log.ip IS 'IP地址';
|
|
||||||
COMMENT ON COLUMN sys_operation_log.duration IS '执行时长(毫秒)';
|
|
||||||
COMMENT ON COLUMN sys_operation_log.status IS '操作状态(0成功 1失败)';
|
|
||||||
COMMENT ON COLUMN sys_operation_log.error_msg IS '错误消息';
|
|
||||||
COMMENT ON COLUMN sys_operation_log.create_by IS '创建人';
|
|
||||||
COMMENT ON COLUMN sys_operation_log.update_by IS '更新人';
|
|
||||||
COMMENT ON COLUMN sys_operation_log.created_at IS '创建时间';
|
|
||||||
COMMENT ON COLUMN sys_operation_log.updated_at IS '更新时间';
|
|
||||||
COMMENT ON COLUMN sys_operation_log.deleted_at IS '删除时间';
|
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
-- 系统菜单初始化数据
|
||||||
|
-- 版本: V6
|
||||||
|
-- 描述: 初始化系统菜单数据
|
||||||
|
|
||||||
|
-- 一级菜单
|
||||||
|
INSERT INTO sys_menu (id, parent_id, menu_name, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||||
|
(1, 0, '系统管理', 1, 'M', NULL, NULL, 1, NOW(), NOW()),
|
||||||
|
(2, 0, '审计日志', 2, 'M', NULL, NULL, 1, NOW(), NOW()),
|
||||||
|
(3, 0, '系统监控', 3, 'M', NULL, NULL, 1, NOW(), NOW());
|
||||||
|
|
||||||
|
-- 系统管理子菜单
|
||||||
|
INSERT INTO sys_menu (id, parent_id, menu_name, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||||
|
(11, 1, '用户管理', 1, 'C', 'system:user:list', 'system/user/index', 1, NOW(), NOW()),
|
||||||
|
(12, 1, '角色管理', 2, 'C', 'system:role:list', 'system/role/index', 1, NOW(), NOW()),
|
||||||
|
(13, 1, '菜单管理', 3, 'C', 'system:menu:list', 'system/menu/index', 1, NOW(), NOW()),
|
||||||
|
(14, 1, '部门管理', 4, 'C', 'system:dept:list', 'system/dept/index', 1, NOW(), NOW()),
|
||||||
|
(15, 1, '字典管理', 5, 'C', 'system:dict:list', 'system/dict/index', 1, NOW(), NOW()),
|
||||||
|
(16, 1, '参数管理', 6, 'C', 'system:config:list', 'system/config/index', 1, NOW(), NOW()),
|
||||||
|
(17, 1, '通知公告', 7, 'C', 'system:notice:list', 'system/notice/index', 1, NOW(), NOW()),
|
||||||
|
(18, 1, '文件管理', 8, 'C', 'system:file:list', 'system/file/index', 1, NOW(), NOW());
|
||||||
|
|
||||||
|
-- 用户管理按钮权限
|
||||||
|
INSERT INTO sys_menu (id, parent_id, menu_name, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||||
|
(111, 11, '用户查询', 1, 'F', 'system:user:query', NULL, 1, NOW(), NOW()),
|
||||||
|
(112, 11, '用户新增', 2, 'F', 'system:user:add', NULL, 1, NOW(), NOW()),
|
||||||
|
(113, 11, '用户修改', 3, 'F', 'system:user:edit', NULL, 1, NOW(), NOW()),
|
||||||
|
(114, 11, '用户删除', 4, 'F', 'system:user:remove', NULL, 1, NOW(), NOW()),
|
||||||
|
(115, 11, '用户导出', 5, 'F', 'system:user:export', NULL, 1, NOW(), NOW()),
|
||||||
|
(116, 11, '用户导入', 6, 'F', 'system:user:import', NULL, 1, NOW(), NOW()),
|
||||||
|
(117, 11, '重置密码', 7, 'F', 'system:user:resetPwd', NULL, 1, NOW(), NOW());
|
||||||
|
|
||||||
|
-- 角色管理按钮权限
|
||||||
|
INSERT INTO sys_menu (id, parent_id, menu_name, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||||
|
(121, 12, '角色查询', 1, 'F', 'system:role:query', NULL, 1, NOW(), NOW()),
|
||||||
|
(122, 12, '角色新增', 2, 'F', 'system:role:add', NULL, 1, NOW(), NOW()),
|
||||||
|
(123, 12, '角色修改', 3, 'F', 'system:role:edit', NULL, 1, NOW(), NOW()),
|
||||||
|
(124, 12, '角色删除', 4, 'F', 'system:role:remove', NULL, 1, NOW(), NOW()),
|
||||||
|
(125, 12, '角色导出', 5, 'F', 'system:role:export', NULL, 1, NOW(), NOW());
|
||||||
|
|
||||||
|
-- 菜单管理按钮权限
|
||||||
|
INSERT INTO sys_menu (id, parent_id, menu_name, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||||
|
(131, 13, '菜单查询', 1, 'F', 'system:menu:query', NULL, 1, NOW(), NOW()),
|
||||||
|
(132, 13, '菜单新增', 2, 'F', 'system:menu:add', NULL, 1, NOW(), NOW()),
|
||||||
|
(133, 13, '菜单修改', 3, 'F', 'system:menu:edit', NULL, 1, NOW(), NOW()),
|
||||||
|
(134, 13, '菜单删除', 4, 'F', 'system:menu:remove', NULL, 1, NOW(), NOW());
|
||||||
|
|
||||||
|
-- 审计日志子菜单
|
||||||
|
INSERT INTO sys_menu (id, parent_id, menu_name, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||||
|
(21, 2, '操作日志', 1, 'C', 'audit:operation:list', 'audit/operation/index', 1, NOW(), NOW()),
|
||||||
|
(22, 2, '登录日志', 2, 'C', 'audit:login:list', 'audit/login/index', 1, NOW(), NOW()),
|
||||||
|
(23, 2, '异常日志', 3, 'C', 'audit:exception:list', 'audit/exception/index', 1, NOW(), NOW());
|
||||||
|
|
||||||
|
-- 操作日志按钮权限
|
||||||
|
INSERT INTO sys_menu (id, parent_id, menu_name, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||||
|
(211, 21, '操作查询', 1, 'F', 'audit:operation:query', NULL, 1, NOW(), NOW()),
|
||||||
|
(212, 21, '操作删除', 2, 'F', 'audit:operation:remove', NULL, 1, NOW(), NOW()),
|
||||||
|
(213, 21, '操作导出', 3, 'F', 'audit:operation:export', NULL, 1, NOW(), NOW());
|
||||||
|
|
||||||
|
-- 登录日志按钮权限
|
||||||
|
INSERT INTO sys_menu (id, parent_id, menu_name, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||||
|
(221, 22, '登录查询', 1, 'F', 'audit:login:query', NULL, 1, NOW(), NOW()),
|
||||||
|
(222, 22, '登录删除', 2, 'F', 'audit:login:remove', NULL, 1, NOW(), NOW()),
|
||||||
|
(223, 22, '登录导出', 3, 'F', 'audit:login:export', NULL, 1, NOW(), NOW());
|
||||||
|
|
||||||
|
-- 异常日志按钮权限
|
||||||
|
INSERT INTO sys_menu (id, parent_id, menu_name, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||||
|
(231, 23, '异常查询', 1, 'F', 'audit:exception:query', NULL, 1, NOW(), NOW()),
|
||||||
|
(232, 23, '异常删除', 2, 'F', 'audit:exception:remove', NULL, 1, NOW(), NOW()),
|
||||||
|
(233, 23, '异常导出', 3, 'F', 'audit:exception:export', NULL, 1, NOW(), NOW());
|
||||||
|
|
||||||
|
-- 系统监控子菜单
|
||||||
|
INSERT INTO sys_menu (id, parent_id, menu_name, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||||
|
(31, 3, '在线用户', 1, 'C', 'monitor:online:list', 'monitor/online/index', 1, NOW(), NOW()),
|
||||||
|
(32, 3, '定时任务', 2, 'C', 'monitor:job:list', 'monitor/job/index', 1, NOW(), NOW()),
|
||||||
|
(33, 3, '数据监控', 3, 'C', 'monitor:data:list', 'monitor/data/index', 1, NOW(), NOW()),
|
||||||
|
(34, 3, '服务监控', 4, 'C', 'monitor:server:list', 'monitor/server/index', 1, NOW(), NOW()),
|
||||||
|
(35, 3, '缓存监控', 5, 'C', 'monitor:cache:list', 'monitor/cache/index', 1, NOW(), NOW());
|
||||||
|
|
||||||
|
-- 在线用户按钮权限
|
||||||
|
INSERT INTO sys_menu (id, parent_id, menu_name, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||||
|
(311, 31, '在线查询', 1, 'F', 'monitor:online:query', NULL, 1, NOW(), NOW()),
|
||||||
|
(312, 31, '在线强退', 2, 'F', 'monitor:online:forceLogout', NULL, 1, NOW(), NOW());
|
||||||
|
|
||||||
|
-- 定时任务按钮权限
|
||||||
|
INSERT INTO sys_menu (id, parent_id, menu_name, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||||
|
(321, 32, '任务查询', 1, 'F', 'monitor:job:query', NULL, 1, NOW(), NOW()),
|
||||||
|
(322, 32, '任务新增', 2, 'F', 'monitor:job:add', NULL, 1, NOW(), NOW()),
|
||||||
|
(323, 32, '任务修改', 3, 'F', 'monitor:job:edit', NULL, 1, NOW(), NOW()),
|
||||||
|
(324, 32, '任务删除', 4, 'F', 'monitor:job:remove', NULL, 1, NOW(), NOW()),
|
||||||
|
(325, 32, '任务执行', 5, 'F', 'monitor:job:execute', NULL, 1, NOW(), NOW());
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
-- Novalon管理系统审计日志表
|
||||||
|
-- 版本: V7
|
||||||
|
-- 描述: 创建审计日志表,记录数据变更前后的完整对比
|
||||||
|
CREATE TABLE IF NOT EXISTS audit_log (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
entity_type VARCHAR(100) NOT NULL,
|
||||||
|
entity_id BIGINT,
|
||||||
|
operation_type VARCHAR(20) NOT NULL,
|
||||||
|
operator VARCHAR(100),
|
||||||
|
operation_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
before_data JSONB,
|
||||||
|
after_data JSONB,
|
||||||
|
changed_fields TEXT [],
|
||||||
|
ip_address VARCHAR(50),
|
||||||
|
user_agent TEXT,
|
||||||
|
description TEXT,
|
||||||
|
create_by VARCHAR(50),
|
||||||
|
update_by VARCHAR(50),
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
deleted_at TIMESTAMP
|
||||||
|
);
|
||||||
|
CREATE INDEX idx_audit_log_entity_type ON audit_log(entity_type);
|
||||||
|
CREATE INDEX idx_audit_log_entity_id ON audit_log(entity_id);
|
||||||
|
CREATE INDEX idx_audit_log_operation_type ON audit_log(operation_type);
|
||||||
|
CREATE INDEX idx_audit_log_operator ON audit_log(operator);
|
||||||
|
CREATE INDEX idx_audit_log_operation_time ON audit_log(operation_time);
|
||||||
|
CREATE INDEX idx_audit_log_entity ON audit_log(entity_type, entity_id);
|
||||||
|
COMMENT ON TABLE audit_log IS '审计日志表';
|
||||||
|
COMMENT ON COLUMN audit_log.id IS '主键ID';
|
||||||
|
COMMENT ON COLUMN audit_log.entity_type IS '实体类型(如User, Role等)';
|
||||||
|
COMMENT ON COLUMN audit_log.entity_id IS '实体ID';
|
||||||
|
COMMENT ON COLUMN audit_log.operation_type IS '操作类型(CREATE, UPDATE, DELETE)';
|
||||||
|
COMMENT ON COLUMN audit_log.operator IS '操作人';
|
||||||
|
COMMENT ON COLUMN audit_log.operation_time IS '操作时间';
|
||||||
|
COMMENT ON COLUMN audit_log.before_data IS '变更前数据(JSON格式)';
|
||||||
|
COMMENT ON COLUMN audit_log.after_data IS '变更后数据(JSON格式)';
|
||||||
|
COMMENT ON COLUMN audit_log.changed_fields IS '变更字段列表';
|
||||||
|
COMMENT ON COLUMN audit_log.ip_address IS 'IP地址';COMMENT ON COLUMN audit_log.description IS '操作描述';
|
||||||
|
COMMENT ON COLUMN audit_log.created_at IS '记录创建时间';
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
-- Novalon管理系统审计日志归档表
|
||||||
|
-- 版本: V8
|
||||||
|
-- 描述: 创建审计日志归档表,用于存储历史审计日志
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS audit_log_archive (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
entity_type VARCHAR(100) NOT NULL,
|
||||||
|
entity_id BIGINT,
|
||||||
|
operation_type VARCHAR(20) NOT NULL,
|
||||||
|
operator VARCHAR(100),
|
||||||
|
operation_time TIMESTAMP,
|
||||||
|
before_data JSONB,
|
||||||
|
after_data JSONB,
|
||||||
|
changed_fields TEXT[],
|
||||||
|
ip_address VARCHAR(50),
|
||||||
|
user_agent TEXT,
|
||||||
|
description TEXT,
|
||||||
|
created_at TIMESTAMP,
|
||||||
|
archived_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX idx_audit_log_archive_entity_type ON audit_log_archive(entity_type);
|
||||||
|
CREATE INDEX idx_audit_log_archive_entity_id ON audit_log_archive(entity_id);
|
||||||
|
CREATE INDEX idx_audit_log_archive_operation_type ON audit_log_archive(operation_type);
|
||||||
|
CREATE INDEX idx_audit_log_archive_operator ON audit_log_archive(operator);
|
||||||
|
CREATE INDEX idx_audit_log_archive_operation_time ON audit_log_archive(operation_time);
|
||||||
|
CREATE INDEX idx_audit_log_archive_archived_at ON audit_log_archive(archived_at);
|
||||||
|
|
||||||
|
COMMENT ON TABLE audit_log_archive IS '审计日志归档表';
|
||||||
|
COMMENT ON COLUMN audit_log_archive.id IS '主键ID';
|
||||||
|
COMMENT ON COLUMN audit_log_archive.entity_type IS '实体类型(如User, Role等)';
|
||||||
|
COMMENT ON COLUMN audit_log_archive.entity_id IS '实体ID';
|
||||||
|
COMMENT ON COLUMN audit_log_archive.operation_type IS '操作类型(CREATE, UPDATE, DELETE)';
|
||||||
|
COMMENT ON COLUMN audit_log_archive.operator IS '操作人';
|
||||||
|
COMMENT ON COLUMN audit_log_archive.operation_time IS '操作时间';
|
||||||
|
COMMENT ON COLUMN audit_log_archive.before_data IS '变更前数据(JSON格式)';
|
||||||
|
COMMENT ON COLUMN audit_log_archive.after_data IS '变更后数据(JSON格式)';
|
||||||
|
COMMENT ON COLUMN audit_log_archive.changed_fields IS '变更字段列表';
|
||||||
|
COMMENT ON COLUMN audit_log_archive.ip_address IS 'IP地址';
|
||||||
|
COMMENT ON COLUMN audit_log_archive.user_agent IS '用户代理';
|
||||||
|
COMMENT ON COLUMN audit_log_archive.description IS '操作描述';
|
||||||
|
COMMENT ON COLUMN audit_log_archive.created_at IS '记录创建时间';
|
||||||
|
COMMENT ON COLUMN audit_log_archive.archived_at IS '归档时间';
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
-- Novalon管理系统权限授予脚本
|
-- Novalon管理系统权限授予脚本
|
||||||
-- 版本: V4
|
-- 版本: V9
|
||||||
-- 描述: 为novalon用户授予所有表的访问权限
|
-- 描述: 为novalon用户授予所有表的访问权限
|
||||||
|
|
||||||
-- 授予所有表的SELECT, INSERT, UPDATE, DELETE权限
|
-- 授予所有表的SELECT, INSERT, UPDATE, DELETE权限
|
||||||
-4
@@ -47,7 +47,6 @@ public class JwtAuthenticationFilter extends AbstractGatewayFilterFactory<JwtAut
|
|||||||
|
|
||||||
ServerHttpRequest modifiedRequest = request.mutate()
|
ServerHttpRequest modifiedRequest = request.mutate()
|
||||||
.header("X-User-Id", String.valueOf(userId))
|
.header("X-User-Id", String.valueOf(userId))
|
||||||
.header("X-Member-Id", String.valueOf(userId))
|
|
||||||
.header("X-Username", username)
|
.header("X-Username", username)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@@ -58,9 +57,6 @@ public class JwtAuthenticationFilter extends AbstractGatewayFilterFactory<JwtAut
|
|||||||
private boolean isPublicPath(String path) {
|
private boolean isPublicPath(String path) {
|
||||||
return path.startsWith("/api/auth/") ||
|
return path.startsWith("/api/auth/") ||
|
||||||
path.equals("/actuator/health") ||
|
path.equals("/actuator/health") ||
|
||||||
path.equals("/api/member/auth/miniapp/login") ||
|
|
||||||
path.equals("/api/member/auth/mp/callback") ||
|
|
||||||
path.equals("/api/auth/login") ||
|
|
||||||
path.startsWith("/actuator/info");
|
path.startsWith("/actuator/info");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,27 +9,27 @@ spring:
|
|||||||
cloud:
|
cloud:
|
||||||
gateway:
|
gateway:
|
||||||
routes:
|
routes:
|
||||||
- id: manage-app
|
- id: manage-app
|
||||||
uri: http://localhost:8084
|
uri: http://localhost:8084
|
||||||
predicates:
|
predicates:
|
||||||
- Path=/api/**
|
- Path=/api/**
|
||||||
default-filters:
|
default-filters:
|
||||||
- name: JwtAuthentication
|
- name: JwtAuthentication
|
||||||
- name: RbacAuthorization
|
- name: RbacAuthorization
|
||||||
- name: Retry
|
- name: Retry
|
||||||
args:
|
args:
|
||||||
retries: 3
|
retries: 3
|
||||||
statuses: BAD_GATEWAY,SERVICE_UNAVAILABLE
|
statuses: BAD_GATEWAY,SERVICE_UNAVAILABLE
|
||||||
methods: GET,POST
|
methods: GET,POST
|
||||||
backoff:
|
backoff:
|
||||||
firstBackoff: 10ms
|
firstBackoff: 10ms
|
||||||
maxBackoff: 50ms
|
maxBackoff: 50ms
|
||||||
factor: 2
|
factor: 2
|
||||||
basedOnPreviousValue: false
|
basedOnPreviousValue: false
|
||||||
- name: DedupeResponseHeader
|
- name: DedupeResponseHeader
|
||||||
args:
|
args:
|
||||||
name: Content-Encoding
|
name: Content-Encoding
|
||||||
strategy: RETAIN_FIRST
|
strategy: RETAIN_FIRST
|
||||||
|
|
||||||
jwt:
|
jwt:
|
||||||
secret: ${JWT_SECRET:enc:U2FsdGVkX1+vZ5Y9QmKxL8nN3rP7tW2jH4fG6dA8sB1cE5yN0zX3qV7wM4}
|
secret: ${JWT_SECRET:enc:U2FsdGVkX1+vZ5Y9QmKxL8nN3rP7tW2jH4fG6dA8sB1cE5yN0zX3qV7wM4}
|
||||||
@@ -64,7 +64,7 @@ signature:
|
|||||||
max-age-minutes: ${SIGNATURE_MAX_AGE_MINUTES:5}
|
max-age-minutes: ${SIGNATURE_MAX_AGE_MINUTES:5}
|
||||||
nonce-cache-size: ${SIGNATURE_NONCE_CACHE_SIZE:10000}
|
nonce-cache-size: ${SIGNATURE_NONCE_CACHE_SIZE:10000}
|
||||||
whitelist:
|
whitelist:
|
||||||
paths: ${SIGNATURE_WHITELIST_PATHS:/actuator/health,/actuator/info,/api/auth/login,/api/auth/register,/api/member/auth/miniapp/login,/api/member/auth/mp/callback}
|
paths: ${SIGNATURE_WHITELIST_PATHS:/actuator/health,/actuator/info,/api/auth/login}
|
||||||
|
|
||||||
resilience:
|
resilience:
|
||||||
enabled: ${RESILIENCE_ENABLED:true}
|
enabled: ${RESILIENCE_ENABLED:true}
|
||||||
|
|||||||
+242
-84
@@ -2,84 +2,186 @@ package cn.novalon.gym.manage.sys.audit;
|
|||||||
|
|
||||||
import cn.novalon.gym.manage.sys.audit.domain.AuditLog;
|
import cn.novalon.gym.manage.sys.audit.domain.AuditLog;
|
||||||
import cn.novalon.gym.manage.sys.audit.service.IAuditLogService;
|
import cn.novalon.gym.manage.sys.audit.service.IAuditLogService;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||||
|
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.Around;
|
import org.aspectj.lang.annotation.Around;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Before;
|
|
||||||
import org.aspectj.lang.reflect.MethodSignature;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.data.domain.Persistable;
|
||||||
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
|
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 审计日志切面
|
||||||
|
*
|
||||||
|
* 文件定义:使用AOP自动拦截Repository操作,记录审计日志
|
||||||
|
* 涉及业务:自动记录所有数据变更操作,包括变更前后对比
|
||||||
|
* 算法:使用异步方式记录日志,不阻塞主流程
|
||||||
|
*
|
||||||
|
* @author 张翔
|
||||||
|
* @date 2026-04-01
|
||||||
|
*/
|
||||||
@Aspect
|
@Aspect
|
||||||
@Component
|
@Component
|
||||||
@Deprecated
|
|
||||||
public class AuditLogAspect {
|
public class AuditLogAspect {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(AuditLogAspect.class);
|
private static final Logger logger = LoggerFactory.getLogger(AuditLogAspect.class);
|
||||||
|
|
||||||
private final IAuditLogService auditLogService;
|
private final IAuditLogService auditLogService;
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
public AuditLogAspect(IAuditLogService auditLogService) {
|
public AuditLogAspect(IAuditLogService auditLogService, ObjectMapper objectMapper) {
|
||||||
this.auditLogService = auditLogService;
|
this.auditLogService = auditLogService;
|
||||||
logger.info("=== AuditLogAspect 初始化完成 ===");
|
this.objectMapper = new ObjectMapper()
|
||||||
|
.registerModule(new JavaTimeModule())
|
||||||
|
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||||
|
.disable(SerializationFeature.FAIL_ON_SELF_REFERENCES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before("execution(* cn.novalon.gym.manage.sys.core.service.impl.SysUserService.createUser(..))")
|
@Around("(execution(* cn.novalon.gym.manage.db.repository.*Repository.save(..)) || " +
|
||||||
public void testAopWorking() {
|
"execution(* cn.novalon.gym.manage.db.repository.*Repository.delete(..)) || " +
|
||||||
logger.info("=== AuditLogAspect @Before 测试: SysUserService.createUser 被调用 ===");
|
"execution(* cn.novalon.gym.manage.db.repository.*Repository.deleteById(..))) && " +
|
||||||
}
|
"!execution(* cn.novalon.gym.manage.db.repository.AuditLogRepository.*(..)) && " +
|
||||||
|
"!execution(* cn.novalon.gym.manage.db.dao.AuditLogDao.*(..))")
|
||||||
@Around("@annotation(auditable)")
|
public Object logAuditEvent(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
public Object logAuditEvent(ProceedingJoinPoint joinPoint, Auditable auditable) throws Throwable {
|
String methodName = joinPoint.getSignature().getName();
|
||||||
String methodName = ((MethodSignature) joinPoint.getSignature()).getName();
|
|
||||||
String className = joinPoint.getTarget().getClass().getSimpleName();
|
String className = joinPoint.getTarget().getClass().getSimpleName();
|
||||||
String entityType = auditable.entityType();
|
Object[] args = joinPoint.getArgs();
|
||||||
String operationType = auditable.operationType();
|
|
||||||
|
String operationType = determineOperationType(methodName);
|
||||||
logger.debug("审计切面拦截: {}.{}(), entityType={}, operationType={}", className, methodName, entityType, operationType);
|
String entityType = extractEntityType(className);
|
||||||
|
|
||||||
|
logger.debug("拦截审计操作: {}.{}, 操作类型: {}, 实体类型: {}",
|
||||||
|
className, methodName, operationType, entityType);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Object result = joinPoint.proceed();
|
if ("save".equals(methodName) && args.length > 0) {
|
||||||
|
return handleSaveOperation(joinPoint, args[0], entityType, operationType);
|
||||||
if (result instanceof Mono) {
|
} else if ("delete".equals(methodName) || "deleteById".equals(methodName)) {
|
||||||
return ((Mono<Object>) result).flatMap(retValue -> {
|
return handleDeleteOperation(joinPoint, args, entityType, operationType);
|
||||||
Long entityId = extractIdFromResult(retValue);
|
|
||||||
String afterData = serializeEntity(retValue);
|
|
||||||
return createAndSaveAuditLog(
|
|
||||||
entityType, entityId, operationType,
|
|
||||||
null, afterData
|
|
||||||
).thenReturn(retValue);
|
|
||||||
});
|
|
||||||
} else if (result instanceof Flux) {
|
|
||||||
return ((Flux<Object>) result).collectList()
|
|
||||||
.flatMapMany(list -> {
|
|
||||||
String afterData = serializeEntity(list);
|
|
||||||
return createAndSaveAuditLog(
|
|
||||||
entityType, null, operationType,
|
|
||||||
null, afterData
|
|
||||||
).thenMany(Flux.fromIterable(list));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return joinPoint.proceed();
|
||||||
} catch (Throwable error) {
|
} catch (Throwable error) {
|
||||||
logger.error("审计日志记录失败: {}.{}()", className, methodName, error);
|
logger.error("审计日志记录失败: {}", error.getMessage(), error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mono<Void> createAndSaveAuditLog(String entityType, Long entityId,
|
private Object handleSaveOperation(ProceedingJoinPoint joinPoint, Object entity,
|
||||||
String operationType, String beforeData,
|
String entityType, String operationType) throws Throwable {
|
||||||
String afterData) {
|
String entityClassName = entity.getClass().getSimpleName();
|
||||||
logger.debug("创建审计日志: entityType={}, entityId={}, operationType={}", entityType, entityId, operationType);
|
if (entityClassName.contains("AuditLog") || entityClassName.contains("AuditLogEntity")) {
|
||||||
|
logger.debug("跳过审计日志实体的审计记录: {}", entityClassName);
|
||||||
|
return joinPoint.proceed();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
final String[] beforeDataHolder = {null};
|
||||||
|
final Long[] entityIdHolder = {null};
|
||||||
|
final String[] operationTypeHolder = {operationType};
|
||||||
|
|
||||||
|
if (entity instanceof Persistable) {
|
||||||
|
Persistable<?> persistable = (Persistable<?>) entity;
|
||||||
|
entityIdHolder[0] = persistable.getId() != null ?
|
||||||
|
((Number) persistable.getId()).longValue() : null;
|
||||||
|
|
||||||
|
if (entityIdHolder[0] != null) {
|
||||||
|
beforeDataHolder[0] = fetchEntityBeforeData(entityType, entityIdHolder[0]);
|
||||||
|
operationTypeHolder[0] = "UPDATE";
|
||||||
|
} else {
|
||||||
|
operationTypeHolder[0] = "CREATE";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Object result = joinPoint.proceed();
|
||||||
|
|
||||||
|
if (result instanceof Mono) {
|
||||||
|
return ((Mono<?>) result).flatMap(savedEntity -> {
|
||||||
|
String afterData = serializeEntity(savedEntity);
|
||||||
|
Long finalEntityId = entityIdHolder[0] != null ? entityIdHolder[0] : extractEntityId(savedEntity);
|
||||||
|
String finalOperationType = operationTypeHolder[0];
|
||||||
|
String finalBeforeData = beforeDataHolder[0];
|
||||||
|
|
||||||
|
logger.debug("保存操作审计日志: entityType={}, entityIdHolder={}, extractedEntityId={}, finalEntityId={}",
|
||||||
|
entityType, entityIdHolder[0], extractEntityId(savedEntity), finalEntityId);
|
||||||
|
|
||||||
|
return createAndSaveAuditLog(
|
||||||
|
entityType, finalEntityId, finalOperationType,
|
||||||
|
finalBeforeData, afterData, savedEntity
|
||||||
|
).thenReturn(savedEntity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} catch (Throwable error) {
|
||||||
|
logger.error("保存操作审计日志记录失败", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object handleDeleteOperation(ProceedingJoinPoint joinPoint, Object[] args,
|
||||||
|
String entityType, String operationType) throws Throwable {
|
||||||
|
try {
|
||||||
|
Long entityId = null;
|
||||||
|
String beforeData = null;
|
||||||
|
|
||||||
|
if (args.length > 0) {
|
||||||
|
if (args[0] instanceof Number) {
|
||||||
|
entityId = ((Number) args[0]).longValue();
|
||||||
|
beforeData = fetchEntityBeforeData(entityType, entityId);
|
||||||
|
} else if (args[0] instanceof Persistable) {
|
||||||
|
Persistable<?> persistable = (Persistable<?>) args[0];
|
||||||
|
entityId = persistable.getId() != null ?
|
||||||
|
((Number) persistable.getId()).longValue() : null;
|
||||||
|
beforeData = serializeEntity(args[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Object result = joinPoint.proceed();
|
||||||
|
|
||||||
|
if (result instanceof Mono) {
|
||||||
|
Long finalEntityId = entityId;
|
||||||
|
String finalBeforeData = beforeData;
|
||||||
|
return ((Mono<?>) result).flatMap(deleted ->
|
||||||
|
createAndSaveAuditLog(
|
||||||
|
entityType, finalEntityId, "DELETE",
|
||||||
|
finalBeforeData, null, null
|
||||||
|
).thenReturn(deleted)
|
||||||
|
);
|
||||||
|
} else if (result instanceof Flux) {
|
||||||
|
Long finalEntityId = entityId;
|
||||||
|
String finalBeforeData = beforeData;
|
||||||
|
return ((Flux<?>) result).flatMap(deleted ->
|
||||||
|
createAndSaveAuditLog(
|
||||||
|
entityType, finalEntityId, "DELETE",
|
||||||
|
finalBeforeData, null, null
|
||||||
|
).thenReturn(deleted)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} catch (Throwable error) {
|
||||||
|
logger.error("删除操作审计日志记录失败", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Mono<Void> createAndSaveAuditLog(String entityType, Long entityId,
|
||||||
|
String operationType, String beforeData,
|
||||||
|
String afterData, Object entity) {
|
||||||
|
logger.debug("创建审计日志: entityType={}, entityId={}, operationType={}", entityType, entityId, operationType);
|
||||||
return ReactiveSecurityContextHolder.getContext()
|
return ReactiveSecurityContextHolder.getContext()
|
||||||
.map(ctx -> ctx.getAuthentication().getPrincipal())
|
.map(ctx -> ctx.getAuthentication().getPrincipal())
|
||||||
.defaultIfEmpty("system")
|
.defaultIfEmpty("system")
|
||||||
@@ -91,12 +193,22 @@ public class AuditLogAspect {
|
|||||||
auditLog.setOperator(principal instanceof String ? (String) principal : "system");
|
auditLog.setOperator(principal instanceof String ? (String) principal : "system");
|
||||||
auditLog.setBeforeData(beforeData);
|
auditLog.setBeforeData(beforeData);
|
||||||
auditLog.setAfterData(afterData);
|
auditLog.setAfterData(afterData);
|
||||||
|
|
||||||
|
logger.debug("审计日志对象: entityId={}, entityType={}, operationType={}",
|
||||||
|
auditLog.getEntityId(), auditLog.getEntityType(), auditLog.getOperationType());
|
||||||
|
|
||||||
|
if (beforeData != null && afterData != null) {
|
||||||
|
String[] changedFields = extractChangedFields(beforeData, afterData);
|
||||||
|
auditLog.setChangedFields(changedFields);
|
||||||
|
}
|
||||||
|
|
||||||
auditLog.setDescription(generateDescription(entityType, operationType, entityId));
|
auditLog.setDescription(generateDescription(entityType, operationType, entityId));
|
||||||
|
|
||||||
return auditLogService.saveAsync(auditLog)
|
return auditLogService.save(auditLog)
|
||||||
.doOnSuccess(saved -> logger.debug("审计日志保存成功: {} - {}, ID={}",
|
.doOnSuccess(saved -> logger.debug("审计日志保存成功: {} - {}",
|
||||||
entityType, operationType, saved.getId()))
|
entityType, operationType))
|
||||||
.doOnError(error -> logger.error("审计日志保存失败: {}", error.getMessage()))
|
.doOnError(error -> logger.error("审计日志保存失败: {}",
|
||||||
|
error.getMessage()))
|
||||||
.then();
|
.then();
|
||||||
})
|
})
|
||||||
.onErrorResume(error -> {
|
.onErrorResume(error -> {
|
||||||
@@ -105,53 +217,99 @@ public class AuditLogAspect {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Long extractIdFromResult(Object result) {
|
private String determineOperationType(String methodName) {
|
||||||
if (result == null) {
|
if (methodName.startsWith("save")) {
|
||||||
return null;
|
return "SAVE";
|
||||||
|
} else if (methodName.startsWith("delete")) {
|
||||||
|
return "DELETE";
|
||||||
}
|
}
|
||||||
try {
|
return "UNKNOWN";
|
||||||
var getIdMethod = result.getClass().getMethod("getId");
|
}
|
||||||
Object id = getIdMethod.invoke(result);
|
|
||||||
if (id instanceof Number) {
|
private String extractEntityType(String className) {
|
||||||
return ((Number) id).longValue();
|
if (className.contains("User")) {
|
||||||
}
|
return "User";
|
||||||
if (id instanceof String) {
|
} else if (className.contains("Role")) {
|
||||||
try {
|
return "Role";
|
||||||
return Long.parseLong((String) id);
|
} else if (className.contains("Menu")) {
|
||||||
} catch (NumberFormatException e) {
|
return "Menu";
|
||||||
return null;
|
} else if (className.contains("Permission")) {
|
||||||
}
|
return "Permission";
|
||||||
}
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
logger.debug("结果对象没有getId方法: {}", result.getClass().getSimpleName());
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.debug("提取结果ID失败: {}", e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
return className.replace("Repository", "").replace("Impl", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String fetchEntityBeforeData(String entityType, Long entityId) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String serializeEntity(Object entity) {
|
private String serializeEntity(Object entity) {
|
||||||
try {
|
try {
|
||||||
ObjectMapper mapper = new ObjectMapper()
|
return objectMapper.writeValueAsString(entity);
|
||||||
.registerModule(new JavaTimeModule())
|
|
||||||
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
|
||||||
.disable(SerializationFeature.FAIL_ON_SELF_REFERENCES);
|
|
||||||
return mapper.writeValueAsString(entity);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("序列化实体失败: {}", e.getMessage());
|
logger.error("序列化实体失败: {}", e.getMessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String generateDescription(String entityType, String operationType, Long entityId) {
|
private Long extractEntityId(Object entity) {
|
||||||
String operation = switch (operationType) {
|
logger.debug("提取实体ID: entity class={}", entity.getClass().getName());
|
||||||
case "CREATE" -> "创建";
|
if (entity instanceof Persistable) {
|
||||||
case "UPDATE" -> "更新";
|
Persistable<?> persistable = (Persistable<?>) entity;
|
||||||
case "DELETE" -> "删除";
|
Object id = persistable.getId();
|
||||||
default -> "操作";
|
logger.debug("Persistable实体ID: id={}, isNew={}", id, persistable.isNew());
|
||||||
};
|
return id != null ? ((Number) id).longValue() : null;
|
||||||
|
}
|
||||||
|
logger.debug("实体不是Persistable类型");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return String.format("%s%s (ID: %s)", operation, entityType,
|
private String[] extractChangedFields(String beforeData, String afterData) {
|
||||||
entityId != null ? entityId : "未知");
|
try {
|
||||||
|
JsonNode beforeNode = objectMapper.readTree(beforeData);
|
||||||
|
JsonNode afterNode = objectMapper.readTree(afterData);
|
||||||
|
|
||||||
|
List<String> changedFields = new ArrayList<>();
|
||||||
|
|
||||||
|
beforeNode.fieldNames().forEachRemaining(fieldName -> {
|
||||||
|
JsonNode beforeValue = beforeNode.get(fieldName);
|
||||||
|
JsonNode afterValue = afterNode.get(fieldName);
|
||||||
|
|
||||||
|
if (afterValue == null || !beforeValue.equals(afterValue)) {
|
||||||
|
changedFields.add(fieldName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
afterNode.fieldNames().forEachRemaining(fieldName -> {
|
||||||
|
if (!beforeNode.has(fieldName)) {
|
||||||
|
changedFields.add(fieldName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return changedFields.toArray(new String[0]);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("提取变更字段失败: {}", e.getMessage());
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String generateDescription(String entityType, String operationType, Long entityId) {
|
||||||
|
String operation = "";
|
||||||
|
switch (operationType) {
|
||||||
|
case "CREATE":
|
||||||
|
operation = "创建";
|
||||||
|
break;
|
||||||
|
case "UPDATE":
|
||||||
|
operation = "更新";
|
||||||
|
break;
|
||||||
|
case "DELETE":
|
||||||
|
operation = "删除";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
operation = "操作";
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.format("%s%s (ID: %s)", operation, entityType,
|
||||||
|
entityId != null ? entityId : "未知");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-80
@@ -1,80 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.sys.audit;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.sys.audit.domain.AuditLog;
|
|
||||||
import cn.novalon.gym.manage.sys.audit.service.IAuditLogService;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
public final class AuditLogHelper {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(AuditLogHelper.class);
|
|
||||||
private static final ObjectMapper objectMapper = new ObjectMapper()
|
|
||||||
.registerModule(new JavaTimeModule())
|
|
||||||
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
|
||||||
.disable(SerializationFeature.FAIL_ON_SELF_REFERENCES);
|
|
||||||
|
|
||||||
private AuditLogHelper() {}
|
|
||||||
|
|
||||||
public static Mono<Void> record(IAuditLogService auditLogService,
|
|
||||||
String entityType, Long entityId,
|
|
||||||
String operationType, Object afterEntity) {
|
|
||||||
return record(auditLogService, entityType, entityId, operationType, null, afterEntity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Mono<Void> record(IAuditLogService auditLogService,
|
|
||||||
String entityType, Long entityId,
|
|
||||||
String operationType, Object beforeEntity, Object afterEntity) {
|
|
||||||
return ReactiveSecurityContextHolder.getContext()
|
|
||||||
.map(ctx -> ctx.getAuthentication().getPrincipal())
|
|
||||||
.defaultIfEmpty("system")
|
|
||||||
.flatMap(principal -> {
|
|
||||||
AuditLog auditLog = new AuditLog();
|
|
||||||
auditLog.generateId();
|
|
||||||
auditLog.setEntityType(entityType);
|
|
||||||
auditLog.setEntityId(entityId != null ? entityId : 0L);
|
|
||||||
auditLog.setOperationType(operationType);
|
|
||||||
auditLog.setOperator(principal instanceof String ? (String) principal : "system");
|
|
||||||
auditLog.setBeforeData(serializeEntity(beforeEntity));
|
|
||||||
auditLog.setAfterData(serializeEntity(afterEntity));
|
|
||||||
auditLog.setDescription(generateDescription(entityType, operationType, entityId));
|
|
||||||
|
|
||||||
logger.info("记录审计日志: {} {} ID={}, operator={}", operationType, entityType, entityId, auditLog.getOperator());
|
|
||||||
|
|
||||||
return auditLogService.saveAsync(auditLog)
|
|
||||||
.doOnSuccess(saved -> logger.info("审计日志保存成功: {} - {}, ID={}",
|
|
||||||
entityType, operationType, saved.getId()))
|
|
||||||
.doOnError(error -> logger.error("审计日志保存失败: {}", error.getMessage()))
|
|
||||||
.then();
|
|
||||||
})
|
|
||||||
.onErrorResume(error -> {
|
|
||||||
logger.error("记录审计日志失败,但不影响主流程: {}", error.getMessage(), error);
|
|
||||||
return Mono.empty();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String serializeEntity(Object entity) {
|
|
||||||
try {
|
|
||||||
if (entity == null) return null;
|
|
||||||
return objectMapper.writeValueAsString(entity);
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("序列化实体失败: {}", e.getMessage());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String generateDescription(String entityType, String operationType, Long entityId) {
|
|
||||||
String operation = switch (operationType) {
|
|
||||||
case "CREATE" -> "创建";
|
|
||||||
case "UPDATE" -> "更新";
|
|
||||||
case "DELETE" -> "删除";
|
|
||||||
default -> "操作";
|
|
||||||
};
|
|
||||||
return String.format("%s%s (ID: %s)", operation, entityType,
|
|
||||||
entityId != null ? entityId : "未知");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-15
@@ -1,15 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.sys.audit;
|
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
|
||||||
|
|
||||||
@Target(ElementType.METHOD)
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Documented
|
|
||||||
public @interface Auditable {
|
|
||||||
|
|
||||||
String entityType();
|
|
||||||
|
|
||||||
String operationType() default "CREATE";
|
|
||||||
|
|
||||||
String description() default "";
|
|
||||||
}
|
|
||||||
-181
@@ -1,181 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.sys.audit;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.sys.core.domain.OperationLog;
|
|
||||||
import cn.novalon.gym.manage.sys.core.service.IOperationLogService;
|
|
||||||
import cn.novalon.gym.manage.sys.util.IpUtils;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import jakarta.annotation.PostConstruct;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.core.Ordered;
|
|
||||||
import org.springframework.core.annotation.Order;
|
|
||||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
|
||||||
import org.springframework.http.HttpMethod;
|
|
||||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
||||||
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.web.reactive.function.server.HandlerStrategies;
|
|
||||||
import org.springframework.web.reactive.function.server.RouterFunction;
|
|
||||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
|
||||||
import org.springframework.web.server.WebFilter;
|
|
||||||
import org.springframework.web.server.WebFilterChain;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@Order(Ordered.LOWEST_PRECEDENCE)
|
|
||||||
public class OperationLogWebFilter implements WebFilter {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(OperationLogWebFilter.class);
|
|
||||||
|
|
||||||
private final IOperationLogService operationLogService;
|
|
||||||
private final ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
private static final Map<String, OperationInfo> OPERATION_MAPPING = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
OPERATION_MAPPING.put("POST:/api/roles", new OperationInfo("角色管理", "创建角色"));
|
|
||||||
OPERATION_MAPPING.put("PUT:/api/roles/", new OperationInfo("角色管理", "更新角色"));
|
|
||||||
OPERATION_MAPPING.put("DELETE:/api/roles/", new OperationInfo("角色管理", "删除角色"));
|
|
||||||
OPERATION_MAPPING.put("POST:/api/users", new OperationInfo("用户管理", "创建用户"));
|
|
||||||
OPERATION_MAPPING.put("PUT:/api/users/", new OperationInfo("用户管理", "更新用户"));
|
|
||||||
OPERATION_MAPPING.put("DELETE:/api/users/", new OperationInfo("用户管理", "删除用户"));
|
|
||||||
OPERATION_MAPPING.put("POST:/api/users/", new OperationInfo("用户管理", "用户操作"));
|
|
||||||
OPERATION_MAPPING.put("POST:/api/menus", new OperationInfo("菜单管理", "创建菜单"));
|
|
||||||
OPERATION_MAPPING.put("PUT:/api/menus/", new OperationInfo("菜单管理", "更新菜单"));
|
|
||||||
OPERATION_MAPPING.put("DELETE:/api/menus/", new OperationInfo("菜单管理", "删除菜单"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public OperationLogWebFilter(IOperationLogService operationLogService, ObjectMapper objectMapper) {
|
|
||||||
logger.info("=== OperationLogWebFilter 构造函数被调用 ===");
|
|
||||||
this.operationLogService = operationLogService;
|
|
||||||
this.objectMapper = objectMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void init() {
|
|
||||||
logger.info("=== OperationLogWebFilter 初始化 ===");
|
|
||||||
logger.info("操作日志映射配置数量: {}", OPERATION_MAPPING.size());
|
|
||||||
OPERATION_MAPPING.forEach((key, value) -> {
|
|
||||||
logger.info(" {} -> {}:{}", key, value.module, value.operation);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
|
||||||
ServerHttpRequest request = exchange.getRequest();
|
|
||||||
String method = request.getMethod().name();
|
|
||||||
String path = request.getPath().value();
|
|
||||||
|
|
||||||
logger.info("WebFilter 拦截请求: {} {}", method, path);
|
|
||||||
|
|
||||||
OperationInfo operationInfo = findOperationInfo(method, path);
|
|
||||||
|
|
||||||
if (operationInfo == null) {
|
|
||||||
logger.info("未匹配到操作日志配置,跳过: {} {}", method, path);
|
|
||||||
return chain.filter(exchange);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("匹配到操作日志配置: {} {} -> {}:{}", method, path, operationInfo.module, operationInfo.operation);
|
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
String ip = IpUtils.getClientIp(request);
|
|
||||||
|
|
||||||
return Mono.deferContextual(contextView -> {
|
|
||||||
return chain.filter(exchange)
|
|
||||||
.then(Mono.defer(() -> {
|
|
||||||
long duration = System.currentTimeMillis() - startTime;
|
|
||||||
logger.info("请求处理完成,准备保存操作日志: {} {}, 耗时: {}ms", method, path, duration);
|
|
||||||
|
|
||||||
return ReactiveSecurityContextHolder.getContext()
|
|
||||||
.flatMap(securityContext -> {
|
|
||||||
Object principal = securityContext.getAuthentication().getPrincipal();
|
|
||||||
String username = principal instanceof String ? (String) principal : "system";
|
|
||||||
logger.info("获取到用户名: {}", username);
|
|
||||||
return Mono.just(username);
|
|
||||||
})
|
|
||||||
.defaultIfEmpty("system")
|
|
||||||
.flatMap(username -> {
|
|
||||||
logger.info("开始保存操作日志: 用户={}, 操作={}", username,
|
|
||||||
operationInfo.module + " - " + operationInfo.operation);
|
|
||||||
|
|
||||||
OperationLog log = new OperationLog();
|
|
||||||
log.setUsername(username);
|
|
||||||
log.setOperation(operationInfo.module + " - " + operationInfo.operation);
|
|
||||||
log.setMethod(method + " " + path);
|
|
||||||
log.setParams(null);
|
|
||||||
log.setIp(ip);
|
|
||||||
log.setDuration(duration);
|
|
||||||
log.setStatus("0");
|
|
||||||
|
|
||||||
return operationLogService.save(log)
|
|
||||||
.doOnSuccess(saved -> logger.info("操作日志保存成功: {} - {}",
|
|
||||||
operationInfo.module, operationInfo.operation))
|
|
||||||
.doOnError(e -> logger.error("操作日志保存失败: {}", e.getMessage(), e))
|
|
||||||
.onErrorResume(e -> Mono.empty());
|
|
||||||
})
|
|
||||||
.then();
|
|
||||||
}))
|
|
||||||
.onErrorResume(error -> {
|
|
||||||
long duration = System.currentTimeMillis() - startTime;
|
|
||||||
logger.error("请求处理失败: {} {}, 错误: {}", method, path, error.getMessage());
|
|
||||||
|
|
||||||
return ReactiveSecurityContextHolder.getContext()
|
|
||||||
.flatMap(securityContext -> {
|
|
||||||
Object principal = securityContext.getAuthentication().getPrincipal();
|
|
||||||
String username = principal instanceof String ? (String) principal : "system";
|
|
||||||
return Mono.just(username);
|
|
||||||
})
|
|
||||||
.defaultIfEmpty("system")
|
|
||||||
.flatMap(username -> {
|
|
||||||
OperationLog log = new OperationLog();
|
|
||||||
log.setUsername(username);
|
|
||||||
log.setOperation(operationInfo.module + " - " + operationInfo.operation);
|
|
||||||
log.setMethod(method + " " + path);
|
|
||||||
log.setParams(null);
|
|
||||||
log.setIp(ip);
|
|
||||||
log.setDuration(duration);
|
|
||||||
log.setStatus("1");
|
|
||||||
log.setErrorMsg(error.getMessage());
|
|
||||||
|
|
||||||
return operationLogService.save(log)
|
|
||||||
.doOnError(e -> logger.error("错误日志保存失败: {}", e.getMessage()))
|
|
||||||
.onErrorResume(e -> Mono.empty());
|
|
||||||
})
|
|
||||||
.then(Mono.error(error));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private OperationInfo findOperationInfo(String method, String path) {
|
|
||||||
String key = method + ":" + path;
|
|
||||||
if (OPERATION_MAPPING.containsKey(key)) {
|
|
||||||
return OPERATION_MAPPING.get(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Map.Entry<String, OperationInfo> entry : OPERATION_MAPPING.entrySet()) {
|
|
||||||
String mappingKey = entry.getKey();
|
|
||||||
if (key.startsWith(mappingKey)) {
|
|
||||||
return entry.getValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class OperationInfo {
|
|
||||||
final String module;
|
|
||||||
final String operation;
|
|
||||||
|
|
||||||
OperationInfo(String module, String operation) {
|
|
||||||
this.module = module;
|
|
||||||
this.operation = operation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+3
-3
@@ -39,7 +39,7 @@ public class AuditLogArchiveService implements IAuditLogArchiveService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(transactionManager = "connectionFactoryTransactionManager")
|
@Transactional
|
||||||
public Mono<Long> archiveOldLogs(int daysToKeep) {
|
public Mono<Long> archiveOldLogs(int daysToKeep) {
|
||||||
LocalDateTime archiveBefore = LocalDateTime.now().minusDays(daysToKeep);
|
LocalDateTime archiveBefore = LocalDateTime.now().minusDays(daysToKeep);
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ public class AuditLogArchiveService implements IAuditLogArchiveService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(transactionManager = "connectionFactoryTransactionManager")
|
@Transactional
|
||||||
public Mono<AuditLogArchive> archiveLog(AuditLog auditLog) {
|
public Mono<AuditLogArchive> archiveLog(AuditLog auditLog) {
|
||||||
AuditLogArchive archive = convertToArchive(auditLog);
|
AuditLogArchive archive = convertToArchive(auditLog);
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ public class AuditLogArchiveService implements IAuditLogArchiveService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(transactionManager = "connectionFactoryTransactionManager")
|
@Transactional
|
||||||
public Mono<Void> deleteArchivedLogsOlderThan(LocalDateTime date) {
|
public Mono<Void> deleteArchivedLogsOlderThan(LocalDateTime date) {
|
||||||
return auditLogArchiveRepository.findByOperationTimeBetween(LocalDateTime.MIN, date)
|
return auditLogArchiveRepository.findByOperationTimeBetween(LocalDateTime.MIN, date)
|
||||||
.flatMap(archive -> auditLogArchiveRepository.deleteById(archive.getId()))
|
.flatMap(archive -> auditLogArchiveRepository.deleteById(archive.getId()))
|
||||||
|
|||||||
+5
-5
@@ -160,13 +160,13 @@ public class AuditLogService implements IAuditLogService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(transactionManager = "connectionFactoryTransactionManager")
|
@Transactional
|
||||||
public Mono<Void> deleteById(Long id) {
|
public Mono<Void> deleteById(Long id) {
|
||||||
return auditLogRepository.deleteById(id);
|
return auditLogRepository.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(transactionManager = "connectionFactoryTransactionManager")
|
@Transactional
|
||||||
public Mono<Void> logicalDeleteById(Long id) {
|
public Mono<Void> logicalDeleteById(Long id) {
|
||||||
return auditLogRepository.findById(id)
|
return auditLogRepository.findById(id)
|
||||||
.flatMap(auditLog -> {
|
.flatMap(auditLog -> {
|
||||||
@@ -177,7 +177,7 @@ public class AuditLogService implements IAuditLogService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(transactionManager = "connectionFactoryTransactionManager")
|
@Transactional
|
||||||
public Mono<Void> logicalDeleteByIds(List<Long> ids) {
|
public Mono<Void> logicalDeleteByIds(List<Long> ids) {
|
||||||
return Flux.fromIterable(ids)
|
return Flux.fromIterable(ids)
|
||||||
.flatMap(this::logicalDeleteById)
|
.flatMap(this::logicalDeleteById)
|
||||||
@@ -185,7 +185,7 @@ public class AuditLogService implements IAuditLogService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(transactionManager = "connectionFactoryTransactionManager")
|
@Transactional
|
||||||
public Mono<Void> restoreById(Long id) {
|
public Mono<Void> restoreById(Long id) {
|
||||||
return auditLogRepository.findById(id)
|
return auditLogRepository.findById(id)
|
||||||
.flatMap(auditLog -> {
|
.flatMap(auditLog -> {
|
||||||
@@ -196,7 +196,7 @@ public class AuditLogService implements IAuditLogService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(transactionManager = "connectionFactoryTransactionManager")
|
@Transactional
|
||||||
public Mono<Void> restoreByIds(List<Long> ids) {
|
public Mono<Void> restoreByIds(List<Long> ids) {
|
||||||
return Flux.fromIterable(ids)
|
return Flux.fromIterable(ids)
|
||||||
.flatMap(this::restoreById)
|
.flatMap(this::restoreById)
|
||||||
|
|||||||
+7
-7
@@ -1,6 +1,5 @@
|
|||||||
package cn.novalon.gym.manage.sys.config;
|
package cn.novalon.gym.manage.sys.config;
|
||||||
|
|
||||||
import cn.novalon.gym.manage.sys.audit.OperationLogWebFilter;
|
|
||||||
import cn.novalon.gym.manage.sys.security.JwtAuthenticationFilter;
|
import cn.novalon.gym.manage.sys.security.JwtAuthenticationFilter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -12,20 +11,22 @@ import org.springframework.security.config.web.server.SecurityWebFiltersOrder;
|
|||||||
import org.springframework.security.config.web.server.ServerHttpSecurity;
|
import org.springframework.security.config.web.server.ServerHttpSecurity;
|
||||||
import org.springframework.security.web.server.SecurityWebFilterChain;
|
import org.springframework.security.web.server.SecurityWebFilterChain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全配置类
|
||||||
|
*
|
||||||
|
* @author 张翔
|
||||||
|
* @date 2026-03-13
|
||||||
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebFluxSecurity
|
@EnableWebFluxSecurity
|
||||||
public class SecurityConfig {
|
public class SecurityConfig {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(SecurityConfig.class);
|
private static final Logger logger = LoggerFactory.getLogger(SecurityConfig.class);
|
||||||
private final JwtAuthenticationFilter jwtAuthenticationFilter;
|
private final JwtAuthenticationFilter jwtAuthenticationFilter;
|
||||||
private final OperationLogWebFilter operationLogWebFilter;
|
|
||||||
private final Environment environment;
|
private final Environment environment;
|
||||||
|
|
||||||
public SecurityConfig(JwtAuthenticationFilter jwtAuthenticationFilter,
|
public SecurityConfig(JwtAuthenticationFilter jwtAuthenticationFilter, Environment environment) {
|
||||||
OperationLogWebFilter operationLogWebFilter,
|
|
||||||
Environment environment) {
|
|
||||||
this.jwtAuthenticationFilter = jwtAuthenticationFilter;
|
this.jwtAuthenticationFilter = jwtAuthenticationFilter;
|
||||||
this.operationLogWebFilter = operationLogWebFilter;
|
|
||||||
this.environment = environment;
|
this.environment = environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +46,6 @@ public class SecurityConfig {
|
|||||||
.httpBasic(ServerHttpSecurity.HttpBasicSpec::disable)
|
.httpBasic(ServerHttpSecurity.HttpBasicSpec::disable)
|
||||||
.formLogin(ServerHttpSecurity.FormLoginSpec::disable)
|
.formLogin(ServerHttpSecurity.FormLoginSpec::disable)
|
||||||
.addFilterBefore(jwtAuthenticationFilter, SecurityWebFiltersOrder.AUTHENTICATION)
|
.addFilterBefore(jwtAuthenticationFilter, SecurityWebFiltersOrder.AUTHENTICATION)
|
||||||
.addFilterAfter(operationLogWebFilter, SecurityWebFiltersOrder.AUTHORIZATION)
|
|
||||||
.authorizeExchange(spec -> {
|
.authorizeExchange(spec -> {
|
||||||
spec.pathMatchers("/api/auth/**").permitAll()
|
spec.pathMatchers("/api/auth/**").permitAll()
|
||||||
.pathMatchers("/api/public/**").permitAll()
|
.pathMatchers("/api/public/**").permitAll()
|
||||||
|
|||||||
-2
@@ -24,8 +24,6 @@ public interface ISysMenuRepository {
|
|||||||
|
|
||||||
Mono<SysMenu> save(SysMenu sysMenu);
|
Mono<SysMenu> save(SysMenu sysMenu);
|
||||||
|
|
||||||
Mono<SysMenu> update(SysMenu sysMenu);
|
|
||||||
|
|
||||||
Mono<Void> deleteById(Long id);
|
Mono<Void> deleteById(Long id);
|
||||||
|
|
||||||
Flux<SysMenu> findAll();
|
Flux<SysMenu> findAll();
|
||||||
|
|||||||
-2
@@ -28,8 +28,6 @@ public interface ISysUserRepository {
|
|||||||
|
|
||||||
Mono<SysUser> save(SysUser sysUser);
|
Mono<SysUser> save(SysUser sysUser);
|
||||||
|
|
||||||
Mono<SysUser> update(SysUser sysUser);
|
|
||||||
|
|
||||||
Mono<Void> deleteById(Long id);
|
Mono<Void> deleteById(Long id);
|
||||||
|
|
||||||
Flux<SysUser> findAll();
|
Flux<SysUser> findAll();
|
||||||
|
|||||||
+2
@@ -48,11 +48,13 @@ public class DictionaryService implements IDictionaryService {
|
|||||||
@Override
|
@Override
|
||||||
public Mono<Dictionary> save(Dictionary dictionary) {
|
public Mono<Dictionary> save(Dictionary dictionary) {
|
||||||
if (dictionary.getId() == null) {
|
if (dictionary.getId() == null) {
|
||||||
|
dictionary.setCreatedAt(LocalDateTime.now());
|
||||||
return checkTypeAndCodeExists(dictionary.getType(), dictionary.getCode())
|
return checkTypeAndCodeExists(dictionary.getType(), dictionary.getCode())
|
||||||
.flatMap(exists -> {
|
.flatMap(exists -> {
|
||||||
if (exists) {
|
if (exists) {
|
||||||
return Mono.error(new DictionaryAlreadyExistsException(dictionary.getType(), dictionary.getCode()));
|
return Mono.error(new DictionaryAlreadyExistsException(dictionary.getType(), dictionary.getCode()));
|
||||||
}
|
}
|
||||||
|
dictionary.setUpdatedAt(LocalDateTime.now());
|
||||||
return repository.save(dictionary);
|
return repository.save(dictionary);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -29,6 +29,7 @@ public class OperationLogService implements IOperationLogService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<OperationLog> save(OperationLog log) {
|
public Mono<OperationLog> save(OperationLog log) {
|
||||||
|
log.setCreatedAt(LocalDateTime.now());
|
||||||
return logRepository.save(log);
|
return logRepository.save(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-12
@@ -1,7 +1,5 @@
|
|||||||
package cn.novalon.gym.manage.sys.core.service.impl;
|
package cn.novalon.gym.manage.sys.core.service.impl;
|
||||||
|
|
||||||
import cn.novalon.gym.manage.sys.audit.AuditLogHelper;
|
|
||||||
import cn.novalon.gym.manage.sys.audit.service.IAuditLogService;
|
|
||||||
import cn.novalon.gym.manage.sys.core.domain.SysConfig;
|
import cn.novalon.gym.manage.sys.core.domain.SysConfig;
|
||||||
import cn.novalon.gym.manage.sys.core.repository.ISysConfigRepository;
|
import cn.novalon.gym.manage.sys.core.repository.ISysConfigRepository;
|
||||||
import cn.novalon.gym.manage.sys.core.service.ISysConfigService;
|
import cn.novalon.gym.manage.sys.core.service.ISysConfigService;
|
||||||
@@ -9,15 +7,19 @@ import org.springframework.stereotype.Service;
|
|||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统配置服务实现类
|
||||||
|
*
|
||||||
|
* @author 张翔
|
||||||
|
* @date 2026-03-14
|
||||||
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class SysConfigService implements ISysConfigService {
|
public class SysConfigService implements ISysConfigService {
|
||||||
|
|
||||||
private final ISysConfigRepository repository;
|
private final ISysConfigRepository repository;
|
||||||
private final IAuditLogService auditLogService;
|
|
||||||
|
|
||||||
public SysConfigService(ISysConfigRepository repository, IAuditLogService auditLogService) {
|
public SysConfigService(ISysConfigRepository repository) {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.auditLogService = auditLogService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -26,28 +28,27 @@ public class SysConfigService implements ISysConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
// @Cacheable(value = "sysConfig", key = "#id")
|
||||||
public Mono<SysConfig> findById(Long id) {
|
public Mono<SysConfig> findById(Long id) {
|
||||||
return repository.findById(id);
|
return repository.findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
// @Cacheable(value = "sysConfig", key = "#configKey")
|
||||||
public Mono<SysConfig> findByConfigKey(String configKey) {
|
public Mono<SysConfig> findByConfigKey(String configKey) {
|
||||||
return repository.findByConfigKeyAndDeletedAtIsNull(configKey);
|
return repository.findByConfigKeyAndDeletedAtIsNull(configKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
// @CacheEvict(value = "sysConfig", allEntries = true)
|
||||||
public Mono<SysConfig> save(SysConfig config) {
|
public Mono<SysConfig> save(SysConfig config) {
|
||||||
return repository.save(config)
|
return repository.save(config);
|
||||||
.flatMap(saved -> AuditLogHelper.record(auditLogService, "Config", saved.getId(), "CREATE", saved)
|
|
||||||
.thenReturn(saved));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
// @CacheEvict(value = "sysConfig", key = "#id")
|
||||||
public Mono<Void> deleteById(Long id) {
|
public Mono<Void> deleteById(Long id) {
|
||||||
return repository.findById(id)
|
return repository.deleteByIdAndDeletedAtIsNull(id);
|
||||||
.flatMap(config -> repository.deleteByIdAndDeletedAtIsNull(id)
|
|
||||||
.then(AuditLogHelper.record(auditLogService, "Config", id, "DELETE", config, null)))
|
|
||||||
.then();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+9
-12
@@ -1,7 +1,5 @@
|
|||||||
package cn.novalon.gym.manage.sys.core.service.impl;
|
package cn.novalon.gym.manage.sys.core.service.impl;
|
||||||
|
|
||||||
import cn.novalon.gym.manage.sys.audit.AuditLogHelper;
|
|
||||||
import cn.novalon.gym.manage.sys.audit.service.IAuditLogService;
|
|
||||||
import cn.novalon.gym.manage.sys.core.domain.SysDictType;
|
import cn.novalon.gym.manage.sys.core.domain.SysDictType;
|
||||||
import cn.novalon.gym.manage.sys.core.repository.ISysDictTypeRepository;
|
import cn.novalon.gym.manage.sys.core.repository.ISysDictTypeRepository;
|
||||||
import cn.novalon.gym.manage.sys.core.service.ISysDictTypeService;
|
import cn.novalon.gym.manage.sys.core.service.ISysDictTypeService;
|
||||||
@@ -9,15 +7,19 @@ import org.springframework.stereotype.Service;
|
|||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典类型服务实现类
|
||||||
|
*
|
||||||
|
* @author 张翔
|
||||||
|
* @date 2026-03-14
|
||||||
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class SysDictTypeService implements ISysDictTypeService {
|
public class SysDictTypeService implements ISysDictTypeService {
|
||||||
|
|
||||||
private final ISysDictTypeRepository repository;
|
private final ISysDictTypeRepository repository;
|
||||||
private final IAuditLogService auditLogService;
|
|
||||||
|
|
||||||
public SysDictTypeService(ISysDictTypeRepository repository, IAuditLogService auditLogService) {
|
public SysDictTypeService(ISysDictTypeRepository repository) {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.auditLogService = auditLogService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -37,16 +39,11 @@ public class SysDictTypeService implements ISysDictTypeService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<SysDictType> save(SysDictType dictType) {
|
public Mono<SysDictType> save(SysDictType dictType) {
|
||||||
return repository.save(dictType)
|
return repository.save(dictType);
|
||||||
.flatMap(saved -> AuditLogHelper.record(auditLogService, "Dict", saved.getId(), "CREATE", saved)
|
|
||||||
.thenReturn(saved));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> deleteById(Long id) {
|
public Mono<Void> deleteById(Long id) {
|
||||||
return repository.findById(id)
|
return repository.deleteByIdAndDeletedAtIsNull(id);
|
||||||
.flatMap(dict -> repository.deleteByIdAndDeletedAtIsNull(id)
|
|
||||||
.then(AuditLogHelper.record(auditLogService, "Dict", id, "DELETE", dict, null)))
|
|
||||||
.then();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-31
@@ -6,8 +6,6 @@ import cn.novalon.gym.manage.sys.core.service.ISysMenuService;
|
|||||||
import cn.novalon.gym.manage.sys.core.command.CreateMenuCommand;
|
import cn.novalon.gym.manage.sys.core.command.CreateMenuCommand;
|
||||||
import cn.novalon.gym.manage.sys.core.command.UpdateMenuCommand;
|
import cn.novalon.gym.manage.sys.core.command.UpdateMenuCommand;
|
||||||
import cn.novalon.gym.manage.common.util.StatusConstants;
|
import cn.novalon.gym.manage.common.util.StatusConstants;
|
||||||
import cn.novalon.gym.manage.sys.audit.AuditLogHelper;
|
|
||||||
import cn.novalon.gym.manage.sys.audit.service.IAuditLogService;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
@@ -26,11 +24,9 @@ import java.util.stream.Collectors;
|
|||||||
public class SysMenuService implements ISysMenuService {
|
public class SysMenuService implements ISysMenuService {
|
||||||
|
|
||||||
private final ISysMenuRepository menuRepository;
|
private final ISysMenuRepository menuRepository;
|
||||||
private final IAuditLogService auditLogService;
|
|
||||||
|
|
||||||
public SysMenuService(ISysMenuRepository menuRepository, IAuditLogService auditLogService) {
|
public SysMenuService(ISysMenuRepository menuRepository) {
|
||||||
this.menuRepository = menuRepository;
|
this.menuRepository = menuRepository;
|
||||||
this.auditLogService = auditLogService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -50,9 +46,8 @@ public class SysMenuService implements ISysMenuService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<SysMenu> createMenu(SysMenu menu) {
|
public Mono<SysMenu> createMenu(SysMenu menu) {
|
||||||
return menuRepository.save(menu)
|
menu.setCreatedAt(LocalDateTime.now());
|
||||||
.flatMap(saved -> AuditLogHelper.record(auditLogService, "Menu", saved.getId(), "CREATE", saved)
|
return menuRepository.save(menu);
|
||||||
.thenReturn(saved));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -65,18 +60,14 @@ public class SysMenuService implements ISysMenuService {
|
|||||||
menu.setComponent(command.component());
|
menu.setComponent(command.component());
|
||||||
menu.setPerms(command.perms());
|
menu.setPerms(command.perms());
|
||||||
menu.setStatus(command.status() != null ? command.status() : StatusConstants.ENABLED);
|
menu.setStatus(command.status() != null ? command.status() : StatusConstants.ENABLED);
|
||||||
return menuRepository.save(menu)
|
menu.setCreatedAt(LocalDateTime.now());
|
||||||
.flatMap(saved -> AuditLogHelper.record(auditLogService, "Menu", saved.getId(), "CREATE", saved)
|
return menuRepository.save(menu);
|
||||||
.thenReturn(saved));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<SysMenu> updateMenu(SysMenu menu) {
|
public Mono<SysMenu> updateMenu(SysMenu menu) {
|
||||||
menu.setUpdatedAt(LocalDateTime.now());
|
menu.setUpdatedAt(LocalDateTime.now());
|
||||||
return menuRepository.findById(menu.getId())
|
return menuRepository.save(menu);
|
||||||
.flatMap(before -> menuRepository.update(menu)
|
|
||||||
.flatMap(saved -> AuditLogHelper.record(auditLogService, "Menu", saved.getId(), "UPDATE", before, saved)
|
|
||||||
.thenReturn(saved)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -84,15 +75,6 @@ public class SysMenuService implements ISysMenuService {
|
|||||||
return menuRepository.findById(command.id())
|
return menuRepository.findById(command.id())
|
||||||
.switchIfEmpty(Mono.error(new RuntimeException("Menu not found")))
|
.switchIfEmpty(Mono.error(new RuntimeException("Menu not found")))
|
||||||
.flatMap(menu -> {
|
.flatMap(menu -> {
|
||||||
SysMenu before = new SysMenu();
|
|
||||||
before.setId(menu.getId());
|
|
||||||
before.setParentId(menu.getParentId());
|
|
||||||
before.setMenuName(menu.getMenuName());
|
|
||||||
before.setMenuType(menu.getMenuType());
|
|
||||||
before.setOrderNum(menu.getOrderNum());
|
|
||||||
before.setComponent(menu.getComponent());
|
|
||||||
before.setPerms(menu.getPerms());
|
|
||||||
before.setStatus(menu.getStatus());
|
|
||||||
if (command.parentId() != null) {
|
if (command.parentId() != null) {
|
||||||
menu.setParentId(command.parentId());
|
menu.setParentId(command.parentId());
|
||||||
}
|
}
|
||||||
@@ -115,18 +97,13 @@ public class SysMenuService implements ISysMenuService {
|
|||||||
menu.setStatus(command.status());
|
menu.setStatus(command.status());
|
||||||
}
|
}
|
||||||
menu.setUpdatedAt(LocalDateTime.now());
|
menu.setUpdatedAt(LocalDateTime.now());
|
||||||
return menuRepository.update(menu)
|
return menuRepository.save(menu);
|
||||||
.flatMap(saved -> AuditLogHelper.record(auditLogService, "Menu", saved.getId(), "UPDATE", before, saved)
|
|
||||||
.thenReturn(saved));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> deleteMenu(Long id) {
|
public Mono<Void> deleteMenu(Long id) {
|
||||||
return menuRepository.findById(id)
|
return menuRepository.deleteById(id);
|
||||||
.flatMap(menu -> menuRepository.deleteById(id)
|
|
||||||
.then(AuditLogHelper.record(auditLogService, "Menu", id, "DELETE", menu, null)))
|
|
||||||
.then();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user