|
@@ -0,0 +1,49 @@
|
|
|
+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.commons.exception.StatusException;
|
|
|
+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.RootOrgCacheBean;
|
|
|
+import cn.com.qmth.examcloud.web.cache.RandomObjectRedisCache;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class RootOrgCache extends RandomObjectRedisCache<RootOrgCacheBean> {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrgRepo orgRepo;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RootOrgCacheBean loadFromResource(Object... keys) {
|
|
|
+ String domain = (String) keys[0];
|
|
|
+
|
|
|
+ OrgEntity e = orgRepo.findByParentIdIsNullAndDomainName(domain);
|
|
|
+ if (null == e) {
|
|
|
+ throw new StatusException("003003", "顶级机构不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ RootOrgCacheBean b = new RootOrgCacheBean();
|
|
|
+ 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_ROOT_ORG:";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int getTimeout() {
|
|
|
+ // 10分钟
|
|
|
+ return 60 * 10;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|