jeecgboot/JeecgBoot · error · JeecgBootException

退出租户失败,租户信息已不存在

Error message

退出租户失败,租户信息已不存在

What it means

exitUserTenant throws when the owner is the creator but userIdsByTenantId is null or empty (size not > 1 and not == 1). This indicates a data inconsistency: the tenant has a createBy but no member relation rows at all. The message '租户信息已不存在' reflects that the member data is gone.

Source

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

    @Override
    public void exitUserTenant(String userId, String username, String tenantId) {
        int tId = Integer.parseInt(tenantId);
        //获取所有租户信息
        List<String> userIdsByTenantId = userTenantMapper.getUserIdsByTenantId(tId);
        //查询当前租户是否为拥有者
        SysTenant sysTenant = tenantMapper.selectById(tId);
        //如果是拥有着
        if (username.equals(sysTenant.getCreateBy())) {
            //判断当前租户信息位数
            if (null != userIdsByTenantId && userIdsByTenantId.size() > 1) {
                //需要指配拥有者
                throw new JeecgBootException("assignedOwen");
            } else if (null != userIdsByTenantId && userIdsByTenantId.size() == 1) {
                //只有拥有者的时候需要去注销租户
                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();

View on GitHub (pinned to 96fb33f5ec)

Solutions

  1. Investigate the data inconsistency: query sys_tenant and sys_user_tenant for the tenantId and reconcile.
  2. If the tenant is genuinely defunct, run the tenant-cancellation/deletion procedure to remove the orphaned row.
  3. Re-create the owner relation row if the tenant should still be active, then retry the exit.
  4. Add a data-integrity check/job that flags tenants whose member list is empty.

Example fix

// before
tenantService.exitUserTenant(userId, username, tenantId);

// after
List<String> members = userTenantMapper.getUserIdsByTenantId(tId);
if (members == null || members.isEmpty()) {
    log.warn("租户 {} 成员数据缺失,进入清理流程", tenantId);
    tenantCancelService.cancelOrphanTenant(tenantId);
    return;
}
tenantService.exitUserTenant(userId, username, tenantId);
Defensive patterns

Strategy: validation

Validate before calling

List<String> members = userTenantMapper.getUserIdsByTenantId(tId);
if (members == null || members.isEmpty()) {
    log.warn("租户 {} 成员缺失,需数据修复", tenantId);
    return Result.error("租户成员数据异常,请联系管理员");
}

Prevention

When it happens

Trigger: The createBy user exits, but userTenantMapper.getUserIdsByTenantId returns null or an empty list — meaning relation records were deleted while the tenant row remains. The owner branch falls through both size checks to the else.

Common situations: Manual DB cleanup removed sys_user_tenant rows without removing the tenant; a partial migration left the tenant orphaned; the tenant was cancelled but the row not purged.

Related errors


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