use of vip.mate.system.entity.SysRolePermission in project matecloud by matevip.
the class SysRoleController method savePermission.
/**
* 角色权限设置
*
* @param roleId 角色Id
* @param ids 多个id使用逗号分隔
* @return Result
*/
@PreAuth
@Log(value = "角色权限设置", exception = "角色权限设置")
@PostMapping("/set-permission")
@ApiOperation(value = "角色权限设置", notes = "角色权限设置")
@ApiImplicitParams({ @ApiImplicitParam(name = "roleId", required = true, value = "角色ID", paramType = "form"), @ApiImplicitParam(name = "ids", required = true, value = "多个用,号隔开", paramType = "form") })
public Result<?> savePermission(@RequestParam String roleId, @RequestParam String ids) {
Collection longs = CollectionUtil.stringToCollection(ids);
long roleIdc = CollectionUtil.strToLong(roleId, 0L);
LambdaQueryWrapper<SysRolePermission> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(SysRolePermission::getRoleId, roleIdc);
sysRolePermissionService.remove(lambdaQueryWrapper);
for (Iterator<Long> it = longs.iterator(); it.hasNext(); ) {
SysRolePermission sysRolePermission = new SysRolePermission();
long menuId = it.next();
sysRolePermission.setMenuId(menuId);
sysRolePermission.setRoleId(roleIdc);
sysRolePermissionService.saveOrUpdate(sysRolePermission);
}
redisService.del("getPermission-" + roleId);
return Result.success("操作成功");
}
use of vip.mate.system.entity.SysRolePermission in project matecloud by matevip.
the class SysRoleServiceImpl method set.
@Override
@Transactional(rollbackFor = Exception.class)
public boolean set(SysRole sysRole) {
this.saveOrUpdate(sysRole);
if (ObjectUtil.isNotEmpty(sysRole.getMenu())) {
List<SysRolePermission> collect = sysRole.getMenu().stream().map(s -> {
SysRolePermission sysRolePermission = new SysRolePermission();
sysRolePermission.setMenuId(Long.valueOf(s));
sysRolePermission.setRoleId(sysRole.getId());
return sysRolePermission;
}).collect(Collectors.toList());
// 根据角色ID删除所有菜单值
sysRolePermissionService.remove(Wrappers.<SysRolePermission>lambdaQuery().eq(SysRolePermission::getRoleId, sysRole.getId()));
// 重新写入角色对应的权限值
sysRolePermissionService.saveBatch(collect);
}
return Boolean.TRUE;
}
Aggregations