{"record":{"id":"0db3ff2eb512f957","repo":"jeecgboot/JeecgBoot","slug":"error-0db3ff","errorCode":null,"errorMessage":"退出租户失败，租户信息已不存在","messagePattern":"退出租户失败，租户信息已不存在","errorType":"exception","errorClass":"JeecgBootException","httpStatus":null,"severity":"error","filePath":"jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysTenantServiceImpl.java","lineNumber":352,"sourceCode":"\n    @Override\n    public void exitUserTenant(String userId, String username, String tenantId) {\n        int tId = Integer.parseInt(tenantId);\n        //获取所有租户信息\n        List<String> userIdsByTenantId = userTenantMapper.getUserIdsByTenantId(tId);\n        //查询当前租户是否为拥有者\n        SysTenant sysTenant = tenantMapper.selectById(tId);\n        //如果是拥有着\n        if (username.equals(sysTenant.getCreateBy())) {\n            //判断当前租户信息位数\n            if (null != userIdsByTenantId && userIdsByTenantId.size() > 1) {\n                //需要指配拥有者\n                throw new JeecgBootException(\"assignedOwen\");\n            } else if (null != userIdsByTenantId && userIdsByTenantId.size() == 1) {\n                //只有拥有者的时候需要去注销租户\n                throw new JeecgBootException(\"cancelTenant\");\n            } else {\n                throw new JeecgBootException(\"退出租户失败，租户信息已不存在\");\n            }\n        } else {\n            //不是拥有者直接删除\n            this.leaveTenant(userId, tenantId);\n            this.leveUserProcess(userId, tenantId);\n        }\n    }\n\n    @Override\n    public void changeOwenUserTenant(String userId, String tId) {\n        //查询当前用户是否存在该租户下\n        // 代码逻辑说明: 租户id应该是传过来的，不应该是当前租户的------------\n        int tenantId = oConvertUtils.getInt(tId, 0);\n        SysTenant sysTenant = tenantMapper.selectById(tenantId);\n        if(null == sysTenant){\n            throw new JeecgBootException(\"退出租户失败，不存在此租户\");\n        }\n        String createBy = sysTenant.getCreateBy();","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysTenantServiceImpl.java#L334-L370","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Investigate the data inconsistency: query sys_tenant and sys_user_tenant for the tenantId and reconcile.","If the tenant is genuinely defunct, run the tenant-cancellation/deletion procedure to remove the orphaned row.","Re-create the owner relation row if the tenant should still be active, then retry the exit.","Add a data-integrity check/job that flags tenants whose member list is empty."],"exampleFix":"// before\ntenantService.exitUserTenant(userId, username, tenantId);\n\n// after\nList<String> members = userTenantMapper.getUserIdsByTenantId(tId);\nif (members == null || members.isEmpty()) {\n    log.warn(\"租户 {} 成员数据缺失，进入清理流程\", tenantId);\n    tenantCancelService.cancelOrphanTenant(tenantId);\n    return;\n}\ntenantService.exitUserTenant(userId, username, tenantId);","handlingStrategy":"validation","validationCode":"List<String> members = userTenantMapper.getUserIdsByTenantId(tId);\nif (members == null || members.isEmpty()) {\n    log.warn(\"租户 {} 成员缺失，需数据修复\", tenantId);\n    return Result.error(\"租户成员数据异常，请联系管理员\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run a data-integrity job to detect tenants with empty member lists.","Reconcile orphaned tenant rows (delete or re-add owner relation).","Avoid manual DB deletes that bypass relation cleanup."],"tags":["tenant","data-integrity","jeecg-boot"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}