# 运维管理系统前端开发API文档 ## 📖 文档概述 本文档为前端开发团队提供完整的API使用指南,包含运维工单管理和AI智能回答功能的所有接口说明、数据结构定义和开发建议。 ## 🌐 基础信息 ### 服务器配置 - **开发环境**: http://localhost:8080 - **API文档**: http://localhost:8080/doc.html - **数据库监控**: http://localhost:8080/druid (admin/123456) ### 认证机制 - **认证方式**: JWT Token + Apache Shiro - **Token有效期**: 10小时(后端Token) - **加密方式**: RSA加密 + SM3哈希 ### 请求/响应格式 ```javascript // 统一请求格式 { "headers": { "Content-Type": "application/json", "Authorization": "Bearer " } } // 统一响应格式 { "code": 200, // 状态码: 200=成功 "message": "操作成功", // 消息说明 "data": {}, // 数据载荷 "timestamp": 1692000000 // 时间戳 } // 错误响应格式 { "code": 500, "message": "系统内部错误: 具体错误信息", "data": null } ``` ## 🏗️ 核心API模块 ### 1. 用户认证模块 (UserController) #### 1.1 用户登录 ```http POST /user/login Content-Type: application/json { "username": "用户名", "password": "加密后的密码" } Response: { "code": 200, "data": { "token": "jwt_token_string", "userInfo": { "id": "用户ID", "username": "用户名", "nickname": "昵称", "org": "所属组织", "role": "角色类型" } } } ``` #### 1.2 获取用户信息 ```http GET /user/info Authorization: Bearer Response: { "code": 200, "data": { "id": "用户ID", "username": "用户名", "nickname": "昵称", "org": "所属组织", "mobile": "手机号", "email": "邮箱" } } ``` #### 1.3 用户退出 ```http POST /user/logout Authorization: Bearer ``` ### 2. 工单管理模块 (RepairController) #### 2.1 创建工单 ```http POST /repair Authorization: Bearer Content-Type: application/json { "title": "工单标题", "faultDescription": "故障描述", "business": "业务模块", "priority": 2, // 1=紧急, 2=高, 3=中, 4=低 "org": "所属组织", "source": "1", // 来源: 1=PC, 2=微信, 3=APP "contactPhone": "联系电话" } Response: { "code": 200, "data": "YW202408140001" // 工单ID } ``` #### 2.2 工单列表查询 ```http POST /repair/list Authorization: Bearer Content-Type: application/json { "pageNum": 1, "pageSize": 20, "title": "搜索关键词", "business": "业务模块", "priority": 2, "dateStart": "2024-08-01", "dateEnd": "2024-08-14" } Response: { "code": 200, "data": { "records": [ { "repairId": "YW202408140001", "title": "工单标题", "faultDescription": "故障描述", "business": "业务模块", "priority": 2, "statusName": "状态名称", "createTime": "2024-08-14T10:30:00", "username": "提交人", "nickname": "提交人昵称" } ], "total": 100, "size": 20, "current": 1 } } ``` #### 2.3 工单详情 ```http GET /repair/detail?repairId=YW202408140001 Authorization: Bearer Response: { "code": 200, "data": { "repairId": "YW202408140001", "title": "工单标题", "faultDescription": "故障描述", "business": "业务模块", "priority": 2, "createTime": "2024-08-14T10:30:00", "handles": [ { "step": "submit", "stepName": "提交", "result": "工单已提交", "happenTime": "2024-08-14T10:30:00", "username": "操作人" } ], "files": [ { "fileName": "截图.png", "fileUrl": "/upload/files/xxx.png" } ] } } ``` #### 2.4 工单处理 ```http POST /repair/handle/next Authorization: Bearer Content-Type: application/json { "repairId": "YW202408140001", "result": "处理结果", "nextStep": "resolve", // 下一步状态 "assignTo": "分配给谁" // 可选 } ``` ### 3. AI智能回答模块 (流式输出,已实现) #### 3.1 流式生成AI回答 (SSE) ```http GET /api/ai/answer/stream/{repairId} Authorization: Bearer Accept: text/event-stream Stream Response (Server-Sent Events): event: progress data: {"stage": "analyzing", "message": "正在分析工单内容...", "progress": 20} event: progress data: {"stage": "searching", "message": "搜索相似案例...", "progress": 40} event: progress data: {"stage": "generating", "message": "生成AI回答...", "progress": 60} event: chunk data: {"text": "## 问题分析\n根据您描述的", "isComplete": false} event: chunk data: {"text": "网络连接问题,可能的原因包括:", "isComplete": false} event: complete data: { "answerId": "answer_20241016001", "repairId": "YW202408140001", "fullAnswer": "## 问题分析\n根据您描述的网络连接问题...", "confidenceScore": 0.85, "generateTime": "2024-08-14T10:35:00", "processingTimeMs": 3250, "usedMcpTools": "knowledge_search,similar_cases", "isComplete": true } ``` #### 3.2 非流式生成AI回答 ```http POST /api/ai/answer/generate Authorization: Bearer Content-Type: application/json { "repairId": "YW202408140001", "streaming": false, "includeHistory": true } Response: { "code": 200, "data": { "answerId": "answer_20241016001", "repairId": "YW202408140001", "answer": "## 问题分析\n根据您描述的网络连接问题...", "confidenceScore": 0.85, "generateTime": "2024-08-14T10:35:00", "processingTimeMs": 1250, "usedMcpTools": "knowledge_search,similar_cases" } } ``` #### 3.3 流式聊天对话 (SSE) ```http POST /api/ai/chat/stream Authorization: Bearer Content-Type: application/json Accept: text/event-stream { "message": "如何解决网络连接问题?", "sessionId": "chat_session_001", // 可选,用于多轮对话 "context": { "repairId": "YW202408140001", // 可选,关联工单 "previousMessages": [] // 可选,历史对话 } } Stream Response: event: start data: {"sessionId": "chat_session_001", "timestamp": "2024-08-14T10:35:00"} event: chunk data: {"text": "根据您的描述,网络连接问题", "index": 0} event: chunk data: {"text": "通常由以下几个方面引起:", "index": 1} event: complete data: { "sessionId": "chat_session_001", "fullResponse": "根据您的描述,网络连接问题通常由以下几个方面引起:...", "tokenCount": 245, "responseTime": 2100, "isComplete": true } ``` #### 3.4 中断流式生成 ```http POST /api/ai/chat/stream/{sessionId}/stop Authorization: Bearer Response: { "code": 200, "data": { "sessionId": "chat_session_001", "status": "stopped", "partialResponse": "已生成的部分内容...", "stopTime": "2024-08-14T10:35:30" } } ``` #### 3.5 获取AI回答历史 ```http GET /api/ai/answer/history/{repairId} Authorization: Bearer Response: { "code": 200, "data": [ { "answerId": "answer_20241016001", "question": "用户提出的问题", "answer": "AI生成的回答", "confidenceScore": 0.85, "status": "generated", // generated, accepted, rejected "generateTime": "2024-08-14T10:35:00", "isStreaming": true, "responseTime": 3250 } ] } ``` #### 3.6 用户反馈AI回答 ```http POST /api/ai/answer/feedback Authorization: Bearer Content-Type: application/json { "answerId": "answer_20241016001", "feedbackType": "accept", // accept, reject, escalate "userRating": 4, // 1-5分评价 "userComment": "回答很有帮助", "improvement": "建议添加更详细的步骤" } ``` ### 4. 工单待办模块 (RepairTodoController) #### 4.1 我的待办工单 ```http POST /repairTodo/list Authorization: Bearer Content-Type: application/json { "pageNum": 1, "pageSize": 20, "step": "declare", // 可选: 按步骤筛选 "urgent": true // 可选: 只看紧急工单 } Response: { "code": 200, "data": { "records": [ { "repairId": "YW202408140001", "title": "工单标题", "step": "declare", "stepName": "待分派", "priority": 2, "createTime": "2024-08-14T10:30:00", "deadline": "2024-08-15T18:00:00" } ], "total": 10 } } ``` ### 5. 统计分析模块 (StatisticController) #### 5.1 工单统计概览 ```http GET /statistic/overview Authorization: Bearer Response: { "code": 200, "data": { "totalRepairs": 1250, "pendingRepairs": 45, "resolvedToday": 28, "avgResolutionTime": 4.2, // 小时 "monthlyStats": [ { "month": "2024-08", "submitted": 156, "resolved": 142, "resolutionRate": 91.0 } ] } } ``` ## 🎨 前端页面开发指南 ### 1. 工单列表页面 #### 核心功能 - 工单列表展示(支持分页、筛选、排序) - 工单状态标识(颜色区分优先级) - 快速操作按钮(查看详情、处理、分派) - 实时状态更新(WebSocket推送) #### 关键组件 ```vue ``` ### 2. AI智能回答页面 (支持流式输出) #### 核心功能 - 流式AI回答展示(实时显示生成过程) - 进度指示器(分析、搜索、生成阶段) - 用户反馈收集(满意度、评分、意见) - 相似案例推荐 - 回答质量评估指标 - 中断生成功能 #### 设计建议 ```vue ``` ## 🔧 开发建议 ### 1. 状态管理 ```javascript // Pinia Store for Repair Management import { defineStore } from 'pinia' export const useRepairStore = defineStore('repair', { state: () => ({ repairList: [], currentRepair: null, aiAnswers: {}, loading: false }), actions: { async fetchRepairList(params) { this.loading = true try { const response = await repairAPI.getRepairList(params) this.repairList = response.data.records return response.data } finally { this.loading = false } }, async generateAIAnswer(repairId) { try { const response = await repairAPI.generateAIAnswer(repairId) this.aiAnswers[repairId] = response.data return response.data } catch (error) { throw error } } } }) ``` ### 2. 错误处理 ```javascript // API错误统一处理 import axios from 'axios' import { ElMessage } from 'element-plus' const apiClient = axios.create({ baseURL: '/api', timeout: 30000 }) apiClient.interceptors.response.use( response => { if (response.data.code !== 200) { ElMessage.error(response.data.message) throw new Error(response.data.message) } return response.data }, error => { if (error.response?.status === 401) { // 跳转到登录页 router.push('/login') } else { ElMessage.error(error.message || '网络请求失败') } return Promise.reject(error) } ) ``` ### 3. WebSocket实时通知 ```javascript // WebSocket连接管理 class WebSocketManager { constructor() { this.ws = null this.reconnectCount = 0 } connect(userId) { this.ws = new WebSocket(`ws://localhost:8080/websocket/${userId}`) this.ws.onmessage = (event) => { const notification = JSON.parse(event.data) this.handleNotification(notification) } this.ws.onclose = () => { // 自动重连逻辑 if (this.reconnectCount < 5) { setTimeout(() => { this.connect(userId) this.reconnectCount++ }, 5000) } } } handleNotification(notification) { switch (notification.type) { case 'ai_answer': ElMessage.success('AI助手已为您的问题提供了解决方案') // 更新页面状态 break case 'repair_assigned': ElMessage.info('您有新的工单分配') break } } } ``` ## 🧪 AI功能测试Demo ### 测试页面实现 创建一个专门的测试页面,用于验证AI功能的各个环节: ```vue ``` ## 📋 总结 ### 开发优先级 1. **Phase 1**: 基础工单管理功能(已可用) 2. **Phase 2**: 用户认证和权限系统(已可用) 3. **Phase 3**: AI智能回答功能(✅ 已实现,支持流式输出) 4. **Phase 4**: 高级统计分析和可视化 ### 技术栈建议 - **前端框架**: Vue 3 + Element Plus - **状态管理**: Pinia - **路由**: Vue Router 4 - **HTTP客户端**: Axios - **Markdown渲染**: marked - **图表库**: ECharts ### 部署说明 - 开发环境已启动在 http://localhost:8080 - API文档可访问 http://localhost:8080/doc.html - 当前可使用基础工单管理功能 - ✅ **AI流式输出功能已实现并可用** ### 🚀 流式输出特性 - **Server-Sent Events (SSE)**: 实时推送AI生成进度 - **实时进度指示**: 分析→搜索→生成阶段可视化 - **中断控制**: 用户可随时停止生成过程 - **性能监控**: 完整的流程追踪和性能指标 - **降级支持**: 自动切换到非流式模式作为备选 ### 🎯 前端集成要点 1. **EventSource API**: 用于接收SSE流式数据 2. **状态管理**: 生成进度、内容缓冲、会话控制 3. **用户体验**: 打字机效果、进度条、停止按钮 4. **错误处理**: 连接失败、超时、异常恢复 5. **资源清理**: 组件卸载时关闭SSE连接 这份文档为前端开发提供了完整的API接口规范、流式输出实现方案和测试Demo,确保前后端协作顺利进行。AI智能回答功能已完全就绪,支持现代化的流式用户体验。