|
@@ -0,0 +1,54 @@
|
|
|
+package cn.com.qmth.examcloud.core.oe.admin.service.cache;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.dao.ExamStudentRepo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.dao.entity.ExamStudentEntity;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.ExamStudentCacheBean;
|
|
|
+import cn.com.qmth.examcloud.web.cache.RandomObjectRedisCache;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class ExamStudentCache extends RandomObjectRedisCache<ExamStudentCacheBean> {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamStudentRepo examStudentRepo;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ExamStudentCacheBean loadFromResource(Object... keys) {
|
|
|
+
|
|
|
+ Long studentId = (Long) keys[0];
|
|
|
+ Long examId = (Long) keys[1];
|
|
|
+ Long courseId = (Long) keys[2];
|
|
|
+
|
|
|
+ ExamStudentEntity e = examStudentRepo.findByStudentIdAndExamIdAndCourseId(studentId, examId,
|
|
|
+ courseId);
|
|
|
+ if (null == e) {
|
|
|
+ throw new StatusException("700001", "no data");
|
|
|
+ }
|
|
|
+
|
|
|
+ ExamStudentCacheBean b = new ExamStudentCacheBean();
|
|
|
+ b.setCourseId(e.getCourseId());
|
|
|
+ b.setEnable(e.getEnable());
|
|
|
+ b.setExamId(e.getExamId());
|
|
|
+ b.setExamStudentId(e.getExamStudentId());
|
|
|
+ b.setExtraNum(e.getExtraNum());
|
|
|
+ b.setStudentId(e.getStudentId());
|
|
|
+ b.setUsedNum(e.getUsedNum());
|
|
|
+
|
|
|
+ return b;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected String getKeyPrefix() {
|
|
|
+ return "OE_ES:";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int getTimeout() {
|
|
|
+ // 180天
|
|
|
+ return 60 * 60 * 24 * 180;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|