初步完成页面
This commit is contained in:
@@ -0,0 +1,272 @@
|
||||
# V10 团课预约业务场景测试数据
|
||||
|
||||
## 概述
|
||||
|
||||
本文档描述了 V10 版本新增的团课预约功能测试数据,覆盖了7种典型的预约业务场景,用于验证系统在不同会员卡状态下的正确处理逻辑。
|
||||
|
||||
**当前日期**: 2026-06-02
|
||||
|
||||
---
|
||||
|
||||
## 一、测试场景总览
|
||||
|
||||
| 场景 | 会员 | 会员卡状态 | 预约课程 | 预期结果 |
|
||||
|-----|------|----------|---------|---------|
|
||||
| 1 | 用户A | 无会员卡 | 次数卡团课 | 提示无可用会员卡 |
|
||||
| 2 | 用户B | 时长卡已过期 | 次数卡团课 | 提示会员卡已过期 |
|
||||
| 3 | 会员C | 时长卡有效 | 次数卡团课 | 预约成功 |
|
||||
| 4 | 会员D | 次数卡次数=0 | 次数卡团课 | 提示剩余次数不足 |
|
||||
| 5 | 会员E | 次数卡次数=5 | 次数卡团课 | 预约成功 |
|
||||
| 6 | 会员F | 储值卡余额=30元 | 储值卡团课(需50元) | 提示余额不足 |
|
||||
| 7 | 会员G | 储值卡余额=200元 | 储值卡团课(需50元) | 预约成功 |
|
||||
|
||||
---
|
||||
|
||||
## 二、测试会员数据
|
||||
|
||||
### 2.1 会员列表
|
||||
|
||||
| 会员编号 | 昵称 | 手机号 | 性别 | 创建时间 |
|
||||
|---------|------|--------|------|---------|
|
||||
| MEM_TEST_A | 用户A_无卡新用户 | 13800001001 | 男 | 2026-06-02 10:00:00 |
|
||||
| MEM_TEST_B | 用户B_过期时长卡 | 13800001002 | 男 | 2026-05-01 10:00:00 |
|
||||
| MEM_TEST_C | 会员C_有效时长卡 | 13800001003 | 女 | 2026-05-01 10:00:00 |
|
||||
| MEM_TEST_D | 会员D_次数用尽 | 13800001004 | 男 | 2026-05-01 10:00:00 |
|
||||
| MEM_TEST_E | 会员E_次数充足 | 13800001005 | 女 | 2026-05-01 10:00:00 |
|
||||
| MEM_TEST_F | 会员F_储值卡余额不足 | 13800001006 | 男 | 2026-05-01 10:00:00 |
|
||||
| MEM_TEST_G | 会员G_储值卡余额充足 | 13800001007 | 女 | 2026-05-01 10:00:00 |
|
||||
|
||||
### 2.2 会员场景说明
|
||||
|
||||
#### 场景1: 用户A - 无会员卡新用户
|
||||
- **会员编号**: MEM_TEST_A
|
||||
- **状态**: 2026-06-02 刚注册,尚未购买任何会员卡
|
||||
- **测试目标**: 验证无会员卡用户申请团课预约时的错误提示
|
||||
|
||||
#### 场景2: 用户B - 时长卡已过期
|
||||
- **会员编号**: MEM_TEST_B
|
||||
- **状态**: 持有30天时长卡,于 2026-05-31 23:59:59 到期
|
||||
- **测试目标**: 验证会员卡过期后的预约行为
|
||||
|
||||
#### 场景3: 会员C - 时长卡有效
|
||||
- **会员编号**: MEM_TEST_C
|
||||
- **状态**: 持有30天时长卡,到期时间 2026-07-02
|
||||
- **测试目标**: 验证有效期内的时长卡可以正常预约次数卡团课
|
||||
|
||||
#### 场景4: 会员D - 次数卡耗尽
|
||||
- **会员编号**: MEM_TEST_D
|
||||
- **状态**: 持有10次卡,剩余次数 = 0
|
||||
- **测试目标**: 验证次数耗尽后无法预约团课
|
||||
|
||||
#### 场景5: 会员E - 次数卡充足
|
||||
- **会员编号**: MEM_TEST_E
|
||||
- **状态**: 持有10次卡,剩余次数 = 5
|
||||
- **测试目标**: 验证次数充足时正常预约
|
||||
|
||||
#### 场景6: 会员F - 储值卡余额不足
|
||||
- **会员编号**: MEM_TEST_F
|
||||
- **状态**: 持有储值卡,余额 = 30.00 元
|
||||
- **测试目标**: 验证预约储值卡团课(需50元)时提示余额不足
|
||||
|
||||
#### 场景7: 会员G - 储值卡余额充足
|
||||
- **会员编号**: MEM_TEST_G
|
||||
- **状态**: 持有储值卡,余额 = 200.00 元
|
||||
- **测试目标**: 验证余额充足时正常预约储值卡团课
|
||||
|
||||
---
|
||||
|
||||
## 三、团课课程数据
|
||||
|
||||
### 3.1 团课列表
|
||||
|
||||
| 课程名称 | 教练ID | 课程类型 | 开始时间 | 结束时间 | 最大人数 | 当前人数 | 状态 | 点卡额度 | 储值额度 |
|
||||
|---------|-------|---------|---------|---------|---------|---------|------|---------|---------|
|
||||
| 燃脂搏击_次数卡课程 | 102 | 2 | 2026-06-10 19:30:00 | 2026-06-10 20:30:00 | 20 | 0 | 正常 | 1 | 0.00 |
|
||||
| 高端普拉提_储值卡课程 | 103 | 1 | 2026-06-11 19:00:00 | 2026-06-11 20:00:00 | 15 | 0 | 正常 | 0 | 50.00 |
|
||||
|
||||
### 3.2 课程说明
|
||||
|
||||
**燃脂搏击_次数卡课程**
|
||||
- **收费类型**: 次数卡
|
||||
- **消耗点数**: 1次
|
||||
- **适用会员**: 时长卡、次数卡用户
|
||||
- **课程描述**: 高强度间歇训练,配合音乐快速燃脂
|
||||
|
||||
**高端普拉提_储值卡课程**
|
||||
- **收费类型**: 储值卡
|
||||
- **消耗金额**: 50.00 元
|
||||
- **适用会员**: 储值卡用户
|
||||
- **课程描述**: 精准训练核心肌群
|
||||
|
||||
---
|
||||
|
||||
## 四、会员卡类型数据
|
||||
|
||||
| 卡名称 | 卡类型 | 价格 | 有效天数 | 总次数 | 面额 | 状态 |
|
||||
|-------|-------|------|---------|-------|------|------|
|
||||
| 30天时长卡 | TIME_CARD | 299.00 | 30 | - | - | 上架 |
|
||||
| 10次卡 | COUNT_CARD | 499.00 | - | 10 | - | 上架 |
|
||||
| 储值卡500 | STORED_VALUE_CARD | 500.00 | - | - | 500.00 | 上架 |
|
||||
|
||||
---
|
||||
|
||||
## 五、会员卡记录数据
|
||||
|
||||
### 5.1 记录列表
|
||||
|
||||
| 会员编号 | 卡名称 | 状态 | 剩余次数 | 剩余金额 | 过期时间 | 购买时间 |
|
||||
|---------|-------|------|---------|---------|---------|---------|
|
||||
| MEM_TEST_B | 30天时长卡 | EXPIRED | 0 | 0.00 | 2026-05-31 | 2026-05-01 |
|
||||
| MEM_TEST_C | 30天时长卡 | ACTIVE | 0 | 0.00 | 2026-07-02 | 2026-06-02 |
|
||||
| MEM_TEST_D | 10次卡 | ACTIVE | 0 | 0.00 | 2026-12-31 | 2026-05-01 |
|
||||
| MEM_TEST_E | 10次卡 | ACTIVE | 5 | 0.00 | 2026-12-31 | 2026-05-01 |
|
||||
| MEM_TEST_F | 储值卡500 | ACTIVE | 0 | 30.00 | 2027-06-02 | 2026-05-01 |
|
||||
| MEM_TEST_G | 储值卡500 | ACTIVE | 0 | 200.00 | 2027-06-02 | 2026-05-01 |
|
||||
|
||||
### 5.2 详细说明
|
||||
|
||||
**用户B - 时长卡已过期**
|
||||
```
|
||||
会员ID: MEM_TEST_B
|
||||
卡名称: 30天时长卡
|
||||
状态: EXPIRED (已过期)
|
||||
有效期: 2026-05-01 至 2026-05-31
|
||||
剩余次数: 0
|
||||
剩余金额: 0.00
|
||||
```
|
||||
|
||||
**会员C - 时长卡有效**
|
||||
```
|
||||
会员ID: MEM_TEST_C
|
||||
卡名称: 30天时长卡
|
||||
状态: ACTIVE (有效)
|
||||
有效期: 2026-06-02 至 2026-07-02
|
||||
剩余次数: 0
|
||||
剩余金额: 0.00
|
||||
```
|
||||
|
||||
**会员D - 次数卡耗尽**
|
||||
```
|
||||
会员ID: MEM_TEST_D
|
||||
卡名称: 10次卡
|
||||
状态: ACTIVE (有效)
|
||||
有效期: 2026-05-01 至 2026-12-31
|
||||
剩余次数: 0 (已用尽)
|
||||
剩余金额: 0.00
|
||||
```
|
||||
|
||||
**会员E - 次数卡充足**
|
||||
```
|
||||
会员ID: MEM_TEST_E
|
||||
卡名称: 10次卡
|
||||
状态: ACTIVE (有效)
|
||||
有效期: 2026-05-01 至 2026-12-31
|
||||
剩余次数: 5
|
||||
剩余金额: 0.00
|
||||
```
|
||||
|
||||
**会员F - 储值卡余额不足**
|
||||
```
|
||||
会员ID: MEM_TEST_F
|
||||
卡名称: 储值卡500
|
||||
状态: ACTIVE (有效)
|
||||
有效期: 2026-05-01 至 2027-06-02
|
||||
剩余次数: 0
|
||||
剩余金额: 30.00 (不足50.00)
|
||||
```
|
||||
|
||||
**会员G - 储值卡余额充足**
|
||||
```
|
||||
会员ID: MEM_TEST_G
|
||||
卡名称: 储值卡500
|
||||
状态: ACTIVE (有效)
|
||||
有效期: 2026-05-01 至 2027-06-02
|
||||
剩余次数: 0
|
||||
剩余金额: 200.00 (充足)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 六、SQL数据插入顺序
|
||||
|
||||
```sql
|
||||
-- 1. 先插入会员用户 (A-G)
|
||||
INSERT INTO member_user (member_no, nickname, phone, gender, is_deleted, created_at, updated_at) VALUES
|
||||
('MEM_TEST_A', '用户A_无卡新用户', '13800001001', 1, false, '2026-06-02 10:00:00', '2026-06-02 10:00:00'),
|
||||
('MEM_TEST_B', '用户B_过期时长卡', '13800001002', 1, false, '2026-05-01 10:00:00', '2026-05-01 10:00:00'),
|
||||
('MEM_TEST_C', '会员C_有效时长卡', '13800001003', 2, false, '2026-05-01 10:00:00', '2026-05-01 10:00:00'),
|
||||
('MEM_TEST_D', '会员D_次数用尽', '13800001004', 1, false, '2026-05-01 10:00:00', '2026-05-01 10:00:00'),
|
||||
('MEM_TEST_E', '会员E_次数充足', '13800001005', 2, false, '2026-05-01 10:00:00', '2026-05-01 10:00:00'),
|
||||
('MEM_TEST_F', '会员F_储值卡余额不足', '13800001006', 1, false, '2026-05-01 10:00:00', '2026-05-01 10:00:00'),
|
||||
('MEM_TEST_G', '会员G_储值卡余额充足', '13800001007', 2, false, '2026-05-01 10:00:00', '2026-05-01 10:00:00');
|
||||
|
||||
-- 2. 插入团课课程
|
||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, description, point_card_amount, stored_value_amount, create_by, created_at, updated_at) VALUES
|
||||
('燃脂搏击_次数卡课程', 102, 2, '2026-06-10 19:30:00', '2026-06-10 20:30:00', 20, 0, '0', '综合训练区', '高强度间歇训练,配合音乐快速燃脂,消耗1次', 1, 0.00, 'admin', '2026-06-01 10:00:00', '2026-06-01 10:00:00');
|
||||
|
||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, description, point_card_amount, stored_value_amount, create_by, created_at, updated_at) VALUES
|
||||
('高端普拉提_储值卡课程', 103, 1, '2026-06-11 19:00:00', '2026-06-11 20:00:00', 15, 0, '0', '普拉提教室', '精准训练核心肌群,消耗储值50元', 0, 50.00, 'admin', '2026-06-01 10:00:00', '2026-06-01 10:00:00');
|
||||
|
||||
-- 3. 插入会员卡类型
|
||||
INSERT INTO member_card (member_card_name, member_card_type, member_card_price, member_card_validity_days, member_card_total_times, member_card_amount, member_card_status, extra_config, created_at, updated_at) VALUES
|
||||
('30天时长卡', 'TIME_CARD', 299.00, 30, NULL, NULL, 1, '{}', '2026-01-01 00:00:00', '2026-01-01 00:00:00'),
|
||||
('10次卡', 'COUNT_CARD', 499.00, NULL, 10, NULL, 1, '{}', '2026-01-01 00:00:00', '2026-01-01 00:00:00'),
|
||||
('储值卡500', 'STORED_VALUE_CARD', 500.00, NULL, NULL, 500.00, 1, '{}', '2026-01-01 00:00:00', '2026-01-01 00:00:00');
|
||||
|
||||
-- 4. 插入会员卡记录
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_B'), (SELECT member_card_id FROM member_card WHERE member_card_name = '30天时长卡'), 'EXPIRED', 0, 0.00, '2026-05-31 23:59:59', '2026-05-01 10:00:00', 0, '{}', '2026-05-01 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_C'), (SELECT member_card_id FROM member_card WHERE member_card_name = '30天时长卡'), 'ACTIVE', 0, 0.00, '2026-07-02 23:59:59', '2026-06-02 10:00:00', 0, '{}', '2026-06-02 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_D'), (SELECT member_card_id FROM member_card WHERE member_card_name = '10次卡'), 'ACTIVE', 0, 0.00, '2026-12-31 23:59:59', '2026-05-01 10:00:00', 0, '{}', '2026-05-01 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_E'), (SELECT member_card_id FROM member_card WHERE member_card_name = '10次卡'), 'ACTIVE', 5, 0.00, '2026-12-31 23:59:59', '2026-05-01 10:00:00', 0, '{}', '2026-05-01 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_F'), (SELECT member_card_id FROM member_card WHERE member_card_name = '储值卡500'), 'ACTIVE', 0, 30.00, '2027-06-02 23:59:59', '2026-05-01 10:00:00', 0, '{}', '2026-05-01 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_G'), (SELECT member_card_id FROM member_card WHERE member_card_name = '储值卡500'), 'ACTIVE', 0, 200.00, '2027-06-02 23:59:59', '2026-05-01 10:00:00', 0, '{}', '2026-05-01 10:00:00', '2026-06-02 10:00:00');
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 七、预期测试结果
|
||||
|
||||
### 7.1 成功场景
|
||||
|
||||
| 场景 | 会员 | 操作 | 预期结果 |
|
||||
|-----|------|-----|---------|
|
||||
| 3 | 会员C | 预约次数卡团课 | 预约成功,消耗时长卡1次 |
|
||||
| 5 | 会员E | 预约次数卡团课 | 预约成功,次数减1 (5→4) |
|
||||
| 7 | 会员G | 预约储值卡团课 | 预约成功,余额减50 (200→150) |
|
||||
|
||||
### 7.2 失败场景
|
||||
|
||||
| 场景 | 会员 | 操作 | 预期错误码 | 预期提示信息 |
|
||||
|-----|------|-----|----------|------------|
|
||||
| 1 | 用户A | 预约次数卡团课 | NO_CARD | 无可用会员卡 |
|
||||
| 2 | 用户B | 预约次数卡团课 | CARD_EXPIRED | 会员卡已过期 |
|
||||
| 4 | 会员D | 预约次数卡团课 | INSUFFICIENT_TIMES | 剩余次数不足 |
|
||||
| 6 | 会员F | 预约储值卡团课 | INSUFFICIENT_BALANCE | 余额不足,当前余额30.00元,需50.00元 |
|
||||
|
||||
---
|
||||
|
||||
## 八、数据清理
|
||||
|
||||
测试完成后,可通过以下 SQL 清理测试数据:
|
||||
|
||||
```sql
|
||||
-- 删除测试会员(会级联删除相关会员卡记录)
|
||||
DELETE FROM member_user WHERE member_no LIKE 'MEM_TEST_%';
|
||||
|
||||
-- 删除测试团课
|
||||
DELETE FROM group_course WHERE course_name LIKE '%_次数卡课程' OR course_name LIKE '%_储值卡课程';
|
||||
|
||||
-- 删除测试会员卡类型
|
||||
DELETE FROM member_card WHERE member_card_name IN ('30天时长卡', '10次卡', '储值卡500');
|
||||
```
|
||||
@@ -0,0 +1,204 @@
|
||||
# V11 团课预约取消测试数据文档
|
||||
|
||||
## 文档说明
|
||||
|
||||
本文档描述了用于测试团课预约取消功能的测试数据,包含三种会员卡类型的取消预约场景。
|
||||
|
||||
## 测试场景概览
|
||||
|
||||
| 序号 | 场景描述 | 用户 | 会员卡类型 |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| 1 | 使用时长卡预约后取消 | 张三 | 时长卡(30天) |
|
||||
| 2 | 使用次数卡预约后取消 | 李四 | 次数卡(10次) |
|
||||
| 3 | 使用储值卡预约后取消 | 王五 | 储值卡(500元) |
|
||||
|
||||
## 测试用户数据
|
||||
|
||||
### 1. 张三(时长卡用户)
|
||||
|
||||
| 字段 | 值 |
|
||||
| :--- | :--- |
|
||||
| 会员编号 | `MEM_TEST_ZHANG` |
|
||||
| 昵称 | 张三_时长卡用户 |
|
||||
| 手机号 | 13800002001 |
|
||||
| 性别 | 男(1) |
|
||||
|
||||
#### 会员卡信息
|
||||
|
||||
| 字段 | 值 |
|
||||
| :--- | :--- |
|
||||
| 卡类型 | 时长卡(TIME_CARD) |
|
||||
| 卡名称 | 30天时长卡 |
|
||||
| 状态 | ACTIVE(有效) |
|
||||
| 到期时间 | 2026-07-02 23:59:59 |
|
||||
| 购买时间 | 2026-06-02 10:00:00 |
|
||||
|
||||
---
|
||||
|
||||
### 2. 李四(次数卡用户)
|
||||
|
||||
| 字段 | 值 |
|
||||
| :--- | :--- |
|
||||
| 会员编号 | `MEM_TEST_LI` |
|
||||
| 昵称 | 李四_次数卡用户 |
|
||||
| 手机号 | 13800002002 |
|
||||
| 性别 | 男(1) |
|
||||
|
||||
#### 会员卡信息
|
||||
|
||||
| 字段 | 值 |
|
||||
| :--- | :--- |
|
||||
| 卡类型 | 次数卡(COUNT_CARD) |
|
||||
| 卡名称 | 10次卡 |
|
||||
| 状态 | ACTIVE(有效) |
|
||||
| 剩余次数 | 5次 |
|
||||
| 到期时间 | 2026-12-31 23:59:59 |
|
||||
|
||||
---
|
||||
|
||||
### 3. 王五(储值卡用户)
|
||||
|
||||
| 字段 | 值 |
|
||||
| :--- | :--- |
|
||||
| 会员编号 | `MEM_TEST_WANG` |
|
||||
| 昵称 | 王五_储值卡用户 |
|
||||
| 手机号 | 13800002003 |
|
||||
| 性别 | 女(2) |
|
||||
|
||||
#### 会员卡信息
|
||||
|
||||
| 字段 | 值 |
|
||||
| :--- | :--- |
|
||||
| 卡类型 | 储值卡(STORED_VALUE_CARD) |
|
||||
| 卡名称 | 储值卡500 |
|
||||
| 状态 | ACTIVE(有效) |
|
||||
| 剩余金额 | 200.00元 |
|
||||
| 到期时间 | 2027-06-02 23:59:59 |
|
||||
|
||||
---
|
||||
|
||||
## 测试课程数据
|
||||
|
||||
### 晚间瑜伽_取消测试
|
||||
|
||||
| 字段 | 值 |
|
||||
| :--- | :--- |
|
||||
| 课程名称 | 晚间瑜伽_取消测试 |
|
||||
| 教练ID | 101 |
|
||||
| 课程类型 | 1 |
|
||||
| 开始时间 | 2026-06-15 19:00:00 |
|
||||
| 结束时间 | 2026-06-15 20:00:00 |
|
||||
| 上课地点 | 瑜伽教室 |
|
||||
| 最大人数 | 20人 |
|
||||
| 当前人数 | 3人(三位测试用户) |
|
||||
| 状态 | 0(正常) |
|
||||
| 次数消耗 | 1次 |
|
||||
| 储值消耗 | 30.00元 |
|
||||
|
||||
---
|
||||
|
||||
## 预约记录数据
|
||||
|
||||
### 预约状态说明
|
||||
|
||||
| 状态码 | 含义 |
|
||||
| :--- | :--- |
|
||||
| `0` | 已预约(等待取消) |
|
||||
| `1` | 已取消 |
|
||||
| `2` | 已出席 |
|
||||
| `3` | 缺席 |
|
||||
|
||||
### 预约记录详情
|
||||
|
||||
| 用户 | 预约时间 | 状态 | 课程名称 |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| 张三 | 2026-06-02 11:00:00 | 0(已预约) | 晚间瑜伽_取消测试 |
|
||||
| 李四 | 2026-06-02 11:30:00 | 0(已预约) | 晚间瑜伽_取消测试 |
|
||||
| 王五 | 2026-06-02 12:00:00 | 0(已预约) | 晚间瑜伽_取消测试 |
|
||||
|
||||
---
|
||||
|
||||
## 测试用例设计
|
||||
|
||||
### 场景1:时长卡用户取消预约
|
||||
|
||||
**前置条件:**
|
||||
- 张三持有有效时长卡
|
||||
- 张三已成功预约课程
|
||||
- 当前时间 < 课程开始时间
|
||||
|
||||
**测试步骤:**
|
||||
1. 调用取消预约接口,传入张三的预约记录ID
|
||||
2. 验证预约状态变为 `1`(已取消)
|
||||
3. 验证课程当前人数减1
|
||||
4. 验证时长卡状态保持不变(时长卡取消预约不影响卡状态)
|
||||
|
||||
**预期结果:**
|
||||
- 预约记录状态更新为已取消
|
||||
- 课程剩余名额增加1
|
||||
- 时长卡有效期不受影响
|
||||
|
||||
---
|
||||
|
||||
### 场景2:次数卡用户取消预约
|
||||
|
||||
**前置条件:**
|
||||
- 李四持有次数卡,剩余5次
|
||||
- 李四已成功预约课程(已扣除1次)
|
||||
- 当前时间 < 课程开始时间
|
||||
|
||||
**测试步骤:**
|
||||
1. 调用取消预约接口,传入李四的预约记录ID
|
||||
2. 验证预约状态变为 `1`(已取消)
|
||||
3. 验证课程当前人数减1
|
||||
4. 验证次数卡剩余次数恢复为5次(返还1次)
|
||||
|
||||
**预期结果:**
|
||||
- 预约记录状态更新为已取消
|
||||
- 课程剩余名额增加1
|
||||
- 次数卡返还1次,剩余次数恢复为5次
|
||||
|
||||
---
|
||||
|
||||
### 场景3:储值卡用户取消预约
|
||||
|
||||
**前置条件:**
|
||||
- 王五持有储值卡,余额200元
|
||||
- 王五已成功预约课程(已扣除30元)
|
||||
- 当前时间 < 课程开始时间
|
||||
|
||||
**测试步骤:**
|
||||
1. 调用取消预约接口,传入王五的预约记录ID
|
||||
2. 验证预约状态变为 `1`(已取消)
|
||||
3. 验证课程当前人数减1
|
||||
4. 验证储值卡余额恢复为200元(返还30元)
|
||||
|
||||
**预期结果:**
|
||||
- 预约记录状态更新为已取消
|
||||
- 课程剩余名额增加1
|
||||
- 储值卡返还30元,余额恢复为200元
|
||||
|
||||
---
|
||||
|
||||
## 数据文件位置
|
||||
|
||||
```
|
||||
manage-db/src/main/resources/db/migration/V11__Insert_Cancel_Booking_Test_Data.sql
|
||||
```
|
||||
|
||||
## 数据依赖
|
||||
|
||||
| 依赖文件 | 说明 |
|
||||
| :--- | :--- |
|
||||
| `V6__Create_GroupCourse_table.sql` | 团课相关表结构 |
|
||||
| `V8__Create_Member_And_MemberCard.sql` | 会员和会员卡表结构 |
|
||||
| `V9__Add_GroupCourse_Booking_Snapshot_Fields.sql` | 预约快照字段 |
|
||||
|
||||
---
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. 测试数据中使用的日期均为未来日期,确保测试时课程尚未开始
|
||||
2. 会员卡状态均为 ACTIVE,确保可以正常预约
|
||||
3. 取消预约功能应在课程开始前24小时内允许操作(具体时间限制由业务逻辑决定)
|
||||
4. 取消预约后应记录操作日志和交易流水
|
||||
@@ -0,0 +1,400 @@
|
||||
# 团课预约场景测试数据文档
|
||||
|
||||
## 概述
|
||||
|
||||
本文档描述了团课预约功能的测试数据,覆盖了各种预约场景,用于验证系统在不同业务条件下的正确性和健壮性。
|
||||
|
||||
---
|
||||
|
||||
## 一、测试数据概览
|
||||
|
||||
| 数据类别 | 数量 | 说明 |
|
||||
|---------|------|------|
|
||||
| 测试会员 | 5个 | 覆盖不同会员卡状态 |
|
||||
| 会员卡类型 | 8种 | 次卡/时长卡/储值卡 |
|
||||
| 会员卡记录 | 5条 | 会员持有的实际卡 |
|
||||
| 团课预约记录 | 4条 | 不同状态的预约 |
|
||||
| 交易流水 | 27条 | 完整的消费记录 |
|
||||
|
||||
---
|
||||
|
||||
## 二、会员测试数据
|
||||
|
||||
### 2.1 会员列表
|
||||
|
||||
| 会员ID | 会员编号 | 昵称 | 手机号 | 性别 | 会员卡状态 |
|
||||
|--------|---------|------|--------|------|-----------|
|
||||
| 1001 | MEM202606001 | 新用户小张 | 13800138001 | 男 | 无会员卡 |
|
||||
| 1002 | MEM202606002 | 额度耗尽用户 | 13800138002 | 女 | 次卡已用完 |
|
||||
| 1003 | MEM202606003 | 额度充足用户 | 13800138003 | 男 | 次卡剩余8次 |
|
||||
| 1004 | MEM202606004 | 过期卡用户 | 13800138004 | 女 | 月卡已过期 |
|
||||
| 1005 | MEM202606005 | 多卡用户小李 | 13800138005 | 男 | 次卡+储值卡 |
|
||||
|
||||
### 2.2 会员详情
|
||||
|
||||
**会员1001 - 新用户小张**
|
||||
- 状态:新注册用户,尚未购买任何会员卡
|
||||
- 用途:测试无会员卡情况下的预约行为
|
||||
|
||||
**会员1002 - 额度耗尽用户**
|
||||
- 状态:持有10次团课卡,已全部用完
|
||||
- 用途:测试会员卡额度耗尽时的预约行为
|
||||
|
||||
**会员1003 - 额度充足用户**
|
||||
- 状态:持有20次团课卡,剩余8次
|
||||
- 用途:测试正常预约流程
|
||||
|
||||
**会员1004 - 过期卡用户**
|
||||
- 状态:持有月卡,已于2026-05-31过期
|
||||
- 用途:测试过期会员卡的预约行为
|
||||
|
||||
**会员1005 - 多卡用户小李**
|
||||
- 状态:持有50次团课卡(剩余45次) + 500元储值卡(剩余350元)
|
||||
- 用途:测试多会员卡用户选择支付方式的场景
|
||||
|
||||
---
|
||||
|
||||
## 三、会员卡类型数据
|
||||
|
||||
### 3.1 次卡类型
|
||||
|
||||
| 卡类型ID | 卡名称 | 类型 | 价格 | 有效天数 | 总次数 | 状态 |
|
||||
|---------|-------|------|------|---------|-------|------|
|
||||
| 101 | 10次团课卡 | COUNT_CARD | 299.00 | 90 | 10 | 上架 |
|
||||
| 102 | 20次团课卡 | COUNT_CARD | 499.00 | 180 | 20 | 上架 |
|
||||
| 103 | 50次团课卡 | COUNT_CARD | 999.00 | 365 | 50 | 上架 |
|
||||
|
||||
### 3.2 时长卡类型
|
||||
|
||||
| 卡类型ID | 卡名称 | 类型 | 价格 | 有效天数 | 状态 |
|
||||
|---------|-------|------|------|---------|------|
|
||||
| 201 | 月卡 | TIME_CARD | 399.00 | 30 | 上架 |
|
||||
| 202 | 季卡 | TIME_CARD | 899.00 | 90 | 上架 |
|
||||
| 203 | 年卡 | TIME_CARD | 2999.00 | 365 | 上架 |
|
||||
|
||||
### 3.3 储值卡类型
|
||||
|
||||
| 卡类型ID | 卡名称 | 类型 | 价格 | 面额 | 有效天数 | 状态 |
|
||||
|---------|-------|------|------|------|---------|------|
|
||||
| 301 | 500元储值卡 | STORED_VALUE_CARD | 500.00 | 500.00 | 365 | 上架 |
|
||||
| 302 | 1000元储值卡 | STORED_VALUE_CARD | 1000.00 | 1000.00 | 365 | 上架 |
|
||||
|
||||
---
|
||||
|
||||
## 四、会员卡记录数据(会员持有的卡)
|
||||
|
||||
| 记录ID | 会员ID | 卡类型ID | 状态 | 剩余次数 | 剩余金额 | 到期时间 | 购买时间 |
|
||||
|-------|--------|---------|------|---------|---------|---------|---------|
|
||||
| 2001 | 1002 | 101 | USED_UP | 0 | 0.00 | 2026-09-01 | 2026-06-01 |
|
||||
| 2002 | 1003 | 102 | ACTIVE | 8 | 0.00 | 2026-12-01 | 2026-06-01 |
|
||||
| 2003 | 1004 | 201 | EXPIRED | 0 | 0.00 | 2026-05-31 | 2026-05-01 |
|
||||
| 2004 | 1005 | 103 | ACTIVE | 45 | 0.00 | 2027-06-01 | 2026-06-01 |
|
||||
| 2005 | 1005 | 301 | ACTIVE | 0 | 350.00 | 2027-06-01 | 2026-05-15 |
|
||||
|
||||
---
|
||||
|
||||
## 五、团课预约记录数据
|
||||
|
||||
| 预约ID | 课程ID | 会员ID | 会员卡记录ID | 预约时间 | 状态 | 课程名称 |
|
||||
|-------|-------|--------|-------------|---------|------|---------|
|
||||
| 3001 | 1 | 1003 | 2002 | 2026-06-01 15:30 | 已预约(0) | 极速燃脂单车 |
|
||||
| 3002 | 2 | 1003 | 2002 | 2026-06-01 10:00 | 已取消(1) | 清晨流瑜伽 |
|
||||
| 3003 | 6 | 1003 | 2002 | 2026-05-28 19:00 | 已出席(2) | 蜜桃臀塑造 |
|
||||
| 3004 | 7 | 1002 | 2001 | 2026-05-30 10:00 | 缺席(3) | 午间冥想放松 |
|
||||
|
||||
### 状态说明
|
||||
|
||||
| 状态码 | 状态名称 | 说明 |
|
||||
|-------|---------|------|
|
||||
| 0 | 已预约 | 用户已成功预约,等待上课 |
|
||||
| 1 | 已取消 | 用户主动取消预约 |
|
||||
| 2 | 已出席 | 用户已按时参加课程 |
|
||||
| 3 | 缺席 | 用户预约后未出席 |
|
||||
|
||||
---
|
||||
|
||||
## 六、测试场景详解
|
||||
|
||||
### 场景1:新注册用户无会员卡预约
|
||||
|
||||
**测试目标**:验证系统对无会员卡用户的预约拦截
|
||||
|
||||
**测试数据**:
|
||||
- 用户ID:1001(新用户小张)
|
||||
- 目标课程:任意课程
|
||||
|
||||
**预期结果**:
|
||||
- 返回错误信息:"未绑定会员卡,请先购买会员卡"
|
||||
- HTTP状态码:400 Bad Request
|
||||
|
||||
---
|
||||
|
||||
### 场景2:会员卡额度耗尽预约
|
||||
|
||||
**测试目标**:验证系统对额度耗尽会员卡的预约拦截
|
||||
|
||||
**测试数据**:
|
||||
- 用户ID:1002(额度耗尽用户)
|
||||
- 会员卡记录ID:2001
|
||||
- 剩余次数:0
|
||||
|
||||
**预期结果**:
|
||||
- 返回错误信息:"会员卡余额不足"
|
||||
- HTTP状态码:400 Bad Request
|
||||
|
||||
---
|
||||
|
||||
### 场景3:会员卡额度充足预约
|
||||
|
||||
**测试目标**:验证正常预约流程
|
||||
|
||||
**测试数据**:
|
||||
- 用户ID:1003(额度充足用户)
|
||||
- 会员卡记录ID:2002
|
||||
- 剩余次数:8
|
||||
- 目标课程:课程ID=1(极速燃脂单车)
|
||||
|
||||
**预期结果**:
|
||||
- 预约成功
|
||||
- 会员卡剩余次数减1(变为7次)
|
||||
- 生成预约记录
|
||||
- HTTP状态码:200 OK
|
||||
|
||||
---
|
||||
|
||||
### 场景4:会员卡已过期预约
|
||||
|
||||
**测试目标**:验证系统对过期会员卡的预约拦截
|
||||
|
||||
**测试数据**:
|
||||
- 用户ID:1004(过期卡用户)
|
||||
- 会员卡记录ID:2003
|
||||
- 状态:EXPIRED
|
||||
- 到期时间:2026-05-31
|
||||
|
||||
**预期结果**:
|
||||
- 返回错误信息:"会员卡已过期"
|
||||
- HTTP状态码:400 Bad Request
|
||||
|
||||
---
|
||||
|
||||
### 场景5:课程已满员预约---------------
|
||||
|
||||
**测试目标**:验证系统对满员课程的预约拦截
|
||||
|
||||
**测试数据**:
|
||||
- 课程ID:3(燃脂搏击)
|
||||
- 当前人数:20/20
|
||||
|
||||
**预期结果**:
|
||||
- 返回错误信息:"课程已满员"
|
||||
- HTTP状态码:400 Bad Request
|
||||
|
||||
---
|
||||
|
||||
### 场景6:课程已取消预约
|
||||
|
||||
**测试目标**:验证系统对已取消课程的预约拦截
|
||||
|
||||
**测试数据**:
|
||||
- 课程ID:5(周末冥想修复)
|
||||
- 状态:1(已取消)
|
||||
|
||||
**预期结果**:
|
||||
- 返回错误信息:"课程已取消"
|
||||
- HTTP状态码:400 Bad Request
|
||||
|
||||
---
|
||||
|
||||
### 场景7:课程已结束预约
|
||||
|
||||
**测试目标**:验证系统对已结束课程的预约拦截
|
||||
|
||||
**测试数据**:
|
||||
- 课程ID:6(蜜桃臀塑造)或 7(午间冥想放松)
|
||||
- 状态:2(已结束)
|
||||
|
||||
**预期结果**:
|
||||
- 返回错误信息:"课程已结束"
|
||||
- HTTP状态码:400 Bad Request
|
||||
|
||||
---
|
||||
|
||||
### 场景8:超出预约时间预约
|
||||
|
||||
**测试目标**:验证系统对预约时间窗口的控制
|
||||
|
||||
**测试数据**:
|
||||
- 课程ID:4(哈他瑜伽)
|
||||
- 开始时间:2026-06-01 15:20:00
|
||||
- 测试时间:课程开始前30分钟内
|
||||
|
||||
**预期结果**:
|
||||
- 返回错误信息:"已过预约时间"
|
||||
- HTTP状态码:400 Bad Request
|
||||
|
||||
---
|
||||
|
||||
### 场景9:重复预约同一课程
|
||||
|
||||
**测试目标**:验证系统对重复预约的拦截
|
||||
|
||||
**测试数据**:
|
||||
- 用户ID:1003(额度充足用户)
|
||||
- 课程ID:1(极速燃脂单车)
|
||||
- 已有预约记录:booking_id=3001
|
||||
|
||||
**预期结果**:
|
||||
- 返回错误信息:"已预约该课程"
|
||||
- HTTP状态码:400 Bad Request
|
||||
|
||||
---
|
||||
|
||||
### 场景10:多会员卡用户选择支付方式
|
||||
|
||||
**测试目标**:验证多卡用户的支付方式选择功能
|
||||
|
||||
**测试数据**:
|
||||
- 用户ID:1005(多卡用户小李)
|
||||
- 可用卡1:次卡(记录ID=2004,剩余45次)
|
||||
- 可用卡2:储值卡(记录ID=2005,剩余350元)
|
||||
|
||||
**预期结果**:
|
||||
- 系统列出用户所有可用会员卡
|
||||
- 用户可选择使用次卡或储值卡支付
|
||||
- 根据选择的卡类型扣减相应额度
|
||||
|
||||
---
|
||||
|
||||
## 七、交易流水说明
|
||||
|
||||
### 7.1 会员1002(额度耗尽用户)消费记录
|
||||
|
||||
| 操作顺序 | 操作类型 | 变动次数 | 剩余次数 | 备注 |
|
||||
|---------|---------|---------|---------|------|
|
||||
| 1 | PURCHASE | +10 | 10 | 购买10次团课卡 |
|
||||
| 2-11 | DEDUCT | -1×10 | 0 | 10次课程消费 |
|
||||
|
||||
### 7.2 会员1003(额度充足用户)消费记录
|
||||
|
||||
| 操作顺序 | 操作类型 | 变动次数 | 剩余次数 | 备注 |
|
||||
|---------|---------|---------|---------|------|
|
||||
| 1 | PURCHASE | +20 | 20 | 购买20次团课卡 |
|
||||
| 2-12 | DEDUCT | -12 | 8 | 12次课程消费 |
|
||||
|
||||
### 7.3 会员1005(多卡用户)消费记录
|
||||
|
||||
| 会员卡记录ID | 操作类型 | 变动次数 | 变动金额 | 备注 |
|
||||
|-------------|---------|---------|---------|------|
|
||||
| 2004 | PURCHASE | +50 | 0 | 购买50次团课卡 |
|
||||
| 2004 | DEDUCT | -5 | 0 | 预约5节课程 |
|
||||
| 2005 | PURCHASE | 0 | +500 | 购买500元储值卡 |
|
||||
| 2005 | DEDUCT | 0 | -150 | 私教课消费150元 |
|
||||
|
||||
---
|
||||
|
||||
## 八、API测试示例
|
||||
|
||||
### 8.1 预约接口
|
||||
|
||||
```http
|
||||
POST /api/group-course/bookings
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"courseId": 1,
|
||||
"memberCardRecordId": 2002
|
||||
}
|
||||
```
|
||||
|
||||
### 8.2 取消预约接口
|
||||
|
||||
```http
|
||||
PUT /api/group-course/bookings/{bookingId}/cancel
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"reason": "临时有事无法参加"
|
||||
}
|
||||
```
|
||||
|
||||
### 8.3 查询用户预约列表
|
||||
|
||||
```http
|
||||
GET /api/group-course/bookings?memberId=1003
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 九、测试数据对应关系图
|
||||
|
||||
```
|
||||
会员表 (member_user)
|
||||
│
|
||||
├── 1001 ──→ (无会员卡)
|
||||
├── 1002 ──→ 会员卡记录 2001 (USED_UP)
|
||||
├── 1003 ──→ 会员卡记录 2002 (ACTIVE, 8次)
|
||||
├── 1004 ──→ 会员卡记录 2003 (EXPIRED)
|
||||
└── 1005 ──→ 会员卡记录 2004 (ACTIVE, 45次)
|
||||
└── 会员卡记录 2005 (ACTIVE, 350元)
|
||||
│
|
||||
↓
|
||||
预约记录表 (group_course_booking)
|
||||
│
|
||||
├── 3001: 已预约
|
||||
├── 3002: 已取消
|
||||
├── 3003: 已出席
|
||||
└── 3004: 缺席
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 十、数据初始化
|
||||
|
||||
测试数据通过 Flyway 迁移脚本 `V10__Insert_Booking_Test_Data.sql` 初始化,需在数据库初始化时执行。
|
||||
|
||||
**执行顺序**:
|
||||
1. V1__Create_all_tables.sql - 创建基础表结构
|
||||
2. V2__Insert_initial_data.sql - 插入初始数据
|
||||
3. V6__Create_GroupCourse_table.sql - 创建团课表
|
||||
4. V7__Insert_GroupCourse_test_data.sql - 插入团课测试数据
|
||||
5. V8__Create_Member_And_MemberCard.sql - 创建会员和会员卡表
|
||||
6. V9__Add_GroupCourse_Booking_Snapshot_Fields.sql - 添加冗余字段
|
||||
7. V10__Insert_Booking_Test_Data.sql - 插入预约测试数据(本文件)
|
||||
|
||||
---
|
||||
|
||||
**文档版本**: v1.1
|
||||
**创建时间**: 2026-06-02
|
||||
**更新时间**: 2026-06-02
|
||||
**适用场景**: 团课预约功能测试
|
||||
|
||||
---
|
||||
|
||||
## 十一、重要说明
|
||||
|
||||
### 11.1 字段说明
|
||||
|
||||
`member_card_record` 表包含两个ID字段:
|
||||
- `id` - 数据库主键(BIGSERIAL PRIMARY KEY)
|
||||
- `member_card_record_id` - 业务ID(BIGSERIAL),代码中使用此字段作为查询和更新条件
|
||||
|
||||
### 11.2 测试数据修复记录
|
||||
|
||||
**v1.1 修复内容**:
|
||||
- 修复了 `member_card_record` 表测试数据缺失 `member_card_record_id` 字段的问题
|
||||
- 原问题:测试数据只插入了 `id` 字段,导致 `member_card_record_id` 为 NULL
|
||||
- 影响:代码使用 `member_card_record_id` 作为WHERE条件时无法匹配到记录,导致扣减权益失败
|
||||
- 解决:在INSERT语句中添加 `member_card_record_id` 字段,值与 `id` 相同
|
||||
|
||||
**修复前**:
|
||||
```sql
|
||||
INSERT INTO member_card_record (id, member_id, member_card_id, ...) VALUES
|
||||
(2001, 1002, 101, ...);
|
||||
```
|
||||
|
||||
**修复后**:
|
||||
```sql
|
||||
INSERT INTO member_card_record (id, member_card_record_id, member_id, member_card_id, ...) VALUES
|
||||
(2001, 2001, 1002, 101, ...);
|
||||
```
|
||||
@@ -0,0 +1,728 @@
|
||||
# 团课管理模块 API 文档
|
||||
|
||||
> **文档版本**: v1.0
|
||||
> **创建日期**: 2026-06-02
|
||||
> **作者**: 张翔
|
||||
> **状态**: 正式发布
|
||||
|
||||
---
|
||||
|
||||
## 📋 目录
|
||||
|
||||
1. [概述](#概述)
|
||||
2. [基础路径](#基础路径)
|
||||
3. [团课管理接口](#团课管理接口)
|
||||
- [获取所有团课](#获取所有团课)
|
||||
- [分页获取团课](#分页获取团课)
|
||||
- [根据ID获取团课详情](#根据ID获取团课详情)
|
||||
- [创建团课](#创建团课)
|
||||
- [更新团课](#更新团课)
|
||||
- [取消团课](#取消团课)
|
||||
- [团课签到](#团课签到)
|
||||
- [删除团课](#删除团课)
|
||||
4. [团课预约接口](#团课预约接口)
|
||||
- [预约团课](#预约团课)
|
||||
- [取消预约](#取消预约)
|
||||
- [查询会员预约记录](#查询会员预约记录)
|
||||
- [查询预约详情](#查询预约详情)
|
||||
- [查询课程预约记录](#查询课程预约记录)
|
||||
5. [数据模型](#数据模型)
|
||||
- [GroupCourse(团课)](#GroupCourse团课)
|
||||
- [GroupCourseBooking(团课预约)](#GroupCourseBooking团课预约)
|
||||
6. [状态码说明](#状态码说明)
|
||||
7. [业务规则](#业务规则)
|
||||
|
||||
---
|
||||
|
||||
## 概述
|
||||
|
||||
团课管理模块提供团课的创建、编辑、查询、取消和签到功能,以及团课预约相关操作。采用 Spring WebFlux 响应式编程,支持高并发场景。
|
||||
|
||||
## 基础路径
|
||||
|
||||
所有接口的基础路径为: `http://{host}:{port}/api/groupCourse`
|
||||
|
||||
---
|
||||
|
||||
## 团课管理接口
|
||||
|
||||
### 获取所有团课
|
||||
|
||||
| 属性 | 值 |
|
||||
|------|-----|
|
||||
| **HTTP方法** | GET |
|
||||
| **接口路径** | `/api/groupCourse/list` |
|
||||
| **所属文件** | `GroupCourseHandler.java` |
|
||||
|
||||
**请求参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 默认值 | 说明 |
|
||||
|--------|------|------|--------|------|
|
||||
| includeDeleted | boolean | 否 | false | 是否包含已删除的团课 |
|
||||
|
||||
**成功响应** (200 OK):
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"courseName": "瑜伽入门",
|
||||
"coachId": 1,
|
||||
"courseType": 1,
|
||||
"startTime": "2026-06-02T09:00:00",
|
||||
"endTime": "2026-06-02T10:00:00",
|
||||
"maxMembers": 20,
|
||||
"currentMembers": 15,
|
||||
"status": 0,
|
||||
"location": "健身房A区",
|
||||
"coverImage": "https://example.com/yoga.jpg",
|
||||
"description": "适合初学者的瑜伽课程",
|
||||
"createdAt": "2026-06-01T10:00:00",
|
||||
"updatedAt": "2026-06-01T10:00:00"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 分页获取团课
|
||||
|
||||
| 属性 | 值 |
|
||||
|------|-----|
|
||||
| **HTTP方法** | POST |
|
||||
| **接口路径** | `/api/groupCourse/page` |
|
||||
| **所属文件** | `GroupCourseHandler.java` |
|
||||
|
||||
**请求体**:
|
||||
|
||||
```json
|
||||
{
|
||||
"page": 0,
|
||||
"size": 10,
|
||||
"sort": "id",
|
||||
"order": "asc",
|
||||
"keyword": "瑜伽"
|
||||
}
|
||||
```
|
||||
|
||||
| 参数名 | 类型 | 必填 | 默认值 | 说明 |
|
||||
|--------|------|------|--------|------|
|
||||
| page | int | 否 | 0 | 页码,从0开始 |
|
||||
| size | int | 否 | 10 | 每页数量,最大100 |
|
||||
| sort | string | 否 | id | 排序字段 |
|
||||
| order | string | 否 | asc | 排序方式(asc/desc) |
|
||||
| keyword | string | 否 | - | 搜索关键词 |
|
||||
|
||||
**请求参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 默认值 | 说明 |
|
||||
|--------|------|------|--------|------|
|
||||
| includeDeleted | boolean | 否 | false | 是否包含已删除的团课 |
|
||||
|
||||
**成功响应** (200 OK):
|
||||
|
||||
```json
|
||||
{
|
||||
"data": [...],
|
||||
"totalPages": 5,
|
||||
"totalElements": 45,
|
||||
"page": 0,
|
||||
"size": 10
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 根据ID获取团课详情
|
||||
|
||||
| 属性 | 值 |
|
||||
|------|-----|
|
||||
| **HTTP方法** | GET |
|
||||
| **接口路径** | `/api/groupCourse/{id}` |
|
||||
| **所属文件** | `GroupCourseHandler.java` |
|
||||
|
||||
**路径参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| id | Long | 是 | 团课ID |
|
||||
|
||||
**成功响应** (200 OK):
|
||||
|
||||
```json
|
||||
{
|
||||
"id": 1,
|
||||
"courseName": "瑜伽入门",
|
||||
"coachId": 1,
|
||||
"courseType": 1,
|
||||
"startTime": "2026-06-02T09:00:00",
|
||||
"endTime": "2026-06-02T10:00:00",
|
||||
"maxMembers": 20,
|
||||
"currentMembers": 15,
|
||||
"status": 0,
|
||||
"location": "健身房A区",
|
||||
"coverImage": "https://example.com/yoga.jpg",
|
||||
"description": "适合初学者的瑜伽课程",
|
||||
"pointCardAmount": 1,
|
||||
"storedValueAmount": 50.00,
|
||||
"createdAt": "2026-06-01T10:00:00",
|
||||
"updatedAt": "2026-06-01T10:00:00"
|
||||
}
|
||||
```
|
||||
|
||||
**失败响应** (404 Not Found):
|
||||
|
||||
```json
|
||||
{}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 创建团课
|
||||
|
||||
| 属性 | 值 |
|
||||
|------|-----|
|
||||
| **HTTP方法** | POST |
|
||||
| **接口路径** | `/api/groupCourse` |
|
||||
| **所属文件** | `GroupCourseHandler.java` |
|
||||
|
||||
**请求体**:
|
||||
|
||||
```json
|
||||
{
|
||||
"courseName": "动感单车",
|
||||
"coachId": 2,
|
||||
"courseType": 2,
|
||||
"startTime": "2026-06-05T18:00:00",
|
||||
"endTime": "2026-06-05T19:00:00",
|
||||
"maxMembers": 25,
|
||||
"location": "健身房B区",
|
||||
"coverImage": "https://example.com/spinning.jpg",
|
||||
"description": "高强度有氧运动课程",
|
||||
"pointCardAmount": 1,
|
||||
"storedValueAmount": 50.00
|
||||
}
|
||||
```
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| courseName | String | **是** | 课程名称 |
|
||||
| coachId | Long | 否 | 教练ID |
|
||||
| courseType | Long | 否 | 课程类型 |
|
||||
| startTime | LocalDateTime | 否 | 开始时间 |
|
||||
| endTime | LocalDateTime | 否 | 结束时间 |
|
||||
| maxMembers | Integer | 否 | 最大参与人数,默认20 |
|
||||
| location | String | 否 | 上课地点 |
|
||||
| coverImage | String | 否 | 封面图URL |
|
||||
| description | String | 否 | 课程描述 |
|
||||
| pointCardAmount | Integer | 否 | 点卡额度(消耗次数),默认1 |
|
||||
| storedValueAmount | BigDecimal | 否 | 储值卡额度(消耗金额),默认0 |
|
||||
|
||||
**成功响应** (200 OK):
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "团课创建成功",
|
||||
"data": {
|
||||
"id": 2,
|
||||
"courseName": "动感单车",
|
||||
"coachId": 2,
|
||||
"courseType": 2,
|
||||
"startTime": "2026-06-05T18:00:00",
|
||||
"endTime": "2026-06-05T19:00:00",
|
||||
"maxMembers": 25,
|
||||
"currentMembers": 0,
|
||||
"status": 0,
|
||||
"location": "健身房B区",
|
||||
"coverImage": "https://example.com/spinning.jpg",
|
||||
"description": "高强度有氧运动课程",
|
||||
"pointCardAmount": 1,
|
||||
"storedValueAmount": 50.00
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**失败响应** (400 Bad Request):
|
||||
|
||||
```json
|
||||
{
|
||||
"success": false,
|
||||
"message": "课程名称不能为空"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 更新团课
|
||||
|
||||
| 属性 | 值 |
|
||||
|------|-----|
|
||||
| **HTTP方法** | PUT |
|
||||
| **接口路径** | `/api/groupCourse/{id}` |
|
||||
| **所属文件** | `GroupCourseHandler.java` |
|
||||
|
||||
**路径参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| id | Long | 是 | 团课ID |
|
||||
|
||||
**请求体**:
|
||||
|
||||
```json
|
||||
{
|
||||
"courseName": "动感单车升级版",
|
||||
"coachId": 2,
|
||||
"maxMembers": 30,
|
||||
"description": "升级版高强度有氧运动课程",
|
||||
"pointCardAmount": 2,
|
||||
"storedValueAmount": 80.00
|
||||
}
|
||||
```
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| courseName | String | 否 | 课程名称 |
|
||||
| coachId | Long | 否 | 教练ID |
|
||||
| courseType | Long | 否 | 课程类型 |
|
||||
| startTime | LocalDateTime | 否 | 开始时间 |
|
||||
| endTime | LocalDateTime | 否 | 结束时间 |
|
||||
| maxMembers | Integer | 否 | 最大参与人数 |
|
||||
| location | String | 否 | 上课地点 |
|
||||
| coverImage | String | 否 | 封面图URL |
|
||||
| description | String | 否 | 课程描述 |
|
||||
| pointCardAmount | Integer | 否 | 点卡额度(消耗次数) |
|
||||
| storedValueAmount | BigDecimal | 否 | 储值卡额度(消耗金额) |
|
||||
|
||||
**成功响应** (200 OK):
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "团课更新成功",
|
||||
"data": {
|
||||
"id": 2,
|
||||
"courseName": "动感单车升级版",
|
||||
"coachId": 2,
|
||||
"maxMembers": 30,
|
||||
"description": "升级版高强度有氧运动课程",
|
||||
"pointCardAmount": 2,
|
||||
"storedValueAmount": 80.00
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**失败响应** (400 Bad Request):
|
||||
|
||||
```json
|
||||
{
|
||||
"success": false,
|
||||
"message": "团课不存在"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 取消团课
|
||||
|
||||
| 属性 | 值 |
|
||||
|------|-----|
|
||||
| **HTTP方法** | POST |
|
||||
| **接口路径** | `/api/groupCourse/{id}/cancel` |
|
||||
| **所属文件** | `GroupCourseHandler.java` |
|
||||
|
||||
**路径参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| id | Long | 是 | 团课ID |
|
||||
|
||||
**成功响应** (200 OK):
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "团课取消成功",
|
||||
"data": {
|
||||
"id": 2,
|
||||
"status": 1
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**失败响应** (400 Bad Request):
|
||||
|
||||
```json
|
||||
{
|
||||
"success": false,
|
||||
"message": "课程取消需提前24小时"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 团课签到
|
||||
|
||||
| 属性 | 值 |
|
||||
|------|-----|
|
||||
| **HTTP方法** | POST |
|
||||
| **接口路径** | `/api/groupCourse/{courseId}/signin` |
|
||||
| **所属文件** | `GroupCourseHandler.java` |
|
||||
|
||||
**路径参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| courseId | Long | 是 | 团课ID |
|
||||
|
||||
**请求体**:
|
||||
|
||||
```json
|
||||
{
|
||||
"memberId": 1001
|
||||
}
|
||||
```
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| memberId | Long | **是** | 会员ID |
|
||||
|
||||
**成功响应** (200 OK):
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "签到成功",
|
||||
"data": {
|
||||
"id": 2,
|
||||
"currentMembers": 16
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**失败响应** (400 Bad Request):
|
||||
|
||||
```json
|
||||
{
|
||||
"success": false,
|
||||
"message": "课程已满员"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 删除团课
|
||||
|
||||
| 属性 | 值 |
|
||||
|------|-----|
|
||||
| **HTTP方法** | DELETE |
|
||||
| **接口路径** | `/api/groupCourse/{id}` |
|
||||
| **所属文件** | `GroupCourseHandler.java` |
|
||||
|
||||
**路径参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| id | Long | 是 | 团课ID |
|
||||
|
||||
**成功响应** (200 OK):
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "团课删除成功"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 团课预约接口
|
||||
|
||||
### 预约团课
|
||||
|
||||
| 属性 | 值 |
|
||||
|------|-----|
|
||||
| **HTTP方法** | POST |
|
||||
| **接口路径** | `/api/groupCourse/book` |
|
||||
| **所属文件** | `GroupCourseBookingHandler.java` |
|
||||
|
||||
**请求体**:
|
||||
|
||||
```json
|
||||
{
|
||||
"courseId": 1,
|
||||
"memberId": 1001,
|
||||
"memberCardRecordId": 5001
|
||||
}
|
||||
```
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| courseId | Long | **是** | 团课ID |
|
||||
| memberId | Long | **是** | 会员ID |
|
||||
| memberCardRecordId | Long | **是** | 会员卡记录ID |
|
||||
|
||||
**成功响应** (200 OK):
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "预约成功",
|
||||
"data": {
|
||||
"id": 100,
|
||||
"courseId": 1,
|
||||
"memberId": 1001,
|
||||
"memberCardRecordId": 5001,
|
||||
"bookingTime": "2026-06-02T08:00:00",
|
||||
"status": "0"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 取消预约
|
||||
|
||||
| 属性 | 值 |
|
||||
|------|-----|
|
||||
| **HTTP方法** | POST |
|
||||
| **接口路径** | `/api/groupCourse/booking/{bookingId}/cancel` |
|
||||
| **所属文件** | `GroupCourseBookingHandler.java` |
|
||||
|
||||
**路径参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| bookingId | Long | 是 | 预约ID |
|
||||
|
||||
**请求体**:
|
||||
|
||||
```json
|
||||
{
|
||||
"memberId": 1001
|
||||
}
|
||||
```
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| memberId | Long | **是** | 会员ID |
|
||||
|
||||
**成功响应** (200 OK):
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "取消成功",
|
||||
"data": {
|
||||
"id": 100,
|
||||
"status": "1",
|
||||
"cancelTime": "2026-06-02T09:00:00"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 查询会员预约记录
|
||||
|
||||
| 属性 | 值 |
|
||||
|------|-----|
|
||||
| **HTTP方法** | GET |
|
||||
| **接口路径** | `/api/groupCourse/bookings/member/{memberId}` |
|
||||
| **所属文件** | `GroupCourseBookingHandler.java` |
|
||||
|
||||
**路径参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| memberId | Long | 是 | 会员ID |
|
||||
|
||||
**成功响应** (200 OK):
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"id": 100,
|
||||
"courseId": 1,
|
||||
"courseName": "瑜伽入门",
|
||||
"memberId": 1001,
|
||||
"memberCardRecordId": 5001,
|
||||
"bookingTime": "2026-06-02T08:00:00",
|
||||
"status": "0",
|
||||
"courseStartTime": "2026-06-02T09:00:00",
|
||||
"location": "健身房A区"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 查询预约详情
|
||||
|
||||
| 属性 | 值 |
|
||||
|------|-----|
|
||||
| **HTTP方法** | GET |
|
||||
| **接口路径** | `/api/groupCourse/bookings/{bookingId}` |
|
||||
| **所属文件** | `GroupCourseBookingHandler.java` |
|
||||
|
||||
**路径参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| bookingId | Long | 是 | 预约ID |
|
||||
|
||||
**成功响应** (200 OK):
|
||||
|
||||
```json
|
||||
{
|
||||
"id": 100,
|
||||
"courseId": 1,
|
||||
"courseName": "瑜伽入门",
|
||||
"memberId": 1001,
|
||||
"memberCardRecordId": 5001,
|
||||
"bookingTime": "2026-06-02T08:00:00",
|
||||
"status": "0",
|
||||
"courseStartTime": "2026-06-02T09:00:00",
|
||||
"courseEndTime": "2026-06-02T10:00:00",
|
||||
"location": "健身房A区"
|
||||
}
|
||||
```
|
||||
|
||||
**失败响应** (404 Not Found):
|
||||
|
||||
```json
|
||||
{}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 查询课程预约记录
|
||||
|
||||
| 属性 | 值 |
|
||||
|------|-----|
|
||||
| **HTTP方法** | GET |
|
||||
| **接口路径** | `/api/groupCourse/bookings/course/{courseId}` |
|
||||
| **所属文件** | `GroupCourseBookingHandler.java` |
|
||||
|
||||
**路径参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| courseId | Long | 是 | 团课ID |
|
||||
|
||||
**成功响应** (200 OK):
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"id": 100,
|
||||
"courseId": 1,
|
||||
"courseName": "瑜伽入门",
|
||||
"memberId": 1001,
|
||||
"bookingTime": "2026-06-02T08:00:00",
|
||||
"status": "0"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 数据模型
|
||||
|
||||
### GroupCourse(团课)
|
||||
|
||||
| 字段名 | 类型 | 说明 |
|
||||
|--------|------|------|
|
||||
| id | Long | 主键ID |
|
||||
| courseName | String | 课程名称 |
|
||||
| coachId | Long | 教练ID |
|
||||
| courseType | Long | 课程类型 |
|
||||
| startTime | LocalDateTime | 开始时间 |
|
||||
| endTime | LocalDateTime | 结束时间 |
|
||||
| maxMembers | Integer | 最大参与人数 |
|
||||
| currentMembers | Integer | 当前参与人数 |
|
||||
| status | Long | 状态(0-正常,1-已取消,2-已结束) |
|
||||
| location | String | 上课地点 |
|
||||
| coverImage | String | 封面图URL |
|
||||
| description | String | 课程描述 |
|
||||
| pointCardAmount | Integer | 点卡额度(消耗次数),默认1 |
|
||||
| storedValueAmount | BigDecimal | 储值卡额度(消耗金额),默认0 |
|
||||
| createdBy | String | 创建人 |
|
||||
| updatedBy | String | 更新人 |
|
||||
| createdAt | LocalDateTime | 创建时间 |
|
||||
| updatedAt | LocalDateTime | 更新时间 |
|
||||
| deletedAt | LocalDateTime | 删除时间(软删除) |
|
||||
|
||||
### GroupCourseBooking(团课预约)
|
||||
|
||||
| 字段名 | 类型 | 说明 |
|
||||
|--------|------|------|
|
||||
| id | Long | 主键ID |
|
||||
| courseId | Long | 团课ID |
|
||||
| courseName | String | 团课名称 |
|
||||
| memberId | Long | 会员ID |
|
||||
| memberCardRecordId | Long | 会员卡记录ID |
|
||||
| bookingTime | LocalDateTime | 预约时间 |
|
||||
| status | String | 状态(0-已预约,1-已取消,2-已出席,3-缺席) |
|
||||
| cancelTime | LocalDateTime | 取消时间 |
|
||||
| courseStartTime | LocalDateTime | 课程开始时间 |
|
||||
| courseEndTime | LocalDateTime | 课程结束时间 |
|
||||
| location | String | 上课地点 |
|
||||
| createdBy | String | 创建人 |
|
||||
| updatedBy | String | 更新人 |
|
||||
| createdAt | LocalDateTime | 创建时间 |
|
||||
| updatedAt | LocalDateTime | 更新时间 |
|
||||
| deletedAt | LocalDateTime | 删除时间(软删除) |
|
||||
|
||||
---
|
||||
|
||||
## 状态码说明
|
||||
|
||||
### 团课状态
|
||||
|
||||
| 状态码 | 含义 |
|
||||
|--------|------|
|
||||
| 0 | 正常 |
|
||||
| 1 | 已取消 |
|
||||
| 2 | 已结束 |
|
||||
|
||||
### 预约状态
|
||||
|
||||
| 状态码 | 含义 |
|
||||
|--------|------|
|
||||
| 0 | 已预约 |
|
||||
| 1 | 已取消 |
|
||||
| 2 | 已出席 |
|
||||
| 3 | 缺席 |
|
||||
|
||||
---
|
||||
|
||||
## 业务规则
|
||||
|
||||
### 团课管理
|
||||
1. **创建团课**:课程名称为必填项
|
||||
2. **取消团课**:需提前24小时通知,否则拒绝操作
|
||||
3. **团课签到**:验证课程状态必须为正常,且未达最大人数限制
|
||||
4. **删除团课**:采用软删除机制,数据保留可恢复
|
||||
|
||||
### 团课预约
|
||||
1. **预约团课**:需验证会员卡有效性和课程名额
|
||||
2. **取消预约**:需在课程开始前至少2小时取消
|
||||
|
||||
---
|
||||
|
||||
## 附录:错误响应格式
|
||||
|
||||
所有接口的错误响应统一格式:
|
||||
|
||||
```json
|
||||
{
|
||||
"success": false,
|
||||
"message": "错误描述信息"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
*文档结束*
|
||||
@@ -0,0 +1,3 @@
|
||||
wrapperVersion=3.3.4
|
||||
distributionType=only-script
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.15/apache-maven-3.9.15-bin.zip
|
||||
@@ -0,0 +1,95 @@
|
||||
<?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 https://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>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<groupId>cn.novalon.gym.manage</groupId>
|
||||
<artifactId>gym-groupCourse</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<name>gym-groupCourse</name>
|
||||
<description>Group Course Management Module</description>
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
</properties>
|
||||
<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>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</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-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-annotations-jakarta</artifactId>
|
||||
<version>2.2.43</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Redis依赖-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 会员模块依赖 -->
|
||||
<dependency>
|
||||
<groupId>cn.novalon.gym.manage</groupId>
|
||||
<artifactId>gym-member</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
|
||||
package cn.novalon.gym.manage.groupcourse.converter;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourseBooking;
|
||||
import cn.novalon.gym.manage.groupcourse.entity.GroupCourseBookingEntity;
|
||||
import cn.novalon.gym.manage.groupcourse.entity.GroupCourseEntity;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 团课相关转换器
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-06-01
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class GroupCourseConverter {
|
||||
|
||||
/**
|
||||
* 将团课实体转换为领域模型
|
||||
*/
|
||||
public GroupCourse toDomain(GroupCourseEntity entity){
|
||||
if(entity == null){
|
||||
return null;
|
||||
}
|
||||
GroupCourse groupCourse = new GroupCourse();
|
||||
BeanUtil.copyProperties(entity,groupCourse);
|
||||
log.info("转换bean,entity-domain:",groupCourse);
|
||||
return groupCourse;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将团课领域模型转换为实体
|
||||
*/
|
||||
public GroupCourseEntity toEntity(GroupCourse domain){
|
||||
if(domain == null){
|
||||
return null;
|
||||
}
|
||||
GroupCourseEntity entity = new GroupCourseEntity();
|
||||
BeanUtil.copyProperties(domain,entity);
|
||||
log.info("转换bean,domain-entity:",entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将团课实体列表转换为领域模型列表
|
||||
*/
|
||||
public List<GroupCourse> toDomainList(List<GroupCourseEntity> entities){
|
||||
if (entities == null) {
|
||||
return null;
|
||||
}
|
||||
return entities.stream()
|
||||
.map(this::toDomain)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 将团课领域模型列表转换为实体列表
|
||||
*/
|
||||
public List<GroupCourseEntity> toEntityList(List<GroupCourse> domains){
|
||||
if (domains == null) {
|
||||
return null;
|
||||
}
|
||||
return domains.stream()
|
||||
.map(this::toEntity)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 将团课预约实体转换为领域模型
|
||||
*/
|
||||
public GroupCourseBooking toBookingDomain(GroupCourseBookingEntity entity){
|
||||
if(entity == null){
|
||||
return null;
|
||||
}
|
||||
GroupCourseBooking booking = new GroupCourseBooking();
|
||||
BeanUtil.copyProperties(entity, booking);
|
||||
log.debug("转换预约记录实体到领域模型:bookingId={}", entity.getId());
|
||||
return booking;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将团课预约领域模型转换为实体
|
||||
*/
|
||||
public GroupCourseBookingEntity toBookingEntity(GroupCourseBooking domain){
|
||||
if(domain == null){
|
||||
return null;
|
||||
}
|
||||
GroupCourseBookingEntity entity = new GroupCourseBookingEntity();
|
||||
BeanUtil.copyProperties(domain, entity);
|
||||
if (domain.getId() != null) {
|
||||
entity.markNotNew();
|
||||
}
|
||||
log.debug("转换预约记录领域模型到实体:bookingId={}", domain.getId());
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将团课预约实体列表转换为领域模型列表
|
||||
*/
|
||||
public List<GroupCourseBooking> toBookingDomainList(List<GroupCourseBookingEntity> entities){
|
||||
if (entities == null) {
|
||||
return null;
|
||||
}
|
||||
return entities.stream()
|
||||
.map(this::toBookingDomain)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 将团课预约领域模型列表转换为实体列表
|
||||
*/
|
||||
public List<GroupCourseBookingEntity> toBookingEntityList(List<GroupCourseBooking> domains){
|
||||
if (domains == null) {
|
||||
return null;
|
||||
}
|
||||
return domains.stream()
|
||||
.map(this::toBookingEntity)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
package cn.novalon.gym.manage.groupcourse.dao;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.entity.GroupCourseBookingEntity;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.r2dbc.repository.R2dbcRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* 团课预约记录DAO接口
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-06-01
|
||||
*/
|
||||
@Repository
|
||||
public interface GroupCourseBookingDao extends R2dbcRepository<GroupCourseBookingEntity, Long> {
|
||||
|
||||
/**
|
||||
* 根据ID查询未删除的预约记录
|
||||
*/
|
||||
Mono<GroupCourseBookingEntity> findByIdIsAndDeletedAtIsNull(Long id);
|
||||
|
||||
/**
|
||||
* 根据会员ID查询所有预约记录
|
||||
*/
|
||||
Flux<GroupCourseBookingEntity> findByMemberIdAndDeletedAtIsNull(Long memberId);
|
||||
|
||||
/**
|
||||
* 根据会员ID查询所有预约记录(带排序)
|
||||
*/
|
||||
Flux<GroupCourseBookingEntity> findByMemberIdAndDeletedAtIsNull(Long memberId, Sort sort);
|
||||
|
||||
/**
|
||||
* 根据团课ID查询所有预约记录
|
||||
*/
|
||||
Flux<GroupCourseBookingEntity> findByCourseIdAndDeletedAtIsNull(Long courseId);
|
||||
|
||||
/**
|
||||
* 根据团课ID和会员ID查询预约记录
|
||||
*/
|
||||
Mono<GroupCourseBookingEntity> findByCourseIdAndMemberIdAndDeletedAtIsNull(Long courseId, Long memberId);
|
||||
|
||||
/**
|
||||
* 根据团课ID和状态查询预约记录
|
||||
*/
|
||||
Flux<GroupCourseBookingEntity> findByCourseIdAndStatusAndDeletedAtIsNull(Long courseId, String status);
|
||||
|
||||
/**
|
||||
* 查询会员在指定课程的有效预约(状态为已预约且未取消)
|
||||
*/
|
||||
Mono<GroupCourseBookingEntity> findByCourseIdAndMemberIdAndStatusAndDeletedAtIsNull(Long courseId, Long memberId, String status);
|
||||
|
||||
/**
|
||||
* 根据会员卡记录ID查询预约记录
|
||||
*/
|
||||
Flux<GroupCourseBookingEntity> findByMemberCardRecordIdAndDeletedAtIsNull(Long memberCardRecordId);
|
||||
|
||||
/**
|
||||
* 统计团课已预约人数
|
||||
*/
|
||||
Mono<Long> countByCourseIdAndStatusAndDeletedAtIsNull(Long courseId, String status);
|
||||
|
||||
/**
|
||||
* 查询会员是否有时间冲突的预约(状态为已预约且未取消)
|
||||
* 时间冲突条件:新课程的开始时间 < 已预约课程的结束时间 且 新课程的结束时间 > 已预约课程的开始时间
|
||||
*/
|
||||
@org.springframework.data.r2dbc.repository.Query("SELECT * FROM group_course_booking b " +
|
||||
"JOIN group_course c ON b.course_id = c.id " +
|
||||
"WHERE b.member_id = :memberId " +
|
||||
"AND b.status = '0' " +
|
||||
"AND b.deleted_at IS NULL " +
|
||||
"AND c.deleted_at IS NULL " +
|
||||
"AND :newStartTime < c.end_time " +
|
||||
"AND :newEndTime > c.start_time")
|
||||
Flux<GroupCourseBookingEntity> findConflictingBookings(Long memberId, java.time.LocalDateTime newStartTime, java.time.LocalDateTime newEndTime);
|
||||
|
||||
/**
|
||||
* 更新预约状态
|
||||
*/
|
||||
@org.springframework.data.r2dbc.repository.Modifying
|
||||
@org.springframework.data.r2dbc.repository.Query("UPDATE group_course_booking SET status = :status, cancel_time = :cancelTime, updated_at = :updatedAt WHERE id = :id AND deleted_at IS NULL")
|
||||
Mono<Integer> updateStatus(Long id, String status, java.time.LocalDateTime cancelTime, java.time.LocalDateTime updatedAt);
|
||||
|
||||
/**
|
||||
* 软删除预约记录
|
||||
*/
|
||||
@org.springframework.data.r2dbc.repository.Modifying
|
||||
@org.springframework.data.r2dbc.repository.Query("UPDATE group_course_booking SET deleted_at = :deletedAt WHERE id = :id")
|
||||
Mono<Integer> softDelete(Long id, java.time.LocalDateTime deletedAt);
|
||||
|
||||
/**
|
||||
* 查询已开始课程但未到场会员的预约记录
|
||||
* 条件:课程开始时间早于当前时间,预约状态为已预约(0)
|
||||
*/
|
||||
@org.springframework.data.r2dbc.repository.Query("SELECT b.* FROM group_course_booking b " +
|
||||
"JOIN group_course c ON b.course_id = c.id " +
|
||||
"WHERE b.status = '0' " +
|
||||
"AND b.deleted_at IS NULL " +
|
||||
"AND c.deleted_at IS NULL " +
|
||||
"AND c.status = '0' " +
|
||||
"AND c.start_time < CURRENT_TIMESTAMP")
|
||||
Flux<GroupCourseBookingEntity> findAbsentMembers();
|
||||
|
||||
/**
|
||||
* 批量更新预约状态为缺席
|
||||
*/
|
||||
@org.springframework.data.r2dbc.repository.Modifying
|
||||
@org.springframework.data.r2dbc.repository.Query("UPDATE group_course_booking SET status = '3', updated_at = :updatedAt WHERE id = :id AND deleted_at IS NULL")
|
||||
Mono<Integer> updateToAbsent(Long id, java.time.LocalDateTime updatedAt);
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
|
||||
package cn.novalon.gym.manage.groupcourse.dao;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.entity.GroupCourseEntity;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.r2dbc.repository.Modifying;
|
||||
import org.springframework.data.r2dbc.repository.Query;
|
||||
import org.springframework.data.r2dbc.repository.R2dbcRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Repository
|
||||
public interface GroupCourseDao extends R2dbcRepository<GroupCourseEntity, Long> {
|
||||
|
||||
Mono<GroupCourseEntity> findByIdIsAndDeletedAtIsNull(Long id);
|
||||
|
||||
Flux<GroupCourseEntity> findAll();
|
||||
|
||||
Flux<GroupCourseEntity> findAll(Sort sort);
|
||||
|
||||
Flux<GroupCourseEntity> findAllByDeletedAtIsNull();
|
||||
|
||||
Flux<GroupCourseEntity> findAllByDeletedAtIsNull(Sort sort);
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE group_course SET status = '1', updated_at = :updatedAt WHERE id = :id AND deleted_at IS NULL")
|
||||
Mono<Integer> cancelCourse(Long id, LocalDateTime updatedAt);
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE group_course SET current_members = current_members + :delta, updated_at = :updatedAt WHERE id = :id AND deleted_at IS NULL")
|
||||
Mono<Integer> updateCurrentMembers(Long id, Integer delta, LocalDateTime updatedAt);
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE group_course SET deleted_at = :deletedAt WHERE id = :id")
|
||||
Mono<Integer> softDelete(Long id, LocalDateTime deletedAt);
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
|
||||
package cn.novalon.gym.manage.groupcourse.domain;
|
||||
|
||||
import cn.novalon.gym.manage.sys.core.domain.BaseDomain;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class GroupCourse extends BaseDomain{
|
||||
|
||||
//课程名称
|
||||
@Schema(description = "团课名", example = "Push-up")
|
||||
private String courseName;
|
||||
|
||||
//教练id
|
||||
@Schema(description = "教练id", example = "1")
|
||||
private Long coachId;
|
||||
|
||||
//课程类型
|
||||
@Schema(description = "课程类型", example = "1")
|
||||
private Long courseType;
|
||||
|
||||
//开始时间
|
||||
@Schema(description = "开始时间", example = "2026-01-01")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
//结束时间
|
||||
@Schema(description = "结束时间", example = "2026-01-02")
|
||||
private LocalDateTime endTime;
|
||||
|
||||
//最大参与人数
|
||||
@Schema(description = "最大参与人数", example = "20")
|
||||
private Integer maxMembers;
|
||||
|
||||
//当前参与人数
|
||||
@Schema(description = "当前参与人数", example = "2")
|
||||
private Integer currentMembers;
|
||||
|
||||
//课程状态:0-正常,1-已取消,2-已结束
|
||||
@Schema(description = "课程状态", example = "0")
|
||||
private Long status;
|
||||
|
||||
//上课地点
|
||||
@Schema(description = "上课地点", example = "龙泉驿区幸福路")
|
||||
private String location;
|
||||
|
||||
//封面图URL
|
||||
@Schema(description = "封面图URL", example = "https://12345.com")
|
||||
private String coverImage;
|
||||
|
||||
//课程描述
|
||||
@Schema(description = "课程描述", example = "从入门到入土")
|
||||
private String description;
|
||||
|
||||
//点卡额度(消耗次数)
|
||||
@Schema(description = "点卡额度(消耗次数)", example = "1")
|
||||
private Integer pointCardAmount;
|
||||
|
||||
//储值卡额度(消耗金额)
|
||||
@Schema(description = "储值卡额度(消耗金额)", example = "50.00")
|
||||
private java.math.BigDecimal storedValueAmount;
|
||||
|
||||
public String getCourseName() {
|
||||
return courseName;
|
||||
}
|
||||
|
||||
public void setCourseName(String courseName) {
|
||||
this.courseName = courseName;
|
||||
}
|
||||
|
||||
public Long getCoachId() {
|
||||
return coachId;
|
||||
}
|
||||
|
||||
public void setCoachId(Long coachId) {
|
||||
this.coachId = coachId;
|
||||
}
|
||||
|
||||
public Long getCourseType() {
|
||||
return courseType;
|
||||
}
|
||||
|
||||
public void setCourseType(Long courseType) {
|
||||
this.courseType = courseType;
|
||||
}
|
||||
|
||||
public LocalDateTime getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(LocalDateTime startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(LocalDateTime endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public Integer getMaxMembers() {
|
||||
return maxMembers;
|
||||
}
|
||||
|
||||
public void setMaxMembers(Integer maxMembers) {
|
||||
this.maxMembers = maxMembers;
|
||||
}
|
||||
|
||||
public Integer getCurrentMembers() {
|
||||
return currentMembers;
|
||||
}
|
||||
|
||||
public void setCurrentMembers(Integer currentMembers) {
|
||||
this.currentMembers = currentMembers;
|
||||
}
|
||||
|
||||
public Long getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Long status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String getCoverImage() {
|
||||
return coverImage;
|
||||
}
|
||||
|
||||
public void setCoverImage(String coverImage) {
|
||||
this.coverImage = coverImage;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Integer getPointCardAmount() {
|
||||
return pointCardAmount;
|
||||
}
|
||||
|
||||
public void setPointCardAmount(Integer pointCardAmount) {
|
||||
this.pointCardAmount = pointCardAmount;
|
||||
}
|
||||
|
||||
public java.math.BigDecimal getStoredValueAmount() {
|
||||
return storedValueAmount;
|
||||
}
|
||||
|
||||
public void setStoredValueAmount(java.math.BigDecimal storedValueAmount) {
|
||||
this.storedValueAmount = storedValueAmount;
|
||||
}
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
package cn.novalon.gym.manage.groupcourse.domain;
|
||||
|
||||
import cn.novalon.gym.manage.sys.core.domain.BaseDomain;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 团课预约记录领域模型
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-06-01
|
||||
*/
|
||||
public class GroupCourseBooking extends BaseDomain {
|
||||
|
||||
//团课ID
|
||||
@Schema(description = "团课ID", example = "1")
|
||||
private Long courseId;
|
||||
|
||||
//团课名称(关联查询)
|
||||
@Schema(description = "团课名称", example = "瑜伽入门")
|
||||
private String courseName;
|
||||
|
||||
//会员ID
|
||||
@Schema(description = "会员ID", example = "1")
|
||||
private Long memberId;
|
||||
|
||||
//会员卡记录ID
|
||||
@Schema(description = "会员卡记录ID", example = "1")
|
||||
private Long memberCardRecordId;
|
||||
|
||||
//预约时间
|
||||
@Schema(description = "预约时间", example = "2026-06-01 10:00:00")
|
||||
private LocalDateTime bookingTime;
|
||||
|
||||
//状态:0-已预约,1-已取消,2-已出席,3-缺席
|
||||
@Schema(description = "状态:0-已预约,1-已取消,2-已出席,3-缺席", example = "0")
|
||||
private String status;
|
||||
|
||||
//取消时间
|
||||
@Schema(description = "取消时间", example = "2026-06-01 11:00:00")
|
||||
private LocalDateTime cancelTime;
|
||||
|
||||
//课程开始时间
|
||||
@Schema(description = "课程开始时间", example = "2026-06-02 09:00:00")
|
||||
private LocalDateTime courseStartTime;
|
||||
|
||||
//课程结束时间
|
||||
@Schema(description = "课程结束时间", example = "2026-06-02 10:00:00")
|
||||
private LocalDateTime courseEndTime;
|
||||
|
||||
//上课地点
|
||||
@Schema(description = "上课地点", example = "健身房A区")
|
||||
private String location;
|
||||
|
||||
public Long getCourseId() {
|
||||
return courseId;
|
||||
}
|
||||
|
||||
public void setCourseId(Long courseId) {
|
||||
this.courseId = courseId;
|
||||
}
|
||||
|
||||
public String getCourseName() {
|
||||
return courseName;
|
||||
}
|
||||
|
||||
public void setCourseName(String courseName) {
|
||||
this.courseName = courseName;
|
||||
}
|
||||
|
||||
public Long getMemberId() {
|
||||
return memberId;
|
||||
}
|
||||
|
||||
public void setMemberId(Long memberId) {
|
||||
this.memberId = memberId;
|
||||
}
|
||||
|
||||
public Long getMemberCardRecordId() {
|
||||
return memberCardRecordId;
|
||||
}
|
||||
|
||||
public void setMemberCardRecordId(Long memberCardRecordId) {
|
||||
this.memberCardRecordId = memberCardRecordId;
|
||||
}
|
||||
|
||||
public LocalDateTime getBookingTime() {
|
||||
return bookingTime;
|
||||
}
|
||||
|
||||
public void setBookingTime(LocalDateTime bookingTime) {
|
||||
this.bookingTime = bookingTime;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public LocalDateTime getCancelTime() {
|
||||
return cancelTime;
|
||||
}
|
||||
|
||||
public void setCancelTime(LocalDateTime cancelTime) {
|
||||
this.cancelTime = cancelTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getCourseStartTime() {
|
||||
return courseStartTime;
|
||||
}
|
||||
|
||||
public void setCourseStartTime(LocalDateTime courseStartTime) {
|
||||
this.courseStartTime = courseStartTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getCourseEndTime() {
|
||||
return courseEndTime;
|
||||
}
|
||||
|
||||
public void setCourseEndTime(LocalDateTime courseEndTime) {
|
||||
this.courseEndTime = courseEndTime;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
package cn.novalon.gym.manage.groupcourse.entity;
|
||||
|
||||
import cn.novalon.gym.manage.db.entity.BaseEntity;
|
||||
import org.springframework.data.relational.core.mapping.Column;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 团课预约记录实体类 - 对应 group_course_booking 表
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-06-01
|
||||
*/
|
||||
@Table("group_course_booking")
|
||||
public class GroupCourseBookingEntity extends BaseEntity {
|
||||
|
||||
//团课ID
|
||||
@Column("course_id")
|
||||
private Long courseId;
|
||||
|
||||
//会员ID
|
||||
@Column("member_id")
|
||||
private Long memberId;
|
||||
|
||||
//会员卡记录ID
|
||||
@Column("member_card_id")
|
||||
private Long memberCardRecordId;
|
||||
|
||||
//预约时间
|
||||
@Column("booking_time")
|
||||
private LocalDateTime bookingTime;
|
||||
|
||||
//状态:0-已预约,1-已取消,2-已出席,3-缺席
|
||||
@Column("status")
|
||||
private String status;
|
||||
|
||||
//取消时间
|
||||
@Column("cancel_time")
|
||||
private LocalDateTime cancelTime;
|
||||
|
||||
//课程名称(冗余字段,保存预约时的课程快照)
|
||||
@Column("course_name")
|
||||
private String courseName;
|
||||
|
||||
//课程开始时间(冗余字段,保存预约时的课程快照)
|
||||
@Column("course_start_time")
|
||||
private LocalDateTime courseStartTime;
|
||||
|
||||
//课程结束时间(冗余字段,保存预约时的课程快照)
|
||||
@Column("course_end_time")
|
||||
private LocalDateTime courseEndTime;
|
||||
|
||||
//上课地点(冗余字段,保存预约时的课程快照)
|
||||
@Column("location")
|
||||
private String location;
|
||||
|
||||
public Long getCourseId() {
|
||||
return courseId;
|
||||
}
|
||||
|
||||
public void setCourseId(Long courseId) {
|
||||
this.courseId = courseId;
|
||||
}
|
||||
|
||||
public Long getMemberId() {
|
||||
return memberId;
|
||||
}
|
||||
|
||||
public void setMemberId(Long memberId) {
|
||||
this.memberId = memberId;
|
||||
}
|
||||
|
||||
public Long getMemberCardRecordId() {
|
||||
return memberCardRecordId;
|
||||
}
|
||||
|
||||
public void setMemberCardRecordId(Long memberCardRecordId) {
|
||||
this.memberCardRecordId = memberCardRecordId;
|
||||
}
|
||||
|
||||
public LocalDateTime getBookingTime() {
|
||||
return bookingTime;
|
||||
}
|
||||
|
||||
public void setBookingTime(LocalDateTime bookingTime) {
|
||||
this.bookingTime = bookingTime;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public LocalDateTime getCancelTime() {
|
||||
return cancelTime;
|
||||
}
|
||||
|
||||
public void setCancelTime(LocalDateTime cancelTime) {
|
||||
this.cancelTime = cancelTime;
|
||||
}
|
||||
|
||||
public String getCourseName() {
|
||||
return courseName;
|
||||
}
|
||||
|
||||
public void setCourseName(String courseName) {
|
||||
this.courseName = courseName;
|
||||
}
|
||||
|
||||
public LocalDateTime getCourseStartTime() {
|
||||
return courseStartTime;
|
||||
}
|
||||
|
||||
public void setCourseStartTime(LocalDateTime courseStartTime) {
|
||||
this.courseStartTime = courseStartTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getCourseEndTime() {
|
||||
return courseEndTime;
|
||||
}
|
||||
|
||||
public void setCourseEndTime(LocalDateTime courseEndTime) {
|
||||
this.courseEndTime = courseEndTime;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
}
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
|
||||
package cn.novalon.gym.manage.groupcourse.entity;
|
||||
|
||||
import cn.novalon.gym.manage.db.entity.BaseEntity;
|
||||
import org.springframework.data.relational.core.mapping.Column;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Table("group_course")
|
||||
public class GroupCourseEntity extends BaseEntity {
|
||||
|
||||
//课程名称
|
||||
@Column("course_name")
|
||||
private String courseName;
|
||||
|
||||
//教练id
|
||||
@Column("coach_id")
|
||||
private Long coachId;
|
||||
|
||||
//课程类型
|
||||
@Column("course_type")
|
||||
private Long courseType;
|
||||
|
||||
//开始时间
|
||||
@Column("start_time")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
//结束时间
|
||||
@Column("end_time")
|
||||
private LocalDateTime endTime;
|
||||
|
||||
//最大参与人数
|
||||
@Column("max_members")
|
||||
private Integer maxMembers;
|
||||
|
||||
//当前参与人数
|
||||
@Column("current_members")
|
||||
private Integer currentMembers;
|
||||
|
||||
//课程状态:0-正常,1-已取消,2-已结束
|
||||
@Column("status")
|
||||
private Long status;
|
||||
|
||||
//上课地点
|
||||
@Column("location")
|
||||
private String location;
|
||||
|
||||
//封面图URL
|
||||
@Column("cover_image")
|
||||
private String coverImage;
|
||||
|
||||
//课程描述
|
||||
@Column("description")
|
||||
private String description;
|
||||
|
||||
//点卡额度(消耗次数)
|
||||
@Column("point_card_amount")
|
||||
private Integer pointCardAmount;
|
||||
|
||||
//储值卡额度(消耗金额)
|
||||
@Column("stored_value_amount")
|
||||
private java.math.BigDecimal storedValueAmount;
|
||||
|
||||
public String getCourseName() {
|
||||
return courseName;
|
||||
}
|
||||
|
||||
public void setCourseName(String courseName) {
|
||||
this.courseName = courseName;
|
||||
}
|
||||
|
||||
public Long getCoachId() {
|
||||
return coachId;
|
||||
}
|
||||
|
||||
public void setCoachId(Long coachId) {
|
||||
this.coachId = coachId;
|
||||
}
|
||||
|
||||
public Long getCourseType() {
|
||||
return courseType;
|
||||
}
|
||||
|
||||
public void setCourseType(Long courseType) {
|
||||
this.courseType = courseType;
|
||||
}
|
||||
|
||||
public LocalDateTime getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(LocalDateTime startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(LocalDateTime endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public Integer getMaxMembers() {
|
||||
return maxMembers;
|
||||
}
|
||||
|
||||
public void setMaxMembers(Integer maxMembers) {
|
||||
this.maxMembers = maxMembers;
|
||||
}
|
||||
|
||||
public Integer getCurrentMembers() {
|
||||
return currentMembers;
|
||||
}
|
||||
|
||||
public void setCurrentMembers(Integer currentMembers) {
|
||||
this.currentMembers = currentMembers;
|
||||
}
|
||||
|
||||
public Long getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Long status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String getCoverImage() {
|
||||
return coverImage;
|
||||
}
|
||||
|
||||
public void setCoverImage(String coverImage) {
|
||||
this.coverImage = coverImage;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Integer getPointCardAmount() {
|
||||
return pointCardAmount;
|
||||
}
|
||||
|
||||
public void setPointCardAmount(Integer pointCardAmount) {
|
||||
this.pointCardAmount = pointCardAmount;
|
||||
}
|
||||
|
||||
public java.math.BigDecimal getStoredValueAmount() {
|
||||
return storedValueAmount;
|
||||
}
|
||||
|
||||
public void setStoredValueAmount(java.math.BigDecimal storedValueAmount) {
|
||||
this.storedValueAmount = storedValueAmount;
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package cn.novalon.gym.manage.groupcourse.enums;
|
||||
|
||||
/**
|
||||
* 团课状态机事件枚举
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-06-02
|
||||
*/
|
||||
public enum CourseEvent {
|
||||
|
||||
CANCEL("取消课程"),
|
||||
END("结束课程"),
|
||||
START("开始课程");
|
||||
|
||||
private final String desc;
|
||||
|
||||
CourseEvent(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package cn.novalon.gym.manage.groupcourse.enums;
|
||||
|
||||
/**
|
||||
* 团课状态枚举
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-06-02
|
||||
*/
|
||||
public enum CourseStatus {
|
||||
|
||||
NORMAL(0L, "正常"),
|
||||
CANCELLED(1L, "已取消"),
|
||||
ENDED(2L, "已结束"),
|
||||
IN_PROGRESS(3L, "进行中");
|
||||
|
||||
private final Long value;
|
||||
private final String desc;
|
||||
|
||||
CourseStatus(Long value, String desc) {
|
||||
this.value = value;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public Long getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据值获取枚举
|
||||
*/
|
||||
public static CourseStatus fromValue(Long value) {
|
||||
for (CourseStatus status : values()) {
|
||||
if (status.value.equals(value)) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return NORMAL;
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package cn.novalon.gym.manage.groupcourse.event;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* 预约提醒事件
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-06-01
|
||||
*/
|
||||
public class BookingReminderEvent extends ApplicationEvent {
|
||||
|
||||
/**
|
||||
* 消息类型枚举
|
||||
*/
|
||||
public enum ReminderType {
|
||||
BOOKING_SUCCESS, // 预约成功
|
||||
COURSE_REMINDER, // 课程即将开始提醒
|
||||
BOOKING_CANCEL // 预约取消
|
||||
}
|
||||
|
||||
private final Long bookingId;
|
||||
private final Long memberId;
|
||||
private final String courseName;
|
||||
private final String courseTime;
|
||||
private final ReminderType type;
|
||||
|
||||
public BookingReminderEvent(Object source, Long bookingId, Long memberId,
|
||||
String courseName, String courseTime, ReminderType type) {
|
||||
super(source);
|
||||
this.bookingId = bookingId;
|
||||
this.memberId = memberId;
|
||||
this.courseName = courseName;
|
||||
this.courseTime = courseTime;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Long getBookingId() {
|
||||
return bookingId;
|
||||
}
|
||||
|
||||
public Long getMemberId() {
|
||||
return memberId;
|
||||
}
|
||||
|
||||
public String getCourseName() {
|
||||
return courseName;
|
||||
}
|
||||
|
||||
public String getCourseTime() {
|
||||
return courseTime;
|
||||
}
|
||||
|
||||
public ReminderType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
package cn.novalon.gym.manage.groupcourse.event;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.event.BookingReminderEvent.ReminderType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 预约提醒事件监听器
|
||||
*
|
||||
* 监听预约相关事件,处理提醒业务
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-06-01
|
||||
*/
|
||||
@Component
|
||||
public class BookingReminderEventListener {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BookingReminderEventListener.class);
|
||||
|
||||
/**
|
||||
* 处理预约提醒事件
|
||||
*
|
||||
* @param event 预约提醒事件
|
||||
*/
|
||||
@EventListener
|
||||
public void handleBookingReminderEvent(BookingReminderEvent event) {
|
||||
logger.info("收到预约提醒事件:type={}, bookingId={}, memberId={}",
|
||||
event.getType(), event.getBookingId(), event.getMemberId());
|
||||
|
||||
try {
|
||||
processReminderEvent(event);
|
||||
} catch (Exception e) {
|
||||
logger.error("处理预约提醒事件失败:bookingId={}, error={}",
|
||||
event.getBookingId(), e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理提醒事件
|
||||
*
|
||||
* 根据事件类型执行不同的提醒逻辑
|
||||
*/
|
||||
private void processReminderEvent(BookingReminderEvent event) {
|
||||
switch (event.getType()) {
|
||||
case BOOKING_SUCCESS:
|
||||
handleBookingSuccess(event);
|
||||
break;
|
||||
case COURSE_REMINDER:
|
||||
handleCourseReminder(event);
|
||||
break;
|
||||
case BOOKING_CANCEL:
|
||||
handleBookingCancel(event);
|
||||
break;
|
||||
default:
|
||||
logger.warn("未知的提醒事件类型:{}", event.getType());
|
||||
}
|
||||
|
||||
logger.info("预约提醒事件处理完成:bookingId={}", event.getBookingId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理预约成功事件
|
||||
*/
|
||||
private void handleBookingSuccess(BookingReminderEvent event) {
|
||||
logger.info("处理预约成功提醒:会员ID={}, 课程={}, 时间={}",
|
||||
event.getMemberId(), event.getCourseName(), event.getCourseTime());
|
||||
|
||||
// 实际业务中会调用通知服务发送短信、APP推送等
|
||||
// sendNotification(event.getMemberId(), "预约成功",
|
||||
// "您已成功预约课程:" + event.getCourseName() + ",时间:" + event.getCourseTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理课程即将开始提醒事件
|
||||
*/
|
||||
private void handleCourseReminder(BookingReminderEvent event) {
|
||||
logger.info("处理课程提醒:会员ID={}, 课程={}, 时间={}",
|
||||
event.getMemberId(), event.getCourseName(), event.getCourseTime());
|
||||
|
||||
// 实际业务中会调用通知服务发送课程开始前提醒
|
||||
// sendNotification(event.getMemberId(), "课程提醒",
|
||||
// "您预约的课程" + event.getCourseName() + "即将开始,时间:" + event.getCourseTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理预约取消事件
|
||||
*/
|
||||
private void handleBookingCancel(BookingReminderEvent event) {
|
||||
logger.info("处理预约取消提醒:会员ID={}, 课程={}",
|
||||
event.getMemberId(), event.getCourseName());
|
||||
|
||||
// 实际业务中会调用通知服务发送预约取消通知
|
||||
// sendNotification(event.getMemberId(), "预约取消",
|
||||
// "您已取消课程:" + event.getCourseName() + "的预约");
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package cn.novalon.gym.manage.groupcourse.event;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.event.BookingReminderEvent.ReminderType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 预约提醒事件发布器
|
||||
*
|
||||
* 使用Spring事件机制发布预约相关事件
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-06-01
|
||||
*/
|
||||
@Component
|
||||
public class BookingReminderEventPublisher {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BookingReminderEventPublisher.class);
|
||||
|
||||
private final ApplicationEventPublisher eventPublisher;
|
||||
|
||||
public BookingReminderEventPublisher(ApplicationEventPublisher eventPublisher) {
|
||||
this.eventPublisher = eventPublisher;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布预约成功事件
|
||||
*
|
||||
* @param bookingId 预约ID
|
||||
* @param memberId 会员ID
|
||||
* @param courseName 课程名称
|
||||
* @param courseTime 课程时间
|
||||
*/
|
||||
public void publishBookingSuccessEvent(Long bookingId, Long memberId, String courseName, String courseTime) {
|
||||
BookingReminderEvent event = new BookingReminderEvent(
|
||||
this, bookingId, memberId, courseName, courseTime, ReminderType.BOOKING_SUCCESS);
|
||||
|
||||
logger.info("发布预约成功事件:bookingId={}, memberId={}", bookingId, memberId);
|
||||
eventPublisher.publishEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布课程即将开始提醒事件
|
||||
*
|
||||
* @param bookingId 预约ID
|
||||
* @param memberId 会员ID
|
||||
* @param courseName 课程名称
|
||||
* @param courseTime 课程时间
|
||||
*/
|
||||
public void publishCourseReminderEvent(Long bookingId, Long memberId, String courseName, String courseTime) {
|
||||
BookingReminderEvent event = new BookingReminderEvent(
|
||||
this, bookingId, memberId, courseName, courseTime, ReminderType.COURSE_REMINDER);
|
||||
|
||||
logger.info("发布课程提醒事件:bookingId={}, memberId={}", bookingId, memberId);
|
||||
eventPublisher.publishEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布预约取消事件
|
||||
*
|
||||
* @param bookingId 预约ID
|
||||
* @param memberId 会员ID
|
||||
* @param courseName 课程名称
|
||||
*/
|
||||
public void publishBookingCancelEvent(Long bookingId, Long memberId, String courseName) {
|
||||
BookingReminderEvent event = new BookingReminderEvent(
|
||||
this, bookingId, memberId, courseName, null, ReminderType.BOOKING_CANCEL);
|
||||
|
||||
logger.info("发布预约取消事件:bookingId={}, memberId={}", bookingId, memberId);
|
||||
eventPublisher.publishEvent(event);
|
||||
}
|
||||
}
|
||||
+369
@@ -0,0 +1,369 @@
|
||||
package cn.novalon.gym.manage.groupcourse.handler;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourseBooking;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseBookingRepository;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseRepository;
|
||||
import cn.novalon.gym.manage.groupcourse.service.impl.GroupCourseRedisService;
|
||||
import cn.novalon.gym.manage.member.entity.MemberCard;
|
||||
import cn.novalon.gym.manage.member.entity.MemberCardRecord;
|
||||
import cn.novalon.gym.manage.member.enums.MemberCardType;
|
||||
import cn.novalon.gym.manage.member.repository.MemberCardRepository;
|
||||
import cn.novalon.gym.manage.member.service.IMemberCardRecordService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 预约 Saga 处理器
|
||||
*
|
||||
* 实现预约和取消预约的分布式事务处理
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-06-02
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class BookingSagaHandler {
|
||||
|
||||
private final IGroupCourseBookingRepository bookingRepository;
|
||||
private final IGroupCourseRepository courseRepository;
|
||||
private final IMemberCardRecordService memberCardRecordService;
|
||||
private final MemberCardRepository memberCardRepository;
|
||||
private final GroupCourseRedisService redisService;
|
||||
|
||||
private static final double DEFAULT_GROUP_COURSE_PRICE = 50.0;
|
||||
|
||||
/**
|
||||
* 执行预约事务
|
||||
*
|
||||
* 步骤:
|
||||
* 1. 保存预约记录
|
||||
* 2. 扣减会员卡权益
|
||||
* 3. 更新课程当前人数
|
||||
*/
|
||||
public Mono<GroupCourseBooking> executeBooking(GroupCourseBooking booking, Long recordId) {
|
||||
List<SagaStep> steps = new ArrayList<>();
|
||||
List<SagaStep> rollbackSteps = new ArrayList<>();
|
||||
|
||||
// 步骤1:保存预约记录
|
||||
SagaStep step1 = new SagaStep(
|
||||
"保存预约记录",
|
||||
saveBooking(booking),
|
||||
Mono.defer(() -> deleteBooking(booking.getId()))
|
||||
);
|
||||
steps.add(step1);
|
||||
rollbackSteps.add(0, step1);
|
||||
|
||||
// 步骤2:扣减会员卡权益(根据卡类型决定扣除次数还是金额)
|
||||
SagaStep step2 = new SagaStep(
|
||||
"扣减会员卡权益",
|
||||
deductCardUsageByCardType(booking.getMemberId(), recordId),
|
||||
Mono.defer(() -> restoreCardUsageByCardType(booking.getMemberId(), recordId))
|
||||
);
|
||||
steps.add(step2);
|
||||
rollbackSteps.add(0, step2);
|
||||
|
||||
// 步骤3:更新课程当前人数
|
||||
SagaStep step3 = new SagaStep(
|
||||
"更新课程当前人数",
|
||||
incrementCourseCurrentMembers(booking.getCourseId()),
|
||||
Mono.defer(() -> decrementCourseCurrentMembers(booking.getCourseId()))
|
||||
);
|
||||
steps.add(step3);
|
||||
rollbackSteps.add(0, step3);
|
||||
|
||||
// 步骤4:更新Redis预约计数
|
||||
SagaStep step4 = new SagaStep(
|
||||
"更新Redis预约计数",
|
||||
incrementRedisBookingCount(booking.getCourseId()),
|
||||
Mono.defer(() -> decrementRedisBookingCount(booking.getCourseId()))
|
||||
);
|
||||
steps.add(step4);
|
||||
rollbackSteps.add(0, step4);
|
||||
|
||||
return executeSaga(steps, rollbackSteps)
|
||||
.then(Mono.just(booking));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据会员卡类型扣减权益
|
||||
*/
|
||||
private Mono<Void> deductCardUsageByCardType(Long memberId, Long recordId) {
|
||||
return memberCardRecordService.findById(recordId)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("会员卡记录不存在")))
|
||||
.flatMap(record -> {
|
||||
// 验证会员卡归属
|
||||
if (!record.getMemberId().equals(memberId)) {
|
||||
return Mono.error(new RuntimeException("会员卡不归属当前用户"));
|
||||
}
|
||||
|
||||
return memberCardRepository.findById(record.getMemberCardId())
|
||||
.flatMap(card -> {
|
||||
MemberCardType cardType = MemberCardType.valueOf(card.getMemberCardType());
|
||||
|
||||
switch (cardType) {
|
||||
case COUNT_CARD:
|
||||
// 次卡扣除次数
|
||||
return deductCardUsage(recordId, 1, 0.0);
|
||||
case STORED_VALUE_CARD:
|
||||
// 储值卡扣除金额
|
||||
return deductCardUsage(recordId, 0, DEFAULT_GROUP_COURSE_PRICE);
|
||||
case TIME_CARD:
|
||||
// 时长卡不扣除,但需验证有效期
|
||||
return validateTimeCard(record);
|
||||
default:
|
||||
return Mono.error(new RuntimeException("不支持的会员卡类型: " + cardType));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证时长卡有效期
|
||||
*
|
||||
* @param record 会员卡记录
|
||||
* @return 验证通过返回Mono.empty(),否则返回Mono.error()
|
||||
*/
|
||||
private Mono<Void> validateTimeCard(MemberCardRecord record) {
|
||||
// 验证会员卡状态
|
||||
cn.novalon.gym.manage.member.enums.MemberCardRecordStatus status = record.getStatus();
|
||||
if (status != cn.novalon.gym.manage.member.enums.MemberCardRecordStatus.ACTIVE) {
|
||||
return Mono.error(new RuntimeException("会员卡状态无效,当前状态: " + (status != null ? status.getDesc() : "未知")));
|
||||
}
|
||||
|
||||
// 验证有效期
|
||||
java.time.LocalDateTime expireTime = record.getExpireTime();
|
||||
if (expireTime == null) {
|
||||
return Mono.error(new RuntimeException("会员卡有效期未设置"));
|
||||
}
|
||||
if (expireTime.isBefore(java.time.LocalDateTime.now())) {
|
||||
return Mono.error(new RuntimeException("会员卡已过期,有效期至: " + expireTime));
|
||||
}
|
||||
|
||||
log.debug("时长卡验证通过: recordId={}, expireTime={}", record.getId(), expireTime);
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据会员卡类型恢复权益
|
||||
*/
|
||||
private Mono<Void> restoreCardUsageByCardType(Long memberId, Long recordId) {
|
||||
return memberCardRecordService.findById(recordId)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("会员卡记录不存在,无法恢复权益")))
|
||||
.flatMap(record -> {
|
||||
// 验证会员卡归属(memberId为null时跳过验证)
|
||||
if (memberId != null && !record.getMemberId().equals(memberId)) {
|
||||
return Mono.error(new RuntimeException("会员卡不归属当前用户"));
|
||||
}
|
||||
|
||||
return memberCardRepository.findById(record.getMemberCardId())
|
||||
.flatMap(card -> {
|
||||
MemberCardType cardType = MemberCardType.valueOf(card.getMemberCardType());
|
||||
|
||||
switch (cardType) {
|
||||
case COUNT_CARD:
|
||||
return restoreCardUsage(recordId, 1, 0.0);
|
||||
case STORED_VALUE_CARD:
|
||||
return restoreCardUsage(recordId, 0, DEFAULT_GROUP_COURSE_PRICE);
|
||||
case TIME_CARD:
|
||||
return Mono.empty();
|
||||
default:
|
||||
return Mono.error(new RuntimeException("不支持的会员卡类型: " + cardType));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行取消预约事务
|
||||
*/
|
||||
public Mono<GroupCourseBooking> executeCancelBooking(Long bookingId, Long courseId, Long recordId, Long memberId) {
|
||||
List<SagaStep> steps = new ArrayList<>();
|
||||
List<SagaStep> rollbackSteps = new ArrayList<>();
|
||||
|
||||
// 步骤1:更新预约状态为已取消
|
||||
SagaStep step1 = new SagaStep(
|
||||
"更新预约状态为已取消",
|
||||
updateBookingStatus(bookingId, "1"),
|
||||
Mono.defer(() -> updateBookingStatus(bookingId, "0"))
|
||||
);
|
||||
steps.add(step1);
|
||||
rollbackSteps.add(0, step1);
|
||||
|
||||
// 步骤2:恢复会员卡权益
|
||||
SagaStep step2 = new SagaStep(
|
||||
"恢复会员卡权益",
|
||||
restoreCardUsageByCardType(memberId, recordId),
|
||||
Mono.defer(() -> deductCardUsageByCardType(memberId, recordId))
|
||||
);
|
||||
steps.add(step2);
|
||||
rollbackSteps.add(0, step2);
|
||||
|
||||
// 步骤3:减少课程当前人数
|
||||
SagaStep step3 = new SagaStep(
|
||||
"减少课程当前人数",
|
||||
decrementCourseCurrentMembers(courseId),
|
||||
Mono.defer(() -> incrementCourseCurrentMembers(courseId))
|
||||
);
|
||||
steps.add(step3);
|
||||
rollbackSteps.add(0, step3);
|
||||
|
||||
// 步骤4:更新Redis预约计数
|
||||
SagaStep step4 = new SagaStep(
|
||||
"更新Redis预约计数",
|
||||
decrementRedisBookingCount(courseId),
|
||||
Mono.defer(() -> incrementRedisBookingCount(courseId))
|
||||
);
|
||||
steps.add(step4);
|
||||
rollbackSteps.add(0, step4);
|
||||
|
||||
return executeSaga(steps, rollbackSteps)
|
||||
.then(bookingRepository.findById(bookingId));
|
||||
}
|
||||
|
||||
private Mono<Void> updateBookingStatus(Long bookingId, String status) {
|
||||
return bookingRepository.updateStatus(bookingId, status)
|
||||
.flatMap(rows -> {
|
||||
if (rows == 0) {
|
||||
return Mono.error(new RuntimeException("更新预约状态失败"));
|
||||
}
|
||||
return Mono.empty();
|
||||
});
|
||||
}
|
||||
|
||||
private Mono<Void> saveBooking(GroupCourseBooking booking) {
|
||||
return bookingRepository.save(booking)
|
||||
.flatMap(saved -> {
|
||||
if (saved.getId() == null) {
|
||||
return Mono.error(new RuntimeException("保存预约记录失败"));
|
||||
}
|
||||
booking.setId(saved.getId());
|
||||
return Mono.empty();
|
||||
});
|
||||
}
|
||||
|
||||
private Mono<Void> deleteBooking(Long bookingId) {
|
||||
return bookingRepository.deleteById(bookingId);
|
||||
}
|
||||
|
||||
private Mono<Void> deductCardUsage(Long recordId, Integer deductTimes, Double deductAmount) {
|
||||
if (deductTimes == 0 && deductAmount == 0.0) {
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
return memberCardRecordService.findById(recordId)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("会员卡记录不存在")))
|
||||
.flatMap(record -> {
|
||||
cn.novalon.gym.manage.member.enums.MemberCardRecordStatus status = record.getStatus();
|
||||
if (status != cn.novalon.gym.manage.member.enums.MemberCardRecordStatus.ACTIVE) {
|
||||
return Mono.error(new RuntimeException("会员卡状态无效,当前状态: " + (status != null ? status.getDesc() : "未知")));
|
||||
}
|
||||
java.time.LocalDateTime expireTime = record.getExpireTime();
|
||||
if (expireTime != null && expireTime.isBefore(java.time.LocalDateTime.now())) {
|
||||
return Mono.error(new RuntimeException("会员卡已过期"));
|
||||
}
|
||||
if (record.getRemainingTimes() != null && deductTimes > 0 && record.getRemainingTimes() < deductTimes) {
|
||||
return Mono.error(new RuntimeException("会员卡剩余次数不足,当前剩余: " + record.getRemainingTimes() + "次"));
|
||||
}
|
||||
if (record.getRemainingAmount() != null && deductAmount > 0 && record.getRemainingAmount() < deductAmount) {
|
||||
return Mono.error(new RuntimeException("会员卡余额不足,当前剩余: " + record.getRemainingAmount()));
|
||||
}
|
||||
return memberCardRecordService.deductUsage(recordId, deductTimes, deductAmount)
|
||||
.flatMap(rows -> {
|
||||
if (rows == 0) {
|
||||
return Mono.error(new RuntimeException("扣减会员卡权益失败,请重试"));
|
||||
}
|
||||
return Mono.empty();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private Mono<Void> restoreCardUsage(Long recordId, Integer addTimes, Double addAmount) {
|
||||
if (addTimes == 0 && addAmount == 0.0) {
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
return memberCardRecordService.findById(recordId)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("会员卡记录不存在,无法恢复权益")))
|
||||
.flatMap(record -> {
|
||||
// 使用当前记录的过期时间,避免清空过期时间
|
||||
return memberCardRecordService.renewCard(recordId, addTimes, addAmount, record.getExpireTime())
|
||||
.flatMap(rows -> {
|
||||
if (rows == 0) {
|
||||
return Mono.error(new RuntimeException("恢复会员卡权益失败,请重试"));
|
||||
}
|
||||
return Mono.empty();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private Mono<Void> incrementCourseCurrentMembers(Long courseId) {
|
||||
return courseRepository.updateCurrentMembers(courseId, 1).then();
|
||||
}
|
||||
|
||||
private Mono<Void> decrementCourseCurrentMembers(Long courseId) {
|
||||
return courseRepository.updateCurrentMembers(courseId, -1).then();
|
||||
}
|
||||
|
||||
private Mono<Void> incrementRedisBookingCount(Long courseId) {
|
||||
return redisService.incrementBookingCount(courseId).then();
|
||||
}
|
||||
|
||||
private Mono<Void> decrementRedisBookingCount(Long courseId) {
|
||||
return redisService.decrementBookingCount(courseId).then();
|
||||
}
|
||||
|
||||
private Mono<Void> executeSaga(List<SagaStep> steps, List<SagaStep> rollbackSteps) {
|
||||
List<SagaStep> completedSteps = new ArrayList<>();
|
||||
return executeStep(steps, 0, completedSteps);
|
||||
}
|
||||
|
||||
private Mono<Void> executeStep(List<SagaStep> steps, int index, List<SagaStep> completedSteps) {
|
||||
if (index >= steps.size()) {
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
SagaStep currentStep = steps.get(index);
|
||||
|
||||
return currentStep.operation()
|
||||
.doOnSuccess(unused -> completedSteps.add(currentStep))
|
||||
.then(Mono.defer(() -> executeStep(steps, index + 1, completedSteps)))
|
||||
.onErrorResume(error -> {
|
||||
log.error("Saga步骤执行失败: step={}, error={}", currentStep.description(), error.getMessage());
|
||||
return rollbackCompletedSteps(completedSteps).then(Mono.error(error));
|
||||
});
|
||||
}
|
||||
|
||||
private Mono<Void> rollbackCompletedSteps(List<SagaStep> completedSteps) {
|
||||
if (completedSteps.isEmpty()) {
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
// 反转已完成的步骤,按逆序回滚
|
||||
List<SagaStep> reversed = new ArrayList<>(completedSteps);
|
||||
Collections.reverse(reversed);
|
||||
|
||||
return rollbackSteps(reversed, 0);
|
||||
}
|
||||
|
||||
private Mono<Void> rollbackSteps(List<SagaStep> rollbackSteps, int index) {
|
||||
if (index >= rollbackSteps.size()) {
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
SagaStep currentStep = rollbackSteps.get(index);
|
||||
|
||||
return currentStep.rollbackOperation()
|
||||
.then(Mono.defer(() -> rollbackSteps(rollbackSteps, index + 1)))
|
||||
.doOnError(error -> log.error("Saga回滚失败: step={}, error={}", currentStep.description(), error.getMessage()))
|
||||
.onErrorResume(e -> Mono.empty());
|
||||
}
|
||||
|
||||
private record SagaStep(String description, Mono<Void> operation, Mono<Void> rollbackOperation) {}
|
||||
}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
package cn.novalon.gym.manage.groupcourse.handler;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourseBooking;
|
||||
import cn.novalon.gym.manage.groupcourse.service.IGroupCourseBookingService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
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.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 团课预约Handler
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-06-01
|
||||
*/
|
||||
@Component
|
||||
@Tag(name = "团课预约", description = "团课预约相关操作")
|
||||
public class GroupCourseBookingHandler {
|
||||
|
||||
private final IGroupCourseBookingService bookingService;
|
||||
|
||||
public GroupCourseBookingHandler(IGroupCourseBookingService bookingService) {
|
||||
this.bookingService = bookingService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 预约团课
|
||||
*/
|
||||
@Operation(summary = "预约团课", description = "会员预约指定团课")
|
||||
public Mono<ServerResponse> bookCourse(ServerRequest request) {
|
||||
return request.bodyToMono(Map.class)
|
||||
.flatMap(body -> {
|
||||
// 验证必填参数
|
||||
if (body.get("courseId") == null) {
|
||||
return buildErrorResponse("请提供课程ID");
|
||||
}
|
||||
if (body.get("memberId") == null) {
|
||||
return buildErrorResponse("请提供会员ID");
|
||||
}
|
||||
if (body.get("memberCardRecordId") == null) {
|
||||
return buildErrorResponse("请提供会员卡记录ID");
|
||||
}
|
||||
|
||||
Long courseId = ((Number) body.get("courseId")).longValue();
|
||||
Long memberId = ((Number) body.get("memberId")).longValue();
|
||||
Long memberCardRecordId = ((Number) body.get("memberCardRecordId")).longValue();
|
||||
|
||||
return bookingService.bookCourse(courseId, memberId, memberCardRecordId)
|
||||
.flatMap(booking -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "预约成功");
|
||||
response.put("data", booking);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消预约
|
||||
*/
|
||||
@Operation(summary = "取消预约", description = "会员取消已预约的团课")
|
||||
public Mono<ServerResponse> cancelBooking(ServerRequest request) {
|
||||
Long bookingId = Long.valueOf(request.pathVariable("bookingId"));
|
||||
|
||||
return request.bodyToMono(Map.class)
|
||||
.flatMap(body -> {
|
||||
Long memberId = ((Number) body.get("memberId")).longValue();
|
||||
|
||||
return bookingService.cancelBooking(bookingId, memberId)
|
||||
.flatMap(booking -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "取消成功");
|
||||
response.put("data", booking);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询会员预约记录
|
||||
*/
|
||||
@Operation(summary = "查询会员预约记录", description = "根据会员ID查询所有预约记录")
|
||||
public Mono<ServerResponse> getBookingsByMemberId(ServerRequest request) {
|
||||
Long memberId = Long.valueOf(request.pathVariable("memberId"));
|
||||
|
||||
return ServerResponse.ok()
|
||||
.body(bookingService.getBookingsByMemberId(memberId), GroupCourseBooking.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询预约详情
|
||||
*/
|
||||
@Operation(summary = "查询预约详情", description = "根据预约ID查询预约详情")
|
||||
public Mono<ServerResponse> getBookingById(ServerRequest request) {
|
||||
Long bookingId = Long.valueOf(request.pathVariable("bookingId"));
|
||||
|
||||
return bookingService.getBookingById(bookingId)
|
||||
.flatMap(booking -> ServerResponse.ok().bodyValue(booking))
|
||||
.switchIfEmpty(ServerResponse.notFound().build());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询课程预约记录
|
||||
*/
|
||||
@Operation(summary = "查询课程预约记录", description = "根据团课ID查询所有预约记录")
|
||||
public Mono<ServerResponse> getBookingsByCourseId(ServerRequest request) {
|
||||
Long courseId = Long.valueOf(request.pathVariable("courseId"));
|
||||
|
||||
return ServerResponse.ok()
|
||||
.body(bookingService.getBookingsByCourseId(courseId), GroupCourseBooking.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建错误响应
|
||||
*/
|
||||
private Mono<ServerResponse> buildErrorResponse(String message) {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", message);
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
}
|
||||
}
|
||||
+261
@@ -0,0 +1,261 @@
|
||||
|
||||
package cn.novalon.gym.manage.groupcourse.handler;
|
||||
|
||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||
import cn.novalon.gym.manage.common.util.RedisUtil;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||
import cn.novalon.gym.manage.groupcourse.service.IGroupCourseService;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Validator;
|
||||
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.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
@Tag(name="团课管理",description = "团课相关操作")
|
||||
public class GroupCourseHandler {
|
||||
private final IGroupCourseService groupCourseService;
|
||||
private final Validator validator;
|
||||
private final RedisUtil redisUtil;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public GroupCourseHandler(IGroupCourseService groupCourseService,
|
||||
Validator validator,
|
||||
RedisUtil redisUtil,
|
||||
ObjectMapper objectMapper){
|
||||
this.groupCourseService = groupCourseService;
|
||||
this.validator = validator;
|
||||
this.redisUtil = redisUtil;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有团课", description = "获取系统中所有团课列表")
|
||||
public Mono<ServerResponse> getAllGroupCourse(ServerRequest request){
|
||||
boolean includeDeleted = Boolean.valueOf(request.queryParam("includeDeleted").orElse("false"));
|
||||
return ServerResponse.ok()
|
||||
.body(groupCourseService.findAll(includeDeleted), GroupCourse.class);
|
||||
}
|
||||
|
||||
@Operation(summary = "分页获取团课", description = "根据分页参数获取团课列表")
|
||||
public Mono<ServerResponse> getGroupCoursesByPage(ServerRequest request) {
|
||||
return request.bodyToMono(PageRequest.class)
|
||||
.flatMap(pageRequest -> {
|
||||
boolean includeDeleted = request.queryParam("includeDeleted")
|
||||
.map(Boolean::parseBoolean)
|
||||
.orElse(false);
|
||||
|
||||
if (pageRequest.getPage() < 0) {
|
||||
pageRequest.setPage(0);
|
||||
}
|
||||
if (pageRequest.getSize() <= 0 || pageRequest.getSize() > 100) {
|
||||
pageRequest.setSize(10);
|
||||
}
|
||||
if (pageRequest.getSort() == null || pageRequest.getSort().isEmpty()) {
|
||||
pageRequest.setSort("id");
|
||||
}
|
||||
if (pageRequest.getOrder() == null || pageRequest.getOrder().isEmpty()) {
|
||||
pageRequest.setOrder("asc");
|
||||
}
|
||||
|
||||
return groupCourseService.findByPage(pageRequest, includeDeleted)
|
||||
.flatMap(response -> ServerResponse.ok().bodyValue(response));
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "根据ID获取团课", description = "根据ID获取团课详情")
|
||||
public Mono<ServerResponse> getGroupCourseById(ServerRequest request){
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
return groupCourseService.findById(id)
|
||||
.flatMap(course -> ServerResponse.ok().bodyValue(course))
|
||||
.switchIfEmpty(ServerResponse.notFound().build());
|
||||
}
|
||||
|
||||
@Operation(summary = "创建团课", description = "创建新的团课")
|
||||
public Mono<ServerResponse> createGroupCourse(ServerRequest request) {
|
||||
return request.bodyToMono(GroupCourse.class)
|
||||
.flatMap(groupCourse -> {
|
||||
if (groupCourse.getCourseName() == null || groupCourse.getCourseName().isEmpty()) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "课程名称不能为空");
|
||||
return ServerResponse.badRequest().bodyValue(error);
|
||||
}
|
||||
|
||||
return groupCourseService.create(groupCourse)
|
||||
.flatMap(course -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "团课创建成功");
|
||||
response.put("data", course);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "更新团课", description = "更新指定团课信息")
|
||||
public Mono<ServerResponse> updateGroupCourse(ServerRequest request) {
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
|
||||
return request.bodyToMono(GroupCourse.class)
|
||||
.flatMap(groupCourse -> {
|
||||
return groupCourseService.update(id, groupCourse)
|
||||
.flatMap(course -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "团课更新成功");
|
||||
response.put("data", course);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "取消团课", description = "取消指定团课(需提前24小时)")
|
||||
public Mono<ServerResponse> cancelGroupCourse(ServerRequest request) {
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
|
||||
return groupCourseService.cancel(id)
|
||||
.flatMap(course -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "团课取消成功");
|
||||
response.put("data", course);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "团课签到", description = "会员签到参加团课")
|
||||
public Mono<ServerResponse> signIn(ServerRequest request) {
|
||||
Long courseId = Long.valueOf(request.pathVariable("courseId"));
|
||||
|
||||
return request.bodyToMono(Map.class)
|
||||
.flatMap(body -> {
|
||||
if (body == null || body.isEmpty()) {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", "请求体不能为空");
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
}
|
||||
|
||||
Object memberIdObj = body.get("memberId");
|
||||
if (memberIdObj == null) {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", "memberId不能为空");
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
}
|
||||
|
||||
Long memberId = ((Number) memberIdObj).longValue();
|
||||
|
||||
return groupCourseService.signIn(courseId, memberId)
|
||||
.flatMap(course -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "签到成功");
|
||||
response.put("data", course);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "删除团课", description = "删除指定团课(软删除)")
|
||||
public Mono<ServerResponse> deleteGroupCourse(ServerRequest request) {
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
|
||||
return groupCourseService.delete(id)
|
||||
.then(Mono.defer(() -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "团课删除成功");
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
}))
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "测试-根据Key获取Redis缓存", description = "测试接口:根据传入的key值获取Redis中缓存的数据")
|
||||
public Mono<ServerResponse> getCacheByKey(ServerRequest request) {
|
||||
return request.bodyToMono(Map.class)
|
||||
.flatMap(body -> {
|
||||
String key = (String) body.get("key");
|
||||
|
||||
if (key == null || key.isEmpty()) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "key参数不能为空");
|
||||
return ServerResponse.badRequest().bodyValue(error);
|
||||
}
|
||||
|
||||
return redisUtil.get(key)
|
||||
.map(cachedValue -> {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
if (cachedValue != null) {
|
||||
result.put("success", true);
|
||||
result.put("key", key);
|
||||
result.put("value", cachedValue);
|
||||
result.put("message", "缓存命中");
|
||||
|
||||
try {
|
||||
if (cachedValue instanceof String) {
|
||||
Object jsonObject = objectMapper.readValue((String) cachedValue, Object.class);
|
||||
result.put("parsedValue", jsonObject);
|
||||
result.put("valueType", "JSON字符串");
|
||||
} else {
|
||||
result.put("valueType", cachedValue.getClass().getSimpleName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("parsedValue", null);
|
||||
result.put("valueType", "无法解析");
|
||||
}
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("key", key);
|
||||
result.put("value", null);
|
||||
result.put("message", "缓存未命中");
|
||||
}
|
||||
|
||||
return result;
|
||||
})
|
||||
.flatMap(result -> ServerResponse.ok().bodyValue(result))
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> errorResponse = new HashMap<>();
|
||||
errorResponse.put("success", false);
|
||||
errorResponse.put("message", "请求处理失败: " + error.getMessage());
|
||||
return ServerResponse.status(500).bodyValue(errorResponse);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
package cn.novalon.gym.manage.groupcourse.handler;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||
import cn.novalon.gym.manage.groupcourse.enums.CourseEvent;
|
||||
import cn.novalon.gym.manage.groupcourse.enums.CourseStatus;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 团课状态机处理器
|
||||
*
|
||||
* 管理团课的状态转换逻辑
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-06-02
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class GroupCourseStateMachine {
|
||||
|
||||
private final Map<CourseStatus, Map<CourseEvent, CourseStatus>> stateTransitionMap;
|
||||
|
||||
public GroupCourseStateMachine() {
|
||||
this.stateTransitionMap = buildStateTransitionMap();
|
||||
}
|
||||
|
||||
private Map<CourseStatus, Map<CourseEvent, CourseStatus>> buildStateTransitionMap() {
|
||||
Map<CourseStatus, Map<CourseEvent, CourseStatus>> map = new HashMap<>();
|
||||
|
||||
// NORMAL 状态可以转换的事件
|
||||
Map<CourseEvent, CourseStatus> normalTransitions = new HashMap<>();
|
||||
normalTransitions.put(CourseEvent.CANCEL, CourseStatus.CANCELLED);
|
||||
normalTransitions.put(CourseEvent.END, CourseStatus.ENDED);
|
||||
normalTransitions.put(CourseEvent.START, CourseStatus.IN_PROGRESS);
|
||||
map.put(CourseStatus.NORMAL, normalTransitions);
|
||||
|
||||
// IN_PROGRESS 状态可以转换的事件
|
||||
Map<CourseEvent, CourseStatus> inProgressTransitions = new HashMap<>();
|
||||
inProgressTransitions.put(CourseEvent.END, CourseStatus.ENDED);
|
||||
map.put(CourseStatus.IN_PROGRESS, inProgressTransitions);
|
||||
|
||||
// CANCELLED 状态是终态,不允许任何转换
|
||||
|
||||
// ENDED 状态是终态,不允许任何转换
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否可以转换状态
|
||||
*/
|
||||
public Mono<Boolean> canTransition(CourseStatus currentState, CourseEvent event) {
|
||||
return Mono.fromSupplier(() -> {
|
||||
Map<CourseEvent, CourseStatus> transitions = stateTransitionMap.get(currentState);
|
||||
if (transitions == null) {
|
||||
return false;
|
||||
}
|
||||
return transitions.containsKey(event);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行状态转换
|
||||
*/
|
||||
public Mono<CourseStatus> transition(CourseStatus currentState, CourseEvent event) {
|
||||
return Mono.fromSupplier(() -> {
|
||||
Map<CourseEvent, CourseStatus> transitions = stateTransitionMap.get(currentState);
|
||||
if (transitions == null || !transitions.containsKey(event)) {
|
||||
log.error("Invalid state transition: currentState={}, event={}", currentState, event);
|
||||
throw new IllegalStateException(
|
||||
String.format("不允许的状态转换: 当前状态=%s, 事件=%s", currentState, event));
|
||||
}
|
||||
CourseStatus newState = transitions.get(event);
|
||||
log.info("State transition: {} --({})--> {}", currentState, event, newState);
|
||||
return newState;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证状态转换是否允许
|
||||
*/
|
||||
public Mono<Void> validateTransition(GroupCourse course, CourseEvent event) {
|
||||
Long statusValue = course.getStatus();
|
||||
CourseStatus currentState = CourseStatus.fromValue(statusValue != null ? statusValue : 0L);
|
||||
|
||||
return canTransition(currentState, event)
|
||||
.flatMap(canTransition -> {
|
||||
if (!canTransition) {
|
||||
String errorMessage = buildErrorMessage(course.getId(), currentState, event);
|
||||
return Mono.error(new IllegalStateException(errorMessage));
|
||||
}
|
||||
return Mono.empty();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建状态转换错误信息
|
||||
*/
|
||||
private String buildErrorMessage(Long courseId, CourseStatus currentState, CourseEvent event) {
|
||||
String currentStateDesc = currentState.getDesc();
|
||||
String eventDesc = event.getDesc();
|
||||
|
||||
String advice = "";
|
||||
switch (currentState) {
|
||||
case CANCELLED:
|
||||
advice = "(课程已取消,无法进行此操作)";
|
||||
break;
|
||||
case ENDED:
|
||||
advice = "(课程已结束,无法进行此操作)";
|
||||
break;
|
||||
case IN_PROGRESS:
|
||||
if (event == CourseEvent.CANCEL) {
|
||||
advice = "(课程正在进行中,无法取消)";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return String.format("团课ID=%d 不允许的状态转换: 当前状态=%s(%s), 操作=%s%s",
|
||||
courseId, currentState, currentStateDesc, eventDesc, advice);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行状态转换并更新课程对象
|
||||
*/
|
||||
public Mono<GroupCourse> applyTransition(GroupCourse course, CourseEvent event) {
|
||||
return validateTransition(course, event)
|
||||
.then(transition(CourseStatus.fromValue(course.getStatus()), event))
|
||||
.map(newStatus -> {
|
||||
course.setStatus(newStatus.getValue());
|
||||
return course;
|
||||
});
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
package cn.novalon.gym.manage.groupcourse.repository;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourseBooking;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* 团课预约记录Repository接口
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-06-01
|
||||
*/
|
||||
public interface IGroupCourseBookingRepository {
|
||||
|
||||
/**
|
||||
* 根据ID查询预约记录
|
||||
*/
|
||||
Mono<GroupCourseBooking> findById(Long id);
|
||||
|
||||
/**
|
||||
* 根据会员ID查询预约记录列表
|
||||
*/
|
||||
Flux<GroupCourseBooking> findByMemberId(Long memberId);
|
||||
|
||||
/**
|
||||
* 根据团课ID查询预约记录列表
|
||||
*/
|
||||
Flux<GroupCourseBooking> findByCourseId(Long courseId);
|
||||
|
||||
/**
|
||||
* 查询会员是否已预约某课程
|
||||
*/
|
||||
Mono<GroupCourseBooking> findByCourseIdAndMemberId(Long courseId, Long memberId);
|
||||
|
||||
/**
|
||||
* 查询会员在指定课程的有效预约
|
||||
*/
|
||||
Mono<GroupCourseBooking> findValidBooking(Long courseId, Long memberId);
|
||||
|
||||
/**
|
||||
* 统计课程有效预约人数
|
||||
*/
|
||||
Mono<Long> countValidBookings(Long courseId);
|
||||
|
||||
/**
|
||||
* 保存预约记录
|
||||
*/
|
||||
Mono<GroupCourseBooking> save(GroupCourseBooking booking);
|
||||
|
||||
/**
|
||||
* 更新预约记录
|
||||
*/
|
||||
Mono<GroupCourseBooking> update(GroupCourseBooking booking);
|
||||
|
||||
/**
|
||||
* 更新预约状态
|
||||
*/
|
||||
Mono<Integer> updateStatus(Long bookingId, String status);
|
||||
|
||||
/**
|
||||
* 删除预约记录
|
||||
*/
|
||||
Mono<Void> deleteById(Long bookingId);
|
||||
|
||||
/**
|
||||
* 根据会员卡记录ID查询预约记录
|
||||
*/
|
||||
Flux<GroupCourseBooking> findByMemberCardRecordId(Long memberCardRecordId);
|
||||
|
||||
/**
|
||||
* 查询会员是否有时间冲突的预约
|
||||
*
|
||||
* @param memberId 会员ID
|
||||
* @param newStartTime 新课程开始时间
|
||||
* @param newEndTime 新课程结束时间
|
||||
* @return 冲突的预约记录列表
|
||||
*/
|
||||
Flux<GroupCourseBooking> findConflictingBookings(Long memberId, java.time.LocalDateTime newStartTime, java.time.LocalDateTime newEndTime);
|
||||
|
||||
/**
|
||||
* 查询已开始课程但未到场会员的预约记录
|
||||
* @return 缺席会员的预约记录列表
|
||||
*/
|
||||
Flux<GroupCourseBooking> findAbsentMembers();
|
||||
|
||||
/**
|
||||
* 更新预约状态为缺席(3)
|
||||
* @param bookingId 预约ID
|
||||
* @return 更新记录数
|
||||
*/
|
||||
Mono<Integer> updateToAbsent(Long bookingId);
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
|
||||
package cn.novalon.gym.manage.groupcourse.repository;
|
||||
|
||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||
import cn.novalon.gym.manage.common.dto.PageResponse;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public interface IGroupCourseRepository {
|
||||
Mono<GroupCourse> findByIdAndDeletedAtIsNull(Long id);
|
||||
Flux<GroupCourse> findAll();
|
||||
Flux<GroupCourse> findAll(Sort sort);
|
||||
Flux<GroupCourse> findByDeletedAtIsNull();
|
||||
Flux<GroupCourse> findByDeletedAtIsNull(Sort sort);
|
||||
|
||||
Mono<PageResponse<GroupCourse>> findByPage(PageRequest pageRequest);
|
||||
Mono<PageResponse<GroupCourse>> findByPageAndNotDeleted(PageRequest pageRequest);
|
||||
|
||||
Mono<GroupCourse> save(GroupCourse groupCourse);
|
||||
|
||||
Mono<GroupCourse> update(GroupCourse groupCourse);
|
||||
|
||||
Mono<GroupCourse> cancel(Long id);
|
||||
|
||||
Mono<Void> deleteById(Long id);
|
||||
|
||||
Mono<GroupCourse> updateCurrentMembers(Long id, Integer delta);
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
package cn.novalon.gym.manage.groupcourse.repository.impl;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.converter.GroupCourseConverter;
|
||||
import cn.novalon.gym.manage.groupcourse.dao.GroupCourseBookingDao;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourseBooking;
|
||||
import cn.novalon.gym.manage.groupcourse.entity.GroupCourseBookingEntity;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseBookingRepository;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* 团课预约记录Repository实现类
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-06-01
|
||||
*/
|
||||
@Repository
|
||||
public class GroupCourseBookingRepository implements IGroupCourseBookingRepository {
|
||||
|
||||
private final GroupCourseBookingDao groupCourseBookingDao;
|
||||
private final GroupCourseConverter groupCourseConverter;
|
||||
|
||||
public GroupCourseBookingRepository(GroupCourseBookingDao groupCourseBookingDao,
|
||||
GroupCourseConverter groupCourseConverter) {
|
||||
this.groupCourseBookingDao = groupCourseBookingDao;
|
||||
this.groupCourseConverter = groupCourseConverter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourseBooking> findById(Long id) {
|
||||
return groupCourseBookingDao.findByIdIsAndDeletedAtIsNull(id)
|
||||
.map(groupCourseConverter::toBookingDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<GroupCourseBooking> findByMemberId(Long memberId) {
|
||||
return groupCourseBookingDao.findByMemberIdAndDeletedAtIsNull(memberId, Sort.by(Sort.Direction.DESC, "bookingTime"))
|
||||
.map(groupCourseConverter::toBookingDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<GroupCourseBooking> findByCourseId(Long courseId) {
|
||||
return groupCourseBookingDao.findByCourseIdAndDeletedAtIsNull(courseId)
|
||||
.map(groupCourseConverter::toBookingDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourseBooking> findByCourseIdAndMemberId(Long courseId, Long memberId) {
|
||||
return groupCourseBookingDao.findByCourseIdAndMemberIdAndDeletedAtIsNull(courseId, memberId)
|
||||
.map(groupCourseConverter::toBookingDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourseBooking> findValidBooking(Long courseId, Long memberId) {
|
||||
return groupCourseBookingDao.findByCourseIdAndMemberIdAndStatusAndDeletedAtIsNull(courseId, memberId, "0")
|
||||
.map(groupCourseConverter::toBookingDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Long> countValidBookings(Long courseId) {
|
||||
return groupCourseBookingDao.countByCourseIdAndStatusAndDeletedAtIsNull(courseId, "0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourseBooking> save(GroupCourseBooking booking) {
|
||||
GroupCourseBookingEntity entity = groupCourseConverter.toBookingEntity(booking);
|
||||
return groupCourseBookingDao.save(entity)
|
||||
.map(groupCourseConverter::toBookingDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourseBooking> update(GroupCourseBooking booking) {
|
||||
GroupCourseBookingEntity entity = groupCourseConverter.toBookingEntity(booking);
|
||||
return groupCourseBookingDao.save(entity)
|
||||
.map(groupCourseConverter::toBookingDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Integer> updateStatus(Long bookingId, String status) {
|
||||
java.time.LocalDateTime now = java.time.LocalDateTime.now();
|
||||
java.time.LocalDateTime cancelTime = "1".equals(status) ? now : null;
|
||||
return groupCourseBookingDao.updateStatus(bookingId, status, cancelTime, now);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> deleteById(Long bookingId) {
|
||||
return groupCourseBookingDao.softDelete(bookingId, java.time.LocalDateTime.now()).then();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<GroupCourseBooking> findByMemberCardRecordId(Long memberCardRecordId) {
|
||||
return groupCourseBookingDao.findByMemberCardRecordIdAndDeletedAtIsNull(memberCardRecordId)
|
||||
.map(groupCourseConverter::toBookingDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<GroupCourseBooking> findConflictingBookings(Long memberId, java.time.LocalDateTime newStartTime, java.time.LocalDateTime newEndTime) {
|
||||
return groupCourseBookingDao.findConflictingBookings(memberId, newStartTime, newEndTime)
|
||||
.map(groupCourseConverter::toBookingDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<GroupCourseBooking> findAbsentMembers() {
|
||||
return groupCourseBookingDao.findAbsentMembers()
|
||||
.map(groupCourseConverter::toBookingDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Integer> updateToAbsent(Long bookingId) {
|
||||
java.time.LocalDateTime now = java.time.LocalDateTime.now();
|
||||
return groupCourseBookingDao.updateToAbsent(bookingId, now);
|
||||
}
|
||||
}
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
|
||||
package cn.novalon.gym.manage.groupcourse.repository.impl;
|
||||
|
||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||
import cn.novalon.gym.manage.common.dto.PageResponse;
|
||||
import cn.novalon.gym.manage.groupcourse.converter.GroupCourseConverter;
|
||||
import cn.novalon.gym.manage.groupcourse.dao.GroupCourseDao;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||
import cn.novalon.gym.manage.groupcourse.entity.GroupCourseEntity;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseRepository;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
||||
import org.springframework.data.relational.core.query.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public class GroupCourseRepository implements IGroupCourseRepository {
|
||||
private final GroupCourseDao groupCourseDao;
|
||||
private final GroupCourseConverter groupCourseConverter;
|
||||
private final R2dbcEntityTemplate r2dbcEntityTemplate;
|
||||
|
||||
public GroupCourseRepository(GroupCourseDao groupCourseDao, GroupCourseConverter groupCourseConverter,
|
||||
R2dbcEntityTemplate r2dbcEntityTemplate){
|
||||
this.groupCourseDao = groupCourseDao;
|
||||
this.groupCourseConverter = groupCourseConverter;
|
||||
this.r2dbcEntityTemplate = r2dbcEntityTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourse> findByIdAndDeletedAtIsNull(Long id) {
|
||||
return groupCourseDao.findByIdIsAndDeletedAtIsNull(id)
|
||||
.map(groupCourseConverter::toDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<GroupCourse> findAll() {
|
||||
return groupCourseDao.findAll()
|
||||
.map(groupCourseConverter::toDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<GroupCourse> findAll(Sort sort) {
|
||||
return groupCourseDao.findAll(sort)
|
||||
.map(groupCourseConverter::toDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<GroupCourse> findByDeletedAtIsNull() {
|
||||
return groupCourseDao.findAllByDeletedAtIsNull()
|
||||
.map(groupCourseConverter::toDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<GroupCourse> findByDeletedAtIsNull(Sort sort) {
|
||||
return groupCourseDao.findAllByDeletedAtIsNull(sort)
|
||||
.map(groupCourseConverter::toDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<PageResponse<GroupCourse>> findByPage(PageRequest pageRequest) {
|
||||
int page = pageRequest.getPage();
|
||||
int size = pageRequest.getSize();
|
||||
String sort = pageRequest.getSort();
|
||||
String order = pageRequest.getOrder();
|
||||
|
||||
Sort sortObj = Sort.unsorted();
|
||||
if (sort != null && !sort.isEmpty()) {
|
||||
sortObj = Sort.by(Sort.Direction.fromString(order), sort);
|
||||
}
|
||||
|
||||
org.springframework.data.domain.PageRequest pageable = org.springframework.data.domain.PageRequest.of(page, size, sortObj);
|
||||
|
||||
Query query = Query.empty();
|
||||
|
||||
return r2dbcEntityTemplate.select(GroupCourseEntity.class)
|
||||
.matching(query.with(pageable))
|
||||
.all()
|
||||
.collectList()
|
||||
.zipWith(r2dbcEntityTemplate.count(query, GroupCourseEntity.class))
|
||||
.map(tuple -> {
|
||||
long total = tuple.getT2();
|
||||
int totalPages = (int) Math.ceil((double) total / size);
|
||||
List<GroupCourse> courseList = tuple.getT1().stream()
|
||||
.map(groupCourseConverter::toDomain)
|
||||
.toList();
|
||||
return new PageResponse<>(courseList, totalPages, total, page, size);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<PageResponse<GroupCourse>> findByPageAndNotDeleted(PageRequest pageRequest) {
|
||||
int page = pageRequest.getPage();
|
||||
int size = pageRequest.getSize();
|
||||
String sort = pageRequest.getSort();
|
||||
String order = pageRequest.getOrder();
|
||||
|
||||
Sort sortObj = Sort.unsorted();
|
||||
if (sort != null && !sort.isEmpty()) {
|
||||
sortObj = Sort.by(Sort.Direction.fromString(order), sort);
|
||||
}
|
||||
|
||||
org.springframework.data.domain.PageRequest pageable = org.springframework.data.domain.PageRequest.of(page, size, sortObj);
|
||||
|
||||
return groupCourseDao.findAllByDeletedAtIsNull(sortObj)
|
||||
.collectList()
|
||||
.zipWith(groupCourseDao.findAllByDeletedAtIsNull().count())
|
||||
.map(tuple -> {
|
||||
List<GroupCourseEntity> allEntities = tuple.getT1();
|
||||
long total = tuple.getT2();
|
||||
|
||||
int fromIndex = page * size;
|
||||
int toIndex = Math.min(fromIndex + size, allEntities.size());
|
||||
|
||||
List<GroupCourse> courseList;
|
||||
if (fromIndex < allEntities.size()) {
|
||||
courseList = allEntities.subList(fromIndex, toIndex).stream()
|
||||
.map(groupCourseConverter::toDomain)
|
||||
.toList();
|
||||
} else {
|
||||
courseList = List.of();
|
||||
}
|
||||
|
||||
int totalPages = (int) Math.ceil((double) total / size);
|
||||
return new PageResponse<>(courseList, totalPages, total, page, size);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourse> save(GroupCourse groupCourse) {
|
||||
GroupCourseEntity entity = groupCourseConverter.toEntity(groupCourse);
|
||||
entity.setCreatedAt(LocalDateTime.now());
|
||||
entity.setUpdatedAt(LocalDateTime.now());
|
||||
entity.setStatus(0L);
|
||||
entity.setCurrentMembers(0);
|
||||
|
||||
return groupCourseDao.save(entity)
|
||||
.map(groupCourseConverter::toDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourse> update(GroupCourse groupCourse) {
|
||||
GroupCourseEntity entity = groupCourseConverter.toEntity(groupCourse);
|
||||
entity.setUpdatedAt(LocalDateTime.now());
|
||||
|
||||
return r2dbcEntityTemplate.update(entity)
|
||||
.then(findByIdAndDeletedAtIsNull(groupCourse.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourse> cancel(Long id) {
|
||||
return groupCourseDao.cancelCourse(id, LocalDateTime.now())
|
||||
.flatMap(updated -> {
|
||||
if (updated > 0) {
|
||||
return findByIdAndDeletedAtIsNull(id);
|
||||
}
|
||||
return Mono.empty();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> deleteById(Long id) {
|
||||
return groupCourseDao.softDelete(id, LocalDateTime.now())
|
||||
.then();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourse> updateCurrentMembers(Long id, Integer delta) {
|
||||
return groupCourseDao.updateCurrentMembers(id, delta, LocalDateTime.now())
|
||||
.flatMap(updated -> {
|
||||
if (updated > 0) {
|
||||
return findByIdAndDeletedAtIsNull(id);
|
||||
}
|
||||
return Mono.empty();
|
||||
});
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package cn.novalon.gym.manage.groupcourse.scheduler;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.service.IGroupCourseBookingService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 团课缺席会员定时任务
|
||||
*
|
||||
* 功能:定期检查已开始但会员未到场的课程,自动更新预约记录状态为缺席
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-06-02
|
||||
*/
|
||||
@Component
|
||||
public class GroupCourseAbsentScheduler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GroupCourseAbsentScheduler.class);
|
||||
|
||||
private final IGroupCourseBookingService bookingService;
|
||||
|
||||
public GroupCourseAbsentScheduler(IGroupCourseBookingService bookingService) {
|
||||
this.bookingService = bookingService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 每分钟检查一次已开始课程但未到场会员的预约记录
|
||||
* 使用fixedRate保证任务间隔稳定执行
|
||||
*/
|
||||
@Scheduled(fixedRate = 60000)
|
||||
public void checkAndUpdateAbsentMembers() {
|
||||
logger.debug("定时任务开始检查已开始课程但未到场会员的预约记录");
|
||||
|
||||
bookingService.processAbsentMembers()
|
||||
.subscribe(
|
||||
count -> logger.debug("定时任务完成,更新了 {} 条缺席记录", count),
|
||||
error -> logger.error("定时任务执行失败:{}", error.getMessage(), error)
|
||||
);
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package cn.novalon.gym.manage.groupcourse.service;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourseBooking;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* 团课预约服务接口
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-06-01
|
||||
*/
|
||||
public interface IGroupCourseBookingService {
|
||||
|
||||
/**
|
||||
* 预约团课
|
||||
*
|
||||
* @param courseId 团课ID
|
||||
* @param memberId 会员ID
|
||||
* @param memberCardRecordId 会员卡记录ID
|
||||
* @return 预约记录
|
||||
*/
|
||||
Mono<GroupCourseBooking> bookCourse(Long courseId, Long memberId, Long memberCardRecordId);
|
||||
|
||||
/**
|
||||
* 取消预约
|
||||
*
|
||||
* @param bookingId 预约ID
|
||||
* @param memberId 会员ID
|
||||
* @return 取消后的预约记录
|
||||
*/
|
||||
Mono<GroupCourseBooking> cancelBooking(Long bookingId, Long memberId);
|
||||
|
||||
/**
|
||||
* 根据会员ID查询预约记录列表
|
||||
*
|
||||
* @param memberId 会员ID
|
||||
* @return 预约记录列表
|
||||
*/
|
||||
Flux<GroupCourseBooking> getBookingsByMemberId(Long memberId);
|
||||
|
||||
/**
|
||||
* 根据预约ID查询预约详情
|
||||
*
|
||||
* @param bookingId 预约ID
|
||||
* @return 预约记录
|
||||
*/
|
||||
Mono<GroupCourseBooking> getBookingById(Long bookingId);
|
||||
|
||||
/**
|
||||
* 根据团课ID查询预约记录列表
|
||||
*
|
||||
* @param courseId 团课ID
|
||||
* @return 预约记录列表
|
||||
*/
|
||||
Flux<GroupCourseBooking> getBookingsByCourseId(Long courseId);
|
||||
|
||||
/**
|
||||
* 处理已开始课程但未到场会员的预约记录
|
||||
* 将状态更新为缺席(3)
|
||||
*
|
||||
* @return 处理的记录数
|
||||
*/
|
||||
Mono<Integer> processAbsentMembers();
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
|
||||
package cn.novalon.gym.manage.groupcourse.service;
|
||||
|
||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||
import cn.novalon.gym.manage.common.dto.PageResponse;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public interface IGroupCourseService {
|
||||
Mono<GroupCourse> findById(Long id);
|
||||
Flux<GroupCourse> findAll();
|
||||
Flux<GroupCourse> findAll(boolean includeDeleted);
|
||||
|
||||
Mono<PageResponse<GroupCourse>> findByPage(PageRequest pageRequest, boolean includeDeleted);
|
||||
|
||||
Mono<GroupCourse> create(GroupCourse groupCourse);
|
||||
|
||||
Mono<GroupCourse> update(Long id, GroupCourse groupCourse);
|
||||
|
||||
Mono<GroupCourse> cancel(Long id);
|
||||
|
||||
Mono<GroupCourse> signIn(Long courseId, Long memberId);
|
||||
|
||||
Mono<Void> delete(Long id);
|
||||
}
|
||||
+372
@@ -0,0 +1,372 @@
|
||||
package cn.novalon.gym.manage.groupcourse.service.impl;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourseBooking;
|
||||
import cn.novalon.gym.manage.groupcourse.event.BookingReminderEventPublisher;
|
||||
import cn.novalon.gym.manage.groupcourse.handler.BookingSagaHandler;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseBookingRepository;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseRepository;
|
||||
import cn.novalon.gym.manage.groupcourse.service.IGroupCourseBookingService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 团课预约服务实现类
|
||||
*
|
||||
* 业务规则:
|
||||
* - 预约需在课程开始前至少30分钟
|
||||
* - 取消预约需在课程开始前至少2小时
|
||||
* - 每节课最多20人
|
||||
* - 预约成功后发送提醒
|
||||
* - 预约成功后扣减权益
|
||||
*
|
||||
* 技术要点:
|
||||
* - 使用Redis缓存团课信息
|
||||
* - 使用分布式锁防止预约冲突
|
||||
* - 使用响应式编程实现高并发预约
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-06-01
|
||||
*/
|
||||
@Service
|
||||
public class GroupCourseBookingService implements IGroupCourseBookingService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GroupCourseBookingService.class);
|
||||
|
||||
private final IGroupCourseBookingRepository bookingRepository;
|
||||
private final IGroupCourseRepository courseRepository;
|
||||
private final GroupCourseRedisService redisService;
|
||||
private final BookingReminderEventPublisher bookingReminderEventPublisher;
|
||||
private final BookingSagaHandler bookingSagaHandler;
|
||||
|
||||
// 预约提前时间限制(分钟)
|
||||
private static final long BOOKING_MIN_ADVANCE_MINUTES = 30;
|
||||
// 取消预约提前时间限制(小时)
|
||||
private static final long CANCEL_MIN_ADVANCE_HOURS = 2;
|
||||
|
||||
public GroupCourseBookingService(IGroupCourseBookingRepository bookingRepository,
|
||||
IGroupCourseRepository courseRepository,
|
||||
GroupCourseRedisService redisService,
|
||||
BookingReminderEventPublisher bookingReminderEventPublisher,
|
||||
BookingSagaHandler bookingSagaHandler) {
|
||||
this.bookingRepository = bookingRepository;
|
||||
this.courseRepository = courseRepository;
|
||||
this.redisService = redisService;
|
||||
this.bookingReminderEventPublisher = bookingReminderEventPublisher;
|
||||
this.bookingSagaHandler = bookingSagaHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourseBooking> bookCourse(Long courseId, Long memberId, Long memberCardRecordId) {
|
||||
logger.info("开始预约团课:courseId={}, memberId={}, memberCardRecordId={}", courseId, memberId, memberCardRecordId);
|
||||
|
||||
// 生成唯一请求ID用于分布式锁
|
||||
String requestId = UUID.randomUUID().toString();
|
||||
|
||||
// 1. 获取分布式锁
|
||||
return redisService.acquireLock(courseId, requestId)
|
||||
.flatMap(lockAcquired -> {
|
||||
if (!lockAcquired) {
|
||||
return Mono.error(new RuntimeException("系统繁忙,请稍后重试"));
|
||||
}
|
||||
|
||||
// 2. 尝试从缓存获取课程信息,如果缓存不存在则从数据库获取
|
||||
return getCourseWithCache(courseId)
|
||||
.flatMap(course -> {
|
||||
// 3. 验证课程状态
|
||||
Long status = course.getStatus();
|
||||
if (status == null || status != 0L) {
|
||||
String errorMessage;
|
||||
if (status == null) {
|
||||
errorMessage = "课程状态异常";
|
||||
} else if (status == 1L) {
|
||||
errorMessage = "课程已取消,无法预约";
|
||||
} else if (status == 2L) {
|
||||
errorMessage = "课程已结束,无法预约";
|
||||
} else {
|
||||
errorMessage = "课程状态不可预约";
|
||||
}
|
||||
return releaseLockAndError(courseId, requestId, errorMessage);
|
||||
}
|
||||
|
||||
// 4. 验证预约时间
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime startTime = course.getStartTime();
|
||||
long minutesUntilStart = ChronoUnit.MINUTES.between(now, startTime);
|
||||
if (minutesUntilStart < BOOKING_MIN_ADVANCE_MINUTES) {
|
||||
return releaseLockAndError(courseId, requestId,
|
||||
"需在课程开始前" + BOOKING_MIN_ADVANCE_MINUTES + "分钟预约");
|
||||
}
|
||||
|
||||
// 5. 验证课程人数是否已满(使用数据库中的current_members字段)
|
||||
if (course.getCurrentMembers() != null &&
|
||||
course.getMaxMembers() != null &&
|
||||
course.getCurrentMembers() >= course.getMaxMembers()) {
|
||||
return releaseLockAndError(courseId, requestId, "课程已满");
|
||||
}
|
||||
|
||||
// 6. 验证时间冲突(会员是否已预约时间重叠的课程)
|
||||
return bookingRepository.findConflictingBookings(memberId, course.getStartTime(), course.getEndTime())
|
||||
.collectList()
|
||||
.flatMap(conflictingBookings -> {
|
||||
if (!conflictingBookings.isEmpty()) {
|
||||
StringBuilder errorMsg = new StringBuilder("您已预约的课程与当前课程时间冲突:");
|
||||
for (GroupCourseBooking conflict : conflictingBookings) {
|
||||
errorMsg.append(conflict.getCourseName())
|
||||
.append("(")
|
||||
.append(conflict.getCourseStartTime())
|
||||
.append(" - ")
|
||||
.append(conflict.getCourseEndTime())
|
||||
.append(") ");
|
||||
}
|
||||
return releaseLockAndError(courseId, requestId, errorMsg.toString());
|
||||
}
|
||||
|
||||
// 7. 验证是否已预约
|
||||
return bookingRepository.findValidBooking(courseId, memberId)
|
||||
.flatMap(existingBooking -> {
|
||||
return releaseLockAndError(courseId, requestId, "您已预约该课程");
|
||||
})
|
||||
.switchIfEmpty(
|
||||
// 8. 使用Redis原子操作验证课程人数是否已满
|
||||
validateAndIncrementBookingCount(courseId, course.getMaxMembers())
|
||||
.flatMap(countValid -> {
|
||||
if (countValid > course.getMaxMembers()) {
|
||||
return releaseLockAndError(courseId, requestId, "课程已满");
|
||||
}
|
||||
|
||||
// 9. 创建预约记录
|
||||
GroupCourseBooking booking = new GroupCourseBooking();
|
||||
booking.setCourseId(courseId);
|
||||
booking.setMemberId(memberId);
|
||||
booking.setMemberCardRecordId(memberCardRecordId);
|
||||
booking.setBookingTime(LocalDateTime.now());
|
||||
booking.setStatus("0"); // 0-已预约
|
||||
|
||||
// 添加课程信息到预约记录
|
||||
booking.setCourseName(course.getCourseName());
|
||||
booking.setCourseStartTime(course.getStartTime());
|
||||
booking.setCourseEndTime(course.getEndTime());
|
||||
booking.setLocation(course.getLocation());
|
||||
|
||||
// 10. 使用Saga事务执行预约(包含权益扣减)
|
||||
return bookingSagaHandler.executeBooking(booking, memberCardRecordId)
|
||||
.flatMap(savedBooking -> {
|
||||
// 11. 释放锁
|
||||
return redisService.releaseLock(courseId, requestId)
|
||||
.then(Mono.just(savedBooking));
|
||||
})
|
||||
.doOnSuccess(savedBooking -> {
|
||||
logger.info("预约成功:bookingId={}, courseId={}, memberId={}",
|
||||
savedBooking.getId(), courseId, memberId);
|
||||
// 发布预约成功事件
|
||||
bookingReminderEventPublisher.publishBookingSuccessEvent(
|
||||
savedBooking.getId(),
|
||||
savedBooking.getMemberId(),
|
||||
savedBooking.getCourseName(),
|
||||
savedBooking.getCourseStartTime().toString()
|
||||
);
|
||||
})
|
||||
.doOnError(error -> {
|
||||
// 回滚Redis计数
|
||||
redisService.decrementBookingCount(courseId).subscribe();
|
||||
logger.error("预约失败:courseId={}, memberId={}, error={}",
|
||||
courseId, memberId, error.getMessage());
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
// 发生错误时释放锁
|
||||
redisService.releaseLock(courseId, requestId).subscribe();
|
||||
return Mono.error(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 从缓存或数据库获取课程信息
|
||||
*/
|
||||
private Mono<GroupCourse> getCourseWithCache(Long courseId) {
|
||||
return redisService.getCachedCourse(courseId)
|
||||
.switchIfEmpty(
|
||||
// 缓存未命中,从数据库查询
|
||||
courseRepository.findByIdAndDeletedAtIsNull(courseId)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("团课不存在")))
|
||||
.flatMap(course -> {
|
||||
// 将课程信息存入缓存
|
||||
return redisService.cacheCourse(course).then(Mono.just(course));
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证并增加预约人数(使用Redis原子操作)
|
||||
*/
|
||||
private Mono<Integer> validateAndIncrementBookingCount(Long courseId, Integer maxMembers) {
|
||||
// 先获取当前Redis中的预约计数
|
||||
return redisService.getBookingCount(courseId)
|
||||
.flatMap(currentCount -> {
|
||||
// 如果Redis中计数为0,可能是首次访问,需要从数据库同步
|
||||
if (currentCount == 0) {
|
||||
// 从数据库查询实际预约人数
|
||||
return bookingRepository.countValidBookings(courseId)
|
||||
.flatMap(dbCount -> {
|
||||
// 将数据库中的实际预约人数同步到Redis
|
||||
return redisService.setBookingCount(courseId, dbCount.intValue())
|
||||
.then(Mono.just(dbCount.intValue()));
|
||||
});
|
||||
}
|
||||
return Mono.just(currentCount);
|
||||
})
|
||||
// 递增预约计数
|
||||
.flatMap(count -> redisService.incrementBookingCount(courseId).map(Long::intValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放锁并返回错误
|
||||
*/
|
||||
private Mono<GroupCourseBooking> releaseLockAndError(Long courseId, String requestId, String errorMessage) {
|
||||
return redisService.releaseLock(courseId, requestId)
|
||||
.then(Mono.error(new RuntimeException(errorMessage)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourseBooking> cancelBooking(Long bookingId, Long memberId) {
|
||||
logger.info("开始取消预约:bookingId={}, memberId={}", bookingId, memberId);
|
||||
|
||||
// 生成唯一请求ID用于分布式锁
|
||||
String requestId = UUID.randomUUID().toString();
|
||||
|
||||
// 获取锁防止并发取消
|
||||
return redisService.acquireLock(bookingId, requestId)
|
||||
.flatMap(lockAcquired -> {
|
||||
if (!lockAcquired) {
|
||||
return Mono.error(new RuntimeException("系统繁忙,请稍后重试"));
|
||||
}
|
||||
|
||||
// 1. 查询预约记录
|
||||
return bookingRepository.findById(bookingId)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("预约记录不存在")))
|
||||
.flatMap(booking -> {
|
||||
// 2. 验证预约归属
|
||||
if (!booking.getMemberId().equals(memberId)) {
|
||||
return releaseLockAndError(bookingId, requestId, "无权取消他人预约");
|
||||
}
|
||||
|
||||
// 3. 验证预约状态
|
||||
String status = booking.getStatus();
|
||||
if (!"0".equals(status)) {
|
||||
String errorMessage;
|
||||
if ("1".equals(status)) {
|
||||
errorMessage = "预约已取消,无需重复取消";
|
||||
} else if ("2".equals(status)) {
|
||||
errorMessage = "课程已出席,无法取消";
|
||||
} else if ("3".equals(status)) {
|
||||
errorMessage = "已缺席课程,无法取消";
|
||||
} else {
|
||||
errorMessage = "预约状态不允许取消";
|
||||
}
|
||||
return releaseLockAndError(bookingId, requestId, errorMessage);
|
||||
}
|
||||
|
||||
// 4. 验证取消时间
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime startTime = booking.getCourseStartTime();
|
||||
if (startTime == null) {
|
||||
return releaseLockAndError(bookingId, requestId, "课程开始时间为空,无法取消预约");
|
||||
}
|
||||
long hoursUntilStart = ChronoUnit.HOURS.between(now, startTime);
|
||||
if (hoursUntilStart < CANCEL_MIN_ADVANCE_HOURS) {
|
||||
return releaseLockAndError(bookingId, requestId,
|
||||
"需在课程开始前" + CANCEL_MIN_ADVANCE_HOURS + "小时取消");
|
||||
}
|
||||
|
||||
// 5. 使用Saga事务执行取消预约(包含权益恢复)
|
||||
return bookingSagaHandler.executeCancelBooking(bookingId, booking.getCourseId(), booking.getMemberCardRecordId(), memberId)
|
||||
.flatMap(updatedBooking -> {
|
||||
// 6. 释放锁
|
||||
return redisService.releaseLock(bookingId, requestId)
|
||||
.then(Mono.just(updatedBooking));
|
||||
})
|
||||
.doOnSuccess(updatedBooking -> {
|
||||
logger.info("取消预约成功:bookingId={}, memberId={}", bookingId, memberId);
|
||||
// 发布预约取消事件
|
||||
bookingReminderEventPublisher.publishBookingCancelEvent(
|
||||
updatedBooking.getId(),
|
||||
updatedBooking.getMemberId(),
|
||||
updatedBooking.getCourseName()
|
||||
);
|
||||
})
|
||||
.doOnError(error -> {
|
||||
logger.error("取消预约失败:bookingId={}, memberId={}, error={}",
|
||||
bookingId, memberId, error.getMessage());
|
||||
});
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
redisService.releaseLock(bookingId, requestId).subscribe();
|
||||
return Mono.error(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<GroupCourseBooking> getBookingsByMemberId(Long memberId) {
|
||||
logger.debug("查询会员预约记录:memberId={}", memberId);
|
||||
return bookingRepository.findByMemberId(memberId)
|
||||
.doOnComplete(() -> logger.debug("查询完成:memberId={}", memberId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourseBooking> getBookingById(Long bookingId) {
|
||||
logger.debug("查询预约详情:bookingId={}", bookingId);
|
||||
return bookingRepository.findById(bookingId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<GroupCourseBooking> getBookingsByCourseId(Long courseId) {
|
||||
logger.debug("查询课程预约记录:courseId={}", courseId);
|
||||
return bookingRepository.findByCourseId(courseId)
|
||||
.doOnComplete(() -> logger.debug("查询完成:courseId={}", courseId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Integer> processAbsentMembers() {
|
||||
logger.info("开始处理已开始课程但未到场会员的预约记录");
|
||||
|
||||
return bookingRepository.findAbsentMembers()
|
||||
.collectList()
|
||||
.flatMap(absentBookings -> {
|
||||
if (absentBookings.isEmpty()) {
|
||||
logger.info("没有需要处理的缺席会员记录");
|
||||
return Mono.just(0);
|
||||
}
|
||||
|
||||
logger.info("发现 {} 条需要更新为缺席状态的预约记录", absentBookings.size());
|
||||
|
||||
// 批量更新状态为缺席
|
||||
return Flux.fromIterable(absentBookings)
|
||||
.flatMap(booking -> {
|
||||
logger.debug("更新预约记录为缺席状态:bookingId={}, memberId={}, courseId={}",
|
||||
booking.getId(), booking.getMemberId(), booking.getCourseId());
|
||||
return bookingRepository.updateToAbsent(booking.getId());
|
||||
})
|
||||
.reduce(Integer::sum)
|
||||
.defaultIfEmpty(0)
|
||||
.doOnSuccess(count -> {
|
||||
logger.info("成功更新 {} 条预约记录为缺席状态", count);
|
||||
})
|
||||
.doOnError(error -> {
|
||||
logger.error("处理缺席会员记录时发生错误:{}", error.getMessage(), error);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
+194
@@ -0,0 +1,194 @@
|
||||
package cn.novalon.gym.manage.groupcourse.service.impl;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.redis.core.ReactiveRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
/**
|
||||
* 团课Redis缓存服务
|
||||
*
|
||||
* 负责团课信息的缓存管理和分布式锁实现
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-06-01
|
||||
*/
|
||||
@Service
|
||||
public class GroupCourseRedisService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GroupCourseRedisService.class);
|
||||
|
||||
// 团课信息缓存Key前缀
|
||||
private static final String GROUP_COURSE_CACHE_PREFIX = "group_course:";
|
||||
// 团课预约锁Key前缀
|
||||
private static final String BOOKING_LOCK_PREFIX = "booking_lock:";
|
||||
// 缓存过期时间(5分钟)
|
||||
private static final Duration CACHE_EXPIRE_TIME = Duration.ofMinutes(5);
|
||||
// 锁过期时间(30秒)
|
||||
private static final Duration LOCK_EXPIRE_TIME = Duration.ofSeconds(30);
|
||||
|
||||
private final ReactiveRedisTemplate<String, Object> reactiveRedisTemplate;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public GroupCourseRedisService(ReactiveRedisTemplate<String, Object> reactiveRedisTemplate,
|
||||
ObjectMapper objectMapper) {
|
||||
this.reactiveRedisTemplate = reactiveRedisTemplate;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取团课缓存Key
|
||||
*/
|
||||
private String getCourseCacheKey(Long courseId) {
|
||||
return GROUP_COURSE_CACHE_PREFIX + courseId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取预约锁Key
|
||||
*/
|
||||
private String getBookingLockKey(Long courseId) {
|
||||
return BOOKING_LOCK_PREFIX + courseId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存团课信息
|
||||
*/
|
||||
public Mono<Void> cacheCourse(GroupCourse course) {
|
||||
String key = getCourseCacheKey(course.getId());
|
||||
try {
|
||||
String value = objectMapper.writeValueAsString(course);
|
||||
return reactiveRedisTemplate.opsForValue()
|
||||
.set(key, value, CACHE_EXPIRE_TIME)
|
||||
.doOnSuccess(result -> logger.debug("团课信息已缓存:courseId={}", course.getId()))
|
||||
.then();
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.error("序列化团课信息失败:courseId={}", course.getId(), e);
|
||||
return Mono.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存的团课信息
|
||||
*/
|
||||
public Mono<GroupCourse> getCachedCourse(Long courseId) {
|
||||
String key = getCourseCacheKey(courseId);
|
||||
return reactiveRedisTemplate.opsForValue()
|
||||
.get(key)
|
||||
.cast(String.class)
|
||||
.flatMap(value -> {
|
||||
try {
|
||||
GroupCourse course = objectMapper.readValue(value, GroupCourse.class);
|
||||
logger.debug("从缓存获取团课信息:courseId={}", courseId);
|
||||
return Mono.just(course);
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.error("反序列化团课信息失败:courseId={}", courseId, e);
|
||||
return Mono.empty();
|
||||
}
|
||||
})
|
||||
.switchIfEmpty(Mono.fromRunnable(() -> logger.debug("缓存中未找到团课信息:courseId={}", courseId)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除团课缓存
|
||||
*/
|
||||
public Mono<Void> invalidateCourseCache(Long courseId) {
|
||||
String key = getCourseCacheKey(courseId);
|
||||
return reactiveRedisTemplate.delete(key)
|
||||
.doOnSuccess(result -> logger.debug("团课缓存已删除:courseId={}", courseId))
|
||||
.then();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分布式锁
|
||||
*
|
||||
* @param courseId 课程ID
|
||||
* @param requestId 请求ID(用于锁的唯一性校验)
|
||||
* @return 是否获取成功
|
||||
*/
|
||||
public Mono<Boolean> acquireLock(Long courseId, String requestId) {
|
||||
String key = getBookingLockKey(courseId);
|
||||
return reactiveRedisTemplate.opsForValue()
|
||||
.setIfAbsent(key, requestId, LOCK_EXPIRE_TIME)
|
||||
.doOnSuccess(acquired -> {
|
||||
if (acquired) {
|
||||
logger.debug("获取预约锁成功:courseId={}, requestId={}", courseId, requestId);
|
||||
} else {
|
||||
logger.debug("获取预约锁失败:courseId={}", courseId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放分布式锁
|
||||
*
|
||||
* @param courseId 课程ID
|
||||
* @param requestId 请求ID(用于锁的唯一性校验)
|
||||
* @return 是否释放成功
|
||||
*/
|
||||
public Mono<Boolean> releaseLock(Long courseId, String requestId) {
|
||||
String key = getBookingLockKey(courseId);
|
||||
return reactiveRedisTemplate.opsForValue()
|
||||
.get(key)
|
||||
.cast(String.class)
|
||||
.flatMap(storedRequestId -> {
|
||||
if (requestId.equals(storedRequestId)) {
|
||||
return reactiveRedisTemplate.delete(key)
|
||||
.map(deleted -> deleted > 0)
|
||||
.doOnSuccess(result -> logger.debug("释放预约锁成功:courseId={}, requestId={}", courseId, requestId));
|
||||
} else {
|
||||
logger.warn("锁归属校验失败:courseId={}, expectedRequestId={}, actualRequestId={}",
|
||||
courseId, requestId, storedRequestId);
|
||||
return Mono.just(false);
|
||||
}
|
||||
})
|
||||
.defaultIfEmpty(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取课程预约人数(缓存)
|
||||
*/
|
||||
public Mono<Integer> getBookingCount(Long courseId) {
|
||||
String key = "booking_count:" + courseId;
|
||||
return reactiveRedisTemplate.opsForValue()
|
||||
.get(key)
|
||||
.map(obj -> (Integer) obj)
|
||||
.defaultIfEmpty(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加课程预约人数
|
||||
*/
|
||||
public Mono<Long> incrementBookingCount(Long courseId) {
|
||||
String key = "booking_count:" + courseId;
|
||||
return reactiveRedisTemplate.opsForValue()
|
||||
.increment(key)
|
||||
.doOnSuccess(count -> logger.debug("预约人数增加:courseId={}, count={}", courseId, count));
|
||||
}
|
||||
|
||||
/**
|
||||
* 减少课程预约人数
|
||||
*/
|
||||
public Mono<Long> decrementBookingCount(Long courseId) {
|
||||
String key = "booking_count:" + courseId;
|
||||
return reactiveRedisTemplate.opsForValue()
|
||||
.decrement(key)
|
||||
.doOnSuccess(count -> logger.debug("预约人数减少:courseId={}, count={}", courseId, count));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置课程预约人数(用于从数据库同步)
|
||||
*/
|
||||
public Mono<Void> setBookingCount(Long courseId, Integer count) {
|
||||
String key = "booking_count:" + courseId;
|
||||
return reactiveRedisTemplate.opsForValue()
|
||||
.set(key, count)
|
||||
.doOnSuccess(result -> logger.debug("预约人数已设置:courseId={}, count={}", courseId, count))
|
||||
.then();
|
||||
}
|
||||
}
|
||||
+396
@@ -0,0 +1,396 @@
|
||||
|
||||
package cn.novalon.gym.manage.groupcourse.service.impl;
|
||||
|
||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||
import cn.novalon.gym.manage.common.dto.PageResponse;
|
||||
import cn.novalon.gym.manage.common.util.RedisUtil;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourseBooking;
|
||||
import cn.novalon.gym.manage.groupcourse.enums.CourseEvent;
|
||||
import cn.novalon.gym.manage.groupcourse.enums.CourseStatus;
|
||||
import cn.novalon.gym.manage.groupcourse.handler.GroupCourseStateMachine;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseBookingRepository;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseRepository;
|
||||
import cn.novalon.gym.manage.groupcourse.service.IGroupCourseService;
|
||||
import cn.novalon.gym.manage.member.entity.MemberCard;
|
||||
import cn.novalon.gym.manage.member.entity.MemberCardRecord;
|
||||
import cn.novalon.gym.manage.member.enums.MemberCardType;
|
||||
import cn.novalon.gym.manage.member.repository.MemberCardRepository;
|
||||
import cn.novalon.gym.manage.member.service.IMemberCardRecordService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Service
|
||||
public class GroupCourseService implements IGroupCourseService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(GroupCourseService.class);
|
||||
|
||||
private final IGroupCourseRepository groupCourseRepository;
|
||||
private final IGroupCourseBookingRepository bookingRepository;
|
||||
private final IMemberCardRecordService memberCardRecordService;
|
||||
private final MemberCardRepository memberCardRepository;
|
||||
private final RedisUtil redisUtil;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final GroupCourseStateMachine stateMachine;
|
||||
|
||||
private static final String CACHE_KEY_PREFIX = "group_course:page:";
|
||||
private static final String CACHE_KEY_ID_PREFIX = "group_course:id:";
|
||||
private static final long CACHE_EXPIRE_SECONDS = 300;
|
||||
|
||||
private static final double DEFAULT_GROUP_COURSE_PRICE = 50.0;
|
||||
|
||||
public GroupCourseService(IGroupCourseRepository groupCourseRepository,
|
||||
IGroupCourseBookingRepository bookingRepository,
|
||||
IMemberCardRecordService memberCardRecordService,
|
||||
MemberCardRepository memberCardRepository,
|
||||
RedisUtil redisUtil,
|
||||
ObjectMapper objectMapper,
|
||||
GroupCourseStateMachine stateMachine){
|
||||
this.groupCourseRepository = groupCourseRepository;
|
||||
this.bookingRepository = bookingRepository;
|
||||
this.memberCardRecordService = memberCardRecordService;
|
||||
this.memberCardRepository = memberCardRepository;
|
||||
this.redisUtil = redisUtil;
|
||||
this.objectMapper = objectMapper;
|
||||
this.stateMachine = stateMachine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourse> findById(Long id) {
|
||||
String cacheKey = CACHE_KEY_ID_PREFIX + id;
|
||||
|
||||
return redisUtil.get(cacheKey, String.class)
|
||||
.flatMap(cachedJson -> {
|
||||
if (cachedJson != null) {
|
||||
try {
|
||||
GroupCourse groupCourse = objectMapper.readValue(cachedJson, GroupCourse.class);
|
||||
logger.info("缓存命中 - findById: id={}", id);
|
||||
return Mono.just(groupCourse);
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.warn("缓存解析失败,删除缓存 - id: {}, error: {}", id, e.getMessage());
|
||||
return redisUtil.delete(cacheKey).then(Mono.empty());
|
||||
}
|
||||
}
|
||||
return Mono.empty();
|
||||
})
|
||||
.switchIfEmpty(
|
||||
groupCourseRepository.findByIdAndDeletedAtIsNull(id)
|
||||
.flatMap(groupCourse -> {
|
||||
try {
|
||||
String jsonData = objectMapper.writeValueAsString(groupCourse);
|
||||
return redisUtil.setWithExpire(cacheKey, jsonData, CACHE_EXPIRE_SECONDS)
|
||||
.thenReturn(groupCourse)
|
||||
.doOnSuccess(gc -> logger.debug("缓存已设置 - findById: id={}", id));
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.error("缓存设置失败 - id: {}, error: {}", id, e.getMessage());
|
||||
return Mono.just(groupCourse);
|
||||
}
|
||||
})
|
||||
.doOnSubscribe(sub -> logger.debug("缓存未命中,查询数据库 - findById: id={}", id))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<GroupCourse> findAll() {
|
||||
return groupCourseRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<GroupCourse> findAll(boolean includeDeleted) {
|
||||
if(includeDeleted){
|
||||
return groupCourseRepository.findAll();
|
||||
}else{
|
||||
return groupCourseRepository.findByDeletedAtIsNull();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<PageResponse<GroupCourse>> findByPage(PageRequest pageRequest, boolean includeDeleted) {
|
||||
int page = pageRequest.getPage();
|
||||
int size = pageRequest.getSize();
|
||||
String sort = pageRequest.getSort();
|
||||
String order = pageRequest.getOrder();
|
||||
String keyword = pageRequest.getKeyword() != null ? pageRequest.getKeyword() : "";
|
||||
|
||||
String cacheKey = CACHE_KEY_PREFIX + page + ":" + size + ":" + includeDeleted + ":" + sort + ":" + order + ":" + keyword;
|
||||
|
||||
return redisUtil.get(cacheKey, String.class)
|
||||
.flatMap(cachedJson -> {
|
||||
if (cachedJson != null) {
|
||||
try {
|
||||
PageResponse<GroupCourse> pageResponse = objectMapper.readValue(cachedJson,
|
||||
objectMapper.getTypeFactory().constructParametricType(PageResponse.class, GroupCourse.class));
|
||||
logger.info("缓存命中 - findByPage: key={}", cacheKey);
|
||||
return Mono.just(pageResponse);
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.warn("缓存解析失败,删除缓存 - key: {}, error: {}", cacheKey, e.getMessage());
|
||||
return redisUtil.delete(cacheKey).then(Mono.empty());
|
||||
}
|
||||
}
|
||||
return Mono.empty();
|
||||
})
|
||||
.switchIfEmpty(
|
||||
Mono.defer(() -> {
|
||||
logger.debug("缓存未命中,查询数据库 - findByPage: key={}", cacheKey);
|
||||
Mono<PageResponse<GroupCourse>> resultMono;
|
||||
if (includeDeleted) {
|
||||
resultMono = groupCourseRepository.findByPage(pageRequest);
|
||||
} else {
|
||||
resultMono = groupCourseRepository.findByPageAndNotDeleted(pageRequest);
|
||||
}
|
||||
|
||||
return resultMono.flatMap(pageResponse -> {
|
||||
try {
|
||||
String jsonData = objectMapper.writeValueAsString(pageResponse);
|
||||
return redisUtil.setWithExpire(cacheKey, jsonData, CACHE_EXPIRE_SECONDS)
|
||||
.thenReturn(pageResponse)
|
||||
.doOnSuccess(pr -> logger.debug("缓存已设置 - findByPage: key={}", cacheKey));
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.error("缓存设置失败 - key: {}, error: {}", cacheKey, e.getMessage());
|
||||
return Mono.just(pageResponse);
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourse> create(GroupCourse groupCourse) {
|
||||
return groupCourseRepository.save(groupCourse)
|
||||
.doOnSuccess(course -> logger.info("团课创建成功 - id={}, name={}", course.getId(), course.getCourseName()))
|
||||
.flatMap(course -> clearCache().thenReturn(course))
|
||||
.doOnError(error -> logger.error("团课创建失败 - error: {}", error.getMessage()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourse> update(Long id, GroupCourse groupCourse) {
|
||||
return groupCourseRepository.findByIdAndDeletedAtIsNull(id)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("团课不存在")))
|
||||
.flatMap(existing -> {
|
||||
if (groupCourse.getCourseName() != null) {
|
||||
existing.setCourseName(groupCourse.getCourseName());
|
||||
}
|
||||
if (groupCourse.getCoachId() != null) {
|
||||
existing.setCoachId(groupCourse.getCoachId());
|
||||
}
|
||||
if (groupCourse.getCourseType() != null) {
|
||||
existing.setCourseType(groupCourse.getCourseType());
|
||||
}
|
||||
if (groupCourse.getStartTime() != null) {
|
||||
existing.setStartTime(groupCourse.getStartTime());
|
||||
}
|
||||
if (groupCourse.getEndTime() != null) {
|
||||
existing.setEndTime(groupCourse.getEndTime());
|
||||
}
|
||||
if (groupCourse.getMaxMembers() != null) {
|
||||
existing.setMaxMembers(groupCourse.getMaxMembers());
|
||||
}
|
||||
if (groupCourse.getStatus() != null) {
|
||||
existing.setStatus(groupCourse.getStatus());
|
||||
}
|
||||
if (groupCourse.getLocation() != null) {
|
||||
existing.setLocation(groupCourse.getLocation());
|
||||
}
|
||||
if (groupCourse.getCoverImage() != null) {
|
||||
existing.setCoverImage(groupCourse.getCoverImage());
|
||||
}
|
||||
if (groupCourse.getDescription() != null) {
|
||||
existing.setDescription(groupCourse.getDescription());
|
||||
}
|
||||
if (groupCourse.getPointCardAmount() != null) {
|
||||
existing.setPointCardAmount(groupCourse.getPointCardAmount());
|
||||
}
|
||||
if (groupCourse.getStoredValueAmount() != null) {
|
||||
existing.setStoredValueAmount(groupCourse.getStoredValueAmount());
|
||||
}
|
||||
return groupCourseRepository.update(existing);
|
||||
})
|
||||
.doOnSuccess(course -> logger.info("团课更新成功 - id={}", id))
|
||||
.flatMap(course -> clearCache().thenReturn(course))
|
||||
.doOnError(error -> logger.error("团课更新失败 - id={}, error: {}", id, error.getMessage()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourse> cancel(Long id) {
|
||||
return groupCourseRepository.findByIdAndDeletedAtIsNull(id)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("团课不存在")))
|
||||
.flatMap(course -> {
|
||||
// 使用状态机验证状态转换
|
||||
return stateMachine.validateTransition(course, CourseEvent.CANCEL)
|
||||
.then(Mono.just(course));
|
||||
})
|
||||
.flatMap(course -> {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 检查当前时间是否超过课程开始前24小时
|
||||
// 如果当前时间 > (课程开始时间 - 24小时),则不允许取消
|
||||
if (now.isAfter(course.getStartTime().minusHours(24))) {
|
||||
return Mono.error(new RuntimeException("课程取消需提前24小时"));
|
||||
}
|
||||
|
||||
// 取消课程并返还权益
|
||||
return groupCourseRepository.cancel(id)
|
||||
.flatMap(canceledCourse -> {
|
||||
// 为所有预约该课程的会员返还权益
|
||||
return refundBookingMembers(canceledCourse.getId())
|
||||
.then(Mono.just(canceledCourse));
|
||||
});
|
||||
})
|
||||
.doOnSuccess(course -> logger.info("团课取消成功 - id={}", id))
|
||||
.flatMap(course -> clearCache().thenReturn(course))
|
||||
.doOnError(error -> logger.error("团课取消失败 - id={}, error: {}", id, error.getMessage()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 为预约课程的所有会员返还权益
|
||||
*
|
||||
* @param courseId 课程ID
|
||||
* @return 空Mono
|
||||
*/
|
||||
private Mono<Void> refundBookingMembers(Long courseId) {
|
||||
logger.info("开始为课程预约会员返还权益: courseId={}", courseId);
|
||||
|
||||
return groupCourseRepository.findByIdAndDeletedAtIsNull(courseId)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("课程不存在")))
|
||||
.flatMap(course -> {
|
||||
Integer pointCardAmount = course.getPointCardAmount() != null ? course.getPointCardAmount() : 1;
|
||||
Double storedValueAmount = course.getStoredValueAmount() != null ?
|
||||
course.getStoredValueAmount().doubleValue() : DEFAULT_GROUP_COURSE_PRICE;
|
||||
|
||||
logger.info("课程权益信息: courseId={}, pointCardAmount={}, storedValueAmount={}",
|
||||
courseId, pointCardAmount, storedValueAmount);
|
||||
|
||||
return bookingRepository.findByCourseId(courseId)
|
||||
.filter(booking -> "0".equals(booking.getStatus())) // 只处理已预约状态的记录
|
||||
.flatMap(booking -> {
|
||||
Long memberCardRecordId = booking.getMemberCardRecordId();
|
||||
if (memberCardRecordId == null) {
|
||||
logger.warn("预约记录没有会员卡记录ID: bookingId={}", booking.getId());
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
// 根据会员卡类型返还权益
|
||||
return refundCardUsage(booking.getId(), memberCardRecordId, pointCardAmount, storedValueAmount)
|
||||
.doOnSuccess(unused -> logger.info("会员权益返还成功: bookingId={}, memberId={}",
|
||||
booking.getId(), booking.getMemberId()))
|
||||
.doOnError(error -> logger.error("会员权益返还失败: bookingId={}, memberId={}, error={}",
|
||||
booking.getId(), booking.getMemberId(), error.getMessage()))
|
||||
.onErrorResume(e -> Mono.empty()); // 单个会员返还失败不影响其他会员
|
||||
})
|
||||
.then();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据会员卡类型返还权益
|
||||
*
|
||||
* @param bookingId 预约ID
|
||||
* @param recordId 会员卡记录ID
|
||||
* @param pointCardAmount 次卡返还次数
|
||||
* @param storedValueAmount 储值卡返还金额
|
||||
* @return 空Mono
|
||||
*/
|
||||
private Mono<Void> refundCardUsage(Long bookingId, Long recordId, Integer pointCardAmount, Double storedValueAmount) {
|
||||
return memberCardRecordService.findById(recordId)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("会员卡记录不存在")))
|
||||
.flatMap(record -> {
|
||||
return memberCardRepository.findById(record.getMemberCardId())
|
||||
.flatMap(card -> {
|
||||
MemberCardType cardType = MemberCardType.valueOf(card.getMemberCardType());
|
||||
|
||||
Mono<Void> refundOperation;
|
||||
switch (cardType) {
|
||||
case COUNT_CARD:
|
||||
// 次卡返还次数(基于课程设置的pointCardAmount)
|
||||
logger.debug("返还次卡次数: recordId={}, amount={}", recordId, pointCardAmount);
|
||||
refundOperation = memberCardRecordService.renewCard(recordId, pointCardAmount, 0.0, record.getExpireTime())
|
||||
.then(Mono.empty());
|
||||
break;
|
||||
case STORED_VALUE_CARD:
|
||||
// 储值卡返还金额(基于课程设置的storedValueAmount)
|
||||
logger.debug("返还储值卡金额: recordId={}, amount={}", recordId, storedValueAmount);
|
||||
refundOperation = memberCardRecordService.renewCard(recordId, 0, storedValueAmount, record.getExpireTime())
|
||||
.then(Mono.empty());
|
||||
break;
|
||||
case TIME_CARD:
|
||||
// 时长卡不返还,仅修改预约记录状态
|
||||
logger.debug("时长卡不返还权益,仅更新预约状态: bookingId={}", bookingId);
|
||||
refundOperation = Mono.empty();
|
||||
break;
|
||||
default:
|
||||
return Mono.error(new RuntimeException("不支持的会员卡类型: " + cardType));
|
||||
}
|
||||
|
||||
// 无论哪种卡类型,都需要更新预约记录状态为已取消
|
||||
return refundOperation.then(bookingRepository.updateStatus(bookingId, "1"))
|
||||
.flatMap(rows -> {
|
||||
if (rows == 0) {
|
||||
logger.warn("更新预约状态失败: bookingId={}", bookingId);
|
||||
}
|
||||
return Mono.empty();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourse> signIn(Long courseId, Long memberId) {
|
||||
return groupCourseRepository.findByIdAndDeletedAtIsNull(courseId)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("团课不存在")))
|
||||
.flatMap(course -> {
|
||||
if (course.getStatus() != 0L) {
|
||||
return Mono.error(new RuntimeException("课程状态不允许签到"));
|
||||
}
|
||||
|
||||
if (course.getCurrentMembers() >= course.getMaxMembers()) {
|
||||
return Mono.error(new RuntimeException("课程已满员"));
|
||||
}
|
||||
|
||||
// 检查会员是否已预约此课程
|
||||
return bookingRepository.findValidBooking(courseId, memberId)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("会员未预约此课程")))
|
||||
.flatMap(booking -> {
|
||||
// 更新课程当前人数
|
||||
return groupCourseRepository.updateCurrentMembers(courseId, 1)
|
||||
.flatMap(updatedCourse -> {
|
||||
// 更新预约状态为已出席
|
||||
return bookingRepository.updateStatus(booking.getId(), "2")
|
||||
.thenReturn(updatedCourse);
|
||||
});
|
||||
});
|
||||
})
|
||||
.doOnSuccess(course -> logger.info("团课签到成功 - courseId={}, memberId={}", courseId, memberId))
|
||||
.flatMap(course -> clearCache().thenReturn(course))
|
||||
.doOnError(error -> logger.error("团课签到失败 - courseId={}, memberId={}, error: {}", courseId, memberId, error.getMessage()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> delete(Long id) {
|
||||
// 先查询课程状态,只有已取消的课程才能删除
|
||||
return groupCourseRepository.findByIdAndDeletedAtIsNull(id)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("团课不存在")))
|
||||
.flatMap(course -> {
|
||||
// 检查课程状态是否为已取消(状态码1)
|
||||
if (course.getStatus() == null || !course.getStatus().equals(CourseStatus.CANCELLED.getValue())) {
|
||||
return Mono.error(new RuntimeException("只有已取消的课程才能删除,当前状态: " +
|
||||
(course.getStatus() != null ? course.getStatus() : "未知")));
|
||||
}
|
||||
|
||||
// 删除课程
|
||||
return groupCourseRepository.deleteById(id)
|
||||
.doOnSuccess(v -> logger.info("团课删除成功 - id={}", id))
|
||||
.then(clearCache())
|
||||
.doOnError(error -> logger.error("团课删除失败 - id={}, error: {}", id, error.getMessage()));
|
||||
});
|
||||
}
|
||||
|
||||
private Mono<Void> clearCache() {
|
||||
return redisUtil.deleteByPattern(CACHE_KEY_PREFIX + "*")
|
||||
.then(redisUtil.deleteByPattern(CACHE_KEY_ID_PREFIX + "*")).then();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
spring:
|
||||
application:
|
||||
name: gym-groupCourse
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package cn.novalon.gym.manage.groupcourse;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class GymGroupCourseApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@ package cn.novalon.gym.manage.member.service.impl;
|
||||
import cn.novalon.gym.manage.member.entity.MemberCardRecord;
|
||||
import cn.novalon.gym.manage.member.repository.MemberCardRecordRepository;
|
||||
import cn.novalon.gym.manage.member.service.IMemberCardRecordService;
|
||||
import cn.novalon.gym.manage.member.util.RedisUtil;
|
||||
import cn.novalon.gym.manage.common.util.RedisUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ import cn.novalon.gym.manage.member.repository.MemberCardRecordRepository;
|
||||
import cn.novalon.gym.manage.member.repository.MemberCardRepository;
|
||||
import cn.novalon.gym.manage.member.service.IMemberCardService;
|
||||
import cn.novalon.gym.manage.member.service.IMemberCardTransactionService;
|
||||
import cn.novalon.gym.manage.member.util.RedisUtil;
|
||||
import cn.novalon.gym.manage.common.util.RedisUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
+1
-10
@@ -17,30 +17,21 @@ import cn.novalon.gym.manage.member.service.MemberService;
|
||||
import cn.novalon.gym.manage.member.util.AesUtil;
|
||||
import cn.novalon.gym.manage.member.util.BeanConvertUtil;
|
||||
import cn.novalon.gym.manage.member.util.EsSyncUtils;
|
||||
import cn.novalon.gym.manage.member.util.RedisUtil;
|
||||
import cn.novalon.gym.manage.common.util.RedisUtil;
|
||||
import cn.novalon.gym.manage.member.vo.MemberCardInfoVO;
|
||||
import cn.novalon.gym.manage.member.vo.MemberDetailVO;
|
||||
import cn.novalon.gym.manage.member.vo.MemberInfoVO;
|
||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||
import co.elastic.clients.elasticsearch.core.IndexResponse;
|
||||
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
|
||||
import co.elastic.clients.transport.rest_client.RestClientTransport;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
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;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import cn.novalon.gym.manage.member.entity.RefundApplication;
|
||||
import cn.novalon.gym.manage.member.enums.RefundStatus;
|
||||
import cn.novalon.gym.manage.member.repository.RefundApplicationRepository;
|
||||
import cn.novalon.gym.manage.member.service.IRefundApplicationService;
|
||||
import cn.novalon.gym.manage.member.util.RedisUtil;
|
||||
import cn.novalon.gym.manage.common.util.RedisUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ 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 cn.novalon.gym.manage.member.util.RedisUtil;
|
||||
import cn.novalon.gym.manage.common.util.RedisUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
+1
-3
@@ -4,8 +4,6 @@ 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.common.util.HtmlEscapeUtil;
|
||||
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;
|
||||
@@ -16,7 +14,7 @@ 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.RedisUtil;
|
||||
import cn.novalon.gym.manage.common.util.RedisUtil;
|
||||
import cn.novalon.gym.manage.member.util.WechatPhoneUtil;
|
||||
import cn.novalon.gym.manage.member.vo.WechatLoginVO;
|
||||
import cn.novalon.gym.manage.sys.security.JwtTokenProvider;
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ 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.util.RedisUtil;
|
||||
import cn.novalon.gym.manage.common.util.RedisUtil;
|
||||
import cn.novalon.gym.manage.member.vo.WechatUserInfoVO;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
2026-06-02T14:56:05.966+08:00 TRACE 22380 --- [gym-manage-api] [ctor-http-nio-7] o.s.w.s.adapter.HttpWebHandlerAdapter : [7ce54381-10] HTTP POST "/api/groupCourse/11/cancel", headers={masked}
|
||||
2026-06-02T14:56:05.967+08:00 DEBUG 22380 --- [gym-manage-api] [ parallel-11] o.s.w.s.s.DefaultWebSessionManager : Created new WebSession.
|
||||
2026-06-02T14:56:05.967+08:00 INFO 22380 --- [gym-manage-api] [ parallel-11] c.n.g.m.sys.audit.OperationLogWebFilter : WebFilter 拦截请求: POST /api/groupCourse/11/cancel
|
||||
2026-06-02T14:56:05.967+08:00 INFO 22380 --- [gym-manage-api] [ parallel-11] c.n.g.m.sys.audit.OperationLogWebFilter : 未匹配到操作日志配置,跳过: POST /api/groupCourse/11/cancel
|
||||
2026-06-02T14:56:05.967+08:00 INFO 22380 --- [gym-manage-api] [ parallel-11] c.n.g.m.sys.audit.OperationLogWebFilter : WebFilter 拦截请求: POST /api/groupCourse/11/cancel
|
||||
2026-06-02T14:56:05.967+08:00 INFO 22380 --- [gym-manage-api] [ parallel-11] c.n.g.m.sys.audit.OperationLogWebFilter : 未匹配到操作日志配置,跳过: POST /api/groupCourse/11/cancel
|
||||
2026-06-02T14:56:05.967+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.967+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.967+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/dictionaries" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "PUT" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "DELETE" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/users" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "PUT" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "DELETE" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/users/{id}/action/change-password" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/users/{id}/action/logical-delete" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/users/logical-delete" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/users/action/restore" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/users/{id}/action/restore" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/users/{id}/roles" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/menus" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "PUT" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "DELETE" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/roles" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "PUT" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "DELETE" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/roles/{id}/restore" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/roles/{id}/permissions" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/config" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "PUT" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "DELETE" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/logs/login" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/logs/exception" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/logs/operation" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/auth/login" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/auth/register" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/auth/logout" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/dict/types" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "PUT" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "DELETE" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/dict/data" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "PUT" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "DELETE" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/notices" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "PUT" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "DELETE" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/messages" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "PUT" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "DELETE" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/files/upload" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "DELETE" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/permissions" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "PUT" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "DELETE" does not match against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.969+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/member/auth/miniapp/login" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/member/auth/mp/callback" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "PUT" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/member/phone/bind" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/admin/member/{id}/phone" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "PUT" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/member-cards" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/member-card-records/purchase" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/member-card-records/{recordId}/renew" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/member-card-records/{recordId}/use" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/member-card-records/{recordId}/refund" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/member-card-records/process-expired" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/member-card-transactions" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/groupCourse/page" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "GET" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/groupCourse" does not match against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "PUT" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "DELETE" does not match against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Method "POST" matches against value "POST"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.server.RequestPredicates : Pattern "/api/groupCourse/{id}/cancel" matches against value "/api/groupCourse/11/cancel"
|
||||
2026-06-02T14:56:05.970+08:00 TRACE 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.function.server.RouterFunctions : [7ce54381-10] Matched (POST && /api/groupCourse/{id}/cancel)
|
||||
2026-06-02T14:56:05.970+08:00 DEBUG 22380 --- [gym-manage-api] [ parallel-11] o.s.w.r.f.s.s.RouterFunctionMapping : [7ce54381-10] Mapped to cn.novalon.gym.manage.app.config.SystemRouter$$Lambda/0x00000198019592d8@6903bec9
|
||||
2026-06-02T14:56:05.972+08:00 DEBUG 22380 --- [gym-manage-api] [ parallel-11] o.s.r2dbc.core.DefaultDatabaseClient : Executing SQL statement [SELECT group_course.course_name, group_course.coach_id, group_course.course_type, group_course.start_time, group_course.end_time, group_course.max_members, group_course.current_members, group_course.status, group_course.location, group_course.cover_image, group_course.description, group_course.point_card_amount, group_course.stored_value_amount, group_course.id, group_course.create_by, group_course.update_by, group_course.created_at, group_course.updated_at, group_course.deleted_at FROM group_course WHERE group_course.id = $1 AND (group_course.deleted_at IS NULL)]
|
||||
2026-06-02T14:56:05.976+08:00 INFO 22380 --- [gym-manage-api] [actor-tcp-nio-5] c.n.g.m.g.c.GroupCourseConverter : 转换bean,entity-domain:
|
||||
2026-06-02T14:56:05.976+08:00 ERROR 22380 --- [gym-manage-api] [actor-tcp-nio-5] c.n.g.m.g.s.impl.GroupCourseService : 团课取消失败 - id=11, error: 课程取消需提前24小时
|
||||
2026-06-02T14:56:05.976+08:00 TRACE 22380 --- [gym-manage-api] [actor-tcp-nio-5] org.springframework.web.HttpLogging : [7ce54381-10] Encoding [{success=false, message=课程取消需提前24小时}]
|
||||
2026-06-02T14:56:05.976+08:00 TRACE 22380 --- [gym-manage-api] [actor-tcp-nio-5] o.s.w.s.adapter.HttpWebHandlerAdapter : [7ce54381-10] Completed 400 BAD_REQUEST, headers={masked}
|
||||
2026-06-02T14:56:05.976+08:00 TRACE 22380 --- [gym-manage-api] [actor-tcp-nio-5] org.springframework.web.HttpLogging : [7ce54381-1, L:/[0:0:0:0:0:0:0:1]:8084 - R:/[0:0:0:0:0:0:0:1]:57674] Handling completed
|
||||
@@ -143,6 +143,12 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.novalon.gym.manage</groupId>
|
||||
<artifactId>gym-groupCourse</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
+4
-1
@@ -13,17 +13,20 @@ import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||
import org.springframework.data.elasticsearch.repository.config.EnableReactiveElasticsearchRepositories;
|
||||
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.web.server.WebFilter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootApplication(scanBasePackages = "cn.novalon.gym.manage", exclude = {
|
||||
ReactiveUserDetailsServiceAutoConfiguration.class })
|
||||
@EnableScheduling
|
||||
@EnableR2dbcRepositories(basePackages = {
|
||||
"cn.novalon.gym.manage.db.dao",
|
||||
"cn.novalon.gym.manage.sys.audit.repository" ,
|
||||
"cn.novalon.gym.manage.gymmembercard.dao",
|
||||
"cn.novalon.gym.manage.member.repository"
|
||||
"cn.novalon.gym.manage.member.repository",
|
||||
"cn.novalon.gym.manage.groupcourse.dao"
|
||||
})
|
||||
@EnableReactiveElasticsearchRepositories(basePackages = "cn.novalon.gym.manage.member.es.repository")
|
||||
public class ManageApplication {
|
||||
|
||||
+26
-1
@@ -2,6 +2,8 @@ package cn.novalon.gym.manage.app.config;
|
||||
|
||||
|
||||
import cn.novalon.gym.manage.file.handler.SysFileHandler;
|
||||
import cn.novalon.gym.manage.groupcourse.handler.GroupCourseBookingHandler;
|
||||
import cn.novalon.gym.manage.groupcourse.handler.GroupCourseHandler;
|
||||
import cn.novalon.gym.manage.member.handler.MemberCardHandler;
|
||||
import cn.novalon.gym.manage.member.handler.MemberCardRecordHandler;
|
||||
import cn.novalon.gym.manage.member.handler.MemberCardTransactionHandler;
|
||||
@@ -62,7 +64,9 @@ public class SystemRouter {
|
||||
PasswordDiagnosticHandler passwordDiagnosticHandler,
|
||||
MemberCardHandler memberCardHandler,
|
||||
MemberCardRecordHandler memberCardRecordHandler,
|
||||
MemberCardTransactionHandler memberCardTransactionHandler) {
|
||||
MemberCardTransactionHandler memberCardTransactionHandler,
|
||||
GroupCourseHandler groupCourseHandler,
|
||||
GroupCourseBookingHandler groupCourseBookingHandler) {
|
||||
|
||||
return route()
|
||||
// ========== 诊断路由 ==========
|
||||
@@ -249,6 +253,27 @@ public class SystemRouter {
|
||||
.GET("/api/member-card-transactions/statistics/deduct/{cardId}", memberCardTransactionHandler::getDeductCountByCardId)
|
||||
.GET("/api/member-card-transactions/statistics/renew", memberCardTransactionHandler::getRenewAmountByTimeRange)
|
||||
.GET("/api/member-card-transactions/statistics/purchase/{memberId}", memberCardTransactionHandler::getPurchaseAmountByMember)
|
||||
|
||||
// ========================================
|
||||
// ========== 团课管理路由 =================
|
||||
// ========================================
|
||||
|
||||
// ===== 团课课程管理 =====
|
||||
.GET("/api/groupCourse/list", groupCourseHandler::getAllGroupCourse)
|
||||
.POST("/api/groupCourse/page", groupCourseHandler::getGroupCoursesByPage)
|
||||
.GET("/api/groupCourse/{id}", groupCourseHandler::getGroupCourseById)
|
||||
.POST("/api/groupCourse", groupCourseHandler::createGroupCourse)
|
||||
.PUT("/api/groupCourse/{id}", groupCourseHandler::updateGroupCourse)
|
||||
.DELETE("/api/groupCourse/{id}", groupCourseHandler::deleteGroupCourse)
|
||||
.POST("/api/groupCourse/{id}/cancel", groupCourseHandler::cancelGroupCourse)
|
||||
.POST("/api/groupCourse/{courseId}/signin", groupCourseHandler::signIn)
|
||||
|
||||
// ===== 团课预约管理 =====
|
||||
.POST("/api/groupCourse/book", groupCourseBookingHandler::bookCourse)
|
||||
.POST("/api/groupCourse/booking/{bookingId}/cancel", groupCourseBookingHandler::cancelBooking)
|
||||
.GET("/api/groupCourse/bookings/member/{memberId}", groupCourseBookingHandler::getBookingsByMemberId)
|
||||
.GET("/api/groupCourse/bookings/{bookingId}", groupCourseBookingHandler::getBookingById)
|
||||
.GET("/api/groupCourse/bookings/course/{courseId}", groupCourseBookingHandler::getBookingsByCourseId)
|
||||
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ spring:
|
||||
url: jdbc:postgresql://localhost:55432/manage_system
|
||||
user: novalon
|
||||
password: novalon123
|
||||
enabled: false
|
||||
enabled: true
|
||||
locations: classpath:db/migration
|
||||
baseline-on-migrate: true
|
||||
validate-on-migrate: true
|
||||
|
||||
@@ -29,7 +29,7 @@ spring:
|
||||
password: ${DB_PASSWORD:novalon123}
|
||||
driver-class-name: org.postgresql.Driver
|
||||
flyway:
|
||||
enabled: false
|
||||
enabled: true
|
||||
locations: classpath:db/migration
|
||||
baseline-on-migrate: true
|
||||
baseline-version: 0
|
||||
@@ -38,11 +38,25 @@ spring:
|
||||
user:
|
||||
name: disabled
|
||||
password: disabled
|
||||
data:
|
||||
redis:
|
||||
host: ${REDIS_HOST:localhost}
|
||||
port: ${REDIS_PORT:6379}
|
||||
password: ${REDIS_PASSWORD:novalon123}
|
||||
timeout: 5000
|
||||
lettuce:
|
||||
pool:
|
||||
max-active: 8 # 最大连接数
|
||||
max-idle: 8 # 最大空闲连接
|
||||
min-idle: 0 # 最小空闲连接
|
||||
max-wait: -1ms # 连接等待时间
|
||||
profiles:
|
||||
active: dev
|
||||
config:
|
||||
import: classpath:member-config.yml
|
||||
|
||||
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package cn.novalon.gym.manage.member.config;
|
||||
package cn.novalon.gym.manage.common.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
+9
-1
@@ -1,4 +1,4 @@
|
||||
package cn.novalon.gym.manage.member.util;
|
||||
package cn.novalon.gym.manage.common.util;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.ReactiveRedisTemplate;
|
||||
@@ -69,4 +69,12 @@ public class RedisUtil {
|
||||
public Mono<Boolean> expire(String key, long timeoutSeconds) {
|
||||
return reactiveRedisTemplate.expire(key, Duration.ofSeconds(timeoutSeconds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据通配符模式删除key
|
||||
*/
|
||||
public Mono<Long> deleteByPattern(String pattern) {
|
||||
return reactiveRedisTemplate.keys(pattern)
|
||||
.flatMap(keys -> reactiveRedisTemplate.delete(keys)).count();
|
||||
}
|
||||
}
|
||||
@@ -99,6 +99,8 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
+1
@@ -10,6 +10,7 @@ import cn.novalon.gym.manage.sys.core.query.SysUserQuery;
|
||||
import cn.novalon.gym.manage.sys.core.repository.ISysUserRepository;
|
||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||
import cn.novalon.gym.manage.common.dto.PageResponse;
|
||||
import cn.novalon.gym.manage.sys.dto.response.UserResponse;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
||||
import org.springframework.data.relational.core.query.Query;
|
||||
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
-- V10: 团课预约业务场景测试数据
|
||||
-- 测试场景:
|
||||
-- 1. 用户A刚刚注册,在没有任何会员卡的情况下申请团课预约
|
||||
-- 2. 用户B已有时长卡,但已经过期
|
||||
-- 3. 会员C有时长卡,未过期
|
||||
-- 4. 会员D有次数卡,但次数卡耗尽次数
|
||||
-- 5. 会员E有次数卡,且次数充足
|
||||
-- 6. 会员F有储值卡,但余额不足以支付其预约的团课
|
||||
-- 7. 会员G有储值卡,余额充足
|
||||
|
||||
-- ============================================
|
||||
-- 1. 创建测试会员用户 (A-G)
|
||||
-- ============================================
|
||||
|
||||
INSERT INTO member_user (member_no, nickname, phone, gender, is_deleted, created_at, updated_at) VALUES
|
||||
('MEM_TEST_A', '用户A_无卡新用户', '13800001001', 1, false, '2026-06-02 10:00:00', '2026-06-02 10:00:00'),
|
||||
('MEM_TEST_B', '用户B_过期时长卡', '13800001002', 1, false, '2026-05-01 10:00:00', '2026-05-01 10:00:00'),
|
||||
('MEM_TEST_C', '会员C_有效时长卡', '13800001003', 2, false, '2026-05-01 10:00:00', '2026-05-01 10:00:00'),
|
||||
('MEM_TEST_D', '会员D_次数用尽', '13800001004', 1, false, '2026-05-01 10:00:00', '2026-05-01 10:00:00'),
|
||||
('MEM_TEST_E', '会员E_次数充足', '13800001005', 2, false, '2026-05-01 10:00:00', '2026-05-01 10:00:00'),
|
||||
('MEM_TEST_F', '会员F_储值卡余额不足', '13800001006', 1, false, '2026-05-01 10:00:00', '2026-05-01 10:00:00'),
|
||||
('MEM_TEST_G', '会员G_储值卡余额充足', '13800001007', 2, false, '2026-05-01 10:00:00', '2026-05-01 10:00:00');
|
||||
|
||||
-- ============================================
|
||||
-- 2. 团课课程测试数据(用于预约测试)
|
||||
-- ============================================
|
||||
|
||||
-- 团课A: 收费类型为次数卡(点卡额度=1)
|
||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, description, point_card_amount, stored_value_amount, create_by, created_at, updated_at) VALUES
|
||||
('燃脂搏击_次数卡课程', 102, 2, '2026-06-10 19:30:00', '2026-06-10 20:30:00', 20, 0, '0', '综合训练区', '高强度间歇训练,配合音乐快速燃脂,消耗1次', 1, 0.00, 'admin', '2026-06-01 10:00:00', '2026-06-01 10:00:00');
|
||||
|
||||
-- 团课B: 收费类型为储值卡(储值额度=50.00)
|
||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, description, point_card_amount, stored_value_amount, create_by, created_at, updated_at) VALUES
|
||||
('高端普拉提_储值卡课程', 103, 1, '2026-06-11 19:00:00', '2026-06-11 20:00:00', 15, 0, '0', '普拉提教室', '精准训练核心肌群,消耗储值50元', 0, 20.00, 'admin', '2026-06-01 10:00:00', '2026-06-01 10:00:00');
|
||||
|
||||
-- ============================================
|
||||
-- 3. 会员卡类型定义
|
||||
-- ============================================
|
||||
|
||||
INSERT INTO member_card (member_card_name, member_card_type, member_card_price, member_card_validity_days, member_card_total_times, member_card_amount, member_card_status, extra_config, created_at, updated_at) VALUES
|
||||
('30天时长卡', 'TIME_CARD', 299.00, 30, NULL, NULL, 1, '{}', '2026-01-01 00:00:00', '2026-01-01 00:00:00'),
|
||||
('10次卡', 'COUNT_CARD', 499.00, NULL, 10, NULL, 1, '{}', '2026-01-01 00:00:00', '2026-01-01 00:00:00'),
|
||||
('储值卡500', 'STORED_VALUE_CARD', 500.00, NULL, NULL, 500.00, 1, '{}', '2026-01-01 00:00:00', '2026-01-01 00:00:00');
|
||||
|
||||
-- ============================================
|
||||
-- 4. 会员卡记录测试数据
|
||||
-- ============================================
|
||||
|
||||
-- 场景2: 用户B - 时长卡已过期 (expire_time < 当前时间)
|
||||
-- 购买于30天前,有效期30天,现已过期
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_B'), (SELECT member_card_id FROM member_card WHERE member_card_name = '30天时长卡'), 'EXPIRED', 0, 0.00, '2026-05-31 23:59:59', '2026-05-01 10:00:00', 0, '{}', '2026-05-01 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
-- 场景3: 会员C - 时长卡未过期 (expire_time > 当前时间)
|
||||
-- 购买于今天,有效期30天,还有30天有效期
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_C'), (SELECT member_card_id FROM member_card WHERE member_card_name = '30天时长卡'), 'ACTIVE', 0, 0.00, '2026-07-02 23:59:59', '2026-06-02 10:00:00', 0, '{}', '2026-06-02 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
-- 场景4: 会员D - 次数卡耗尽 (remaining_times = 0)
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_D'), (SELECT member_card_id FROM member_card WHERE member_card_name = '10次卡'), 'ACTIVE', 0, 0.00, '2026-12-31 23:59:59', '2026-05-01 10:00:00', 0, '{}', '2026-05-01 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
-- 场景5: 会员E - 次数卡充足 (remaining_times >= point_card_amount)
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_E'), (SELECT member_card_id FROM member_card WHERE member_card_name = '10次卡'), 'ACTIVE', 5, 0.00, '2026-12-31 23:59:59', '2026-05-01 10:00:00', 0, '{}', '2026-05-01 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
-- 场景6: 会员F - 储值卡余额不足 (remaining_amount < stored_value_amount of course)
|
||||
-- 团课B收费50元,但会员F储值卡只有30元
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_F'), (SELECT member_card_id FROM member_card WHERE member_card_name = '储值卡500'), 'ACTIVE', 0, 30.00, '2027-06-02 23:59:59', '2026-05-01 10:00:00', 0, '{}', '2026-05-01 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
-- 场景7: 会员G - 储值卡余额充足 (remaining_amount >= stored_value_amount of course)
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_G'), (SELECT member_card_id FROM member_card WHERE member_card_name = '储值卡500'), 'ACTIVE', 0, 200.00, '2027-06-02 23:59:59', '2026-05-01 10:00:00', 0, '{}', '2026-05-01 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
-- ============================================
|
||||
-- 5. 测试场景说明
|
||||
-- ============================================
|
||||
|
||||
-- 场景1: 用户A无会员卡 -> 预约团课时应提示"无可用会员卡"
|
||||
-- 场景2: 用户B时长卡已过期 -> 预约团课时应提示"会员卡已过期"
|
||||
-- 场景3: 会员C时长卡有效 -> 可以正常预约次数卡团课
|
||||
-- 场景4: 会员D次数为0 -> 预约团课时应提示"剩余次数不足"
|
||||
-- 场景5: 会员E次数充足 -> 可以正常预约次数卡团课
|
||||
-- 场景6: 会员F储值卡余额30元,团课需50元 -> 预约时应提示"余额不足"
|
||||
-- 场景7: 会员G储值卡余额200元,团课需50元 -> 可以正常预约储值卡团课
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
-- V11: 团课预约取消业务场景测试数据
|
||||
-- 测试场景:
|
||||
-- 1. 用户张三使用时长卡预约了团课,需要取消预约
|
||||
-- 2. 用户李四使用次数卡预约了团课,需要取消预约
|
||||
-- 3. 用户王五使用储值卡预约了团课,需要取消预约
|
||||
|
||||
-- ============================================
|
||||
-- 1. 创建测试会员用户 (张三、李四、王五)
|
||||
-- ============================================
|
||||
|
||||
INSERT INTO member_user (member_no, nickname, phone, gender, is_deleted, created_at, updated_at) VALUES
|
||||
('MEM_TEST_ZHANG', '张三_时长卡用户', '13800002001', 1, false, '2026-06-02 10:00:00', '2026-06-02 10:00:00'),
|
||||
('MEM_TEST_LI', '李四_次数卡用户', '13800002002', 1, false, '2026-06-02 10:00:00', '2026-06-02 10:00:00'),
|
||||
('MEM_TEST_WANG', '王五_储值卡用户', '13800002003', 2, false, '2026-06-02 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
-- ============================================
|
||||
-- 2. 确保会员卡类型已存在(如果不存在则创建)
|
||||
-- ============================================
|
||||
|
||||
-- 时长卡类型(30天)
|
||||
INSERT INTO member_card (member_card_name, member_card_type, member_card_price, member_card_validity_days, member_card_total_times, member_card_amount, member_card_status, extra_config, created_at, updated_at)
|
||||
SELECT '30天时长卡', 'TIME_CARD', 299.00, 30, NULL, NULL, 1, '{}', '2026-01-01 00:00:00', '2026-01-01 00:00:00'
|
||||
WHERE NOT EXISTS (SELECT 1 FROM member_card WHERE member_card_name = '30天时长卡');
|
||||
|
||||
-- 次数卡类型(10次)
|
||||
INSERT INTO member_card (member_card_name, member_card_type, member_card_price, member_card_validity_days, member_card_total_times, member_card_amount, member_card_status, extra_config, created_at, updated_at)
|
||||
SELECT '10次卡', 'COUNT_CARD', 499.00, NULL, 10, NULL, 1, '{}', '2026-01-01 00:00:00', '2026-01-01 00:00:00'
|
||||
WHERE NOT EXISTS (SELECT 1 FROM member_card WHERE member_card_name = '10次卡');
|
||||
|
||||
-- 储值卡类型(500元)
|
||||
INSERT INTO member_card (member_card_name, member_card_type, member_card_price, member_card_validity_days, member_card_total_times, member_card_amount, member_card_status, extra_config, created_at, updated_at)
|
||||
SELECT '储值卡500', 'STORED_VALUE_CARD', 500.00, NULL, NULL, 500.00, 1, '{}', '2026-01-01 00:00:00', '2026-01-01 00:00:00'
|
||||
WHERE NOT EXISTS (SELECT 1 FROM member_card WHERE member_card_name = '储值卡500');
|
||||
|
||||
-- ============================================
|
||||
-- 3. 为测试用户分配会员卡
|
||||
-- ============================================
|
||||
|
||||
-- 张三:时长卡(有效期内)
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_ZHANG'),
|
||||
(SELECT member_card_id FROM member_card WHERE member_card_name = '30天时长卡'),
|
||||
'ACTIVE', 0, 0.00, '2026-07-02 23:59:59', '2026-06-02 10:00:00', 0, '{}', '2026-06-02 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
-- 李四:次数卡(剩余5次)
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_LI'),
|
||||
(SELECT member_card_id FROM member_card WHERE member_card_name = '10次卡'),
|
||||
'ACTIVE', 5, 0.00, '2026-12-31 23:59:59', '2026-05-01 10:00:00', 0, '{}', '2026-05-01 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
-- 王五:储值卡(余额200元)
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_WANG'),
|
||||
(SELECT member_card_id FROM member_card WHERE member_card_name = '储值卡500'),
|
||||
'ACTIVE', 0, 200.00, '2027-06-02 23:59:59', '2026-05-01 10:00:00', 0, '{}', '2026-05-01 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
-- ============================================
|
||||
-- 4. 创建用于取消预约测试的团课
|
||||
-- ============================================
|
||||
|
||||
-- 团课X: 时长卡可用课程(使用次数卡支付,时长卡会员可预约)
|
||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, description, point_card_amount, stored_value_amount, create_by, created_at, updated_at) VALUES
|
||||
('晚间瑜伽_取消测试', 101, 1, '2026-06-15 19:00:00', '2026-06-15 20:00:00', 20, 0, '0', '瑜伽教室', '适合所有级别的瑜伽课程,用于测试取消预约功能', 1, 30.00, 'admin', '2026-06-02 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
-- ============================================
|
||||
-- 5. 创建已预约的记录(状态为0-已预约)
|
||||
-- ============================================
|
||||
|
||||
-- 张三使用时长卡预约团课(状态:已预约)
|
||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at) VALUES
|
||||
((SELECT id FROM group_course WHERE course_name = '晚间瑜伽_取消测试'),
|
||||
(SELECT id FROM member_user WHERE member_no = 'MEM_TEST_ZHANG'),
|
||||
(SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_TEST_ZHANG')),
|
||||
'2026-06-02 11:00:00', '0', '晚间瑜伽_取消测试', '2026-06-15 19:00:00', '2026-06-15 20:00:00', '瑜伽教室',
|
||||
'2026-06-02 11:00:00', '2026-06-02 11:00:00');
|
||||
|
||||
-- 李四使用次数卡预约团课(状态:已预约)
|
||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at) VALUES
|
||||
((SELECT id FROM group_course WHERE course_name = '晚间瑜伽_取消测试'),
|
||||
(SELECT id FROM member_user WHERE member_no = 'MEM_TEST_LI'),
|
||||
(SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_TEST_LI')),
|
||||
'2026-06-02 11:30:00', '0', '晚间瑜伽_取消测试', '2026-06-15 19:00:00', '2026-06-15 20:00:00', '瑜伽教室',
|
||||
'2026-06-02 11:30:00', '2026-06-02 11:30:00');
|
||||
|
||||
-- 王五使用储值卡预约团课(状态:已预约)
|
||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at) VALUES
|
||||
((SELECT id FROM group_course WHERE course_name = '晚间瑜伽_取消测试'),
|
||||
(SELECT id FROM member_user WHERE member_no = 'MEM_TEST_WANG'),
|
||||
(SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_TEST_WANG')),
|
||||
'2026-06-02 12:00:00', '0', '晚间瑜伽_取消测试', '2026-06-15 19:00:00', '2026-06-15 20:00:00', '瑜伽教室',
|
||||
'2026-06-02 12:00:00', '2026-06-02 12:00:00');
|
||||
|
||||
-- ============================================
|
||||
-- 6. 更新团课当前预约人数
|
||||
-- ============================================
|
||||
|
||||
UPDATE group_course
|
||||
SET current_members = current_members + 3
|
||||
WHERE course_name = '晚间瑜伽_取消测试';
|
||||
|
||||
-- ============================================
|
||||
-- 测试数据说明
|
||||
-- ============================================
|
||||
-- 用户信息:
|
||||
-- 张三 (MEM_TEST_ZHANG): 13800002001 - 持有有效期内的时长卡
|
||||
-- 李四 (MEM_TEST_LI): 13800002002 - 持有次数卡(剩余5次)
|
||||
-- 王五 (MEM_TEST_WANG): 13800002003 - 持有储值卡(余额200元)
|
||||
|
||||
-- 测试场景:
|
||||
-- 1. 张三使用时长卡预约了团课 -> 取消预约 -> 应恢复时长卡状态,释放课程名额
|
||||
-- 2. 李四使用次数卡预约了团课 -> 取消预约 -> 应返还扣除的次数,释放课程名额
|
||||
-- 3. 王五使用储值卡预约了团课 -> 取消预约 -> 应返还扣除的金额,释放课程名额
|
||||
|
||||
-- 预约记录状态说明:
|
||||
-- status = '0' 表示已预约
|
||||
-- status = '1' 表示已取消(取消后应更新为此状态)
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
-- V12: 团课预约时间冲突测试数据
|
||||
-- 测试场景:会员预约两个时间重叠的团课时,系统应检测到时间冲突并拒绝预约
|
||||
|
||||
-- ============================================
|
||||
-- 1. 创建测试会员
|
||||
-- ============================================
|
||||
|
||||
INSERT INTO member_user (member_no, nickname, phone, gender, is_deleted, created_at, updated_at) VALUES
|
||||
('MEM_TIME_CONFLICT', '时间冲突测试会员', '13800009999', 1, false, '2026-06-02 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
-- ============================================
|
||||
-- 2. 创建时间冲突的团课
|
||||
-- ============================================
|
||||
|
||||
-- 团课A: 6月15日 13:00 - 15:00
|
||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, description, point_card_amount, stored_value_amount, create_by, created_at, updated_at) VALUES
|
||||
('时间冲突测试_A_13点-15点', 102, 2, '2026-06-15 13:00:00', '2026-06-15 15:00:00', 20, 0, '0', '综合训练区', '测试用团课A,用于验证时间冲突检测', 1, 0.00, 'admin', '2026-06-02 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
-- 团课B: 6月15日 14:00 - 16:00 (与团课A时间重叠)
|
||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, description, point_card_amount, stored_value_amount, create_by, created_at, updated_at) VALUES
|
||||
('时间冲突测试_B_14点-16点', 103, 1, '2026-06-15 14:00:00', '2026-06-15 16:00:00', 15, 0, '0', '普拉提教室', '测试用团课B,与团课A时间重叠(14:00-15:00)', 1, 0.00, 'admin', '2026-06-02 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
-- 团课C: 6月15日 10:00 - 12:00 (不冲突,作为对照)
|
||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, description, point_card_amount, stored_value_amount, create_by, created_at, updated_at) VALUES
|
||||
('时间冲突测试_C_10点-12点', 101, 1, '2026-06-15 10:00:00', '2026-06-15 12:00:00', 15, 0, '0', '瑜伽教室', '测试用团课C,与团课A/B不冲突', 1, 0.00, 'admin', '2026-06-02 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
-- ============================================
|
||||
-- 3. 会员卡记录(用于预约)
|
||||
-- ============================================
|
||||
|
||||
-- 为时间冲突测试会员创建有效次数卡
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TIME_CONFLICT'), (SELECT member_card_id FROM member_card WHERE member_card_name = '10次卡'), 'ACTIVE', 10, 0.00, '2026-12-31 23:59:59', '2026-06-02 10:00:00', 0, '{}', '2026-06-02 10:00:00', '2026-06-02 10:00:00');
|
||||
|
||||
-- ============================================
|
||||
-- 4. 测试场景说明
|
||||
-- ============================================
|
||||
--
|
||||
-- 测试步骤:
|
||||
-- 1. 使用会员 MEM_TIME_CONFLICT 预约团课A (course_name='时间冲突测试_A_13点-15点')
|
||||
-- → 预期:预约成功
|
||||
--
|
||||
-- 2. 使用会员 MEM_TIME_CONFLICT 预约团课B (course_name='时间冲突测试_B_14点-16点')
|
||||
-- → 预期:预约失败,提示时间冲突(14:00-15:00与已预约的团课A重叠)
|
||||
--
|
||||
-- 3. 使用会员 MEM_TIME_CONFLICT 预约团课C (course_name='时间冲突测试_C_10点-12点')
|
||||
-- → 预期:预约成功(与团课A时间不冲突)
|
||||
--
|
||||
-- 时间冲突判断逻辑:
|
||||
-- 新课程开始时间 < 已预约课程结束时间 AND 新课程结束时间 > 已预约课程开始时间
|
||||
-- 即:newStartTime < existingEndTime AND newEndTime > existingStartTime
|
||||
--
|
||||
-- 本测试数据中的时间关系:
|
||||
-- - 团课A: 13:00 - 15:00
|
||||
-- - 团课B: 14:00 - 16:00
|
||||
-- → 14:00 < 15:00 AND 16:00 > 13:00 → 冲突
|
||||
-- - 团课C: 10:00 - 12:00
|
||||
-- → 10:00 < 15:00 AND 12:00 > 13:00 → 12:00 > 13:00 不成立 → 不冲突
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
-- ============================================
|
||||
-- 团课相关表
|
||||
-- ============================================
|
||||
|
||||
-- 团课课程表
|
||||
CREATE TABLE IF NOT EXISTS group_course (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
course_name VARCHAR(100) NOT NULL,
|
||||
coach_id BIGINT,
|
||||
course_type BIGINT,
|
||||
start_time TIMESTAMP NOT NULL,
|
||||
end_time TIMESTAMP NOT NULL,
|
||||
max_members INTEGER DEFAULT 20,
|
||||
current_members INTEGER DEFAULT 0,
|
||||
status VARCHAR(1) DEFAULT '0',
|
||||
location VARCHAR(255),
|
||||
cover_image VARCHAR(500),
|
||||
description TEXT,
|
||||
point_card_amount INTEGER DEFAULT 1,
|
||||
stored_value_amount DECIMAL(10,2) 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 group_course_booking (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
course_id BIGINT NOT NULL,
|
||||
member_id BIGINT NOT NULL,
|
||||
member_card_id BIGINT NOT NULL,
|
||||
booking_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
status VARCHAR(1) DEFAULT '0',
|
||||
cancel_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
|
||||
);
|
||||
|
||||
COMMENT ON TABLE group_course IS '团课课程表';
|
||||
COMMENT ON COLUMN group_course.id IS '主键ID';
|
||||
COMMENT ON COLUMN group_course.course_name IS '课程名称';
|
||||
COMMENT ON COLUMN group_course.coach_id IS '教练ID(关联sys_user)';
|
||||
COMMENT ON COLUMN group_course.course_type IS '课程类型(如瑜伽/普拉提/动感单车)';
|
||||
COMMENT ON COLUMN group_course.start_time IS '开始时间';
|
||||
COMMENT ON COLUMN group_course.end_time IS '结束时间';
|
||||
COMMENT ON COLUMN group_course.max_members IS '最大参与人数';
|
||||
COMMENT ON COLUMN group_course.current_members IS '当前参与人数';
|
||||
COMMENT ON COLUMN group_course.status IS '状态(0正常 1已取消 2已结束)';
|
||||
COMMENT ON COLUMN group_course.location IS '上课地点';
|
||||
COMMENT ON COLUMN group_course.cover_image IS '封面图URL';
|
||||
COMMENT ON COLUMN group_course.description IS '课程描述';
|
||||
COMMENT ON COLUMN group_course.point_card_amount IS '点卡额度(消耗次数)';
|
||||
COMMENT ON COLUMN group_course.stored_value_amount IS '储值卡额度(消耗金额)';
|
||||
COMMENT ON COLUMN group_course.create_by IS '创建人';
|
||||
COMMENT ON COLUMN group_course.update_by IS '更新人';
|
||||
COMMENT ON COLUMN group_course.created_at IS '创建时间';
|
||||
COMMENT ON COLUMN group_course.updated_at IS '更新时间';
|
||||
COMMENT ON COLUMN group_course.deleted_at IS '删除时间(软删除)';
|
||||
|
||||
COMMENT ON TABLE group_course_booking IS '团课预约记录表';
|
||||
COMMENT ON COLUMN group_course_booking.id IS '主键ID';
|
||||
COMMENT ON COLUMN group_course_booking.course_id IS '团课ID';
|
||||
COMMENT ON COLUMN group_course_booking.member_id IS '用户ID';
|
||||
COMMENT ON COLUMN group_course_booking.member_card_id IS '会员卡ID';
|
||||
COMMENT ON COLUMN group_course_booking.booking_time IS '预约时间';
|
||||
COMMENT ON COLUMN group_course_booking.status IS '状态(0已预约 1已取消 2已出席 3缺席)';
|
||||
COMMENT ON COLUMN group_course_booking.cancel_time IS '取消时间';
|
||||
COMMENT ON COLUMN group_course_booking.create_by IS '创建人';
|
||||
COMMENT ON COLUMN group_course_booking.update_by IS '更新人';
|
||||
COMMENT ON COLUMN group_course_booking.created_at IS '创建时间';
|
||||
COMMENT ON COLUMN group_course_booking.updated_at IS '更新时间';
|
||||
COMMENT ON COLUMN group_course_booking.deleted_at IS '删除时间(软删除)';
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
-- 场景1: 0人预约,可预约(正常状态,6月15日,距开始还有14天)
|
||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, create_by, created_at, updated_at) VALUES
|
||||
('极速燃脂单车', 104, 2, '2026-06-02 16:45:00', '2026-06-15 20:20:00', 25, 0, 0, '单车房', '/images/spinning.jpg', '跟随音乐节奏变换阻力和速度,体验爬坡与冲刺的快感,一节课消耗800大卡。', 'admin', '2026-06-01 11:00:00', '2026-06-01 11:00:00');
|
||||
|
||||
-- 场景2: 已有人预约,可预约(正常状态,6月12日,5/15人)
|
||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, create_by, created_at, updated_at) VALUES
|
||||
('清晨流瑜伽', 101, 1, '2026-06-12 09:00:00', '2026-06-12 10:30:00', 15, 5, 0, 'A座3楼瑜伽教室', '/images/yoga_flow.jpg', '适合有一定基础的学员,通过流畅的体式连接呼吸,唤醒身体能量。', 'admin', '2026-06-01 10:00:00', '2026-06-01 10:00:00');
|
||||
|
||||
-- 场景3: 满员,不可预约(正常状态但已满员,6月10日,20/20人)
|
||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, create_by, created_at, updated_at) VALUES
|
||||
('燃脂搏击', 102, 2, '2026-06-10 18:30:00', '2026-06-10 19:30:00', 20, 20, 0, '综合训练区', '/images/kickboxing.jpg', '高强度间歇训练,配合音乐快速燃脂,释放压力。名额已满,无法预约。', 'coach_zhang', '2026-06-01 14:30:00', '2026-06-01 14:30:00');
|
||||
|
||||
-- 场景4: 超出可预约时间,不可预约(正常状态但距开始不足30分钟)
|
||||
-- 当前时间: 2026-06-01 15:00,课程开始: 2026-06-01 15:20
|
||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, create_by, created_at, updated_at) VALUES
|
||||
('哈他瑜伽', 101, 1, '2026-06-01 15:20:00', '2026-06-01 16:50:00', 12, 3, 0, '瑜伽教室B', '/images/hatha_yoga.jpg', '基础哈他瑜伽,适合所有级别。距开始不足30分钟,已停止预约。', 'coach_li', '2026-06-01 08:00:00', '2026-06-01 08:00:00');
|
||||
|
||||
-- 场景5: 课程已取消,不可预约(status=1)
|
||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, create_by, created_at, updated_at) VALUES
|
||||
('周末冥想修复', 101, 1, '2026-06-20 15:00:00', '2026-06-20 16:00:00', 12, 3, 1, '冥想室', '/images/meditation.jpg', '通过呼吸和正念冥想,深度放松身心。该课程已被取消。', 'coach_wang', '2026-05-28 08:00:00', '2026-05-28 08:00:00');
|
||||
|
||||
-- 场景6: 课程已结束,不可预约(status=2)
|
||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, create_by, created_at, updated_at) VALUES
|
||||
('蜜桃臀塑造', 103, 3, '2026-05-30 19:00:00', '2026-05-30 20:00:00', 10, 8, 2, '私教专区', '/images/glute.jpg', '针对性训练臀部肌肉群,课程已于5月30日结束,无法预约。', 'coach_li', '2026-05-20 09:15:00', '2026-05-20 09:15:00');
|
||||
|
||||
-- 场景7(可选): 已结束但未满员的课程(status=2,即使有空位也不可预约)
|
||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, create_by, created_at, updated_at) VALUES
|
||||
('午间冥想放松', 101, 1, '2026-05-31 12:00:00', '2026-05-31 13:00:00', 15, 6, 2, '冥想室', '/images/meditation_noon.jpg', '午间冥想课程,已于5月31日结束。', 'admin', '2026-05-25 09:00:00', '2026-05-25 09:00:00');
|
||||
+281
@@ -0,0 +1,281 @@
|
||||
-- ============================================
|
||||
-- 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 DATE, -- 生日
|
||||
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 '最后一次取消关注时间';
|
||||
|
||||
|
||||
-- ============================================
|
||||
-- 3. member_card 表(会员卡类型表)
|
||||
-- ============================================
|
||||
CREATE TABLE IF NOT EXISTS member_card (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
deleted_at TIMESTAMP,
|
||||
|
||||
member_card_id BIGSERIAL,
|
||||
member_card_name VARCHAR(100) NOT NULL,
|
||||
member_card_type VARCHAR(20) NOT NULL,
|
||||
member_card_price DECIMAL(10, 2) NOT NULL,
|
||||
member_card_validity_days INTEGER,
|
||||
member_card_total_times INTEGER,
|
||||
member_card_amount DECIMAL(10, 2),
|
||||
member_card_status INTEGER DEFAULT 1 NOT NULL,
|
||||
extra_config TEXT DEFAULT '{}'
|
||||
);
|
||||
|
||||
COMMENT ON TABLE member_card IS '会员卡类型表';
|
||||
COMMENT ON COLUMN member_card.member_card_id IS '会员卡ID';
|
||||
COMMENT ON COLUMN member_card.member_card_name IS '会员卡名称';
|
||||
COMMENT ON COLUMN member_card.member_card_type IS '会员卡类型:TIME_CARD-时长卡, COUNT_CARD-次卡, STORED_VALUE_CARD-储值卡';
|
||||
COMMENT ON COLUMN member_card.member_card_price IS '会员卡价格';
|
||||
COMMENT ON COLUMN member_card.member_card_validity_days IS '有效天数(时长卡用)';
|
||||
COMMENT ON COLUMN member_card.member_card_total_times IS '总次数(次卡用)';
|
||||
COMMENT ON COLUMN member_card.member_card_amount IS '面额(储值卡用)';
|
||||
COMMENT ON COLUMN member_card.member_card_status IS '状态:0-下架, 1-上架';
|
||||
COMMENT ON COLUMN member_card.extra_config IS '扩展配置(JSON格式)';
|
||||
|
||||
|
||||
-- ============================================
|
||||
-- 4. member_card_record 表(会员卡记录表)
|
||||
-- ============================================
|
||||
CREATE TABLE IF NOT EXISTS member_card_record (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
deleted_at TIMESTAMP,
|
||||
|
||||
member_card_record_id BIGSERIAL,
|
||||
member_id BIGINT NOT NULL,
|
||||
member_card_id BIGINT NOT NULL,
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'ACTIVE',
|
||||
remaining_times INTEGER DEFAULT 0,
|
||||
remaining_amount DECIMAL(10, 2) DEFAULT 0.00,
|
||||
expire_time TIMESTAMP,
|
||||
source_order_id BIGINT,
|
||||
purchase_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
version INTEGER DEFAULT 0 NOT NULL,
|
||||
card_composition TEXT
|
||||
);
|
||||
|
||||
-- 索引优化
|
||||
CREATE INDEX IF NOT EXISTS idx_member_card_record_member_id ON member_card_record(member_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_member_card_record_status ON member_card_record(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_member_card_record_expire_time ON member_card_record(expire_time);
|
||||
CREATE INDEX IF NOT EXISTS idx_member_card_record_member_status ON member_card_record(member_id, status);
|
||||
CREATE INDEX IF NOT EXISTS idx_member_card_record_status_expire ON member_card_record(status, expire_time)
|
||||
WHERE status = 'ACTIVE';
|
||||
|
||||
COMMENT ON TABLE member_card_record IS '会员卡记录表(会员持有的卡)';
|
||||
COMMENT ON COLUMN member_card_record.member_card_record_id IS '会员卡记录ID';
|
||||
COMMENT ON COLUMN member_card_record.member_id IS '会员ID';
|
||||
COMMENT ON COLUMN member_card_record.member_card_id IS '会员卡类型ID';
|
||||
COMMENT ON COLUMN member_card_record.status IS '状态:ACTIVE-有效, USED_UP-用完, EXPIRED-过期, REFUNDED-已退款';
|
||||
COMMENT ON COLUMN member_card_record.remaining_times IS '剩余次数';
|
||||
COMMENT ON COLUMN member_card_record.remaining_amount IS '剩余金额';
|
||||
COMMENT ON COLUMN member_card_record.expire_time IS '到期时间';
|
||||
COMMENT ON COLUMN member_card_record.source_order_id IS '来源订单ID';
|
||||
COMMENT ON COLUMN member_card_record.purchase_time IS '购买时间';
|
||||
COMMENT ON COLUMN member_card_record.version IS '乐观锁版本号';
|
||||
COMMENT ON COLUMN member_card_record.card_composition IS '卡片组成(JSON格式,用于组合卡)';
|
||||
|
||||
|
||||
-- ============================================
|
||||
-- 5. member_card_transactions 表(会员卡交易流水表)
|
||||
-- ============================================
|
||||
CREATE TABLE IF NOT EXISTS member_card_transactions (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
member_card_record_id BIGINT NOT NULL,
|
||||
member_id BIGINT NOT NULL,
|
||||
member_card_id BIGINT NOT NULL,
|
||||
operation_type VARCHAR(20) NOT NULL,
|
||||
change_amount INTEGER DEFAULT 0,
|
||||
change_balance DECIMAL(10, 2) DEFAULT 0.00,
|
||||
after_remaining_count INTEGER DEFAULT 0,
|
||||
after_remaining_balance DECIMAL(10, 2) DEFAULT 0.00,
|
||||
related_biz_type VARCHAR(20),
|
||||
source_order_id BIGINT,
|
||||
remark VARCHAR(500),
|
||||
is_archived BOOLEAN DEFAULT FALSE,
|
||||
archived_at TIMESTAMP
|
||||
);
|
||||
|
||||
-- 索引优化
|
||||
CREATE INDEX IF NOT EXISTS idx_member_card_transactions_member_id ON member_card_transactions(member_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_member_card_transactions_record_id ON member_card_transactions(member_card_record_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_member_card_transactions_created_at ON member_card_transactions(created_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_member_card_transactions_member_type_time
|
||||
ON member_card_transactions(member_id, operation_type, created_at);
|
||||
|
||||
COMMENT ON TABLE member_card_transactions IS '会员卡交易流水表';
|
||||
COMMENT ON COLUMN member_card_transactions.operation_type IS '操作类型:PURCHASE-购买, DEDUCT-扣次/扣费, RENEW-续费, REFUND-退款, EXPIRE-过期';
|
||||
COMMENT ON COLUMN member_card_transactions.change_amount IS '变动次数';
|
||||
COMMENT ON COLUMN member_card_transactions.change_balance IS '变动金额';
|
||||
COMMENT ON COLUMN member_card_transactions.after_remaining_count IS '变动后剩余次数';
|
||||
COMMENT ON COLUMN member_card_transactions.after_remaining_balance IS '变动后剩余金额';
|
||||
COMMENT ON COLUMN member_card_transactions.related_biz_type IS '关联业务类型:GROUP_CLASS-团课, PT_CLASS-私教, CHECK_IN-签到';
|
||||
COMMENT ON COLUMN member_card_transactions.is_archived IS '是否已归档';
|
||||
COMMENT ON COLUMN member_card_transactions.archived_at IS '归档时间';
|
||||
|
||||
|
||||
-- ============================================
|
||||
-- 6. refund_application 表(退款申请表)
|
||||
-- ============================================
|
||||
CREATE TABLE IF NOT EXISTS refund_application (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
deleted_at TIMESTAMP,
|
||||
|
||||
record_id BIGINT NOT NULL,
|
||||
member_id BIGINT NOT NULL,
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'PENDING',
|
||||
reason VARCHAR(500),
|
||||
apply_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
audit_time TIMESTAMP,
|
||||
auditor_id BIGINT,
|
||||
audit_remark VARCHAR(500),
|
||||
refund_amount DECIMAL(10, 2)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_refund_application_record_id ON refund_application(record_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_refund_application_status ON refund_application(status);
|
||||
|
||||
COMMENT ON TABLE refund_application IS '退款申请表';
|
||||
COMMENT ON COLUMN refund_application.status IS '状态:PENDING-待审核, APPROVED-已批准, REJECTED-已拒绝, PROCESSING-处理中, SUCCESS-成功, FAILED-失败';
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
-- ============================================
|
||||
-- 为团课预约记录表添加课程冗余字段
|
||||
-- 用于保存预约时的课程快照信息
|
||||
-- ============================================
|
||||
|
||||
ALTER TABLE group_course_booking
|
||||
ADD COLUMN IF NOT EXISTS course_name VARCHAR(100),
|
||||
ADD COLUMN IF NOT EXISTS course_start_time TIMESTAMP,
|
||||
ADD COLUMN IF NOT EXISTS course_end_time TIMESTAMP,
|
||||
ADD COLUMN IF NOT EXISTS location VARCHAR(255);
|
||||
|
||||
COMMENT ON COLUMN group_course_booking.course_name IS '课程名称(冗余字段,保存预约时的课程快照)';
|
||||
COMMENT ON COLUMN group_course_booking.course_start_time IS '课程开始时间(冗余字段,保存预约时的课程快照)';
|
||||
COMMENT ON COLUMN group_course_booking.course_end_time IS '课程结束时间(冗余字段,保存预约时的课程快照)';
|
||||
COMMENT ON COLUMN group_course_booking.location IS '上课地点(冗余字段,保存预约时的课程快照)';
|
||||
+8
-1
@@ -50,7 +50,14 @@ public class SecurityConfig {
|
||||
spec.pathMatchers("/api/auth/**").permitAll()
|
||||
.pathMatchers("/api/public/**").permitAll()
|
||||
.pathMatchers("/ws/**").permitAll()
|
||||
.pathMatchers("/actuator/**").permitAll();
|
||||
.pathMatchers("/actuator/**").permitAll()
|
||||
.pathMatchers("/api/groupCourse/**").permitAll()
|
||||
.pathMatchers("/api/member/**").permitAll()
|
||||
.pathMatchers("/api/admin/member/**").permitAll()
|
||||
.pathMatchers("/api/member-cards/**").permitAll()
|
||||
.pathMatchers("/api/member-card-records/**").permitAll()
|
||||
.pathMatchers("/api/member-card-transactions/**").permitAll();
|
||||
|
||||
|
||||
if (isDevOrTest) {
|
||||
spec.pathMatchers("/swagger-ui.html").permitAll()
|
||||
|
||||
+1
@@ -15,6 +15,7 @@ import cn.novalon.gym.manage.sys.core.repository.IUserRoleRepository;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysUserService;
|
||||
import cn.novalon.gym.manage.sys.core.command.CreateUserCommand;
|
||||
import cn.novalon.gym.manage.sys.core.command.UpdateUserCommand;
|
||||
import cn.novalon.gym.manage.sys.dto.response.UserResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
||||
+11
-4
@@ -43,6 +43,7 @@
|
||||
<module>manage-notify</module>
|
||||
<module>manage-file</module>
|
||||
<module>gym-member</module>
|
||||
<module>gym-groupCourse</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
@@ -223,12 +224,18 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Redis响应式支持(会员卡模块需要) -->
|
||||
<!-- HuTool工具箱-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.38</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 环境配置文件
|
||||
* 当前仅使用模拟数据(开发模式)
|
||||
*/
|
||||
|
||||
import { groupCourseMockApi } from './groupCourse.mock.js'
|
||||
|
||||
/**
|
||||
* 团课服务(仅使用模拟数据)
|
||||
*/
|
||||
export const groupCourseService = groupCourseMockApi
|
||||
|
||||
export default groupCourseService
|
||||
@@ -0,0 +1,407 @@
|
||||
/**
|
||||
* 团课模拟数据(测试环境使用)
|
||||
* 数据格式与后端返回格式保持一致
|
||||
*/
|
||||
|
||||
// 模拟团课列表数据(与后端返回格式一致)
|
||||
const mockCourseList = [
|
||||
{
|
||||
"id": "1",
|
||||
"createBy": "admin",
|
||||
"updateBy": null,
|
||||
"createdAt": "2026-06-01T11:00:00",
|
||||
"updatedAt": "2026-06-01T11:00:00",
|
||||
"deletedAt": null,
|
||||
"courseName": "极速燃脂单车",
|
||||
"coachId": "104",
|
||||
"courseType": "2",
|
||||
"startTime": "2026-06-02T16:45:00",
|
||||
"endTime": "2026-06-15T20:20:00",
|
||||
"maxMembers": 25,
|
||||
"currentMembers": 0,
|
||||
"status": "0",
|
||||
"location": "单车房",
|
||||
"coverImage": "https://picsum.photos/seed/spinning/640/360",
|
||||
"description": "跟随音乐节奏变换阻力和速度,体验爬坡与冲刺的快感,一节课消耗800大卡。支持次数卡(1次)或储值卡(50元)支付。",
|
||||
"pointCardAmount": 0,
|
||||
"storedValueAmount": 0
|
||||
},
|
||||
{
|
||||
"id": "3",
|
||||
"createBy": "coach_zhang",
|
||||
"updateBy": null,
|
||||
"createdAt": "2026-06-01T14:30:00",
|
||||
"updatedAt": "2026-06-01T14:30:00",
|
||||
"deletedAt": null,
|
||||
"courseName": "燃脂搏击",
|
||||
"coachId": "102",
|
||||
"courseType": "2",
|
||||
"startTime": "2026-06-10T18:30:00",
|
||||
"endTime": "2026-06-10T19:30:00",
|
||||
"maxMembers": 20,
|
||||
"currentMembers": 20,
|
||||
"status": "0",
|
||||
"location": "综合训练区",
|
||||
"coverImage": "https://picsum.photos/seed/kickboxing/640/360",
|
||||
"description": "高强度间歇训练,配合音乐快速燃脂,释放压力。名额已满,无法预约。支持次数卡(1次)或储值卡(60元)支付。",
|
||||
"pointCardAmount": 1,
|
||||
"storedValueAmount": 60
|
||||
},
|
||||
{
|
||||
"id": "4",
|
||||
"createBy": "coach_li",
|
||||
"updateBy": null,
|
||||
"createdAt": "2026-06-01T08:00:00",
|
||||
"updatedAt": "2026-06-01T08:00:00",
|
||||
"deletedAt": null,
|
||||
"courseName": "哈他瑜伽",
|
||||
"coachId": "101",
|
||||
"courseType": "1",
|
||||
"startTime": "2026-06-01T15:20:00",
|
||||
"endTime": "2026-06-01T16:50:00",
|
||||
"maxMembers": 12,
|
||||
"currentMembers": 3,
|
||||
"status": "0",
|
||||
"location": "瑜伽教室B",
|
||||
"coverImage": "https://picsum.photos/seed/yoga/640/360",
|
||||
"description": "基础哈他瑜伽,适合所有级别。距开始不足30分钟,已停止预约。支持次数卡(1次)或储值卡(40元)支付。",
|
||||
"pointCardAmount": 1,
|
||||
"storedValueAmount": 40
|
||||
},
|
||||
{
|
||||
"id": "5",
|
||||
"createBy": "coach_wang",
|
||||
"updateBy": null,
|
||||
"createdAt": "2026-05-28T08:00:00",
|
||||
"updatedAt": "2026-05-28T08:00:00",
|
||||
"deletedAt": null,
|
||||
"courseName": "周末冥想修复",
|
||||
"coachId": "101",
|
||||
"courseType": "1",
|
||||
"startTime": "2026-06-20T15:00:00",
|
||||
"endTime": "2026-06-20T16:00:00",
|
||||
"maxMembers": 12,
|
||||
"currentMembers": 3,
|
||||
"status": "1",
|
||||
"location": "冥想室",
|
||||
"coverImage": "https://picsum.photos/seed/meditation/640/360",
|
||||
"description": "通过呼吸和正念冥想,深度放松身心。该课程已被取消。支持次数卡(1次)或储值卡(30元)支付。",
|
||||
"pointCardAmount": 1,
|
||||
"storedValueAmount": 30
|
||||
},
|
||||
{
|
||||
"id": "6",
|
||||
"createBy": "coach_li",
|
||||
"updateBy": null,
|
||||
"createdAt": "2026-05-20T09:15:00",
|
||||
"updatedAt": "2026-05-20T09:15:00",
|
||||
"deletedAt": null,
|
||||
"courseName": "蜜桃臀塑造",
|
||||
"coachId": "103",
|
||||
"courseType": "3",
|
||||
"startTime": "2026-05-30T19:00:00",
|
||||
"endTime": "2026-05-30T20:00:00",
|
||||
"maxMembers": 10,
|
||||
"currentMembers": 8,
|
||||
"status": "2",
|
||||
"location": "私教专区",
|
||||
"coverImage": "https://picsum.photos/seed/glute/640/360",
|
||||
"description": "针对性训练臀部肌肉群,课程已于5月30日结束,无法预约。支持次数卡(1次)或储值卡(80元)支付。",
|
||||
"pointCardAmount": 1,
|
||||
"storedValueAmount": 80
|
||||
},
|
||||
{
|
||||
"id": "7",
|
||||
"createBy": "admin",
|
||||
"updateBy": null,
|
||||
"createdAt": "2026-05-25T09:00:00",
|
||||
"updatedAt": "2026-05-25T09:00:00",
|
||||
"deletedAt": null,
|
||||
"courseName": "午间冥想放松",
|
||||
"coachId": "101",
|
||||
"courseType": "1",
|
||||
"startTime": "2026-05-31T12:00:00",
|
||||
"endTime": "2026-05-31T13:00:00",
|
||||
"maxMembers": 15,
|
||||
"currentMembers": 6,
|
||||
"status": "2",
|
||||
"location": "冥想室",
|
||||
"coverImage": "https://picsum.photos/seed/noonmeditation/640/360",
|
||||
"description": "午间冥想课程,已于5月31日结束。支持次数卡(1次)或储值卡(25元)支付。",
|
||||
"pointCardAmount": 1,
|
||||
"storedValueAmount": 25
|
||||
},
|
||||
{
|
||||
"id": "8",
|
||||
"createBy": "admin",
|
||||
"updateBy": null,
|
||||
"createdAt": "2026-06-01T10:00:00",
|
||||
"updatedAt": "2026-06-01T10:00:00",
|
||||
"deletedAt": null,
|
||||
"courseName": "燃脂搏击_次数卡课程",
|
||||
"coachId": "102",
|
||||
"courseType": "2",
|
||||
"startTime": "2026-06-10T19:30:00",
|
||||
"endTime": "2026-06-10T20:30:00",
|
||||
"maxMembers": 20,
|
||||
"currentMembers": 0,
|
||||
"status": "0",
|
||||
"location": "综合训练区",
|
||||
"coverImage": null,
|
||||
"description": "高强度间歇训练,配合音乐快速燃脂,消耗1次",
|
||||
"pointCardAmount": 1,
|
||||
"storedValueAmount": 0
|
||||
},
|
||||
{
|
||||
"id": "9",
|
||||
"createBy": "admin",
|
||||
"updateBy": null,
|
||||
"createdAt": "2026-06-01T10:00:00",
|
||||
"updatedAt": "2026-06-01T10:00:00",
|
||||
"deletedAt": null,
|
||||
"courseName": "高端普拉提_储值卡课程",
|
||||
"coachId": "103",
|
||||
"courseType": "1",
|
||||
"startTime": "2026-06-11T19:00:00",
|
||||
"endTime": "2026-06-11T20:00:00",
|
||||
"maxMembers": 15,
|
||||
"currentMembers": 0,
|
||||
"status": "0",
|
||||
"location": "普拉提教室",
|
||||
"coverImage": null,
|
||||
"description": "精准训练核心肌群,消耗储值50元",
|
||||
"pointCardAmount": 0,
|
||||
"storedValueAmount": 20
|
||||
},
|
||||
{
|
||||
"id": "11",
|
||||
"createBy": "admin",
|
||||
"updateBy": null,
|
||||
"createdAt": "2026-06-02T10:00:00",
|
||||
"updatedAt": "2026-06-02T10:00:00",
|
||||
"deletedAt": null,
|
||||
"courseName": "时间冲突测试_A_13点-15点",
|
||||
"coachId": "102",
|
||||
"courseType": "2",
|
||||
"startTime": "2026-06-15T13:00:00",
|
||||
"endTime": "2026-06-15T15:00:00",
|
||||
"maxMembers": 20,
|
||||
"currentMembers": 0,
|
||||
"status": "0",
|
||||
"location": "综合训练区",
|
||||
"coverImage": null,
|
||||
"description": "测试用团课A,用于验证时间冲突检测。支持次数卡(1次)或储值卡(50元)支付。",
|
||||
"pointCardAmount": 1,
|
||||
"storedValueAmount": 50
|
||||
},
|
||||
{
|
||||
"id": "12",
|
||||
"createBy": "admin",
|
||||
"updateBy": null,
|
||||
"createdAt": "2026-06-02T10:00:00",
|
||||
"updatedAt": "2026-06-02T10:00:00",
|
||||
"deletedAt": null,
|
||||
"courseName": "时间冲突测试_B_14点-16点",
|
||||
"coachId": "103",
|
||||
"courseType": "1",
|
||||
"startTime": "2026-06-15T14:00:00",
|
||||
"endTime": "2026-06-15T16:00:00",
|
||||
"maxMembers": 15,
|
||||
"currentMembers": 0,
|
||||
"status": "0",
|
||||
"location": "普拉提教室",
|
||||
"coverImage": null,
|
||||
"description": "测试用团课B,与团课A时间重叠(14:00-15:00)。支持次数卡(1次)或储值卡(50元)支付。",
|
||||
"pointCardAmount": 1,
|
||||
"storedValueAmount": 50
|
||||
},
|
||||
{
|
||||
"id": "13",
|
||||
"createBy": "admin",
|
||||
"updateBy": null,
|
||||
"createdAt": "2026-06-02T10:00:00",
|
||||
"updatedAt": "2026-06-02T10:00:00",
|
||||
"deletedAt": null,
|
||||
"courseName": "时间冲突测试_C_10点-12点",
|
||||
"coachId": "101",
|
||||
"courseType": "1",
|
||||
"startTime": "2026-06-15T10:00:00",
|
||||
"endTime": "2026-06-15T12:00:00",
|
||||
"maxMembers": 15,
|
||||
"currentMembers": 0,
|
||||
"status": "0",
|
||||
"location": "瑜伽教室",
|
||||
"coverImage": null,
|
||||
"description": "测试用团课C,与团课A/B不冲突。支持次数卡(1次)或储值卡(50元)支付。",
|
||||
"pointCardAmount": 1,
|
||||
"storedValueAmount": 50
|
||||
},
|
||||
{
|
||||
"id": "14",
|
||||
"createBy": "system",
|
||||
"updateBy": "system",
|
||||
"createdAt": "2026-06-02T17:32:50.532336",
|
||||
"updatedAt": "2026-06-02T17:32:50.532336",
|
||||
"deletedAt": null,
|
||||
"courseName": "动感单车aaa",
|
||||
"coachId": "2",
|
||||
"courseType": "2",
|
||||
"startTime": "2026-06-05T18:00:00",
|
||||
"endTime": "2026-06-05T19:00:00",
|
||||
"maxMembers": 25,
|
||||
"currentMembers": 0,
|
||||
"status": "0",
|
||||
"location": "健身房B区",
|
||||
"coverImage": "https://example.com/spinning.jpg",
|
||||
"description": "高强度有氧运动课程",
|
||||
"pointCardAmount": 1,
|
||||
"storedValueAmount": 50
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"createBy": "admin",
|
||||
"updateBy": null,
|
||||
"createdAt": "2026-06-01T10:00:00",
|
||||
"updatedAt": "2026-06-02T17:35:35.155616",
|
||||
"deletedAt": null,
|
||||
"courseName": "清晨流瑜伽",
|
||||
"coachId": "101",
|
||||
"courseType": "1",
|
||||
"startTime": "2026-06-12T09:00:00",
|
||||
"endTime": "2026-06-12T10:30:00",
|
||||
"maxMembers": 15,
|
||||
"currentMembers": 6,
|
||||
"status": "0",
|
||||
"location": "A座3楼瑜伽教室",
|
||||
"coverImage": "https://picsum.photos/seed/yogaflow/640/360",
|
||||
"description": "适合有一定基础的学员,通过流畅的体式连接呼吸,唤醒身体能量。支持次数卡(1次)或储值卡(45元)支付。",
|
||||
"pointCardAmount": 1,
|
||||
"storedValueAmount": 45
|
||||
},
|
||||
{
|
||||
"id": "15",
|
||||
"createBy": "system",
|
||||
"updateBy": "system",
|
||||
"createdAt": "2026-06-02T17:57:27.483488",
|
||||
"updatedAt": "2026-06-02T17:57:27.483488",
|
||||
"deletedAt": null,
|
||||
"courseName": "动感单车",
|
||||
"coachId": "2",
|
||||
"courseType": "2",
|
||||
"startTime": "2026-06-05T18:00:00",
|
||||
"endTime": "2026-06-05T19:00:00",
|
||||
"maxMembers": 25,
|
||||
"currentMembers": 0,
|
||||
"status": "0",
|
||||
"location": "健身房B区",
|
||||
"coverImage": "https://example.com/spinning.jpg",
|
||||
"description": "高强度有氧运动课程",
|
||||
"pointCardAmount": 1,
|
||||
"storedValueAmount": 50
|
||||
}
|
||||
]
|
||||
|
||||
/**
|
||||
* 模拟团课API(测试环境)
|
||||
* 接口签名与真实API保持一致
|
||||
*/
|
||||
export const groupCourseMockApi = {
|
||||
/**
|
||||
* 获取团课列表(支持分页)
|
||||
* @param {Object} params - 查询参数
|
||||
* @param {number} params.pageNum - 页码(从1开始)
|
||||
* @param {number} params.pageSize - 每页数量
|
||||
* @returns {Promise} - 分页团课列表数据
|
||||
*/
|
||||
getList: (params = {}) => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
const pageNum = params.pageNum || 1
|
||||
const pageSize = params.pageSize || 10
|
||||
|
||||
const total = mockCourseList.length
|
||||
const startIndex = (pageNum - 1) * pageSize
|
||||
const endIndex = startIndex + pageSize
|
||||
const list = mockCourseList.slice(startIndex, endIndex)
|
||||
|
||||
console.log('[groupCourse.mock.js] 模拟获取团课列表(分页):', {
|
||||
pageNum,
|
||||
pageSize,
|
||||
total,
|
||||
listCount: list.length
|
||||
})
|
||||
|
||||
resolve({
|
||||
code: 0,
|
||||
message: 'success',
|
||||
data: {
|
||||
list,
|
||||
total,
|
||||
pageNum,
|
||||
pageSize,
|
||||
totalPages: Math.ceil(total / pageSize)
|
||||
}
|
||||
})
|
||||
}, 500)
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取团课详情
|
||||
* @param {string} id - 课程ID
|
||||
* @returns {Promise} - 团课详情数据
|
||||
*/
|
||||
getDetail: (id) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
console.log('[groupCourse.mock.js] 模拟获取团课详情:', id)
|
||||
const course = mockCourseList.find(item => item.id === id)
|
||||
if (course) {
|
||||
resolve(course)
|
||||
} else {
|
||||
reject({ code: -1, message: '课程不存在' })
|
||||
}
|
||||
}, 300)
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 预约团课
|
||||
* @param {Object} data - 预约数据
|
||||
* @param {string} data.courseId - 课程ID
|
||||
* @param {string} data.memberId - 会员ID
|
||||
* @returns {Promise} - 预约结果
|
||||
*/
|
||||
book: (data) => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
console.log('[groupCourse.mock.js] 模拟预约团课:', data)
|
||||
resolve({
|
||||
code: 0,
|
||||
message: '预约成功',
|
||||
data: { bookingId: `BK${Date.now()}` }
|
||||
})
|
||||
}, 400)
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 取消预约
|
||||
* @param {string} id - 预约记录ID
|
||||
* @returns {Promise} - 取消结果
|
||||
*/
|
||||
cancelBooking: (id) => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
console.log('[groupCourse.mock.js] 模拟取消预约:', id)
|
||||
resolve({
|
||||
code: 0,
|
||||
message: '取消成功',
|
||||
data: null
|
||||
})
|
||||
}, 300)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default groupCourseMockApi
|
||||
@@ -1,4 +1,5 @@
|
||||
const BASE_URL = 'http://localhost:8080/api'
|
||||
// const BASE_URL = 'http://localhost:8080/api'
|
||||
const BASE_URL = '/api'
|
||||
|
||||
export const request = (options) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
import { request, setToken, clearToken, clearAllCache, clearCache } from '@/utils/request.js'
|
||||
|
||||
// ========== 登录相关API ==========
|
||||
|
||||
/**
|
||||
* 微信小程序登录
|
||||
* @param {object} data - 登录参数
|
||||
* @param {string} data.code - 微信登录code
|
||||
* @param {string} [data.encryptedData] - 加密数据
|
||||
* @param {string} [data.iv] - 加密向量
|
||||
* @returns {Promise} 登录结果
|
||||
*/
|
||||
export const login = (data) => {
|
||||
return request({
|
||||
url: '/member/auth/miniapp/login',
|
||||
method: 'POST',
|
||||
data: data,
|
||||
needToken: false // 登录请求不需要token
|
||||
}).then(res => {
|
||||
// 登录成功,保存token
|
||||
if (res.data && res.data.token) {
|
||||
setToken(res.data.token)
|
||||
}
|
||||
return res
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
* @returns {Promise} 退出结果
|
||||
*/
|
||||
export const logout = () => {
|
||||
return request({
|
||||
url: '/member/auth/logout',
|
||||
method: 'POST'
|
||||
}).then(res => {
|
||||
// 退出成功,清除token和缓存
|
||||
clearToken()
|
||||
clearAllCache()
|
||||
return res
|
||||
}).catch(err => {
|
||||
// 即使请求失败,也清除本地token
|
||||
clearToken()
|
||||
clearAllCache()
|
||||
throw err
|
||||
})
|
||||
}
|
||||
|
||||
// ========== 签到相关API ==========
|
||||
|
||||
/**
|
||||
* 获取签到二维码
|
||||
* @param {boolean} [cache=true] - 是否启用缓存
|
||||
* @returns {Promise} 二维码数据
|
||||
*/
|
||||
export const getQRCode = (cache = true) => {
|
||||
return request({
|
||||
url: '/checkIn/qrcode',
|
||||
method: 'GET',
|
||||
cache: cache,
|
||||
cacheTime: 5 * 60 * 1000 // 5分钟缓存
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码签到
|
||||
* @param {string} qrContent - 二维码内容
|
||||
* @returns {Promise} 签到结果
|
||||
*/
|
||||
export const checkIn = (qrContent) => {
|
||||
return request({
|
||||
url: '/checkIn/scan',
|
||||
method: 'POST',
|
||||
data: { qrContent }
|
||||
})
|
||||
}
|
||||
|
||||
// ========== 用户相关API ==========
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* @param {boolean} [cache=true] - 是否启用缓存
|
||||
* @returns {Promise} 用户信息
|
||||
*/
|
||||
export const getUserInfo = (cache = true) => {
|
||||
return request({
|
||||
url: '/member/info',
|
||||
method: 'GET',
|
||||
cache: cache,
|
||||
cacheTime: 30 * 60 * 1000 // 30分钟缓存
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户信息
|
||||
* @param {object} data - 用户信息
|
||||
* @returns {Promise} 更新结果
|
||||
*/
|
||||
export const updateUserInfo = (data) => {
|
||||
return request({
|
||||
url: '/member/info',
|
||||
method: 'PUT',
|
||||
data: data
|
||||
}).then(res => {
|
||||
// 更新成功,清除用户信息缓存
|
||||
const cacheKey = `GET_/member/info_{}`
|
||||
clearCache(cacheKey)
|
||||
return res
|
||||
})
|
||||
}
|
||||
|
||||
// ========== 课程相关API ==========
|
||||
|
||||
/**
|
||||
* 获取推荐课程列表
|
||||
* @param {boolean} [cache=true] - 是否启用缓存
|
||||
* @returns {Promise} 课程列表
|
||||
*/
|
||||
export const getRecommendCourses = (cache = true) => {
|
||||
return request({
|
||||
url: '/course/recommend',
|
||||
method: 'GET',
|
||||
cache: cache,
|
||||
cacheTime: 10 * 60 * 1000 // 10分钟缓存
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取课程详情
|
||||
* @param {number} id - 课程ID
|
||||
* @param {boolean} [cache=true] - 是否启用缓存
|
||||
* @returns {Promise} 课程详情
|
||||
*/
|
||||
export const getCourseDetail = (id, cache = true) => {
|
||||
return request({
|
||||
url: `/course/${id}`,
|
||||
method: 'GET',
|
||||
cache: cache,
|
||||
cacheTime: 15 * 60 * 1000 // 15分钟缓存
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
login,
|
||||
logout,
|
||||
getQRCode,
|
||||
checkIn,
|
||||
getUserInfo,
|
||||
updateUserInfo,
|
||||
getRecommendCourses,
|
||||
getCourseDetail
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,25 @@
|
||||
@font-face {
|
||||
font-family: "iconfont_courseCard"; /* Project id */
|
||||
src: url('./font/iconfont_courseCard.ttf?t=1780537357472') format('truetype');
|
||||
}
|
||||
|
||||
.iconfont_courseCard {
|
||||
font-family: "iconfont_courseCard" !important;
|
||||
font-size: 16px;
|
||||
font-style: normal;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
.icon-didian:before {
|
||||
content: "\e61a";
|
||||
}
|
||||
|
||||
.icon-renwu-ren:before {
|
||||
content: "\e749";
|
||||
}
|
||||
|
||||
.icon-shijian:before {
|
||||
content: "\e61d";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
@font-face {
|
||||
font-family: "iconfont_time_select"; /* Project id */
|
||||
src: url('./font/iconfont_time_select.ttf?t=1780535096813') format('truetype');
|
||||
}
|
||||
|
||||
.iconfont_time_select {
|
||||
font-family: "iconfont_time_select" !important;
|
||||
font-size: 25px;
|
||||
font-style: normal;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
.icon-zaochen:before {
|
||||
content: "\e784";
|
||||
}
|
||||
|
||||
.icon-gengduo:before {
|
||||
content: "\e6df";
|
||||
}
|
||||
|
||||
.icon-xiawucha:before {
|
||||
content: "\100ff";
|
||||
}
|
||||
|
||||
.icon-yewan:before {
|
||||
content: "\e67e";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
<template>
|
||||
<view class="qr-status">
|
||||
<!-- 加载中状态 -->
|
||||
<view v-if="status === 'loading'" class="status-loading">
|
||||
<view class="status-icon">
|
||||
<view class="loading-spinner"></view>
|
||||
</view>
|
||||
<text>生成中...</text>
|
||||
</view>
|
||||
|
||||
<!-- 签到成功状态 -->
|
||||
<view v-else-if="status === 'scanned'" class="status-success">
|
||||
<view class="status-icon">
|
||||
<uni-icons type="checkmarkcircle" size="40rpx" color="#2ECC71"></uni-icons>
|
||||
</view>
|
||||
<text>签到成功!</text>
|
||||
</view>
|
||||
|
||||
<!-- 错误状态(支持自定义文案) -->
|
||||
<view v-else-if="status === 'error'" class="status-error">
|
||||
<view class="status-icon">
|
||||
<uni-icons type="closecircle" size="40rpx" color="#E74C3C"></uni-icons>
|
||||
</view>
|
||||
<text>{{ errorText || '签到失败,请重试' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { defineProps } from 'vue';
|
||||
|
||||
// 扩展Props,支持自定义错误文案
|
||||
const props = defineProps({
|
||||
status: {
|
||||
type: String,
|
||||
required: true,
|
||||
default: ''
|
||||
},
|
||||
// 自定义错误文本(可选)
|
||||
errorText: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: ''
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 保留原样式,新增加载中样式 */
|
||||
.qr-status {
|
||||
margin-bottom: 48rpx;
|
||||
}
|
||||
|
||||
.status-loading,
|
||||
.status-waiting,
|
||||
.status-success,
|
||||
.status-error {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 16rpx;
|
||||
font-size: 29rpx;
|
||||
}
|
||||
|
||||
.status-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
/* 加载中样式 */
|
||||
.status-loading {
|
||||
color: #FF6B35;
|
||||
}
|
||||
.loading-spinner {
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
border: 4rpx solid #E9EDF2;
|
||||
border-top-color: #FF6B35;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
.status-success {
|
||||
color: #2ECC71;
|
||||
}
|
||||
|
||||
.status-error {
|
||||
color: #E74C3C;
|
||||
}
|
||||
|
||||
|
||||
/* 旋转动画 */
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
</style>
|
||||
@@ -2,6 +2,7 @@
|
||||
<view class="tab-bar">
|
||||
<view
|
||||
v-for="(tab, index) in tabs"
|
||||
<<<<<<< HEAD
|
||||
:key="tab.path"
|
||||
:class="['tab-item', { active: currentIndex === index }]"
|
||||
hover-class="tab-item--hover"
|
||||
@@ -12,12 +13,22 @@
|
||||
mode="aspectFit"
|
||||
class="tab-icon"
|
||||
/>
|
||||
=======
|
||||
:key="index"
|
||||
:class="['tab-item', { active: currentActive === index }]"
|
||||
@click="switchTab(index)"
|
||||
>
|
||||
<!-- 导航栏图标 -->
|
||||
<image :src="currentActive === index ? tab.iconActive : tab.icon" mode="aspectFit" class="tab-icon" />
|
||||
<!-- 导航栏标签文字 -->
|
||||
>>>>>>> 8cf3c9ccee0d9274f647f0126b50dc1e79178809
|
||||
<text class="tab-label">{{ tab.label }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
<<<<<<< HEAD
|
||||
import { computed, ref } from 'vue'
|
||||
import {
|
||||
PAGE,
|
||||
@@ -36,9 +47,29 @@ const props = defineProps({
|
||||
})
|
||||
|
||||
const tapping = ref(false)
|
||||
=======
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
// 当前激活的导航栏索引(从外部传入)
|
||||
const props = defineProps({
|
||||
activeTab: {
|
||||
type: Number,
|
||||
default: 0
|
||||
}
|
||||
})
|
||||
|
||||
// 当前激活状态
|
||||
const currentActive = ref(props.activeTab)
|
||||
|
||||
// 监听外部传入的激活状态变化
|
||||
watch(() => props.activeTab, (newVal) => {
|
||||
currentActive.value = newVal
|
||||
})
|
||||
>>>>>>> 8cf3c9ccee0d9274f647f0126b50dc1e79178809
|
||||
|
||||
const tabs = [
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
path: PAGE.INDEX,
|
||||
icon: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/tabBar/home.png',
|
||||
iconActive: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/tabBar/active/home.png',
|
||||
@@ -82,6 +113,58 @@ function onTabTap(index) {
|
||||
setTimeout(() => {
|
||||
tapping.value = false
|
||||
}, 350)
|
||||
=======
|
||||
icon: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/tabBar/home.png',
|
||||
iconActive: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/tabBar/active/home.png',
|
||||
label: '首页',
|
||||
path: '/pages/index/index'
|
||||
},
|
||||
{
|
||||
icon: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/tabBar/course.png',
|
||||
iconActive: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/tabBar/active/course.png',
|
||||
label: '课程',
|
||||
path: '/pages/groupCourse/list'
|
||||
},
|
||||
{
|
||||
icon: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/tabBar/train.png',
|
||||
iconActive: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/tabBar/active/train.png',
|
||||
label: '训练',
|
||||
path: '/pages/train/index'
|
||||
},
|
||||
{
|
||||
icon: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/tabBar/discover.png',
|
||||
iconActive: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/tabBar/active/discover.png',
|
||||
label: '发现',
|
||||
path: '/pages/discover/index'
|
||||
},
|
||||
{
|
||||
icon: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/tabBar/profile.png',
|
||||
iconActive: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/tabBar/active/profile.png',
|
||||
label: '我的',
|
||||
path: '/pages/profile/index'
|
||||
}
|
||||
]
|
||||
|
||||
// 切换标签页
|
||||
const switchTab = (index) => {
|
||||
currentActive.value = index
|
||||
const tab = tabs[index]
|
||||
|
||||
// 获取当前页面路径
|
||||
const pages = getCurrentPages()
|
||||
const currentPage = pages[pages.length - 1]
|
||||
const currentPath = '/' + currentPage.route
|
||||
|
||||
// 如果点击的是当前页面,不跳转
|
||||
if (currentPath === tab.path) {
|
||||
return
|
||||
}
|
||||
|
||||
// 跳转对应页面
|
||||
uni.redirectTo({
|
||||
url: tab.path
|
||||
})
|
||||
>>>>>>> 8cf3c9ccee0d9274f647f0126b50dc1e79178809
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -100,7 +183,11 @@ function onTabTap(index) {
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.06);
|
||||
border-radius: 32rpx 32rpx 0 0;
|
||||
<<<<<<< HEAD
|
||||
z-index: 999;
|
||||
=======
|
||||
z-index: 100;
|
||||
>>>>>>> 8cf3c9ccee0d9274f647f0126b50dc1e79178809
|
||||
}
|
||||
|
||||
.tab-item {
|
||||
|
||||
@@ -0,0 +1,487 @@
|
||||
<template>
|
||||
<!-- 团课卡片容器 -->
|
||||
<view class="course-card" @click="goDetail">
|
||||
<!-- 卡片顶部图片区域 -->
|
||||
<view class="card-top">
|
||||
<!-- 图片骨架屏 -->
|
||||
<view v-if="!imageLoaded" class="skeleton skeleton-image"></view>
|
||||
<!-- 课程封面图片 -->
|
||||
<image
|
||||
:src="course.coverImage"
|
||||
mode="aspectFill"
|
||||
class="cover-image"
|
||||
:class="{ hidden: !imageLoaded }"
|
||||
@load="imageLoaded = true"
|
||||
@error="imageLoaded = true"
|
||||
/>
|
||||
<!-- 课程状态标签 -->
|
||||
<view :class="['status-tag', statusClass]">
|
||||
{{ statusText }}
|
||||
</view>
|
||||
<!-- 剩余名额标签 -->
|
||||
<view class="spots-tag" v-if="course.currentMembers < course.maxMembers">
|
||||
<span class="iconfont_courseCard icon-renwu-ren"></span>
|
||||
<text>{{ course.maxMembers - course.currentMembers }}个名额</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 卡片内容区域 -->
|
||||
<view class="card-content">
|
||||
<!-- 课程名称 -->
|
||||
<view class="course-name-wrapper">
|
||||
<text class="course-name">{{ course.courseName }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 课程信息 -->
|
||||
<view class="course-info">
|
||||
<!-- 上课时间 -->
|
||||
<view class="info-item">
|
||||
<span class="iconfont_courseCard icon-shijian "></span>
|
||||
<text class="info-text">{{ formatTime(course.startTime) }}</text>
|
||||
</view>
|
||||
<!-- 上课地点 -->
|
||||
<view class="info-item">
|
||||
<span class="iconfont_courseCard icon-didian"></span>
|
||||
<text class="info-text">{{ course.location }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 课程时长 -->
|
||||
<view class="course-duration">
|
||||
<uni-icons type="time" size="14" color="#8A99B4" />
|
||||
<text>{{ formatDuration(course.startTime, course.endTime) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 卡片底部操作区域 -->
|
||||
<view class="card-footer">
|
||||
<!-- 价格信息 -->
|
||||
<view class="price-info">
|
||||
<!-- 免费课程 -->
|
||||
<view v-if="course.storedValueAmount === 0 && course.pointCardAmount === 0" class="price-free">
|
||||
<text class="free-text">免费</text>
|
||||
</view>
|
||||
<!-- 支持多种支付方式 -->
|
||||
<view v-else-if="course.storedValueAmount > 0 && course.pointCardAmount > 0" class="price-multi">
|
||||
<view class="price-item stored-value">
|
||||
<text class="currency">¥</text>
|
||||
<text class="amount">{{ course.storedValueAmount }}</text>
|
||||
<text class="label">储值卡</text>
|
||||
</view>
|
||||
<view class="price-divider"></view>
|
||||
<view class="price-item point-card">
|
||||
<uni-icons type="shop" size="14" color="#FF6B35" />
|
||||
<text class="amount">{{ course.pointCardAmount }}次</text>
|
||||
<text class="label">次卡</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 仅储值卡支付 -->
|
||||
<view v-else-if="course.storedValueAmount > 0" class="price-single">
|
||||
<text class="price">
|
||||
<text class="currency">¥</text>{{ course.storedValueAmount }}
|
||||
</text>
|
||||
<text class="pay-label">储值卡</text>
|
||||
</view>
|
||||
<!-- 仅次卡支付 -->
|
||||
<view v-else-if="course.pointCardAmount > 0" class="price-single">
|
||||
<text class="price points">
|
||||
<uni-icons type="shop" size="14" color="#FF6B35" />
|
||||
<text>{{ course.pointCardAmount }}次</text>
|
||||
</text>
|
||||
<text class="pay-label">次卡</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 预约按钮 -->
|
||||
<view :class="['booking-btn', { disabled: !canBook }]" @click.stop="handleBooking">
|
||||
<text>{{ canBook ? '立即预约' : (course.currentMembers >= course.maxMembers ? '已满员' : '已结束') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue'
|
||||
|
||||
// 图片加载状态
|
||||
const imageLoaded = ref(false)
|
||||
|
||||
const props = defineProps({
|
||||
course: {
|
||||
type: Object,
|
||||
required: true
|
||||
}
|
||||
})
|
||||
|
||||
const emit = defineEmits(['booking', 'detail'])
|
||||
|
||||
const statusText = computed(() => {
|
||||
const status = props.course.status
|
||||
if (status === '0') return '进行中'
|
||||
if (status === '1') return '已取消'
|
||||
if (status === '2') return '已结束'
|
||||
return '未知'
|
||||
})
|
||||
|
||||
const statusClass = computed(() => {
|
||||
const status = props.course.status
|
||||
if (status === '0') return 'active'
|
||||
if (status === '1') return 'canceled'
|
||||
if (status === '2') return 'ended'
|
||||
return ''
|
||||
})
|
||||
|
||||
const canBook = computed(() => {
|
||||
const status = props.course.status
|
||||
const isFull = props.course.currentMembers >= props.course.maxMembers
|
||||
return status === '0' && !isFull
|
||||
})
|
||||
|
||||
const formatTime = (dateStr) => {
|
||||
if (!dateStr) return ''
|
||||
const date = new Date(dateStr)
|
||||
const month = date.getMonth() + 1
|
||||
const day = date.getDate()
|
||||
const weekDays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
|
||||
const weekDay = weekDays[date.getDay()]
|
||||
const hours = date.getHours().toString().padStart(2, '0')
|
||||
const minutes = date.getMinutes().toString().padStart(2, '0')
|
||||
return `${month}月${day}日 ${weekDay} ${hours}:${minutes}`
|
||||
}
|
||||
|
||||
const formatDuration = (startStr, endStr) => {
|
||||
if (!startStr || !endStr) return ''
|
||||
const start = new Date(startStr)
|
||||
const end = new Date(endStr)
|
||||
const minutes = Math.floor((end.getTime() - start.getTime()) / 60000)
|
||||
return `${minutes}分钟`
|
||||
}
|
||||
|
||||
const goDetail = () => {
|
||||
emit('detail', props.course.id)
|
||||
}
|
||||
|
||||
const handleBooking = () => {
|
||||
if (canBook.value) {
|
||||
emit('booking', props.course)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@import "@/common/style/iconfont_courseCard.css";
|
||||
|
||||
/* 团课卡片容器 */
|
||||
.course-card {
|
||||
background: #ffffff;
|
||||
border-radius: 28rpx;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.04);
|
||||
margin-bottom: 28rpx;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
transition: all 0.3s ease;
|
||||
|
||||
&:active {
|
||||
transform: scale(0.98);
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
}
|
||||
|
||||
/* 卡片顶部图片区域 */
|
||||
.card-top {
|
||||
position: relative;
|
||||
height: 320rpx;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* 课程封面图片 */
|
||||
.cover-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
transition: opacity 0.3s ease;
|
||||
|
||||
&.hidden {
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
/* 骨架屏基础样式 */
|
||||
.skeleton {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
background: linear-gradient(90deg, #f6f7f8 0%, #e0e0e0 20%, #f6f7f8 40%, #f6f7f8 100%);
|
||||
background-size: 100% 100%;
|
||||
animation: skeleton-loading 1.5s infinite;
|
||||
border-radius: inherit;
|
||||
}
|
||||
|
||||
/* 骨架屏动画 */
|
||||
@keyframes skeleton-loading {
|
||||
0% {
|
||||
background-position: 100% 0;
|
||||
}
|
||||
100% {
|
||||
background-position: -100% 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* 图片骨架屏 */
|
||||
.skeleton-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
/* 课程状态标签 */
|
||||
.status-tag {
|
||||
position: absolute;
|
||||
top: 24rpx;
|
||||
left: 24rpx;
|
||||
padding: 10rpx 24rpx;
|
||||
border-radius: 24rpx;
|
||||
font-size: 22rpx;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
backdrop-filter: blur(8rpx);
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.15);
|
||||
|
||||
&.active {
|
||||
background: linear-gradient(135deg, #10B981 0%, #059669 100%);
|
||||
}
|
||||
|
||||
&.canceled {
|
||||
background: linear-gradient(135deg, #9CA3AF 0%, #6B7280 100%);
|
||||
}
|
||||
|
||||
&.ended {
|
||||
background: linear-gradient(135deg, #D1D5DB 0%, #9CA3AF 100%);
|
||||
}
|
||||
}
|
||||
|
||||
/* 剩余名额标签 */
|
||||
.spots-tag {
|
||||
position: absolute;
|
||||
top: 24rpx;
|
||||
right: 24rpx;
|
||||
padding: 10rpx 20rpx;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
backdrop-filter: blur(8rpx);
|
||||
border-radius: 24rpx;
|
||||
font-size: 22rpx;
|
||||
color: #ffffff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8rpx;
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
/* 卡片内容区域 */
|
||||
.card-content {
|
||||
padding: 28rpx 32rpx;
|
||||
}
|
||||
|
||||
/* 课程名称容器 */
|
||||
.course-name-wrapper {
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
/* 课程名称 */
|
||||
.course-name {
|
||||
font-size: 34rpx;
|
||||
font-weight: 700;
|
||||
color: #1F2937;
|
||||
display: block;
|
||||
line-height: 1.4;
|
||||
letter-spacing: 0.5rpx;
|
||||
}
|
||||
|
||||
/* 课程信息容器 */
|
||||
.course-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 14rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
/* 信息项 */
|
||||
.info-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
padding: 12rpx 16rpx;
|
||||
background: linear-gradient(135deg, #F9FAFB 0%, #F3F4F6 100%);
|
||||
border-radius: 16rpx;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:active {
|
||||
background: linear-gradient(135deg, #F3F4F6 0%, #E5E7EB 100%);
|
||||
}
|
||||
}
|
||||
|
||||
/* 信息图标 */
|
||||
.info-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* 图标字体垂直居中 */
|
||||
.iconfont_courseCard {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
/* 信息文字 */
|
||||
.info-text {
|
||||
font-size: 26rpx;
|
||||
color: #4B5563;
|
||||
line-height: 1.5;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
/* 课程时长 */
|
||||
.course-duration {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8rpx;
|
||||
padding: 10rpx 20rpx;
|
||||
background: linear-gradient(135deg, #EFF6FF 0%, #DBEAFE 100%);
|
||||
border-radius: 20rpx;
|
||||
font-size: 24rpx;
|
||||
color: #3B82F6;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* 卡片底部区域 */
|
||||
.card-footer {
|
||||
padding: 24rpx 32rpx 28rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
border-top: 1rpx solid #F3F4F6;
|
||||
margin-top: 4rpx;
|
||||
}
|
||||
|
||||
/* 价格信息 */
|
||||
.price-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.price {
|
||||
font-size: 36rpx;
|
||||
font-weight: 700;
|
||||
color: #FF6B35;
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 4rpx;
|
||||
|
||||
.currency {
|
||||
font-size: 24rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
&.points {
|
||||
color: #FF6B35;
|
||||
gap: 6rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 免费课程样式 */
|
||||
.price-free {
|
||||
.free-text {
|
||||
font-size: 36rpx;
|
||||
font-weight: 700;
|
||||
color: #10B981;
|
||||
}
|
||||
}
|
||||
|
||||
/* 多种支付方式样式 */
|
||||
.price-multi {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
|
||||
.price-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6rpx;
|
||||
|
||||
.currency {
|
||||
font-size: 20rpx;
|
||||
font-weight: 600;
|
||||
color: #FF6B35;
|
||||
}
|
||||
|
||||
.amount {
|
||||
font-size: 30rpx;
|
||||
font-weight: 700;
|
||||
color: #FF6B35;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 20rpx;
|
||||
color: #6B7280;
|
||||
margin-left: 4rpx;
|
||||
}
|
||||
|
||||
&.stored-value {
|
||||
.currency, .amount {
|
||||
color: #FF6B35;
|
||||
}
|
||||
}
|
||||
|
||||
&.point-card {
|
||||
.amount {
|
||||
color: #FF6B35;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.price-divider {
|
||||
width: 2rpx;
|
||||
height: 32rpx;
|
||||
background: #E5E7EB;
|
||||
}
|
||||
}
|
||||
|
||||
/* 单一支付方式样式 */
|
||||
.price-single {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 8rpx;
|
||||
|
||||
.pay-label {
|
||||
font-size: 20rpx;
|
||||
color: #6B7280;
|
||||
padding: 4rpx 12rpx;
|
||||
background: #F3F4F6;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
}
|
||||
|
||||
/* 预约按钮 */
|
||||
.booking-btn {
|
||||
padding: 18rpx 48rpx;
|
||||
background: linear-gradient(135deg, #FF6B35 0%, #FF8C5A 100%);
|
||||
border-radius: 44rpx;
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
box-shadow: 0 8rpx 20rpx rgba(255, 107, 53, 0.25);
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
letter-spacing: 1rpx;
|
||||
|
||||
&:active {
|
||||
transform: scale(0.95);
|
||||
box-shadow: 0 4rpx 12rpx rgba(255, 107, 53, 0.2);
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
background: linear-gradient(135deg, #F3F4F6 0%, #E5E7EB 100%);
|
||||
color: #9CA3AF;
|
||||
box-shadow: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,202 @@
|
||||
<template>
|
||||
<view class="filter-section">
|
||||
<!-- 时间区间筛选 -->
|
||||
<view class="filter-item" @click="handleTimePick">
|
||||
<uni-icons type="calendar" size="18" color="#5E6F8D" class="filter-icon" />
|
||||
<text class="filter-text">{{ timeRangeText || '选择时间' }}</text>
|
||||
<uni-icons type="right" size="20" color="#A0AEC0" class="filter-arrow" />
|
||||
</view>
|
||||
|
||||
<!-- 排序方式 -->
|
||||
<picker
|
||||
mode="selector"
|
||||
:range="sortOptions"
|
||||
range-key="label"
|
||||
:value="sortIndex"
|
||||
@change="onSortChange"
|
||||
>
|
||||
<view class="filter-item">
|
||||
<uni-icons type="list" size="18" color="#5E6F8D" class="filter-icon" />
|
||||
<text class="filter-text">{{ sortOptions[sortIndex].label }}</text>
|
||||
<uni-icons type="right" size="20" color="#A0AEC0" class="filter-arrow" />
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
timeRangeText: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
sortOptions: {
|
||||
type: Array,
|
||||
default: () => [
|
||||
{ label: '默认排序', value: 'default' },
|
||||
{ label: '价格从低到高', value: 'priceAsc' },
|
||||
{ label: '价格从高到低', value: 'priceDesc' },
|
||||
{ label: '剩余名额最多', value: 'spotsDesc' },
|
||||
{ label: '仅次数卡', value: 'pointCardOnly' },
|
||||
{ label: '仅储值卡', value: 'storedValueOnly' },
|
||||
{ label: '两种支付', value: 'bothPayment' }
|
||||
]
|
||||
},
|
||||
sortIndex: {
|
||||
type: Number,
|
||||
default: 0
|
||||
}
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:sortIndex', 'timePick'])
|
||||
|
||||
const localSortIndex = ref(props.sortIndex)
|
||||
|
||||
watch(() => props.sortIndex, (val) => {
|
||||
localSortIndex.value = val
|
||||
})
|
||||
|
||||
const onSortChange = (e) => {
|
||||
localSortIndex.value = e.detail.value
|
||||
console.log('[FilterSection] 排序方式变更:', {
|
||||
index: localSortIndex.value,
|
||||
value: props.sortOptions[localSortIndex.value]
|
||||
})
|
||||
emit('update:sortIndex', localSortIndex.value)
|
||||
}
|
||||
|
||||
const handleTimePick = () => {
|
||||
console.log('[FilterSection] 触发时间选择器')
|
||||
emit('timePick')
|
||||
}
|
||||
|
||||
const getFilterParams = () => {
|
||||
const params = {
|
||||
sortType: props.sortOptions[localSortIndex.value].value,
|
||||
timeRangeText: props.timeRangeText
|
||||
}
|
||||
console.log('[FilterSection] 获取筛选参数:', params)
|
||||
return params
|
||||
}
|
||||
|
||||
const getSortType = () => {
|
||||
return props.sortOptions[localSortIndex.value].value
|
||||
}
|
||||
|
||||
const comparePrice = (a, b, ascending = true) => {
|
||||
const getEffectivePrice = (item) => {
|
||||
if (item.storedValueAmount > 0 && item.pointCardAmount > 0) {
|
||||
return Math.min(item.storedValueAmount, item.pointCardAmount * 50)
|
||||
} else if (item.storedValueAmount > 0) {
|
||||
return item.storedValueAmount
|
||||
} else if (item.pointCardAmount > 0) {
|
||||
return item.pointCardAmount * 50
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
const priceA = getEffectivePrice(a)
|
||||
const priceB = getEffectivePrice(b)
|
||||
|
||||
return ascending ? priceA - priceB : priceB - priceA
|
||||
}
|
||||
|
||||
const compareByPaymentType = (a, b, sortType) => {
|
||||
const getPaymentType = (item) => {
|
||||
const hasPointCard = item.pointCardAmount > 0
|
||||
const hasStoredValue = item.storedValueAmount > 0
|
||||
|
||||
if (hasPointCard && !hasStoredValue) return 1
|
||||
if (!hasPointCard && hasStoredValue) return 2
|
||||
if (hasPointCard && hasStoredValue) return 3
|
||||
return 0
|
||||
}
|
||||
|
||||
const typeA = getPaymentType(a)
|
||||
const typeB = getPaymentType(b)
|
||||
|
||||
switch (sortType) {
|
||||
case 'pointCardOnly':
|
||||
if (typeA === 1 && typeB !== 1) return -1
|
||||
if (typeA !== 1 && typeB === 1) return 1
|
||||
return 0
|
||||
case 'storedValueOnly':
|
||||
if (typeA === 2 && typeB !== 2) return -1
|
||||
if (typeA !== 2 && typeB === 2) return 1
|
||||
return 0
|
||||
case 'bothPayment':
|
||||
if (typeA === 3 && typeB !== 3) return -1
|
||||
if (typeA !== 3 && typeB === 3) return 1
|
||||
return 0
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
const sortCourses = (courses) => {
|
||||
const sortType = getSortType()
|
||||
if (!courses || !Array.isArray(courses)) return []
|
||||
|
||||
const sorted = [...courses]
|
||||
|
||||
switch (sortType) {
|
||||
case 'priceAsc':
|
||||
sorted.sort((a, b) => comparePrice(a, b, true))
|
||||
break
|
||||
case 'priceDesc':
|
||||
sorted.sort((a, b) => comparePrice(a, b, false))
|
||||
break
|
||||
case 'spotsDesc':
|
||||
sorted.sort((a, b) => (b.maxMembers - b.currentMembers) - (a.maxMembers - a.currentMembers))
|
||||
break
|
||||
case 'pointCardOnly':
|
||||
case 'storedValueOnly':
|
||||
case 'bothPayment':
|
||||
sorted.sort((a, b) => compareByPaymentType(a, b, sortType))
|
||||
break
|
||||
default:
|
||||
sorted.sort((a, b) => new Date(a.startTime) - new Date(b.startTime))
|
||||
}
|
||||
|
||||
return sorted
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
getFilterParams,
|
||||
getSortType,
|
||||
sortCourses
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.filter-section {
|
||||
display: flex;
|
||||
gap: 16rpx;
|
||||
|
||||
.filter-item {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12rpx;
|
||||
padding: 20rpx 24rpx;
|
||||
background: #F5F7FA;
|
||||
border-radius: 16rpx;
|
||||
font-size: 26rpx;
|
||||
color: #5E6F8D;
|
||||
|
||||
.filter-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.filter-arrow {
|
||||
margin-left: auto;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,165 @@
|
||||
<template>
|
||||
<view class="search-bar-wrapper">
|
||||
<!-- 搜索框 -->
|
||||
<view class="search-bar">
|
||||
<view class="search-input-wrapper">
|
||||
<uni-icons type="search" size="20" color="#A0AEC0" class="search-icon" />
|
||||
<input
|
||||
class="search-input"
|
||||
v-model="keyword"
|
||||
placeholder="搜索课程名称"
|
||||
placeholder-class="input-placeholder"
|
||||
@confirm="handleSearch"
|
||||
/>
|
||||
<uni-icons
|
||||
v-if="keyword"
|
||||
type="closeempty"
|
||||
size="16"
|
||||
color="#A0AEC0"
|
||||
class="clear-icon"
|
||||
@click="clearSearch"
|
||||
/>
|
||||
</view>
|
||||
<view class="search-btn" @click="handleSearch">搜索</view>
|
||||
</view>
|
||||
|
||||
<!-- 热门关键词 -->
|
||||
<view class="hot-keywords">
|
||||
<text class="hot-label">热门搜索:</text>
|
||||
<view
|
||||
v-for="(kw, index) in hotKeywords"
|
||||
:key="index"
|
||||
:class="['hot-tag', { active: keyword === kw }]"
|
||||
@click="selectKeyword(kw)"
|
||||
>
|
||||
{{ kw }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
hotKeywords: {
|
||||
type: Array,
|
||||
default: () => ['燃脂', '瑜伽', '单车', '普拉提', '高强度']
|
||||
}
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:modelValue', 'search'])
|
||||
|
||||
const keyword = ref(props.modelValue)
|
||||
|
||||
watch(() => props.modelValue, (val) => {
|
||||
keyword.value = val
|
||||
})
|
||||
|
||||
const handleSearch = () => {
|
||||
console.log('[SearchBar] 搜索参数:', { keyword: keyword.value })
|
||||
emit('update:modelValue', keyword.value)
|
||||
emit('search', { keyword: keyword.value })
|
||||
}
|
||||
|
||||
const clearSearch = () => {
|
||||
keyword.value = ''
|
||||
emit('update:modelValue', '')
|
||||
console.log('[SearchBar] 已清除搜索关键词')
|
||||
}
|
||||
|
||||
const selectKeyword = (kw) => {
|
||||
keyword.value = kw
|
||||
handleSearch()
|
||||
}
|
||||
|
||||
const getSearchParams = () => {
|
||||
console.log('[SearchBar] 获取搜索参数:', { keyword: keyword.value })
|
||||
return { keyword: keyword.value }
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
getSearchParams,
|
||||
clearSearch
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/* 搜索框 */
|
||||
.search-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
margin-bottom: 20rpx;
|
||||
|
||||
.search-input-wrapper {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: #F5F7FA;
|
||||
border-radius: 44rpx;
|
||||
padding: 0 24rpx;
|
||||
height: 72rpx;
|
||||
|
||||
.search-icon {
|
||||
margin-right: 12rpx;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
flex: 1;
|
||||
font-size: 28rpx;
|
||||
color: #1a202c;
|
||||
}
|
||||
|
||||
.input-placeholder {
|
||||
color: #A0AEC0;
|
||||
}
|
||||
|
||||
.clear-icon {
|
||||
padding: 8rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.search-btn {
|
||||
padding: 0 32rpx;
|
||||
height: 72rpx;
|
||||
line-height: 72rpx;
|
||||
background: linear-gradient(135deg, #FF6B35 0%, #FF8C5A 100%);
|
||||
color: #ffffff;
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
border-radius: 44rpx;
|
||||
}
|
||||
}
|
||||
|
||||
/* 热门关键词 */
|
||||
.hot-keywords {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
|
||||
.hot-label {
|
||||
font-size: 26rpx;
|
||||
color: #8A99B4;
|
||||
}
|
||||
|
||||
.hot-tag {
|
||||
padding: 8rpx 20rpx;
|
||||
background: #F5F7FA;
|
||||
color: #5E6F8D;
|
||||
font-size: 24rpx;
|
||||
border-radius: 28rpx;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&.active {
|
||||
background: linear-gradient(135deg, #FF6B35 0%, #FF8C5A 100%);
|
||||
color: #ffffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,191 @@
|
||||
<template>
|
||||
<view class="time-period-selector">
|
||||
<view class="sort-header">
|
||||
<uni-icons type="calendar" size="16" color="#FF6B35" class="sort-icon" />
|
||||
<text class="sort-label">上课时段</text>
|
||||
</view>
|
||||
<view class="slider-wrapper">
|
||||
<view
|
||||
v-for="(option, index) in timePeriodOptions"
|
||||
:key="index"
|
||||
:class="['slider-item', { active: currentIndex === index }]"
|
||||
@click="handlePeriodChange(index)"
|
||||
>
|
||||
<span class="iconfont_time_select" v-bind:class="getPeriodIcon(option.value)"></span>
|
||||
|
||||
<text :class="['slider-text', { active: currentIndex === index }]">
|
||||
{{ option.label.split(' ')[0] }}
|
||||
</text>
|
||||
</view>
|
||||
<!-- 滑动指示器 -->
|
||||
<view
|
||||
class="slider-indicator"
|
||||
:style="{ left: `calc(8rpx + ${currentIndex} * (100% - 16rpx) / 4)` }"
|
||||
></view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
timePeriodOptions: {
|
||||
type: Array,
|
||||
default: () => [
|
||||
{ label: '全部', value: 'all' },
|
||||
{ label: '早上 (6-12 点)', value: 'morning', startHour: 6, endHour: 12 },
|
||||
{ label: '下午 (12-18 点)', value: 'afternoon', startHour: 12, endHour: 18 },
|
||||
{ label: '晚上 (18-24 点)', value: 'evening', startHour: 18, endHour: 24 }
|
||||
]
|
||||
},
|
||||
modelValue: {
|
||||
type: Number,
|
||||
default: 0
|
||||
}
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:modelValue', 'change'])
|
||||
|
||||
const currentIndex = ref(props.modelValue)
|
||||
|
||||
watch(() => props.modelValue, (val) => {
|
||||
currentIndex.value = val
|
||||
})
|
||||
|
||||
const getPeriodIcon = (value) => {
|
||||
const iconMap = {
|
||||
'all': 'icon-gengduo ',
|
||||
'morning': 'icon-zaochen',
|
||||
'afternoon': 'icon-xiawucha ',
|
||||
'evening': 'icon-yewan '
|
||||
}
|
||||
return iconMap[value] || iconMap[all]
|
||||
}
|
||||
|
||||
const handlePeriodChange = (index) => {
|
||||
currentIndex.value = index
|
||||
const option = props.timePeriodOptions[index]
|
||||
console.log('[TimePeriodSelector] 时间段变更:', {
|
||||
index,
|
||||
value: option.value,
|
||||
label: option.label
|
||||
})
|
||||
emit('update:modelValue', index)
|
||||
emit('change', option)
|
||||
}
|
||||
|
||||
const getTimePeriodParams = () => {
|
||||
const option = props.timePeriodOptions[currentIndex.value]
|
||||
const params = {
|
||||
index: currentIndex.value,
|
||||
value: option.value,
|
||||
label: option.label,
|
||||
startHour: option.startHour,
|
||||
endHour: option.endHour
|
||||
}
|
||||
console.log('[TimePeriodSelector] 获取时间段参数:', params)
|
||||
return params
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
getTimePeriodParams,
|
||||
getPeriodIcon
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@import "@/common/style/iconfont_time_select.css";
|
||||
|
||||
.time-period-selector {
|
||||
padding: 24rpx;
|
||||
background: linear-gradient(135deg, #F5F7FA 0%, #E9EDF2 100%);
|
||||
border-radius: 20rpx;
|
||||
box-shadow: inset 0 2rpx 8rpx rgba(0, 0, 0, 0.03);
|
||||
|
||||
.sort-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10rpx;
|
||||
margin-bottom: 20rpx;
|
||||
|
||||
.sort-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.sort-label {
|
||||
font-size: 28rpx;
|
||||
color: #1a202c;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
.slider-wrapper {
|
||||
position: relative;
|
||||
display: flex;
|
||||
background: #ffffff;
|
||||
border-radius: 16rpx;
|
||||
padding: 8rpx;
|
||||
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.08);
|
||||
overflow: hidden;
|
||||
|
||||
.slider-item {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8rpx;
|
||||
padding: 20rpx 0;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
|
||||
.slider-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.slider-text {
|
||||
font-size: 24rpx;
|
||||
color: #8A99B4;
|
||||
font-weight: 500;
|
||||
transition: all 0.3s ease;
|
||||
|
||||
&.active {
|
||||
color: #ffffff;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
&.active {
|
||||
.slider-icon {
|
||||
color: #ffffff !important;
|
||||
}
|
||||
|
||||
.slider-text {
|
||||
color: #ffffff !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 滑动指示器 */
|
||||
.slider-indicator {
|
||||
position: absolute;
|
||||
top: 8rpx;
|
||||
left: 8rpx;
|
||||
width: calc((100% - 16rpx) / 4);
|
||||
height: calc(100% - 16rpx);
|
||||
background: linear-gradient(135deg, #FF6B35 0%, #FF8C5A 100%);
|
||||
border-radius: 12rpx;
|
||||
box-shadow: 0 4rpx 12rpx rgba(255, 107, 53, 0.4);
|
||||
transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
z-index: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,728 @@
|
||||
<template>
|
||||
<view>
|
||||
<!-- 时间范围选择弹窗 -->
|
||||
<Transition name="modal">
|
||||
<view v-if="visible" class="time-range-modal">
|
||||
<view class="modal-mask" @click="handleClose"></view>
|
||||
<view class="modal-content">
|
||||
<view class="modal-header">
|
||||
<text class="modal-title">选择时间范围</text>
|
||||
<view class="header-actions">
|
||||
<text class="modal-clear" @click="handleClear">清空</text>
|
||||
<text class="modal-close" @click="handleClose">×</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="modal-body">
|
||||
<!-- 开始日期 -->
|
||||
<view class="date-item">
|
||||
<text class="date-label">开始日期</text>
|
||||
<view class="date-value" @click="toggleStartPicker">
|
||||
<text>{{ localStartDate || '请选择' }}</text>
|
||||
<text class="date-arrow">›</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 结束日期 -->
|
||||
<view class="date-item">
|
||||
<text class="date-label">结束日期</text>
|
||||
<view class="date-value" @click="toggleEndPicker">
|
||||
<text>{{ localEndDate || '请选择' }}</text>
|
||||
<text class="date-arrow">›</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 快捷选择 -->
|
||||
<view class="quick-select">
|
||||
<text class="quick-label">快捷选择</text>
|
||||
<view class="quick-btns">
|
||||
<view
|
||||
v-for="item in quickOptions"
|
||||
:key="item.value"
|
||||
class="quick-btn"
|
||||
:class="{ active: quickSelected === item.value }"
|
||||
@click="applyQuickOption(item.value)"
|
||||
>
|
||||
{{ item.label }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="modal-footer">
|
||||
<view class="btn btn-cancel" @click="handleClose">取消</view>
|
||||
<view class="btn btn-confirm" @click="handleConfirm">确定</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 日期选择器弹窗 -->
|
||||
<Transition name="date-picker">
|
||||
<view v-if="showDatePicker" class="date-picker-modal">
|
||||
<view class="date-mask" @click="showDatePicker = false"></view>
|
||||
<view class="date-picker-content">
|
||||
<view class="date-header">
|
||||
<text class="date-prev" @click="prevMonth">‹</text>
|
||||
<text class="date-title">{{ currentYear }}年{{ currentMonth }}月</text>
|
||||
<text class="date-next" @click="nextMonth">›</text>
|
||||
</view>
|
||||
<view class="date-weekdays">
|
||||
<text v-for="day in weekdays" :key="day">{{ day }}</text>
|
||||
</view>
|
||||
<view class="date-days">
|
||||
<view
|
||||
v-for="(day, index) in calendarDays"
|
||||
:key="index"
|
||||
class="date-day"
|
||||
:class="{
|
||||
'other-month': !day.currentMonth,
|
||||
'today': day.isToday,
|
||||
'selected': day.date === selectedDate,
|
||||
'disabled': day.disabled
|
||||
}"
|
||||
@click="selectDate(day)"
|
||||
>
|
||||
{{ day.day }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</Transition>
|
||||
</view>
|
||||
</Transition>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch, computed, onMounted } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
startDate: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
endDate: {
|
||||
type: String,
|
||||
default: ''
|
||||
}
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:visible', 'update:startDate', 'update:endDate', 'confirm', 'cancel'])
|
||||
|
||||
const localStartDate = ref(props.startDate)
|
||||
const localEndDate = ref(props.endDate)
|
||||
const showDatePicker = ref(false)
|
||||
const pickerType = ref('start') // 'start' | 'end'
|
||||
const currentYear = ref(2024)
|
||||
const currentMonth = ref(1)
|
||||
const selectedDate = ref('')
|
||||
const quickSelected = ref('')
|
||||
|
||||
const weekdays = ['日', '一', '二', '三', '四', '五', '六']
|
||||
|
||||
const quickOptions = [
|
||||
{ label: '近7天', value: '7d' },
|
||||
{ label: '近30天', value: '30d' },
|
||||
{ label: '本月', value: 'month' },
|
||||
{ label: '上月', value: 'lastMonth' }
|
||||
]
|
||||
|
||||
// 监听 props 变化
|
||||
watch(() => props.startDate, (val) => {
|
||||
localStartDate.value = val
|
||||
})
|
||||
|
||||
watch(() => props.endDate, (val) => {
|
||||
localEndDate.value = val
|
||||
})
|
||||
|
||||
watch(() => props.visible, (val) => {
|
||||
if (val) {
|
||||
// 弹窗打开时设置当前日期
|
||||
const now = new Date()
|
||||
currentYear.value = now.getFullYear()
|
||||
currentMonth.value = now.getMonth() + 1
|
||||
}
|
||||
})
|
||||
|
||||
// 计算时间范围文本
|
||||
const timeRangeText = computed(() => {
|
||||
if (localStartDate.value && localEndDate.value) {
|
||||
return `${localStartDate.value} 至 ${localEndDate.value}`
|
||||
} else if (localStartDate.value) {
|
||||
return `${localStartDate.value} 起`
|
||||
} else if (localEndDate.value) {
|
||||
return `至 ${localEndDate.value}`
|
||||
}
|
||||
return ''
|
||||
})
|
||||
|
||||
// 生成日历日期
|
||||
const calendarDays = computed(() => {
|
||||
const days = []
|
||||
const firstDay = new Date(currentYear.value, currentMonth.value - 1, 1)
|
||||
const lastDay = new Date(currentYear.value, currentMonth.value, 0)
|
||||
const startDay = firstDay.getDay()
|
||||
const totalDays = lastDay.getDate()
|
||||
|
||||
// 上个月的天数
|
||||
const prevMonthLastDay = new Date(currentYear.value, currentMonth.value - 1, 0).getDate()
|
||||
for (let i = startDay - 1; i >= 0; i--) {
|
||||
days.push({
|
||||
day: prevMonthLastDay - i,
|
||||
date: formatDate(currentYear.value, currentMonth.value - 1, prevMonthLastDay - i),
|
||||
currentMonth: false,
|
||||
isToday: false,
|
||||
disabled: true
|
||||
})
|
||||
}
|
||||
|
||||
// 本月的天数
|
||||
const today = new Date()
|
||||
for (let i = 1; i <= totalDays; i++) {
|
||||
const dateStr = formatDate(currentYear.value, currentMonth.value, i)
|
||||
days.push({
|
||||
day: i,
|
||||
date: dateStr,
|
||||
currentMonth: true,
|
||||
isToday: isToday(currentYear.value, currentMonth.value, i),
|
||||
disabled: isFuture(currentYear.value, currentMonth.value, i)
|
||||
})
|
||||
}
|
||||
|
||||
// 下个月的天数
|
||||
const remaining = 42 - days.length
|
||||
for (let i = 1; i <= remaining; i++) {
|
||||
days.push({
|
||||
day: i,
|
||||
date: formatDate(currentYear.value, currentMonth.value + 1, i),
|
||||
currentMonth: false,
|
||||
isToday: false,
|
||||
disabled: true
|
||||
})
|
||||
}
|
||||
|
||||
return days
|
||||
})
|
||||
|
||||
// 格式化日期
|
||||
function formatDate(year, month, day) {
|
||||
const m = month.toString().padStart(2, '0')
|
||||
const d = day.toString().padStart(2, '0')
|
||||
return `${year}-${m}-${d}`
|
||||
}
|
||||
|
||||
// 判断是否是今天
|
||||
function isToday(year, month, day) {
|
||||
const today = new Date()
|
||||
return year === today.getFullYear() &&
|
||||
month === today.getMonth() + 1 &&
|
||||
day === today.getDate()
|
||||
}
|
||||
|
||||
// 判断是否是未来日期
|
||||
function isFuture(year, month, day) {
|
||||
const today = new Date()
|
||||
today.setHours(0, 0, 0, 0)
|
||||
const date = new Date(year, month - 1, day)
|
||||
return date > today
|
||||
}
|
||||
|
||||
// 切换日期选择器
|
||||
const toggleStartPicker = () => {
|
||||
pickerType.value = 'start'
|
||||
selectedDate.value = localStartDate.value
|
||||
showDatePicker.value = true
|
||||
}
|
||||
|
||||
const toggleEndPicker = () => {
|
||||
pickerType.value = 'end'
|
||||
selectedDate.value = localEndDate.value
|
||||
showDatePicker.value = true
|
||||
}
|
||||
|
||||
// 月份切换
|
||||
const prevMonth = () => {
|
||||
if (currentMonth.value === 1) {
|
||||
currentYear.value--
|
||||
currentMonth.value = 12
|
||||
} else {
|
||||
currentMonth.value--
|
||||
}
|
||||
}
|
||||
|
||||
const nextMonth = () => {
|
||||
if (currentMonth.value === 12) {
|
||||
currentYear.value++
|
||||
currentMonth.value = 1
|
||||
} else {
|
||||
currentMonth.value++
|
||||
}
|
||||
}
|
||||
|
||||
// 选择日期
|
||||
const selectDate = (day) => {
|
||||
if (day.disabled) return
|
||||
selectedDate.value = day.date
|
||||
if (pickerType.value === 'start') {
|
||||
localStartDate.value = day.date
|
||||
emit('update:startDate', day.date)
|
||||
} else {
|
||||
localEndDate.value = day.date
|
||||
emit('update:endDate', day.date)
|
||||
}
|
||||
showDatePicker.value = false
|
||||
console.log(`[TimeRangePicker] ${pickerType.value === 'start' ? '开始' : '结束'}日期变更:`, day.date)
|
||||
}
|
||||
|
||||
// 应用快捷选项
|
||||
const applyQuickOption = (value) => {
|
||||
quickSelected.value = value
|
||||
const today = new Date()
|
||||
let startDate, endDate
|
||||
|
||||
switch (value) {
|
||||
case '7d':
|
||||
startDate = new Date(today.getTime() - 7 * 24 * 60 * 60 * 1000)
|
||||
endDate = today
|
||||
break
|
||||
case '30d':
|
||||
startDate = new Date(today.getTime() - 30 * 24 * 60 * 60 * 1000)
|
||||
endDate = today
|
||||
break
|
||||
case 'month':
|
||||
startDate = new Date(today.getFullYear(), today.getMonth(), 1)
|
||||
endDate = today
|
||||
break
|
||||
case 'lastMonth':
|
||||
startDate = new Date(today.getFullYear(), today.getMonth() - 1, 1)
|
||||
endDate = new Date(today.getFullYear(), today.getMonth(), 0)
|
||||
break
|
||||
}
|
||||
|
||||
localStartDate.value = formatDate(startDate.getFullYear(), startDate.getMonth() + 1, startDate.getDate())
|
||||
localEndDate.value = formatDate(endDate.getFullYear(), endDate.getMonth() + 1, endDate.getDate())
|
||||
emit('update:startDate', localStartDate.value)
|
||||
emit('update:endDate', localEndDate.value)
|
||||
console.log('[TimeRangePicker] 快捷选择:', value, { start: localStartDate.value, end: localEndDate.value })
|
||||
}
|
||||
|
||||
// 清空选择
|
||||
const handleClear = () => {
|
||||
localStartDate.value = ''
|
||||
localEndDate.value = ''
|
||||
quickSelected.value = ''
|
||||
emit('update:startDate', '')
|
||||
emit('update:endDate', '')
|
||||
console.log('[TimeRangePicker] 已清空时间选择')
|
||||
}
|
||||
|
||||
// 关闭弹窗
|
||||
const handleClose = () => {
|
||||
console.log('[TimeRangePicker] 关闭时间选择器')
|
||||
emit('update:visible', false)
|
||||
emit('cancel')
|
||||
}
|
||||
|
||||
// 确认选择
|
||||
const handleConfirm = () => {
|
||||
console.log('[TimeRangePicker] 确认时间范围:', {
|
||||
startDate: localStartDate.value,
|
||||
endDate: localEndDate.value,
|
||||
timeRangeText: timeRangeText.value
|
||||
})
|
||||
emit('update:visible', false)
|
||||
emit('confirm', {
|
||||
startDate: localStartDate.value,
|
||||
endDate: localEndDate.value,
|
||||
timeRangeText: timeRangeText.value
|
||||
})
|
||||
}
|
||||
|
||||
// 获取参数
|
||||
const getTimeRangeParams = () => {
|
||||
const params = {
|
||||
startDate: localStartDate.value,
|
||||
endDate: localEndDate.value,
|
||||
timeRangeText: timeRangeText.value
|
||||
}
|
||||
console.log('[TimeRangePicker] 获取时间范围参数:', params)
|
||||
return params
|
||||
}
|
||||
|
||||
// 重置日期
|
||||
const resetDate = () => {
|
||||
localStartDate.value = ''
|
||||
localEndDate.value = ''
|
||||
quickSelected.value = ''
|
||||
emit('update:startDate', '')
|
||||
emit('update:endDate', '')
|
||||
console.log('[TimeRangePicker] 已重置日期')
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
getTimeRangeParams,
|
||||
resetDate,
|
||||
timeRangeText
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.time-range-modal {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 1000;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
.modal-mask {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
transition: background 0.3s ease;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
position: relative;
|
||||
width: 640rpx;
|
||||
background: #ffffff;
|
||||
border-radius: 24rpx;
|
||||
overflow: hidden;
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 32rpx;
|
||||
border-bottom: 1rpx solid #E9EDF2;
|
||||
|
||||
.modal-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: #1a202c;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 24rpx;
|
||||
}
|
||||
|
||||
.modal-clear {
|
||||
font-size: 28rpx;
|
||||
color: #8A99B4;
|
||||
padding: 8rpx 16rpx;
|
||||
}
|
||||
|
||||
.modal-close {
|
||||
font-size: 48rpx;
|
||||
color: #8A99B4;
|
||||
line-height: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
padding: 32rpx;
|
||||
|
||||
.date-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 24rpx 0;
|
||||
border-bottom: 1rpx solid #F0F2F5;
|
||||
|
||||
&:last-of-type {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.date-label {
|
||||
font-size: 28rpx;
|
||||
color: #6B7280;
|
||||
}
|
||||
|
||||
.date-value {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
|
||||
text {
|
||||
font-size: 28rpx;
|
||||
color: #1a202c;
|
||||
}
|
||||
|
||||
.date-arrow {
|
||||
font-size: 32rpx;
|
||||
color: #C4C9D4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.quick-select {
|
||||
margin-top: 24rpx;
|
||||
|
||||
.quick-label {
|
||||
font-size: 26rpx;
|
||||
color: #9CA3AF;
|
||||
margin-bottom: 16rpx;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.quick-btns {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 16rpx;
|
||||
|
||||
.quick-btn {
|
||||
padding: 16rpx 28rpx;
|
||||
background: #F5F7FA;
|
||||
border-radius: 32rpx;
|
||||
font-size: 26rpx;
|
||||
color: #6B7280;
|
||||
|
||||
&.active {
|
||||
background: #FF6B35;
|
||||
color: #ffffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
display: flex;
|
||||
border-top: 1rpx solid #E9EDF2;
|
||||
|
||||
.btn {
|
||||
flex: 1;
|
||||
padding: 32rpx;
|
||||
text-align: center;
|
||||
font-size: 30rpx;
|
||||
|
||||
&.btn-cancel {
|
||||
color: #6B7280;
|
||||
border-right: 1rpx solid #E9EDF2;
|
||||
}
|
||||
|
||||
&.btn-confirm {
|
||||
color: #FF6B35;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.date-picker-modal {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 1001;
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
|
||||
.date-mask {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
transition: background 0.3s ease;
|
||||
}
|
||||
|
||||
.date-picker-content {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
background: #ffffff;
|
||||
border-radius: 32rpx 32rpx 0 0;
|
||||
transform: translateY(0);
|
||||
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
|
||||
.date-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 32rpx;
|
||||
|
||||
.date-prev, .date-next {
|
||||
font-size: 40rpx;
|
||||
color: #1a202c;
|
||||
width: 64rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.date-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: #1a202c;
|
||||
}
|
||||
}
|
||||
|
||||
.date-weekdays {
|
||||
display: flex;
|
||||
padding: 0 24rpx;
|
||||
|
||||
text {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
font-size: 26rpx;
|
||||
color: #9CA3AF;
|
||||
padding: 16rpx 0;
|
||||
}
|
||||
}
|
||||
|
||||
.date-days {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
padding: 16rpx 24rpx 32rpx;
|
||||
|
||||
.date-day {
|
||||
width: calc(100% / 7);
|
||||
height: 80rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 28rpx;
|
||||
color: #1a202c;
|
||||
border-radius: 50%;
|
||||
|
||||
&.other-month {
|
||||
color: #D1D5DB;
|
||||
}
|
||||
|
||||
&.today {
|
||||
background: #F5F7FA;
|
||||
color: #FF6B35;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
&.selected {
|
||||
background: #FF6B35;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
color: #E5E7EB;
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 居中弹窗进入动画 */
|
||||
.modal-enter-active {
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.modal-enter-active .modal-mask {
|
||||
transition: background 0.3s ease;
|
||||
}
|
||||
|
||||
.modal-enter-active .modal-content {
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.modal-enter-from .modal-mask {
|
||||
background: rgba(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
.modal-enter-from .modal-content {
|
||||
opacity: 0;
|
||||
transform: scale(0.9);
|
||||
}
|
||||
|
||||
/* 居中弹窗退出动画 */
|
||||
.modal-leave-active {
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.modal-leave-active .modal-mask {
|
||||
transition: background 0.3s ease;
|
||||
}
|
||||
|
||||
.modal-leave-active .modal-content {
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.modal-leave-to .modal-mask {
|
||||
background: rgba(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
.modal-leave-to .modal-content {
|
||||
opacity: 0;
|
||||
transform: scale(0.9);
|
||||
}
|
||||
|
||||
@keyframes modalIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: scale(0.9);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes slideUp {
|
||||
from {
|
||||
transform: translateY(100%);
|
||||
}
|
||||
to {
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
/* 日期选择器进入动画 */
|
||||
.date-picker-enter-active {
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.date-picker-enter-active .date-mask {
|
||||
transition: background 0.3s ease;
|
||||
}
|
||||
|
||||
.date-picker-enter-active .date-picker-content {
|
||||
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.date-picker-enter-from .date-mask {
|
||||
background: rgba(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
.date-picker-enter-from .date-picker-content {
|
||||
transform: translateY(100%);
|
||||
}
|
||||
|
||||
/* 日期选择器退出动画 */
|
||||
.date-picker-leave-active {
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.date-picker-leave-active .date-mask {
|
||||
transition: background 0.3s ease;
|
||||
}
|
||||
|
||||
.date-picker-leave-active .date-picker-content {
|
||||
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.date-picker-leave-to .date-mask {
|
||||
background: rgba(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
.date-picker-leave-to .date-picker-content {
|
||||
transform: translateY(100%);
|
||||
}
|
||||
</style>
|
||||
@@ -6,6 +6,7 @@
|
||||
v-for="(item, index) in entries"
|
||||
:key="index"
|
||||
class="entry-item"
|
||||
@tap="QEClick(item.path)"
|
||||
>
|
||||
<!-- 入口图标容器 -->
|
||||
<view :class="['entry-icon', { accent: item.accent }]">
|
||||
@@ -21,37 +22,44 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
|
||||
const QEClick = () => {
|
||||
uni.navigateTo({
|
||||
url:"/pages/checkIn/checkIn"
|
||||
})
|
||||
}
|
||||
// 快捷入口数据列表
|
||||
const entries = [
|
||||
{
|
||||
icon: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/icons/course.png',
|
||||
title: '找课程',
|
||||
desc: '精品课程',
|
||||
accent: false ,
|
||||
accent: false
|
||||
},
|
||||
{
|
||||
icon: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/icons/plan.png',
|
||||
title: '训练计划',
|
||||
desc: '个性定制',
|
||||
accent: true ,
|
||||
accent: true
|
||||
},
|
||||
{
|
||||
icon: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/icons/data.png',
|
||||
title: '健身数据',
|
||||
desc: '记录分析',
|
||||
accent: false ,
|
||||
accent: false
|
||||
},
|
||||
{
|
||||
icon: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/icons/message.png',
|
||||
title: '消息',
|
||||
desc: '通知消息',
|
||||
accent: true,
|
||||
accent: true
|
||||
},
|
||||
{
|
||||
icon: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/icons/checkIn.png',
|
||||
title: '签到',
|
||||
desc: '打卡签到',
|
||||
accent: false,
|
||||
path: "/pages/checkIn/checkIn"
|
||||
}
|
||||
]
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
import { ref, computed } from 'vue'
|
||||
import { groupCourseService } from '@/api/envConfig.js'
|
||||
|
||||
export function useGroupCourseList() {
|
||||
// 分页相关
|
||||
const pageNum = ref(1)
|
||||
const pageSize = ref(10)
|
||||
const total = ref(0)
|
||||
const totalPages = ref(0)
|
||||
const loading = ref(false)
|
||||
const hasMore = ref(true)
|
||||
|
||||
// 团课列表数据
|
||||
const courseList = ref([])
|
||||
|
||||
// 搜索相关
|
||||
const searchKeyword = ref('')
|
||||
const hotKeywords = ref(['燃脂', '瑜伽', '单车', '普拉提', '高强度'])
|
||||
|
||||
// 排序相关
|
||||
const sortOptions = ref([
|
||||
{ label: '默认排序', value: 'default' },
|
||||
{ label: '价格从低到高', value: 'priceAsc' },
|
||||
{ label: '价格从高到低', value: 'priceDesc' },
|
||||
{ label: '剩余名额最多', value: 'spotsDesc' }
|
||||
])
|
||||
const sortIndex = ref(0)
|
||||
|
||||
// 时间段选择相关
|
||||
const timePeriodOptions = ref([
|
||||
{ label: '全部', value: 'all' },
|
||||
{ label: '早上 (6-12 点)', value: 'morning', startHour: 6, endHour: 12 },
|
||||
{ label: '下午 (12-18 点)', value: 'afternoon', startHour: 12, endHour: 18 },
|
||||
{ label: '晚上 (18-24 点)', value: 'evening', startHour: 18, endHour: 24 }
|
||||
])
|
||||
const timePeriodIndex = ref(0)
|
||||
|
||||
// 时间筛选相关
|
||||
const showTimePicker = ref(false)
|
||||
const startDate = ref('')
|
||||
const endDate = ref('')
|
||||
const timeRangeText = ref('')
|
||||
|
||||
// 筛选后的课程列表
|
||||
const filteredCourseList = computed(() => {
|
||||
let result = [...courseList.value]
|
||||
|
||||
// 关键词搜索
|
||||
if (searchKeyword.value) {
|
||||
result = result.filter(course =>
|
||||
course.courseName.includes(searchKeyword.value)
|
||||
)
|
||||
}
|
||||
|
||||
// 时间范围筛选
|
||||
if (startDate.value || endDate.value) {
|
||||
result = result.filter(course => {
|
||||
const courseDate = course.startTime.split('T')[0]
|
||||
if (startDate.value && courseDate < startDate.value) return false
|
||||
if (endDate.value && courseDate > endDate.value) return false
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
// 时间段筛选
|
||||
const timePeriod = timePeriodOptions.value[timePeriodIndex.value]
|
||||
if (timePeriod.value !== 'all') {
|
||||
result = result.filter(course => {
|
||||
const courseHour = new Date(course.startTime).getHours()
|
||||
return courseHour >= timePeriod.startHour && courseHour < timePeriod.endHour
|
||||
})
|
||||
}
|
||||
|
||||
// 排序
|
||||
const sortType = sortOptions.value[sortIndex.value].value
|
||||
if (sortType === 'priceAsc') {
|
||||
result.sort((a, b) => (a.storedValueAmount || a.pointCardAmount) - (b.storedValueAmount || b.pointCardAmount))
|
||||
} else if (sortType === 'priceDesc') {
|
||||
result.sort((a, b) => (b.storedValueAmount || b.pointCardAmount) - (a.storedValueAmount || a.pointCardAmount))
|
||||
} else if (sortType === 'spotsDesc') {
|
||||
result.sort((a, b) => (b.maxMembers - b.currentMembers) - (a.maxMembers - a.currentMembers))
|
||||
}
|
||||
|
||||
return result
|
||||
})
|
||||
|
||||
// 获取所有搜索参数
|
||||
const getAllSearchParams = (searchBarRef, filterSectionRef, timePeriodRef, timeRangePickerRef) => {
|
||||
const searchParams = searchBarRef?.getSearchParams?.() || { keyword: searchKeyword.value }
|
||||
const filterParams = filterSectionRef?.getFilterParams?.() || { sortType: sortOptions.value[sortIndex.value].value }
|
||||
const timePeriodParams = timePeriodRef?.getTimePeriodParams?.() || { index: timePeriodIndex.value, value: timePeriodOptions.value[timePeriodIndex.value].value }
|
||||
const timeRangeParams = timeRangePickerRef?.getTimeRangeParams?.() || { startDate: startDate.value, endDate: endDate.value, timeRangeText: timeRangeText.value }
|
||||
|
||||
const allParams = {
|
||||
search: searchParams,
|
||||
filter: filterParams,
|
||||
timePeriod: timePeriodParams,
|
||||
timeRange: timeRangeParams
|
||||
}
|
||||
|
||||
console.log('[useGroupCourseList] 获取所有搜索参数:', allParams)
|
||||
return allParams
|
||||
}
|
||||
|
||||
// 搜索处理
|
||||
const handleSearch = (params) => {
|
||||
console.log('[useGroupCourseList] 搜索触发:', params)
|
||||
uni.showToast({
|
||||
title: params.keyword ? `搜索:${params.keyword}` : '请输入关键词',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
|
||||
// 时间段变化处理
|
||||
const onTimePeriodChange = (option) => {
|
||||
console.log('[useGroupCourseList] 时间段选择:', option)
|
||||
}
|
||||
|
||||
// 时间范围确认处理
|
||||
const onTimeRangeConfirm = (params) => {
|
||||
console.log('[useGroupCourseList] 时间范围确认:', params)
|
||||
timeRangeText.value = params.timeRangeText
|
||||
}
|
||||
|
||||
// 预约处理
|
||||
const handleBooking = (course) => {
|
||||
console.log('[useGroupCourseList] 预约课程:', course)
|
||||
uni.showToast({
|
||||
title: `预约课程:${course.courseName}`,
|
||||
icon: 'success'
|
||||
})
|
||||
}
|
||||
|
||||
// 跳转详情
|
||||
const goDetail = (courseId) => {
|
||||
console.log('[useGroupCourseList] 跳转到课程详情:', courseId)
|
||||
uni.navigateTo({
|
||||
url: `/pages/groupCourse/detail?id=${courseId}`
|
||||
})
|
||||
}
|
||||
|
||||
// 获取团课列表
|
||||
const fetchCourseList = async (isLoadMore = false) => {
|
||||
if (loading.value) return
|
||||
|
||||
loading.value = true
|
||||
|
||||
try {
|
||||
const result = await groupCourseService.getList({
|
||||
pageNum: pageNum.value,
|
||||
pageSize: pageSize.value
|
||||
})
|
||||
|
||||
if (result.code === 0 && result.data) {
|
||||
const { list, total: totalCount, pageNum: currentPage, totalPages: pages } = result.data
|
||||
|
||||
if (isLoadMore) {
|
||||
courseList.value = [...courseList.value, ...list]
|
||||
} else {
|
||||
courseList.value = list
|
||||
}
|
||||
|
||||
total.value = totalCount
|
||||
pageNum.value = currentPage
|
||||
totalPages.value = pages
|
||||
hasMore.value = pageNum.value < totalPages.value
|
||||
|
||||
console.log('[useGroupCourseList] 团课列表获取成功:', {
|
||||
total: total.value,
|
||||
currentPage: pageNum.value,
|
||||
totalPages: totalPages.value,
|
||||
hasMore: hasMore.value
|
||||
})
|
||||
} else {
|
||||
console.error('[useGroupCourseList] 获取团课列表失败:', result.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[useGroupCourseList] 获取团课列表异常:', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 加载更多
|
||||
const loadMore = () => {
|
||||
if (!hasMore.value || loading.value) return
|
||||
pageNum.value++
|
||||
fetchCourseList(true)
|
||||
}
|
||||
|
||||
// 滚动到底部触发
|
||||
const onScrollToLower = () => {
|
||||
loadMore()
|
||||
}
|
||||
|
||||
return {
|
||||
// 状态
|
||||
pageNum,
|
||||
pageSize,
|
||||
total,
|
||||
totalPages,
|
||||
loading,
|
||||
hasMore,
|
||||
courseList,
|
||||
searchKeyword,
|
||||
hotKeywords,
|
||||
sortOptions,
|
||||
sortIndex,
|
||||
timePeriodOptions,
|
||||
timePeriodIndex,
|
||||
showTimePicker,
|
||||
startDate,
|
||||
endDate,
|
||||
timeRangeText,
|
||||
filteredCourseList,
|
||||
|
||||
// 方法
|
||||
getAllSearchParams,
|
||||
handleSearch,
|
||||
onTimePeriodChange,
|
||||
onTimeRangeConfirm,
|
||||
handleBooking,
|
||||
goDetail,
|
||||
fetchCourseList,
|
||||
loadMore,
|
||||
onScrollToLower
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
# 团课管理系统 API 文档
|
||||
|
||||
## 1. 项目概述
|
||||
|
||||
本项目是一个基于 UniApp 的健身房团课管理系统,包含完整的 API 层设计,支持开发/生产环境的快速切换。
|
||||
|
||||
### 1.1 项目结构
|
||||
|
||||
```
|
||||
gym-manage-uniapp/
|
||||
├── api/ # API 层目录
|
||||
│ ├── requestBase.js # 基础请求封装
|
||||
│ ├── groupCourse.js # 团课真实API
|
||||
│ ├── groupCourse.mock.js # 团课模拟数据API
|
||||
│ └── envConfig.js # 环境配置与服务导出
|
||||
├── pages/
|
||||
│ └── groupCourse/
|
||||
│ └── list.vue # 团课列表页面
|
||||
└── components/ # 组件目录
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. API 层设计
|
||||
|
||||
### 2.1 架构设计
|
||||
|
||||
| 层级 | 文件 | 职责 |
|
||||
|------|------|------|
|
||||
| 基础层 | `requestBase.js` | 封装 uni.request,统一处理加载状态、错误提示 |
|
||||
| 接口层 | `groupCourse.js` | 定义真实后端API接口 |
|
||||
| 模拟层 | `groupCourse.mock.js` | 提供模拟数据,支持开发测试 |
|
||||
| 配置层 | `envConfig.js` | 环境配置,统一服务导出入口 |
|
||||
|
||||
### 2.2 环境切换机制
|
||||
|
||||
通过修改 `envConfig.js` 中的 `ENV_MODE` 变量实现环境切换:
|
||||
|
||||
```javascript
|
||||
// envConfig.js
|
||||
export const ENV_MODE = 'development' // 'production' | 'development'
|
||||
```
|
||||
|
||||
- **`production`**:生产环境,使用真实网络请求
|
||||
- **`development`**:开发环境,使用模拟数据
|
||||
|
||||
---
|
||||
|
||||
## 3. 文件详细说明
|
||||
|
||||
### 3.1 requestBase.js - 基础请求封装
|
||||
|
||||
**功能定位**:封装 `uni.request`,提供统一的请求处理逻辑。
|
||||
|
||||
**核心特性**:
|
||||
- 自动显示/隐藏加载提示
|
||||
- 统一的响应状态码处理
|
||||
- 统一的错误提示机制
|
||||
|
||||
**接口定义**:
|
||||
|
||||
| 方法 | 说明 | 参数 | 返回值 |
|
||||
|------|------|------|--------|
|
||||
| `request(options)` | 发起网络请求 | `options` 对象 | `Promise` |
|
||||
|
||||
**options 参数**:
|
||||
|
||||
| 参数 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| `url` | string | 是 | 请求路径 |
|
||||
| `method` | string | 否 | 请求方法,默认 `GET` |
|
||||
| `data` | object | 否 | 请求数据 |
|
||||
| `header` | object | 否 | 请求头 |
|
||||
|
||||
**响应数据结构**:
|
||||
|
||||
```javascript
|
||||
// 成功响应
|
||||
{
|
||||
code: 0, // 状态码,0表示成功
|
||||
message: 'success', // 提示信息
|
||||
data: {} // 业务数据
|
||||
}
|
||||
```
|
||||
|
||||
### 3.2 groupCourse.js - 团课真实 API
|
||||
|
||||
**功能定位**:定义团课相关的真实后端接口。
|
||||
|
||||
**接口列表**:
|
||||
|
||||
| 方法 | 说明 | 参数 | HTTP方法 | 路径 |
|
||||
|------|------|------|----------|------|
|
||||
| `getList()` | 获取团课列表 | 无 | GET | `/api/groupCourse/list` |
|
||||
| `getDetail(id)` | 获取团课详情 | `id`: 课程ID | GET | `/api/groupCourse/detail/{id}` |
|
||||
| `book(data)` | 预约团课 | `data`: 预约数据 | POST | `/api/groupCourse/book` |
|
||||
| `cancelBooking(id)` | 取消预约 | `id`: 预约记录ID | POST | `/api/groupCourse/cancel/{id}` |
|
||||
|
||||
**book 方法参数结构**:
|
||||
|
||||
```javascript
|
||||
{
|
||||
courseId: string, // 课程ID
|
||||
memberId: string // 会员ID
|
||||
}
|
||||
```
|
||||
|
||||
### 3.3 groupCourse.mock.js - 团课模拟数据 API
|
||||
|
||||
**功能定位**:提供模拟数据,支持开发测试,无需后端服务。
|
||||
|
||||
**特性**:
|
||||
- 模拟网络延迟(300-500ms)
|
||||
- 接口签名与真实API完全一致
|
||||
- 包含6条完整的模拟团课数据
|
||||
|
||||
**模拟数据结构**:
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| `id` | string | 课程唯一标识 |
|
||||
| `courseName` | string | 课程名称 |
|
||||
| `coachName` | string | 教练姓名 |
|
||||
| `coachAvatar` | string | 教练头像 |
|
||||
| `startTime` | string | 开始时间(ISO格式) |
|
||||
| `endTime` | string | 结束时间(ISO格式) |
|
||||
| `duration` | number | 课程时长(分钟) |
|
||||
| `location` | string | 上课地点 |
|
||||
| `maxMembers` | number | 最大人数 |
|
||||
| `currentMembers` | number | 当前人数 |
|
||||
| `storedValueAmount` | number | 储值卡价格(元) |
|
||||
| `pointCardAmount` | number | 次卡次数 |
|
||||
| `courseType` | string | 课程类型 |
|
||||
| `level` | string | 难度级别 |
|
||||
| `description` | string | 课程描述 |
|
||||
| `tags` | array | 标签列表 |
|
||||
| `status` | string | 状态(available/closed) |
|
||||
|
||||
### 3.4 envConfig.js - 环境配置
|
||||
|
||||
**功能定位**:统一服务导出入口,根据环境模式自动选择 API 实现。
|
||||
|
||||
**导出内容**:
|
||||
|
||||
| 导出项 | 类型 | 说明 |
|
||||
|--------|------|------|
|
||||
| `ENV_MODE` | string | 当前环境模式 |
|
||||
| `groupCourseService` | object | 团课服务实例 |
|
||||
|
||||
---
|
||||
|
||||
## 4. 使用示例
|
||||
|
||||
### 4.1 在页面中使用
|
||||
|
||||
```javascript
|
||||
// pages/groupCourse/list.vue
|
||||
import { groupCourseService } from '@/api/envConfig.js'
|
||||
|
||||
// 获取团课列表
|
||||
const fetchCourseList = async () => {
|
||||
try {
|
||||
const data = await groupCourseService.getList()
|
||||
courseList.value = data
|
||||
console.log('团课列表获取成功:', data)
|
||||
} catch (error) {
|
||||
console.error('获取团课列表异常:', error)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 4.2 切换环境
|
||||
|
||||
```javascript
|
||||
// api/envConfig.js
|
||||
// 开发环境 - 使用模拟数据
|
||||
export const ENV_MODE = 'development'
|
||||
|
||||
// 生产环境 - 使用真实网络请求
|
||||
export const ENV_MODE = 'production'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. 数据流转图
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ 页面层 (View) │
|
||||
│ pages/groupCourse/list.vue │
|
||||
└───────────────────────────┬─────────────────────────────────┘
|
||||
│ import & call
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ 环境配置层 (Config) │
|
||||
│ api/envConfig.js │
|
||||
│ 根据 ENV_MODE 选择对应的服务实现 │
|
||||
└───────────────────────────┬─────────────────────────────────┘
|
||||
│
|
||||
┌─────────────────┴─────────────────┐
|
||||
▼ ▼
|
||||
┌─────────────────────────┐ ┌─────────────────────────────┐
|
||||
│ groupCourse.js │ │ groupCourse.mock.js │
|
||||
│ (production 环境) │ │ (development 环境) │
|
||||
└───────────┬─────────────┘ └─────────────┬───────────────┘
|
||||
│ │
|
||||
▼ ▼
|
||||
┌─────────────────────────┐ ┌─────────────────────┐
|
||||
│ requestBase.js │ │ 本地模拟数据 │
|
||||
│ (真实网络请求) │ │ (无需后端) │
|
||||
└───────────┬─────────────┘ └─────────────────────┘
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────┐
|
||||
│ 后端服务器 API │
|
||||
└─────────────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. 注意事项
|
||||
|
||||
1. **环境变量配置**:部署前务必确认 `ENV_MODE` 设置正确
|
||||
2. **数据一致性**:模拟数据结构应与真实API保持一致
|
||||
3. **错误处理**:所有API调用都应包含 try-catch 错误处理
|
||||
4. **日志记录**:建议在关键节点添加日志,便于调试
|
||||
|
||||
---
|
||||
|
||||
## 7. 版本历史
|
||||
|
||||
| 版本 | 日期 | 更新内容 |
|
||||
|------|------|----------|
|
||||
| v1.0 | 2026-06-04 | 初始版本,完成基础API层设计 |
|
||||
@@ -50,7 +50,7 @@
|
||||
"quickapp" : {},
|
||||
/* 小程序特有相关 */
|
||||
"mp-weixin" : {
|
||||
"appid" : "wx8278fdbc9f158915",
|
||||
"appid" : "wx8f0d644d1d8985f6",
|
||||
"setting" : {
|
||||
"urlCheck" : false
|
||||
},
|
||||
|
||||
@@ -212,6 +212,18 @@
|
||||
"navigationStyle": "custom",
|
||||
"navigationBarTitleText": "课程评价"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/checkIn/checkIn",
|
||||
"style": {
|
||||
"navigationBarTitleText": "会员签到"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/groupCourse/list",
|
||||
"style": {
|
||||
"navigationBarTitleText": "团课列表"
|
||||
}
|
||||
}
|
||||
],
|
||||
"globalStyle": {
|
||||
@@ -260,4 +272,4 @@
|
||||
]
|
||||
},
|
||||
"uniIdRouter": {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,979 @@
|
||||
<template>
|
||||
<view class="checkin-page">
|
||||
<!-- 顶部导航栏(固定顶部) -->
|
||||
<view class="header">
|
||||
<view class="header-title">会员签到</view>
|
||||
<view class="header-subtitle">扫码入场,开启今日训练</view>
|
||||
</view>
|
||||
|
||||
<!-- 会员信息卡片 -->
|
||||
<view class="member-card card-default">
|
||||
<view class="member-avatar">
|
||||
<image src="/static/default-avatar.png" mode="aspectFill"></image>
|
||||
</view>
|
||||
<view class="member-info">
|
||||
<view class="member-name">尊敬的会员</view>
|
||||
<view class="member-level">
|
||||
<text class="level-badge">黄金会员</text>
|
||||
<text class="valid-date">有效期至 2026-12-31</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="member-points">
|
||||
<view class="points-value">1280</view>
|
||||
<view class="points-label">积分</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 二维码核心区域 -->
|
||||
<view class="qr-container card-default">
|
||||
<view class="qr-header">
|
||||
<view class="qr-title">出示二维码签到</view>
|
||||
<view class="qr-tip">将二维码对准前台扫码设备</view>
|
||||
</view>
|
||||
|
||||
<view class="QRBox">
|
||||
<view class="QR">
|
||||
<image :src="image" mode="" :style="{width: Math.min(width, 500) + 'rpx',height: Math.min(height, 500) + 'rpx' } "></image>
|
||||
</view>
|
||||
<view v-if="!image || STQRC" class="loadingBox" :style="{width: Math.min(width, 500) + 'rpx',height: Math.min(height, 500) + 'rpx' }">
|
||||
<view class="loading-spinner">
|
||||
<view v-if="!isCheckIn" class="spinner-circle"></view>
|
||||
<view v-else>
|
||||
<uni-icons type="checkmarkempty" size="30"></uni-icons>
|
||||
</view>
|
||||
<text class="loading-text">{{ QRStatus }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 二维码装饰边框 -->
|
||||
<view v-else class="qr-border" :style="{width: Math.min(width, 500) + 80 + 'rpx',height: Math.min(height, 500) + 80 + 'rpx' }">
|
||||
<view class="corner top-left"></view>
|
||||
<view class="corner top-right"></view>
|
||||
<view class="corner bottom-left"></view>
|
||||
<view class="corner bottom-right"></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 状态组件(传递状态和自定义错误文案)- 已签到时不显示 -->
|
||||
<QrStatus
|
||||
v-if="!isCheckIn"
|
||||
:status="status"
|
||||
:errorText="errorText"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 操作提示 -->
|
||||
<view class="tips-section">
|
||||
<view class="tips-title">温馨提示</view>
|
||||
<view class="tips-list">
|
||||
<view class="tip-item">
|
||||
<view class="tip-dot"></view>
|
||||
<text>二维码每5分钟自动刷新,请勿截图使用</text>
|
||||
</view>
|
||||
<view class="tip-item">
|
||||
<view class="tip-dot"></view>
|
||||
<text>签到成功后可进入场馆开始训练</text>
|
||||
</view>
|
||||
<view class="tip-item">
|
||||
<view class="tip-dot"></view>
|
||||
<text>如有问题请联系前台工作人员</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 底部按钮(z-index永久置顶) -->
|
||||
<view class="bottom-actions">
|
||||
<button @tap="handleLongPress">签到</button>
|
||||
<button class="btn-refresh" @tap="refreshQR">
|
||||
<uni-icons type="refresh" size="36rpx" color="#5E6F8D"></uni-icons>
|
||||
<text>刷新二维码</text>
|
||||
</button>
|
||||
|
||||
<!-- 测试用:手动清除缓存按钮 -->
|
||||
<button class="btn-clear-cache" @tap="handleClearCache">
|
||||
<uni-icons type="trash" size="36rpx" color="#ef4444"></uni-icons>
|
||||
<text>清除缓存</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { onLoad, onUnload } from '@dcloudio/uni-app'
|
||||
// 引入状态组件(路径与你保持一致)
|
||||
import QrStatus from '@/components/QRCode/StatusCard.vue'
|
||||
// 引入API封装
|
||||
import { getQRCode, checkIn as apiCheckIn } from '@/api/main.js'
|
||||
|
||||
let image = ref("")
|
||||
let width = ref(0)
|
||||
let height = ref(0)
|
||||
let status = ref('loading')
|
||||
let socketTask = null
|
||||
const scanStatus = ref(false)
|
||||
const QRStatus = ref("生成中...")
|
||||
const STQRC = ref(false)//是否扫码
|
||||
const isCheckIn = ref(false)
|
||||
|
||||
const qrcode = ref("")
|
||||
|
||||
// 新增:自定义错误文本变量
|
||||
const errorText = ref('')
|
||||
|
||||
/**
|
||||
* 缓存键名前缀
|
||||
*/
|
||||
const CACHE_PREFIX = 'QR_'
|
||||
|
||||
/**
|
||||
* 获取带前缀的缓存键名
|
||||
* @param {string} key - 原始键名
|
||||
* @returns {string} 带前缀的键名
|
||||
*/
|
||||
const getCacheKey = (key) => {
|
||||
return CACHE_PREFIX + key
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取今日23:59:59的时间戳(当日过期时间)
|
||||
* @returns {number} 今日23:59:59的时间戳
|
||||
*/
|
||||
const getTodayExpireTime = () => {
|
||||
const now = new Date()
|
||||
const expire = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999)
|
||||
return expire.getTime()
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查缓存是否过期
|
||||
* @param {string} key - 缓存键名(不带前缀)
|
||||
* @returns {boolean} 是否有效(未过期)
|
||||
*/
|
||||
const isCacheValid = (key) => {
|
||||
try {
|
||||
const cacheKey = getCacheKey(key)
|
||||
const cacheData = uni.getStorageSync(cacheKey)
|
||||
if (!cacheData) return false
|
||||
|
||||
if (typeof cacheData === 'object' && cacheData.expireTime) {
|
||||
const now = Date.now()
|
||||
return now <= cacheData.expireTime
|
||||
}
|
||||
return false
|
||||
} catch (e) {
|
||||
console.error('检查缓存有效性失败:', e)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存数据(自动校验过期时间)
|
||||
* @param {string} key - 缓存键名(不带前缀)
|
||||
* @returns {any} 缓存数据(过期返回null)
|
||||
*/
|
||||
const getCacheData = (key) => {
|
||||
try {
|
||||
if (!isCacheValid(key)) {
|
||||
// 缓存已过期,清除缓存
|
||||
uni.removeStorageSync(getCacheKey(key))
|
||||
return null
|
||||
}
|
||||
|
||||
const cacheData = uni.getStorageSync(getCacheKey(key))
|
||||
if (typeof cacheData === 'object' && cacheData.data !== undefined) {
|
||||
return cacheData.data
|
||||
}
|
||||
return null
|
||||
} catch (e) {
|
||||
console.error('获取缓存数据失败:', e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置缓存数据(自动设置当日23:59:59过期)
|
||||
* @param {string} key - 缓存键名(不带前缀)
|
||||
* @param {any} data - 要缓存的数据
|
||||
*/
|
||||
const setCacheData = (key, data) => {
|
||||
try {
|
||||
const cacheData = {
|
||||
data: data,
|
||||
expireTime: getTodayExpireTime()
|
||||
}
|
||||
uni.setStorageSync(getCacheKey(key), cacheData)
|
||||
} catch (e) {
|
||||
console.error('设置缓存数据失败:', e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有QR_开头的缓存(用于测试阶段)
|
||||
*/
|
||||
const clearQRCache = () => {
|
||||
try {
|
||||
const keys = uni.getStorageInfoSync().keys || []
|
||||
let clearedCount = 0
|
||||
for (const key of keys) {
|
||||
if (key.startsWith(CACHE_PREFIX)) {
|
||||
uni.removeStorageSync(key)
|
||||
clearedCount++
|
||||
}
|
||||
}
|
||||
console.log(`已清除 ${clearedCount} 个QR_开头的缓存`)
|
||||
return clearedCount
|
||||
} catch (e) {
|
||||
console.error('清除QR缓存失败:', e)
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试用:手动清除缓存按钮点击事件
|
||||
*/
|
||||
const handleClearCache = () => {
|
||||
uni.showModal({
|
||||
title: '清除缓存',
|
||||
content: '确定要清除所有签到相关的缓存吗?(测试用)',
|
||||
confirmText: '确定',
|
||||
cancelText: '取消',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
const clearedCount = clearQRCache()
|
||||
// 重置页面状态
|
||||
image.value = ""
|
||||
width.value = 0
|
||||
height.value = 0
|
||||
status.value = 'loading'
|
||||
QRStatus.value = "生成中..."
|
||||
STQRC.value = false
|
||||
isCheckIn.value = false
|
||||
|
||||
uni.showToast({
|
||||
title: `已清除 ${clearedCount} 个缓存`,
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
|
||||
// 重新请求二维码
|
||||
setTimeout(() => {
|
||||
getStorage(null)
|
||||
}, 500)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onLoad(() => {
|
||||
uni.showLoading({
|
||||
title: '生成签到二维码...',
|
||||
mask: true
|
||||
})
|
||||
|
||||
// 读取签到状态缓存(自动检查过期)
|
||||
// isCheckIn 代表签到状态,从缓存读取
|
||||
const cachedIsCheckIn = getCacheData("isCheckIn")
|
||||
// checkInTime 代表具体签到时间,从缓存读取(显示在 loading-text 中)
|
||||
const cachedCheckInTime = getCacheData("checkInTime")
|
||||
|
||||
if(cachedIsCheckIn != null) {
|
||||
console.log("进入缓存 - 签到状态")
|
||||
isCheckIn.value = cachedIsCheckIn
|
||||
STQRC.value = true
|
||||
}
|
||||
|
||||
// 如果已经签到成功,直接显示成功状态,不需要请求后端
|
||||
if(isCheckIn.value) {
|
||||
console.log("已签到且有缓存,无需请求后端")
|
||||
// 读取二维码图片缓存用于显示
|
||||
const cachedQRInfo = getCacheData("QRInfo")
|
||||
if(cachedQRInfo) {
|
||||
image.value = cachedQRInfo.qrCodeBase64
|
||||
width.value = cachedQRInfo.width * 2
|
||||
height.value = cachedQRInfo.height * 2
|
||||
}
|
||||
// QRStatus 显示具体签到时间(从缓存读取,显示在 loading-text 中)
|
||||
QRStatus.value = cachedCheckInTime || "已完成签到"
|
||||
uni.hideLoading()
|
||||
return
|
||||
}
|
||||
|
||||
// 未签到或缓存失效,需要请求后端获取二维码
|
||||
// QRStatus 重置为默认的请求状态
|
||||
QRStatus.value = "生成中..."
|
||||
getStorage(null)
|
||||
})
|
||||
|
||||
// 页面卸载时关闭WebSocket连接(不清除缓存,让缓存自然过期)
|
||||
onUnload(() => {
|
||||
closeWebSocket()
|
||||
// 缓存会在当日23:59:59自动过期,页面卸载时不主动清除
|
||||
// 如需测试,使用页面上的"清除缓存"按钮手动清除
|
||||
})
|
||||
|
||||
// 获取二维码接口
|
||||
const fetchQRCode = () => {
|
||||
console.log(1111)
|
||||
status.value = ''
|
||||
errorText.value = '' // 重置错误文本
|
||||
image.value = ""
|
||||
|
||||
getQRCode(true).then(res => {
|
||||
console.log(res)
|
||||
// 保存到本地缓存(用于签到状态判断)
|
||||
setCacheData("QRInfo", res)
|
||||
getStorage(res)
|
||||
qrcode.value = res.qrContent
|
||||
}).catch(err => {
|
||||
console.error('获取二维码失败:', err)
|
||||
status.value = 'error'
|
||||
errorText.value = err.message || '获取二维码失败'
|
||||
uni.showToast({
|
||||
title: errorText.value,
|
||||
icon: 'error'
|
||||
})
|
||||
}).finally(() => {
|
||||
uni.hideLoading()
|
||||
})
|
||||
}
|
||||
|
||||
const refreshQR = () => {
|
||||
// 如果已签到,不允许刷新二维码
|
||||
if (isCheckIn.value) {
|
||||
uni.showToast({
|
||||
title: '您已签到',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
image.value = ""
|
||||
QRStatus.value = "正在刷新二维码..."
|
||||
setTimeout(() => {
|
||||
getStorage(null)
|
||||
}, 500)
|
||||
}
|
||||
|
||||
const getStorage = res => {
|
||||
let data = res
|
||||
if(data == null) {
|
||||
// 使用带过期检查的缓存读取
|
||||
data = getCacheData("QRInfo")
|
||||
uni.hideLoading()
|
||||
}
|
||||
if(!data) fetchQRCode()
|
||||
|
||||
if(data) {
|
||||
image.value = data.qrCodeBase64
|
||||
// 使用带过期时间的缓存(当日23:59:59过期)
|
||||
setCacheData("QRInfo", data)
|
||||
width.value = data.width * 2
|
||||
height.value = data.height * 2
|
||||
|
||||
// 只有在未签到的情况下才连接WebSocket等待扫码
|
||||
if (data.qrContent && !isCheckIn.value) {
|
||||
console.log("未签到,连接WebSocket等待扫码")
|
||||
connectWebSocket(data.qrContent)
|
||||
} else if (isCheckIn.value) {
|
||||
console.log("已签到,无需连接WebSocket")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleLongPress = () => {
|
||||
uni.scanCode({
|
||||
onlyFromCamera: false,
|
||||
scanType: ['qrCode'],
|
||||
success: (res) => {
|
||||
console.log(res)
|
||||
checkIn(res.result)
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('扫码失败:', err)
|
||||
uni.showToast({
|
||||
title: '扫码失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 手动签到接口
|
||||
const checkIn = (qrContent) => {
|
||||
console.log(qrContent)
|
||||
apiCheckIn(qrContent).then(res => {
|
||||
closeWebSocket()
|
||||
console.log(res)
|
||||
status.value = 'scanned'
|
||||
errorText.value = '' // 成功重置错误文本
|
||||
QRStatus.value = res.dateTime + " 成功签到"
|
||||
isCheckIn.value = true
|
||||
// 使用带过期时间的缓存(当日23:59:59过期)
|
||||
setCacheData("checkInTime", QRStatus.value)
|
||||
setCacheData("isCheckIn", isCheckIn.value)
|
||||
uni.showToast({
|
||||
title: '签到成功!',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
}).catch(err => {
|
||||
console.error('签到请求失败:', err)
|
||||
status.value = 'error'
|
||||
errorText.value = err.message || '签到失败,请重试' // 对应错误文案
|
||||
})
|
||||
}
|
||||
|
||||
// 建立WebSocket连接
|
||||
const connectWebSocket = (qrContent) => {
|
||||
const wsUrl = `ws://192.168.43.89:8084/webSocket/checkIn`
|
||||
|
||||
console.log('WebSocket 连接地址:', wsUrl)
|
||||
|
||||
socketTask = uni.connectSocket({
|
||||
url: wsUrl,
|
||||
success: () => {
|
||||
console.log('WebSocket 连接中...')
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('WebSocket 连接失败:', err)
|
||||
status.value = 'error'
|
||||
errorText.value = '连接失败,请重试' // 对应错误文案
|
||||
}
|
||||
})
|
||||
|
||||
// 连接打开成功
|
||||
socketTask.onOpen(() => {
|
||||
console.log('WebSocket 连接成功')
|
||||
status.value = 'waiting'
|
||||
errorText.value = '' // 成功重置错误文本
|
||||
sendQRCodeInfo(qrContent)
|
||||
})
|
||||
|
||||
// 发送二维码信息到后端
|
||||
const sendQRCodeInfo = (qrContent) => {
|
||||
const qrCodeDto = {
|
||||
qrContent: qrContent,
|
||||
used: false
|
||||
}
|
||||
|
||||
console.log('发送二维码信息:', qrCodeDto)
|
||||
|
||||
socketTask.send({
|
||||
data: JSON.stringify(qrCodeDto),
|
||||
success: () => {
|
||||
console.log('二维码信息发送成功')
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('发送失败:', err)
|
||||
status.value = 'error'
|
||||
errorText.value = '连接失败,请重试' // 对应错误文案
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 接收后端消息
|
||||
socketTask.onMessage((res) => {
|
||||
console.log('收到 WebSocket 消息:', res.data)
|
||||
const message = res.data
|
||||
|
||||
if (message === '正在进行签到') {
|
||||
QRStatus.value = "正在进行签到..."
|
||||
STQRC.value = true
|
||||
// status.value = 'scanned'
|
||||
// errorText.value = '' // 成功重置错误文本
|
||||
// uni.showToast({
|
||||
// title: '签到成功!',
|
||||
// icon: 'success',
|
||||
// duration: 2000
|
||||
// })
|
||||
} else if (message.startsWith('二维码无效')) {
|
||||
uni.showToast({
|
||||
title: message,
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
status.value = 'error'
|
||||
errorText.value = '二维码无效,请刷新' // 对应错误文案
|
||||
setTimeout(() => {
|
||||
closeWebSocket()
|
||||
}, 3000)
|
||||
} else if (message === '消息格式错误') {
|
||||
uni.showToast({
|
||||
title: '消息格式错误',
|
||||
icon: 'none'
|
||||
})
|
||||
status.value = 'error'
|
||||
errorText.value = '消息格式错误' // 对应错误文案
|
||||
} else {
|
||||
console.log('未知消息:', message)
|
||||
}
|
||||
})
|
||||
|
||||
// 连接关闭
|
||||
socketTask.onClose(() => {
|
||||
console.log('WebSocket 连接关闭')
|
||||
status.value = 'closed'
|
||||
errorText.value = '' // 重置错误文本
|
||||
})
|
||||
|
||||
// 连接错误
|
||||
socketTask.onError((err) => {
|
||||
console.error('WebSocket 错误:', err)
|
||||
status.value = 'error'
|
||||
errorText.value = '连接失败,请重试' // 对应错误文案
|
||||
uni.showToast({
|
||||
title: '连接失败',
|
||||
icon: 'none'
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 关闭WebSocket连接
|
||||
const closeWebSocket = () => {
|
||||
if (socketTask) {
|
||||
socketTask.close({
|
||||
success: () => {
|
||||
console.log('主动关闭 WebSocket')
|
||||
}
|
||||
})
|
||||
socketTask = null
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.checkin-page {
|
||||
min-height: 100vh;
|
||||
background-color: #F9FAFE;
|
||||
padding-top: 200rpx; /* 为固定顶部导航预留空间 */
|
||||
padding-bottom: 160rpx; /* 为底部按钮预留空间 */
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* 顶部导航(固定顶部) */
|
||||
.header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 99998; /* 低于底部按钮,确保底部按钮永远最上层 */
|
||||
background: linear-gradient(135deg, #0B2B4B 0%, #1A4A6F 100%);
|
||||
padding: 64rpx 48rpx 48rpx;
|
||||
text-align: center;
|
||||
color: #FFFFFF;
|
||||
border-bottom-left-radius: 56rpx;
|
||||
border-bottom-right-radius: 56rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
|
||||
|
||||
.header-title {
|
||||
font-size: 45rpx;
|
||||
font-weight: 700;
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.header-subtitle {
|
||||
font-size: 26rpx;
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
|
||||
/* 通用卡片样式 */
|
||||
.card-default {
|
||||
background: #FFFFFF;
|
||||
border-radius: 40rpx;
|
||||
box-shadow: 0 16rpx 40rpx rgba(0, 0, 0, 0.03), 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
|
||||
border: 1rpx solid #E9EDF2;
|
||||
padding: 32rpx;
|
||||
}
|
||||
|
||||
/* 会员信息卡片 */
|
||||
.member-card {
|
||||
margin: 0 32rpx 48rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 32rpx;
|
||||
flex-wrap: nowrap;
|
||||
|
||||
.member-avatar {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
border-radius: 999px;
|
||||
overflow: hidden;
|
||||
border: 4rpx solid #FF6B35;
|
||||
flex-shrink: 0;
|
||||
|
||||
image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.member-info {
|
||||
flex: 1;
|
||||
margin-left: 32rpx;
|
||||
flex-shrink: 1;
|
||||
min-width: 0;
|
||||
|
||||
.member-name {
|
||||
font-size: 32rpx;
|
||||
font-weight: 500;
|
||||
color: #1E2A3A;
|
||||
margin-bottom: 8rpx;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.member-level {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.level-badge {
|
||||
background: linear-gradient(135deg, #FF6B35 0%, #FF8C5A 100%);
|
||||
color: white;
|
||||
padding: 4rpx 16rpx;
|
||||
border-radius: 24rpx;
|
||||
font-size: 22rpx;
|
||||
font-weight: 500;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.valid-date {
|
||||
font-size: 22rpx;
|
||||
color: #5E6F8D;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.member-points {
|
||||
text-align: center;
|
||||
flex-shrink: 0;
|
||||
margin-left: 16rpx;
|
||||
|
||||
.points-value {
|
||||
font-size: 38rpx;
|
||||
font-weight: 700;
|
||||
color: #FF6B35;
|
||||
}
|
||||
|
||||
.points-label {
|
||||
font-size: 22rpx;
|
||||
color: #5E6F8D;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 二维码容器 */
|
||||
.qr-container {
|
||||
margin: 0 32rpx 48rpx;
|
||||
padding: 48rpx 32rpx;
|
||||
text-align: center;
|
||||
|
||||
.qr-header {
|
||||
margin-bottom: 64rpx;
|
||||
|
||||
.qr-title {
|
||||
font-size: 38rpx;
|
||||
font-weight: 700;
|
||||
color: #1E2A3A;
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.qr-tip {
|
||||
font-size: 26rpx;
|
||||
color: #5E6F8D;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 二维码核心区域 */
|
||||
.QRBox {
|
||||
position: relative;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin: 0 auto 64rpx;
|
||||
max-width: 100%;
|
||||
|
||||
.QR {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
padding: 20rpx;
|
||||
background: white;
|
||||
border-radius: 40rpx;
|
||||
}
|
||||
|
||||
.loadingBox {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
z-index: 3;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
border-radius: 40rpx;
|
||||
|
||||
.loading-spinner {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
|
||||
.spinner-circle {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
border: 6rpx solid #E9EDF2;
|
||||
border-top-color: #FF6B35;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
.loading-text {
|
||||
font-size: 26rpx;
|
||||
color: #5E6F8D;
|
||||
width: 250rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 二维码装饰边框 */
|
||||
.qr-border {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
z-index: 1;
|
||||
|
||||
.corner {
|
||||
position: absolute;
|
||||
width: 48rpx;
|
||||
height: 48rpx;
|
||||
border: 6rpx solid #FF6B35;
|
||||
|
||||
&.top-left {
|
||||
top: 0;
|
||||
left: 0;
|
||||
border-right: none;
|
||||
border-bottom: none;
|
||||
border-top-left-radius: 40rpx;
|
||||
}
|
||||
|
||||
&.top-right {
|
||||
top: 0;
|
||||
right: 0;
|
||||
border-left: none;
|
||||
border-bottom: none;
|
||||
border-top-right-radius: 40rpx;
|
||||
}
|
||||
|
||||
&.bottom-left {
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
border-right: none;
|
||||
border-top: none;
|
||||
border-bottom-left-radius: 40rpx;
|
||||
}
|
||||
|
||||
&.bottom-right {
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
border-left: none;
|
||||
border-top: none;
|
||||
border-bottom-right-radius: 40rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 温馨提示 */
|
||||
.tips-section {
|
||||
margin: 0 32rpx 48rpx;
|
||||
|
||||
.tips-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: 500;
|
||||
color: #1E2A3A;
|
||||
margin-bottom: 32rpx;
|
||||
}
|
||||
|
||||
.tips-list {
|
||||
background: #FFFFFF;
|
||||
border-radius: 40rpx;
|
||||
padding: 32rpx;
|
||||
border: 1rpx solid #E9EDF2;
|
||||
|
||||
.tip-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 16rpx;
|
||||
margin-bottom: 16rpx;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.tip-dot {
|
||||
width: 12rpx;
|
||||
height: 12rpx;
|
||||
background: #FF6B35;
|
||||
border-radius: 50%;
|
||||
margin-top: 12rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
text {
|
||||
font-size: 26rpx;
|
||||
color: #5E6F8D;
|
||||
line-height: 1.6;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 底部按钮(z-index永久置顶+安全区域适配) */
|
||||
.bottom-actions {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 99999; /* 极高z-index确保永远在最上层 */
|
||||
padding: 32rpx 48rpx calc(32rpx + env(safe-area-inset-bottom));
|
||||
background: #FFFFFF;
|
||||
border-top: 1rpx solid #E9EDF2;
|
||||
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.05);
|
||||
|
||||
.btn-refresh {
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
background: #F2F5F9;
|
||||
color: #5E6F8D;
|
||||
border: none;
|
||||
border-radius: 999px;
|
||||
font-size: 29rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 16rpx;
|
||||
margin-bottom: 20rpx;
|
||||
|
||||
&:active {
|
||||
background: #E9EDF2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 测试用:清除缓存按钮 */
|
||||
.btn-clear-cache {
|
||||
width: calc(100% - 96rpx);
|
||||
height: 88rpx;
|
||||
background: #FEF2F2;
|
||||
color: #EF4444;
|
||||
border: 1rpx solid #FECACA;
|
||||
border-radius: 999px;
|
||||
font-size: 29rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 16rpx;
|
||||
|
||||
&:active {
|
||||
background: #FEE2E2;
|
||||
}
|
||||
}
|
||||
|
||||
/* 旋转动画 */
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
/* 暗色模式适配 */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.checkin-page {
|
||||
background-color: #121826;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: linear-gradient(135deg, #123A5E 0%, #1A4A6F 100%);
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.card-default {
|
||||
background: #1E2636;
|
||||
border-color: #2A3346;
|
||||
box-shadow: 0 16rpx 40rpx rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.member-card .member-info .member-name {
|
||||
color: #EDF2F7;
|
||||
}
|
||||
|
||||
.member-card .member-info .member-level .valid-date,
|
||||
.member-card .member-points .points-label {
|
||||
color: #9AA9C1;
|
||||
}
|
||||
|
||||
.qr-container .qr-header .qr-title {
|
||||
color: #EDF2F7;
|
||||
}
|
||||
|
||||
.qr-container .qr-header .qr-tip {
|
||||
color: #9AA9C1;
|
||||
}
|
||||
|
||||
.QRBox .loadingBox {
|
||||
background: rgba(30, 38, 54, 0.95);
|
||||
}
|
||||
|
||||
.QRBox .loadingBox .loading-spinner .loading-text {
|
||||
color: #9AA9C1;
|
||||
}
|
||||
|
||||
.tips-section .tips-title {
|
||||
color: #EDF2F7;
|
||||
}
|
||||
|
||||
.tips-section .tips-list {
|
||||
background: #1E2636;
|
||||
border-color: #2A3346;
|
||||
}
|
||||
|
||||
.tips-section .tips-list .tip-item text {
|
||||
color: #9AA9C1;
|
||||
}
|
||||
|
||||
.bottom-actions {
|
||||
background: #1E2636;
|
||||
border-color: #2A3346;
|
||||
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.bottom-actions .btn-refresh {
|
||||
background: #0F141F;
|
||||
color: #9AA9C1;
|
||||
|
||||
&:active {
|
||||
background: #2A3346;
|
||||
}
|
||||
}
|
||||
|
||||
.btn-clear-cache {
|
||||
background: #3D1919;
|
||||
color: #FCA5A5;
|
||||
border-color: #5C2B2B;
|
||||
|
||||
&:active {
|
||||
background: #4A2525;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,172 @@
|
||||
<template>
|
||||
<view class="group-course-page">
|
||||
<!-- 搜索区域 -->
|
||||
<view class="search-section">
|
||||
<!-- 搜索框组件 -->
|
||||
<SearchBar
|
||||
v-model="searchKeyword"
|
||||
:hot-keywords="hotKeywords"
|
||||
@search="handleSearch"
|
||||
ref="searchBarRef"
|
||||
/>
|
||||
|
||||
<!-- 筛选条件组件 -->
|
||||
<FilterSection
|
||||
:time-range-text="timeRangeText"
|
||||
:sort-options="sortOptions"
|
||||
v-model:sort-index="sortIndex"
|
||||
@time-pick="showTimePicker = true"
|
||||
ref="filterSectionRef"
|
||||
/>
|
||||
|
||||
<!-- 时间段选择组件 -->
|
||||
<TimePeriodSelector
|
||||
:time-period-options="timePeriodOptions"
|
||||
v-model="timePeriodIndex"
|
||||
@change="onTimePeriodChange"
|
||||
ref="timePeriodRef"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 团课列表 -->
|
||||
<scroll-view
|
||||
scroll-y
|
||||
class="course-list"
|
||||
@scrolltolower="onScrollToLower"
|
||||
scroll-with-animation
|
||||
>
|
||||
<GroupCourseCard
|
||||
v-for="course in filteredCourseList"
|
||||
:key="course.id"
|
||||
:course="course"
|
||||
@booking="handleBooking"
|
||||
@detail="goDetail"
|
||||
></GroupCourseCard>
|
||||
|
||||
<!-- 加载更多提示 -->
|
||||
<view class="load-more">
|
||||
<text v-if="loading">加载中...</text>
|
||||
<text v-else-if="!hasMore">没有更多数据了</text>
|
||||
<text v-else class="load-more-text" @tap="loadMore">点击加载更多</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<!-- 底部导航 -->
|
||||
<TabBar :active-tab="1" />
|
||||
|
||||
<!-- 时间选择器组件 -->
|
||||
<TimeRangePicker
|
||||
v-model:visible="showTimePicker"
|
||||
v-model:start-date="startDate"
|
||||
v-model:end-date="endDate"
|
||||
@confirm="onTimeRangeConfirm"
|
||||
ref="timeRangePickerRef"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import TabBar from '@/components/TabBar.vue'
|
||||
import GroupCourseCard from '@/components/groupCourse/CourseCard.vue'
|
||||
import SearchBar from '@/components/groupCourse/SearchBar.vue'
|
||||
import FilterSection from '@/components/groupCourse/FilterSection.vue'
|
||||
import TimePeriodSelector from '@/components/groupCourse/TimePeriodSelector.vue'
|
||||
import TimeRangePicker from '@/components/groupCourse/TimeRangePicker.vue'
|
||||
import { useGroupCourseList } from '@/composables/useGroupCourseList.js'
|
||||
|
||||
// 组件引用
|
||||
const searchBarRef = ref(null)
|
||||
const filterSectionRef = ref(null)
|
||||
const timePeriodRef = ref(null)
|
||||
const timeRangePickerRef = ref(null)
|
||||
|
||||
// 使用组合式函数
|
||||
const {
|
||||
// 状态
|
||||
loading,
|
||||
hasMore,
|
||||
searchKeyword,
|
||||
hotKeywords,
|
||||
sortOptions,
|
||||
sortIndex,
|
||||
timePeriodOptions,
|
||||
timePeriodIndex,
|
||||
showTimePicker,
|
||||
startDate,
|
||||
endDate,
|
||||
timeRangeText,
|
||||
filteredCourseList,
|
||||
|
||||
// 方法
|
||||
getAllSearchParams,
|
||||
handleSearch,
|
||||
onTimePeriodChange,
|
||||
onTimeRangeConfirm,
|
||||
handleBooking,
|
||||
goDetail,
|
||||
fetchCourseList,
|
||||
loadMore,
|
||||
onScrollToLower
|
||||
} = useGroupCourseList()
|
||||
|
||||
// 组件挂载时调用接口获取团课列表
|
||||
onMounted(() => {
|
||||
console.log('[list.vue] 页面组件已挂载,开始获取团课列表')
|
||||
fetchCourseList()
|
||||
console.log('[list.vue] 可用的搜索参数获取方法:')
|
||||
console.log(' - searchBarRef.getSearchParams()')
|
||||
console.log(' - filterSectionRef.getFilterParams()')
|
||||
console.log(' - timePeriodRef.getTimePeriodParams()')
|
||||
console.log(' - timeRangePickerRef.getTimeRangeParams()')
|
||||
console.log(' - getAllSearchParams() 获取所有参数')
|
||||
})
|
||||
|
||||
// 暴露方法供外部调用
|
||||
defineExpose({
|
||||
getAllSearchParams: () => getAllSearchParams(searchBarRef.value, filterSectionRef.value, timePeriodRef.value, timeRangePickerRef.value),
|
||||
searchBarRef,
|
||||
filterSectionRef,
|
||||
timePeriodRef,
|
||||
timeRangePickerRef
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
.group-course-page {
|
||||
min-height: 100vh;
|
||||
background: #F5F7FA;
|
||||
}
|
||||
|
||||
/* 搜索区域 */
|
||||
.search-section {
|
||||
background: #ffffff;
|
||||
padding: 24rpx;
|
||||
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 24rpx;
|
||||
}
|
||||
|
||||
/* 课程列表 */
|
||||
.course-list {
|
||||
height: calc(100vh - 380rpx);
|
||||
padding: 24rpx 24rpx;
|
||||
padding-bottom: calc(160rpx + constant(safe-area-inset-bottom));
|
||||
padding-bottom: calc(160rpx + env(safe-area-inset-bottom));
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* 加载更多提示 */
|
||||
.load-more {
|
||||
text-align: center;
|
||||
padding: 30rpx 0;
|
||||
color: #999999;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.load-more-text {
|
||||
color: #1890ff;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,215 @@
|
||||
const BASE_URL = 'http://192.168.43.89:8084/api'
|
||||
|
||||
// 缓存相关常量
|
||||
const CACHE_PREFIX = 'API_CACHE_'
|
||||
const CACHE_EXPIRE_TIME = 5 * 60 * 1000 // 默认缓存时间5分钟
|
||||
|
||||
/**
|
||||
* 获取缓存数据
|
||||
* @param {string} key - 缓存键名
|
||||
* @returns {any} 缓存数据(过期返回null)
|
||||
*/
|
||||
export const getCache = (key) => {
|
||||
try {
|
||||
const cacheData = uni.getStorageSync(CACHE_PREFIX + key)
|
||||
if (cacheData && cacheData.expireTime && Date.now() < cacheData.expireTime) {
|
||||
return cacheData.data
|
||||
}
|
||||
// 缓存过期,清除
|
||||
uni.removeStorageSync(CACHE_PREFIX + key)
|
||||
return null
|
||||
} catch (e) {
|
||||
console.error('获取缓存失败:', e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置缓存数据
|
||||
* @param {string} key - 缓存键名
|
||||
* @param {any} data - 要缓存的数据
|
||||
* @param {number} expireTime - 过期时间(毫秒),默认5分钟
|
||||
*/
|
||||
export const setCache = (key, data, expireTime = CACHE_EXPIRE_TIME) => {
|
||||
try {
|
||||
const cacheData = {
|
||||
data: data,
|
||||
expireTime: Date.now() + expireTime
|
||||
}
|
||||
uni.setStorageSync(CACHE_PREFIX + key, cacheData)
|
||||
} catch (e) {
|
||||
console.error('设置缓存失败:', e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除指定缓存
|
||||
* @param {string} key - 缓存键名
|
||||
*/
|
||||
export const clearCache = (key) => {
|
||||
try {
|
||||
uni.removeStorageSync(CACHE_PREFIX + key)
|
||||
} catch (e) {
|
||||
console.error('清除缓存失败:', e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有API缓存
|
||||
*/
|
||||
export const clearAllCache = () => {
|
||||
try {
|
||||
const keys = uni.getStorageInfoSync().keys || []
|
||||
for (const key of keys) {
|
||||
if (key.startsWith(CACHE_PREFIX)) {
|
||||
uni.removeStorageSync(key)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('清除所有缓存失败:', e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取token
|
||||
* @returns {string|null} token
|
||||
*/
|
||||
export const getToken = () => {
|
||||
try {
|
||||
return uni.getStorageSync('token') || null
|
||||
} catch (e) {
|
||||
console.error('获取token失败:', e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置token
|
||||
* @param {string} token - token值
|
||||
*/
|
||||
export const setToken = (token) => {
|
||||
try {
|
||||
uni.setStorageSync('token', token)
|
||||
} catch (e) {
|
||||
console.error('设置token失败:', e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除token
|
||||
*/
|
||||
export const clearToken = () => {
|
||||
try {
|
||||
uni.removeStorageSync('token')
|
||||
} catch (e) {
|
||||
console.error('清除token失败:', e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求缓存键名
|
||||
* @param {string} url - 请求URL
|
||||
* @param {object} data - 请求参数
|
||||
* @param {string} method - 请求方法
|
||||
* @returns {string} 缓存键名
|
||||
*/
|
||||
const generateCacheKey = (url, data, method) => {
|
||||
const params = JSON.stringify(data || {})
|
||||
return `${method}_${url}_${params}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用请求函数
|
||||
* @param {object} options - 请求配置
|
||||
* @param {string} options.url - 请求URL
|
||||
* @param {string} [options.method='GET'] - 请求方法
|
||||
* @param {object} [options.data={}] - 请求参数
|
||||
* @param {object} [options.header={}] - 请求头
|
||||
* @param {boolean} [options.cache=false] - 是否启用缓存
|
||||
* @param {number} [options.cacheTime] - 缓存时间(毫秒)
|
||||
* @param {boolean} [options.needToken=true] - 是否需要token
|
||||
* @returns {Promise} 请求Promise
|
||||
*/
|
||||
export const request = (options) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const {
|
||||
url,
|
||||
method = 'GET',
|
||||
data = {},
|
||||
header = {},
|
||||
cache = false,
|
||||
cacheTime,
|
||||
needToken = true
|
||||
} = options
|
||||
|
||||
// 生成缓存键名
|
||||
const cacheKey = cache ? generateCacheKey(url, data, method) : null
|
||||
|
||||
// 如果启用缓存且存在有效缓存,直接返回缓存数据
|
||||
if (cache && cacheKey) {
|
||||
const cachedData = getCache(cacheKey)
|
||||
if (cachedData !== null) {
|
||||
console.log(`[API] 命中缓存: ${url}`)
|
||||
resolve(cachedData)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 构建请求头
|
||||
const requestHeader = {
|
||||
'Content-Type': 'application/json',
|
||||
...header
|
||||
}
|
||||
|
||||
// 如果需要token,自动添加到请求头
|
||||
if (needToken) {
|
||||
const token = getToken()
|
||||
if (token) {
|
||||
requestHeader['Authorization'] = `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
|
||||
uni.request({
|
||||
url: BASE_URL + url,
|
||||
method: method,
|
||||
data: data,
|
||||
header: requestHeader,
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200) {
|
||||
// 如果启用缓存,保存响应数据
|
||||
if (cache && cacheKey && res.data) {
|
||||
setCache(cacheKey, res.data, cacheTime)
|
||||
}
|
||||
resolve(res.data)
|
||||
} else if (res.statusCode === 401) {
|
||||
// token过期,清除token并提示重新登录
|
||||
clearToken()
|
||||
uni.showToast({
|
||||
title: '登录已过期,请重新登录',
|
||||
icon: 'none'
|
||||
})
|
||||
reject({ code: 401, message: '登录已过期' })
|
||||
} else {
|
||||
reject({ code: res.statusCode, message: res.data?.message || '请求失败' })
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error(`[API] 请求失败: ${url}`, err)
|
||||
reject({ code: -1, message: '网络请求失败', error: err })
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 工具函数导出
|
||||
export const requestUtils = {
|
||||
getToken,
|
||||
setToken,
|
||||
clearToken,
|
||||
getCache,
|
||||
setCache,
|
||||
clearCache,
|
||||
clearAllCache
|
||||
}
|
||||
|
||||
export default request
|
||||
@@ -0,0 +1,24 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import uni from '@dcloudio/vite-plugin-uni'
|
||||
import path from 'path'
|
||||
|
||||
// 用来匹配地址,解决跨域问题
|
||||
export default defineConfig({
|
||||
plugins: [uni()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, 'src')
|
||||
},
|
||||
},
|
||||
server: {
|
||||
proxy: {
|
||||
// 匹配所有 /api 开头的请求
|
||||
'/api': {
|
||||
target: 'http://192.168.43.89:8084', // 你的后端SpringBoot地址
|
||||
changeOrigin: true, // 开启跨域伪装
|
||||
// rewrite: (path) => path.replace(/^\/areyouok/, '')
|
||||
// 举例:前端请求 /api/login → 代理成 http://localhost:8088/login
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user