jeecgboot/JeecgBoot · error · JeecgBootException

退出租户失败,不存在此租户

Error message

退出租户失败,不存在此租户

What it means

changeOwenUserTenant throws when tenantMapper.selectById(tenantId) returns null — the tenant ID (parsed via oConvertUtils.getInt with default 0) does not correspond to any tenant row. Ownership cannot be transferred to a non-existent tenant.

Source

Thrown at jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysTenantServiceImpl.java:368

                throw new JeecgBootException("cancelTenant");
            } else {
                throw new JeecgBootException("退出租户失败,租户信息已不存在");
            }
        } else {
            //不是拥有者直接删除
            this.leaveTenant(userId, tenantId);
            this.leveUserProcess(userId, tenantId);
        }
    }

    @Override
    public void changeOwenUserTenant(String userId, String tId) {
        //查询当前用户是否存在该租户下
        // 代码逻辑说明: 租户id应该是传过来的,不应该是当前租户的------------
        int tenantId = oConvertUtils.getInt(tId, 0);
        SysTenant sysTenant = tenantMapper.selectById(tenantId);
        if(null == sysTenant){
            throw new JeecgBootException("退出租户失败,不存在此租户");
        }
        String createBy = sysTenant.getCreateBy();
        Integer count = userTenantMapper.userTenantIzExist(userId, tenantId);
        if (count == 0) {
            throw new JeecgBootException("退出租户失败,此租户下没有该用户");
        }
        //获取用户信息
        SysUser user = userService.getById(userId);
        //变更拥有者
        SysTenant tenant = new SysTenant();
        tenant.setCreateBy(user.getUsername());
        tenant.setId(tenantId);
        tenantMapper.updateById(tenant);
        //删除当前登录用户的租户信息
        //update-begin---author:wangshuai ---date:20230705  for:旧拥有者退出后,需要将就拥有者的用户租户关系改成已离职------------
        //获取原创建人的用户id
        SysUser userByName = userService.getUserByName(createBy);
        LambdaQueryWrapper<SysUserTenant> query = new LambdaQueryWrapper<>();

View on GitHub (pinned to 96fb33f5ec)

Solutions

  1. Verify the tenantId is valid and the tenant row exists before calling changeOwenUserTenant.
  2. Ensure the tId parameter is correctly bound from the request (check param name and that it is non-empty).
  3. If the tenant was deleted, remove stale references in the UI/links that still point to it.
  4. Add input validation to reject non-positive or non-numeric tenant IDs at the controller boundary.

Example fix

// before
tenantService.changeOwenUserTenant(userId, tId);

// after
int tenantId = oConvertUtils.getInt(tId, 0);
if (tenantId <= 0 || tenantMapper.selectById(tenantId) == null) {
    return Result.error("租户不存在,无法转让拥有者");
}
tenantService.changeOwenUserTenant(userId, tId);
Defensive patterns

Strategy: validation

Validate before calling

int tenantId = oConvertUtils.getInt(tId, 0);
if (tenantId <= 0 || tenantMapper.selectById(tenantId) == null) {
    return Result.error("租户不存在");
}

Prevention

When it happens

Trigger: Calling changeOwenUserTenant(userId, tId) with a tenant ID that is missing, non-numeric (defaults to 0), or references a deleted tenant.

Common situations: Frontend passes a stale tenant id after the tenant was deleted; the tId param is undefined and parseInt yields 0; URL/query param naming mismatch so tId is blank; tenant was logically deleted but id still referenced in a link.

Related errors


AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14). Data as JSON: /api/errors/1312b8a444ae1082. Report an issue: GitHub.