jeecgboot/JeecgBoot · error · JeecgBootException

退出租户失败,此租户下没有该用户

Error message

退出租户失败,此租户下没有该用户

What it means

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.

Source

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

            //不是拥有者直接删除
            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<>();
        query.eq(SysUserTenant::getUserId,userByName.getId());
        query.eq(SysUserTenant::getTenantId,tenantId);
        SysUserTenant userTenant = new SysUserTenant();
        userTenant.setStatus(CommonConstant.USER_TENANT_QUIT);
        userTenantMapper.update(userTenant,query);

View on GitHub (pinned to 96fb33f5ec)

Solutions

  1. Confirm the target userId is an active member of the tenant before transferring ownership.
  2. Refresh the candidate-owner list from current tenant membership data.
  3. If the user should be a member, add them to the tenant first, then transfer ownership.
  4. Validate the userId against sys_user_tenant in the controller before invoking the service.

Example fix

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

// after
Integer cnt = userTenantMapper.userTenantIzExist(newOwnerId, tenantId);
if (cnt == null || cnt == 0) {
    return Result.error("该用户不属于此组织,无法设为拥有者");
}
tenantService.changeOwenUserTenant(newOwnerId, tId);
Defensive patterns

Strategy: validation

Validate before calling

Integer cnt = userTenantMapper.userTenantIzExist(newOwnerId, tenantId);
if (cnt == null || cnt == 0) {
    return Result.error("该用户不属于此组织");
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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