保存当前工作进度 - 2025-06-20 18:08:36

Change-Id: I9465ca3726869f7cd91fe381097d780fe7fc1271
diff --git a/Merge/front/src/api/README.md b/Merge/front/src/api/README.md
new file mode 100644
index 0000000..567d772
--- /dev/null
+++ b/Merge/front/src/api/README.md
@@ -0,0 +1,109 @@
+# API 服务修改说明
+
+## 修改概述
+
+根据要求,仅首页的推荐和搜索功能使用 `back_jwlll` 服务,其他功能使用已有的其他后端服务。
+
+## 服务分工
+
+### JWLLL 服务 (端口 5000)
+**仅用于首页推荐和搜索功能**
+- 搜索内容 (`/search`)
+- 获取用户标签 (`/user_tags`)
+- 标签推荐 (`/recommend_tags`)
+- 协同过滤推荐 (`/user_based_recommend`)
+
+### WZY 服务 (端口 5714)
+**用于帖子相关功能**
+- 帖子详情查看 (`/posts/{id}`)
+- 帖子创建/更新/删除 (`/posts`)
+- 点赞功能 (`/posts/{id}/like`)
+- 评论功能 (`/posts/{id}/comments`)
+
+### LJC 服务 (端口 5715)
+**用于用户相关功能**
+- 用户信息管理 (`/api/user/{id}`)
+- 关注功能 (`/api/follow/{id}`)
+- 收藏功能 (`/api/user/{id}/favorites`)
+
+### TRM 服务 (端口 5713)
+**用于审核相关功能**
+- 帖子审核 (`/areview`)
+- 管理员功能 (`/apostlist`)
+
+## 修改的文件
+
+### 1. `/src/api/search_jwlll.js`
+- **修改内容**: 重构API调用,推荐搜索功能继续使用JWLLL服务,其他功能重定向到相应服务
+- **主要变更**:
+  - 搜索和推荐API仍使用 `http://127.0.0.1:5000`
+  - 帖子详情、点赞、评论、上传功能改用 WZY 服务 `http://10.126.59.25:5714`
+  - 添加数据格式适配逻辑
+
+### 2. `/src/api/posts_api.js` (新增)
+- **作用**: 提供统一的帖子相关API接口
+- **功能**: 整合不同后端服务的帖子和用户功能
+
+## 数据格式适配
+
+### 评论数据适配
+- **WZY服务返回**: `{id, user_id, content, created_at, replies}`
+- **前端期望**: `{id, user_name, content, create_time}`
+- **适配方案**: 在 `getComments` 方法中进行字段映射
+
+### 帖子上传适配
+- **前端数据**: `{title, content, tags, category, type, media_files}`
+- **WZY服务期望**: `{title, content, type, media_urls, status}`
+- **适配方案**: 在 `uploadPost` 方法中进行数据转换
+
+## 影响的组件
+
+### 自动适配的组件
+- `HomeFeed.jsx` - 推荐和搜索功能,继续使用JWLLL服务
+- `PostDetailJWLLL.jsx` - 帖子详情、点赞、评论功能,自动切换到WZY服务
+- `UploadPageJWLLL.jsx` - 帖子上传功能,自动切换到WZY服务
+
+### 使用新API的组件
+如需要,其他组件可以导入 `posts_api.js` 来使用统一的帖子和用户API。
+
+## 注意事项
+
+1. **标签功能限制**: WZY服务暂不完全支持标签功能,上传帖子时标签信息会被忽略
+2. **用户名显示**: 评论中的用户名使用 `用户{user_id}` 格式生成
+3. **服务兼容性**: 确保所有后端服务都正常运行且端口配置正确
+4. **错误处理**: 各服务的错误响应格式可能不同,前端已添加通用错误处理
+
+## 测试建议
+
+### 测试文件
+提供了 `test_api.js` 文件来验证API服务分工是否正确:
+
+```javascript
+import { runAllTests } from './test_api.js'
+
+// 运行所有测试
+runAllTests()
+```
+
+### 手动测试步骤
+1. **首页搜索测试**
+   - 在首页搜索框输入关键词
+   - 验证搜索结果来自 JWLLL 服务
+   - 测试推荐功能是否正常
+
+2. **帖子详情测试**
+   - 点击帖子进入详情页
+   - 验证帖子数据来自 WZY 服务
+   - 测试点赞、评论功能
+
+3. **帖子上传测试**
+   - 使用上传页面发布新帖子
+   - 验证上传请求发送到 WZY 服务
+   - 确认数据格式转换正确
+
+### 服务状态检查
+确保以下服务正常运行:
+- JWLLL 服务: `curl http://127.0.0.1:5000/word2vec_status`
+- WZY 服务: `curl http://10.126.59.25:5714/posts`
+- LJC 服务: `curl http://10.126.59.25:5715/api/current-user`
+- TRM 服务: `curl http://10.126.59.25:5713/health` (如果有)
diff --git a/Merge/front/src/api/posts_api.js b/Merge/front/src/api/posts_api.js
new file mode 100644
index 0000000..a336da0
--- /dev/null
+++ b/Merge/front/src/api/posts_api.js
@@ -0,0 +1,136 @@
+// 帖子相关API接口
+// 整合不同后端服务的帖子功能
+
+// WZY 后端服务 - 帖子CRUD、点赞、评论
+const WZY_BASE_URL = 'http://10.126.59.25:5714'
+// LJC 后端服务 - 用户相关功能
+const LJC_BASE_URL = 'http://10.126.59.25:5715'
+
+// 通用请求函数
+const request = async (url, options = {}) => {
+  try {
+    const response = await fetch(url, {
+      headers: {
+        'Content-Type': 'application/json',
+        ...options.headers
+      },
+      ...options
+    })
+    return await response.json()
+  } catch (error) {
+    console.error('API请求错误:', error)
+    throw error
+  }
+}
+
+// 帖子相关API
+export const postsAPI = {
+  // ===== 帖子基础功能 - 使用 WZY 服务 =====
+  
+  // 获取帖子列表
+  fetchPosts: async (userId = null) => {
+    const url = userId ? `${WZY_BASE_URL}/posts?user_id=${userId}` : `${WZY_BASE_URL}/posts`
+    return await request(url)
+  },
+
+  // 获取帖子详情
+  fetchPost: async (postId) => {
+    return await request(`${WZY_BASE_URL}/posts/${postId}`)
+  },
+
+  // 创建帖子
+  createPost: async (postData) => {
+    return await request(`${WZY_BASE_URL}/posts`, {
+      method: 'POST',
+      body: JSON.stringify(postData)
+    })
+  },
+
+  // 更新帖子
+  updatePost: async (postId, postData) => {
+    return await request(`${WZY_BASE_URL}/posts/${postId}`, {
+      method: 'PUT',
+      body: JSON.stringify(postData)
+    })
+  },
+
+  // 删除帖子
+  deletePost: async (postId) => {
+    return await request(`${WZY_BASE_URL}/posts/${postId}`, {
+      method: 'DELETE'
+    })
+  },
+
+  // ===== 互动功能 - 使用 WZY 服务 =====
+
+  // 点赞帖子
+  likePost: async (postId, userId) => {
+    return await request(`${WZY_BASE_URL}/posts/${postId}/like`, {
+      method: 'POST',
+      body: JSON.stringify({ user_id: userId })
+    })
+  },
+
+  // 取消点赞
+  unlikePost: async (postId, userId) => {
+    return await request(`${WZY_BASE_URL}/posts/${postId}/like`, {
+      method: 'DELETE',
+      body: JSON.stringify({ user_id: userId })
+    })
+  },
+
+  // 添加评论
+  addComment: async (postId, userId, content, parentId = null) => {
+    return await request(`${WZY_BASE_URL}/posts/${postId}/comments`, {
+      method: 'POST',
+      body: JSON.stringify({ 
+        user_id: userId, 
+        content,
+        parent_id: parentId 
+      })
+    })
+  },
+
+  // 获取评论列表
+  fetchComments: async (postId) => {
+    return await request(`${WZY_BASE_URL}/posts/${postId}/comments`)
+  },
+
+  // ===== 用户相关功能 - 使用 LJC 服务 =====
+
+  // 获取用户信息
+  getCurrentUser: async () => {
+    return await request(`${LJC_BASE_URL}/api/current-user`)
+  },
+
+  // 获取用户详情
+  getUser: async (userId) => {
+    return await request(`${LJC_BASE_URL}/api/user/${userId}`)
+  },
+
+  // 获取用户帖子
+  getUserPosts: async (userId) => {
+    return await request(`${LJC_BASE_URL}/api/user/${userId}/posts`)
+  },
+
+  // 关注用户
+  followUser: async (followeeId) => {
+    return await request(`${LJC_BASE_URL}/api/follow/${followeeId}`, {
+      method: 'POST'
+    })
+  },
+
+  // 取消关注
+  unfollowUser: async (followeeId) => {
+    return await request(`${LJC_BASE_URL}/api/follow/${followeeId}`, {
+      method: 'DELETE'
+    })
+  },
+
+  // 获取收藏列表
+  getFavorites: async (userId) => {
+    return await request(`${LJC_BASE_URL}/api/user/${userId}/favorites`)
+  }
+}
+
+export default postsAPI
diff --git a/Merge/front/src/utils/test_user_id.js b/Merge/front/src/utils/test_user_id.js
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Merge/front/src/utils/test_user_id.js