wangwei 5 tahun lalu
induk
melakukan
6d204fd003

+ 1 - 0
examcloud-core-oe-admin-dao/src/main/java/cn/com/qmth/examcloud/core/oe/admin/dao/ExamStudentRepo.java

@@ -101,5 +101,6 @@ public interface ExamStudentRepo extends JpaRepository<ExamStudentEntity, Long>,
 	@Query(nativeQuery = true, value = "update ec_oe_exam_student set finished=?2,normal_exam_times=?3,is_reexamine=?4,reexamine_completed=?5,update_time=?6 where id=?1")
 	void updateExamStudentStartExamStatusInfo(Long id, Boolean finished, int normalExamTimes, Boolean isReExamine, Boolean reexamineCompleted, Date updateTime);
 
+	ExamStudentEntity findByStudentIdAndExamIdAndCourseId(Long studentId,Long examId,Long courseId);
 
 }

+ 54 - 0
examcloud-core-oe-admin-service/src/main/java/cn/com/qmth/examcloud/core/oe/admin/service/cache/ExamStudentCache.java

@@ -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;
+	}
+
+}