35 lines
2.9 KiB
TypeScript
35 lines
2.9 KiB
TypeScript
// Presentation only: request payloads and concurrency fields retain their original values.
|
||
export function isInternalDataField(key: string): boolean {
|
||
return /^(?:(?:current|expected|expectedCurrent|baseline|new|base|result|source|target|pinned)?(?:releaseId|mappingVersionId|ruleVersionId|targetVersionId|masterDataVersionId)|schemaVersion|rowVersion|revisionId|engineVersion|engineRuleVersion|ruleVersion|rulesVersion|mappingVersion|targetVersion|masterDataVersion|configVersion|baselineSha256)$/i.test(key);
|
||
}
|
||
|
||
export function publicJson(value: unknown): string | undefined {
|
||
return JSON.stringify(value, (key, child) => isInternalDataField(key) ? undefined : child, 2);
|
||
}
|
||
|
||
export function publicErrorMessage(message: string, status?: number): string {
|
||
if (status && [502, 503, 504].includes(status)) return `质量数据服务暂不可用(HTTP ${status}),请稍后重试;当前无法确认数据覆盖。`;
|
||
if (/<(?:!doctype|html|head|body|script|title|h1)\b/i.test(message)) return `服务返回异常响应${status ? `(HTTP ${status})` : ''},请稍后重试。`;
|
||
return message
|
||
.replace(/(?:数据|发布|规则|映射|目标|配置)版本(?:\s*[((]?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}[))]?)?/gi, '当前数据或配置')
|
||
.replace(/(?:releaseId|mappingVersionId|ruleVersionId|targetVersionId)\s*[:=:]?\s*[0-9a-f-]{36}/gi, '当前数据或配置');
|
||
}
|
||
|
||
/** Display translation only. The service remains the source of formula and null policies. */
|
||
export function readableMetricFormula(description: unknown): string {
|
||
if (typeof description !== 'string' || !description.trim()) return '当前指标服务未提供公式说明';
|
||
const names: Record<string, string> = {
|
||
blackRate: '黑片合格率', brightRate: '亮片合格率', brightRateWithoutHeadquartersScrap: '亮片调整率(去本部报废)',
|
||
compositeRate: '综合合格率', compositeRateWithoutHeadquartersScrap: '综合调整率',
|
||
blackGood: '黑片合格重量', blackScrap: '黑片报废重量', blackTotal: '黑片适用总重量',
|
||
brightGood: '亮片合格重量', brightScrap: '亮片报废重量', brightTotal: '亮片适用总重量', headquartersScrap: '亮片本部报废重量',
|
||
};
|
||
const outcomes: Record<string, string> = { ONE: '取1(率值100%)', ZERO: '取0', NULL: '保留空值', ERROR: '报错' };
|
||
const nulls: Record<string, string> = { PROPAGATE: '运算结果保持空值', ZERO: '按0处理', IGNORE: '忽略空值' };
|
||
return description.replace(/\b[A-Za-z][A-Za-z0-9]*\b/g, token => names[token] || token)
|
||
.replace(/\*/g, '×').replace(/\//g, '÷')
|
||
.replace(/运算空值=(PROPAGATE|ZERO|IGNORE)/g, (_, policy: string) => `运算中遇到空值:${nulls[policy]}`)
|
||
.replace(/零分母=(ONE|ZERO|NULL|ERROR)/g, (_, policy: string) => `分母为0:${outcomes[policy]}`)
|
||
.replace(/空结果=(ONE|ZERO|NULL|ERROR)/g, (_, policy: string) => `计算结果为空:${outcomes[policy]}`);
|
||
}
|