{"record":{"id":"c1b143c146475bf1","repo":"jeecgboot/JeecgBoot","slug":"error-c1b143","errorCode":null,"errorMessage":"当前父级为部门或岗位，无法变更为子公司!","messagePattern":"当前父级为部门或岗位，无法变更为子公司!","errorType":"exception","errorClass":"JeecgBootBizTipException","httpStatus":null,"severity":"error","filePath":"jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysDepartServiceImpl.java","lineNumber":352,"sourceCode":"     */\n    private void verifyOrgCategory(SysDepart sysDepart) {\n        //update-begin---author:wangshuai---date:2025-08-21---for: 当部门类型为岗位的时候，需要查看是否存在下级，存在下级无法变更为岗位---\n        //如果是岗位的情况下，不能存在子级\n        if (oConvertUtils.isNotEmpty(sysDepart.getOrgCategory()) && DepartCategoryEnum.DEPART_CATEGORY_POST.getValue().equals(sysDepart.getOrgCategory())) {\n            long count = this.count(new QueryWrapper<SysDepart>().lambda().eq(SysDepart::getParentId, sysDepart.getId()));\n            if (count > 0) {\n                throw new JeecgBootBizTipException(\"当前子公司/部门下存在子级，无法变更为岗位!\");\n            }\n        }\n        //如果是子公司的情况下，则上级不能为部门或者岗位\n        if (oConvertUtils.isNotEmpty(sysDepart.getOrgCategory()) && DepartCategoryEnum.DEPART_CATEGORY_SUB_COMPANY.getValue().equals(sysDepart.getOrgCategory())\n                && oConvertUtils.isNotEmpty(sysDepart.getParentId())) {\n            LambdaQueryWrapper<SysDepart> queryWrapper = new LambdaQueryWrapper<>();\n            queryWrapper.eq(SysDepart::getId, sysDepart.getParentId());\n            queryWrapper.in(SysDepart::getOrgCategory, DepartCategoryEnum.DEPART_CATEGORY_POST.getValue(), DepartCategoryEnum.DEPART_CATEGORY_DEPART.getValue());\n            long count = this.count(queryWrapper);\n            if (count > 0) {\n                throw new JeecgBootBizTipException(\"当前父级为部门或岗位，无法变更为子公司!\");\n            }\n        }\n        //如果是部门的情况下，下级不能为子公司或者公司\n        if (oConvertUtils.isNotEmpty(sysDepart.getOrgCategory()) && DepartCategoryEnum.DEPART_CATEGORY_DEPART.getValue().equals(sysDepart.getOrgCategory())) {\n            LambdaQueryWrapper<SysDepart> queryWrapper = new LambdaQueryWrapper<>();\n            queryWrapper.eq(SysDepart::getParentId, sysDepart.getId());\n            queryWrapper.in(SysDepart::getOrgCategory, DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue(), DepartCategoryEnum.DEPART_CATEGORY_SUB_COMPANY.getValue());\n            long count = this.count(queryWrapper);\n            if (count > 0) {\n                throw new JeecgBootBizTipException(\"当前子级存在子公司，无法变更为部门!\");\n            }\n        }\n    }\n    \n    @Override\n\t@Transactional(rollbackFor = Exception.class)\n\tpublic void deleteBatchWithChildren(List<String> ids) {\n\t\t//存放子级的id","sourceCodeStart":334,"sourceCodeEnd":370,"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#L334-L370","documentation":"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}.","triggerScenarios":"Setting orgCategory=SUB_COMPANY on a node whose parent (sys_depart.parent_id) is a DEPART or POST.","commonSituations":"Re-parenting a node incorrectly; moving a sub-company under a department via drag-drop; data import assigning wrong parent categories.","solutions":["Re-parent the node to a company-level ancestor (COMPANY or another SUB_COMPANY) first.","Alternatively, keep the node as DEPART if the parent must remain a department.","Validate the (parent category, new category) pair before saving."],"exampleFix":"// before\nsysDepart.setOrgCategory(DepartCategoryEnum.DEPART_CATEGORY_SUB_COMPANY.getValue());\nsysDepartService.updateById(sysDepart); // parent is DEPART -> throws\n// after\nSysDepart parent = sysDepartService.getById(sysDepart.getParentId());\nif (isDepartOrPost(parent)) {\n    return Result.error(\"上级为部门/岗位, 无法变更为子公司, 请先调整上级\");\n}\nsysDepart.setOrgCategory(DepartCategoryEnum.DEPART_CATEGORY_SUB_COMPANY.getValue());\nsysDepartService.updateById(sysDepart);","handlingStrategy":"validation","validationCode":"// Validate the (parent category, new category) pair before saving.\nSysDepart parent = sysDepartService.getById(sysDepart.getParentId());\nif (DepartCategoryEnum.DEPART_CATEGORY_SUB_COMPANY.getValue().equals(sysDepart.getOrgCategory())\n        && parent != null\n        && (DepartCategoryEnum.DEPART_CATEGORY_POST.getValue().equals(parent.getOrgCategory())\n            || DepartCategoryEnum.DEPART_CATEGORY_DEPART.getValue().equals(parent.getOrgCategory()))) {\n    return Result.error(\"上级为部门/岗位, 无法变更为子公司\");\n}","typeGuard":"public boolean parentAllowsSubCompany(SysDepart node) {\n    if (!DepartCategoryEnum.DEPART_CATEGORY_SUB_COMPANY.getValue().equals(node.getOrgCategory())) return true;\n    SysDepart parent = this.getById(node.getParentId());\n    if (parent == null) return true;\n    String pc = parent.getOrgCategory();\n    return !DepartCategoryEnum.DEPART_CATEGORY_POST.getValue().equals(pc)\n        && !DepartCategoryEnum.DEPART_CATEGORY_DEPART.getValue().equals(pc);\n}","tryCatchPattern":"try {\n    sysDepartService.updateById(sysDepart);\n} catch (JeecgBootBizTipException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"无法变更为子公司\")) {\n        return Result.error(\"请先将上级调整为公司级节点\");\n    }\n    throw e;\n}","preventionTips":["Validate the parent's category before allowing a SUB_COMPANY change.","Restrict drag-drop reparenting so subsidiaries cannot land under departments.","Surface hierarchy rules in the admin UI before save."],"tags":["department","org-tree","validation","hierarchy"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}