|
@@ -1,14 +1,13 @@
|
|
|
package cn.com.qmth.examcloud.core.basic.service.impl;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
import java.util.Set;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import com.google.common.collect.Lists;
|
|
|
-
|
|
|
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.PrivilegeGroupRepo;
|
|
@@ -22,6 +21,7 @@ import cn.com.qmth.examcloud.core.basic.dao.entity.RolePrivilegeRelationEntity;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.RolePrivilegeRelationPK;
|
|
|
import cn.com.qmth.examcloud.core.basic.service.RolePrivilegeService;
|
|
|
import cn.com.qmth.examcloud.core.basic.service.bean.RoleInfo;
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.cache.PrrivilegeRolesCache;
|
|
|
import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
|
|
|
/**
|
|
@@ -52,33 +52,58 @@ public class RolePrivilegeServiceImpl implements RolePrivilegeService {
|
|
|
@Autowired
|
|
|
UserRoleRelationRepo userRoleRelationRepo;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ PrrivilegeRolesCache prrivilegeRolesCache;
|
|
|
+
|
|
|
@Override
|
|
|
public void updateRolePrivilegeRelations(Long rootOrgId, Long roleId, Long privilegeGroupId,
|
|
|
Set<Long> privilegeIdSet) {
|
|
|
|
|
|
+ RoleEntity roleEntity = GlobalHelper.getEntity(roleRepo, roleId, RoleEntity.class);
|
|
|
+ Long roleRootOrgId = roleEntity.getRootOrgId();
|
|
|
+ if (null != roleRootOrgId) {
|
|
|
+ if (!roleRootOrgId.equals(rootOrgId)) {
|
|
|
+ throw new StatusException("620150", "角色和机构不匹配");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Long cur : privilegeIdSet) {
|
|
|
+ PrivilegeEntity privilegeEntity = GlobalHelper.getPresentEntity(privilegeRepo, cur,
|
|
|
+ PrivilegeEntity.class);
|
|
|
+ if (!privilegeEntity.getGroupId().equals(privilegeGroupId)) {
|
|
|
+ throw new StatusException("620151", "权限和权限组不匹配");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
List<PrivilegeEntity> privilegeList = privilegeRepo
|
|
|
.findAllByGroupIdOrderByWeightDesc(privilegeGroupId);
|
|
|
|
|
|
- List<RolePrivilegeRelationEntity> list = Lists.newArrayList();
|
|
|
-
|
|
|
for (PrivilegeEntity cur : privilegeList) {
|
|
|
- Long id = cur.getId();
|
|
|
- if (privilegeIdSet.contains(id)) {
|
|
|
- RolePrivilegeRelationEntity bean = new RolePrivilegeRelationEntity();
|
|
|
- bean.setRoleId(roleId);
|
|
|
- bean.setRootOrgId(rootOrgId);
|
|
|
- bean.setPrivilegeId(id);
|
|
|
- list.add(bean);
|
|
|
+ RolePrivilegeRelationPK pk = new RolePrivilegeRelationPK(roleId, cur.getId(),
|
|
|
+ rootOrgId);
|
|
|
+ Optional<RolePrivilegeRelationEntity> optional = rolePrivilegeRelationRepo.findById(pk);
|
|
|
+ if (optional.isPresent()) {
|
|
|
+ rolePrivilegeRelationRepo.delete(optional.get());
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- RolePrivilegeRelationPK pk = new RolePrivilegeRelationPK(roleId, id, rootOrgId);
|
|
|
- if (rolePrivilegeRelationRepo.findById(pk).isPresent()) {
|
|
|
- rolePrivilegeRelationRepo
|
|
|
- .deleteById(new RolePrivilegeRelationPK(roleId, id, rootOrgId));
|
|
|
- }
|
|
|
+ rolePrivilegeRelationRepo.deleteByRoleIdAndRootOrgId(roleId, rootOrgId);
|
|
|
+
|
|
|
+ for (Long cur : privilegeIdSet) {
|
|
|
+ RolePrivilegeRelationEntity bean = new RolePrivilegeRelationEntity();
|
|
|
+ bean.setRoleId(roleId);
|
|
|
+ bean.setRootOrgId(rootOrgId);
|
|
|
+ bean.setPrivilegeId(cur);
|
|
|
+
|
|
|
+ rolePrivilegeRelationRepo.save(bean);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Long cur : privilegeIdSet) {
|
|
|
+ PrivilegeEntity privilegeEntity = GlobalHelper.getPresentEntity(privilegeRepo, cur,
|
|
|
+ PrivilegeEntity.class);
|
|
|
+ prrivilegeRolesCache.remove(rootOrgId, privilegeEntity.getCode());
|
|
|
}
|
|
|
|
|
|
- rolePrivilegeRelationRepo.saveAll(list);
|
|
|
}
|
|
|
|
|
|
@Override
|