{"record":{"id":"5249bb66b96f4d21","repo":"jeecgboot/JeecgBoot","slug":"error-5249bb","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":373,"sourceCode":"            //不是拥有者直接删除\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();\n        Integer count = userTenantMapper.userTenantIzExist(userId, tenantId);\n        if (count == 0) {\n            throw new JeecgBootException(\"退出租户失败，此租户下没有该用户\");\n        }\n        //获取用户信息\n        SysUser user = userService.getById(userId);\n        //变更拥有者\n        SysTenant tenant = new SysTenant();\n        tenant.setCreateBy(user.getUsername());\n        tenant.setId(tenantId);\n        tenantMapper.updateById(tenant);\n        //删除当前登录用户的租户信息\n        //update-begin---author:wangshuai ---date:20230705  for：旧拥有者退出后，需要将就拥有者的用户租户关系改成已离职------------\n        //获取原创建人的用户id\n        SysUser userByName = userService.getUserByName(createBy);\n        LambdaQueryWrapper<SysUserTenant> query = new LambdaQueryWrapper<>();\n        query.eq(SysUserTenant::getUserId,userByName.getId());\n        query.eq(SysUserTenant::getTenantId,tenantId);\n        SysUserTenant userTenant = new SysUserTenant();\n        userTenant.setStatus(CommonConstant.USER_TENANT_QUIT);\n        userTenantMapper.update(userTenant,query);","sourceCodeStart":355,"sourceCodeEnd":391,"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#L355-L391","documentation":"changeOwenUserTenant throws when userTenantMapper.userTenantIzExist(userId, tenantId) returns count 0 — the target user has no relation to the given tenant, so they cannot become its owner. This guards against assigning ownership to someone outside the tenant.","triggerScenarios":"Transferring ownership to a userId that is not a member of the tenant (no sys_user_tenant row linking them). The tenant exists (passed error 212's check) but the proposed owner isn't in it.","commonSituations":"Operator selects a user from another tenant by mistake; the user was removed/quit the tenant but is still shown in a stale UI list; userId typo or copy-paste error; the user's relation was logically deleted.","solutions":["Confirm the target userId is an active member of the tenant before transferring ownership.","Refresh the candidate-owner list from current tenant membership data.","If the user should be a member, add them to the tenant first, then transfer ownership.","Validate the userId against sys_user_tenant in the controller before invoking the service."],"exampleFix":"// before\ntenantService.changeOwenUserTenant(newOwnerId, tId);\n\n// after\nInteger cnt = userTenantMapper.userTenantIzExist(newOwnerId, tenantId);\nif (cnt == null || cnt == 0) {\n    return Result.error(\"该用户不属于此组织，无法设为拥有者\");\n}\ntenantService.changeOwenUserTenant(newOwnerId, tId);","handlingStrategy":"validation","validationCode":"Integer cnt = userTenantMapper.userTenantIzExist(newOwnerId, tenantId);\nif (cnt == null || cnt == 0) {\n    return Result.error(\"该用户不属于此组织\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build the candidate-owner list from current tenant membership.","Verify membership before transferring ownership.","Refresh membership data to avoid stale lists."],"tags":["tenant","validation","ownership","jeecg-boot"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}