Search in sources :

Example 1 with RoleMenuDo

use of com.albedo.java.modules.sys.domain.RoleMenuDo 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 2 with RoleMenuDo

use of com.albedo.java.modules.sys.domain.RoleMenuDo 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 3 with RoleMenuDo

use of com.albedo.java.modules.sys.domain.RoleMenuDo in project albedo by somowhere.

the class MenuServiceImpl method saveByGenScheme.

@Override
public boolean saveByGenScheme(GenSchemeDto schemeDto) {
    String moduleName = schemeDto.getSchemeName(), parentMenuId = schemeDto.getParentMenuId(), url = schemeDto.getUrl();
    String permission = StringUtil.toCamelCase(StringUtil.lowerFirst(url), CharUtil.DASHED).replace(StringUtil.SLASH, "_").substring(1), permissionLike = permission.substring(0, permission.length() - 1);
    List<MenuDo> currentMenuListDo = repository.selectList(Wrappers.<MenuDo>query().lambda().eq(MenuDo::getName, moduleName).or().likeLeft(MenuDo::getPermission, permissionLike));
    for (MenuDo currentMenuDo : currentMenuListDo) {
        if (currentMenuDo != null) {
            List<Long> idList = repository.selectList(Wrappers.<MenuDo>query().lambda().likeLeft(MenuDo::getPermission, permissionLike).or(i -> i.eq(MenuDo::getId, currentMenuDo.getId()).or().eq(MenuDo::getParentId, currentMenuDo.getId()))).stream().map(MenuDo::getId).collect(Collectors.toList());
            roleMenuRepository.delete(Wrappers.<RoleMenuDo>query().lambda().in(RoleMenuDo::getMenuId, idList));
            repository.deleteBatchIds(idList);
        }
    }
    MenuDo parentMenuDo = repository.selectById(parentMenuId);
    ArgumentAssert.notNull(parentMenuDo, StringUtil.toAppendStr("根据模块id[", parentMenuId, "无法查询到模块信息]"));
    MenuDo module = new MenuDo();
    module.setName(moduleName);
    module.setParentId(parentMenuDo.getId());
    module.setType(MenuDo.TYPE_MENU);
    module.setIcon("app");
    module.setPath(StringUtil.toRevertCamelCase(StringUtil.lowerFirst(schemeDto.getClassName()), CharUtil.DASHED));
    module.setComponent(url.substring(1) + "index");
    save(module);
    MenuDo moduleView = new MenuDo();
    moduleView.setParent(module);
    moduleView.setName(moduleName + "查看");
    moduleView.setPermission(permission + "view");
    moduleView.setParentId(module.getId());
    moduleView.setType(MenuDo.TYPE_BUTTON);
    moduleView.setSort(20);
    save(moduleView);
    MenuDo moduleEdit = new MenuDo();
    moduleEdit.setParent(module);
    moduleEdit.setName(moduleName + "编辑");
    moduleEdit.setPermission(permission + "edit");
    moduleEdit.setParentId(module.getId());
    moduleEdit.setType(MenuDo.TYPE_BUTTON);
    moduleEdit.setSort(40);
    save(moduleEdit);
    MenuDo moduleDelete = new MenuDo();
    moduleDelete.setParent(module);
    moduleDelete.setName(moduleName + "删除");
    moduleDelete.setPermission(permission + "del");
    moduleDelete.setParentId(module.getId());
    moduleDelete.setType(MenuDo.TYPE_BUTTON);
    moduleDelete.setSort(80);
    save(moduleDelete);
    return true;
}
Also used : MenuDo(com.albedo.java.modules.sys.domain.MenuDo) RoleMenuDo(com.albedo.java.modules.sys.domain.RoleMenuDo)

Example 4 with RoleMenuDo

use of com.albedo.java.modules.sys.domain.RoleMenuDo in project albedo by somowhere.

the class MenuServiceImpl method removeByIds.

@Override
public void removeByIds(Set<Long> ids) {
    ids.forEach(id -> {
        SysCacheUtil.delMenuCaches(id);
        // 查询父节点为当前节点的节点
        List<MenuDo> menuDoList = this.list(Wrappers.<MenuDo>query().lambda().eq(MenuDo::getParentId, id));
        ArgumentAssert.notEmpty(menuDoList, () -> new BizException("菜单含有下级不能删除"));
        roleMenuRepository.delete(Wrappers.<RoleMenuDo>query().lambda().eq(RoleMenuDo::getMenuId, id));
        // 删除当前菜单及其子菜单
        this.removeById(id);
    });
}
Also used : MenuDo(com.albedo.java.modules.sys.domain.MenuDo) RoleMenuDo(com.albedo.java.modules.sys.domain.RoleMenuDo) BizException(com.albedo.java.common.core.exception.BizException)

Example 5 with RoleMenuDo

use of com.albedo.java.modules.sys.domain.RoleMenuDo in project albedo by somowhere.

the class RoleServiceImpl method getOneDto.

@Override
public RoleDto getOneDto(Serializable id) {
    RoleDto oneVo = super.getOneDto(id);
    oneVo.setMenuIdList(roleMenuService.list(Wrappers.<RoleMenuDo>query().lambda().eq(RoleMenuDo::getRoleId, id)).stream().map(RoleMenuDo::getMenuId).collect(Collectors.toList()));
    oneVo.setDeptIdList(findDeptIdsByRoleId(id));
    return oneVo;
}
Also used : RoleDto(com.albedo.java.modules.sys.domain.dto.RoleDto) RoleMenuDo(com.albedo.java.modules.sys.domain.RoleMenuDo)

Aggregations

RoleMenuDo (com.albedo.java.modules.sys.domain.RoleMenuDo)5 BizException (com.albedo.java.common.core.exception.BizException)2 MenuDo (com.albedo.java.modules.sys.domain.MenuDo)2 RoleDto (com.albedo.java.modules.sys.domain.dto.RoleDto)2 RoleMenuService (com.albedo.java.modules.sys.service.RoleMenuService)2 SysCacheUtil (com.albedo.java.modules.sys.util.SysCacheUtil)2 Wrappers (com.baomidou.mybatisplus.core.toolkit.Wrappers)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 AllArgsConstructor (lombok.AllArgsConstructor)2 Service (org.springframework.stereotype.Service)2 Transactional (org.springframework.transaction.annotation.Transactional)2 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 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 Result (com.albedo.java.common.core.util.Result)1 SecurityUtil (com.albedo.java.common.security.util.SecurityUtil)1