use of com.baomidou.mybatisplus.core.toolkit.Wrappers in project diboot by dibo-software.
the class IamResourcePermissionServiceImpl method updateMenuAndPermissions.
@Override
@Transactional(rollbackFor = Exception.class)
public void updateMenuAndPermissions(IamResourcePermissionDTO iamResourcePermissionDTO) {
// 检查是否设置了自身id为parentId,如果设置parentId与自身id相同,将会导致非常严重的潜在隐患
if (V.equals(iamResourcePermissionDTO.getId(), iamResourcePermissionDTO.getParentId())) {
throw new BusinessException(Status.FAIL_OPERATION, "不可设置父级菜单资源为自身");
}
// 设置menu的接口列表
if (V.notEmpty(iamResourcePermissionDTO.getApiSetList())) {
iamResourcePermissionDTO.setApiSet(S.join(iamResourcePermissionDTO.getApiSetList(), ","));
}
// 更新menu
this.updateEntity(iamResourcePermissionDTO);
List<IamResourcePermissionDTO> permissionList = iamResourcePermissionDTO.getPermissionList();
permissionList.forEach(p -> {
p.setParentId(iamResourcePermissionDTO.getId());
p.setDisplayType(Cons.RESOURCE_PERMISSION_DISPLAY_TYPE.PERMISSION.name());
});
// 需要更新的列表
List<IamResourcePermissionDTO> updatePermissionList = permissionList.stream().filter(p -> V.notEmpty(p.getId())).collect(Collectors.toList());
// 需要新建的列表
List<IamResourcePermissionDTO> createPermissionDTOList = permissionList.stream().filter(p -> V.isEmpty(p.getId())).collect(Collectors.toList());
List<Long> updatePermissionIdList = updatePermissionList.stream().map(IamResourcePermission::getId).collect(Collectors.toList());
// 批量删除不存在的按钮/权限列表
List<IamResourcePermission> oldPermissionList = this.getEntityList(Wrappers.<IamResourcePermission>lambdaQuery().eq(IamResourcePermission::getParentId, iamResourcePermissionDTO.getId()).eq(IamResourcePermission::getDisplayType, Cons.RESOURCE_PERMISSION_DISPLAY_TYPE.PERMISSION));
if (V.notEmpty(oldPermissionList)) {
LambdaQueryWrapper<IamResourcePermission> deleteWrapper = Wrappers.<IamResourcePermission>lambdaQuery().eq(IamResourcePermission::getParentId, iamResourcePermissionDTO.getId()).eq(IamResourcePermission::getDisplayType, Cons.RESOURCE_PERMISSION_DISPLAY_TYPE.PERMISSION);
if (V.notEmpty(updatePermissionIdList)) {
deleteWrapper.notIn(IamResourcePermission::getId, updatePermissionIdList);
}
this.deleteEntities(deleteWrapper);
}
// 批量新建按钮/权限列表
if (V.notEmpty(createPermissionDTOList)) {
List<IamResourcePermission> createPermissionList = BeanUtils.convertList(createPermissionDTOList, IamResourcePermission.class);
this.createEntities(createPermissionList);
}
// 批量更新按钮/权限列表
if (V.notEmpty(updatePermissionList)) {
for (IamResourcePermissionDTO updatePermission : updatePermissionList) {
this.updateEntity(updatePermission);
}
}
// 检测是否有脏数据存在
if (hasDirtyData()) {
throw new BusinessException(Status.FAIL_OPERATION, "父级节点不可设置在自己的子节点上");
}
// 清理脏数据
// this.clearDirtyData();
}
use of com.baomidou.mybatisplus.core.toolkit.Wrappers 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;
}
use of com.baomidou.mybatisplus.core.toolkit.Wrappers in project albedo by somowhere.
the class RoleMenuServiceImpl method saveRoleMenus.
/**
* @param roleMenuDto 角色菜单
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Result saveRoleMenus(RoleMenuDto roleMenuDto) {
this.remove(Wrappers.<RoleMenuDo>query().lambda().eq(RoleMenuDo::getRoleId, roleMenuDto.getRoleId()));
List<RoleMenuDo> roleMenuDoList = roleMenuDto.getMenuIdList().stream().map(menuId -> {
RoleMenuDo roleMenuDo = new RoleMenuDo();
roleMenuDo.setRoleId(roleMenuDto.getRoleId());
roleMenuDo.setMenuId(menuId);
return roleMenuDo;
}).collect(Collectors.toList());
this.saveBatch(roleMenuDoList);
SysCacheUtil.delRoleCaches(roleMenuDto.getRoleId());
return Result.buildOk("操作成功");
}
use of com.baomidou.mybatisplus.core.toolkit.Wrappers in project albedo by somowhere.
the class RoleServiceImpl method saveOrUpdate.
@Override
@Transactional(rollbackFor = Exception.class)
public void saveOrUpdate(RoleDto roleDto) {
boolean add = ObjectUtil.isEmpty(roleDto.getId());
super.saveOrUpdate(roleDto);
if (CollUtil.isNotEmpty(roleDto.getMenuIdList())) {
roleMenuService.remove(Wrappers.<RoleMenuDo>query().lambda().eq(RoleMenuDo::getRoleId, roleDto.getId()));
List<RoleMenuDo> roleMenuDoList = roleDto.getMenuIdList().stream().map(menuId -> {
RoleMenuDo roleMenuDo = new RoleMenuDo();
roleMenuDo.setRoleId(roleDto.getId());
roleMenuDo.setMenuId(menuId);
return roleMenuDo;
}).collect(Collectors.toList());
roleMenuService.saveBatch(roleMenuDoList);
}
if (CollUtil.isNotEmpty(roleDto.getDeptIdList())) {
roleDeptService.remove(Wrappers.<RoleDeptDo>query().lambda().eq(RoleDeptDo::getRoleId, roleDto.getId()));
List<RoleDeptDo> roleDeptDoList = roleDto.getDeptIdList().stream().map(deptId -> {
RoleDeptDo roleDeptDo = new RoleDeptDo();
roleDeptDo.setRoleId(roleDto.getId());
roleDeptDo.setDeptId(deptId);
return roleDeptDo;
}).collect(Collectors.toList());
roleDeptService.saveBatch(roleDeptDoList);
}
// 清空userinfo
if (!add) {
SysCacheUtil.delRoleCaches(roleDto.getId());
}
}
use of com.baomidou.mybatisplus.core.toolkit.Wrappers in project SurveyKing by javahuang.
the class ProjectPartnerServiceImpl method addProjectPartner.
@Override
public void addProjectPartner(ProjectPartnerRequest request) {
// 过滤掉已存在的用户
List<String> existUserIds = list(Wrappers.<ProjectPartner>lambdaQuery().in(ProjectPartner::getUserId, request.getUserIds()).eq(ProjectPartner::getProjectId, request.getProjectId())).stream().map(x -> x.getUserId()).collect(Collectors.toList());
saveBatch(request.getUserIds().stream().filter(userId -> {
if (existUserIds.contains(userId)) {
return false;
}
cacheManager.getCache(CacheConsts.projectPermissionCacheName).evict(userId);
return true;
}).map(userId -> {
ProjectPartner partner = new ProjectPartner();
partner.setProjectId(request.getProjectId());
partner.setUserId(userId);
partner.setType(request.getType());
return partner;
}).collect(Collectors.toList()));
}
Aggregations