jeecgboot/JeecgBoot · error · JeecgBootBizTipException

当前子公司/部门下存在子级,无法变更为岗位!

Error message

当前子公司/部门下存在子级,无法变更为岗位!

What it means

SysDepartServiceImpl.verifyOrgCategory enforces the organization-type hierarchy on updates. A node cannot be changed to POST (岗位) while it still has child sys_depart rows, because posts are leaves that may not own children. The check counts children by parent_id and throws if count > 0.

Source

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

			return true;
		} else {
			return false;
		}

	}

    /**
     * 验证部门类型
     *
     * @param sysDepart
     */
    private void verifyOrgCategory(SysDepart sysDepart) {
        //update-begin---author:wangshuai---date:2025-08-21---for: 当部门类型为岗位的时候,需要查看是否存在下级,存在下级无法变更为岗位---
        //如果是岗位的情况下,不能存在子级
        if (oConvertUtils.isNotEmpty(sysDepart.getOrgCategory()) && DepartCategoryEnum.DEPART_CATEGORY_POST.getValue().equals(sysDepart.getOrgCategory())) {
            long count = this.count(new QueryWrapper<SysDepart>().lambda().eq(SysDepart::getParentId, sysDepart.getId()));
            if (count > 0) {
                throw new JeecgBootBizTipException("当前子公司/部门下存在子级,无法变更为岗位!");
            }
        }
        //如果是子公司的情况下,则上级不能为部门或者岗位
        if (oConvertUtils.isNotEmpty(sysDepart.getOrgCategory()) && DepartCategoryEnum.DEPART_CATEGORY_SUB_COMPANY.getValue().equals(sysDepart.getOrgCategory())
                && oConvertUtils.isNotEmpty(sysDepart.getParentId())) {
            LambdaQueryWrapper<SysDepart> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(SysDepart::getId, sysDepart.getParentId());
            queryWrapper.in(SysDepart::getOrgCategory, DepartCategoryEnum.DEPART_CATEGORY_POST.getValue(), DepartCategoryEnum.DEPART_CATEGORY_DEPART.getValue());
            long count = this.count(queryWrapper);
            if (count > 0) {
                throw new JeecgBootBizTipException("当前父级为部门或岗位,无法变更为子公司!");
            }
        }
        //如果是部门的情况下,下级不能为子公司或者公司
        if (oConvertUtils.isNotEmpty(sysDepart.getOrgCategory()) && DepartCategoryEnum.DEPART_CATEGORY_DEPART.getValue().equals(sysDepart.getOrgCategory())) {
            LambdaQueryWrapper<SysDepart> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(SysDepart::getParentId, sysDepart.getId());
            queryWrapper.in(SysDepart::getOrgCategory, DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue(), DepartCategoryEnum.DEPART_CATEGORY_SUB_COMPANY.getValue());

View on GitHub (pinned to 96fb33f5ec)

Solutions

  1. First move or delete the node's children (re-parent them elsewhere).
  2. Alternatively, set orgCategory to DEPART instead of POST if the node must keep children.
  3. Before saving, count children client-side and warn the user.

Example fix

// before
sysDepart.setOrgCategory(DepartCategoryEnum.DEPART_CATEGORY_POST.getValue());
sysDepartService.updateById(sysDepart); // throws if children exist
// after
long childCount = sysDepartService.count(new LambdaQueryWrapper<SysDepart>()
        .eq(SysDepart::getParentId, sysDepart.getId()));
if (childCount > 0) {
    return Result.error("该节点存在子级, 无法变更为岗位, 请先转移子级");
}
sysDepart.setOrgCategory(DepartCategoryEnum.DEPART_CATEGORY_POST.getValue());
sysDepartService.updateById(sysDepart);
Defensive patterns

Strategy: validation

Validate before calling

// Count children before changing to POST; block or warn the user.
long childCount = sysDepartService.count(new LambdaQueryWrapper<SysDepart>()
    .eq(SysDepart::getParentId, sysDepart.getId()));
if (DepartCategoryEnum.DEPART_CATEGORY_POST.getValue().equals(sysDepart.getOrgCategory())
        && childCount > 0) {
    return Result.error("该节点存在子级, 无法变更为岗位");
}

Type guard

public boolean canBecomePost(SysDepart node) {
    if (!DepartCategoryEnum.DEPART_CATEGORY_POST.getValue().equals(node.getOrgCategory())) return true;
    long n = this.count(new LambdaQueryWrapper<SysDepart>().eq(SysDepart::getParentId, node.getId()));
    return n == 0;
}

Try / catch

try {
    sysDepartService.updateById(sysDepart);
} catch (JeecgBootBizTipException e) {
    if (e.getMessage() != null && e.getMessage().contains("无法变更为岗位")) {
        return Result.error("存在子级, 请先转移子级再变更类型");
    }
    throw e;
}

Prevention

When it happens

Trigger: Editing a department (update/editDepart) and setting orgCategory to the POST value on a node that has one or more child sys_depart rows.

Common situations: Reorganizing the org tree and converting a department that still has sub-departments into a post; bulk category changes applied without checking descendants.

Related errors


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