{"record":{"id":"5145a45e0963542c","repo":"jeecgboot/JeecgBoot","slug":"error-5145a4","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":341,"sourceCode":"\t\t\treturn true;\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\n\t}\n\n    /**\n     * 验证部门类型\n     *\n     * @param sysDepart\n     */\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());","sourceCodeStart":323,"sourceCodeEnd":359,"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#L323-L359","documentation":"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.","triggerScenarios":"Editing a department (update/editDepart) and setting orgCategory to the POST value on a node that has one or more child sys_depart rows.","commonSituations":"Reorganizing the org tree and converting a department that still has sub-departments into a post; bulk category changes applied without checking descendants.","solutions":["First move or delete the node's children (re-parent them elsewhere).","Alternatively, set orgCategory to DEPART instead of POST if the node must keep children.","Before saving, count children client-side and warn the user."],"exampleFix":"// before\nsysDepart.setOrgCategory(DepartCategoryEnum.DEPART_CATEGORY_POST.getValue());\nsysDepartService.updateById(sysDepart); // throws if children exist\n// after\nlong childCount = sysDepartService.count(new LambdaQueryWrapper<SysDepart>()\n        .eq(SysDepart::getParentId, sysDepart.getId()));\nif (childCount > 0) {\n    return Result.error(\"该节点存在子级, 无法变更为岗位, 请先转移子级\");\n}\nsysDepart.setOrgCategory(DepartCategoryEnum.DEPART_CATEGORY_POST.getValue());\nsysDepartService.updateById(sysDepart);","handlingStrategy":"validation","validationCode":"// Count children before changing to POST; block or warn the user.\nlong childCount = sysDepartService.count(new LambdaQueryWrapper<SysDepart>()\n    .eq(SysDepart::getParentId, sysDepart.getId()));\nif (DepartCategoryEnum.DEPART_CATEGORY_POST.getValue().equals(sysDepart.getOrgCategory())\n        && childCount > 0) {\n    return Result.error(\"该节点存在子级, 无法变更为岗位\");\n}","typeGuard":"public boolean canBecomePost(SysDepart node) {\n    if (!DepartCategoryEnum.DEPART_CATEGORY_POST.getValue().equals(node.getOrgCategory())) return true;\n    long n = this.count(new LambdaQueryWrapper<SysDepart>().eq(SysDepart::getParentId, node.getId()));\n    return n == 0;\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":["Count children on the frontend before enabling the POST option.","Provide a 'move children' workflow so users can re-parent before converting.","Document the org-type hierarchy rules for administrators."],"tags":["department","org-tree","validation","hierarchy"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}