merge
This commit is contained in:
GoCo 2025-09-02 15:55:50 +08:00
commit 6cc473fead
2 changed files with 205 additions and 5 deletions

View File

@ -17,6 +17,8 @@ import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.query.QueryRuleEnum; import org.jeecg.common.system.query.QueryRuleEnum;
import org.jeecg.common.util.oConvertUtils; import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.aiol.dto.QuestionAnswerDTO;
import org.jeecg.modules.aiol.dto.QuestionAnswerUser;
import org.jeecg.modules.aiol.entity.*; import org.jeecg.modules.aiol.entity.*;
import org.jeecg.modules.aiol.service.*; import org.jeecg.modules.aiol.service.*;
@ -79,7 +81,7 @@ public class AiolExamController extends JeecgController<AiolExam, IAiolExamServi
IPage<AiolExam> pageList = aiolExamService.page(page, queryWrapper); IPage<AiolExam> pageList = aiolExamService.page(page, queryWrapper);
return Result.OK(pageList); return Result.OK(pageList);
} }
/** /**
* 添加 * 添加
* *
@ -95,7 +97,7 @@ public class AiolExamController extends JeecgController<AiolExam, IAiolExamServi
return Result.OK("添加成功!"); return Result.OK("添加成功!");
} }
/** /**
* 编辑 * 编辑
* *
@ -110,7 +112,7 @@ public class AiolExamController extends JeecgController<AiolExam, IAiolExamServi
aiolExamService.updateById(aiolExam); aiolExamService.updateById(aiolExam);
return Result.OK("编辑成功!"); return Result.OK("编辑成功!");
} }
/** /**
* 通过id删除 * 通过id删除
* *
@ -125,7 +127,7 @@ public class AiolExamController extends JeecgController<AiolExam, IAiolExamServi
aiolExamService.removeById(id); aiolExamService.removeById(id);
return Result.OK("删除成功!"); return Result.OK("删除成功!");
} }
/** /**
* 批量删除 * 批量删除
* *
@ -140,7 +142,7 @@ public class AiolExamController extends JeecgController<AiolExam, IAiolExamServi
this.aiolExamService.removeByIds(Arrays.asList(ids.split(","))); this.aiolExamService.removeByIds(Arrays.asList(ids.split(",")));
return Result.OK("批量删除成功!"); return Result.OK("批量删除成功!");
} }
/** /**
* 通过id查询 * 通过id查询
* *
@ -325,6 +327,184 @@ public class AiolExamController extends JeecgController<AiolExam, IAiolExamServi
return examRecordService.update(updateWrapper) ? Result.OK() : Result.error("提交考试失败"); return examRecordService.update(updateWrapper) ? Result.OK() : Result.error("提交考试失败");
} }
//获取名下考试信息
@GetMapping("/getExamInfo")
@Operation(summary = "获取教师名下考试")
public Result<?> getExamInfo(@RequestParam String userId) {
return Result.OK(examService.list(new LambdaQueryWrapper<AiolExam>().eq(AiolExam::getCreateBy, userId)));
}
//获取考试相关答卷
@GetMapping("/getExamRecord")
@Operation(summary = "获取考试相关答卷记录")
public Result<?> getExamRecord(@RequestParam String examId) {
return Result.OK(examRecordService.
list(new LambdaQueryWrapper<AiolExamRecord>().
eq(AiolExamRecord::getExamId, examId)));
}
//获取考试相关答卷
@GetMapping("/getExamRecordByUser")
@Operation(summary = "获取考试相关答卷答案")
public Result<?> getExamRecordByUser(@RequestParam String examId,@RequestParam String userId) {
List<AiolExamAnswer> list = examAnswerService.
list(new LambdaQueryWrapper<AiolExamAnswer>().
eq(AiolExamAnswer::getExamId, examId).
eq(AiolExamAnswer::getUserId, userId));
Map<String, AiolExamAnswer> questionIdToAnswerMap = list.stream()
.collect(Collectors.toMap(
AiolExamAnswer::getQuestionId,
answer -> answer
));
if(!list.isEmpty()){
List<String> questionIds = list.stream()
.map(AiolExamAnswer::getQuestionId)
.collect(Collectors.toList());
List<AiolQuestion> questions = questionService.listByIds(questionIds);
//取出简答题
List<AiolQuestion> type4Questions = questions.stream()
.filter(question -> question.getType() == 4)
.collect(Collectors.toList());
Map<String, AiolQuestion> questionIdToTitleMap = type4Questions.stream().collect(Collectors.toMap(AiolQuestion::getId, question -> question));
if(!type4Questions.isEmpty()){
List<String> collect = type4Questions.stream().map(AiolQuestion::getId).collect(Collectors.toList());
//查询题目答案
List<AiolQuestionAnswer> list1 = questionAnswerService.list(new LambdaQueryWrapper<AiolQuestionAnswer>()
.in(AiolQuestionAnswer::getQuestionId, collect)
);
// 查询题目分数
AiolExam exam = examService.getById(examId);
AiolPaper paper = paperService.getById(exam.getPaperId());
// 根据试卷生成模式获取分数
Map<String, Double> questionIdToScoreMap = Optional.ofNullable(paper)
.filter(p -> p.getGenerateMode() == 0)
.map(p -> paperQuestionService.list(new LambdaQueryWrapper<AiolPaperQuestion>()
.eq(AiolPaperQuestion::getPaperId, p.getId())
.in(AiolPaperQuestion::getQuestionId, collect)))
.orElse(Collections.emptyList())
.stream()
.collect(Collectors.toMap(
AiolPaperQuestion::getQuestionId,
AiolPaperQuestion::getScore
));
// 获取类型4的题目分数仅在非固定模式下
Double type4Score = Optional.ofNullable(paper)
.filter(p -> p.getGenerateMode() != 0)
.map(p -> JSON.parseObject(p.getRules()).getDouble("type4_score"))
.orElse(0.0);
// 构建用户答案列表
List<QuestionAnswerUser> questionAnswerUserList = list1.stream()
.map(questionAnswer -> {
QuestionAnswerUser questionAnswerUser = new QuestionAnswerUser();
questionAnswerUser.setQuestion(questionIdToTitleMap.get(questionAnswer.getQuestionId()));
questionAnswerUser.setUserAnswer(questionIdToAnswerMap.get(questionAnswer.getQuestionId()));
questionAnswerUser.setAnswer(questionAnswer);
questionAnswerUser.setFullMark(questionIdToScoreMap.getOrDefault(
questionAnswer.getQuestionId(),
type4Score
));
return questionAnswerUser;
})
.collect(Collectors.toList());
return Result.OK(questionAnswerUserList);
}
}
return Result.OK("没有需要批改的题目数据");
}
@PostMapping("/submitGrade")
@Operation(summary = "提交批改")
@Transactional
public Result<?> submitGrade(@RequestBody List<AiolExamAnswer> examAnswers) {
// 检查输入参数是否为空
if (CollectionUtils.isEmpty(examAnswers)) {
return Result.error("批改数据不能为空");
}
try {
String examId = examAnswers.get(0).getExamId();
String userId = examAnswers.get(0).getUserId();
List<AiolExamAnswer> list = examAnswerService.list(new LambdaQueryWrapper<AiolExamAnswer>()
.eq(AiolExamAnswer::getExamId, examId)
.eq(AiolExamAnswer::getUserId, userId));
// 创建examAnswers的ID映射方便查找
Map<String, AiolExamAnswer> examAnswerMap = examAnswers.stream()
.collect(Collectors.toMap(AiolExamAnswer::getId, answer -> answer));
// 创建list的id映射
Map<String, AiolExamAnswer> listIdMap = list.stream()
.collect(Collectors.toMap(AiolExamAnswer::getQuestionId, answer -> answer));
//计算总分
Double totalScore = list.stream().mapToDouble(AiolExamAnswer::getScore).sum() + examAnswers.stream().mapToDouble(AiolExamAnswer::getScore).sum();
// 复合题对错得分
List<AiolExamAnswer> sonList = list.stream()
.filter(answer -> answer.getParentQuestionId() != null && !answer.getParentQuestionId().isEmpty())
.collect(Collectors.toList());
if (!sonList.isEmpty()) {
// 按父ID分组
Map<String, List<AiolExamAnswer>> parentGroup = sonList.stream()
.collect(Collectors.groupingBy(AiolExamAnswer::getParentQuestionId));
// 遍历每个父题组
for (Map.Entry<String, List<AiolExamAnswer>> entry : parentGroup.entrySet()) {
String parentId = entry.getKey();
List<AiolExamAnswer> children = entry.getValue();
Double parentScore = 0.0;
boolean isCorrect = true;
// 计算每个子题的分数和正确性
for (AiolExamAnswer childAnswer : children) {
Double sonScore = 0.0;
if (examAnswerMap.get(childAnswer.getId()) != null) {
if (isCorrect && examAnswerMap.get(childAnswer.getId()).getIzCorrect() == 0) {
isCorrect = false;
}
sonScore = examAnswerMap.get(childAnswer.getId()).getScore();
} else {
if (isCorrect && childAnswer.getIzCorrect() == 0) {
isCorrect = false;
}
sonScore = childAnswer.getScore();
}
parentScore += sonScore;
}
// 更新父题的分数和正确性
AiolExamAnswer parentAnswer = listIdMap.get(parentId);
if (parentAnswer != null) {
parentAnswer.setIzCorrect(isCorrect ? 1 : 0);
parentAnswer.setScore(parentScore);
examAnswers.add(parentAnswer);
}
}
}
// 更新考试记录的状态为已批改
examRecordService.update(new LambdaUpdateWrapper<AiolExamRecord>()
.set(AiolExamRecord::getStatus, 2)
.set(AiolExamRecord::getTotalScore, totalScore)
.eq(AiolExamRecord::getExamId, examId)
.eq(AiolExamRecord::getUserId, userId));
// 批量更新答题分数
boolean success = examAnswerService.updateBatchById(examAnswers);
if (!success) {
return Result.error("批改失败");
}
// 可选更新考试的总分和平均分如果需要
// 这里可以添加额外的业务逻辑
return Result.OK("批改成功");
} catch (Exception e) {
log.error("提交批改失败", e);
return Result.error("系统错误:" + e.getMessage());
}
}
@GetMapping("/queryExamProgress") @GetMapping("/queryExamProgress")
@Operation(summary = "查询考试进度") @Operation(summary = "查询考试进度")
public Result<?> queryExamProgress(@RequestParam String examId, @RequestParam String userId) { public Result<?> queryExamProgress(@RequestParam String examId, @RequestParam String userId) {

View File

@ -0,0 +1,20 @@
package org.jeecg.modules.aiol.dto;
import lombok.Data;
import org.jeecg.modules.aiol.entity.AiolExamAnswer;
import org.jeecg.modules.aiol.entity.AiolQuestion;
import org.jeecg.modules.aiol.entity.AiolQuestionAnswer;
import java.util.List;
@Data
public class QuestionAnswerUser {
//题目内容
private AiolQuestion question;
//答案
private AiolQuestionAnswer answer;
//用户答案
private AiolExamAnswer userAnswer;
//满分
private Double fullMark;
}