// 考试题库相关API接口 import { ApiRequest } from '../request' import type { ApiResponse, ApiResponseWithResult, Repo, Question, CreateRepoRequest, UpdateRepoRequest, CreateQuestionRequest, UpdateQuestionRequest, CreateQuestionOptionRequest, UpdateQuestionOptionRequest, CreateQuestionAnswerRequest, UpdateQuestionAnswerRequest, CreateQuestionRepoRequest, UpdateQuestionRepoRequest, } from '../types' /** * 考试题库API模块 */ export class ExamApi { // ========== 题库管理 ========== /** * 课程新建题库 */ static async createCourseRepo(data: CreateRepoRequest): Promise> { console.log('🚀 创建课程题库:', data) const response = await ApiRequest.post('/aiol/repo/courseAdd', data) console.log('✅ 创建课程题库成功:', response) return response } /** * 获取课程题库 */ static async getCourseRepoList(): Promise> { const response = await ApiRequest.get<{ result: Repo[] }>(`/aiol/aiolRepo/repoList`) console.log('✅ 获取课程题库列表成功:', response) return response } /** * 获取课程列表(用于题库筛选) */ static async getCourseList(): Promise> { try { // 调用现有的课程列表API,但只返回id和name字段 const response = await ApiRequest.get('/biz/course/list') console.log('✅ 获取课程列表成功:', response) // 处理响应数据,只提取id和name if (response.data && response.data.success && response.data.result) { const courseList = response.data.result.map((course: any) => ({ id: course.id, name: course.name || course.title || '未命名课程' })) return { code: response.data.code || 200, message: response.data.message || 'success', data: courseList } } // 如果响应格式不符合预期,返回空数组 return { code: 200, message: 'success', data: [] } } catch (error) { console.error('获取课程列表失败:', error) throw error } } /** * 删除题库 */ static async deleteRepo(id: string): Promise> { console.log('🚀 删除题库:', { id }) const response = await ApiRequest.delete('/gen/repo/repo/delete', { id }) console.log('✅ 删除题库成功:', response) return response } /** * 编辑题库 */ static async updateRepo(data: UpdateRepoRequest): Promise> { console.log('🚀 编辑题库:', data) const response = await ApiRequest.put('/gen/repo/repo/edit', data) console.log('✅ 编辑题库成功:', response) return response } // ========== 题目管理 ========== /** * 查询题库下题目 */ static async getQuestionsByRepo(repoId: string): Promise> { console.log('🚀 查询题库下题目:', { repoId }) const response = await ApiRequest.get(`/aiol/aiolRepo/questionList/${repoId}`) console.log('✅ 查询题库下题目成功:', response) return response } /** * 查询题目详情 */ static async getQuestionDetail(questionId: string): Promise> { console.log('🚀 查询题目详情:', { questionId }) const response = await ApiRequest.get(`/biz/repo/repoList/${questionId}`) console.log('✅ 查询题目详情成功:', response) return response } /** * 添加题目 */ static async createQuestion(data: CreateQuestionRequest): Promise> { console.log('🚀 添加题目:', data) const response = await ApiRequest.post('/gen/question/question/add', data) console.log('✅ 添加题目成功:', response) return response } /** * 编辑题目 */ static async updateQuestion(data: UpdateQuestionRequest): Promise> { console.log('🚀 编辑题目:', data) const response = await ApiRequest.put('/gen/question/question/edit', data) console.log('✅ 编辑题目成功:', response) return response } /** * 删除题目 */ static async deleteQuestion(id: string): Promise> { console.log('🚀 删除题目:', { id }) const response = await ApiRequest.delete('/gen/question/question/delete', { params: { id } }) console.log('✅ 删除题目成功:', response) return response } // ========== 题目选项管理 ========== /** * 添加题目选项 */ static async createQuestionOption(data: CreateQuestionOptionRequest): Promise> { console.log('🚀 添加题目选项:', data) const response = await ApiRequest.post('/gen/questionoption/questionOption/add', data) console.log('✅ 添加题目选项成功:', response) return response } /** * 编辑题目选项 */ static async updateQuestionOption(data: UpdateQuestionOptionRequest): Promise> { console.log('🚀 编辑题目选项:', data) const response = await ApiRequest.put('/gen/questionoption/questionOption/edit', data) console.log('✅ 编辑题目选项成功:', response) return response } /** * 删除题目选项 */ static async deleteQuestionOption(id: string): Promise> { console.log('🚀 删除题目选项:', { id }) const response = await ApiRequest.delete('/gen/questionoption/questionOption/delete', { params: { id } }) console.log('✅ 删除题目选项成功:', response) return response } // ========== 题目答案管理 ========== /** * 添加题目答案 */ static async createQuestionAnswer(data: CreateQuestionAnswerRequest): Promise> { console.log('🚀 添加题目答案:', data) const response = await ApiRequest.post('/gen/questionanswer/questionAnswer/add', data) console.log('✅ 添加题目答案成功:', response) return response } /** * 编辑题目答案 */ static async updateQuestionAnswer(data: UpdateQuestionAnswerRequest): Promise> { console.log('🚀 编辑题目答案:', data) const response = await ApiRequest.put('/gen/questionanswer/questionAnswer/edit', data) console.log('✅ 编辑题目答案成功:', response) return response } /** * 删除题目答案 */ static async deleteQuestionAnswer(id: string): Promise> { console.log('🚀 删除题目答案:', { id }) const response = await ApiRequest.delete('/gen/questionanswer/questionAnswer/delete', { params: { id } }) console.log('✅ 删除题目答案成功:', response) return response } // ========== 题库题目关联管理 ========== /** * 添加题库题目关联 */ static async createQuestionRepo(data: CreateQuestionRepoRequest): Promise> { console.log('🚀 添加题库题目关联:', data) const response = await ApiRequest.post('/gen/questionrepo/questionRepo/add', data) console.log('✅ 添加题库题目关联成功:', response) return response } /** * 编辑题库题目关联 */ static async updateQuestionRepo(data: UpdateQuestionRepoRequest): Promise> { console.log('🚀 编辑题库题目关联:', data) const response = await ApiRequest.put('/gen/questionrepo/questionRepo/edit', data) console.log('✅ 编辑题库题目关联成功:', response) return response } /** * 删除题库题目关联 */ static async deleteQuestionRepo(id: string): Promise> { console.log('🚀 删除题库题目关联:', { id }) const response = await ApiRequest.delete('/gen/questionrepo/questionRepo/delete', { params: { id } }) console.log('✅ 删除题库题目关联成功:', response) return response } // ========== 常用工具方法 ========== /** * 题目类型映射 */ static getQuestionTypeText(type: number): string { const typeMap: Record = { 0: '单选题', 1: '多选题', 2: '判断题', 3: '填空题', 4: '简答题', 5: '复合题' } return typeMap[type] || '未知类型' } /** * 难度等级映射 */ static getDifficultyText(difficulty: number): string { const difficultyMap: Record = { 1: '简单', 2: '中等', 3: '困难' } return difficultyMap[difficulty] || '未知难度' } /** * 批量添加题目选项 */ static async batchCreateQuestionOptions( questionId: string, options: Omit[] ): Promise[]> { console.log('🚀 批量添加题目选项:', { questionId, options }) const promises = options.map(option => this.createQuestionOption({ ...option, questionId }) ) const responses = await Promise.all(promises) console.log('✅ 批量添加题目选项成功:', responses) return responses } /** * 批量添加题目答案 */ static async batchCreateQuestionAnswers( questionId: string, answers: Omit[] ): Promise[]> { console.log('🚀 批量添加题目答案:', { questionId, answers }) const promises = answers.map(answer => this.createQuestionAnswer({ ...answer, questionId }) ) const responses = await Promise.all(promises) console.log('✅ 批量添加题目答案成功:', responses) return responses } } export default ExamApi