Skip to content

Commit 6724c79

Browse files
committed
feat: 添加Role关系表删除方法
1 parent bfa410b commit 6724c79

4 files changed

Lines changed: 151 additions & 18 deletions

File tree

system/src/main/java/top/cadecode/uniboot/system/mapper/SysRoleMapper.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,22 @@
1616
@Mapper
1717
public interface SysRoleMapper extends BaseMapper<SysRole> {
1818

19-
List<SysRole> listByUserId(@Param("userId") Long userId);
19+
List<SysRole> listByUserIds(@Param("userIds") List<Long> userIds);
2020

21-
List<SysRole> listByMenuId(@Param("menuId") Long menuId);
21+
List<SysRole> listByMenuIds(@Param("menuIds") List<Long> menuIds);
2222

23-
List<SysRole> listByApiId(@Param("apiId") Long apiId);
23+
List<SysRole> listByApiIds(@Param("apiIds") List<Long> apiIds);
2424

25+
int deleteRoleUserByUserIds(@Param("userIds") List<Long> userIds);
26+
27+
int deleteRoleUserByRoleIds(@Param("roleIds") List<Long> roleIds);
28+
29+
int deleteRoleMenuByMenuIds(@Param("menuIds") List<Long> menuIds);
30+
31+
int deleteRoleMenuByRoleIds(@Param("roleIds") List<Long> roleIds);
32+
33+
int deleteRoleApiByApiIds(@Param("apiIds") List<Long> apiIds);
34+
35+
int deleteRoleApiByRoleIds(@Param("roleIds") List<Long> roleIds);
2536

2637
}

system/src/main/java/top/cadecode/uniboot/system/service/SysRoleService.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,21 @@
1313
*/
1414
public interface SysRoleService extends IService<SysRole> {
1515

16-
List<SysRole> listByUserId( Long userId);
16+
List<SysRole> listByUserIds(List<Long> userIds);
1717

18-
List<SysRole> listByMenuId(Long menuId);
18+
List<SysRole> listByMenuIds(List<Long> menuIds);
1919

20-
List<SysRole> listByApiId(Long apiId);
20+
List<SysRole> listByApiIds(List<Long> apiIds);
21+
22+
int deleteRoleUserByUserIds(List<Long> userIds);
23+
24+
int deleteRoleUserByRoleIds(List<Long> roleIds);
25+
26+
int deleteRoleMenuByMenuIds(List<Long> menuIds);
27+
28+
int deleteRoleMenuByRoleIds(List<Long> roleIds);
29+
30+
int deleteRoleApiByApiIds(List<Long> apiIds);
31+
32+
int deleteRoleApiByRoleIds(List<Long> roleIds);
2133
}

system/src/main/java/top/cadecode/uniboot/system/serviceimpl/SysRoleServiceImpl.java

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,48 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
2222
private final SysRoleMapper sysRoleMapper;
2323

2424
@Override
25-
public List<SysRole> listByUserId(Long userId) {
26-
return sysRoleMapper.listByUserId(userId);
25+
public List<SysRole> listByUserIds(List<Long> userIds) {
26+
return sysRoleMapper.listByUserIds(userIds);
2727
}
2828

2929
@Override
30-
public List<SysRole> listByMenuId(Long menuId) {
31-
return sysRoleMapper.listByMenuId(menuId);
30+
public List<SysRole> listByMenuIds(List<Long> menuIds) {
31+
return sysRoleMapper.listByMenuIds(menuIds);
3232
}
3333

3434
@Override
35-
public List<SysRole> listByApiId(Long apiId) {
36-
return sysRoleMapper.listByApiId(apiId);
35+
public List<SysRole> listByApiIds(List<Long> apiIds) {
36+
return sysRoleMapper.listByApiIds(apiIds);
37+
}
38+
39+
@Override
40+
public int deleteRoleUserByUserIds(List<Long> userIds) {
41+
return sysRoleMapper.deleteRoleUserByUserIds(userIds);
42+
}
43+
44+
@Override
45+
public int deleteRoleUserByRoleIds(List<Long> roleIds) {
46+
return sysRoleMapper.deleteRoleUserByRoleIds(roleIds);
47+
}
48+
49+
@Override
50+
public int deleteRoleMenuByMenuIds(List<Long> menuIds) {
51+
return sysRoleMapper.deleteRoleMenuByMenuIds(menuIds);
52+
}
53+
54+
@Override
55+
public int deleteRoleMenuByRoleIds(List<Long> roleIds) {
56+
return sysRoleMapper.deleteRoleMenuByRoleIds(roleIds);
57+
58+
}
59+
60+
@Override
61+
public int deleteRoleApiByApiIds(List<Long> apiIds) {
62+
return sysRoleMapper.deleteRoleApiByApiIds(apiIds);
63+
}
64+
65+
@Override
66+
public int deleteRoleApiByRoleIds(List<Long> roleIds) {
67+
return sysRoleMapper.deleteRoleApiByRoleIds(roleIds);
3768
}
3869
}
Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,101 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
33
<mapper namespace="top.cadecode.uniboot.system.mapper.SysRoleMapper">
4-
<select id="listByUserId" resultType="top.cadecode.uniboot.system.bean.po.SysRole">
4+
<select id="listByUserIds" resultType="top.cadecode.uniboot.system.bean.po.SysRole">
55
SELECT *
66
FROM sys_role_user ru
77
INNER JOIN sys_role r ON ru.role_id = r.id
8-
WHERE ru.user_id = #{userId}
8+
<if test="userIds != null and userIds.size > 0">
9+
WHERE ru.user_id IN (
10+
<foreach collection="userIds" item="id" separator=",">
11+
#{id}
12+
</foreach>
13+
)
14+
</if>
915
</select>
10-
<select id="listByMenuId" resultType="top.cadecode.uniboot.system.bean.po.SysRole">
16+
<select id="listByMenuIds" resultType="top.cadecode.uniboot.system.bean.po.SysRole">
1117
SELECT *
1218
FROM sys_role_menu rm
1319
INNER JOIN sys_role r ON rm.role_id = r.id
14-
WHERE rm.menu_id = #{menuId}
20+
<if test="menuIds != null and menuIds.size > 0">
21+
WHERE rm.menu_id IN (
22+
<foreach collection="menuIds" item="id" separator=",">
23+
#{id}
24+
</foreach>
25+
)
26+
</if>
1527
</select>
16-
<select id="listByApiId" resultType="top.cadecode.uniboot.system.bean.po.SysRole">
28+
<select id="listByApiIds" resultType="top.cadecode.uniboot.system.bean.po.SysRole">
1729
SELECT *
1830
FROM sys_role_api ra
1931
INNER JOIN sys_role r ON ra.role_id = r.id
20-
WHERE ra.api_id = #{apiId}
32+
<if test="apiIds != null and apiIds.size > 0">
33+
WHERE ra.api_id IN (
34+
<foreach collection="apiIds" item="id" separator=",">
35+
#{id}
36+
</foreach>
37+
)
38+
</if>
2139
</select>
40+
<delete id="deleteRoleUserByUserIds">
41+
DELETE FROM sys_role_user ru
42+
<if test="userIds != null and userIds.size > 0">
43+
WHERE ru.user_id IN (
44+
<foreach collection="userIds" item="id" separator=",">
45+
#{id}
46+
</foreach>
47+
)
48+
</if>
49+
</delete>
50+
<delete id="deleteRoleUserByRoleIds">
51+
DELETE FROM sys_role_user ru
52+
<if test="userIds != null and userIds.size > 0">
53+
WHERE ru.role_id IN (
54+
<foreach collection="roleIds" item="id" separator=",">
55+
#{id}
56+
</foreach>
57+
)
58+
</if>
59+
</delete>
60+
<delete id="deleteRoleMenuByMenuIds">
61+
DELETE FROM sys_role_menu rm
62+
<if test="menuIds != null and menuIds.size > 0">
63+
WHERE rm.menu_id IN (
64+
<foreach collection="menuIds" item="id" separator=",">
65+
#{id}
66+
</foreach>
67+
)
68+
</if>
69+
</delete>
70+
<delete id="deleteRoleMenuByRoleIds">
71+
DELETE FROM sys_role_menu rm
72+
<if test="menuIds != null and menuIds.size > 0">
73+
WHERE rm.role_id IN (
74+
<foreach collection="roleIds" item="id" separator=",">
75+
#{id}
76+
</foreach>
77+
)
78+
</if>
79+
</delete>
80+
<delete id="deleteRoleApiByApiIds">
81+
DELETE FROM sys_role_api ra
82+
<if test="apiIds != null and apiIds.size > 0">
83+
WHERE ra.api_id IN (
84+
<foreach collection="apiIds" item="id" separator=",">
85+
#{id}
86+
</foreach>
87+
)
88+
</if>
89+
</delete>
90+
<delete id="deleteRoleApiByRoleIds">
91+
DELETE FROM sys_role_api ra
92+
<if test="apiIds != null and apiIds.size > 0">
93+
WHERE ra.role_id IN (
94+
<foreach collection="roleIds" item="id" separator=",">
95+
#{id}
96+
</foreach>
97+
)
98+
</if>
99+
</delete>
100+
22101
</mapper>

0 commit comments

Comments
 (0)