|
@@ -3,21 +3,25 @@ package cn.com.qmth.examcloud.core.basic.service.impl;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
|
|
|
-import javax.transaction.Transactional;
|
|
|
-
|
|
|
+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.base.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.PrivilegeGroupRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.PrivilegeRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.RolePrivilegeRelationRepo;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.RoleRepo;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.UserRoleRelationRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.PrivilegeEntity;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.RoleEntity;
|
|
|
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;
|
|
|
|
|
|
/**
|
|
|
* 类注释
|
|
@@ -27,7 +31,6 @@ import cn.com.qmth.examcloud.core.basic.service.RolePrivilegeService;
|
|
|
* @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
*/
|
|
|
@Service
|
|
|
-@Transactional
|
|
|
public class RolePrivilegeServiceImpl implements RolePrivilegeService {
|
|
|
|
|
|
@Autowired
|
|
@@ -36,6 +39,9 @@ public class RolePrivilegeServiceImpl implements RolePrivilegeService {
|
|
|
@Autowired
|
|
|
OrgRepo orgRepo;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ RoleRepo roleRepo;
|
|
|
+
|
|
|
@Autowired
|
|
|
RolePrivilegeRelationRepo rolePrivilegeRelationRepo;
|
|
|
|
|
@@ -43,7 +49,7 @@ public class RolePrivilegeServiceImpl implements RolePrivilegeService {
|
|
|
PrivilegeGroupRepo privilegeGroupRepo;
|
|
|
|
|
|
@Autowired
|
|
|
- RolePrivilegeService rolePrivilegeService;
|
|
|
+ UserRoleRelationRepo userRoleRelationRepo;
|
|
|
|
|
|
@Override
|
|
|
public void updateRolePrivilegeRelations(Long rootOrgId, Long roleId, Long privilegeGroupId,
|
|
@@ -74,4 +80,78 @@ public class RolePrivilegeServiceImpl implements RolePrivilegeService {
|
|
|
rolePrivilegeRelationRepo.save(list);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public RoleEntity saveRole(RoleInfo info) {
|
|
|
+ String code = info.getCode();
|
|
|
+ String name = info.getName();
|
|
|
+ Long rootOrgId = info.getRootOrgId();
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(code)) {
|
|
|
+ throw new StatusException("B-620001", "code is blank");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(name)) {
|
|
|
+ throw new StatusException("B-620002", "name is blank");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null == rootOrgId) {
|
|
|
+ throw new StatusException("B-620003", "rootOrgId is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ RoleEntity roleEntity = roleRepo.findByCodeAndRootOrgId(code, rootOrgId);
|
|
|
+
|
|
|
+ if (null == roleEntity) {
|
|
|
+ roleEntity = new RoleEntity();
|
|
|
+ roleEntity.setCode(code);
|
|
|
+ roleEntity.setName(name);
|
|
|
+ roleEntity.setRootOrgId(rootOrgId);
|
|
|
+ }
|
|
|
+
|
|
|
+ RoleEntity saved = roleRepo.save(roleEntity);
|
|
|
+
|
|
|
+ return saved;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RoleEntity deleteRole(RoleInfo info, boolean cascade) {
|
|
|
+ Long id = info.getId();
|
|
|
+ String code = info.getCode();
|
|
|
+ Long rootOrgId = info.getRootOrgId();
|
|
|
+
|
|
|
+ if (null == rootOrgId) {
|
|
|
+ throw new StatusException("B-620001", "name is blank");
|
|
|
+ }
|
|
|
+
|
|
|
+ RoleEntity roleEntity = null;
|
|
|
+ if (null != id) {
|
|
|
+ roleEntity = roleRepo.findOne(id);
|
|
|
+ } else if (StringUtils.isNotBlank(code)) {
|
|
|
+ roleEntity = roleRepo.findByCodeAndRootOrgId(code, rootOrgId);
|
|
|
+ } else {
|
|
|
+ throw new StatusException("B-620002", "id,code can not be all null");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null == roleEntity) {
|
|
|
+ throw new StatusException("B-620003", "roleEntity is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!cascade) {
|
|
|
+ if (0 < rolePrivilegeRelationRepo.countByRoleIdAndRootOrgId(roleEntity.getId(),
|
|
|
+ rootOrgId)) {
|
|
|
+ throw new StatusException("B-620004", "角色已关联权限");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (0 < userRoleRelationRepo.countByRoleId(roleEntity.getId())) {
|
|
|
+ throw new StatusException("B-620004", "角色已关联用户");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ roleRepo.delete(roleEntity);
|
|
|
+
|
|
|
+ rolePrivilegeRelationRepo.deleteByRoleIdAndRootOrgId(roleEntity.getId(), rootOrgId);
|
|
|
+ userRoleRelationRepo.deleteByRoleId(roleEntity.getId());
|
|
|
+
|
|
|
+ return roleEntity;
|
|
|
+ }
|
|
|
+
|
|
|
}
|