fix(rule-groups): 修复 getChildGroups 函数使用 FastAPI v3 接口
问题: - 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 <noreply@anthropic.com>
This commit is contained in:
@@ -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<ApiResponse<Array<{id: number}>>>(
|
||||
'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 {
|
||||
|
||||
Reference in New Issue
Block a user