wangliang пре 3 година
родитељ
комит
d8ec06217c

+ 12 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysRoleServiceImpl.java

@@ -224,6 +224,18 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
             } else if (Objects.nonNull(schoolId)) {
                 role.setSchoolId(schoolId);
             }
+            // 系统默认内置角色(不允许和系统默认角色重名)
+            List<String> defaultRoleNames = this.list(new QueryWrapper<SysRole>().lambda()
+                            .eq(SysRole::getDefaultRole, true)
+                            .eq(SysRole::getEnable, true))
+                    .stream()
+                    .map(SysRole::getName)
+                    .distinct()
+                    .collect(Collectors.toList());
+            String roleName = role.getName();
+            if (defaultRoleNames.contains(roleName)) {
+                throw ExceptionResultEnum.ERROR.exception("自定义角色名称不能和系统默认角色【" + roleName + "】同名");
+            }
             if (Objects.nonNull(role.getId())) {//编辑
                 List<SysRolePrivilege> sysRolePrivilegeList = commonCacheService.rolePrivilegeCache(role.getId());
                 QueryWrapper<SysPrivilege> sysPrivilegeQueryWrapper = new QueryWrapper<>();