1.修复创建多个向量库2.查看试卷没有用户答案3.向量化自动出题
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package top.tqx.demo_1.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -14,14 +14,14 @@ import top.tqx.demo_1.dto.QuestionStatsRequest;
|
||||
import top.tqx.demo_1.dto.QuestionStatsResponse;
|
||||
import top.tqx.demo_1.dto.QuestionUpdateRequest;
|
||||
import top.tqx.demo_1.entity.Question;
|
||||
import top.tqx.demo_1.service.AuthService;
|
||||
import top.tqx.demo_1.service.QuestionService;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
@Tag(name = "题目管理", description = "题目的增删改查管理接口")
|
||||
@RestController
|
||||
@RequestMapping("/question")
|
||||
@@ -31,6 +31,9 @@ public class QuestionController extends BaseController {
|
||||
@Autowired
|
||||
private QuestionService questionService;
|
||||
|
||||
@Autowired
|
||||
private AuthService authService;
|
||||
|
||||
@Operation(summary = "创建题目", description = "创建新的题目记录")
|
||||
@PostMapping
|
||||
public Result<Question> createQuestion(@RequestBody QuestionCreateRequest request) {
|
||||
@@ -66,11 +69,11 @@ public class QuestionController extends BaseController {
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取题目详情", description = "根据题目UUID获取题目详细信息")
|
||||
@GetMapping("/{questionId}")
|
||||
@Operation(summary = "获取题目详情", description = "根据题目ID获取题目详细信息")
|
||||
@GetMapping("/{id}")
|
||||
public Result<Question> getQuestionById(
|
||||
@Parameter(description = "题目UUID") @PathVariable String questionId) {
|
||||
Question question = questionService.getByQuestionId(questionId);
|
||||
@Parameter(description = "题目ID") @PathVariable Long id) {
|
||||
Question question = questionService.getById(id);
|
||||
if (question == null) {
|
||||
return Result.error(404, "题目不存在");
|
||||
}
|
||||
@@ -85,38 +88,64 @@ public class QuestionController extends BaseController {
|
||||
}
|
||||
|
||||
@Operation(summary = "更新题目", description = "更新题目信息,支持部分字段更新")
|
||||
@PutMapping("/{questionId}")
|
||||
@PutMapping("/{id}")
|
||||
public Result<Question> updateQuestion(
|
||||
@Parameter(description = "题目UUID") @PathVariable String questionId,
|
||||
@Parameter(description = "题目ID(支持Long类型的id或UUID格式的questionId)") @PathVariable String id,
|
||||
@RequestBody QuestionUpdateRequest request) {
|
||||
try {
|
||||
Question existing = questionService.getByQuestionId(questionId);
|
||||
Question existing = null;
|
||||
|
||||
if (isNumeric(id)) {
|
||||
existing = questionService.getById(Long.parseLong(id));
|
||||
log.info("通过自增ID查询题目: id={}", id);
|
||||
} else {
|
||||
LambdaQueryWrapper<Question> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Question::getQuestionId, id);
|
||||
existing = questionService.getOne(wrapper);
|
||||
log.info("通过UUID查询题目: questionId={}", id);
|
||||
}
|
||||
|
||||
if (existing == null) {
|
||||
return Result.error(404, "题目不存在");
|
||||
return Result.error(404, "题目不存在: " + id);
|
||||
}
|
||||
|
||||
Question updated = questionService.updateQuestion(existing.getId(), request);
|
||||
log.info("更新题目成功: questionId={}", questionId);
|
||||
log.info("更新题目成功: id={}, questionId={}", existing.getId(), existing.getQuestionId());
|
||||
return Result.success("题目更新成功", updated);
|
||||
} catch (NumberFormatException e) {
|
||||
log.error("ID格式错误: {}", id, e);
|
||||
return Result.error(400, "ID格式错误,请使用数字ID或有效的UUID");
|
||||
} catch (Exception e) {
|
||||
log.error("更新题目失败: {}", e.getMessage(), e);
|
||||
return Result.error(500, "更新题目失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "删除题目", description = "根据UUID删除题目")
|
||||
@DeleteMapping("/{questionId}")
|
||||
public Result<Void> deleteQuestion(
|
||||
@Parameter(description = "题目UUID") @PathVariable String questionId) {
|
||||
private boolean isNumeric(String str) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Question existing = questionService.getByQuestionId(questionId);
|
||||
Long.parseLong(str);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "删除题目", description = "根据ID删除题目")
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<Void> deleteQuestion(
|
||||
@Parameter(description = "题目ID") @PathVariable Long id) {
|
||||
try {
|
||||
Question existing = questionService.getById(id);
|
||||
if (existing == null) {
|
||||
return Result.error(404, "题目不存在");
|
||||
}
|
||||
|
||||
boolean success = questionService.deleteById(existing.getId());
|
||||
boolean success = questionService.deleteById(id);
|
||||
if (success) {
|
||||
log.info("删除题目成功: questionId={}", questionId);
|
||||
log.info("删除题目成功: id={}", id);
|
||||
return Result.success("题目删除成功");
|
||||
} else {
|
||||
return Result.error(500, "删除题目失败");
|
||||
|
||||
Reference in New Issue
Block a user