Java Code Examples for cn.hutool.core.convert.Convert#toLongArray()

The following examples show how to use cn.hutool.core.convert.Convert#toLongArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RestRoleService.java    From Guns with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 设置某个角色的权限
 *
 * @param roleId 角色id
 * @param ids    权限的id
 * @date 2017年2月13日 下午8:26:53
 */
@Transactional(rollbackFor = Exception.class)
public void setAuthority(Long roleId, String ids) {

    // 删除该角色所有的权限
    this.restRoleMapper.deleteRolesById(roleId);

    // 添加新的权限
    for (Long id : Convert.toLongArray(ids.split(","))) {
        RestRelation relation = new RestRelation();
        relation.setRoleId(roleId);
        relation.setMenuId(id);
        this.restRelationMapper.insert(relation);
    }

    // 刷新当前用户的权限
    restUserService.refreshCurrentUser();
}
 
Example 2
Source File: RoleService.java    From Guns with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 设置某个角色的权限
 *
 * @param roleId 角色id
 * @param ids    权限的id
 * @date 2017年2月13日 下午8:26:53
 */
@Transactional(rollbackFor = Exception.class)
public void setAuthority(Long roleId, String ids) {

    // 删除该角色所有的权限
    this.roleMapper.deleteRolesById(roleId);

    // 添加新的权限
    for (Long id : Convert.toLongArray(ids.split(","))) {
        Relation relation = new Relation();
        relation.setRoleId(roleId);
        relation.setMenuId(id);
        this.relationMapper.insert(relation);
    }

    // 刷新当前用户的权限
    userService.refreshCurrentUser();
}
 
Example 3
Source File: ConstantFactory.java    From Guns with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.ROLES_NAME + "'+#roleIds")
public String getRoleName(String roleIds) {
    if (ToolUtil.isEmpty(roleIds)) {
        return "";
    }
    Long[] roles = Convert.toLongArray(roleIds);
    StringBuilder sb = new StringBuilder();
    for (Long role : roles) {
        Role roleObj = roleMapper.selectById(role);
        if (ToolUtil.isNotEmpty(roleObj) && ToolUtil.isNotEmpty(roleObj.getName())) {
            sb.append(roleObj.getName()).append(",");
        }
    }
    return StrUtil.removeSuffix(sb.toString(), ",");
}
 
Example 4
Source File: RoleServiceImpl.java    From WebStack-Guns with MIT License 5 votes vote down vote up
@Override
@Transactional
public void setAuthority(Integer roleId, String ids) {

    // 删除该角色所有的权限
    this.roleMapper.deleteRolesById(roleId);

    // 添加新的权限
    for (Long id : Convert.toLongArray(ids.split(","))) {
        Relation relation = new Relation();
        relation.setRoleid(roleId);
        relation.setMenuid(id);
        this.relationMapper.insert(relation);
    }
}
 
Example 5
Source File: SysUserServiceImpl.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 批量删除用户信息
 *
 * @param ids 需要删除的数据ID
 * @return 结果
 */
@Override
public int deleteUserByIds(String ids) {
    Long[] userIds = Convert.toLongArray(ids);
    for (Long userId : userIds) {
        if (SysUser.isAdmin(userId)) {
            throw new BusinessException("不允许删除超级管理员用户");
        }
    }
    return userMapper.deleteUserByIds(userIds);
}
 
Example 6
Source File: SysRoleServiceImpl.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 批量删除角色信息
 *
 * @param ids 需要删除的数据ID
 * @throws BusinessException 异常
 */
@Override
public int deleteRoleByIds(String ids) {
    Long[] roleIds = Convert.toLongArray(ids);
    for (Long roleId : roleIds) {
        SysRole role = selectRoleById(roleId);
        if (countUserRoleByRoleId(roleId) > 0) {
            throw new BusinessException(String.format("%1$s已分配,不能删除", role.getRoleName()));
        }
    }
    return roleMapper.deleteRoleByIds(roleIds);
}
 
Example 7
Source File: SysRoleServiceImpl.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 批量选择授权用户角色
 *
 * @param roleId  角色ID
 * @param userIds 需要删除的用户数据ID
 * @return 结果
 */
@Override
public int insertAuthUsers(Long roleId, String userIds) {
    Long[] users = Convert.toLongArray(userIds);
    // 新增用户与角色管理
    List<SysUserRole> list = new ArrayList<>();
    for (Long userId : users) {
        SysUserRole ur = new SysUserRole();
        ur.setUserId(userId);
        ur.setRoleId(roleId);
        list.add(ur);
    }
    return userRoleMapper.batchUserRole(list);
}
 
Example 8
Source File: SysDictTypeServiceImpl.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 批量删除字典类型
 *
 * @param ids 需要删除的数据
 * @return 结果
 */
@Override
public int deleteDictTypeByIds(String ids){
    Long[] dictIds = Convert.toLongArray(ids);
    for (Long dictId : dictIds) {
        SysDictType dictType = selectDictTypeById(dictId);
        if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0) {
            throw new BusinessException(String.format("%1$s已分配,不能删除" , dictType.getDictName()));
        }
    }
    return dictTypeMapper.deleteDictTypeByIds(dictIds);
}
 
Example 9
Source File: SysPostServiceImpl.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 批量删除岗位信息
 *
 * @param ids 需要删除的数据ID
 * @throws BusinessException 异常
 */
@Override
public int deletePostByIds(String ids) throws BusinessException {
    Long[] postIds = Convert.toLongArray(ids);
    for (Long postId : postIds) {
        SysPost post = selectPostById(postId);
        if (countUserPostById(postId) > 0) {
            throw new BusinessException(String.format("%1$s已分配,不能删除", post.getPostName()));
        }
    }
    return postMapper.deletePostByIds(postIds);
}
 
Example 10
Source File: SysJobServiceImpl.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 批量删除调度信息
 *
 * @param ids 需要删除的数据ID
 */
@Override
public void deleteJobByIds(String ids) throws SchedulerException{
    Long[] jobIds = Convert.toLongArray(ids);
    for (Long jobId : jobIds) {
        SysJob job = jobMapper.selectJobById(jobId);
        deleteJob(job);
    }
}
 
Example 11
Source File: ConstantFactory.java    From Guns with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String getMenuNames(String menuIds) {
    Long[] menus = Convert.toLongArray(menuIds);
    StringBuilder sb = new StringBuilder();
    for (Long menu : menus) {
        Menu menuObj = menuMapper.selectById(menu);
        if (ToolUtil.isNotEmpty(menuObj) && ToolUtil.isNotEmpty(menuObj.getName())) {
            sb.append(menuObj.getName()).append(",");
        }
    }
    return StrUtil.removeSuffix(sb.toString(), ",");
}