mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-11 20:06:51 +08:00
考试重复提交判断-测试
This commit is contained in:
@@ -4,9 +4,11 @@ import java.time.LocalDateTime;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
@@ -29,6 +31,10 @@ public class StudyExamApi extends ApiBaseController{
|
|||||||
@Autowired
|
@Autowired
|
||||||
IStudyExamService sexamService;
|
IStudyExamService sexamService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
StringRedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
|
||||||
/**2024.04.24
|
/**2024.04.24
|
||||||
* 矫正学员课程进度及完成状态
|
* 矫正学员课程进度及完成状态
|
||||||
* */
|
* */
|
||||||
@@ -53,6 +59,19 @@ public class StudyExamApi extends ApiBaseController{
|
|||||||
return badRequest("得分计算错误");
|
return badRequest("得分计算错误");
|
||||||
}
|
}
|
||||||
try {
|
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();
|
CurrentUser cu=getCurrent();
|
||||||
exam.setStudentId(cu.getAccountId());
|
exam.setStudentId(cu.getAccountId());
|
||||||
exam.setStudentName(cu.getName());
|
exam.setStudentName(cu.getName());
|
||||||
@@ -65,6 +84,10 @@ public class StudyExamApi extends ApiBaseController{
|
|||||||
log.info( exam.getStudyId() + "_" + exam.getContentId() + ",------------试卷保存完毕 ,msg = " + msg + " , " + LocalDateTime.now());
|
log.info( exam.getStudyId() + "_" + exam.getContentId() + ",------------试卷保存完毕 ,msg = " + msg + " , " + LocalDateTime.now());
|
||||||
exam.setAnswerJson("");
|
exam.setAnswerJson("");
|
||||||
exam.setPaperJson("");
|
exam.setPaperJson("");
|
||||||
|
|
||||||
|
//执行完毕 清除redis记录
|
||||||
|
redisTemplate.delete(key);
|
||||||
|
|
||||||
return success(exam);
|
return success(exam);
|
||||||
}catch(Exception e) {
|
}catch(Exception e) {
|
||||||
log.error("保存答卷信息错误",e);
|
log.error("保存答卷信息错误",e);
|
||||||
|
|||||||
@@ -54,21 +54,16 @@ public class StudyExamServiceImpl implements IStudyExamService{
|
|||||||
@Transactional
|
@Transactional
|
||||||
public String save(StudyExam exam) {
|
public String save(StudyExam exam) {
|
||||||
String key = exam.getStudyId() + "_" + exam.getContentId();
|
String key = exam.getStudyId() + "_" + exam.getContentId();
|
||||||
try {
|
// //判断是否存在redis
|
||||||
Thread.sleep(10000L);
|
// if(StringUtils.isNotEmpty(redisTemplate.opsForValue().get(key))){
|
||||||
} catch (InterruptedException e) {
|
// log.info("------------试卷提交验证中,请等待! ");
|
||||||
e.printStackTrace();
|
// return "试卷提交验证中,请等待!";
|
||||||
}
|
// }
|
||||||
//判断是否存在redis
|
// //加入redis 2分钟过期
|
||||||
if(StringUtils.isNotEmpty(redisTemplate.opsForValue().get(key))){
|
// redisTemplate.opsForValue().set(key,key);
|
||||||
log.info("------------试卷提交验证中,请等待! ");
|
// //设置过期时间为1天
|
||||||
return "试卷提交验证中,请等待!";
|
// redisTemplate.expire(key, 5 * 60, TimeUnit.SECONDS);
|
||||||
}
|
// log.info("------------设置redis-key ,请等待! " + LocalDateTime.now() + ", key = " + redisTemplate.opsForValue().get(key));
|
||||||
//加入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));
|
|
||||||
|
|
||||||
//用于计算考试成绩
|
//用于计算考试成绩
|
||||||
CourseExam cexam=cexamDao.get(exam.getTestId());
|
CourseExam cexam=cexamDao.get(exam.getTestId());
|
||||||
@@ -116,7 +111,7 @@ public class StudyExamServiceImpl implements IStudyExamService{
|
|||||||
scItemDao.updateFieldById(exam.getStudyItemId(), "score", f);
|
scItemDao.updateFieldById(exam.getStudyItemId(), "score", f);
|
||||||
}
|
}
|
||||||
//执行完毕 清除redis记录
|
//执行完毕 清除redis记录
|
||||||
redisTemplate.delete(key);
|
// redisTemplate.delete(key);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user