Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
education
Project
Project
Details
Activity
Releases
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
李丛阳
education
Commits
17c50c7c
Commit
17c50c7c
authored
May 14, 2018
by
李博今
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加删除角色限制,并且查询时返回用户数
parent
d1e5d6ac
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
12 deletions
+51
-12
ResultServiceEnums.java
...main/java/org/rcisoft/core/result/ResultServiceEnums.java
+2
-0
SysRoleRepository.java
...main/java/org/rcisoft/sys/role/dao/SysRoleRepository.java
+4
-2
SysRole.java
src/main/java/org/rcisoft/sys/role/entity/SysRole.java
+4
-0
SysRoleServiceImpl.java
...org/rcisoft/sys/role/service/impl/SysRoleServiceImpl.java
+20
-10
SysUserMapper.java
src/main/java/org/rcisoft/sys/user/dao/SysUserMapper.java
+3
-0
roleMapper.xml
src/main/resources/mapper/sys/role/mapper/roleMapper.xml
+18
-0
No files found.
src/main/java/org/rcisoft/core/result/ResultServiceEnums.java
View file @
17c50c7c
...
...
@@ -175,6 +175,8 @@ public enum ResultServiceEnums {
STARTDATE_AFTER_ENDDATE
(
93
,
"开始时间比结束时间晚"
),
STARTDATE_EQUAL_ENDDATE
(
94
,
"开始时间等于结束时间"
),
ROLE_HAS_USER
(
95
,
"仍然有绑定此角色的用户,不可删除此角色"
),
;
private
Integer
code
;
...
...
src/main/java/org/rcisoft/sys/role/dao/SysRoleRepository.java
View file @
17c50c7c
...
...
@@ -32,9 +32,11 @@ public interface SysRoleRepository extends BaseMapper<SysRole> {
+
" <if test=\"roleName !=null and roleName != ''\">and role_name = #{roleName} </if> "
+
" order by create_date desc"
+
"</script>"
)
@ResultMap
(
value
=
"
BaseResultMap
"
)
@ResultMap
(
value
=
"
SelectAllAndUserNum
"
)
List
<
SysRole
>
queryRoles
(
SysRole
sysRole
);
//获得此角色的用户数
int
countUserNum
(
String
roleId
);
@Select
(
"<script>select * from s_role where "
+
"DEL_FLAG='0' "
...
...
src/main/java/org/rcisoft/sys/role/entity/SysRole.java
View file @
17c50c7c
...
...
@@ -8,6 +8,7 @@ import org.hibernate.validator.constraints.NotBlank;
import
org.rcisoft.core.entity.IdEntity
;
import
javax.persistence.Table
;
import
javax.persistence.Transient
;
/**
* Created by gaowenfeng on 2017/8/9.
...
...
@@ -24,4 +25,7 @@ public class SysRole extends IdEntity<SysRole> {
@Length
(
min
=
1
,
max
=
64
,
message
=
"长度最小为1,最大为50"
)
@NotBlank
private
String
code
;
@Transient
private
int
userNum
;
}
src/main/java/org/rcisoft/sys/role/service/impl/SysRoleServiceImpl.java
View file @
17c50c7c
...
...
@@ -13,6 +13,7 @@ import org.rcisoft.sys.dept.entity.DeptRole;
import
org.rcisoft.sys.role.dao.SysRoleRepository
;
import
org.rcisoft.sys.role.entity.SysRole
;
import
org.rcisoft.sys.role.service.SysRoleService
;
import
org.rcisoft.sys.user.dao.SysUserMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Isolation
;
...
...
@@ -35,6 +36,8 @@ public class SysRoleServiceImpl implements SysRoleService {
@Autowired
private
SysRoleRepository
sysRoleRepository
;
@Autowired
private
SysUserMapper
sysUserMapper
;
@Transactional
(
propagation
=
Propagation
.
REQUIRED
,
isolation
=
Isolation
.
DEFAULT
)
@Override
...
...
@@ -62,16 +65,23 @@ public class SysRoleServiceImpl implements SysRoleService {
@Transactional
(
propagation
=
Propagation
.
REQUIRED
,
isolation
=
Isolation
.
DEFAULT
)
@Override
public
int
removeRole
(
String
id
,
String
token
)
{
//删除该角色所有的关联信息
sysRoleRepository
.
deleteRoleMenuByRoleId
(
id
);
sysRoleRepository
.
deleteUserRoleByRoleId
(
id
);
SysRole
sysRole
=
sysRoleRepository
.
selectByPrimaryKey
(
id
);
sysRole
.
setDelFlag
(
DelStatus
.
DELETED
.
getStatus
());
UserUtil
.
setCurrentMergeOperation
(
sysRole
);
int
line
=
sysRoleRepository
.
updateByPrimaryKeySelective
(
sysRole
);
log
.
info
(
UserUtil
.
getUserInfoProp
(
token
,
UserUtil
.
USER_USERNAME
)+
"删除了ID为"
+
sysRole
.
getBusinessId
()+
"的角色信息"
);
return
line
;
//获得当前是此角色的人数
int
userCount
=
sysUserMapper
.
countUserByRole
(
id
);
//如果仍然有用户是此角色,则该角色不可删除
if
(
userCount
>
0
){
throw
new
ServiceException
(
ResultServiceEnums
.
ROLE_HAS_USER
);
}
else
{
//删除该角色所有的关联信息
sysRoleRepository
.
deleteRoleMenuByRoleId
(
id
);
sysRoleRepository
.
deleteUserRoleByRoleId
(
id
);
SysRole
sysRole
=
sysRoleRepository
.
selectByPrimaryKey
(
id
);
sysRole
.
setDelFlag
(
DelStatus
.
DELETED
.
getStatus
());
UserUtil
.
setCurrentMergeOperation
(
sysRole
);
int
line
=
sysRoleRepository
.
updateByPrimaryKeySelective
(
sysRole
);
log
.
info
(
UserUtil
.
getUserInfoProp
(
token
,
UserUtil
.
USER_USERNAME
)+
"删除了ID为"
+
sysRole
.
getBusinessId
()+
"的角色信息"
);
return
line
;
}
}
@Override
...
...
src/main/java/org/rcisoft/sys/user/dao/SysUserMapper.java
View file @
17c50c7c
...
...
@@ -95,4 +95,7 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
@Select
(
"select business_id from s_user where login_name = #{0} and del_flag = 0"
)
String
selectByLoginName
(
String
loginName
);
@Select
(
"select count(*) from s_r_user_role where role_id = #{roleId} "
)
int
countUserByRole
(
String
roleId
);
}
src/main/resources/mapper/sys/role/mapper/roleMapper.xml
View file @
17c50c7c
...
...
@@ -13,6 +13,24 @@
<result
column=
"update_date"
property=
"updateDate"
jdbcType=
"TIMESTAMP"
/>
<result
column=
"create_date"
property=
"createDate"
jdbcType=
"TIMESTAMP"
/>
</resultMap>
<resultMap
id=
"SelectAllAndUserNum"
type=
"org.rcisoft.sys.role.entity.SysRole"
>
<id
column=
"business_id"
jdbcType=
"VARCHAR"
property=
"businessId"
/>
<result
column=
"role_name"
jdbcType=
"VARCHAR"
property=
"roleName"
/>
<result
column=
"CODE"
jdbcType=
"VARCHAR"
property=
"code"
/>
<result
column=
"checked"
jdbcType=
"VARCHAR"
property=
"checked"
/>
<result
column=
"CREATE_BY"
property=
"createBy"
jdbcType=
"VARCHAR"
/>
<result
column=
"FLAG"
property=
"flag"
jdbcType=
"VARCHAR"
/>
<result
column=
"UPDATE_BY"
property=
"updateBy"
jdbcType=
"VARCHAR"
/>
<result
column=
"DEL_FLAG"
property=
"delFlag"
jdbcType=
"VARCHAR"
/>
<result
column=
"update_date"
property=
"updateDate"
jdbcType=
"TIMESTAMP"
/>
<result
column=
"create_date"
property=
"createDate"
jdbcType=
"TIMESTAMP"
/>
<association
property=
"userNum"
column=
"business_id"
select=
"countUserNum"
/>
</resultMap>
<select
id=
"countUserNum"
parameterType=
"string"
resultType=
"int"
>
select count(*)
from s_r_user_role where role_id = #{id}
</select>
<resultMap
id=
"drResultMap"
type=
"org.rcisoft.sys.dept.entity.DeptRole"
>
<result
column=
"drid"
jdbcType=
"VARCHAR"
property=
"id"
/>
<result
column=
"rid"
jdbcType=
"VARCHAR"
property=
"rid"
/>
...
...
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