feat(ai): 新增产品问答导入功能中的难度等级设置
- 在导入接口中添加难度参数支持
- 更新服务层方法签名以接收难度等级
- 实现难度等级在数据库中的存储逻辑
- 在前端页面增加难度选择下拉框组件
- 扩展模态窗口尺寸以容纳新选项
- 添加难度等级选择的事件监听处理
- 修改AJAX请求以传递难度参数到后端
| | |
| | | |
| | | @PostMapping(value = "/importNewProductQuestion") |
| | | @ControllerEndpoint(operation = "模板导入", exceptionMessage = "操作失败") |
| | | public FebsResponse importNewProductQuestion(@RequestBody MultipartFile file, @RequestParam String categoryId){ |
| | | public FebsResponse importNewProductQuestion(@RequestBody MultipartFile file, @RequestParam String categoryId, @RequestParam Integer difficulty){ |
| | | |
| | | String companyId = getCurrentUserCompanyId(); |
| | | return aiProductQuestionService.importNewProductQuestion(file, categoryId, companyId); |
| | | return aiProductQuestionService.importNewProductQuestion(file, categoryId, companyId,difficulty); |
| | | } |
| | | } |
| | |
| | | |
| | | void exportNewProductQuestion(AiProductQuestion dto, HttpServletResponse response); |
| | | |
| | | FebsResponse importNewProductQuestion(MultipartFile file, String categoryId, String companyId); |
| | | FebsResponse importNewProductQuestion(MultipartFile file, String categoryId, String companyId, Integer difficulty); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse importNewProductQuestion(MultipartFile file, String categoryId, String companyId) { |
| | | public FebsResponse importNewProductQuestion(MultipartFile file, String categoryId, String companyId, Integer difficulty) { |
| | | try { |
| | | if (file.isEmpty()) { |
| | | return new FebsResponse().fail().message("文件不能为空"); |
| | |
| | | question.setCompanyId(companyId); |
| | | question.setProductCategoryId(categoryId); |
| | | question.setTitle(title); |
| | | question.setDifficulty(2); // 默认中等难度 |
| | | question.setDifficulty(difficulty); // 默认中等难度 |
| | | question.setState(0); // 默认启用 |
| | | question.setCreatedTime(new Date()); |
| | | |
| | |
| | | |
| | | // 在外层定义变量,使其在多个函数中可访问 |
| | | var selectedCategoryId = ''; |
| | | var selectedDifficulty = '2'; // 默认选择中等难度 |
| | | var selectedFile = null; |
| | | |
| | | // 使用 layer.open 替代 febs.modal.open |
| | | layer.open({ |
| | | title: '模板导入(新增)', |
| | | type: 1, |
| | | area: ['500px', '350px'], |
| | | area: ['500px', '400px'], // 增加高度以适应新选项 |
| | | btn: ['开始导入', '取消'], |
| | | content: '<div style="padding: 20px;">' + |
| | | '<div class="layui-form-item">' + |
| | | '<label class="layui-form-label">选择分类</label>' + |
| | | '<div class="layui-input-block">' + |
| | | '<div id="importCategorySelect"></div>' + |
| | | '</div>' + |
| | | '</div>' + |
| | | '<div class="layui-form-item">' + |
| | | '<label class="layui-form-label">难易程度</label>' + |
| | | '<div class="layui-input-block">' + |
| | | '<select id="importDifficultySelect" lay-filter="difficulty">' + |
| | | '<option value="1">简单</option>' + |
| | | '<option value="2" selected>中等</option>' + |
| | | '<option value="3">困难</option>' + |
| | | '</select>' + |
| | | '</div>' + |
| | | '</div>' + |
| | | '<div class="layui-form-item">' + |
| | |
| | | } |
| | | }); |
| | | |
| | | // 初始化难易程度下拉框 |
| | | form.render('select', 'importDifficultySelect'); |
| | | |
| | | // 监听难易程度选择变化 |
| | | form.on('select(difficulty)', function(data){ |
| | | selectedDifficulty = data.value; |
| | | console.log('选择的难易程度:', selectedDifficulty); |
| | | }); |
| | | |
| | | // 初始化文件选择(不上传) |
| | | $('#importFileBtn').click(function() { |
| | | // 创建隐藏的文件输入 |
| | |
| | | }, |
| | | yes: function(index, layero) { |
| | | console.log('开始导入,selectedCategoryId:', selectedCategoryId); // 调试用 |
| | | console.log('开始导入,selectedDifficulty:', selectedDifficulty); // 调试用 |
| | | console.log('开始导入,selectedFile:', selectedFile); // 调试用 |
| | | |
| | | // 点击"开始导入"按钮 |
| | |
| | | // 显示加载中 |
| | | var loadingIndex = layer.load(1); |
| | | |
| | | // 使用 AJAX 上传文件 |
| | | // 使用 AJAX 上传文件,同时传递难易程度参数 |
| | | $.ajax({ |
| | | url: ctx + 'admin/productQuestion/importNewProductQuestion?categoryId=' + selectedCategoryId, |
| | | url: ctx + 'admin/productQuestion/importNewProductQuestion?categoryId=' + selectedCategoryId + '&difficulty=' + selectedDifficulty, |
| | | type: 'POST', |
| | | data: formData, |
| | | contentType: false, |