|
|
|
@ -7,6 +7,9 @@ import com.project.exam.domain.entity.ExamRecordEntity; |
|
|
|
import com.project.exam.domain.service.BuildExamRecordDomainService; |
|
|
|
import com.project.exam.domain.service.NotifyExamRecordDomainService; |
|
|
|
import com.project.exam.domain.service.SubmitPaperDomainService; |
|
|
|
import com.project.exam.domain.service.strategy.ScoringContext; |
|
|
|
import com.project.exam.domain.service.strategy.ScoringStrategy; |
|
|
|
import com.project.exam.domain.service.strategy.ScoringStrategyFactory; |
|
|
|
import com.project.exam.mapper.ExamRecordMapper; |
|
|
|
import com.project.statistics.application.StatisticsApplicationService; |
|
|
|
import com.project.task.domain.dto.TaskDTO; |
|
|
|
@ -48,6 +51,10 @@ public class SubmitPaperDomainServiceImpl implements SubmitPaperDomainService { |
|
|
|
@Autowired |
|
|
|
private StatisticsApplicationService statisticsApplicationService; |
|
|
|
|
|
|
|
// V1.1 新增:判分策略工厂
|
|
|
|
@Autowired |
|
|
|
private ScoringStrategyFactory scoringStrategyFactory; |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public ExamRecordDTO submitPaper(Long recordId) throws Exception { |
|
|
|
@ -59,24 +66,39 @@ public class SubmitPaperDomainServiceImpl implements SubmitPaperDomainService { |
|
|
|
TaskUserEntity taskUser = taskUserMapper.selectById(record.getTaskUserId()); |
|
|
|
TaskEntity task = taskMapper.selectById(taskUser.getTaskId()); |
|
|
|
|
|
|
|
// 判分
|
|
|
|
// V1.1:使用策略模式判分(客观题比对答案 + 简答题调AI)
|
|
|
|
double finalScore = 0.0; |
|
|
|
List<ExamRecordEntity.QuestionSnapshot> snapshotList = record.getAnswerSnapshot(); |
|
|
|
//记录对的题目
|
|
|
|
int rightCount = 0; |
|
|
|
|
|
|
|
// 构建判分上下文
|
|
|
|
ScoringContext scoringContext = new ScoringContext(); |
|
|
|
scoringContext.setTask(task); |
|
|
|
|
|
|
|
for (ExamRecordEntity.QuestionSnapshot snapshot : snapshotList) { |
|
|
|
// 比对答案
|
|
|
|
if (StrUtil.equals(formatAnswer(snapshot.getUserAnswer()) , formatAnswer(snapshot.getRightAnswer()))) { |
|
|
|
snapshot.setIsRight(true); |
|
|
|
// 根据题型获取任务创建时算好的单题分值
|
|
|
|
finalScore += getQuestionWeight(snapshot.getType(), task); |
|
|
|
rightCount ++; |
|
|
|
} else { |
|
|
|
snapshot.setIsRight(false); |
|
|
|
} |
|
|
|
// 设置题目分值到快照(DTO转换用)
|
|
|
|
ExamRecordDTO.QuestionSnapshotDTO tempDto = new ExamRecordDTO.QuestionSnapshotDTO(); |
|
|
|
tempDto.setQuestionId(snapshot.getQuestionId()); |
|
|
|
tempDto.setType(snapshot.getType()); |
|
|
|
tempDto.setQuestionContent(snapshot.getQuestionContent()); |
|
|
|
tempDto.setUserAnswer(snapshot.getUserAnswer()); |
|
|
|
tempDto.setRightAnswer(snapshot.getRightAnswer()); |
|
|
|
tempDto.setScore(getQuestionWeight(snapshot.getType(), task)); |
|
|
|
|
|
|
|
// 根据题型获取对应策略并判分
|
|
|
|
ScoringStrategy strategy = scoringStrategyFactory.getStrategy(snapshot.getType()); |
|
|
|
strategy.score(tempDto, scoringContext, task.getId()); |
|
|
|
|
|
|
|
// 回写判分结果到快照
|
|
|
|
snapshot.setIsRight(tempDto.getIsRight()); |
|
|
|
snapshot.setAiScore(tempDto.getAiScore()); |
|
|
|
snapshot.setAiComment(tempDto.getAiComment()); |
|
|
|
snapshot.setHitPoints(tempDto.getHitPoints()); |
|
|
|
} |
|
|
|
if (rightCount == snapshotList.size()) { |
|
|
|
//全对,直接给满分(避免因为小数点导致的误差)
|
|
|
|
|
|
|
|
// 汇总总分:客观题 + 简答题
|
|
|
|
finalScore = scoringContext.getTotalScore(); |
|
|
|
if (scoringContext.getRightCount() == scoringContext.getObjectiveTotal() && scoringContext.getSubjectiveScore() == 0) { |
|
|
|
// 全部客观题答对且无简答题,直接给满分(避免小数点误差)
|
|
|
|
finalScore = new BigDecimal("100").doubleValue(); |
|
|
|
} else { |
|
|
|
// 四舍五入处理(不能超过100分)
|
|
|
|
|