361 lines
7.9 KiB
Markdown
361 lines
7.9 KiB
Markdown
|
|
# ✅ 预约与日历数据统一 - 后端接口完成
|
|||
|
|
|
|||
|
|
**日期**: 2026-01-24
|
|||
|
|
**状态**: ✅ 后端接口已完成
|
|||
|
|
**下一步**: 修改前端页面
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 📝 已完成的修改
|
|||
|
|
|
|||
|
|
### 1. CalendarService 接口
|
|||
|
|
|
|||
|
|
**文件**: `peidu/backend/src/main/java/com/peidu/service/CalendarService.java`
|
|||
|
|
|
|||
|
|
**新增方法**:
|
|||
|
|
```java
|
|||
|
|
/**
|
|||
|
|
* 获取用户的所有预约记录(不限日期)
|
|||
|
|
*/
|
|||
|
|
List<AppointmentVO> getAllAppointments(Long userId);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取用户的所有预约统计(不限日期)
|
|||
|
|
*/
|
|||
|
|
Map<String, Object> getAllStats(Long userId);
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### 2. CalendarServiceImpl 实现类
|
|||
|
|
|
|||
|
|
**文件**: `peidu/backend/src/main/java/com/peidu/service/impl/CalendarServiceImpl.java`
|
|||
|
|
|
|||
|
|
**实现方法**:
|
|||
|
|
|
|||
|
|
#### getAllAppointments - 获取所有预约记录
|
|||
|
|
```java
|
|||
|
|
@Override
|
|||
|
|
public List<AppointmentVO> getAllAppointments(Long userId) {
|
|||
|
|
log.info("查询用户所有预约记录, userId: {}", userId);
|
|||
|
|
|
|||
|
|
QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
|
|||
|
|
queryWrapper.eq("user_id", userId)
|
|||
|
|
.in("status", Arrays.asList(1, 2, 3, 4)) // 待接单、待服务、服务中、已完成
|
|||
|
|
.eq("deleted", 0)
|
|||
|
|
.orderByAsc("service_date", "time_slot");
|
|||
|
|
|
|||
|
|
List<Order> orders = orderMapper.selectList(queryWrapper);
|
|||
|
|
|
|||
|
|
log.info("查询到 {} 条订单记录", orders.size());
|
|||
|
|
|
|||
|
|
return orders.stream()
|
|||
|
|
.map(this::convertToAppointmentVO)
|
|||
|
|
.collect(Collectors.toList());
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**特点**:
|
|||
|
|
- ✅ 不限制日期范围,查询所有订单
|
|||
|
|
- ✅ 只查询有效状态的订单(1,2,3,4)
|
|||
|
|
- ✅ 按服务日期和时间段排序
|
|||
|
|
|
|||
|
|
#### getAllStats - 获取所有预约统计
|
|||
|
|
```java
|
|||
|
|
@Override
|
|||
|
|
public Map<String, Object> getAllStats(Long userId) {
|
|||
|
|
log.info("查询用户所有预约统计, userId: {}", userId);
|
|||
|
|
|
|||
|
|
QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
|
|||
|
|
queryWrapper.eq("user_id", userId)
|
|||
|
|
.eq("deleted", 0);
|
|||
|
|
|
|||
|
|
List<Order> orders = orderMapper.selectList(queryWrapper);
|
|||
|
|
|
|||
|
|
Map<String, Object> stats = new HashMap<>();
|
|||
|
|
stats.put("totalCount", orders.size());
|
|||
|
|
stats.put("pendingCount", orders.stream()
|
|||
|
|
.filter(o -> o.getStatus() == 1 || o.getStatus() == 2)
|
|||
|
|
.count());
|
|||
|
|
stats.put("ongoingCount", orders.stream()
|
|||
|
|
.filter(o -> o.getStatus() == 3)
|
|||
|
|
.count());
|
|||
|
|
stats.put("completedCount", orders.stream()
|
|||
|
|
.filter(o -> o.getStatus() == 4)
|
|||
|
|
.count());
|
|||
|
|
|
|||
|
|
return stats;
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**返回数据**:
|
|||
|
|
- `totalCount`: 总订单数
|
|||
|
|
- `pendingCount`: 待服务数(状态1+2)
|
|||
|
|
- `ongoingCount`: 服务中数(状态3)
|
|||
|
|
- `completedCount`: 已完成数(状态4)
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### 3. CalendarController 控制器
|
|||
|
|
|
|||
|
|
**文件**: `peidu/backend/src/main/java/com/peidu/controller/CalendarController.java`
|
|||
|
|
|
|||
|
|
**新增接口**:
|
|||
|
|
|
|||
|
|
#### GET /api/calendar/all-appointments
|
|||
|
|
```java
|
|||
|
|
@GetMapping("/all-appointments")
|
|||
|
|
@ApiOperation("获取所有预约记录(不限日期)")
|
|||
|
|
public Result<List<AppointmentVO>> getAllAppointments(
|
|||
|
|
javax.servlet.http.HttpServletRequest request) {
|
|||
|
|
|
|||
|
|
Long userId = getCurrentUserId(request);
|
|||
|
|
List<AppointmentVO> appointments = calendarService.getAllAppointments(userId);
|
|||
|
|
|
|||
|
|
log.info("查询到 {} 条预约记录", appointments.size());
|
|||
|
|
return Result.success(appointments);
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**接口说明**:
|
|||
|
|
- 请求方式: GET
|
|||
|
|
- 路径: `/api/calendar/all-appointments`
|
|||
|
|
- 参数: 无(从请求中获取userId)
|
|||
|
|
- 返回: 所有预约记录列表
|
|||
|
|
|
|||
|
|
#### GET /api/calendar/all-stats
|
|||
|
|
```java
|
|||
|
|
@GetMapping("/all-stats")
|
|||
|
|
@ApiOperation("获取所有预约统计(不限日期)")
|
|||
|
|
public Result<Object> getAllStats(
|
|||
|
|
javax.servlet.http.HttpServletRequest request) {
|
|||
|
|
|
|||
|
|
Long userId = getCurrentUserId(request);
|
|||
|
|
Object stats = calendarService.getAllStats(userId);
|
|||
|
|
|
|||
|
|
return Result.success(stats);
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**接口说明**:
|
|||
|
|
- 请求方式: GET
|
|||
|
|
- 路径: `/api/calendar/all-stats`
|
|||
|
|
- 参数: 无(从请求中获取userId)
|
|||
|
|
- 返回: 统计数据对象
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 🧪 接口测试
|
|||
|
|
|
|||
|
|
### 测试1: 获取所有预约记录
|
|||
|
|
|
|||
|
|
**请求**:
|
|||
|
|
```http
|
|||
|
|
GET /api/calendar/all-appointments
|
|||
|
|
Authorization: Bearer {token}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**预期响应**:
|
|||
|
|
```json
|
|||
|
|
{
|
|||
|
|
"code": 200,
|
|||
|
|
"message": "success",
|
|||
|
|
"data": [
|
|||
|
|
{
|
|||
|
|
"id": 1,
|
|||
|
|
"orderNo": "ORD20260124120616006",
|
|||
|
|
"serviceDate": "2026-01-28",
|
|||
|
|
"timeSlot": "14:00-16:00",
|
|||
|
|
"serviceType": "陪伴服务",
|
|||
|
|
"serviceName": "数字辅导",
|
|||
|
|
"status": 1,
|
|||
|
|
"statusText": "待接单"
|
|||
|
|
},
|
|||
|
|
// ... 更多订单
|
|||
|
|
]
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 测试2: 获取所有预约统计
|
|||
|
|
|
|||
|
|
**请求**:
|
|||
|
|
```http
|
|||
|
|
GET /api/calendar/all-stats
|
|||
|
|
Authorization: Bearer {token}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**预期响应**:
|
|||
|
|
```json
|
|||
|
|
{
|
|||
|
|
"code": 200,
|
|||
|
|
"message": "success",
|
|||
|
|
"data": {
|
|||
|
|
"totalCount": 62,
|
|||
|
|
"pendingCount": 62,
|
|||
|
|
"ongoingCount": 0,
|
|||
|
|
"completedCount": 0
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 📊 数据对比
|
|||
|
|
|
|||
|
|
### 修改前:
|
|||
|
|
|
|||
|
|
| 接口 | 查询范围 | 返回数量 |
|
|||
|
|
|------|---------|---------|
|
|||
|
|
| `/api/calendar/appointments` | 当前月份 | 6条 |
|
|||
|
|
| `/api/calendar/monthly-stats` | 当前月份 | 6条 |
|
|||
|
|
|
|||
|
|
### 修改后:
|
|||
|
|
|
|||
|
|
| 接口 | 查询范围 | 返回数量 |
|
|||
|
|
|------|---------|---------|
|
|||
|
|
| `/api/calendar/appointments` | 当前月份 | 6条 |
|
|||
|
|
| `/api/calendar/all-appointments` | 所有月份 | 62条 ✅ |
|
|||
|
|
| `/api/calendar/monthly-stats` | 当前月份 | 6条 |
|
|||
|
|
| `/api/calendar/all-stats` | 所有月份 | 62条 ✅ |
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 🎯 下一步操作
|
|||
|
|
|
|||
|
|
### 1. 编译后端代码
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
cd peidu/backend
|
|||
|
|
mvn clean compile
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 2. 重启后端服务
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 停止现有服务
|
|||
|
|
# 启动新服务
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 3. 测试新接口
|
|||
|
|
|
|||
|
|
使用Postman或浏览器测试:
|
|||
|
|
- `GET http://localhost:8080/api/calendar/all-appointments`
|
|||
|
|
- `GET http://localhost:8080/api/calendar/all-stats`
|
|||
|
|
|
|||
|
|
### 4. 修改前端页面
|
|||
|
|
|
|||
|
|
需要修改的文件:
|
|||
|
|
- `peidu/uniapp/src/user-package/pages/calendar/index.vue`
|
|||
|
|
- `peidu/uniapp/src/api/index.js` (添加新的API方法)
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 📝 前端修改计划
|
|||
|
|
|
|||
|
|
### 1. 添加API方法
|
|||
|
|
|
|||
|
|
```javascript
|
|||
|
|
// api/index.js
|
|||
|
|
export const calendarApi = {
|
|||
|
|
// 现有方法
|
|||
|
|
getAppointments(startDate, endDate) {
|
|||
|
|
return request({
|
|||
|
|
url: '/api/calendar/appointments',
|
|||
|
|
method: 'get',
|
|||
|
|
params: { startDate, endDate }
|
|||
|
|
})
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
// 新增方法
|
|||
|
|
getAllAppointments() {
|
|||
|
|
return request({
|
|||
|
|
url: '/api/calendar/all-appointments',
|
|||
|
|
method: 'get'
|
|||
|
|
})
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
getAllStats() {
|
|||
|
|
return request({
|
|||
|
|
url: '/api/calendar/all-stats',
|
|||
|
|
method: 'get'
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 2. 修改日历页面
|
|||
|
|
|
|||
|
|
添加视图切换:
|
|||
|
|
- 月视图: 显示当前月份的订单
|
|||
|
|
- 全部视图: 显示所有订单
|
|||
|
|
|
|||
|
|
添加统计信息:
|
|||
|
|
- 本月课时: 当前月份订单数
|
|||
|
|
- 全部课时: 所有订单数
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## ✅ 完成清单
|
|||
|
|
|
|||
|
|
- [x] 修改 CalendarService 接口
|
|||
|
|
- [x] 实现 CalendarServiceImpl 方法
|
|||
|
|
- [x] 添加 CalendarController 接口
|
|||
|
|
- [ ] 编译后端代码
|
|||
|
|
- [ ] 测试新接口
|
|||
|
|
- [ ] 修改前端API方法
|
|||
|
|
- [ ] 修改前端日历页面
|
|||
|
|
- [ ] 测试前端功能
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 🔍 注意事项
|
|||
|
|
|
|||
|
|
### 1. 用户ID获取
|
|||
|
|
|
|||
|
|
确保 `getCurrentUserId()` 方法能正确获取用户ID:
|
|||
|
|
```java
|
|||
|
|
private Long getCurrentUserId(javax.servlet.http.HttpServletRequest request) {
|
|||
|
|
Object userIdObj = request.getAttribute("userId");
|
|||
|
|
if (userIdObj != null) {
|
|||
|
|
return Long.valueOf(userIdObj.toString());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Object teacherIdObj = request.getAttribute("teacherId");
|
|||
|
|
if (teacherIdObj != null) {
|
|||
|
|
return Long.valueOf(teacherIdObj.toString());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
log.warn("无法从请求中获取用户ID");
|
|||
|
|
return 1L; // 默认值
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 2. 订单状态
|
|||
|
|
|
|||
|
|
当前查询的状态:
|
|||
|
|
- 1: 待接单(已支付)
|
|||
|
|
- 2: 待服务(已接单)
|
|||
|
|
- 3: 服务中
|
|||
|
|
- 4: 已完成
|
|||
|
|
|
|||
|
|
不包括:
|
|||
|
|
- 0: 待支付
|
|||
|
|
- -1: 已取消
|
|||
|
|
- -2: 退款中
|
|||
|
|
- -3: 已退款
|
|||
|
|
|
|||
|
|
### 3. 性能考虑
|
|||
|
|
|
|||
|
|
如果订单数量很大,建议:
|
|||
|
|
- 添加分页功能
|
|||
|
|
- 添加缓存机制
|
|||
|
|
- 优化查询条件
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
**完成时间**: 2026-01-24
|
|||
|
|
**修改人员**: Kiro AI Assistant
|
|||
|
|
**状态**: ✅ 后端接口已完成,等待编译测试
|
|||
|
|
|
|||
|
|
🎉 后端接口已完成!现在可以编译并测试新接口了!
|