【修改】 修改学生端倒计时闪烁补充项

This commit is contained in:
DESKTOP-9ERGOBP\任维炳
2025-10-20 12:25:30 +08:00
parent c708a30443
commit ad2b0b510e
2 changed files with 10 additions and 8 deletions

View File

@@ -402,6 +402,8 @@ public class AutoToolsController {
stringRedisTemplate.opsForValue().set(key, JsonUtils.toJsonString(info));
monitorMapper.updateById(info);
}
// 删除对应任务
taskManager.stopTaskByUserId(userId);
return CommonResult.success(true);
}
@@ -412,13 +414,9 @@ public class AutoToolsController {
* @return true
*/
@GetMapping("/stopExamForAdmin")
public CommonResult<Boolean> stopExamForAdmin(@RequestParam("userId") String userId, @RequestParam("taskId") String taskId, @RequestParam("paperNum") String paperNum) {
String paperId = educationPaperService.selectPaperByPaperNum(paperNum);
// 将userId 拼接 taskId 作为key
// 防止不同试卷ID冲突
userId += "_" + taskId + "_" + paperId;
public CommonResult<Boolean> stopExamForAdmin(@RequestParam("userId") String userId) {
// 删除对应的线程池
taskManager.stopTask(userId);
taskManager.stopTaskByUserId(userId);
return CommonResult.success(true);
}

View File

@@ -95,9 +95,13 @@ public class TaskManager {
/**通过ID结束任务*/
public void stopTaskByUserId(String userId) {
tasks.keySet().stream()
String taskId = tasks.keySet().stream()
.filter(key -> key.startsWith(userId + "_"))
.findFirst().ifPresent(this::stopTask);
.findFirst()
.orElse(null);
if (taskId != null) {
stopTask(taskId);
}
}