|
@@ -0,0 +1,46 @@
|
|
|
|
+package cn.com.qmth.examcloud.core.basic.service.cache;
|
|
|
|
+
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.CourseRepo;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.CourseEntity;
|
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.CourseCacheBean;
|
|
|
|
+import cn.com.qmth.examcloud.web.cache.RandomObjectRedisCache;
|
|
|
|
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
|
+
|
|
|
|
+@Service
|
|
|
|
+public class CourseCache extends RandomObjectRedisCache<CourseCacheBean> {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ CourseRepo courseRepo;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public CourseCacheBean loadFromResource(Object... keys) {
|
|
|
|
+ Long courseId = (Long) keys[0];
|
|
|
|
+
|
|
|
|
+ CourseEntity c = GlobalHelper.getPresentEntity(courseRepo, courseId, CourseEntity.class);
|
|
|
|
+
|
|
|
|
+ CourseCacheBean b = new CourseCacheBean();
|
|
|
|
+ b.setId(c.getId());
|
|
|
|
+ b.setCode(c.getCode());
|
|
|
|
+ b.setLevel(c.getLevel().name());
|
|
|
|
+ b.setName(c.getName());
|
|
|
|
+ b.setRootOrgId(c.getRootOrgId());
|
|
|
|
+ b.setEnable(c.getEnable());
|
|
|
|
+
|
|
|
|
+ return b;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected String getKeyPrefix() {
|
|
|
|
+ return "B_COURSE:";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected int getTimeout() {
|
|
|
|
+ // 5分钟
|
|
|
|
+ return 60 * 5;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|