Search in sources :

Example 1 with RoleDeptDo

use of com.albedo.java.modules.sys.domain.RoleDeptDo 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)

Aggregations

CacheKey (com.albedo.java.common.core.cache.model.CacheKey)1 CacheKeyBuilder (com.albedo.java.common.core.cache.model.CacheKeyBuilder)1 CommonConstants (com.albedo.java.common.core.constant.CommonConstants)1 BizException (com.albedo.java.common.core.exception.BizException)1 ArgumentAssert (com.albedo.java.common.core.util.ArgumentAssert)1 CollUtil (com.albedo.java.common.core.util.CollUtil)1 ObjectUtil (com.albedo.java.common.core.util.ObjectUtil)1 SecurityUtil (com.albedo.java.common.security.util.SecurityUtil)1 RoleCacheKeyBuilder (com.albedo.java.modules.sys.cache.RoleCacheKeyBuilder)1 RoleDeptDo (com.albedo.java.modules.sys.domain.RoleDeptDo)1 RoleDo (com.albedo.java.modules.sys.domain.RoleDo)1 RoleMenuDo (com.albedo.java.modules.sys.domain.RoleMenuDo)1 UserDo (com.albedo.java.modules.sys.domain.UserDo)1 RoleDto (com.albedo.java.modules.sys.domain.dto.RoleDto)1 RoleRepository (com.albedo.java.modules.sys.repository.RoleRepository)1 UserRepository (com.albedo.java.modules.sys.repository.UserRepository)1 RoleDeptService (com.albedo.java.modules.sys.service.RoleDeptService)1 RoleMenuService (com.albedo.java.modules.sys.service.RoleMenuService)1 RoleService (com.albedo.java.modules.sys.service.RoleService)1 SysCacheUtil (com.albedo.java.modules.sys.util.SysCacheUtil)1