zhibo/调试关注功能指南.md
2026-01-03 15:32:31 +08:00

262 lines
5.5 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.

# 关注功能调试指南
## 第一步:检查数据库
### 1.1 连接数据库
```bash
mysql -h 1.15.149.240 -u root -p
use crmeb;
```
### 1.2 执行诊断脚本
```sql
source diagnose_follow_issue.sql;
```
### 1.3 检查关键点
- [ ] `eb_follow_record` 表是否存在?
- [ ] 表结构是否正确?
- [ ] 是否有测试数据?
如果表不存在,执行:
```sql
source migrate_follow_data.sql;
```
## 第二步查看Android日志
### 2.1 连接设备并查看日志
```bash
adb logcat | grep -i "RoomDetail\|follow"
```
### 2.2 关键日志
查找以下日志:
- `关注主播: streamerId=xxx, roomId=xxx` - 确认发送的用户ID
- `关注响应: code=xxx, message=xxx` - 查看服务器响应
- `房间信息加载成功: streamerId=xxx, isFollowing=xxx` - 确认房间信息
## 第三步:检查后端日志
### 3.1 查看后端日志
```bash
ssh root@1.15.149.240
cd /root/zhibo/Zhibo/zhibo-h
tail -f crmeb-admin/logs/info.log | grep -i follow
```
### 3.2 查看错误日志
```bash
tail -f crmeb-admin/logs/error.log
```
## 第四步手动测试API
### 4.1 获取token
```bash
# 登录获取token
curl -X POST http://1.15.149.240:30001/api/front/login \
-H "Content-Type: application/json" \
-d '{
"phone": "你的手机号",
"password": "你的密码"
}'
```
### 4.2 测试关注接口
```bash
# 替换 YOUR_TOKEN 和 STREAMER_ID
curl -X POST http://1.15.149.240:30001/api/front/follow/follow \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"userId": STREAMER_ID
}'
```
### 4.3 测试获取房间信息
```bash
curl -X GET http://1.15.149.240:30001/api/front/live/public/rooms/ROOM_ID \
-H "Authorization: Bearer YOUR_TOKEN"
```
## 第五步:常见问题排查
### 问题1表不存在
**症状**: 后端日志显示 `Table 'crmeb.eb_follow_record' doesn't exist`
**解决**:
```sql
source migrate_follow_data.sql;
```
### 问题2streamerId为null
**症状**: Android日志显示 `streamerId is null`
**原因**: 房间信息中没有streamerId字段
**检查**:
```sql
SELECT id, uid, title, streamer_name FROM eb_live_room LIMIT 5;
```
**解决**: 确保LiveRoomController的toResponse方法设置了streamerId
```java
resp.setStreamerId(room.getUid());
```
### 问题3接口404
**症状**: Android日志显示 `response code=404`
**原因**: API路径不正确
**检查**:
- Android: `ApiService.followUser` 使用 `/api/front/follow/follow`
- 后端: `FollowController``@PostMapping("/follow")`
### 问题4401未授权
**症状**: 返回401错误
**原因**: Token过期或无效
**解决**: 重新登录获取新token
### 问题5关注成功但状态不保存
**症状**: 点击关注提示成功,但退出重进还是未关注
**检查数据库**:
```sql
-- 查看是否有记录
SELECT * FROM eb_follow_record
WHERE follower_id = YOUR_USER_ID
AND followed_id = STREAMER_ID
ORDER BY create_time DESC;
-- 检查状态
SELECT
follower_id,
followed_id,
follow_status,
is_deleted,
create_time
FROM eb_follow_record
WHERE follower_id = YOUR_USER_ID
ORDER BY create_time DESC
LIMIT 10;
```
## 第六步:完整测试流程
### 6.1 准备测试数据
```sql
-- 查看可用的用户和主播
SELECT uid, nickname, phone, is_streamer
FROM eb_user
WHERE is_streamer = 1
LIMIT 5;
-- 查看可用的直播间
SELECT id, uid, title, streamer_name
FROM eb_live_room
LIMIT 5;
```
### 6.2 记录测试信息
- 测试用户ID: ________
- 主播用户ID: ________
- 直播间ID: ________
### 6.3 执行测试
1. 登录应用(使用测试用户)
2. 进入直播间记录的直播间ID
3. 查看Android日志记录
- roomId: ________
- streamerId: ________
4. 点击关注按钮
5. 查看提示信息: ________
6. 查看Android日志中的响应
7. 查看数据库记录:
```sql
SELECT * FROM eb_follow_record
WHERE follower_id = 测试用户ID
AND followed_id = 主播用户ID;
```
### 6.4 验证结果
- [ ] 数据库中有记录
- [ ] follow_status = 1
- [ ] is_deleted = 0
- [ ] 退出重进后按钮显示"已关注"
## 第七步:如果还是不行
### 收集以下信息:
1. **数据库检查结果**
```sql
-- 执行并提供结果
SELECT * FROM information_schema.tables
WHERE table_schema = 'crmeb'
AND table_name IN ('eb_follow_record', 'eb_user_follow');
```
2. **Android日志**
```
提供 adb logcat 中关于 RoomDetail 和 follow 的日志
```
3. **后端日志**
```
提供 /root/zhibo/Zhibo/zhibo-h/crmeb-admin/logs/info.log 中的相关日志
```
4. **API测试结果**
```
提供 curl 测试的完整响应
```
5. **数据库记录**
```sql
-- 执行并提供结果
SELECT * FROM eb_follow_record
WHERE create_time > DATE_SUB(NOW(), INTERVAL 1 HOUR)
ORDER BY create_time DESC;
```
## 快速检查清单
- [ ] 数据库中 `eb_follow_record` 表已创建
- [ ] 后端服务已重启
- [ ] Android应用已重新编译
- [ ] 用户已登录
- [ ] 进入的是有效的直播间
- [ ] 直播间的主播用户存在
- [ ] Android日志中能看到 streamerId
- [ ] 网络连接正常
- [ ] API接口路径正确
- [ ] Token有效
## 紧急修复方案
如果以上都不行,可以尝试简化方案:
### 方案A使用 eb_user_follow 表
修改 `FollowRecord` 类的表名:
```java
@TableName("eb_user_follow") // 改为使用现有表
```
并修改字段映射:
```java
@TableField("user_id")
private Integer followerId;
@TableField("follow_user_id")
private Integer followedId;
```
### 方案B直接使用JDBC
`FollowRecordServiceImpl` 中使用 JdbcTemplate 直接操作数据库绕过MyBatis。