From 0e812ba181016c48d0d89888dc7ddcd5a80efe9f Mon Sep 17 00:00:00 2001 From: Wenyan Date: Tue, 25 Nov 2025 20:39:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(rule-groups):=20=E4=BF=AE=E5=A4=8D=20getChi?= =?UTF-8?q?ldGroups=20=E5=87=BD=E6=95=B0=E4=BD=BF=E7=94=A8=20FastAPI=20v3?= =?UTF-8?q?=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: - getChildGroups 函数内部仍在调用已重命名的 getRuleGroups 函数 - 导致运行时错误:"getRuleGroups is not defined" - 影响子分组加载功能 修复: - 更新 getChildGroups 使用 FastAPI v3 的 getEvaluationPointGroupChildren - 删除手动统计评查点数量的代码(FastAPI v3 接口已返回 rule_count) - 简化函数逻辑,直接返回接口数据 影响范围: - app/api/evaluation_points/rule-groups.ts (getChildGroups 函数) 功能: - 获取子分组列表及评查点数量 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/api/evaluation_points/rule-groups.ts | 58 ++++-------------------- 1 file changed, 10 insertions(+), 48 deletions(-) diff --git a/app/api/evaluation_points/rule-groups.ts b/app/api/evaluation_points/rule-groups.ts index b7832c3..5c6f58b 100644 --- a/app/api/evaluation_points/rule-groups.ts +++ b/app/api/evaluation_points/rule-groups.ts @@ -207,66 +207,28 @@ export async function getRuleGroups_legacy( /** * 获取指定分组的子分组(包含评查点数量统计) + * 🆕 已更新为使用 FastAPI v3 接口 * @param parentId 父分组ID * @param token JWT token (可选) * @returns 子分组列表 */ export async function getChildGroups(parentId: string, token?: string): Promise<{data: RuleGroup[]; error?: never} | {data?: never; error: string; status?: number}> { try { - // 使用改进后的 getRuleGroups 函数获取子分组 - const response = await getRuleGroups({ - pid: parentId, - pageSize: 1000, // 设置较大的页面大小以获取所有子分组 + // 🆕 使用 FastAPI v3 的 getEvaluationPointGroupChildren 获取子分组 + const response = await getEvaluationPointGroupChildren( + parentId, + { + pageSize: 1000, // 设置较大的页面大小以获取所有子分组 + }, token - }); + ); if (response.error) { return { error: response.error, status: response.status }; } - const childGroups = response.data || []; - - // 为每个子分组添加评查点数量统计 - const groupsWithCount = await Promise.all( - childGroups.map(async (group) => { - // 获取该分组的评查点数量 - const ruleCountParams: PostgrestParams = { - select: 'id', - filter: { - 'evaluation_point_groups_id': `eq.${group.id}` - }, - token - }; - - const ruleCountResponse = await postgrestGet>>( - 'evaluation_points', - ruleCountParams - ); - - let ruleCount = 0; - if (ruleCountResponse.error) { - // 查询失败,使用默认值 0 - ruleCount = 0; - } else if (ruleCountResponse.data) { - // 处理包装格式的响应 - if ('code' in ruleCountResponse.data && 'data' in ruleCountResponse.data) { - const wrappedData = ruleCountResponse.data as {code: number; data: Array<{id: number}>}; - ruleCount = Array.isArray(wrappedData.data) ? wrappedData.data.length : 0; - } - // 处理直接数组格式的响应 - else if (Array.isArray(ruleCountResponse.data)) { - ruleCount = (ruleCountResponse.data as Array<{id: number}>).length; - } - } - - return { - ...group, - ruleCount - }; - }) - ); - - return { data: groupsWithCount }; + // 🆕 FastAPI v3 接口已经返回了 rule_count(已转换为 ruleCount),无需手动统计 + return { data: response.data || [] }; } catch (error) { console.error('获取子分组列表出错:', error); return {