|
@@ -0,0 +1,74 @@
|
|
|
+package cn.com.qmth.examcloud.core.basic.service.cache;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import com.google.common.collect.Sets;
|
|
|
+
|
|
|
+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.PrivilegeRepo;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.RootOrgPrivilegeRelationRepo;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.OrgEntity;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.PrivilegeEntity;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.RootOrgPrivilegeRelationEntity;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.RootOrgPrivilegesCacheBean;
|
|
|
+import cn.com.qmth.examcloud.web.cache.RandomObjectRedisCache;
|
|
|
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class RootOrgPrrivilegesCache extends RandomObjectRedisCache<RootOrgPrivilegesCacheBean> {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PrivilegeRepo privilegeRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrgRepo orgRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RootOrgPrivilegeRelationRepo rootOrgPrivilegeRelationRepo;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RootOrgPrivilegesCacheBean loadFromResource(Object... keys) {
|
|
|
+ Long rootOrgId = (Long) keys[0];
|
|
|
+
|
|
|
+ OrgEntity orgEntity = GlobalHelper.getPresentEntity(orgRepo, rootOrgId, OrgEntity.class);
|
|
|
+ if (null != orgEntity.getParentId()) {
|
|
|
+ throw new StatusException("120001", "org [id=" + rootOrgId + "] is not a root org");
|
|
|
+ }
|
|
|
+ List<RootOrgPrivilegeRelationEntity> relationList = rootOrgPrivilegeRelationRepo
|
|
|
+ .findAllByRootOrgId(rootOrgId);
|
|
|
+
|
|
|
+ Set<Long> privilegeIdList = Sets.newHashSet();
|
|
|
+ Set<String> privilegeCodeList = Sets.newHashSet();
|
|
|
+
|
|
|
+ for (RootOrgPrivilegeRelationEntity cur : relationList) {
|
|
|
+ privilegeIdList.add(cur.getPrivilegeId());
|
|
|
+ PrivilegeEntity privilegeEntity = GlobalHelper.getPresentEntity(privilegeRepo,
|
|
|
+ cur.getPrivilegeId(), PrivilegeEntity.class);
|
|
|
+ privilegeCodeList.add(privilegeEntity.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ RootOrgPrivilegesCacheBean bean = new RootOrgPrivilegesCacheBean();
|
|
|
+ bean.setRootOrgId(rootOrgId);
|
|
|
+ bean.setPrivilegeIdList(privilegeIdList);
|
|
|
+ bean.setPrivilegeCodeList(privilegeCodeList);
|
|
|
+
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected String getKeyPrefix() {
|
|
|
+ return "$__ROOT_ORG_PRIVS:";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int getTimeout() {
|
|
|
+ // 10分钟
|
|
|
+ return 60 * 10;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|