{"record":{"id":"40e921d5d7b50674","repo":"jeecgboot/JeecgBoot","slug":"error-40e921","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":362,"sourceCode":"        //如果是子公司的情况下，则上级不能为部门或者岗位\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\n\t\tList<String> idList = new ArrayList<String>();\n\t\t//存放父级的id\n\t\tList<String> parentIdList = new ArrayList<>();\n\t\tfor(String id: ids) {\n\t\t\tidList.add(id);\n\t\t\t//此步骤是为了删除子级\n\t\t\tthis.checkChildrenExists(id, idList);\n\t\t\t// 代码逻辑说明: 【QQYUN-5757】批量删除部门时未正确置为叶子节点 ------------\n\t\t\tSysDepart depart = this.getDepartById(id);\n\t\t\tif (oConvertUtils.isNotEmpty(depart.getParentId())) {","sourceCodeStart":344,"sourceCodeEnd":380,"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#L344-L380","documentation":"verifyOrgCategory rule: a node cannot become a DEPART (部门) if any of its children are COMPANY or SUB_COMPANY, because a department may not be the parent of a company-level node. Children are counted by parent_id where orgCategory is in {COMPANY, SUB_COMPANY}.","triggerScenarios":"Setting orgCategory=DEPART on a node that has child rows whose orgCategory is COMPANY or SUB_COMPANY.","commonSituations":"Demoting a company-level node that still owns subsidiaries; restructuring that flattens the tree without re-parenting company children first.","solutions":["Re-parent the COMPANY/SUB_COMPANY children to another company-level node first.","Alternatively, keep the node as COMPANY or SUB_COMPANY.","Count company-level children before applying the demotion and warn the user."],"exampleFix":"// before\nsysDepart.setOrgCategory(DepartCategoryEnum.DEPART_CATEGORY_DEPART.getValue());\nsysDepartService.updateById(sysDepart); // has SUB_COMPANY child -> throws\n// after\nlong coKids = sysDepartService.count(new LambdaQueryWrapper<SysDepart>()\n        .eq(SysDepart::getParentId, sysDepart.getId())\n        .in(SysDepart::getOrgCategory,\n            DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue(),\n            DepartCategoryEnum.DEPART_CATEGORY_SUB_COMPANY.getValue()));\nif (coKids > 0) {\n    return Result.error(\"存在公司级子级, 无法变更为部门\");\n}\nsysDepart.setOrgCategory(DepartCategoryEnum.DEPART_CATEGORY_DEPART.getValue());\nsysDepartService.updateById(sysDepart);","handlingStrategy":"validation","validationCode":"// Count company-level children before demoting to DEPART.\nlong coKids = sysDepartService.count(new LambdaQueryWrapper<SysDepart>()\n    .eq(SysDepart::getParentId, sysDepart.getId())\n    .in(SysDepart::getOrgCategory,\n        DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue(),\n        DepartCategoryEnum.DEPART_CATEGORY_SUB_COMPANY.getValue()));\nif (DepartCategoryEnum.DEPART_CATEGORY_DEPART.getValue().equals(sysDepart.getOrgCategory()) && coKids > 0) {\n    return Result.error(\"存在公司级子级, 无法变更为部门\");\n}","typeGuard":"public boolean canBecomeDepart(SysDepart node) {\n    if (!DepartCategoryEnum.DEPART_CATEGORY_DEPART.getValue().equals(node.getOrgCategory())) return true;\n    long n = this.count(new LambdaQueryWrapper<SysDepart>()\n        .eq(SysDepart::getParentId, node.getId())\n        .in(SysDepart::getOrgCategory,\n            DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue(),\n            DepartCategoryEnum.DEPART_CATEGORY_SUB_COMPANY.getValue()));\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":["Check for company-level children before allowing a demotion to DEPART.","Provide a bulk re-parent tool for restructuring.","Validate hierarchy transitions on the client before submit."],"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"}