Skip to content

Commit b86e5b9

Browse files
committed
feat: 添加根据菜单、api查询角色的方法
1 parent 5367524 commit b86e5b9

4 files changed

Lines changed: 46 additions & 0 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ public interface SysRoleMapper extends BaseMapper<SysRole> {
1818

1919
List<SysRole> listByUserId(@Param("userId") Long userId);
2020

21+
List<SysRole> listByMenuId(@Param("menuId") Long menuId);
22+
23+
List<SysRole> listByApiId(@Param("apiId") Long apiId);
24+
25+
2126
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@
33
import com.baomidou.mybatisplus.extension.service.IService;
44
import top.cadecode.uniboot.system.bean.po.SysRole;
55

6+
import java.util.List;
7+
68
/**
79
* 系统角色服务
810
*
911
* @author Cade Li
1012
* @date 2022/5/27
1113
*/
1214
public interface SysRoleService extends IService<SysRole> {
15+
16+
List<SysRole> listByUserId( Long userId);
17+
18+
List<SysRole> listByMenuId(Long menuId);
19+
20+
List<SysRole> listByApiId(Long apiId);
1321
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
11
package top.cadecode.uniboot.system.serviceimpl;
22

33
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4+
import lombok.RequiredArgsConstructor;
45
import org.springframework.stereotype.Service;
56
import top.cadecode.uniboot.system.bean.po.SysRole;
67
import top.cadecode.uniboot.system.mapper.SysRoleMapper;
78
import top.cadecode.uniboot.system.service.SysRoleService;
89

10+
import java.util.List;
11+
912
/**
1013
* 系统角色服务实现
1114
*
1215
* @author Cade Li
1316
* @date 2022/5/27
1417
*/
18+
@RequiredArgsConstructor
1519
@Service
1620
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {
21+
22+
private final SysRoleMapper sysRoleMapper;
23+
24+
@Override
25+
public List<SysRole> listByUserId(Long userId) {
26+
return sysRoleMapper.listByUserId(userId);
27+
}
28+
29+
@Override
30+
public List<SysRole> listByMenuId(Long menuId) {
31+
return sysRoleMapper.listByMenuId(menuId);
32+
}
33+
34+
@Override
35+
public List<SysRole> listByApiId(Long apiId) {
36+
return sysRoleMapper.listByApiId(apiId);
37+
}
1738
}

system/src/main/resources/mapper/SysRoleMapper.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,16 @@
77
INNER JOIN sys_role r ON ru.role_id = r.id
88
WHERE ru.user_id = #{userId}
99
</select>
10+
<select id="listByMenuId" resultType="top.cadecode.uniboot.system.bean.po.SysRole">
11+
SELECT *
12+
FROM sys_role_menu rm
13+
INNER JOIN sys_role r ON rm.role_id = r.id
14+
WHERE rm.menu_id = #{menuId}
15+
</select>
16+
<select id="listByApiId" resultType="top.cadecode.uniboot.system.bean.po.SysRole">
17+
SELECT *
18+
FROM sys_role_api ra
19+
INNER JOIN sys_role r ON ra.role_id = r.id
20+
WHERE ra.api_id = #{apiId}
21+
</select>
1022
</mapper>

0 commit comments

Comments
 (0)