Files
zyt/FINAL_DEBUG_GUIDE.md
T
2026-03-04 15:32:30 +08:00

177 lines
3.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 预约时间段Bug最终调试指南
## 问题确认
- 数据库中只有上午排班记录
- 但前端显示了上午和下午的时间段
- 测试脚本证明代码逻辑是正确的
## 调试步骤
### 步骤1: 确认数据库数据
```sql
SELECT id, doctor_id, date, period, status, quota,
HEX(period) as period_hex, -- 查看period的十六进制值
LENGTH(period) as period_length -- 查看period的长度
FROM zyt_doctor_roster
WHERE doctor_id = 1 AND date = '2026-03-06';
```
**期望结果:**
- 只有1条记录
- period = 'morning' 或 '上午' 或 1
- status = 1
**如果有2条记录,说明数据有问题!**
### 步骤2: 清除所有缓存
#### 后端缓存
```bash
# 清除ThinkPHP缓存
rm -rf runtime/cache/*
rm -rf runtime/temp/*
```
#### 前端缓存
1. 浏览器按 Ctrl+Shift+Delete 清除缓存
2. 或者按 Ctrl+Shift+R 强制刷新
3. 或者打开开发者工具 -> Network -> 勾选 "Disable cache"
### 步骤3: 测试API并查看响应
#### 使用浏览器测试
访问:
```
http://your-domain/adminapi/doctor.appointment/availableSlots?doctor_id=1&appointment_date=2026-03-06&period=all
```
#### 使用curl测试
```bash
curl "http://your-domain/adminapi/doctor.appointment/availableSlots?doctor_id=1&appointment_date=2026-03-06&period=all"
```
**检查返回的JSON**
```json
{
"code": 1,
"data": {
"slots": [
{"time": "09:00", ...},
{"time": "09:15", ...},
...
{"time": "11:45", ...}
]
}
}
```
**如果slots数组中有14:00之后的时间,说明后端返回了错误数据!**
### 步骤4: 查看日志
查看文件:`runtime/log/日期.log`
搜索关键字:
```
该日期所有排班数据(包括非出诊)
```
日志应该显示:
```
该日期所有排班数据(包括非出诊): {
"count": 1, // 只有1条记录
"all_rosters": [
{
"id": 1,
"doctor_id": 1,
"date": "2026-03-06",
"period": "morning",
"status": 1,
...
}
]
}
```
然后搜索:
```
morning_slots
afternoon_slots
```
应该显示:
```
生成的时间段数量(去重后): {
"count": 12,
"morning_slots": 12,
"afternoon_slots": 0,
...
}
```
**如果afternoon_slots > 0,说明代码生成了下午时段!**
### 步骤5: 前端调试
在浏览器控制台查看:
```javascript
// 应该会看到两行输出
时间段数据: {slots: Array(12)}
处理后的时间段: Array(12)
```
**如果Array的长度大于12,说明返回了下午时段!**
## 可能的原因和解决方案
### 原因1: 数据库中有多条记录
**解决方案:** 删除多余的记录
```sql
-- 查看所有记录
SELECT * FROM zyt_doctor_roster WHERE doctor_id = 1 AND date = '2026-03-06';
-- 如果有下午的记录且不需要,删除它
DELETE FROM zyt_doctor_roster
WHERE doctor_id = 1 AND date = '2026-03-06' AND period IN ('afternoon', '下午', '2');
```
### 原因2: period字段值异常
**解决方案:** 修正period字段
```sql
-- 检查period字段的实际值
SELECT DISTINCT period, HEX(period), LENGTH(period)
FROM zyt_doctor_roster;
-- 如果发现异常值,统一修正
UPDATE zyt_doctor_roster SET period = 'morning' WHERE period = '上午';
UPDATE zyt_doctor_roster SET period = 'afternoon' WHERE period = '下午';
```
### 原因3: 前端缓存
**解决方案:** 清除浏览器缓存,强制刷新
### 原因4: 代码被修改过
**解决方案:** 检查是否有其他人修改了代码,或者有其他版本的代码在运行
## 终极测试
运行测试脚本:
```bash
php test_slot_generation.php
```
应该输出:
```
✓ 测试通过!逻辑正确。
```
如果测试通过,说明代码逻辑没问题,问题在数据或缓存。
## 下一步
根据上述调试结果,确定问题所在:
1. 如果是数据问题 -> 清理数据库
2. 如果是缓存问题 -> 清除缓存
3. 如果是代码问题 -> 检查代码版本
4. 如果都不是 -> 提供日志和API响应,我们继续分析