Forráskód Böngészése

rename cache keys.

deason 2 éve
szülő
commit
c0859b61c7

+ 38 - 38
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/cache/OrgCache.java

@@ -1,52 +1,52 @@
 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.CacheConstants;
 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;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
 @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);
-
-		if (null == e) {
-			throw new StatusException("001250", "orgId is wrong");
-		}
-
-		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());
-		b.setDomainName(e.getDomainName());
-
-		return b;
-	}
-
-	@Override
-	protected String getKeyPrefix() {
-		return "B_ORG:";
-	}
-
-	@Override
-	protected int getTimeout() {
-		// 60分钟
-		return 60 * 60;
-	}
+    @Autowired
+    OrgRepo orgRepo;
+
+    @Override
+    public OrgCacheBean loadFromResource(Object... keys) {
+        Long orgId = (Long) keys[0];
+
+        OrgEntity e = GlobalHelper.getPresentEntity(orgRepo, orgId, OrgEntity.class);
+
+        if (null == e) {
+            throw new StatusException("001250", "orgId is wrong");
+        }
+
+        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());
+        b.setDomainName(e.getDomainName());
+
+        return b;
+    }
+
+    @Override
+    protected String getKeyPrefix() {
+        return CacheConstants.CACHE_B_ORG;
+    }
+
+    @Override
+    protected int getTimeout() {
+        // 60分钟
+        return 60 * 60;
+    }
 
 }

+ 42 - 42
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/cache/OrgPropertyCache.java

@@ -1,8 +1,5 @@
 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.commons.helpers.DynamicEnum;
 import cn.com.qmth.examcloud.commons.helpers.DynamicEnumManager;
@@ -11,61 +8,64 @@ import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
 import cn.com.qmth.examcloud.core.basic.dao.entity.OrgEntity;
 import cn.com.qmth.examcloud.core.basic.dao.entity.OrgPropertyEntity;
 import cn.com.qmth.examcloud.core.basic.dao.enums.OrgProperty;
+import cn.com.qmth.examcloud.support.CacheConstants;
 import cn.com.qmth.examcloud.support.cache.bean.OrgPropertyCacheBean;
 import cn.com.qmth.examcloud.web.cache.RandomObjectRedisCache;
 import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
 @Service
 public class OrgPropertyCache extends RandomObjectRedisCache<OrgPropertyCacheBean> {
 
-	@Autowired
-	OrgRepo orgRepo;
+    @Autowired
+    OrgRepo orgRepo;
 
-	@Autowired
-	OrgPropertyRepo orgPropertyRepo;
+    @Autowired
+    OrgPropertyRepo orgPropertyRepo;
 
-	@Override
-	public OrgPropertyCacheBean loadFromResource(Object... keys) {
-		Long orgId = (Long) keys[0];
-		String key = (String) keys[1];
+    @Override
+    public OrgPropertyCacheBean loadFromResource(Object... keys) {
+        Long orgId = (Long) keys[0];
+        String key = (String) keys[1];
 
-		OrgEntity orgEntity = null;
-		if (null != orgId) {
-			orgEntity = GlobalHelper.getEntity(orgRepo, orgId, OrgEntity.class);
-			if (null == orgEntity) {
-				throw new StatusException("001250", "orgId is wrong");
-			}
-		} else {
-			throw new StatusException("001253", "orgId and domainName are all null");
-		}
+        OrgEntity orgEntity = null;
+        if (null != orgId) {
+            orgEntity = GlobalHelper.getEntity(orgRepo, orgId, OrgEntity.class);
+            if (null == orgEntity) {
+                throw new StatusException("001250", "orgId is wrong");
+            }
+        } else {
+            throw new StatusException("001253", "orgId and domainName are all null");
+        }
 
-		DynamicEnumManager manager = OrgProperty.getDynamicEnumManager();
-		DynamicEnum de = manager.getByName(key);
-		OrgPropertyEntity one = orgPropertyRepo.findByOrgIdAndKeyId(orgEntity.getId(), de.getId());
+        DynamicEnumManager manager = OrgProperty.getDynamicEnumManager();
+        DynamicEnum de = manager.getByName(key);
+        OrgPropertyEntity one = orgPropertyRepo.findByOrgIdAndKeyId(orgEntity.getId(), de.getId());
 
-		OrgPropertyCacheBean b = new OrgPropertyCacheBean();
-		b.setOrgId(orgId);
-		b.setKey(key);
+        OrgPropertyCacheBean b = new OrgPropertyCacheBean();
+        b.setOrgId(orgId);
+        b.setKey(key);
 
-		if (null == one) {
-			b.setHasValue(false);
-			return b;
-		}
+        if (null == one) {
+            b.setHasValue(false);
+            return b;
+        }
 
-		b.setValue(one.getValue());
+        b.setValue(one.getValue());
 
-		return b;
-	}
+        return b;
+    }
 
-	@Override
-	protected String getKeyPrefix() {
-		return "B_ORG_PROP:";
-	}
+    @Override
+    protected String getKeyPrefix() {
+        return CacheConstants.CACHE_B_ORG_PROP;
+    }
 
-	@Override
-	protected int getTimeout() {
-		// 60分钟
-		return 60 * 60;
-	}
+    @Override
+    protected int getTimeout() {
+        // 60分钟
+        return 60 * 60;
+    }
 
 }

+ 36 - 36
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/cache/RootOrgCache.java

@@ -1,49 +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.CacheConstants;
 import cn.com.qmth.examcloud.support.cache.bean.RootOrgCacheBean;
 import cn.com.qmth.examcloud.web.cache.RandomObjectRedisCache;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
 @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() {
-		// 60分钟
-		return 60 * 60;
-	}
+    @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 CacheConstants.CACHE_B_ROOT_ORG;
+    }
+
+    @Override
+    protected int getTimeout() {
+        // 60分钟
+        return 60 * 60;
+    }
 
 }

+ 31 - 31
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/cache/ThirdPartyAccessCache.java

@@ -1,53 +1,53 @@
 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.ThirdPartyAccessRepo;
 import cn.com.qmth.examcloud.core.basic.dao.entity.ThirdPartyAccessEntity;
 import cn.com.qmth.examcloud.core.basic.dao.entity.ThirdPartyAccessPK;
+import cn.com.qmth.examcloud.support.CacheConstants;
 import cn.com.qmth.examcloud.support.cache.bean.ThirdPartyAccessCacheBean;
 import cn.com.qmth.examcloud.web.cache.RandomObjectRedisCache;
 import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
 @Service
 public class ThirdPartyAccessCache extends RandomObjectRedisCache<ThirdPartyAccessCacheBean> {
 
-	@Autowired
-	ThirdPartyAccessRepo thirdPartyAccessRepo;
+    @Autowired
+    ThirdPartyAccessRepo thirdPartyAccessRepo;
 
-	@Override
-	public ThirdPartyAccessCacheBean loadFromResource(Object... keys) {
-		Long rootOrgId = (Long) keys[0];
-		String appId = (String) keys[1];
+    @Override
+    public ThirdPartyAccessCacheBean loadFromResource(Object... keys) {
+        Long rootOrgId = (Long) keys[0];
+        String appId = (String) keys[1];
 
-		ThirdPartyAccessEntity entity = GlobalHelper.getEntity(thirdPartyAccessRepo,
-				new ThirdPartyAccessPK(rootOrgId, appId), ThirdPartyAccessEntity.class);
+        ThirdPartyAccessEntity entity = GlobalHelper.getEntity(thirdPartyAccessRepo,
+                new ThirdPartyAccessPK(rootOrgId, appId), ThirdPartyAccessEntity.class);
 
-		ThirdPartyAccessCacheBean bean = new ThirdPartyAccessCacheBean();
+        ThirdPartyAccessCacheBean bean = new ThirdPartyAccessCacheBean();
 
-		if (null == entity) {
-			bean.setHasValue(false);
-			return bean;
-		}
+        if (null == entity) {
+            bean.setHasValue(false);
+            return bean;
+        }
 
-		bean.setAppId(entity.getAppId());
-		bean.setRootOrgId(entity.getRootOrgId());
-		bean.setSecretKey(entity.getSecretKey());
-		bean.setTimeRange(entity.getTimeRange());
+        bean.setAppId(entity.getAppId());
+        bean.setRootOrgId(entity.getRootOrgId());
+        bean.setSecretKey(entity.getSecretKey());
+        bean.setTimeRange(entity.getTimeRange());
 
-		return bean;
-	}
+        return bean;
+    }
 
-	@Override
-	protected String getKeyPrefix() {
-		return "B_THIRD_PARTY_ACCESS:";
-	}
+    @Override
+    protected String getKeyPrefix() {
+        return CacheConstants.CACHE_B_THIRD_PARTY_ACCESS;
+    }
 
-	@Override
-	protected int getTimeout() {
-		// 5分钟
-		return 60 * 5;
-	}
+    @Override
+    protected int getTimeout() {
+        // 5分钟
+        return 60 * 5;
+    }
 
 }