|
@@ -0,0 +1,78 @@
|
|
|
+package cn.com.qmth.examcloud.core.examwork.service.cache;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.ExamSpecialSettingsRepo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamSpecialSettingsEntity;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.ExamStudentSettingsCacheBean;
|
|
|
+import cn.com.qmth.examcloud.web.cache.RandomObjectRedisCache;
|
|
|
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class ExamStudentSettingsCache extends RandomObjectRedisCache<ExamStudentSettingsCacheBean> {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamRepo examRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamSpecialSettingsRepo examSpecialSettingsRepo;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ExamStudentSettingsCacheBean loadFromResource(Object... keys) {
|
|
|
+ Long examId = (Long) keys[0];
|
|
|
+ Long studentId = (Long) keys[1];
|
|
|
+
|
|
|
+ ExamEntity exam = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
|
|
|
+
|
|
|
+ if (null == exam) {
|
|
|
+ throw new StatusException("002005", "考试不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ ExamStudentSettingsCacheBean bean = new ExamStudentSettingsCacheBean();
|
|
|
+
|
|
|
+ bean.setId(exam.getId());
|
|
|
+ bean.setBeginTime(exam.getBeginTime());
|
|
|
+ bean.setDuration(exam.getDuration());
|
|
|
+ bean.setEnable(exam.getEnable());
|
|
|
+ bean.setEndTime(exam.getEndTime());
|
|
|
+ bean.setExamTimes(exam.getExamTimes());
|
|
|
+ bean.setExamType(exam.getExamType().name());
|
|
|
+ bean.setName(exam.getName());
|
|
|
+ bean.setCode(exam.getCode());
|
|
|
+ bean.setRemark(exam.getRemark());
|
|
|
+ bean.setRootOrgId(exam.getRootOrgId());
|
|
|
+ bean.setExamLimit(exam.getExamLimit());
|
|
|
+
|
|
|
+ ExamSpecialSettingsEntity examOrgEntity = examSpecialSettingsRepo
|
|
|
+ .findByExamIdAndStudentIdAndOrgIdIsNullAndCourseIdIsNull(exam.getId(), studentId);
|
|
|
+ if (null != examOrgEntity) {
|
|
|
+ if (null != examOrgEntity.getBeginTime()) {
|
|
|
+ bean.setBeginTime(examOrgEntity.getBeginTime());
|
|
|
+ }
|
|
|
+ if (null != examOrgEntity.getEndTime()) {
|
|
|
+ bean.setEndTime(examOrgEntity.getEndTime());
|
|
|
+ }
|
|
|
+ if (null != examOrgEntity.getExamLimit()) {
|
|
|
+ bean.setExamLimit(examOrgEntity.getExamLimit());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected String getKeyPrefix() {
|
|
|
+ return "E_EXAM_STUDENT_SETTINGS:";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int getTimeout() {
|
|
|
+ // 2分钟
|
|
|
+ return 60 * 2;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|