角色权限唯一校验

dep_wangsr
RuoYi 6 years ago committed by Limy
parent a4ce0ba066
commit ee042d34e0

@ -48,6 +48,10 @@ public class UserConstants
/** 角色名称是否唯一的返回结果码 */ /** 角色名称是否唯一的返回结果码 */
public final static String ROLE_NAME_UNIQUE = "0"; public final static String ROLE_NAME_UNIQUE = "0";
public final static String ROLE_NAME_NOT_UNIQUE = "1"; 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"; public final static String MENU_NAME_UNIQUE = "0";

@ -146,6 +146,21 @@ public class RoleController extends BaseController
} }
return uniqueFlag; return uniqueFlag;
} }
/**
*
*/
@PostMapping("/checkRoleKeyUnique")
@ResponseBody
public String checkRoleKeyUnique(Role role)
{
String uniqueFlag = "0";
if (role != null)
{
uniqueFlag = roleService.checkRoleKeyUnique(role);
}
return uniqueFlag;
}
/** /**
* *

@ -81,5 +81,13 @@ public interface RoleMapper
* @return * @return
*/ */
public Role checkRoleNameUnique(String roleName); public Role checkRoleNameUnique(String roleName);
/**
*
*
* @param roleKey
* @return
*/
public Role checkRoleKeyUnique(String roleKey);
} }

@ -91,6 +91,14 @@ public interface IRoleService
* @return * @return
*/ */
public String checkRoleNameUnique(Role role); public String checkRoleNameUnique(Role role);
/**
*
*
* @param role
* @return
*/
public String checkRoleKeyUnique(Role role);
/** /**
* ID使 * ID使

@ -224,6 +224,24 @@ public class RoleServiceImpl implements IRoleService
} }
return UserConstants.ROLE_NAME_UNIQUE; 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使 * ID使

@ -64,6 +64,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where role_name=#{roleName} where role_name=#{roleName}
</select> </select>
<select id="checkRoleKeyUnique" parameterType="String" resultMap="RoleResult">
<include refid="selectRoleVo"/>
where role_key=#{roleKey}
</select>
<delete id="deleteRoleById" parameterType="Long"> <delete id="deleteRoleById" parameterType="Long">
delete from sys_role where role_id = #{roleId} delete from sys_role where role_id = #{roleId}
</delete> </delete>

@ -98,6 +98,20 @@
}, },
roleKey:{ roleKey:{
required:true, 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:{ roleSort:{
required:true, required:true,
@ -106,7 +120,10 @@
}, },
messages: { messages: {
"roleName": { "roleName": {
remote: "角色已经存在" remote: "角色名称已经存在"
},
"roleKey": {
remote: "角色权限已经存在"
} }
}, },
submitHandler:function(form){ submitHandler:function(form){

@ -102,6 +102,23 @@
}, },
roleKey:{ roleKey:{
required:true, 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:{ roleSort:{
required:true, required:true,
@ -110,7 +127,10 @@
}, },
messages: { messages: {
"roleName": { "roleName": {
remote: "角色已经存在" remote: "角色名称已经存在"
},
"roleKey": {
remote: "角色权限已经存在"
} }
}, },
submitHandler:function(form){ submitHandler:function(form){

Loading…
Cancel
Save