{"record":{"id":"0536656c87fcb198","repo":"jeecgboot/JeecgBoot","slug":"departcategoryenum-getnamebyvalue-oldorg","errorCode":null,"errorMessage":"当前部门类型为【${DepartCategoryEnum.getNameByValue(oldOrgCategory)}】,不允许移动到公司","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":2069,"sourceCode":"     * @param dropPosition 拖拽位置\n     */\n    private void validateDragOperation(SysDepart dragDept, SysDepart targetDept, Integer dropPosition) {\n        // 禁止拖拽到自身\n        if (dragDept.getId().equals(targetDept.getId())) {\n            throw new RuntimeException(\"不能拖拽到自身\");\n        }\n        // 禁止拖拽到自身子部门\n        if (isDescendant(dragDept, targetDept.getId())) {\n            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) {","sourceCodeStart":2051,"sourceCodeEnd":2087,"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#L2051-L2087","documentation":"Thrown by validateDragOperation when dropPosition != 0 and the target is a company-type department (DEPART_CATEGORY_COMPANY), but the dragged department is not itself a company. This JeecgBootBizTipException enforces the business rule that only companies can be reordered as siblings of other companies. The message dynamically includes the dragged department's category name.","triggerScenarios":"Attempting to drag a department or post (not a company) to a position above or below a company node (dropPosition -1 or 1). The DepartCategoryEnum.getNameByValue method resolves the source category for the error message.","commonSituations":"User misunderstands the organizational hierarchy rules and tries to place a department alongside companies; inconsistent org-category data where a department is miscategorized; frontend doesn't filter drop targets by category compatibility.","solutions":["Ensure the dragged department is of company type before dropping it adjacent to another company.","Add a frontend visual restriction: only allow sibling drops on companies if the drag source is also a company.","Review the orgCategory values in the database for both source and target to confirm they are correct.","If the business rule has changed, update the validateDragOperation logic accordingly."],"exampleFix":"// before — backend rejects at validation time\nif (!DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue().equals(oldOrgCategory)) {\n    throw new JeecgBootBizTipException(\"当前部门类型为【\" + DepartCategoryEnum.getNameByValue(oldOrgCategory) + \"】,不允许移动到公司\");\n}\n\n// after — frontend pre-checks category compatibility\nfunction canDropAdjacentToCompany(dragNode, dropNode) {\n    if (dropNode.orgCategory !== 'company') return true;\n    if (dragNode.orgCategory !== 'company') {\n        ElMessage.warning('只有公司类型可以移动到公司旁边');\n        return false;\n    }\n    return true;\n}","handlingStrategy":"validation","validationCode":"// Frontend: check category compatibility before drop\nconst isCompany = (node) => node.orgCategory === DepartCategoryEnum.COMPANY;\nif (dropPosition !== 0 && isCompany(dropNode) && !isCompany(dragNode)) {\n    ElMessage.warning('只有公司类型可以移动到公司旁边');\n    return;\n}","typeGuard":"public boolean canMoveAdjacentToCompany(String dragOrgCategory, String targetOrgCategory, int dropPosition) {\n    if (dropPosition == 0) return true;\n    if (!DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue().equals(targetOrgCategory)) return true;\n    return DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue().equals(dragOrgCategory);\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":["Filter drop targets by org-category compatibility in the frontend.","Display department type labels in the tree for clarity.","Educate users on the organizational hierarchy rules."],"tags":["jeecg-boot","department","drag-drop","business-rule","category-validation"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}