From 33e2e50e5bdc3cb5accc712629fa85192d7769cb Mon Sep 17 00:00:00 2001 From: 670788339 <670788339@qq.com> Date: Thu, 9 May 2024 17:42:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=83=E8=AF=95=E9=87=8D=E5=A4=8D=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E5=88=A4=E6=96=AD-=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xboe/school/study/api/StudyExamApi.java | 23 ++++++++++++++++ .../service/impl/StudyExamServiceImpl.java | 27 ++++++++----------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/servers/boe-server-all/src/main/java/com/xboe/school/study/api/StudyExamApi.java b/servers/boe-server-all/src/main/java/com/xboe/school/study/api/StudyExamApi.java index 4b4adb47..d22bf8d9 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/school/study/api/StudyExamApi.java +++ b/servers/boe-server-all/src/main/java/com/xboe/school/study/api/StudyExamApi.java @@ -4,9 +4,11 @@ import java.time.LocalDateTime; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -29,6 +31,10 @@ public class StudyExamApi extends ApiBaseController{ @Autowired IStudyExamService sexamService; + @Autowired + StringRedisTemplate redisTemplate; + + /**2024.04.24 * 矫正学员课程进度及完成状态 * */ @@ -53,6 +59,19 @@ public class StudyExamApi extends ApiBaseController{ return badRequest("得分计算错误"); } try { + String key = exam.getStudyId() + "_" + exam.getContentId(); + //判断是否存在redis + if(StringUtils.isNotEmpty(redisTemplate.opsForValue().get(key))){ + log.info("------------试卷提交验证中,请等待! "); + return error("","试卷提交验证中,请等待"); + } + //加入redis 2分钟过期 + redisTemplate.opsForValue().set(key,key); + //设置过期时间为1天 + redisTemplate.expire(key, 5 * 60, TimeUnit.SECONDS); + log.info("------------设置redis-key ,请等待! " + LocalDateTime.now() + ", key = " + redisTemplate.opsForValue().get(key)); + + CurrentUser cu=getCurrent(); exam.setStudentId(cu.getAccountId()); exam.setStudentName(cu.getName()); @@ -65,6 +84,10 @@ public class StudyExamApi extends ApiBaseController{ log.info( exam.getStudyId() + "_" + exam.getContentId() + ",------------试卷保存完毕 ,msg = " + msg + " , " + LocalDateTime.now()); exam.setAnswerJson(""); exam.setPaperJson(""); + + //执行完毕 清除redis记录 + redisTemplate.delete(key); + return success(exam); }catch(Exception e) { log.error("保存答卷信息错误",e); diff --git a/servers/boe-server-all/src/main/java/com/xboe/school/study/service/impl/StudyExamServiceImpl.java b/servers/boe-server-all/src/main/java/com/xboe/school/study/service/impl/StudyExamServiceImpl.java index ae176cfc..39ec0bec 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/school/study/service/impl/StudyExamServiceImpl.java +++ b/servers/boe-server-all/src/main/java/com/xboe/school/study/service/impl/StudyExamServiceImpl.java @@ -54,21 +54,16 @@ public class StudyExamServiceImpl implements IStudyExamService{ @Transactional public String save(StudyExam exam) { String key = exam.getStudyId() + "_" + exam.getContentId(); - try { - Thread.sleep(10000L); - } catch (InterruptedException e) { - e.printStackTrace(); - } - //判断是否存在redis - if(StringUtils.isNotEmpty(redisTemplate.opsForValue().get(key))){ - log.info("------------试卷提交验证中,请等待! "); - return "试卷提交验证中,请等待!"; - } - //加入redis 2分钟过期 - redisTemplate.opsForValue().set(key,key); - //设置过期时间为1天 - redisTemplate.expire(key, 2, TimeUnit.SECONDS); - log.info("------------设置redis-key ,请等待! " + LocalDateTime.now() + ", key = " + redisTemplate.opsForValue().get(key)); +// //判断是否存在redis +// if(StringUtils.isNotEmpty(redisTemplate.opsForValue().get(key))){ +// log.info("------------试卷提交验证中,请等待! "); +// return "试卷提交验证中,请等待!"; +// } +// //加入redis 2分钟过期 +// redisTemplate.opsForValue().set(key,key); +// //设置过期时间为1天 +// redisTemplate.expire(key, 5 * 60, TimeUnit.SECONDS); +// log.info("------------设置redis-key ,请等待! " + LocalDateTime.now() + ", key = " + redisTemplate.opsForValue().get(key)); //用于计算考试成绩 CourseExam cexam=cexamDao.get(exam.getTestId()); @@ -116,7 +111,7 @@ public class StudyExamServiceImpl implements IStudyExamService{ scItemDao.updateFieldById(exam.getStudyItemId(), "score", f); } //执行完毕 清除redis记录 - redisTemplate.delete(key); +// redisTemplate.delete(key); return ""; }