【fix】修复根据用户ID添加角色权限会添加相同角色的问题

This commit is contained in:
nixj 2024-06-18 10:05:57 +08:00
parent 9dcbdad7f1
commit 5fff0d28c0
1 changed files with 8 additions and 0 deletions

View File

@ -116,6 +116,14 @@ public class UserController {
@ApiOperation("根据用户ID添加角色权限") @ApiOperation("根据用户ID添加角色权限")
@PostMapping("/add/role") @PostMapping("/add/role")
public Result<String> addRoleUser(@RequestBody RoleOrgParam roleOrgParam) { public Result<String> addRoleUser(@RequestBody RoleOrgParam roleOrgParam) {
//查询已有权限
List<RoleUser> exist=roleUserRepository.findByUserId(roleOrgParam.getUserId());
List<Long> roleIdList=roleOrgParam.getRoleIdList();
roleIdList.removeAll(exist.stream().map(RoleUser::getRoleId).toList());
if (roleIdList.isEmpty()) {
return Result.Success();
}
roleOrgParam.setRoleIdList(roleIdList);
roleOrgParam.getRoleIdList().stream() roleOrgParam.getRoleIdList().stream()
.map(it -> RoleUser.of(roleOrgParam.getUserId(), it)) .map(it -> RoleUser.of(roleOrgParam.getUserId(), it))
.toList() .toList()