implement find permissions by role's ID method

This commit is contained in:
myh 2023-12-03 23:45:17 +08:00
parent 5aa2ff89c0
commit e168925d5c

View File

@ -1,12 +1,14 @@
package com.example.springdemo.service;
package com.example.springdemo.serviceImpl;
import com.example.springdemo.dao.PermissionsRepository;
import com.example.springdemo.dao.RolesPermissionsRepository;
import com.example.springdemo.entities.RBAC.Permissions;
import com.example.springdemo.service.PermissionsService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@ -54,4 +56,15 @@ public class PermissionsServiceImpl implements PermissionsService {
public List<Permissions> findAllPermissions() {
return permissionsRepository.findAll();
}
//根据角色id查询权限
@Override
public List<Permissions> findPermissionsByRoleId(Long roleId) {
List<Long> permissionsId = rolesPermissionsRepository.findPermissionsIdByRolesId(roleId);
List<Permissions> permissions = new ArrayList<>();
for (Long permissionId : permissionsId) {
permissions.add(permissionsRepository.findById(permissionId).orElseThrow());
}
return permissions;
}
}