mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-07 09:56:47 +08:00
考试重复提交判断
This commit is contained in:
@@ -60,7 +60,9 @@ public class StudyExamApi extends ApiBaseController{
|
||||
if(exam.getEndTime()==null) {
|
||||
exam.setEndTime(exam.getLastTime());
|
||||
}
|
||||
sexamService.save(exam);
|
||||
log.info( exam.getStudyId() + "_" + exam.getContentId() + ",------------试卷开始提交 " + LocalDateTime.now());
|
||||
String msg = sexamService.save(exam);
|
||||
log.info( exam.getStudyId() + "_" + exam.getContentId() + ",------------试卷保存完毕 ,msg = " + msg + " , " + LocalDateTime.now());
|
||||
exam.setAnswerJson("");
|
||||
exam.setPaperJson("");
|
||||
return success(exam);
|
||||
|
||||
@@ -10,7 +10,7 @@ public interface IStudyExamService {
|
||||
* 保存考试信息
|
||||
* @param exam
|
||||
*/
|
||||
void save(StudyExam exam);
|
||||
String save(StudyExam exam);
|
||||
|
||||
|
||||
StudyExam get(String id);
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.xboe.school.study.service.impl;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.transaction.Transactional;
|
||||
@@ -11,6 +12,7 @@ import com.xboe.system.user.entity.Message;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.xboe.common.OrderCondition;
|
||||
@@ -44,9 +46,25 @@ public class StudyExamServiceImpl implements IStudyExamService{
|
||||
@Autowired
|
||||
StudyCourseItemDao scItemDao;
|
||||
|
||||
@Autowired
|
||||
StringRedisTemplate redisTemplate;
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void save(StudyExam exam) {
|
||||
public String save(StudyExam exam) {
|
||||
String key = exam.getStudyId() + "_" + exam.getContentId();
|
||||
//判断是否存在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());
|
||||
|
||||
//用于计算考试成绩
|
||||
CourseExam cexam=cexamDao.get(exam.getTestId());
|
||||
//完成处理,判断是否已存在
|
||||
@@ -92,6 +110,9 @@ public class StudyExamServiceImpl implements IStudyExamService{
|
||||
Float f=(Float)dao.findField("max(score)", FieldFilters.eq("contentId", exam.getContentId()));
|
||||
scItemDao.updateFieldById(exam.getStudyItemId(), "score", f);
|
||||
}
|
||||
//执行完毕 清除redis记录
|
||||
redisTemplate.delete(key);
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user