{"record":{"id":"4aa1580426398494","repo":"flipped-aurora/gin-vue-admin","slug":"primarydeptid-d-v","errorCode":null,"errorMessage":"primaryDeptId %d 必须属于合并后的部门集合 %v","messagePattern":"primaryDeptId (.+?) 必须属于合并后的部门集合 (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/mcp/org_member_assigner.go","lineNumber":155,"sourceCode":"\t\tUserID:   user.ID,\n\t\tUserName: user.Username,\n\t}\n\tvar messages []string\n\n\tif len(deptIDs) > 0 {\n\t\tmerged, added := mergeUintSets(currentDeptIDs, deptIDs)\n\n\t\t// 主部门语义:显式传参优先,否则保留用户现有主部门;上游对 0 值取集合首个\n\t\tprimary := user.DeptId\n\t\tif value, ok := args[\"primaryDeptId\"]; ok && value != nil {\n\t\t\texplicit, err := parseUintParam(value, \"primaryDeptId\")\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tprimary = explicit\n\t\t}\n\t\tif primary != 0 && !containsUint(merged, primary) {\n\t\t\treturn nil, fmt.Errorf(\"primaryDeptId %d 必须属于合并后的部门集合 %v\", primary, merged)\n\t\t}\n\n\t\tif len(added) > 0 || (primary != user.DeptId && primary != 0) {\n\t\t\tif _, err := postUpstream[map[string]any](ctx, \"/user/setUserDepartments\", map[string]any{\n\t\t\t\t\"ID\":            user.ID,\n\t\t\t\t\"deptIds\":       merged,\n\t\t\t\t\"primaryDeptId\": primary,\n\t\t\t}); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"设置用户部门失败: %w\", err)\n\t\t\t}\n\t\t\tmessages = append(messages, fmt.Sprintf(\"部门新增 %v\", added))\n\t\t} else {\n\t\t\tmessages = append(messages, \"部门均已存在,未写入\")\n\t\t}\n\t\tresult.Departments = &orgAssignChange{Before: currentDeptIDs, After: merged, Added: added}\n\t\t// 上游对 primaryDeptId=0 取部门集合首个;如实回报生效主部门,不因 0 值被 omitempty 隐去而误导\n\t\tresult.PrimaryDeptID = primary\n\t\tif primary == 0 && len(merged) > 0 {","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/mcp/org_member_assigner.go#L137-L173","documentation":"Validation error thrown by org_member_assigner Handle when the explicitly requested primaryDeptId is not a member of the final merged department set. The tool refuses to set a user's primary department to one they would not belong to after the merge of current and new department IDs, because the upstream setUserDepartments API would reject or inconsistently store such a primary.","triggerScenarios":"Calling the org member assign MCP tool with a primaryDeptId that is neither among the user's existing deptIds nor in the deptIDs being added, while primaryDeptId != 0.","commonSituations":"Typo or stale department ID from a deleted dept; passing a parent/ancestor department expecting implicit membership; forgetting to include the primary dept in the deptIDs list of the same call.","solutions":["Add the primaryDeptId value to the deptIDs array in the same tool call so it lands in the merged set","Use primaryDeptId=0 (or omit it) to keep the user's existing primary department","Verify the department ID exists via the org query tool and re-check for typos"],"exampleFix":"// before\n{\"userId\": 5, \"deptIds\": [2,3], \"primaryDeptId\": 9}\n// after\n{\"userId\": 5, \"deptIds\": [2,3,9], \"primaryDeptId\": 9}","handlingStrategy":"validation","validationCode":"func canAssign(deptIDs, merged []uint, primaryDeptId uint) error {\n    if primaryDeptId == 0 {\n        return nil\n    }\n    for _, id := range merged {\n        if id == primaryDeptId {\n            return nil\n        }\n    }\n    return fmt.Errorf(\"primaryDeptId %d not in merged dept set %v\", primaryDeptId, merged)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include primaryDeptId in the deptIDs array of the same call","Pass primaryDeptId=0 when you do not intend to change the primary department","Look up department IDs with the org query tool instead of hardcoding them"],"tags":["validation","mcp","org-assign"],"backgroundTag":"invalid-parameter-validation","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}