use of com.company.project.entity.SysRoleDeptEntity in project springboot-manager by aitangbao.
the class RoleServiceImpl method detailInfo.
@Override
public SysRole detailInfo(String id) {
SysRole sysRole = sysRoleMapper.selectById(id);
if (sysRole == null) {
log.error("传入 的 id:{}不合法", id);
throw new BusinessException(BaseResponseCode.DATA_ERROR);
}
List<PermissionRespNode> permissionRespNodes = permissionService.selectAllByTree();
LambdaQueryWrapper<SysRolePermission> queryWrapper = Wrappers.<SysRolePermission>lambdaQuery().select(SysRolePermission::getPermissionId).eq(SysRolePermission::getRoleId, sysRole.getId());
Set<Object> checkList = new HashSet<>(rolePermissionService.listObjs(queryWrapper));
setChecked(permissionRespNodes, checkList);
sysRole.setPermissionRespNodes(permissionRespNodes);
LambdaQueryWrapper<SysRoleDeptEntity> queryWrapperDept = Wrappers.<SysRoleDeptEntity>lambdaQuery().select(SysRoleDeptEntity::getDeptId).eq(SysRoleDeptEntity::getRoleId, sysRole.getId());
List<DeptRespNodeVO> deptRespNodes = deptService.deptTreeList(null, true);
Set<Object> checkDeptList = new HashSet<>(sysRoleDeptService.listObjs(queryWrapperDept));
setCheckedDept(deptRespNodes, checkDeptList);
sysRole.setDeptRespNodes(deptRespNodes);
return sysRole;
}
use of com.company.project.entity.SysRoleDeptEntity in project springboot-manager by aitangbao.
the class RoleController method bindDept.
@PostMapping("/role/bindDept")
@ApiOperation(value = "绑定角色部门接口")
@LogAnnotation(title = "角色管理", action = "绑定角色部门信息")
@RequiresPermissions("sys:role:bindDept")
public DataResult bindDept(@RequestBody SysRole vo) {
if (StringUtils.isEmpty(vo.getId())) {
return DataResult.fail("id不能为空");
}
if (roleService.getById(vo.getId()) == null) {
return DataResult.fail("获取角色失败");
}
// 先删除所有绑定
sysRoleDeptService.remove(Wrappers.<SysRoleDeptEntity>lambdaQuery().eq(SysRoleDeptEntity::getRoleId, vo.getId()));
// 如果不是自定义
if (vo.getDataScope() != 2) {
vo.setDepts(null);
}
if (!CollectionUtils.isEmpty(vo.getDepts())) {
List<SysRoleDeptEntity> list = new ArrayList<>();
for (String deptId : vo.getDepts()) {
SysRoleDeptEntity sysRoleDeptEntity = new SysRoleDeptEntity();
sysRoleDeptEntity.setDeptId(deptId);
sysRoleDeptEntity.setRoleId(vo.getId());
list.add(sysRoleDeptEntity);
}
sysRoleDeptService.saveBatch(list);
}
roleService.updateById(new SysRole().setId(vo.getId()).setDataScope(vo.getDataScope()));
return DataResult.success();
}
Aggregations