Search in sources :

Example 1 with Wrappers

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();
}
Also used : Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) RelationsBinder(com.diboot.core.binding.RelationsBinder) InvalidResourcePermissionVO(com.diboot.iam.vo.InvalidResourcePermissionVO) java.util(java.util) IamCacheManager(com.diboot.iam.cache.IamCacheManager) Status(com.diboot.core.vo.Status) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) BusinessException(com.diboot.core.exception.BusinessException) IamResourcePermissionMapper(com.diboot.iam.mapper.IamResourcePermissionMapper) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) S(com.diboot.core.util.S) V(com.diboot.core.util.V) Service(org.springframework.stereotype.Service) Cons(com.diboot.iam.config.Cons) IamResourcePermissionService(com.diboot.iam.service.IamResourcePermissionService) IamResourcePermissionDTO(com.diboot.iam.dto.IamResourcePermissionDTO) IamResourcePermissionListVO(com.diboot.iam.vo.IamResourcePermissionListVO) BeanUtils(com.diboot.core.util.BeanUtils) IamResourcePermission(com.diboot.iam.entity.IamResourcePermission) Transactional(org.springframework.transaction.annotation.Transactional) BusinessException(com.diboot.core.exception.BusinessException) IamResourcePermissionDTO(com.diboot.iam.dto.IamResourcePermissionDTO) IamResourcePermission(com.diboot.iam.entity.IamResourcePermission) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Wrappers

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;
}
Also used : ISysUserService(vip.mate.system.service.ISysUserService) SysUser(vip.mate.system.entity.SysUser) Arrays(java.util.Arrays) ObjectUtil(cn.hutool.core.util.ObjectUtil) ISysRolePermissionService(vip.mate.system.service.ISysRolePermissionService) Autowired(org.springframework.beans.factory.annotation.Autowired) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) SysRolePermission(vip.mate.system.entity.SysRolePermission) Service(org.springframework.stereotype.Service) Map(java.util.Map) ISysRoleService(vip.mate.system.service.ISysRoleService) SysRolePOI(vip.mate.system.poi.SysRolePOI) ServiceImpl(com.baomidou.mybatisplus.extension.service.impl.ServiceImpl) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) Search(vip.mate.core.database.entity.Search) SysRoleVO(vip.mate.system.vo.SysRoleVO) SysRole(vip.mate.system.entity.SysRole) PageUtil(vip.mate.core.database.util.PageUtil) Collectors(java.util.stream.Collectors) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) SysRoleMapper(vip.mate.system.mapper.SysRoleMapper) Lazy(org.springframework.context.annotation.Lazy) IPage(com.baomidou.mybatisplus.core.metadata.IPage) BeanUtils(org.springframework.beans.BeanUtils) Transactional(org.springframework.transaction.annotation.Transactional) SysRolePermission(vip.mate.system.entity.SysRolePermission) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Wrappers

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("操作成功");
}
Also used : Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) Result(com.albedo.java.common.core.util.Result) RoleMenuDo(com.albedo.java.modules.sys.domain.RoleMenuDo) BaseServiceImpl(com.albedo.java.plugins.database.mybatis.service.impl.BaseServiceImpl) Collectors(java.util.stream.Collectors) RoleMenuService(com.albedo.java.modules.sys.service.RoleMenuService) SysCacheUtil(com.albedo.java.modules.sys.util.SysCacheUtil) List(java.util.List) Service(org.springframework.stereotype.Service) RoleMenuRepository(com.albedo.java.modules.sys.repository.RoleMenuRepository) RoleMenuDto(com.albedo.java.modules.sys.domain.dto.RoleMenuDto) AllArgsConstructor(lombok.AllArgsConstructor) Transactional(org.springframework.transaction.annotation.Transactional) RoleMenuDo(com.albedo.java.modules.sys.domain.RoleMenuDo) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Wrappers

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());
    }
}
Also used : UserRepository(com.albedo.java.modules.sys.repository.UserRepository) ObjectUtil(com.albedo.java.common.core.util.ObjectUtil) ArgumentAssert(com.albedo.java.common.core.util.ArgumentAssert) CollUtil(com.albedo.java.common.core.util.CollUtil) RoleDo(com.albedo.java.modules.sys.domain.RoleDo) RoleDto(com.albedo.java.modules.sys.domain.dto.RoleDto) RoleCacheKeyBuilder(com.albedo.java.modules.sys.cache.RoleCacheKeyBuilder) SysCacheUtil(com.albedo.java.modules.sys.util.SysCacheUtil) Service(org.springframework.stereotype.Service) UserDo(com.albedo.java.modules.sys.domain.UserDo) RoleDeptDo(com.albedo.java.modules.sys.domain.RoleDeptDo) RoleRepository(com.albedo.java.modules.sys.repository.RoleRepository) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) RoleMenuDo(com.albedo.java.modules.sys.domain.RoleMenuDo) RoleDeptService(com.albedo.java.modules.sys.service.RoleDeptService) Set(java.util.Set) CommonConstants(com.albedo.java.common.core.constant.CommonConstants) CacheKeyBuilder(com.albedo.java.common.core.cache.model.CacheKeyBuilder) Collectors(java.util.stream.Collectors) SecurityUtil(com.albedo.java.common.security.util.SecurityUtil) RoleMenuService(com.albedo.java.modules.sys.service.RoleMenuService) Serializable(java.io.Serializable) List(java.util.List) AbstractDataCacheServiceImpl(com.albedo.java.plugins.database.mybatis.service.impl.AbstractDataCacheServiceImpl) BizException(com.albedo.java.common.core.exception.BizException) AllArgsConstructor(lombok.AllArgsConstructor) RoleService(com.albedo.java.modules.sys.service.RoleService) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) RoleDeptDo(com.albedo.java.modules.sys.domain.RoleDeptDo) RoleMenuDo(com.albedo.java.modules.sys.domain.RoleMenuDo) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Wrappers

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()));
}
Also used : Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) BaseService(cn.surveyking.server.service.BaseService) SecurityContextUtils(cn.surveyking.server.core.uitls.SecurityContextUtils) ProjectPartnerRequest(cn.surveyking.server.domain.dto.ProjectPartnerRequest) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CacheConsts(cn.surveyking.server.core.constant.CacheConsts) UserService(cn.surveyking.server.service.UserService) ProjectPartnerView(cn.surveyking.server.domain.dto.ProjectPartnerView) Collectors(java.util.stream.Collectors) ProjectPartnerMapper(cn.surveyking.server.mapper.ProjectPartnerMapper) List(java.util.List) CacheManager(org.springframework.cache.CacheManager) Service(org.springframework.stereotype.Service) ProjectPartnerService(cn.surveyking.server.service.ProjectPartnerService) ProjectPartner(cn.surveyking.server.domain.model.ProjectPartner) Transactional(org.springframework.transaction.annotation.Transactional) ProjectPartner(cn.surveyking.server.domain.model.ProjectPartner)

Aggregations

Wrappers (com.baomidou.mybatisplus.core.toolkit.Wrappers)16 Collectors (java.util.stream.Collectors)15 Service (org.springframework.stereotype.Service)14 List (java.util.List)13 Transactional (org.springframework.transaction.annotation.Transactional)11 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)8 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 ArrayList (java.util.ArrayList)4 RequiredArgsConstructor (lombok.RequiredArgsConstructor)4 StrUtil (cn.hutool.core.util.StrUtil)3 Arrays (java.util.Arrays)3 Slf4j (lombok.extern.slf4j.Slf4j)3 SecurityContextUtils (cn.surveyking.server.core.uitls.SecurityContextUtils)2 BaseService (cn.surveyking.server.service.BaseService)2 UserService (cn.surveyking.server.service.UserService)2 RoleMenuDo (com.albedo.java.modules.sys.domain.RoleMenuDo)2 RoleMenuService (com.albedo.java.modules.sys.service.RoleMenuService)2 SysCacheUtil (com.albedo.java.modules.sys.util.SysCacheUtil)2 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)2