{"record":{"id":"9912908edcb0baa5","repo":"jeecgboot/JeecgBoot","slug":"error-991290","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":980,"sourceCode":"    public void deleteUser(SysUser sysUser, Integer tenantId) {\n        //被删除人的用户id\n        String userId = sysUser.getId();\n        //被删除人的密码\n        String password = sysUser.getPassword();\n        //当前登录用户\n        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();\n        //step1 判断当前用户是否为当前租户的创建者才可以删除\n        SysTenant sysTenant = this.getById(tenantId);\n        if(null == sysTenant || !user.getUsername().equals(sysTenant.getCreateBy())){\n            throw new JeecgBootException(\"您不是当前组织的创建者，无法删除用户！\");\n        }\n        //step2 判断除了当前组织之外是否还有加入了其他组织\n        LambdaQueryWrapper<SysUserTenant> query = new LambdaQueryWrapper<>();\n        query.eq(SysUserTenant::getUserId,userId);\n        query.ne(SysUserTenant::getTenantId,tenantId);\n        List<SysUserTenant> sysUserTenants = userTenantMapper.selectList(query);\n        if(CollectionUtils.isNotEmpty(sysUserTenants)){\n            throw new JeecgBootException(\"该用户还存在于其它组织中，无法删除用户！\");\n        }\n        //step3 验证创建时间和密码\n        SysUser sysUserData = userService.getById(userId);\n        this.verifyCreateTimeAndPassword(sysUserData,password);\n        //step4 真实删除用户\n        userService.deleteUser(userId);\n        userService.removeLogicDeleted(Collections.singletonList(userId));\n    }\n\n    /**\n     * 为用户添加租户下所有套餐\n     *\n     * @param userId   用户id\n     * @param tenantId 租户id\n     */\n    public void addPackUser(String userId, String tenantId) {\n        //根据租户id和产品包的code获取租户套餐id\n        List<String> packIds = sysTenantPackMapper.getPackIdByPackCodeAndTenantId(oConvertUtils.getInt(tenantId));","sourceCodeStart":962,"sourceCodeEnd":998,"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#L962-L998","documentation":"Thrown by SysTenantServiceImpl.deleteUser at step2. It queries sys_user_tenant for rows with the same userId but a different tenantId; if any exist it refuses the hard delete because the user still belongs to at least one other organization.","triggerScenarios":"A user who is a member of multiple tenants/organizations attempts full deletion while still linked to another tenant. The query uses userId and ne tenantId.","commonSituations":"User accepted invitations to several orgs; old tenant memberships were never removed; soft-deleted memberships still present as rows; the UI only removes from the current org but calls the full-delete API.","solutions":["Remove the user from all other organizations first (delete sys_user_tenant rows for other tenantIds), then retry full deletion.","Or call the org-removal endpoint instead of the full-delete endpoint when the user is multi-tenant.","Audit sys_user_tenant for stray rows for this userId and clean them.","Confirm whether the intended action is 'leave this org' vs 'permanently delete account'."],"exampleFix":"// before: full delete while user is in other tenants\ndeleteUser(sysUser, tenantId);  // throws\n\n// after: remove membership from each tenant, then delete\nfor (Integer tId : otherTenantIds) {\n    userTenantMapper.delete(new LambdaQueryWrapper<SysUserTenant>()\n        .eq(SysUserTenant::getUserId, userId).eq(SysUserTenant::getTenantId, tId));\n}\ndeleteUser(sysUser, tenantId);","handlingStrategy":"validation","validationCode":"LambdaQueryWrapper<SysUserTenant> q = new LambdaQueryWrapper<>();\nq.eq(SysUserTenant::getUserId, userId).ne(SysUserTenant::getTenantId, tenantId);\nif (userTenantMapper.selectList(q).size() > 0) {\n    return Result.error(\"请先将用户移出其它组织\");\n}","typeGuard":"boolean isOnlyInThisTenant(String userId, Integer tenantId) {\n  LambdaQueryWrapper<SysUserTenant> q = new LambdaQueryWrapper<>();\n  q.eq(SysUserTenant::getUserId, userId).ne(SysUserTenant::getTenantId, tenantId);\n  return userTenantMapper.selectCount(q) == 0;\n}","tryCatchPattern":"try { sysTenantService.deleteUser(sysUser, tenantId); }\ncatch (JeecgBootException e) {\n  if (e.getMessage().contains(\"其它组织\")) { return Result.error(e.getMessage()); }\n  throw e;\n}","preventionTips":["Offer a 'leave this org' action distinct from 'delete account'.","Pre-check other-tenant memberships before the delete call.","Clean up orphaned sys_user_tenant rows periodically."],"tags":["tenant","user-management","data-integrity"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}