refactor: expose ETC integration readiness

This commit is contained in:
kkfluous
2026-08-07 15:00:58 +08:00
parent cdf1fd27e7
commit 0fb62135f3
8 changed files with 363 additions and 76 deletions
+125 -4
View File
@@ -1,5 +1,5 @@
export type MetricDomain = 'mileage' | 'hydrogen' | 'electric';
export type MetricUnit = 'km' | 'kg' | 'kwh' | 'cny' | 'cny-per-kwh' | 'percent' | 'vehicle' | 'station' | 'order' | 'timestamp';
export type MetricDomain = 'mileage' | 'hydrogen' | 'electric' | 'etc';
export type MetricUnit = 'km' | 'kg' | 'kwh' | 'cny' | 'cny-per-kwh' | 'percent' | 'vehicle' | 'station' | 'order' | 'passage' | 'timestamp';
export type MetricAggregation = 'sum' | 'count' | 'derived' | 'weighted-ratio' | 'distinct-count' | 'latest';
export type MetricTimeSemantics = 'flow' | 'snapshot' | 'freshness';
@@ -14,10 +14,10 @@ export interface MetricDefinition {
formula: string;
sources: readonly string[];
dimensions: readonly string[];
drillEntity: 'vehicle' | 'assessment-target' | 'hydrogen-station' | 'hydrogen-customer' | 'hydrogen-order' | 'electric-charge-order';
drillEntity: 'vehicle' | 'assessment-target' | 'hydrogen-station' | 'hydrogen-customer' | 'hydrogen-order' | 'electric-charge-order' | 'etc-toll-record' | 'etc-bill';
}
export const METRIC_CATALOG_VERSION = 3;
export const METRIC_CATALOG_VERSION = 4;
const MILEAGE_METRICS: readonly MetricDefinition[] = [
{
@@ -275,10 +275,131 @@ const ELECTRIC_METRICS: readonly MetricDefinition[] = [
},
];
const ETC_METRICS: readonly MetricDefinition[] = [
{
id: 'etc.toll_amount',
domain: 'etc',
label: '通行费',
description: '有效 ETC 通行记录中的道路通行费之和,不含服务费。',
unit: 'cny',
aggregation: 'sum',
timeSemantics: 'flow',
formula: "SUM(toll_amount) WHERE del_flag = '0'",
sources: ['etc_toll_record'],
dimensions: ['date', 'plate', 'customer', 'route', 'cost-type', 'payment-mode', 'contract-match'],
drillEntity: 'etc-toll-record',
},
{
id: 'etc.service_fee',
domain: 'etc',
label: 'ETC 服务费',
description: '有效 ETC 通行记录中的服务费之和。',
unit: 'cny',
aggregation: 'sum',
timeSemantics: 'flow',
formula: "SUM(service_fee) WHERE del_flag = '0'",
sources: ['etc_toll_record'],
dimensions: ['date', 'plate', 'customer', 'route', 'cost-type', 'payment-mode'],
drillEntity: 'etc-toll-record',
},
{
id: 'etc.total_amount',
domain: 'etc',
label: 'ETC 总费用',
description: '有效 ETC 通行记录的总金额之和,业务定义为通行费加服务费。',
unit: 'cny',
aggregation: 'sum',
timeSemantics: 'flow',
formula: "SUM(total_amount) WHERE del_flag = '0'",
sources: ['etc_toll_record'],
dimensions: ['date', 'plate', 'customer', 'route', 'cost-type', 'payment-mode', 'deduction-status'],
drillEntity: 'etc-toll-record',
},
{
id: 'etc.passage_count',
domain: 'etc',
label: '通行次数',
description: '有效 ETC 通行记录按记录编码去重后的通行次数。',
unit: 'passage',
aggregation: 'distinct-count',
timeSemantics: 'flow',
formula: "COUNT(DISTINCT record_code) WHERE del_flag = '0'",
sources: ['etc_toll_record'],
dimensions: ['date', 'plate', 'customer', 'route', 'cost-type', 'payment-mode'],
drillEntity: 'etc-toll-record',
},
{
id: 'etc.vehicle_count',
domain: 'etc',
label: '通行车辆数',
description: '所选范围内产生有效 ETC 通行记录的去重车牌数量。',
unit: 'vehicle',
aggregation: 'distinct-count',
timeSemantics: 'flow',
formula: "COUNT(DISTINCT plate_number) WHERE del_flag = '0'",
sources: ['etc_toll_record'],
dimensions: ['date', 'customer', 'route', 'cost-type'],
drillEntity: 'vehicle',
},
{
id: 'etc.company_borne_amount',
domain: 'etc',
label: '我方承担 ETC 费用',
description: '费用承担方 cost_type=2 的有效 ETC 总费用。',
unit: 'cny',
aggregation: 'sum',
timeSemantics: 'flow',
formula: "SUM(total_amount) WHERE del_flag = '0' AND cost_type = 2",
sources: ['etc_toll_record'],
dimensions: ['date', 'plate', 'customer', 'route', 'payment-mode'],
drillEntity: 'etc-toll-record',
},
{
id: 'etc.customer_borne_amount',
domain: 'etc',
label: '客户承担 ETC 费用',
description: '费用承担方 cost_type=1 的有效 ETC 总费用。',
unit: 'cny',
aggregation: 'sum',
timeSemantics: 'flow',
formula: "SUM(total_amount) WHERE del_flag = '0' AND cost_type = 1",
sources: ['etc_toll_record'],
dimensions: ['date', 'plate', 'customer', 'route', 'payment-mode'],
drillEntity: 'etc-toll-record',
},
{
id: 'etc.bill_receivable',
domain: 'etc',
label: 'ETC 账单应收',
description: '有效 ETC 账单的应收金额之和,与通行记录费用属于不同结算粒度。',
unit: 'cny',
aggregation: 'sum',
timeSemantics: 'flow',
formula: "SUM(receivable_amount) WHERE del_flag = '0'",
sources: ['energy_etc_bill'],
dimensions: ['bill-period', 'customer', 'payment-status', 'review-status', 'finance-status'],
drillEntity: 'etc-bill',
},
{
id: 'etc.bill_paid_amount',
domain: 'etc',
label: 'ETC 账单已收',
description: '有效 ETC 账单的已支付金额之和。',
unit: 'cny',
aggregation: 'sum',
timeSemantics: 'flow',
formula: "SUM(paid_amount) WHERE del_flag = '0'",
sources: ['energy_etc_bill'],
dimensions: ['bill-period', 'customer', 'payment-status', 'review-status', 'finance-status'],
drillEntity: 'etc-bill',
},
];
export const METRIC_CATALOG: readonly MetricDefinition[] = [
...MILEAGE_METRICS,
...HYDROGEN_METRICS,
...ELECTRIC_METRICS,
...ETC_METRICS,
];
export function isMetricDomain(value: string): value is MetricDomain {