wangwei 7 éve
szülő
commit
c5775ef241

+ 7 - 1
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/PrivilegeController.java

@@ -2,6 +2,7 @@ package cn.com.qmth.examcloud.core.basic.api.controller;
 
 import java.util.List;
 
+import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Sort;
 import org.springframework.web.bind.annotation.DeleteMapping;
@@ -106,7 +107,7 @@ public class PrivilegeController extends ControllerSupport {
 			if (null == parentPrivilege) {
 				throw new StatusException("B-020002", "父权限不存在");
 			}
-			if (parentPrivilege.getGroupId().equals(privilege.getGroupId())) {
+			if (!parentPrivilege.getGroupId().equals(privilege.getGroupId())) {
 				throw new StatusException("B-020003", "权限组错误");
 			}
 		}
@@ -150,6 +151,11 @@ public class PrivilegeController extends ControllerSupport {
 		if (null == privilege) {
 			throw new StatusException("B-020004", "权限不存在");
 		}
+
+		List<Privilege> children = privilegeRepo.findAllByParentId(privilege.getId());
+		if (CollectionUtils.isNotEmpty(children)) {
+			throw new StatusException("B-020005", "存在子权限");
+		}
 		privilegeRepo.delete(id);
 	}
 

+ 2 - 0
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/PrivilegeRepo.java

@@ -23,6 +23,8 @@ public interface PrivilegeRepo
 
 	List<Privilege> findAllByGroupId(Long groupId);
 
+	List<Privilege> findAllByParentId(Long parentId);
+
 	List<Privilege> findAllByIdIn(List<Long> idList);
 
 }