{"record":{"id":"2703c5b3d4b9f149","repo":"jeecgboot/JeecgBoot","slug":"error-2703c5","errorCode":null,"errorMessage":"公司不允许作为子级","messagePattern":"公司不允许作为子级","errorType":"exception","errorClass":"JeecgBootBizTipException","httpStatus":null,"severity":"warning","filePath":"jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysDepartServiceImpl.java","lineNumber":2078,"sourceCode":"            throw new RuntimeException(\"不能拖拽到自身子部门\");\n        }\n        //公司岗位判断\n        String orgCategory = targetDept.getOrgCategory();\n        String oldOrgCategory = dragDept.getOrgCategory();\n        //部门为公司\n        if(0 != dropPosition && DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue().equals(orgCategory)){\n            //当前部门不能为子公司、部门和岗位\n            if(!DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue().equals(oldOrgCategory)){\n                throw new JeecgBootBizTipException(\"当前部门类型为【\"+DepartCategoryEnum.getNameByValue(oldOrgCategory)+\"】,不允许移动到公司\");\n            }\n        }\n        //部门为岗位不允许移入\n        if(0 == dropPosition && DepartCategoryEnum.DEPART_CATEGORY_POST.getValue().equals(orgCategory)) {\n            throw new JeecgBootBizTipException(\"岗位不允许存在子级\");\n        }\n        //公司不能做为子级\n        if(oConvertUtils.isNotEmpty(targetDept.getParentId()) && DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue().equals(oldOrgCategory)){\n            throw new JeecgBootBizTipException(\"公司不允许作为子级\");\n        }\n    }\n\n    /**\n     * 判断目标部门是否是被拖拽部门的子部门\n     */\n    private boolean isDescendant(SysDepart dragDept, String targetId) {\n        List<SysDepart> children = departMapper.getDepartByParentId(dragDept.getId());\n        for (SysDepart child : children) {\n            if (child.getId().equals(targetId)) {\n                return true;\n            }\n            if (isDescendant(child, targetId)) {\n                return true;\n            }\n        }\n        return false;\n    }","sourceCodeStart":2060,"sourceCodeEnd":2096,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysDepartServiceImpl.java#L2060-L2096","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add a frontend guard: if the dragged node is a company, only allow dropping at the root level.","Verify the company department's orgCategory and parent_id in the database are consistent.","Lock root-level company nodes in the UI so they can only be reordered among themselves, not nested."],"exampleFix":"// before\nif (oConvertUtils.isNotEmpty(targetDept.getParentId()) && DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue().equals(oldOrgCategory)) {\n    throw new JeecgBootBizTipException(\"公司不允许作为子级\");\n}\n\n// after — frontend restricts company drag to root-level drops\nfunction isAllowedDrop(dragNode, dropNode, position) {\n    if (dragNode.orgCategory === 'company' && position === 0 && dropNode.parentId) {\n        ElMessage.warning('公司不允许作为子级');\n        return false;\n    }\n    return true;\n}","handlingStrategy":"validation","validationCode":"// Frontend: prevent company from being dropped inside a non-root node\nconst isCompany = (node) => node.orgCategory === DepartCategoryEnum.COMPANY;\nif (isCompany(dragNode) && dropPosition === 0 && dropNode.parentId) {\n    ElMessage.warning('公司不允许作为子级');\n    return;\n}","typeGuard":"public boolean canCompanyBeChild(SysDepart dragDept, SysDepart targetDept, int dropPosition) {\n    if (!DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue().equals(dragDept.getOrgCategory())) return true;\n    if (dropPosition != 0) return true;\n    return oConvertUtils.isEmpty(targetDept.getParentId());\n}","tryCatchPattern":"try {\n    service.updateChangeDepart(changeDepartVo);\n} catch (JeecgBootBizTipException e) {\n    if (e.getMessage().contains(\"公司不允许作为子级\")) {\n        return Result.error(\"公司只能在根级别存在\");\n    }\n    throw e;\n}","preventionTips":["Restrict company drag to root-level drops only in the frontend.","Lock company nodes visually to indicate they cannot be nested.","Verify company department records have correct orgCategory values."],"tags":["jeecg-boot","department","drag-drop","business-rule","root-level"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}