|
@@ -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.OrgRepo;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.OrgEntity;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.OrgCacheBean;
|
|
|
+import cn.com.qmth.examcloud.web.cache.RandomObjectRedisCache;
|
|
|
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class OrgCache extends RandomObjectRedisCache<OrgCacheBean> {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrgRepo orgRepo;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public OrgCacheBean loadFromResource(Object... keys) {
|
|
|
+ Long orgId = (Long) keys[0];
|
|
|
+
|
|
|
+ OrgEntity e = GlobalHelper.getPresentEntity(orgRepo, orgId, OrgEntity.class);
|
|
|
+
|
|
|
+ OrgCacheBean b = new OrgCacheBean();
|
|
|
+ b.setCode(e.getCode());
|
|
|
+ b.setEnable(e.getEnable());
|
|
|
+ b.setId(e.getId());
|
|
|
+ b.setName(e.getName());
|
|
|
+ b.setParentId(e.getParentId());
|
|
|
+ b.setRootId(e.getRootId());
|
|
|
+
|
|
|
+ return b;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected String getKeyPrefix() {
|
|
|
+ return "B_ORG:";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int getTimeout() {
|
|
|
+ // 5分钟
|
|
|
+ return 60 * 5;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|