diff --git a/src/main/java/com/ruoyi/common/constant/UserConstants.java b/src/main/java/com/ruoyi/common/constant/UserConstants.java index cff69c1f..51141843 100644 --- a/src/main/java/com/ruoyi/common/constant/UserConstants.java +++ b/src/main/java/com/ruoyi/common/constant/UserConstants.java @@ -48,6 +48,10 @@ public class UserConstants /** 角色名称是否唯一的返回结果码 */ public final static String ROLE_NAME_UNIQUE = "0"; public final static String ROLE_NAME_NOT_UNIQUE = "1"; + + /** 角色权限是否唯一的返回结果码 */ + public final static String ROLE_KEY_UNIQUE = "0"; + public final static String ROLE_KEY_NOT_UNIQUE = "1"; /** 菜单名称是否唯一的返回结果码 */ public final static String MENU_NAME_UNIQUE = "0"; diff --git a/src/main/java/com/ruoyi/project/system/role/controller/RoleController.java b/src/main/java/com/ruoyi/project/system/role/controller/RoleController.java index 7b1ff9a9..6a333d5d 100644 --- a/src/main/java/com/ruoyi/project/system/role/controller/RoleController.java +++ b/src/main/java/com/ruoyi/project/system/role/controller/RoleController.java @@ -146,6 +146,21 @@ public class RoleController extends BaseController } return uniqueFlag; } + + /** + * 校验角色权限 + */ + @PostMapping("/checkRoleKeyUnique") + @ResponseBody + public String checkRoleKeyUnique(Role role) + { + String uniqueFlag = "0"; + if (role != null) + { + uniqueFlag = roleService.checkRoleKeyUnique(role); + } + return uniqueFlag; + } /** * 选择菜单树 diff --git a/src/main/java/com/ruoyi/project/system/role/mapper/RoleMapper.java b/src/main/java/com/ruoyi/project/system/role/mapper/RoleMapper.java index 1cc4fe1c..eba5aa90 100644 --- a/src/main/java/com/ruoyi/project/system/role/mapper/RoleMapper.java +++ b/src/main/java/com/ruoyi/project/system/role/mapper/RoleMapper.java @@ -81,5 +81,13 @@ public interface RoleMapper * @return 角色信息 */ public Role checkRoleNameUnique(String roleName); + + /** + * 校验角色权限是否唯一 + * + * @param roleKey 角色权限 + * @return 角色信息 + */ + public Role checkRoleKeyUnique(String roleKey); } diff --git a/src/main/java/com/ruoyi/project/system/role/service/IRoleService.java b/src/main/java/com/ruoyi/project/system/role/service/IRoleService.java index 02c6ccca..d522e9db 100644 --- a/src/main/java/com/ruoyi/project/system/role/service/IRoleService.java +++ b/src/main/java/com/ruoyi/project/system/role/service/IRoleService.java @@ -91,6 +91,14 @@ public interface IRoleService * @return 结果 */ public String checkRoleNameUnique(Role role); + + /** + * 校验角色权限是否唯一 + * + * @param role 角色信息 + * @return 结果 + */ + public String checkRoleKeyUnique(Role role); /** * 通过角色ID查询角色使用数量 diff --git a/src/main/java/com/ruoyi/project/system/role/service/RoleServiceImpl.java b/src/main/java/com/ruoyi/project/system/role/service/RoleServiceImpl.java index cae6b72a..36c2ea52 100644 --- a/src/main/java/com/ruoyi/project/system/role/service/RoleServiceImpl.java +++ b/src/main/java/com/ruoyi/project/system/role/service/RoleServiceImpl.java @@ -224,6 +224,24 @@ public class RoleServiceImpl implements IRoleService } return UserConstants.ROLE_NAME_UNIQUE; } + + /** + * 校验角色权限是否唯一 + * + * @param role 角色信息 + * @return 结果 + */ + @Override + public String checkRoleKeyUnique(Role role) + { + Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId(); + Role info = roleMapper.checkRoleKeyUnique(role.getRoleKey()); + if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) + { + return UserConstants.ROLE_KEY_NOT_UNIQUE; + } + return UserConstants.ROLE_KEY_UNIQUE; + } /** * 通过角色ID查询角色使用数量 diff --git a/src/main/resources/mybatis/system/RoleMapper.xml b/src/main/resources/mybatis/system/RoleMapper.xml index 04ab82ae..3733bd9e 100644 --- a/src/main/resources/mybatis/system/RoleMapper.xml +++ b/src/main/resources/mybatis/system/RoleMapper.xml @@ -64,6 +64,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where role_name=#{roleName} + + delete from sys_role where role_id = #{roleId} diff --git a/src/main/resources/templates/system/role/add.html b/src/main/resources/templates/system/role/add.html index 679ebd90..208abfa0 100644 --- a/src/main/resources/templates/system/role/add.html +++ b/src/main/resources/templates/system/role/add.html @@ -98,6 +98,20 @@ }, roleKey:{ required:true, + remote: { + url: ctx + "system/role/checkRoleKeyUnique", + type: "post", + dataType: "json", + data: { + "roleName" : function() { + return $.trim($("#roleName").val()); + } + }, + dataFilter: function(data, type) { + if (data == "0") return true; + else return false; + } + } }, roleSort:{ required:true, @@ -106,7 +120,10 @@ }, messages: { "roleName": { - remote: "角色已经存在" + remote: "角色名称已经存在" + }, + "roleKey": { + remote: "角色权限已经存在" } }, submitHandler:function(form){ diff --git a/src/main/resources/templates/system/role/edit.html b/src/main/resources/templates/system/role/edit.html index 02271236..ef3e10ef 100644 --- a/src/main/resources/templates/system/role/edit.html +++ b/src/main/resources/templates/system/role/edit.html @@ -102,6 +102,23 @@ }, roleKey:{ required:true, + remote: { + url: ctx + "system/role/checkRoleKeyUnique", + type: "post", + dataType: "json", + data: { + "roleId": function() { + return $("input[name='roleId']").val(); + }, + "roleKey": function() { + return $("input[name='roleKey']").val(); + } + }, + dataFilter: function(data, type) { + if (data == "0") return true; + else return false; + } + } }, roleSort:{ required:true, @@ -110,7 +127,10 @@ }, messages: { "roleName": { - remote: "角色已经存在" + remote: "角色名称已经存在" + }, + "roleKey": { + remote: "角色权限已经存在" } }, submitHandler:function(form){