山东大学软件学院项目实训-基于大模型的模拟面试系统-面试官和面试记录的分享功能(2)
本文记录在发布文章时,可以添加自己创建的面试官和面试记录到文章中这一功能的实现。
前端
首先是在原本的界面的底部添加了两个多选框(后期需要美化调整)
实现的代码:
{{ item.name }} {{ item.topic }} { item.topic }} -->
然后是前端脚本,添加以下函数:
- getInterviewers用来获取该用户创建的所有面试官。
- getInterviews用来获取该用户创建的所有面试记录。
其次,在创建文章和保存文章时,也添加了两个列表分别存储面试官ID和面试记录ID。
// 获取用户创建的面试官列表 async getInterviewers() { let _ts = this; _ts.interviewersLoading = true; try { const res = await _ts.$axios.$get('/api/share/getUserInterviewers'); if (res) { _ts.$set(_ts, 'interviewersList', res); console.log(res); } } catch (err) { _ts.$message.error('获取面试官列表失败'); } finally { _ts.interviewersLoading = false; } },
// 获取用户创建的面试记录列表 async getInterviews() { let _ts = this; _ts.interviewsLoading = true; try { const res = await _ts.$axios.$get('/api/share/getUserChatRecords'); if (res) { _ts.$set(_ts, 'interviewsList', res); console.log(res); } } catch (err) { _ts.$message.error('获取面试记录列表失败'); } finally { _ts.interviewsLoading = false; } }
后端接口
- getUserInterviewers用来获取该用户创建的所有面试官。
- /getUserChatRecords用来获取该用户创建的所有面试记录。
@GetMapping("/getUserInterviewers") public GlobalResult getUserInterviewers() { Long idUser = UserUtils.getCurrentUserByToken().getIdUser(); List interviewers = interviewerService.findInterviewers().stream() .filter(interviewer -> interviewer.getUserId() != null && interviewer.getUserId().equals(idUser)) .collect(Collectors.toList()); return GlobalResultGenerator.genSuccessResult(interviewers); } @GetMapping("/getUserChatRecords") public GlobalResult getUserChatRecords() { Long idUser = UserUtils.getCurrentUserByToken().getIdUser(); // 1. 查询用户的所有面试官 List interviewers = interviewerService.findInterviewers(); // 2. 收集所有面试记录 List allRecords = new ArrayList(); for (Interviewer interviewer : interviewers) { ChatRecords query = new ChatRecords(); query.setUserId(idUser); query.setInterviewerId(interviewer.getInterviewerId()); allRecords.addAll(chatService.getChatRecords(query)); } return GlobalResultGenerator.genSuccessResult(allRecords); }
问题记录
- 前端发送的 JSON 中:
"chatRecordsList": [248], // 数字数组 "interviewerList": ["680c96954b1d8a29c9e78e97"] // 字符串数组
- 后端 DTO 期望:
private List chatRecordsList; // 需要对象而非数字 private List interviewerList; // 需要对象而非字符串
- FastJSON 无法直接将 248 或字符串 ID 转换为 ChatRecordsDto/Interviewer 对象。
解决方案
调整前端 JSON 结构
后端需要完整的对象而非 ID,前端发送嵌套对象:
{ "chatRecordsList": [{"id": 248}], // 匹配 ChatRecordsDto 结构 "interviewerList": [{"id": "680c96954b1d8a29c9e78e97"}] // 匹配 Interviewer 结构 }
具体修改:
let article = { idArticle: _ts.idArticle, articleTitle: _ts.articleTitle, articleContent: articleContent, articleContentHtml: articleContentHtml, articleTags: _ts.articleTags.join(","), articleStatus: 0, interviewerList: _ts.selectedInterviewers.map(id => ({ interviewerId: id, name: null, userId: null, knowledgeBaseId: null, customPrompt: null, settingsList: null })), chatRecordsList: _ts.selectedInterviews.map(id => { const interview = _ts.interviewsList.find(item => item.chatId === id); return { interviewer: { interviewerId: interview ? interview.interviewerId : null, name: null, userId: null, knowledgeBaseId: null, customPrompt: null, settingsList: null }, branch: null, chatId: id, userId: null, interviewerId: interview ? interview.interviewerId : null, createdAt: null, updatedAt: null, topic: null, }; }) };
- FastJSON 无法直接将 248 或字符串 ID 转换为 ChatRecordsDto/Interviewer 对象。
- 后端 DTO 期望:
免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们。