|
@@ -0,0 +1,71 @@
|
|
|
+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;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.OrgPropertyRepo;
|
|
|
+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.cache.bean.OrgPropertyCacheBean;
|
|
|
+import cn.com.qmth.examcloud.web.cache.RandomObjectRedisCache;
|
|
|
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class OrgPropertyCache extends RandomObjectRedisCache<OrgPropertyCacheBean> {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrgRepo orgRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrgPropertyRepo orgPropertyRepo;
|
|
|
+
|
|
|
+ @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");
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ if (null == one) {
|
|
|
+ b.setHasValue(false);
|
|
|
+ return b;
|
|
|
+ }
|
|
|
+
|
|
|
+ b.setValue(one.getValue());
|
|
|
+
|
|
|
+ return b;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected String getKeyPrefix() {
|
|
|
+ return "B_ORG_PROP:";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int getTimeout() {
|
|
|
+ // 60分钟
|
|
|
+ return 60 * 60;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|