【新增】 1、交互接口,学生端定时与后台交互,获取交互时间存入缓存;2、更换PC答题,使用交互时间进行判断
This commit is contained in:
@@ -28,20 +28,17 @@ 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.IEducationPaperQuService;
|
||||
import pc.exam.pp.module.exam.service.paper.IEducationPaperService;
|
||||
import pc.exam.pp.module.exam.service.stuPaperScore.StuPaperScoreService;
|
||||
import pc.exam.pp.module.exam.service.stu_paper_file.StuPaperFileService;
|
||||
import pc.exam.pp.module.judgement.controller.admin.autoTools.vo.*;
|
||||
import pc.exam.pp.module.judgement.service.TaskManager;
|
||||
import pc.exam.pp.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -76,6 +73,8 @@ public class AutoToolsController {
|
||||
IEducationPaperQuService educationPaperQuService;
|
||||
@Resource
|
||||
StuPaperFileService stuPaperFileService;
|
||||
@Resource
|
||||
IEducationPaperService educationPaperService;
|
||||
|
||||
@GetMapping("/getStuScoreInfo")
|
||||
@Operation(summary = "通过学生ID、试卷ID获取")
|
||||
@@ -109,6 +108,34 @@ public class AutoToolsController {
|
||||
return CommonResult.success(stuPaperScoreInfoVos);
|
||||
}
|
||||
|
||||
/**
|
||||
* 学生端进行交互
|
||||
* @param taskId 方案ID
|
||||
* @return 是否完成
|
||||
*/
|
||||
@GetMapping("/getStuSideStatus")
|
||||
public CommonResult<Boolean> getStuSideStatus(@RequestParam("taskId") String taskId) {
|
||||
// 获取登录用户
|
||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||
if (loginUser != null) {
|
||||
// 获取ID
|
||||
long userId = loginUser.getId();
|
||||
// 通过方案ID获取学生考试状态
|
||||
String key = "userCache:" + taskId + ":" + userId;
|
||||
MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key), MonitorDO.class);
|
||||
if (info != null) {
|
||||
// 更新交互时间
|
||||
LocalDateTime nowTime = LocalDateTime.now();
|
||||
DateTimeFormatter formatterNow = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
// 考试考试的时候初始化交互时间为当前时间
|
||||
info.setInteractiveTime(nowTime.format(formatterNow));
|
||||
// 更新缓存
|
||||
stringRedisTemplate.opsForValue().set(key, JsonUtils.toJsonString(info));
|
||||
}
|
||||
}
|
||||
return CommonResult.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始考试 通过websocket进行传输时间
|
||||
*
|
||||
@@ -186,16 +213,33 @@ public class AutoToolsController {
|
||||
// 学生端重新登录,判断是否上一次考试没有结束就退出了
|
||||
@GetMapping("/reStartExamStatus")
|
||||
public CommonResult<String> reStartExamStatus() {
|
||||
HttpServletRequest request = ServletUtils.getRequest();
|
||||
// 获取学生ID
|
||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||
if (loginUser != null) {
|
||||
long userId = loginUser.getId();
|
||||
String key = taskManager.getTaskById(String.valueOf(userId));
|
||||
if (key == null) {
|
||||
return CommonResult.success("0");
|
||||
long userId = loginUser.getId();
|
||||
Set<String> userCaches = stringRedisTemplate.keys("userCache:*");
|
||||
for (String userCache : userCaches) {
|
||||
// 获取所有试卷的数据
|
||||
Set<String> userCacheInfos = stringRedisTemplate.keys(userCache);
|
||||
for (String userCacheInfo : userCacheInfos) {
|
||||
MonitorDO monitorDO = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(userCacheInfo), MonitorDO.class);
|
||||
if (monitorDO.getStuId().equals(String.valueOf(userId))) {
|
||||
if (monitorDO.getExamStatus().equals("1")) {
|
||||
// 说明考试没有结束
|
||||
String key = taskManager.getTaskById(String.valueOf(userId));
|
||||
if (key != null) {
|
||||
return CommonResult.success(key);
|
||||
} else {
|
||||
// 通过试卷number查找试卷ID
|
||||
String paperNum = monitorDO.getPaperNum();
|
||||
String paperId = educationPaperService.selectPaperByPaperNum(paperNum);
|
||||
key = loginUser.getId() + "_" + monitorDO.getTaskId() + "_" + paperId;
|
||||
return CommonResult.success(key);
|
||||
}
|
||||
} else {
|
||||
return CommonResult.success("0");
|
||||
}
|
||||
}
|
||||
}
|
||||
return CommonResult.success(key);
|
||||
}
|
||||
return CommonResult.success("0");
|
||||
}
|
||||
@@ -270,6 +314,7 @@ public class AutoToolsController {
|
||||
}
|
||||
return CommonResult.error(1_0001_002,"没有找到对应的学生信息");
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止考试
|
||||
*
|
||||
|
@@ -0,0 +1,13 @@
|
||||
package pc.exam.pp.module.judgement.controller.admin.autoTools.vo;
|
||||
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class StuSideReqVo {
|
||||
|
||||
@Schema(description = "试卷号")
|
||||
private String taskId;
|
||||
|
||||
}
|
Reference in New Issue
Block a user