Browse Source

bug修复

master
luogw 2 months ago
parent
commit
0e7af3c010
  1. 23
      src/main/java/com/project/classicpaper/application/impl/ClassicCategoryApplicationServiceImpl.java
  2. 19
      src/main/java/com/project/classicpaper/domain/service/impl/ImportClassicPaperDomainServiceImpl.java

23
src/main/java/com/project/classicpaper/application/impl/ClassicCategoryApplicationServiceImpl.java

@ -72,32 +72,29 @@ public class ClassicCategoryApplicationServiceImpl implements ClassicCategoryApp
/**
* 按名称排序规则
* - 中文 按拼音首字母使用 java Collator
* - 英文 按字母顺序
* - 其他 ID
* - 中文/英文 混合按拼音/字母序权重相同
* - 其他数字符号等 ID 排序
*/
private int compareByName(ClassicCategoryDTO a, ClassicCategoryDTO b) {
String nameA = a.getName();
String nameB = b.getName();
int typeA = getCharType(nameA);
int typeB = getCharType(nameB);
if (typeA != typeB) {
return Integer.compare(typeA, typeB);
}
if (typeA == 0) {
boolean aIsNormal = typeA == 0 || typeA == 1;
boolean bIsNormal = typeB == 0 || typeB == 1;
if (aIsNormal && bIsNormal) {
return Collator.getInstance(Locale.CHINESE).compare(
nameA != null ? nameA : "",
nameB != null ? nameB : "");
} else if (typeA == 1) {
String safeA = nameA != null ? nameA : "";
String safeB = nameB != null ? nameB : "";
return safeA.compareToIgnoreCase(safeB);
} else {
}
if (aIsNormal) return -1;
if (bIsNormal) return 1;
return Long.compare(
a.getId() != null ? a.getId() : 0L,
b.getId() != null ? b.getId() : 0L);
}
}
/**
* 判断首字符类型0-中文1-英文2-其他

19
src/main/java/com/project/classicpaper/domain/service/impl/ImportClassicPaperDomainServiceImpl.java

@ -21,6 +21,7 @@ import com.project.question.domain.enums.QuestionSourceTypeEnum;
import com.project.question.domain.service.QuestionBaseService;
import com.project.question.domain.service.SaveQuestionDomainService;
import com.project.task.config.ExamScoreRatioConfig;
import com.project.task.domain.enums.QuestionTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -32,6 +33,7 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -102,9 +104,9 @@ public class ImportClassicPaperDomainServiceImpl implements ImportClassicPaperDo
int singleChoiceNum = 0, multipleChoiceNum = 0, trueFalseNum = 0, shortAnswerNum = 0;
for (WordQuestionParser.ParsedQuestion pq : parsedQuestions) {
switch (pq.getQuestionType()) {
case 0 -> singleChoiceNum++;
case 1 -> multipleChoiceNum++;
case 2 -> trueFalseNum++;
case 1 -> singleChoiceNum++;
case 2 -> multipleChoiceNum++;
case 3 -> trueFalseNum++;
case 4 -> shortAnswerNum++;
}
}
@ -157,9 +159,14 @@ public class ImportClassicPaperDomainServiceImpl implements ImportClassicPaperDo
for (int i = 0; i < parsedQuestions.size(); i++) {
WordQuestionParser.ParsedQuestion parsed = parsedQuestions.get(i);
// 构建选项 Map
// 构建选项 Map(判断题直接构造选项)
Map<String, String> optionsMap = new TreeMap<>();
if (parsed.getOptions() != null) {
String rightAnswer = parsed.getAnswer();
if (Objects.equals(parsed.getQuestionType(), QuestionTypeEnum.TRUE_FALSE.getValue())) {
optionsMap.put("A", "正确");
optionsMap.put("B", "错误");
rightAnswer = "正确".equals(parsed.getAnswer()) ? "A" : "B";
} else if (parsed.getOptions() != null) {
for (WordQuestionParser.ParsedOption opt : parsed.getOptions()) {
optionsMap.put(opt.getLabel(), opt.getContent());
}
@ -175,7 +182,7 @@ public class ImportClassicPaperDomainServiceImpl implements ImportClassicPaperDo
detailDTO.setQuestionContent(parsed.getStem());
detailDTO.setType(parsed.getQuestionType());
detailDTO.setOptions(optionsMap.isEmpty() ? null : optionsMap);
detailDTO.setRightAnswer(parsed.getAnswer());
detailDTO.setRightAnswer(rightAnswer);
detailDTO.setAnalysis(parsed.getAnalysis());
// 简答题得分点

Loading…
Cancel
Save