WANG il y a 5 ans
Parent
commit
74ff0871a5

+ 62 - 0
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/cache/ExamSettingsCache.java

@@ -0,0 +1,62 @@
+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.support.cache.bean.ExamSettingsCacheBean;
+import cn.com.qmth.examcloud.web.cache.RandomObjectRedisCache;
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
+
+@Service
+public class ExamSettingsCache extends RandomObjectRedisCache<ExamSettingsCacheBean> {
+
+	@Autowired
+	ExamRepo examRepo;
+
+	@Autowired
+	ExamSpecialSettingsRepo examSpecialSettingsRepo;
+
+	@Override
+	public ExamSettingsCacheBean loadFromResource(Object... keys) {
+		Long examId = (Long) keys[0];
+
+		ExamEntity exam = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
+
+		if (null == exam) {
+			throw new StatusException("002005", "考试不存在");
+		}
+
+		ExamSettingsCacheBean bean = new ExamSettingsCacheBean();
+
+		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());
+
+		return bean;
+	}
+
+	@Override
+	protected String getKeyPrefix() {
+		return "E_EXAM:";
+	}
+
+	@Override
+	protected int getTimeout() {
+		// 1分钟
+		return 60;
+	}
+
+}