jeecgboot/JeecgBoot · warning · RuntimeException

不能拖拽到自身

Error message

不能拖拽到自身

What it means

Thrown by validateDragOperation when dragDept.getId().equals(targetDept.getId()) — the dragged department is the same as the target. This RuntimeException prevents a self-referencing move operation that would create a cycle or no-op. It is the first check in the drag validation chain.

Source

Thrown at jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysDepartServiceImpl.java:2056

                break;
            default:
                throw new RuntimeException("无效的拖拽位置");
        }
        //5. 清空缓存
        redisUtil.removeAll(CommonConstant.DEPART_NAME_REDIS_KEY_PRE);
    }

    /**
     * 验证拖拽操作是否合法
     *
     * @param dragDept     被拖拽的部门
     * @param targetDept   目标部门
     * @param dropPosition 拖拽位置
     */
    private void validateDragOperation(SysDepart dragDept, SysDepart targetDept, Integer dropPosition) {
        // 禁止拖拽到自身
        if (dragDept.getId().equals(targetDept.getId())) {
            throw new RuntimeException("不能拖拽到自身");
        }
        // 禁止拖拽到自身子部门
        if (isDescendant(dragDept, targetDept.getId())) {
            throw new RuntimeException("不能拖拽到自身子部门");
        }
        //公司岗位判断
        String orgCategory = targetDept.getOrgCategory();
        String oldOrgCategory = dragDept.getOrgCategory();
        //部门为公司
        if(0 != dropPosition && DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue().equals(orgCategory)){
            //当前部门不能为子公司、部门和岗位
            if(!DepartCategoryEnum.DEPART_CATEGORY_COMPANY.getValue().equals(oldOrgCategory)){
                throw new JeecgBootBizTipException("当前部门类型为【"+DepartCategoryEnum.getNameByValue(oldOrgCategory)+"】,不允许移动到公司");
            }
        }
        //部门为岗位不允许移入
        if(0 == dropPosition && DepartCategoryEnum.DEPART_CATEGORY_POST.getValue().equals(orgCategory)) {
            throw new JeecgBootBizTipException("岗位不允许存在子级");

View on GitHub (pinned to 96fb33f5ec)

Solutions

  1. Add a frontend guard: disable drop events on the node being dragged.
  2. Validate that dragId != dropId in the controller before calling the service.
  3. In the UI, visually indicate that self-drop is not allowed (e.g., show a 'no-drop' cursor).

Example fix

// before
if (dragDept.getId().equals(targetDept.getId())) {
    throw new RuntimeException("不能拖拽到自身");
}

// after — frontend prevents the call entirely
function onDrop(dragNode, dropNode, position) {
    if (dragNode.id === dropNode.id) {
        ElMessage.warning('不能拖拽到自身');
        return false;
    }
    return true;
}
Defensive patterns

Strategy: validation

Validate before calling

// Frontend: prevent self-drag before API call
if (dragId === dropId) {
    ElMessage.warning('不能拖拽到自身');
    return;
}
// Backend controller pre-check:
if (changeDepartVo.getDragId().equals(changeDepartVo.getDropId())) {
    return Result.error("不能拖拽到自身");
}

Type guard

public boolean isSelfDrag(String dragId, String dropId) {
    return dragId != null && dragId.equals(dropId);
}

Try / catch

try {
    service.updateChangeDepart(changeDepartVo);
} catch (RuntimeException e) {
    if (e.getMessage().contains("不能拖拽到自身")) {
        return Result.error("不能拖拽到自身,请选择其他目标");
    }
    throw e;
}

Prevention

When it happens

Trigger: A drag-and-drop where the user drags a department onto itself, or where the frontend erroneously sends the same ID for both dragId and dropId. This can happen with UI bugs where the drag source and drop target resolve to the same tree node.

Common situations: Frontend tree component fires a drop event on the source node itself; a user accidentally releases the mouse on the same node; a programmatic test or script passes identical IDs.

Related errors


AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14). Data as JSON: /api/errors/56de34b7464c239e. Report an issue: GitHub.