角色权限唯一校验

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

@ -49,6 +49,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";
public final static String MENU_NAME_NOT_UNIQUE = "1";

@ -147,6 +147,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;
}
/**
*
*/

@ -82,4 +82,12 @@ public interface RoleMapper
*/
public Role checkRoleNameUnique(String roleName);
/**
*
*
* @param roleKey
* @return
*/
public Role checkRoleKeyUnique(String roleKey);
}

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

@ -225,6 +225,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使
*

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

@ -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){

@ -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){

Loading…
Cancel
Save