【修改】 修改考试剩余时间异常闪动问题
This commit is contained in:
@@ -157,11 +157,9 @@ public class AutoToolsController {
|
||||
securityProperties.getTokenHeader(), securityProperties.getTokenParameter());
|
||||
// 获取登录用户
|
||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||
// userId 是否存在
|
||||
String wsKey = taskManager.getTaskById(String.valueOf(loginUser.getId()));
|
||||
if (wsKey != null) {
|
||||
// 停止任务
|
||||
taskManager.stopTask(wsKey);
|
||||
// 通过ID 直接停止
|
||||
if (loginUser != null) {
|
||||
taskManager.stopTaskByUserId(String.valueOf(loginUser.getId()));
|
||||
}
|
||||
int startTime = 0;
|
||||
// 查找对应的task
|
||||
@@ -213,7 +211,9 @@ public class AutoToolsController {
|
||||
// 返回数据-网络状态
|
||||
stuTheExamInfo.setNetwork("强");
|
||||
// 创建对应的线程池
|
||||
if (loginUser != null) {
|
||||
taskManager.startTask(stuInTheExam, stuTheExamInfo, token, countdown, new AtomicInteger(0), loginUser.getId() + "_" + stuInTheExam.getTaskId() + "_" + stuInTheExam.getPaperId());
|
||||
}
|
||||
return CommonResult.success(token);
|
||||
}
|
||||
return CommonResult.success("未登录");
|
||||
@@ -261,8 +261,10 @@ public class AutoToolsController {
|
||||
securityProperties.getTokenHeader(), securityProperties.getTokenParameter());
|
||||
ExamRestartPaperVo examRestartPaperVo = new ExamRestartPaperVo();
|
||||
// 如果继续考试,需要关闭之前的,重新开始ws
|
||||
String taskManagerId = loginUser.getId() + "_" + stuInTheExam.getTaskId() + "_" + stuInTheExam.getPaperId();
|
||||
taskManager.stopTask(taskManagerId);
|
||||
// 通过ID 直接停止
|
||||
if (loginUser != null) {
|
||||
taskManager.stopTaskByUserId(String.valueOf(loginUser.getId()));
|
||||
}
|
||||
// 获取试卷详情
|
||||
ExamPaperVo examPaperVo = educationPaperQuService.selectPaperQuListByPaperId(stuInTheExam.getPaperId());
|
||||
// 获取剩余的时间
|
||||
@@ -353,6 +355,12 @@ public class AutoToolsController {
|
||||
userId += "_" + taskId + "_" + paperId;
|
||||
// 删除对应的线程池
|
||||
taskManager.stopTask(userId);
|
||||
// 为了确保停止成功,笨办法在请求另一个停止接口
|
||||
try {
|
||||
taskManager.stopTaskByUserId(String.valueOf(userId));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return CommonResult.success(true);
|
||||
}
|
||||
|
||||
|
@@ -93,6 +93,14 @@ public class TaskManager {
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/**通过ID结束任务*/
|
||||
public void stopTaskByUserId(String userId) {
|
||||
tasks.keySet().stream()
|
||||
.filter(key -> key.startsWith(userId + "_"))
|
||||
.findFirst().ifPresent(this::stopTask);
|
||||
}
|
||||
|
||||
|
||||
/** 全部停止(可选) */
|
||||
public void stopAll() {
|
||||
tasks.forEach((k, f) -> f.cancel(false));
|
||||
|
Reference in New Issue
Block a user