diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/student/StuPaperScoreDO.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/student/StuPaperScoreDO.java index d03891a6..d0cf2052 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/student/StuPaperScoreDO.java +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/student/StuPaperScoreDO.java @@ -34,6 +34,10 @@ public class StuPaperScoreDO extends TenantBaseDO { * 试卷ID */ private String paperId; + /** + * 临时ID,每次做题都会变 + */ + private String temporaryId; /** * 试题ID */ diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/student/StuPaperScoreMapper.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/student/StuPaperScoreMapper.java index e09cdfee..a165f2c6 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/student/StuPaperScoreMapper.java +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/student/StuPaperScoreMapper.java @@ -16,7 +16,7 @@ import java.util.List; @Mapper public interface StuPaperScoreMapper extends BaseMapperX { - List findByStuIdAndPaperId(@Param("stuId") Long stuId, @Param("paperId") String paperId); + List findByStuIdAndPaperId(@Param("stuId") Long stuId, @Param("paperId") String paperId, @Param("temporaryId") String temporaryId); List getStuScore(@Param("stuId") Long stuId, @Param("paperId") String paperId); diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/stuPaperScore/StuPaperScoreService.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/stuPaperScore/StuPaperScoreService.java index 97be40c4..4b61ec8a 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/stuPaperScore/StuPaperScoreService.java +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/stuPaperScore/StuPaperScoreService.java @@ -13,7 +13,7 @@ import java.util.List; */ public interface StuPaperScoreService { - List findByStuIDAndPaperId(Long stuId, String paperId); + List findByStuIDAndPaperId(Long stuId, String paperId, String temporaryId); void insertStuPaperScore(StuPaperScoreDO stuPaperScoreDO); diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/stuPaperScore/StuPaperScoreServiceImpl.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/stuPaperScore/StuPaperScoreServiceImpl.java index ea06882e..f3b300fb 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/stuPaperScore/StuPaperScoreServiceImpl.java +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/stuPaperScore/StuPaperScoreServiceImpl.java @@ -27,8 +27,8 @@ public class StuPaperScoreServiceImpl implements StuPaperScoreService { private EducationPaperMapper educationPaperMapper; @Override - public List findByStuIDAndPaperId(Long stuId, String paperId) { - return stuPaperScoreMapper.findByStuIdAndPaperId(stuId, paperId); + public List findByStuIDAndPaperId(Long stuId, String paperId, String temporaryId) { + return stuPaperScoreMapper.findByStuIdAndPaperId(stuId, paperId, temporaryId); } @Override diff --git a/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/student/StuPaperScoreMapper.xml b/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/student/StuPaperScoreMapper.xml index 5e74233b..72eb5220 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/student/StuPaperScoreMapper.xml +++ b/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/student/StuPaperScoreMapper.xml @@ -9,7 +9,7 @@ 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ --> diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/AutoToolsController.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/AutoToolsController.java index 3f0f7c66..3ea297dc 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/AutoToolsController.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/AutoToolsController.java @@ -23,8 +23,6 @@ import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperSessionMapper; import pc.exam.pp.module.exam.dal.mysql.question.ExamQuestionMapper; import pc.exam.pp.module.exam.dal.mysql.student.StuScoreVo; import pc.exam.pp.module.exam.service.paper.IEducationPaperParamService; -import pc.exam.pp.module.exam.service.paper.IEducationPaperSessionService; -import pc.exam.pp.module.exam.service.paper.IEducationPaperTaskService; import pc.exam.pp.module.exam.service.stuPaperScore.StuPaperScoreService; import pc.exam.pp.module.judgement.controller.admin.autoTools.vo.StuInTheExam; import pc.exam.pp.module.judgement.controller.admin.autoTools.vo.StuPaperReqVo; @@ -79,7 +77,7 @@ public class AutoToolsController { StuScoreVo stuScoreVo = stuPaperScoreService.getStuScore(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId()); stuPaperScoreInfoVos.setStuInfoReqVo(stuScoreVo); // 3、查询学生试卷得分信息 - stuPaperScoreInfoVos.setStuPaperScoreDOList(stuPaperScoreService.findByStuIDAndPaperId(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId())); + stuPaperScoreInfoVos.setStuPaperScoreDOList(stuPaperScoreService.findByStuIDAndPaperId(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId(), stuPaperReqVo.getTemporaryId())); // 4、查询学生试卷内容信息 List quIds = educationPaperQuMapper.selectPaperQuByPaperId(stuPaperReqVo.getPaperId()); List examQuestionList = examQuestionMapper.selectExamQuestionListByQuIds(quIds); @@ -92,7 +90,7 @@ public class AutoToolsController { // 一条一条进行查询试题,防止顺序错乱 stuPaperScoreInfoVos.setExamQuestionList(examQuestionList); // 5、查询学生试卷分析 - List scoreDOS = stuPaperScoreService.findByStuIDAndPaperId(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId()); + List scoreDOS = stuPaperScoreService.findByStuIDAndPaperId(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId(), stuPaperReqVo.getTemporaryId()); String judgementStr = "

试卷分析

"; for (StuPaperScoreDO scoreDO : scoreDOS) { judgementStr += "

---------------------------------------

"; @@ -111,66 +109,69 @@ public class AutoToolsController { public CommonResult startExam(@RequestBody StuInTheExam stuInTheExam) { HttpServletRequest request = ServletUtils.getRequest(); // 获取登录token - String token = SecurityFrameworkUtils.obtainAuthorization(request, - securityProperties.getTokenHeader(), securityProperties.getTokenParameter()); - // 获取登录用户 - LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); - // 通过token获取用户redis信息,获取refreshToken - OAuth2AccessTokenDO oAuth2AccessTokenDO = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get("oauth2_access_token:"+token), OAuth2AccessTokenDO.class); - int startTime = 0; - if (oAuth2AccessTokenDO != null) { - String refreshToken = oAuth2AccessTokenDO.getRefreshToken(); - // 查找对应的task - EducationPaperParam educationPaperParam = educationPaperParamService.selectEducationPaperParamByTaskId(stuInTheExam.getTaskId()); - String isSession = educationPaperParam.getIsSession(); - if (isSession.equals("0")) { - // 设置了场次 - // 剩余时间需要继续计算 - EducationPaperPerson educationPaperPerson = educationPaperPersonMapper.selectByTaskIdAndPersonId(stuInTheExam.getTaskId(), String.valueOf(loginUser.getId())); - EducationPaperSession educationPaperSession = educationPaperSessionMapper.selectEducationPaperSessionBySessionId(educationPaperPerson.getSessionId()); - //结束时间 - Date endTime = educationPaperSession.getEndTime(); - Date nowTime = new Date(); - // 将 Date 转换为 Instant - Instant endInstant = endTime.toInstant(); - Instant nowInstant = nowTime.toInstant(); - // 计算秒数差 - long diffInSeconds = Duration.between(nowInstant, endInstant).getSeconds(); - startTime = (int) diffInSeconds; - } else { - // 没有设置场次 - // 剩余时间直接读取数据 - String isTime = educationPaperParam.getIsTime(); - if (isTime.equals("0")) { - // 设置了时间 - // 剩余时间直接读取数据 - long seconds = educationPaperParam.getExamTime().toLocalTime().toSecondOfDay(); - startTime = (int) seconds; + String token = null; + if (request != null) { + token = SecurityFrameworkUtils.obtainAuthorization(request, + securityProperties.getTokenHeader(), securityProperties.getTokenParameter()); + // 获取登录用户 + LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); + // 通过token获取用户redis信息,获取refreshToken + OAuth2AccessTokenDO oAuth2AccessTokenDO = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get("oauth2_access_token:"+token), OAuth2AccessTokenDO.class); + int startTime = 0; + if (oAuth2AccessTokenDO != null) { + String refreshToken = oAuth2AccessTokenDO.getRefreshToken(); + // 查找对应的task + EducationPaperParam educationPaperParam = educationPaperParamService.selectEducationPaperParamByTaskId(stuInTheExam.getTaskId()); + String isSession = educationPaperParam.getIsSession(); + if (isSession.equals("0")) { + // 设置了场次 + // 剩余时间需要继续计算 + EducationPaperPerson educationPaperPerson = educationPaperPersonMapper.selectByTaskIdAndPersonId(stuInTheExam.getTaskId(), String.valueOf(loginUser.getId())); + EducationPaperSession educationPaperSession = educationPaperSessionMapper.selectEducationPaperSessionBySessionId(educationPaperPerson.getSessionId()); + //结束时间 + Date endTime = educationPaperSession.getEndTime(); + Date nowTime = new Date(); + // 将 Date 转换为 Instant + Instant endInstant = endTime.toInstant(); + Instant nowInstant = nowTime.toInstant(); + // 计算秒数差 + long diffInSeconds = Duration.between(nowInstant, endInstant).getSeconds(); + startTime = (int) diffInSeconds; } else { - // 没有设置时间 默认1小时 = 3600秒 - startTime = 3600; + // 没有设置场次 + // 剩余时间直接读取数据 + String isTime = educationPaperParam.getIsTime(); + if (isTime.equals("0")) { + // 设置了时间 + // 剩余时间直接读取数据 + long seconds = educationPaperParam.getExamTime().toLocalTime().toSecondOfDay(); + startTime = (int) seconds; + } else { + // 没有设置时间 默认1小时 = 3600秒 + startTime = 3600; + } } + // 判断是否存在对应的场次 + // 定时上传文件时间 + String time = educationPaperParam.getUploadTime(); + // 将分钟继续转换成秒 + stuInTheExam.setTimes(Integer.parseInt(time) * 60); + // 倒计时 + AtomicInteger countdown = new AtomicInteger(startTime); + // 创建初始返回数据 + StuTheExamInfo stuTheExamInfo = new StuTheExamInfo(); + // 返回数据-剩余时间 + stuTheExamInfo.setTime(formatLongDuration(countdown.get())); + // 返回数据-上传文件状态 0:上传;1:不上传 + stuTheExamInfo.setUpload(1); + // 返回数据-上传文件状态 0:结束;1:不结束 + stuTheExamInfo.setEndStatus(1); + // 返回数据-网络状态 + stuTheExamInfo.setNetwork("强"); + // 创建对应的线程池 + taskManager.startTask(stuInTheExam, stuTheExamInfo, refreshToken, countdown, new AtomicInteger(0)); + return CommonResult.success(refreshToken); } - // 判断是否存在对应的场次 - // 定时上传文件时间 - String time = educationPaperParam.getUploadTime(); - // 将分钟继续转换成秒 - stuInTheExam.setTimes(Integer.parseInt(time) * 60); - // 倒计时 - AtomicInteger countdown = new AtomicInteger(startTime); - // 创建初始返回数据 - StuTheExamInfo stuTheExamInfo = new StuTheExamInfo(); - // 返回数据-剩余时间 - stuTheExamInfo.setTime(formatLongDuration(countdown.get())); - // 返回数据-上传文件状态 0:上传;1:不上传 - stuTheExamInfo.setUpload(1); - // 返回数据-上传文件状态 0:结束;1:不结束 - stuTheExamInfo.setEndStatus(1); - // 返回数据-网络状态 - stuTheExamInfo.setNetwork("强"); - // 创建对应的线程池 - taskManager.startTask(stuInTheExam, stuTheExamInfo, refreshToken, countdown, new AtomicInteger(0)); - return CommonResult.success(refreshToken); } return CommonResult.success("未登录"); } @@ -182,14 +183,17 @@ public class AutoToolsController { @GetMapping("/stopExam") public CommonResult stopExam() { HttpServletRequest request = ServletUtils.getRequest(); - String token = SecurityFrameworkUtils.obtainAuthorization(request, - securityProperties.getTokenHeader(), securityProperties.getTokenParameter()); - OAuth2AccessTokenDO oAuth2AccessTokenDO = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get("oauth2_access_token:"+token), OAuth2AccessTokenDO.class); - if (oAuth2AccessTokenDO != null) { - // 删除对应的线程池 - String refreshToken = oAuth2AccessTokenDO.getRefreshToken(); - taskManager.stopTask(refreshToken); - return CommonResult.success(true); + String token = null; + if (request != null) { + token = SecurityFrameworkUtils.obtainAuthorization(request, + securityProperties.getTokenHeader(), securityProperties.getTokenParameter()); + OAuth2AccessTokenDO oAuth2AccessTokenDO = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get("oauth2_access_token:"+token), OAuth2AccessTokenDO.class); + if (oAuth2AccessTokenDO != null) { + // 删除对应的线程池 + String refreshToken = oAuth2AccessTokenDO.getRefreshToken(); + taskManager.stopTask(refreshToken); + return CommonResult.success(true); + } } return CommonResult.success(false); } @@ -199,6 +203,6 @@ public class AutoToolsController { int minutes = (totalSeconds % 3600) / 60; int seconds = totalSeconds % 60; - return String.format("%d:%02d:%02d", hours, minutes, seconds); + return String.format("%02d:%02d:%02d", hours, minutes, seconds); } } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/vo/StuPaperReqVo.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/vo/StuPaperReqVo.java index 771cd962..c25f81d3 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/vo/StuPaperReqVo.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/vo/StuPaperReqVo.java @@ -13,5 +13,6 @@ public class StuPaperReqVo { @Schema(description = "试卷号") private String paperId; - + @Schema(description = "临时ID") + private String temporaryId; } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/TaskManager.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/TaskManager.java index 013ee6e3..93650603 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/TaskManager.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/TaskManager.java @@ -101,7 +101,7 @@ public class TaskManager { int minutes = (totalSeconds % 3600) / 60; int seconds = totalSeconds % 60; - return String.format("%d:%02d:%02d", hours, minutes, seconds); + return String.format("%02d:%02d:%02d", hours, minutes, seconds); } }