|
|
@ -2,6 +2,8 @@ package com.project.appeal.domain.service.Impl; |
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
import cn.hutool.core.util.StrUtil; |
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
|
import cn.hutool.json.JSONArray; |
|
|
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
@ -130,24 +132,7 @@ public class SearchAppealDomainServiceImpl implements SearchAppealDomainService |
|
|
appealDTO.setKpIdList(questionEntity.getKpIdList()); |
|
|
appealDTO.setKpIdList(questionEntity.getKpIdList()); |
|
|
kpIdSet.addAll(questionEntity.getKpIdList()); |
|
|
kpIdSet.addAll(questionEntity.getKpIdList()); |
|
|
|
|
|
|
|
|
//构建参考答案
|
|
|
appealDTO.setRightAnswer(buildRightAnswer(questionDetail)); |
|
|
String rightAnswer = questionDetail.getRightAnswer(); |
|
|
|
|
|
List<String> rightAnswerList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
if (StrUtil.isNotBlank(rightAnswer)) { |
|
|
|
|
|
rightAnswerList = rightAnswer.contains(",") |
|
|
|
|
|
? new ArrayList<>(Arrays.asList(rightAnswer.split(","))) |
|
|
|
|
|
: rightAnswer.chars().mapToObj(c -> String.valueOf((char) c)).collect(Collectors.toCollection(ArrayList::new)); |
|
|
|
|
|
} |
|
|
|
|
|
// 按 ABCD 顺序提取完整答案
|
|
|
|
|
|
Map<String, String> options = questionDetail.getOptions(); |
|
|
|
|
|
List<String> optionOrder = new ArrayList<>(Arrays.asList("A", "B", "C", "D")); |
|
|
|
|
|
final List<String> finalRightAnswerList = rightAnswerList; |
|
|
|
|
|
String fullRightAnswer = optionOrder.stream() |
|
|
|
|
|
.filter(finalRightAnswerList::contains) |
|
|
|
|
|
.map(opt -> opt + "." + options.get(opt)).filter(StrUtil::isNotBlank) |
|
|
|
|
|
.collect(Collectors.joining(",")); |
|
|
|
|
|
appealDTO.setRightAnswer(fullRightAnswer); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
@ -181,4 +166,59 @@ public class SearchAppealDomainServiceImpl implements SearchAppealDomainService |
|
|
|
|
|
|
|
|
return appealDTOList; |
|
|
return appealDTOList; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 构建参考答案 |
|
|
|
|
|
*/ |
|
|
|
|
|
private String buildRightAnswer(QuestionEntity.QuestionDetail questionDetail) { |
|
|
|
|
|
if (QuestionTypeEnum.SHORT_ANSWER.getValue().equals(questionDetail.getType())) { |
|
|
|
|
|
// 简答题:拼接得分点
|
|
|
|
|
|
List<QuestionEntity.ScoringPoint> scoringPoints = questionDetail.getScoringPoints(); |
|
|
|
|
|
if (scoringPoints != null && !scoringPoints.isEmpty()) { |
|
|
|
|
|
return scoringPoints.stream() |
|
|
|
|
|
.map(sp -> { |
|
|
|
|
|
String formatted = formatScoringPointContent(sp.getContent()); |
|
|
|
|
|
return sp.getIndex() + ":" + formatted; |
|
|
|
|
|
}) |
|
|
|
|
|
.collect(Collectors.joining("。")); |
|
|
|
|
|
} |
|
|
|
|
|
return ""; |
|
|
|
|
|
} |
|
|
|
|
|
// 客观题:按 ABCD 顺序提取完整答案
|
|
|
|
|
|
String rightAnswer = questionDetail.getRightAnswer(); |
|
|
|
|
|
List<String> rightAnswerList = new ArrayList<>(); |
|
|
|
|
|
if (StrUtil.isNotBlank(rightAnswer)) { |
|
|
|
|
|
rightAnswerList = rightAnswer.contains(",") |
|
|
|
|
|
? new ArrayList<>(Arrays.asList(rightAnswer.split(","))) |
|
|
|
|
|
: rightAnswer.chars().mapToObj(c -> String.valueOf((char) c)).collect(Collectors.toCollection(ArrayList::new)); |
|
|
|
|
|
} |
|
|
|
|
|
Map<String, String> options = questionDetail.getOptions(); |
|
|
|
|
|
List<String> optionOrder = new ArrayList<>(Arrays.asList("A", "B", "C", "D")); |
|
|
|
|
|
final List<String> finalRightAnswerList = rightAnswerList; |
|
|
|
|
|
return optionOrder.stream() |
|
|
|
|
|
.filter(finalRightAnswerList::contains) |
|
|
|
|
|
.map(opt -> opt + "." + options.get(opt)).filter(StrUtil::isNotBlank) |
|
|
|
|
|
.collect(Collectors.joining(",")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 格式化得分点内容:解析JSON中的example和keywords字段 |
|
|
|
|
|
* 格式:【标准答案】example\n【关键词】keyword1, keyword2 |
|
|
|
|
|
*/ |
|
|
|
|
|
private String formatScoringPointContent(String content) { |
|
|
|
|
|
if (StrUtil.isBlank(content)) { |
|
|
|
|
|
return content; |
|
|
|
|
|
} |
|
|
|
|
|
try { |
|
|
|
|
|
cn.hutool.json.JSONObject json = JSONUtil.parseObj(content); |
|
|
|
|
|
String example = json.getStr("example"); |
|
|
|
|
|
JSONArray keywords = json.getJSONArray("keywords"); |
|
|
|
|
|
if (StrUtil.isNotBlank(example) && keywords != null && !keywords.isEmpty()) { |
|
|
|
|
|
String keywordsStr = StrUtil.join(", ", keywords.toArray()); |
|
|
|
|
|
return StrUtil.format("【标准答案】{}\n【关键词】{}", example, keywordsStr); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception ignored) { |
|
|
|
|
|
} |
|
|
|
|
|
return content; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|