Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fgqyxxlr
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yaru
fgqyxxlr
Commits
336faf6f
Commit
336faf6f
authored
Aug 01, 2018
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
角色权限唯一校验
parent
982ce06c
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
97 additions
and
2 deletions
+97
-2
src/main/java/com/ruoyi/common/constant/UserConstants.java
+4
-0
src/main/java/com/ruoyi/project/system/role/controller/RoleController.java
+15
-0
src/main/java/com/ruoyi/project/system/role/mapper/RoleMapper.java
+8
-0
src/main/java/com/ruoyi/project/system/role/service/IRoleService.java
+8
-0
src/main/java/com/ruoyi/project/system/role/service/RoleServiceImpl.java
+18
-0
src/main/resources/mybatis/system/RoleMapper.xml
+5
-0
src/main/resources/templates/system/role/add.html
+18
-1
src/main/resources/templates/system/role/edit.html
+21
-1
No files found.
src/main/java/com/ruoyi/common/constant/UserConstants.java
View file @
336faf6f
...
...
@@ -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"
;
...
...
src/main/java/com/ruoyi/project/system/role/controller/RoleController.java
View file @
336faf6f
...
...
@@ -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
;
}
/**
* 选择菜单树
...
...
src/main/java/com/ruoyi/project/system/role/mapper/RoleMapper.java
View file @
336faf6f
...
...
@@ -81,5 +81,13 @@ public interface RoleMapper
* @return 角色信息
*/
public
Role
checkRoleNameUnique
(
String
roleName
);
/**
* 校验角色权限是否唯一
*
* @param roleKey 角色权限
* @return 角色信息
*/
public
Role
checkRoleKeyUnique
(
String
roleKey
);
}
src/main/java/com/ruoyi/project/system/role/service/IRoleService.java
View file @
336faf6f
...
...
@@ -91,6 +91,14 @@ public interface IRoleService
* @return 结果
*/
public
String
checkRoleNameUnique
(
Role
role
);
/**
* 校验角色权限是否唯一
*
* @param role 角色信息
* @return 结果
*/
public
String
checkRoleKeyUnique
(
Role
role
);
/**
* 通过角色ID查询角色使用数量
...
...
src/main/java/com/ruoyi/project/system/role/service/RoleServiceImpl.java
View file @
336faf6f
...
...
@@ -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查询角色使用数量
...
...
src/main/resources/mybatis/system/RoleMapper.xml
View file @
336faf6f
...
...
@@ -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>
...
...
src/main/resources/templates/system/role/add.html
View file @
336faf6f
...
...
@@ -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
){
...
...
src/main/resources/templates/system/role/edit.html
View file @
336faf6f
...
...
@@ -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
){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment