flipped-aurora/gin-vue-admin · error
部门 %d 不存在,可先用 query_org_structure 查询部门树
Error message
部门 %d 不存在,可先用 query_org_structure 查询部门树
What it means
Before writing, assign_user_org validates every deptId against the flattened department tree fetched from upstream. Any ID absent from the tree is rejected with this error, suggesting the query_org_structure tool to discover valid IDs.
Source
Thrown at server/mcp/org_member_assigner.go:109
}
if len(deptIDs) > orgBatchLimit || len(positionIDs) > orgBatchLimit {
return nil, fmt.Errorf("单次分配的部门/岗位数量各不能超过 %d 个", orgBatchLimit)
}
// primaryDeptId 只在设置部门(deptIds)时生效;仅传 primaryDeptId 不传 deptIds 会被静默丢弃,
// 显式挡回避免调用方误以为主部门已变更
if value, ok := args["primaryDeptId"]; ok && value != nil && len(deptIDs) == 0 {
return nil, errors.New("primaryDeptId 需与 deptIds 一起传入(主部门必须属于本次追加或已有的部门集合);仅调整主部门请到前端组织管理页操作")
}
// 校验目标部门/岗位真实存在,把无效ID挡在写入之前
if len(deptIDs) > 0 {
deptIndex, err := fetchDeptIndex(ctx)
if err != nil {
return nil, err
}
for _, id := range deptIDs {
if _, ok := deptIndex[id]; !ok {
return nil, fmt.Errorf("部门 %d 不存在,可先用 query_org_structure 查询部门树", id)
}
}
}
for _, id := range positionIDs {
query := url.Values{}
query.Set("id", strconv.FormatUint(uint64(id), 10))
if _, err := getUpstream[system.SysPosition](ctx, "/position/findPosition", query); err != nil {
return nil, fmt.Errorf("岗位 %d 校验失败: %w", id, err)
}
}
user, err := findUserByID(ctx, userID, usernameHint)
if err != nil {
return nil, err
}
currentDeptIDs := make([]uint, 0, len(user.Departments))
for _, dept := range user.Departments {View on GitHub (pinned to 3136500ef3)
Solutions
- Run the query_org_structure MCP tool to list the actual department tree and pick valid IDs
- Verify the department exists in the admin UI organization page
- Check you are in the correct environment (IDs differ between dev/prod)
- Remove the stale ID from your automation/config
Defensive patterns
Strategy: validation
Validate before calling
// load the department tree first and filter to known-good IDs
const tree = await fetch('/department/getDepartmentList', { method: 'POST' }).then(r => r.json())
const valid = new Set(flatten(tree.data).map(d => d.ID))
const safe = deptIds.filter(id => valid.has(id)) Type guard
function deptExists(deptIndex, id) {
return Object.prototype.hasOwnProperty.call(deptIndex, id)
} Try / catch
try {
await callMcpTool('assign_user_org', args)
} catch (e) {
if (/部门 \d+ 不存在/.test(e.message)) {
// call query_org_structure, refresh your ID map, re-issue with valid IDs
}
} Prevention
- Discover department IDs via query_org_structure instead of hardcoding
- Never reuse dept IDs across environments
- Re-sync your ID cache after org restructures or deletions
When it happens
Trigger: Calling assign_user_org with a deptId that does not exist (typo, deleted department, or an ID from another environment).
Common situations: Hardcoded department IDs that changed after reorg/department deletion; copying IDs between dev and prod; LLM hallucinating plausible-looking department IDs.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/14415a1dd1991aa5.
Report an issue: GitHub.