jeecgboot/JeecgBoot · error · JeecgBootException

用户没有离职,不允许删除!

Error message

用户没有离职,不允许删除!

What it means

deleteUserByPassword throws (step2) when the target user's relation to the tenant is missing or not in USER_TENANT_QUIT status. Deletion is only permitted for users who have already resigned from the org, as a safety gate against deleting active members.

Source

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

    }

    @Override
    public void deleteUserByPassword(SysUser sysUser, Integer tenantId) {
        //被删除人的用户id
        String userId = sysUser.getId();
        //被删除人的密码
        String password = sysUser.getPassword();
        //当前登录用户
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        //step1 判断当前用户是否为当前租户的管理员(只有超级管理员和账号管理员可以删除)
        Long isHaveAdmin = sysTenantPackUserMapper.izHaveBuyAuth(user.getId(), tenantId);
        if(null == isHaveAdmin || 0 == isHaveAdmin){
            throw new JeecgBootException("您不是当前组织的管理员,无法删除用户!");
        }
        //step2 离职状态下,并且无其他组织情况下,可以删除
        SysUserTenant sysUserTenant = userTenantMapper.getUserTenantByTenantId(userId, tenantId);
        if(null == sysUserTenant || !CommonConstant.USER_TENANT_QUIT.equals(sysUserTenant.getStatus())){
            throw new JeecgBootException("用户没有离职,不允许删除!"); 
        }
        List<Integer> tenantIdsByUserId = userTenantMapper.getTenantIdsByUserId(userId);
        if(CollectionUtils.isNotEmpty(tenantIdsByUserId) && tenantIdsByUserId.size()>0){
            throw new JeecgBootException("用户尚有未退出的组织,无法删除!");
        }
        //step3 当天创建的用户和创建人可以删除
        SysUser sysUserData = userService.getById(userId);
        if(!sysUserData.getCreateBy().equals(user.getUsername())){
            throw new JeecgBootException("您不是该用户的创建人,无法删除!");
        }
        
        // 代码逻辑说明: 【QQYUN-11839】删除用户,需要输入被删除用户的密码,这逻辑对吗?不应该是管理员的密码吗---
        this.verifyCreateTimeAndPassword(sysUserData,password);

        //step5 逻辑删除用户
        userService.deleteUser(userId);
        //step6 真实删除用户
        userService.removeLogicDeleted(Collections.singletonList(userId));

View on GitHub (pinned to 96fb33f5ec)

Solutions

  1. Process the user's resignation (set tenant relation status to quit) before attempting deletion.
  2. Verify via getUserTenantByTenantId that the relation exists and is in quit status.
  3. If the relation is missing, reconcile the data or use the appropriate removal flow instead of delete.
  4. Frontend should only enable delete for users showing 'resigned' status.

Example fix

// before
tenantService.deleteUserByPassword(targetUser, tenantId);

// after
SysUserTenant rel = userTenantMapper.getUserTenantByTenantId(targetUser.getId(), tenantId);
if (rel == null || !CommonConstant.USER_TENANT_QUIT.equals(rel.getStatus())) {
    return Result.error("用户尚未离职,请先办理离职再删除");
}
tenantService.deleteUserByPassword(targetUser, tenantId);
Defensive patterns

Strategy: validation

Validate before calling

SysUserTenant rel = userTenantMapper.getUserTenantByTenantId(userId, tenantId);
if (rel == null || !CommonConstant.USER_TENANT_QUIT.equals(rel.getStatus())) {
    return Result.error("用户尚未离职,无法删除");
}

Prevention

When it happens

Trigger: Attempting to delete a user whose tenant relation status is normal, under-review, or has no relation row at all. The status must equal USER_TENANT_QUIT (resigned) to proceed.

Common situations: Trying to delete an active member without first processing their resignation; the user was never part of the tenant; the quit status was reverted; the relation row is missing due to data inconsistency.

Related errors


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