mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-09 10:56:50 +08:00
考试重复提交判断-测试
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 "";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user