jeecgboot/JeecgBoot · warning · JeecgBootBizTipException

公司不允许作为子级

Error message

公司不允许作为子级

What it means

Thrown by validateDragOperation when the dragged department is a company (oldOrgCategory == COMPANY) and the target has a non-empty parentId (meaning the target is not a root node). This JeecgBootBizTipException enforces the rule that companies can only exist at the root level — a company cannot become a child of another department.

Source

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

            throw new RuntimeException("不能拖拽到自身子部门");
        }
        //公司岗位判断
        String orgCategory = targetDept.getOrgCategory();
        String oldOrgCategory = dragDept.getOrgCategory();
        //部门为公司
        if(0 != dropPosition && DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue().equals(orgCategory)){
            //当前部门不能为子公司、部门和岗位
            if(!DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue().equals(oldOrgCategory)){
                throw new JeecgBootBizTipException("当前部门类型为【"+DepartCategoryEnum.getNameByValue(oldOrgCategory)+"】,不允许移动到公司");
            }
        }
        //部门为岗位不允许移入
        if(0 == dropPosition && DepartCategoryEnum.DEPART_CATEGORY_POST.getValue().equals(orgCategory)) {
            throw new JeecgBootBizTipException("岗位不允许存在子级");
        }
        //公司不能做为子级
        if(oConvertUtils.isNotEmpty(targetDept.getParentId()) && DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue().equals(oldOrgCategory)){
            throw new JeecgBootBizTipException("公司不允许作为子级");
        }
    }

    /**
     * 判断目标部门是否是被拖拽部门的子部门
     */
    private boolean isDescendant(SysDepart dragDept, String targetId) {
        List<SysDepart> children = departMapper.getDepartByParentId(dragDept.getId());
        for (SysDepart child : children) {
            if (child.getId().equals(targetId)) {
                return true;
            }
            if (isDescendant(child, targetId)) {
                return true;
            }
        }
        return false;
    }

View on GitHub (pinned to 96fb33f5ec)

Solutions

  1. Add a frontend guard: if the dragged node is a company, only allow dropping at the root level.
  2. Verify the company department's orgCategory and parent_id in the database are consistent.
  3. Lock root-level company nodes in the UI so they can only be reordered among themselves, not nested.

Example fix

// before
if (oConvertUtils.isNotEmpty(targetDept.getParentId()) && DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue().equals(oldOrgCategory)) {
    throw new JeecgBootBizTipException("公司不允许作为子级");
}

// after — frontend restricts company drag to root-level drops
function isAllowedDrop(dragNode, dropNode, position) {
    if (dragNode.orgCategory === 'company' && position === 0 && dropNode.parentId) {
        ElMessage.warning('公司不允许作为子级');
        return false;
    }
    return true;
}
Defensive patterns

Strategy: validation

Validate before calling

// Frontend: prevent company from being dropped inside a non-root node
const isCompany = (node) => node.orgCategory === DepartCategoryEnum.COMPANY;
if (isCompany(dragNode) && dropPosition === 0 && dropNode.parentId) {
    ElMessage.warning('公司不允许作为子级');
    return;
}

Type guard

public boolean canCompanyBeChild(SysDepart dragDept, SysDepart targetDept, int dropPosition) {
    if (!DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue().equals(dragDept.getOrgCategory())) return true;
    if (dropPosition != 0) return true;
    return oConvertUtils.isEmpty(targetDept.getParentId());
}

Try / catch

try {
    service.updateChangeDepart(changeDepartVo);
} catch (JeecgBootBizTipException e) {
    if (e.getMessage().contains("公司不允许作为子级")) {
        return Result.error("公司只能在根级别存在");
    }
    throw e;
}

Prevention

When it happens

Trigger: Dragging a company-type department and dropping it inside (dropPosition=0) any non-root department. The condition checks oConvertUtils.isNotEmpty(targetDept.getParentId()) combined with the source being a company.

Common situations: User attempts to reorganize the company under a department; company was incorrectly allowed to be dragged from root; inconsistent data where a company has a parentId in the database.

Related errors


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