Accept Merge Request #137: (hyc -> master)

Merge Request: 【修改】监控管理 学生判分结束返回值

Created By: @华允传
Accepted By: @华允传
URL: https://g-iswv8783.coding.net/p/education/d/pengchen-exam-java/git/merge/137?initial=true
This commit is contained in:
华允传
2025-06-27 10:08:00 +08:00
committed by Coding
4 changed files with 55 additions and 60 deletions

View File

@@ -8,7 +8,4 @@ import lombok.Data;
public class StuMonitorPaperEndVo {
private String stuId;
private String paperId;
private String score;
private String taskId;
}

View File

@@ -2,7 +2,6 @@ package pc.exam.pp.module.exam.dal.mysql.paper;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@@ -10,13 +9,10 @@ import pc.exam.pp.framework.common.pojo.PageResult;
import pc.exam.pp.framework.mybatis.core.mapper.BaseMapperX;
import pc.exam.pp.framework.mybatis.core.query.LambdaQueryWrapperX;
import pc.exam.pp.framework.tenant.core.aop.TenantIgnore;
import pc.exam.pp.module.exam.controller.admin.paper.dto.EducationPaperStuDto;
import pc.exam.pp.module.exam.controller.admin.paper.dto.PaperIdAndNum;
import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperPageVo;
import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperTaskPageVo;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaper;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaperScheme;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaperTask;
/**
* 试卷Mapper接口
@@ -178,10 +174,12 @@ public interface EducationPaperMapper extends BaseMapperX<EducationPaper>
List<String> selectTaskNumByids(@Param("cannotDeleteTaskIds")List<String> cannotDeleteTaskIds);
// //查询所有正在考试的 试卷id
// 查询所有正在考试的 试卷id
@TenantIgnore
List<String> selectSpecilayCounts(Long loginTenantId);
//查询学生的考试分数
double selctStuScoreByStuIdAndPaperId(@Param("stuId") String stuId
, @Param("paperId") String paperId);
}

View File

@@ -10,6 +10,8 @@ import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.sql.Time;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
@@ -353,57 +355,50 @@ public class MonitorServiceImpl implements MonitorService {
@Override
public void endStuMonitor(StuMonitorPaperEndVo stuMonitorPaperEndVo) {
// String key = "userCache:" + stuMonitorPaperEndVo.getTaskId()+":" +stuMonitorPaperEndVo.getStuId();
// String keychoice = "keychoice:"+stuMonitorPaperEndVo.getTaskId()+":" + stuMonitorPaperEndVo.getStuId();
// StuMonitorQuVo stuMonitorQuVo = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(keychoice),StuMonitorQuVo.class);
//
// try {
// String fileName = "StuMonitorQu.txt";
// FileWriter writer = new FileWriter(fileName);
// writer.write(JsonUtils.toJsonString(stuMonitorQuVo));
// writer.close();
// //上传至
// String stuId = stuMonitorPaperEndVo.getStuId(); // 学生ID
// String paperId = stuMonitorPaperEndVo.getPaperId(); // 试卷ID
// String path = ""; // 存储路径(可选)
// // 1. 生成 JSON 内容
// String content = JsonUtils.toJsonString(stuMonitorQuVo);
//
// // 2. 转换为 UTF-8 字节数组(关键修复!)
// byte[] bytes = content.getBytes(StandardCharsets.UTF_8);
//// String fileurl= fileService.createFile(fileName,path, bytes);
//// System.out.println(fileurl);
//
// } catch (IOException e) {
// System.out.println(e);
// }
//
// MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class);
// EducationPaperParam educationPaperParam = educationPaperParamMapper.selectEducationPaperParamByTaskId(stuMonitorPaperEndVo.getTaskId());
// EducationPaperTask educationPaperTask = educationPaperTaskMapper.selectEducationPaperTaskByTaskId(stuMonitorPaperEndVo.getTaskId());
// if ("1".equals(educationPaperParam.getSaveGrades())){
// info.setScore(stuMonitorPaperEndVo.getScore());
// }else {
// MonitorDO monitorDO = monitorMapper.selectById(info.getMonitorId());
// info.setScore(stuMonitorPaperEndVo.getScore());
// if (StringUtils.isNotBlank(monitorDO.getScore())) {
// if (Integer.parseInt(monitorDO.getScore()) <Integer.parseInt(stuMonitorPaperEndVo.getScore())){
// info.setScore(stuMonitorPaperEndVo.getScore());
// }
// }
//
//
// }
// //练习下的任务 结束改为 代考 其他为结束
// if ("0".equals(educationPaperTask.getTaskType())){
// info.setExamStatus("0");
// }else {
// info.setExamStatus("2");
// }
// //todo 这些都写成方法
// redisTemplate.delete(key);
// redisTemplate.delete(keychoice);
// monitorMapper.updateById(info);
EducationPaper educationPaper = educationPaperMapper.selectEducationPaperByPaperId(stuMonitorPaperEndVo.getPaperId());
String taskId = educationPaper.getTaskId();
String key = "userCache:" + taskId + ":" + stuMonitorPaperEndVo.getStuId();
double score =educationPaperMapper.selctStuScoreByStuIdAndPaperId(stuMonitorPaperEndVo.getStuId(),stuMonitorPaperEndVo.getPaperId());
MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class);
info.setRemainingTime(0L);
EducationPaperParam educationPaperParam = educationPaperParamMapper.selectEducationPaperParamByTaskId(taskId);
EducationPaperTask educationPaperTask = educationPaperTaskMapper.selectEducationPaperTaskByTaskId(taskId);
if ("1".equals(educationPaperParam.getSaveGrades())){
info.setScore(String.valueOf(score));
}else {
MonitorDO monitorDO = monitorMapper.selectById(info.getMonitorId());
info.setScore(String.valueOf(score));
if (StringUtils.isNotBlank(monitorDO.getScore())) {
try {
double oldScore = Double.parseDouble(monitorDO.getScore());
if (score > oldScore) {
info.setScore(String.valueOf(score));
} else {
info.setScore(monitorDO.getScore()); // 保留旧成绩
}
} catch (NumberFormatException e) {
// 如果旧分数格式错误,则直接设置新分数
info.setScore(String.valueOf(score));
}
} else {
// 如果没有旧成绩,则直接设置
info.setScore(String.valueOf(score));
}
}
//考试下的任务 结束改为 结束 其他为待考
if ("1".equals(educationPaperTask.getTaskType())){
info.setExamStatus("2");
redisTemplate.delete(key);
}else {
info.setExamStatus("0");
stringRedisTemplate.opsForValue().set(key, JsonUtils.toJsonString(info));
}
monitorMapper.updateById(info);
}

View File

@@ -145,6 +145,11 @@ select task_id from education_paper where paper_id=#{paperId}
AND em.tenant_id = #{loginTenantId}
ORDER BY em.paper_num;
</select>
<select id="selctStuScoreByStuIdAndPaperId" resultType="java.lang.Double">
SELECT COALESCE(SUM(score), 0.0)
FROM exam_stu_paper_score
WHERE stu_id = #{stuId} AND paper_id = #{paperId}
</select>
<insert id="insertEducationPaper" parameterType="EducationPaper">