diff --git a/app/api/evaluation_points/rules.ts b/app/api/evaluation_points/rules.ts index 67a2d1d..3c1c33f 100644 --- a/app/api/evaluation_points/rules.ts +++ b/app/api/evaluation_points/rules.ts @@ -277,35 +277,39 @@ export async function getRulesList(params: RulesQueryParams): Promise<{data: Rul console.log('✅ [getRulesList] 成功获取评查点列表,共', response.data.total, '条'); - // 🆕 将 FastAPI 返回的 EvaluationPointData 映射到前端的 Rule 模型 - // 注意:FastAPI 已经包含了分组信息,不需要再额外查询 + // 🆕 直接映射后端返回的数据到前端 Rule 模型 + // 后端已包含 ruleType、groupName、groupId 字段,无需额外处理 const mappedRules: Rule[] = response.data.data.map((point: EvaluationPointData) => { - // 将 EvaluationPointData 转换为 ApiRule 格式(临时兼容旧的映射函数) - const apiRule: ApiRule = { - id: point.id!, - code: point.code, - name: point.name, - area: point.area, - evaluation_point_groups_id: point.evaluation_point_groups_id, - evaluation_point_groups_pid: point.evaluation_point_groups_pid, - risk: point.risk, - description: point.description || '', - is_enabled: point.is_enabled, - created_at: point.created_at!, - updated_at: point.updated_at!, - // FastAPI 返回的数据已包含分组信息(如果后端实现了关联查询) - // 如果没有,这里可以设置为 null,前端会显示 ID - child_group: null, - parent_group: null + // 风险等级映射到优先级 + const priorityMap: Record = { + '高': 'high', + '中': 'medium', + '低': 'low', + 'high': 'high', + 'medium': 'medium', + 'low': 'low' }; - const rule = mapApiRuleToFrontendModel(apiRule); + // 🔑 清洗评查点编码:移除最后一个 '--' 及其后面的字符 + let cleanedCode = point.code || ''; + const lastDoubleHyphenIndex = cleanedCode.lastIndexOf('--'); + if (lastDoubleHyphenIndex !== -1) { + cleanedCode = cleanedCode.substring(0, lastDoubleHyphenIndex); + } - // 格式化日期字段 - rule.createdAt = formatDate(rule.createdAt); - rule.updatedAt = formatDate(rule.updatedAt); - - return rule; + return { + id: point.id?.toString() || '', + code: cleanedCode, + name: point.name || '', + ruleType: point.ruleType || '', // ✅ 后端直接返回 + groupId: point.groupId || '', // ✅ 后端直接返回 + groupName: point.groupName || '', // ✅ 后端直接返回 + priority: priorityMap[point.risk] || 'medium', + description: point.description || '', + isActive: point.is_enabled, + createdAt: formatDate(point.created_at || ''), + updatedAt: formatDate(point.updated_at || '') + }; }); return { @@ -789,10 +793,18 @@ export interface RuleGroup { */ export async function getRuleTypes(documentTypeIds?: number[], token?: string): Promise<{data: RuleType[]; error?: never} | {data?: never; error: string; status?: number}> { try { + // 🔑 如果没有传入 documentTypeIds,返回空数组 + if (!documentTypeIds || documentTypeIds.length === 0) { + console.warn('getRuleTypes: 未提供 documentTypeIds 参数'); + return { data: [] }; + } const documentTypesParams: PostgrestParams = { select: 'id, name, evaluation_point_groups_ids', - filter: {}, + filter: { + // 🔑 只查询指定的文档类型 ID + 'id': `in.(${documentTypeIds.join(',')})` + }, token }; @@ -1776,6 +1788,10 @@ export interface EvaluationPointData { description?: string; evaluation_point_groups_id: number | null; evaluation_point_groups_pid: number | null; + // 🆕 后端新增的分组名称字段 + ruleType?: string; // 评查点类型(一级分组名称) + groupName?: string; // 所属规则组(二级分组名称) + groupId?: string; // 规则组ID(二级分组ID的字符串形式) references_laws: { name: string; content: string;