jeecgboot/JeecgBoot · error · JeecgBootBizTipException

当前父级为部门或岗位,无法变更为子公司!

Error message

当前父级为部门或岗位,无法变更为子公司!

What it means

verifyOrgCategory rule: a node cannot become a SUB_COMPANY (子公司) if its parent's orgCategory is DEPART or POST, because a subsidiary must sit beneath a company-level node. The parent is looked up by id and its category checked against {POST, DEPART}.

Source

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

     */
    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());
            long count = this.count(queryWrapper);
            if (count > 0) {
                throw new JeecgBootBizTipException("当前子级存在子公司,无法变更为部门!");
            }
        }
    }
    
    @Override
	@Transactional(rollbackFor = Exception.class)
	public void deleteBatchWithChildren(List<String> ids) {
		//存放子级的id

View on GitHub (pinned to 96fb33f5ec)

Solutions

  1. Re-parent the node to a company-level ancestor (COMPANY or another SUB_COMPANY) first.
  2. Alternatively, keep the node as DEPART if the parent must remain a department.
  3. Validate the (parent category, new category) pair before saving.

Example fix

// before
sysDepart.setOrgCategory(DepartCategoryEnum.DEPART_CATEGORY_SUB_COMPANY.getValue());
sysDepartService.updateById(sysDepart); // parent is DEPART -> throws
// after
SysDepart parent = sysDepartService.getById(sysDepart.getParentId());
if (isDepartOrPost(parent)) {
    return Result.error("上级为部门/岗位, 无法变更为子公司, 请先调整上级");
}
sysDepart.setOrgCategory(DepartCategoryEnum.DEPART_CATEGORY_SUB_COMPANY.getValue());
sysDepartService.updateById(sysDepart);
Defensive patterns

Strategy: validation

Validate before calling

// Validate the (parent category, new category) pair before saving.
SysDepart parent = sysDepartService.getById(sysDepart.getParentId());
if (DepartCategoryEnum.DEPART_CATEGORY_SUB_COMPANY.getValue().equals(sysDepart.getOrgCategory())
        && parent != null
        && (DepartCategoryEnum.DEPART_CATEGORY_POST.getValue().equals(parent.getOrgCategory())
            || DepartCategoryEnum.DEPART_CATEGORY_DEPART.getValue().equals(parent.getOrgCategory()))) {
    return Result.error("上级为部门/岗位, 无法变更为子公司");
}

Type guard

public boolean parentAllowsSubCompany(SysDepart node) {
    if (!DepartCategoryEnum.DEPART_CATEGORY_SUB_COMPANY.getValue().equals(node.getOrgCategory())) return true;
    SysDepart parent = this.getById(node.getParentId());
    if (parent == null) return true;
    String pc = parent.getOrgCategory();
    return !DepartCategoryEnum.DEPART_CATEGORY_POST.getValue().equals(pc)
        && !DepartCategoryEnum.DEPART_CATEGORY_DEPART.getValue().equals(pc);
}

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: Setting orgCategory=SUB_COMPANY on a node whose parent (sys_depart.parent_id) is a DEPART or POST.

Common situations: Re-parenting a node incorrectly; moving a sub-company under a department via drag-drop; data import assigning wrong parent categories.

Related errors


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