{"record":{"id":"54b1e2d94a880822","repo":"jeecgboot/JeecgBoot","slug":"error-54b1e2","errorCode":null,"errorMessage":"无效的拖拽位置","messagePattern":"无效的拖拽位置","errorType":"exception","errorClass":"RuntimeException","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":2040,"sourceCode":"        //3. 验证拖拽操作是否合法\n        validateDragOperation(dragDept, targetDept, changeDepartVo.getDropPosition());\n        //4. 根据dropPosition调整部门顺序\n        Integer dropPosition = changeDepartVo.getDropPosition();\n        switch (dropPosition) {\n            case -1:\n                // 拖拽到上方\n                moveToAbove(dragDept, targetDept);\n                break;\n            case 0:\n                // 拖拽到内部（作为子部门）\n                moveAsChild(dragDept, targetDept);\n                break;\n            case 1:\n                //拖拽到下方\n                moveToBelow(dragDept, targetDept, changeDepartVo.getSort());\n                break;\n            default:\n                throw new RuntimeException(\"无效的拖拽位置\");\n        }\n        //5. 清空缓存\n        redisUtil.removeAll(CommonConstant.DEPART_NAME_REDIS_KEY_PRE);\n    }\n\n    /**\n     * 验证拖拽操作是否合法\n     *\n     * @param dragDept     被拖拽的部门\n     * @param targetDept   目标部门\n     * @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        // 禁止拖拽到自身子部门","sourceCodeStart":2022,"sourceCodeEnd":2058,"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#L2022-L2058","documentation":"Thrown by the default case in updateChangeDepart's switch statement when dropPosition is not one of {-1, 0, 1}. This is a raw RuntimeException (not JeecgBootBizTipException), meaning it is an unexpected/programmatic error rather than a user-facing business tip. The switch expects -1 (above), 0 (inside as child), or 1 (below).","triggerScenarios":"Calling updateChangeDepart with a dropPosition value outside {-1, 0, 1}, such as null, 2, -2, or any other integer. Most commonly a frontend bug in computing the drop position from the drag event, or a malformed API request.","commonSituations":"Frontend drag library version change that alters position encoding; null dropPosition from a missing form field; API testing with an invalid integer; a new position type added to the UI without backend support.","solutions":["Inspect the dropPosition value being sent by the frontend — it must be exactly -1, 0, or 1.","Fix the frontend drag handler to correctly map the drop location to one of the three valid positions.","Add input validation at the controller layer to reject invalid dropPosition before reaching the service.","If using a tree component library, verify its drop-position encoding matches the backend convention."],"exampleFix":"// before\nswitch (dropPosition) {\n    case -1: moveToAbove(dragDept, targetDept); break;\n    case 0: moveAsChild(dragDept, targetDept); break;\n    case 1: moveToBelow(dragDept, targetDept, changeDepartVo.getSort()); break;\n    default: throw new RuntimeException(\"无效的拖拽位置\");\n}\n\n// after — validate at the controller, use business exception in service\nif (dropPosition == null || dropPosition < -1 || dropPosition > 1) {\n    throw new JeecgBootBizTipException(\"无效的拖拽位置，必须为 -1、0 或 1\");\n}","handlingStrategy":"validation","validationCode":"// Validate dropPosition before calling updateChangeDepart\nInteger dropPosition = changeDepartVo.getDropPosition();\nif (dropPosition == null || dropPosition < -1 || dropPosition > 1) {\n    return Result.error(\"无效的拖拽位置，必须为 -1(上方)、0(内部) 或 1(下方)\");\n}\nservice.updateChangeDepart(changeDepartVo);","typeGuard":"public boolean isValidDropPosition(Integer position) {\n    return position != null && (position == -1 || position == 0 || position == 1);\n}","tryCatchPattern":"try {\n    service.updateChangeDepart(changeDepartVo);\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"无效的拖拽位置\")) {\n        return Result.error(\"拖拽位置参数无效，请重新操作\");\n    }\n    throw e;\n}","preventionTips":["Map frontend drag events to exactly {-1, 0, 1} before sending.","Add controller-layer validation for dropPosition range.","Test drag interactions across different tree component versions."],"tags":["jeecg-boot","department","drag-drop","invalid-input","runtime-exception"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}