feat: sync rule management and review ui fixes
This commit is contained in:
@@ -3,6 +3,7 @@ import { getUserSession } from '~/api/login/auth.server';
|
||||
import {
|
||||
buildRuleYamlPack,
|
||||
EMPTY_RULE_YAML,
|
||||
type RuleSummary,
|
||||
type RuleYamlPack,
|
||||
} from './rules-yaml-mock.server';
|
||||
|
||||
@@ -28,6 +29,23 @@ type RuleConfigPackApi = {
|
||||
sourceStatus?: 'ready' | 'empty' | 'missing';
|
||||
};
|
||||
|
||||
|
||||
export type RuleConfigPackSummary = {
|
||||
id: string;
|
||||
documentType: string;
|
||||
moduleType: string;
|
||||
mainType: string;
|
||||
subtype: string;
|
||||
businessType: string;
|
||||
ruleTypeCode: string;
|
||||
currentVersionId?: number | null;
|
||||
fallbackVersionId?: number | null;
|
||||
resolvedVersionId?: number | null;
|
||||
yamlName: string;
|
||||
sourceStatus: 'ready' | 'empty' | 'missing';
|
||||
rules: RuleSummary[];
|
||||
};
|
||||
|
||||
type ApiEnvelope<T> = {
|
||||
code?: number;
|
||||
message?: string;
|
||||
@@ -52,6 +70,27 @@ function getMessage(payload: unknown, fallback: string): string {
|
||||
return String((payload as ApiEnvelope<unknown>).message || (payload as ApiEnvelope<unknown>).msg || fallback);
|
||||
}
|
||||
|
||||
|
||||
function mapApiPackSummary(item: RuleConfigPackApi & { yamlName?: string; rules?: RuleSummary[] }): RuleConfigPackSummary {
|
||||
const ruleTypeCode = String(item.ruleType || '').trim();
|
||||
const businessType = item.mainType || item.documentType || '';
|
||||
return {
|
||||
id: String(item.packId),
|
||||
documentType: item.documentType || '',
|
||||
moduleType: item.moduleType || (item.documentType ? `${item.documentType}评查` : '规则配置'),
|
||||
mainType: item.mainType || item.documentType || '',
|
||||
subtype: item.subtype || '通用',
|
||||
businessType,
|
||||
ruleTypeCode,
|
||||
currentVersionId: item.currentVersionId ?? null,
|
||||
fallbackVersionId: item.fallbackVersionId ?? null,
|
||||
resolvedVersionId: item.resolvedVersionId ?? null,
|
||||
yamlName: String(item.yamlName || item.ruleName || ''),
|
||||
sourceStatus: item.sourceStatus || 'empty',
|
||||
rules: Array.isArray(item.rules) ? item.rules : [],
|
||||
};
|
||||
}
|
||||
|
||||
function mapApiPackToRuleYamlPack(item: RuleConfigPackApi): RuleYamlPack {
|
||||
const ruleTypeCode = String(item.ruleType || '').trim();
|
||||
// 业务类型必须以后端 pack 聚合返回的 mainType 为准。
|
||||
@@ -101,6 +140,12 @@ async function fetchRuleConfigPayload<T>(request: Request, path: string): Promis
|
||||
return payload.data;
|
||||
}
|
||||
|
||||
|
||||
export async function loadRuleConfigPackSummaries(request: Request): Promise<RuleConfigPackSummary[]> {
|
||||
const items = await fetchRuleConfigPayload<Array<RuleConfigPackApi & { yamlName?: string; rules?: RuleSummary[] }>>(request, '/api/v3/rule-config-packs?summaryOnly=true');
|
||||
return items.map(mapApiPackSummary);
|
||||
}
|
||||
|
||||
export async function loadRuleConfigPacks(request: Request): Promise<RuleYamlPack[]> {
|
||||
const items = await fetchRuleConfigPayload<RuleConfigPackApi[]>(request, '/api/v3/rule-config-packs');
|
||||
return items.map(mapApiPackToRuleYamlPack);
|
||||
|
||||
Reference in New Issue
Block a user