瀏覽代碼

content-service/exam 的 Question 添加一个 long 类型的 questionId

reghao 7 月之前
父節點
當前提交
022d9dece1
共有 26 個文件被更改,包括 388 次插入200 次删除
  1. 2 2
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/controller/QuestionController.java
  2. 1 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/db/mapper/PaperAnswerMapper.java
  3. 1 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/db/mapper/PaperQuestionMapper.java
  4. 5 3
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/db/mapper/QuestionMapper.java
  5. 2 2
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/db/mapper/QuestionOptionMapper.java
  6. 1 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/dto/ExamMarkResult.java
  7. 1 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/dto/QuestionAddDto.java
  8. 2 2
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/dto/UserAnswer.java
  9. 5 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/po/Paper.java
  10. 2 2
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/po/PaperAnswer.java
  11. 3 3
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/po/PaperQuestion.java
  12. 15 11
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/po/Question.java
  13. 3 3
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/po/QuestionOption.java
  14. 2 0
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/vo/PaperDetail.java
  15. 1 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/vo/QuestionAnswerInfo.java
  16. 2 2
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/vo/QuestionDetail.java
  17. 2 2
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/vo/QuestionInfo.java
  18. 1 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/vo/QuestionView.java
  19. 10 10
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/service/ExamResultService.java
  20. 16 9
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/service/ExamService.java
  21. 7 7
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/service/PaperService.java
  22. 19 22
      content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/service/QuestionService.java
  23. 2 2
      content/content-service/src/main/resources/mapper/exam/PaperMapper.xml
  24. 19 6
      content/content-service/src/main/resources/mapper/exam/QuestionMapper.xml
  25. 264 0
      content/content-service/src/test/java/cn/reghao/tnb/content/app/exam/service/ExamTest.java
  26. 0 105
      content/content-service/src/test/java/cn/reghao/tnb/content/app/vod/service/ExamTest.java

+ 2 - 2
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/controller/QuestionController.java

@@ -39,7 +39,7 @@ public class QuestionController {
 
     @Operation(summary = "删除试题", description = "N")
     @DeleteMapping(value = "/{questionId}", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String deleteQuestion(@PathVariable("questionId") Integer questionId) {
+    public String deleteQuestion(@PathVariable("questionId") Long questionId) {
         Result result = questionService.deleteQuestion(questionId);
         return WebResult.result(result);
     }
@@ -53,7 +53,7 @@ public class QuestionController {
 
     @Operation(summary = "获取试题详情", description = "N")
     @GetMapping(value = "/{questionId}", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String getQuestion(@PathVariable("questionId") Integer questionId) {
+    public String getQuestion(@PathVariable("questionId") Long questionId) {
         QuestionDetail questionDetail = questionService.getQuestionDetail(questionId);
         return WebResult.success(questionDetail);
     }

+ 1 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/db/mapper/PaperAnswerMapper.java

@@ -14,7 +14,7 @@ import java.util.List;
 @Mapper
 public interface PaperAnswerMapper extends BaseMapper<PaperAnswer> {
     void updatePaperAnswer(@Param("resultId") int resultId,
-                           @Param("questionId") int questionId,
+                           @Param("questionId") long questionId,
                            @Param("review") String review,
                            @Param("score") int score);
 

+ 1 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/db/mapper/PaperQuestionMapper.java

@@ -15,5 +15,5 @@ import java.util.List;
 public interface PaperQuestionMapper extends BaseMapper<PaperQuestion> {
     void deleteByPaperId(int paperId);
     List<PaperQuestion> findByPaperId(int paperId);
-    List<PaperQuestion> findByPaperIdAndPid(@Param("paperId") int paperId, @Param("pid") int pid);
+    List<PaperQuestion> findByPaperIdAndPid(@Param("paperId") int paperId, @Param("pid") long pid);
 }

+ 5 - 3
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/db/mapper/QuestionMapper.java

@@ -16,10 +16,12 @@ import java.util.List;
  */
 @Mapper
 public interface QuestionMapper extends BaseMapper<Question> {
-    void deleteById(int id);
+    void deleteByQuestionId(long questionId);
+
     List<Question> findBySubjectId(int subjectId);
-    List<Question> findByPid(int pid);
-    List<Question> findByQuestionIds(List<Integer> list);
+    Question findByQuestionId(long questionId);
+    List<Question> findByPid(long pid);
+    List<Question> findByQuestionIds(List<Long> list);
     List<GroupCount> findGroupBySubjectId(int subjectId);
 
     int countByCriteria(QuestionQuery questionQuery);

+ 2 - 2
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/db/mapper/QuestionOptionMapper.java

@@ -12,6 +12,6 @@ import java.util.List;
  */
 @Mapper
 public interface QuestionOptionMapper extends BaseMapper<QuestionOption> {
-    void deleteByQuestionId(int questionId);
-    List<QuestionOption> findByQuestionId(int questionId);
+    void deleteByQuestionId(long questionId);
+    List<QuestionOption> findByQuestionId(long questionId);
 }

+ 1 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/dto/ExamMarkResult.java

@@ -13,7 +13,7 @@ import javax.validation.constraints.NotNull;
 @Getter
 public class ExamMarkResult {
     @NotNull
-    private Integer questionId;
+    private Long questionId;
     @NotNull
     private Integer pos;
     @NotNull

+ 1 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/dto/QuestionAddDto.java

@@ -24,7 +24,7 @@ import javax.validation.constraints.Size;
 public class QuestionAddDto {
     @ValidEnum(value = QuestionType.class, message = "请选择正确的试题类型")
     private Integer questionType;
-    private Integer questionId;
+    private Long questionId;
     @ValidEnum(value = QuestionLevel.class, message = "请选择正确的难度等级")
     private Integer questionLevel;
     @NotNull

+ 2 - 2
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/dto/UserAnswer.java

@@ -14,8 +14,8 @@ import lombok.Setter;
 @Getter
 public class UserAnswer {
     private Integer pos;
-    private Integer pid;
-    private Integer questionId;
+    private Long pid;
+    private Long questionId;
     private Integer questionType;
     private String answer;
 

+ 5 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/po/Paper.java

@@ -8,6 +8,7 @@ import lombok.NoArgsConstructor;
 
 import java.time.LocalDateTime;
 import java.time.ZoneId;
+import java.util.List;
 
 /**
  * 试卷
@@ -27,9 +28,11 @@ public class Paper extends BaseObject<Integer> {
     private LocalDateTime startTime;
     private LocalDateTime endTime;
     private String passcode;
-    private int status;
+    private Integer status;
+    private Boolean hasSubjective;
     private LocalDateTime createAt;
     private Long createBy;
+    private transient List<PaperQuestion> paperQuestionList;
 
     public Paper(PaperAddDto paperAddDto) {
         this.subjectId = 1;
@@ -42,6 +45,7 @@ public class Paper extends BaseObject<Integer> {
         this.endTime = LocalDateTime.ofInstant(paperAddDto.getEndTime().toInstant(), ZoneId.systemDefault());
         this.passcode = paperAddDto.getExamPassword();
         this.status = 1;
+        this.hasSubjective = false;
         this.createAt = LocalDateTime.now();
         this.createBy = UserContext.getUser();
     }

+ 2 - 2
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/po/PaperAnswer.java

@@ -16,8 +16,8 @@ import lombok.NoArgsConstructor;
 public class PaperAnswer extends BaseObject<Integer> {
     private Integer resultId;
     private Integer pos;
-    private Integer pid;
-    private Integer questionId;
+    private Long pid;
+    private Long questionId;
     private Integer questionType;
     private String answer;
     private Boolean correct;

+ 3 - 3
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/po/PaperQuestion.java

@@ -16,11 +16,11 @@ import java.util.List;
 @Getter
 public class PaperQuestion extends BaseObject<Integer> {
     private Integer paperId;
-    private Integer pid;
+    private Long pid;
     @NotNull
     private Integer pos;
     @NotNull
-    private Integer questionId;
+    private Long questionId;
     @NotNull
     private Integer score;
     private Boolean child;
@@ -28,7 +28,7 @@ public class PaperQuestion extends BaseObject<Integer> {
     private transient List<PaperQuestion> children;
 
     public PaperQuestion() {
-        this.pid = 0;
+        this.pid = 0L;
         this.child = false;
     }
 

+ 15 - 11
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/po/Question.java

@@ -10,6 +10,7 @@ import lombok.Setter;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 
 /**
  * 试题
@@ -21,49 +22,52 @@ import java.util.List;
 @Getter
 @Setter
 public class Question extends BaseObject<Integer> {
+    private Long questionId;
     private Integer subjectId;
     private Integer type;
     private Integer level;
     private String content;
     private String analysis;
     private Long createBy;
-    private Integer pid;
+    private Long pid;
     private Boolean child;
     private Integer pos;
     private String extra;
     private transient List<QuestionOption> questionOptions;
 
-    public Question(int id, String content, int questionType, String extra) {
-        this.id = id;
+    public Question(long questionId, String content, int questionType, String extra) {
+        this.questionId = questionId;
         this.subjectId = 1;
         this.type = questionType;
         this.level = QuestionLevel.EASY.getCode();
         this.content = content;
         this.analysis = "";
-        this.pid = 0;
-        this.child = false;
+        this.pid = 0L;
+        this.child = questionType == QuestionType.QUESTION8.getCode();
         this.pos = 0;
         this.extra = extra;
     }
 
-    public Question(QuestionAddDto questionAddDto) {
+    public Question(long questionId, QuestionAddDto questionAddDto) {
+        this.questionId = questionId;
         this.subjectId = questionAddDto.getSubjectId();
         this.type = questionAddDto.getQuestionType();
         this.level = questionAddDto.getQuestionLevel();
         this.content = questionAddDto.getQuestionContent();
         this.analysis = questionAddDto.getAnalysis();
-        this.pid = 0;
-        this.child = false;
+        this.pid = 0L;
+        this.child = Objects.equals(questionAddDto.getQuestionType(), QuestionType.QUESTION8.getCode());
         this.pos = 0;
     }
 
-    public Question(QuestionAddDto questionAddDto, boolean child) {
+    public Question(long questionId, QuestionAddDto questionAddDto, boolean child) {
+        this.questionId = questionId;
         this.subjectId = questionAddDto.getSubjectId();
         this.type = questionAddDto.getQuestionType();
         this.level = questionAddDto.getQuestionLevel();
         this.content = questionAddDto.getQuestionContent();
         this.analysis = questionAddDto.getAnalysis();
-        this.pid = 0;
+        this.pid = 0L;
         this.child = child;
         this.pos = 0;
     }
@@ -72,7 +76,7 @@ public class Question extends BaseObject<Integer> {
         this.subjectId = subjectId;
     }
 
-    public void setPid(Integer pid) {
+    public void setPid(Long pid) {
         this.pid = pid;
     }
 

+ 3 - 3
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/po/QuestionOption.java

@@ -14,13 +14,13 @@ import lombok.Setter;
 @Setter
 @Getter
 public class QuestionOption extends BaseObject<Integer> {
-    private Integer questionId;
+    private Long questionId;
     private Integer pos;
     private String content;
     private String analysis;
     private Boolean correct;
 
-    public QuestionOption(int questionId, String content, int pos, boolean correct) {
+    public QuestionOption(long questionId, String content, int pos, boolean correct) {
         this.questionId = questionId;
         this.pos = pos;
         this.content = content;
@@ -35,7 +35,7 @@ public class QuestionOption extends BaseObject<Integer> {
         this.correct = option.getCorrect();
     }
 
-    public void setQuestionId(Integer questionId) {
+    public void setQuestionId(long questionId) {
         this.questionId = questionId;
     }
 }

+ 2 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/vo/PaperDetail.java

@@ -9,6 +9,7 @@ import java.util.List;
  * @date 2024-08-29 17:48:51
  */
 public class PaperDetail {
+    private int paperId;
     private String name;
     private String description;
     private int duration;
@@ -16,6 +17,7 @@ public class PaperDetail {
     private List<QuestionInfo> questions;
 
     public PaperDetail(Paper paper, List<QuestionInfo> questions) {
+        this.paperId = paper.getId();
         this.name = paper.getName();
         this.description = paper.getDescription();
         this.duration = paper.getDuration();

+ 1 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/vo/QuestionAnswerInfo.java

@@ -15,7 +15,7 @@ import lombok.Setter;
 @Setter
 @Getter
 public class QuestionAnswerInfo {
-    private Integer questionId;
+    private Long questionId;
     private Integer pos;
     private String answer;
     private Boolean correct;

+ 2 - 2
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/vo/QuestionDetail.java

@@ -9,7 +9,7 @@ import java.util.List;
  * @date 2024-08-25 17:42:04
  */
 public class QuestionDetail {
-    private int questionId;
+    private long questionId;
     private String subject;
     private int type;
     private String typeStr;
@@ -20,7 +20,7 @@ public class QuestionDetail {
     private List<QuestionDetail> children;
 
     public QuestionDetail(Question question, String subject, String type, String level, List<QuestionOptionDetail> options) {
-        this.questionId = question.getId();
+        this.questionId = question.getQuestionId();
         this.subject = subject;
         this.type = question.getType();
         this.typeStr = type;

+ 2 - 2
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/vo/QuestionInfo.java

@@ -16,7 +16,7 @@ import java.util.List;
 public class QuestionInfo {
     private int pos;
     private int questionType;
-    private int questionId;
+    private long questionId;
     private String questionContent;
     private int score;
     private List<String> images;
@@ -26,7 +26,7 @@ public class QuestionInfo {
     public QuestionInfo(int pos, Question question, int score) {
         this.pos = pos;
         this.questionType = question.getType();
-        this.questionId = question.getId();
+        this.questionId = question.getQuestionId();
         this.questionContent = question.getContent();
         this.answer = Collections.emptyList();
         this.score = score;

+ 1 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/model/vo/QuestionView.java

@@ -11,7 +11,7 @@ import lombok.Getter;
 @AllArgsConstructor
 @Getter
 public class QuestionView {
-    private int questionId;
+    private long questionId;
     private String subject;
     private String type;
     private int typeCode;

+ 10 - 10
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/service/ExamResultService.java

@@ -70,7 +70,7 @@ public class ExamResultService {
     public void markExamResult(ExamMarkForm examMarkForm) {
         int resultId = examMarkForm.getResultId();
         examMarkForm.getPaperMarks().forEach(examMarkResult -> {
-            int questionId = examMarkResult.getQuestionId();
+            long questionId = examMarkResult.getQuestionId();
             String review = examMarkResult.getReview();
             int score = examMarkResult.getScore();
             paperAnswerMapper.updatePaperAnswer(resultId, questionId, review, score);
@@ -104,7 +104,7 @@ public class ExamResultService {
         }
 
         List<PaperAnswer> paperAnswers = paperAnswerMapper.findByResultId(resultId);
-        Map<Integer, PaperAnswer> answerMap = paperAnswers.stream()
+        Map<Long, PaperAnswer> answerMap = paperAnswers.stream()
                 .collect(Collectors.toMap(PaperAnswer::getQuestionId, paperAnswer -> paperAnswer));
 
         int paperId = paperResult.getPaperId();
@@ -112,7 +112,7 @@ public class ExamResultService {
         List<PaperQuestion> paperQuestions = paperQuestionMapper.findByPaperId(paperId);
         paperQuestions.sort(Comparator.comparingInt(PaperQuestion::getPos));
 
-        List<Integer> questionIds = paperQuestions.stream()
+        List<Long> questionIds = paperQuestions.stream()
                 .map(PaperQuestion::getQuestionId)
                 .collect(Collectors.toList());
         List<QuestionInfo> questionInfos = paperService.getPaperQuestions(paperId);
@@ -132,15 +132,15 @@ public class ExamResultService {
         return new ExamResult(paper, paperResult, questionResults);
     }
 
-    private List<QuestionResult> getQuestionResults(List<Integer> questionIds,
+    private List<QuestionResult> getQuestionResults(List<Long> questionIds,
                                                    List<QuestionInfo> questionInfos,
-                                                   Map<Integer, PaperAnswer> answerMap) {
-        Map<Integer, QuestionInfo> questionMap = questionInfos.stream()
+                                                   Map<Long, PaperAnswer> answerMap) {
+        Map<Long, QuestionInfo> questionMap = questionInfos.stream()
                 .collect(Collectors.toMap(QuestionInfo::getQuestionId, k -> k));
 
         List<Question> questions = questionMapper.findByQuestionIds(questionIds);
         return questions.stream().map(question -> {
-            int questionId = question.getId();
+            long questionId = question.getQuestionId();
             boolean child = question.getChild();
             QuestionResult questionResult;
             if (child) {
@@ -165,9 +165,9 @@ public class ExamResultService {
     }
 
     private QuestionResult getQuestionResult(Question question,
-                                             Map<Integer, QuestionInfo> questionMap,
-                                             Map<Integer, PaperAnswer> answerMap) {
-        int questionId = question.getId();
+                                             Map<Long, QuestionInfo> questionMap,
+                                             Map<Long, PaperAnswer> answerMap) {
+        long questionId = question.getQuestionId();
         List<QuestionOption> questionOptions = questionOptionMapper.findByQuestionId(questionId);
         List<QuestionOption> correctOptions = questionOptions.stream()
                 .filter(QuestionOption::getCorrect)

+ 16 - 9
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/service/ExamService.java

@@ -36,25 +36,25 @@ public class ExamService {
     public int submitExamPaper(UserResult userResult) {
         int paperId = userResult.getPaperId();
         List<PaperQuestion> paperQuestions = paperQuestionMapper.findByPaperId(paperId);
-        Map<Integer, PaperQuestion> paperQuestionsMap = paperQuestions.stream()
+        Map<Long, PaperQuestion> paperQuestionsMap = paperQuestions.stream()
                 .collect(Collectors.toMap(PaperQuestion::getQuestionId, k -> k));
 
-        Map<Integer, Integer> scoreMap = paperQuestions.stream()
+        Map<Long, Integer> scoreMap = paperQuestions.stream()
                 .collect(Collectors.toMap(PaperQuestion::getQuestionId, PaperQuestion::getScore));
 
         // pid -> List<UserAnswer>
-        Map<Integer, List<UserAnswer>> group = userResult.getUserAnswers().stream()
+        Map<Long, List<UserAnswer>> group = userResult.getUserAnswers().stream()
                 .collect(Collectors.groupingBy(UserAnswer::getPid));
         List<PaperAnswer> paperAnswers = new ArrayList<>();
-        for (Map.Entry<Integer, List<UserAnswer>> entry : group.entrySet()) {
-            int pid = entry.getKey();
+        for (Map.Entry<Long, List<UserAnswer>> entry : group.entrySet()) {
+            long pid = entry.getKey();
             List<UserAnswer> answers = entry.getValue();
             if (pid == 0) {
                 List<PaperAnswer> list1 = calculateScore(answers, scoreMap);
                 paperAnswers.addAll(list1);
             } else {
                 List<PaperQuestion> list = paperQuestionMapper.findByPaperIdAndPid(paperId, pid);
-                Map<Integer, Integer> scoreMap1 = list.stream()
+                Map<Long, Integer> scoreMap1 = list.stream()
                         .collect(Collectors.toMap(PaperQuestion::getQuestionId, PaperQuestion::getScore));
                 List<PaperAnswer> list2 = calculateScore(answers, scoreMap1);
                 paperAnswers.addAll(list2);
@@ -80,14 +80,21 @@ public class ExamService {
         return resultId;
     }
 
-    private List<PaperAnswer> calculateScore(List<UserAnswer> userAnswers, Map<Integer, Integer> scoreMap) {
+    /**
+     * 对客观题进行算分
+     *
+     * @param
+     * @return
+     * @date 2025-08-06 10:18:57
+     */
+    private List<PaperAnswer> calculateScore(List<UserAnswer> userAnswers, Map<Long, Integer> scoreMap) {
         List<PaperAnswer> list = new ArrayList<>();
         for (UserAnswer userAnswer : userAnswers) {
             PaperAnswer paperAnswer = new PaperAnswer(userAnswer);
 
-            int questionId = userAnswer.getQuestionId();
+            long questionId = userAnswer.getQuestionId();
             String submitAnswer = userAnswer.getAnswer();
-            Question question = questionMapper.findById(questionId);
+            Question question = questionMapper.findByQuestionId(questionId);
             List<QuestionOption> correctOptions = questionOptionMapper.findByQuestionId(questionId).stream()
                     .filter(QuestionOption::getCorrect)
                     .collect(Collectors.toList());

+ 7 - 7
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/service/PaperService.java

@@ -58,7 +58,7 @@ public class PaperService {
                         return null;
                     }
 
-                    int questionId = paperQuestion.getQuestionId();
+                    long questionId = paperQuestion.getQuestionId();
                     paperQuestion.getChildren().forEach(paperQuestion1 -> {
                         paperQuestion1.setPaperId(paperId);
                         paperQuestion1.setPid(questionId);
@@ -91,12 +91,12 @@ public class PaperService {
     public List<QuestionInfo> getPaperQuestions(int paperId) {
         List<PaperQuestion> questions = paperQuestionMapper.findByPaperId(paperId);
         // questionId -> pos
-        Map<Integer, PaperQuestion> questionMap = questions.stream()
+        Map<Long, PaperQuestion> questionMap = questions.stream()
                 .collect(Collectors.toMap(PaperQuestion::getQuestionId, k -> k));
         List<Question> list1 = questionMapper.findByQuestionIds(new ArrayList<>(questionMap.keySet()));
         return list1.stream().map(question -> {
             QuestionInfo questionInfo = getQuestionInfo(question, questionMap);
-            int questionId = question.getId();
+            long questionId = question.getQuestionId();
             boolean child = question.getChild();
             if (child) {
                 List<QuestionInfo> children = getGroupQuestion(paperId, questionId);
@@ -106,9 +106,9 @@ public class PaperService {
         }).sorted(Comparator.comparingInt(QuestionInfo::getPos)).collect(Collectors.toList());
     }
 
-    private List<QuestionInfo> getGroupQuestion(int paperId, int pid) {
+    private List<QuestionInfo> getGroupQuestion(int paperId, long pid) {
         List<Question> questions = questionMapper.findByPid(pid);
-        Map<Integer, PaperQuestion> questionMap = paperQuestionMapper.findByPaperIdAndPid(paperId, pid).stream()
+        Map<Long, PaperQuestion> questionMap = paperQuestionMapper.findByPaperIdAndPid(paperId, pid).stream()
                 .collect(Collectors.toMap(PaperQuestion::getQuestionId, k -> k));
 
         return questions.stream()
@@ -116,8 +116,8 @@ public class PaperService {
                 .collect(Collectors.toList());
     }
 
-    private QuestionInfo getQuestionInfo(Question question, Map<Integer, PaperQuestion> questionMap) {
-        int questionId = question.getId();
+    private QuestionInfo getQuestionInfo(Question question, Map<Long, PaperQuestion> questionMap) {
+        long questionId = question.getQuestionId();
         int pos = questionMap.get(questionId).getPos();
         int score = questionMap.get(questionId).getScore();
 

+ 19 - 22
content/content-service/src/main/java/cn/reghao/tnb/content/app/exam/service/QuestionService.java

@@ -4,6 +4,7 @@ import cn.reghao.jutil.jdk.converter.DateTimeConverter;
 import cn.reghao.jutil.jdk.db.Page;
 import cn.reghao.jutil.jdk.db.PageList;
 import cn.reghao.jutil.jdk.result.Result;
+import cn.reghao.jutil.tool.id.SnowFlake;
 import cn.reghao.tnb.common.auth.UserContext;
 import cn.reghao.tnb.common.db.KeyValue;
 import cn.reghao.tnb.content.app.exam.db.mapper.QuestionMapper;
@@ -35,68 +36,64 @@ public class QuestionService {
     private final QuestionMapper questionMapper;
     private final QuestionOptionMapper questionOptionMapper;
     private final SubjectMapper subjectMapper;
+    private SnowFlake idGenerator;
 
     public QuestionService(QuestionMapper questionMapper, QuestionOptionMapper questionOptionMapper,
                            SubjectMapper subjectMapper) {
         this.questionMapper = questionMapper;
         this.questionOptionMapper = questionOptionMapper;
         this.subjectMapper = subjectMapper;
+        this.idGenerator = new SnowFlake(1L, 1L);
     }
 
     public Result addQuestion(QuestionAddDto questionAddDto) {
+        long questionId = idGenerator.nextId();
         int type = questionAddDto.getQuestionType();
         if (type == QuestionType.QUESTION8.getCode()) {
-            Question question = new Question(questionAddDto, true);
+            Question question = new Question(questionId, questionAddDto, true);
             questionMapper.save(question);
-            int questionId = question.getId();
-            int subjectId = question.getSubjectId();
 
+            int subjectId = question.getSubjectId();
             Arrays.stream(questionAddDto.getChildren()).forEach(questionAddDto1 -> {
-                Question question1 = new Question(questionAddDto1);
+                long questionId1 = idGenerator.nextId();
+                Question question1 = new Question(questionId1, questionAddDto1);
                 question1.setPid(questionId);
                 question1.setSubjectId(subjectId);
                 List<QuestionOption> options1 = getQuestionOptions(questionAddDto1);
                 save(question1, options1);
             });
         } else {
-            Question question = new Question(questionAddDto);
+            Question question = new Question(questionId, questionAddDto);
             List<QuestionOption> options = getQuestionOptions(questionAddDto);
             save(question, options);
         }
 
         if (type == QuestionType.QUESTION1.getCode()) {
-
         } else if (type == QuestionType.QUESTION2.getCode()) {
-
         } else if (type == QuestionType.QUESTION3.getCode()) {
-
         } else if (type == QuestionType.QUESTION4.getCode()) {
-
         } else if (type == QuestionType.QUESTION5.getCode()) {
-
         } else if (type == QuestionType.QUESTION6.getCode()) {
-
         } else if (type == QuestionType.QUESTION7.getCode()) {
-
         } else {
         }
 
         return Result.success();
     }
 
-    public Result deleteQuestion(int questionId) {
-        Question question = questionMapper.findById(questionId);
+    public Result deleteQuestion(long questionId) {
+        Question question = questionMapper.findByQuestionId(questionId);
         if (question.getChild()) {
             List<Question> children = questionMapper.findByPid(questionId);
             children.forEach(question1 -> {
-                int questionId1 = question1.getId();
+                long questionId1 = question1.getQuestionId();
                 questionOptionMapper.deleteByQuestionId(questionId1);
-                questionMapper.deleteById(questionId1);
+                questionMapper.deleteByQuestionId(questionId1);
             });
         }
 
         questionOptionMapper.deleteByQuestionId(questionId);
-        questionMapper.deleteById(questionId);
+        questionMapper.deleteByQuestionId(questionId);
         return Result.success();
     }
 
@@ -114,7 +111,7 @@ public class QuestionService {
 
     private void save(Question question, List<QuestionOption> options) {
         questionMapper.save(question);
-        int questionId = question.getId();
+        long questionId = question.getQuestionId();
         options.forEach(questionOption -> questionOption.setQuestionId(questionId));
         if (!options.isEmpty()) {
             questionOptionMapper.saveAll(options);
@@ -130,7 +127,7 @@ public class QuestionService {
     }
 
     private QuestionView getQuestionView(Question question) {
-        int questionId = question.getId();
+        long questionId = question.getQuestionId();
         int subjectId = question.getSubjectId();
         Subject subject = subjectMapper.findById(subjectId);
         int type = question.getType();
@@ -143,8 +140,8 @@ public class QuestionService {
         return new QuestionView(questionId, subject.getName(), typeStr, type, levelStr, question.getContent(), createBy, createAt);
     }
 
-    public QuestionDetail getQuestionDetail(int questionId) {
-        Question question = questionMapper.findById(questionId);
+    public QuestionDetail getQuestionDetail(long questionId) {
+        Question question = questionMapper.findByQuestionId(questionId);
         List<QuestionOptionDetail> options = questionOptionMapper.findByQuestionId(questionId).stream()
                 .map(QuestionOptionDetail::new)
                 .collect(Collectors.toList());
@@ -158,7 +155,7 @@ public class QuestionService {
         QuestionDetail questionDetail = new QuestionDetail(question, subject.getName(), typeStr, levelStr, options);
         if (type == QuestionType.QUESTION8.getCode()) {
             List<QuestionDetail> list1 = questionMapper.findByPid(questionId).stream().map(question1 -> {
-                int questionId1 = question1.getId();
+                long questionId1 = question1.getQuestionId();
                 int type1 = question1.getType();
                 String typeStr1 = QuestionType.getDescByCode(type1);
                 int level1 = question1.getLevel();

+ 2 - 2
content/content-service/src/main/resources/mapper/exam/PaperMapper.xml

@@ -4,9 +4,9 @@
 <mapper namespace="cn.reghao.tnb.content.app.exam.db.mapper.PaperMapper">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
         insert into exam_paper
-        (`subject_id`,`name`,`description`,`duration`,`total_score`,`pass_score`,`start_time`,`end_time`,`passcode`,`status`,`create_at`,`create_by`)
+        (`subject_id`,`name`,`description`,`duration`,`total_score`,`pass_score`,`start_time`,`end_time`,`passcode`,`status`,`has_subjective`,`create_at`,`create_by`)
         values 
-        (#{subjectId},#{name},#{description},#{duration},#{totalScore},#{passScore},#{endTime},#{startTime},#{passcode},#{status},#{createAt},#{createBy})
+        (#{subjectId},#{name},#{description},#{duration},#{totalScore},#{passScore},#{endTime},#{startTime},#{passcode},#{status},#{hasSubjective},#{createAt},#{createBy})
     </insert>
 
     <delete id="deleteById">

+ 19 - 6
content/content-service/src/main/resources/mapper/exam/QuestionMapper.xml

@@ -4,14 +4,22 @@
 <mapper namespace="cn.reghao.tnb.content.app.exam.db.mapper.QuestionMapper">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
         insert into exam_question
-        (`subject_id`,`type`,`level`,`content`,`analysis`,`create_by`,`pid`,`child`,`pos`,`extra`)
+        (`subject_id`,`question_id`,`type`,`level`,`content`,`analysis`,`create_by`,`pid`,`child`,`pos`,`extra`)
         values 
-        (#{subjectId},#{type},#{level},#{content},#{analysis},#{createBy},#{pid},#{child},#{pos},#{extra})
+        (#{subjectId},#{questionId},#{type},#{level},#{content},#{analysis},#{createBy},#{pid},#{child},#{pos},#{extra})
+    </insert>
+    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
+        insert into exam_question
+        (`subject_id`,`question_id`,`type`,`level`,`content`,`analysis`,`create_by`,`pid`,`child`,`pos`,`extra`)
+        values
+        <foreach collection="list" item="item" index="index" separator=",">
+            (#{item.subjectId},#{item.questionId},#{item.type},#{item.level},#{item.content},#{item.analysis},#{item.createBy},#{item.pid},#{item.child},#{item.pos},#{item.extra})
+        </foreach>
     </insert>
 
-    <delete id="deleteById">
+    <delete id="deleteByQuestionId">
         delete from exam_question
-        where id=#{id}
+        where question_id=#{questionId}
     </delete>
 
     <select id="findAll" resultType="cn.reghao.tnb.content.app.exam.model.po.Question">
@@ -22,13 +30,18 @@
     <select id="findById" resultType="cn.reghao.tnb.content.app.exam.model.po.Question">
         select *
         from exam_question
-        where id=#{id}
+        where question_id=#{id}
     </select>
     <select id="findBySubjectId" resultType="cn.reghao.tnb.content.app.exam.model.po.Question">
         select *
         from exam_question
         where subject_id=#{subjectId}
     </select>
+    <select id="findByQuestionId" resultType="cn.reghao.tnb.content.app.exam.model.po.Question">
+        select *
+        from exam_question
+        where question_id=#{questionId}
+    </select>
     <select id="findByPid" resultType="cn.reghao.tnb.content.app.exam.model.po.Question">
         select *
         from exam_question
@@ -37,7 +50,7 @@
     <select id="findByQuestionIds" resultType="cn.reghao.tnb.content.app.exam.model.po.Question">
         select *
         from exam_question
-        where id in
+        where question_id in
         <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
             #{id}
         </foreach>

+ 264 - 0
content/content-service/src/test/java/cn/reghao/tnb/content/app/exam/service/ExamTest.java

@@ -0,0 +1,264 @@
+package cn.reghao.tnb.content.app.exam.service;
+
+import cn.reghao.jutil.jdk.serializer.JsonConverter;
+import cn.reghao.jutil.jdk.text.TextFile;
+import cn.reghao.jutil.tool.id.SnowFlake;
+import cn.reghao.tnb.content.app.ContentApplication;
+import cn.reghao.tnb.content.app.exam.db.mapper.*;
+import cn.reghao.tnb.content.app.exam.model.constant.QuestionType;
+import cn.reghao.tnb.content.app.exam.model.dto.PaperAddDto;
+import cn.reghao.tnb.content.app.exam.model.po.Paper;
+import cn.reghao.tnb.content.app.exam.model.po.PaperQuestion;
+import cn.reghao.tnb.content.app.exam.model.po.Question;
+import cn.reghao.tnb.content.app.exam.model.po.QuestionOption;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+
+import java.io.File;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * @author reghao
+ * @date 2025-08-05 21:28:11
+ */
+@ActiveProfiles("dev")
+@SpringBootTest(classes = ContentApplication.class)
+public class ExamTest {
+    @Autowired
+    QuestionMapper questionMapper;
+    @Autowired
+    QuestionOptionMapper questionOptionMapper;
+    @Autowired
+    PaperMapper paperMapper;
+    @Autowired
+    PaperQuestionMapper paperQuestionMapper;
+    @Autowired
+    PaperAnswerMapper paperAnswerMapper;
+
+    @Test
+    public void questionTest() {
+        int questionType = QuestionType.QUESTION1.getCode();
+        long questionId = 1;
+        String content = "";
+        String extra = "";
+        Question question = new Question(questionId, content, questionType, extra);
+
+        String content1 = "";
+        int pos = 1;
+        boolean correct = true;
+        QuestionOption questionOption = new QuestionOption(questionId, content1, pos, correct);
+    }
+
+    SnowFlake idGenerator = new SnowFlake(1L, 1L);
+    @Test
+    public void setQuestion8Test() {
+        int questionType = QuestionType.QUESTION8.getCode();
+        long questionId = idGenerator.nextId();
+        String content = "阅读下面的文字,完成1—3题。   \n" +
+                "\n" +
+                "随着中国考古学的飞速发展,考古资料得以大量积累,考古学文化时空框架体系基本建立,多学科合作日益深入,各种专题研究广泛展开。“考古写史”在中国已经取得巨大成就,获得诸多具有突破性和填补空白意义的成绩,中国考古学证明了自身的价值,尤其是在上古史构建方面展现了广阔前景。从考古发现来看,考古学提供了传统历史学不可想象的新发现、新材料,呈现出不同时期的古代物质文化面貌、古人日常生产生活状态以及各地的文明化进程等,如不同区域新石器时代晚期大型聚落遗址、大型公共建筑、大型墓葬、水利设施、手工业作坊,以及象征王权、神权、军权和复杂礼制出现的精美玉器、陶器、漆器、象牙器等。   \n" +
+                "\n" +
+                "从考古发现来看,考古学提供了传统历史学不可想象的新发现、新材科,呈现出不同时期的古代物质文化面貌、古人日常生产生活状态以及各地的文明化进程等,如不同区域新石器时代晚期大型聚落遗址、大型公共建筑、大型墓葬、水利设施、手工业作坊,以及象征王权、神权、军权和复杂礼制出现的精美玉器、陶器、漆器、象牙器等。   \n" +
+                "\n" +
+                "从重构上古史体系角度看,20 世纪70—80年代,夏鼐、苏秉琦等系统地构建了新石器与夏商周三代时期的考古学文化区系类型时空框架体系。苏秉琦在新石器时代考古学文化区系类型基础上提出“满天星斗”“多元一体”和“古国一方国帝国”等关于中国上古史的历史叙述体系。严文明提出“重瓣花朵”模式,在承认多区域文化共存的文化多元性的同时,强调中原文化区“联系各文化区的核心作用”。张光直认为各地区文化多元发展并通过彼此之间的密切交流而形成一个“中国相互作用圈”。   \n" +
+                "\n" +
+                "从二里头文化、二里岗文化到殷墟考古学文化、周代考古学文化,考古学不仅展现了不同于传统文献记载的这一时期文化、科技、礼制等众多方面从发展到成熟的历史脉络,而且填补了诸多传统历史学的空白,如四川的三星堆一金沙文化、江西的吴城文化、两周时期的曾国与中山国历史,等等。   \n" +
+                "\n" +
+                "这些成果证明考古学完全有能力把当重写中国上古史的重任,并且已经初步形成具有自身特色的上古史叙述与解释体系,超越了传统的具有传说性质的三皇五帝体系和存在争议的夏商周三代古史体系,正如习近平总书记所说:“经过几代考古人接续奋斗,我国考古工作取得了重大成就,延伸了历史轴线,增强了历史信度,丰富了历史内涵,活化了历史场景。”   \n" +
+                "\n" +
+                "学界一直存在着“证经补史”的传统史学思路,试图将考古学文化体系纳入三皇五帝的古史框架体系之中,似乎中国考古学如果没有发现并证明三皇五帝与夏商周,就没有价值和意义,但研究实践告诉我们:这种传统治史思路影响了中国考古学的视野和思维方式,限制了考古学在重构中国上古史中的作用。比如,考古发现与研究显示,二里头遗址和二里头文化在东亚地区的文明形成与发展中占据了关键性地位,奠定了中国独特的礼乐文化传统的基础,在人类文明史上具有世界性的标志意义,尽管二里头遗址是否就是文献记载中的夏都所在地,在学术界仍有争议。我们对二里头遗址与二里头文化应该开展扎实的田野工作并展开全方位的考古学研究与阐释,而不是将主要目标集中于它是否是文献记载中的“夏”,并为此争论不休。\n" +
+                "\n" +
+                "(摘编自徐良高《以考古学构建中国上古史》)";
+        String extra = "";
+        Question question = new Question(questionId, content, questionType, extra);
+        questionMapper.save(question);
+
+        TextFile textFile = new TextFile();
+        String filePath = "/home/reghao/Downloads/8.txt";
+        List<String> list = textFile.read(filePath);
+
+        Map<String, List<String>> map = new HashMap<>();
+        List<String> lines = new ArrayList<>();
+        for (String line : list) {
+            if (line.isBlank()) {
+                map.put(lines.get(0), lines);
+                lines = new ArrayList<>();
+            } else {
+                lines.add(line);
+            }
+        }
+        map.put(lines.get(0), lines);
+
+        for (Map.Entry<String, List<String>> entry : map.entrySet()) {
+            String key = entry.getKey();
+            List<String> valList = entry.getValue();
+
+            int questionType1 = QuestionType.QUESTION1.getCode();
+            long pid = question.getQuestionId();
+            long questionId1 = idGenerator.nextId();
+            String content1 = key;
+            String extra1 = "";
+            Question question1 = new Question(questionId1, content1, questionType1, extra1);
+            question1.setPid(pid);
+            List<QuestionOption> questionOptionList1 = new ArrayList<>();
+
+            for (int i = 1; i < valList.size(); i++) {
+                String optionContent2 = valList.get(i);
+                boolean correct2 = i == valList.size()-1;
+                QuestionOption questionOption2 = new QuestionOption(questionId1, optionContent2, i, correct2);
+                questionOptionList1.add(questionOption2);
+            }
+
+            question1.setQuestionOptions(questionOptionList1);
+            questionMapper.save(question1);
+            questionOptionMapper.saveAll(questionOptionList1);
+        }
+    }
+
+    @Test
+    public void setQuestion5Test() {
+        TextFile textFile = new TextFile();
+        String filePath = "/home/reghao/Downloads/5.txt";
+        List<String> list = textFile.read(filePath);
+
+        Map<String, List<String>> map = new HashMap<>();
+        List<String> lines = new ArrayList<>();
+        for (String line : list) {
+            if (line.startsWith("######################")) {
+                map.put(lines.get(0), lines);
+                lines = new ArrayList<>();
+            } else {
+                lines.add(line);
+            }
+        }
+        map.put(lines.get(0), lines);
+
+        map.values().forEach(strList -> {
+            StringBuilder sb = new StringBuilder();
+            for (String str : strList) {
+                sb.append(str).append(System.lineSeparator());
+            }
+            String content = sb.toString();
+
+            int questionType = QuestionType.QUESTION5.getCode();
+            long questionId = idGenerator.nextId();
+            String extra = "";
+            Question question = new Question(questionId, content, questionType, extra);
+
+            List<String> valList = List.of("233");
+            List<QuestionOption> questionOptionList1 = new ArrayList<>();
+            for (int i = 0; i < valList.size(); i++) {
+                String optionContent2 = valList.get(i);
+                int pos = i+1;
+                boolean correct2 = i == valList.size()-1;
+                QuestionOption questionOption2 = new QuestionOption(questionId, optionContent2, pos, correct2);
+                questionOptionList1.add(questionOption2);
+            }
+
+            questionMapper.save(question);
+            questionOptionMapper.saveAll(questionOptionList1);
+        });
+    }
+
+    @Test
+    public void parseQuestionTest() {
+        String filePath = "/home/reghao/Downloads/xxqg.json";
+        JsonObject jsonObject = JsonConverter.jsonFileToObject(new File(filePath), JsonObject.class);
+        List<AhaQuestion> questionList = new ArrayList<>();
+        jsonObject.entrySet().forEach(entry -> {
+            AhaQuestion question1 = new AhaQuestion();
+            JsonElement jsonElement = entry.getValue();
+            String correctAnswer = jsonElement.getAsString();
+            question1.setCorrectAnswer(correctAnswer);
+
+            String key = entry.getKey();
+            String[] arr = key.split("\\|");
+            for (int i = 1; i < arr.length; i++) {
+                question1.getAnswers().add(arr[i]);
+            }
+
+            String question = arr[0];
+            if (question.contains("来源:")) {
+                String[] arr1 = question.split("来源:");
+                question1.setTitle(arr1[0]);
+                question1.setSource("来源:" + arr1[1]);
+            } else {
+                question1.setTitle(question);
+            }
+            questionList.add(question1);
+        });
+
+        for (int i = 0; i < questionList.size(); i++) {
+            AhaQuestion ahaQuestion = questionList.get(i);
+            long questionId = idGenerator.nextId();
+            String content = ahaQuestion.getTitle();
+            String extra = ahaQuestion.getSource();
+            String correctAnswer = ahaQuestion.getCorrectAnswer();
+
+            int questionType = QuestionType.QUESTION1.getCode();
+            int size = ahaQuestion.getAnswers().size();
+            if (size == 2 && (correctAnswer.equals("正确") || correctAnswer.equals("错误"))) {
+                questionType = QuestionType.QUESTION4.getCode();
+            }
+
+            Question question = new Question(questionId, content, questionType, extra);
+            List<String> answers = ahaQuestion.getAnswers();
+            List<QuestionOption> questionOptionList = new ArrayList<>();
+            for (int j = 0; j < answers.size(); j++) {
+                String answer = answers.get(j);
+                boolean correct = answer.equalsIgnoreCase(correctAnswer);
+                int pos = j+1;
+
+                QuestionOption questionOption = new QuestionOption(questionId, answer, pos, correct);
+                questionOptionList.add(questionOption);
+            }
+            question.setQuestionOptions(questionOptionList);
+
+            questionMapper.save(question);
+            questionOptionMapper.saveAll(questionOptionList);
+        }
+    }
+
+    @NoArgsConstructor
+    @Setter
+    @Getter
+    class AhaQuestion {
+        private String title;
+        private List<String> answers = new ArrayList<>();
+        private String correctAnswer;
+        private String source;
+    }
+
+    @Test
+    public void paperTest() {
+        int paperId = 3;
+        Paper paper = paperMapper.findByPaperId(paperId);
+        List<PaperQuestion> paperQuestionList = paperQuestionMapper.findByPaperId(paperId);
+        paperQuestionList.forEach(paperQuestion -> {
+            long questionId = paperQuestion.getQuestionId();
+            List<Question> questionList = questionMapper.findByQuestionIds(List.of(questionId));
+            Question question = questionList.get(0);
+            int questionType = question.getType();
+        });
+
+        PaperAddDto paperAddDto = new PaperAddDto();
+    }
+
+    private void getPaper(PaperAddDto paperAddDto) {
+        List<Long> questionIdList = paperAddDto.getQuestions().stream()
+                .map(PaperQuestion::getQuestionId)
+                .collect(Collectors.toList());
+        List<Question> questionList = questionMapper.findByQuestionIds(questionIdList);
+        List<Question> list = questionList.stream().map(question -> {
+            return question;
+        }).filter(Objects::nonNull).collect(Collectors.toList());
+    }
+}

+ 0 - 105
content/content-service/src/test/java/cn/reghao/tnb/content/app/vod/service/ExamTest.java

@@ -1,105 +0,0 @@
-package cn.reghao.tnb.content.app.vod.service;
-
-import cn.reghao.jutil.jdk.serializer.JsonConverter;
-import cn.reghao.tnb.content.app.ContentApplication;
-import cn.reghao.tnb.content.app.exam.db.mapper.QuestionMapper;
-import cn.reghao.tnb.content.app.exam.db.mapper.QuestionOptionMapper;
-import cn.reghao.tnb.content.app.exam.model.constant.QuestionType;
-import cn.reghao.tnb.content.app.exam.model.po.Question;
-import cn.reghao.tnb.content.app.exam.model.po.QuestionOption;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.ActiveProfiles;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author reghao
- * @date 2025-08-05 21:28:11
- */
-@ActiveProfiles("dev")
-@SpringBootTest(classes = ContentApplication.class)
-public class ExamTest {
-    @Autowired
-    QuestionMapper questionMapper;
-    @Autowired
-    QuestionOptionMapper questionOptionMapper;
-
-    @Test
-    public void questionTest() {
-        String filePath = "/home/reghao/Downloads/xxqg.json";
-        JsonObject jsonObject = JsonConverter.jsonFileToObject(new File(filePath), JsonObject.class);
-        List<AhaQuestion> questionList = new ArrayList<>();
-        jsonObject.entrySet().forEach(entry -> {
-            AhaQuestion question1 = new AhaQuestion();
-            JsonElement jsonElement = entry.getValue();
-            String correctAnswer = jsonElement.getAsString();
-            question1.setCorrectAnswer(correctAnswer);
-
-            String key = entry.getKey();
-            String[] arr = key.split("\\|");
-            for (int i = 1; i < arr.length; i++) {
-                question1.getAnswers().add(arr[i]);
-            }
-
-            String question = arr[0];
-            if (question.contains("来源:")) {
-                String[] arr1 = question.split("来源:");
-                question1.setTitle(arr1[0]);
-                question1.setSource("来源:" + arr1[1]);
-            } else {
-                question1.setTitle(question);
-            }
-            questionList.add(question1);
-        });
-
-        List<Question> list = new ArrayList<>();
-        for (int i = 0; i < questionList.size(); i++) {
-            AhaQuestion ahaQuestion = questionList.get(i);
-            int questionId = i+1;
-            String content = ahaQuestion.getTitle();
-            String extra = ahaQuestion.getSource();
-            String correctAnswer = ahaQuestion.getCorrectAnswer();
-
-            int questionType = QuestionType.QUESTION1.getCode();
-            int size = ahaQuestion.getAnswers().size();
-            if (size == 2 && (correctAnswer.equals("正确") || correctAnswer.equals("错误"))) {
-                questionType = QuestionType.QUESTION4.getCode();
-            }
-
-            Question question = new Question(questionId, content, questionType, extra);
-            List<String> answers = ahaQuestion.getAnswers();
-            List<QuestionOption> questionOptionList = new ArrayList<>();
-            for (int j = 0; j < answers.size(); j++) {
-                String answer = answers.get(j);
-                boolean correct = answer.equalsIgnoreCase(correctAnswer);
-                int pos = j+1;
-
-                QuestionOption questionOption = new QuestionOption(questionId, answer, pos, correct);
-                questionOptionList.add(questionOption);
-            }
-            question.setQuestionOptions(questionOptionList);
-            
-            questionMapper.save(question);
-            questionOptionMapper.saveAll(questionOptionList);
-        }
-    }
-
-    @NoArgsConstructor
-    @Setter
-    @Getter
-    class AhaQuestion {
-        private String title;
-        private List<String> answers = new ArrayList<>();
-        private String correctAnswer;
-        private String source;
-    }
-}