| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- export const FACILITY_STATUS_LABELS = {
- source: { '0': '正常', '1': '异常' },
- plant: { '0': '正常', '1': '停产' },
- pumpStation: { '0': '正常', '1': '故障停运', '2': '检修中' },
- // 管网状态与其他设施统一:0-正常 / 1-异常
- pipe: { '0': '正常', '1': '异常' },
- user: { '0': '正常', '1': '欠费', '2': '停用' }
- }
- export const FACILITY_TYPE_LABELS = {
- source: '水源地',
- plant: '水厂',
- pumpStation: '泵站',
- pipe: '管网',
- user: '用水户'
- }
- export const FACILITY_SECTION_TYPES = {
- pipeNetwork: 'pipe',
- waterPlant: 'plant',
- waterSource: 'source',
- waterUser: 'user',
- pumpStation: 'pumpStation'
- }
- export const FACILITY_SECTION_LABELS = {
- pipeNetwork: FACILITY_TYPE_LABELS.pipe,
- waterPlant: FACILITY_TYPE_LABELS.plant,
- waterSource: FACILITY_TYPE_LABELS.source,
- waterUser: FACILITY_TYPE_LABELS.user,
- pumpStation: FACILITY_TYPE_LABELS.pumpStation
- }
- export const FACILITY_STATUS_TAG_TYPES = {
- source: { '0': 'success', '1': 'danger' },
- plant: { '0': 'success', '1': 'danger' },
- pumpStation: { '0': 'success', '1': 'danger', '2': 'warning' },
- pipe: { '0': 'success', '1': 'danger' },
- user: { '0': 'success', '1': 'warning', '2': 'danger' }
- }
- const unknownStatus = { label: '未知', tagType: 'info' }
- const FACILITY_TYPE_ORDER = ['source', 'plant', 'pumpStation', 'pipe', 'user']
- // 后端统计汇总接口以 Map 返回明细,键名是 SQL 别名(total_count / design_capacity ...)。
- // 这里以驼峰键为唯一口径,同时在查询前把下划线键归一化,避免英文原键漏到统计明细表格。
- export const STATISTIC_METRIC_LABELS = {
- totalCount: '总数',
- totalLength: '总长度',
- averageDiameter: '平均管径',
- designCapacity: '设计规模',
- currentCapacity: '实际规模',
- capacityUtilization: '产能利用率',
- pumpCount: '水泵数量',
- designFlow: '设计流量',
- designHead: '设计扬程',
- powerCapacity: '装机容量',
- annualWaterConsumption: '年用水量',
- materialDistribution: '管材分布',
- diameterDistribution: '管径分布',
- layingYearDistribution: '建设年代分布',
- levelDistribution: '等级分布',
- statusDistribution: '状态分布',
- waterSourceTypeDistribution: '水源类型分布',
- sourceTypeDistribution: '水源地类型分布',
- qualityDistribution: '水质等级分布',
- protectionDistribution: '保护等级分布',
- userTypeDistribution: '用水户类型分布',
- consumptionDistribution: '用水量分布'
- }
- export const STATISTIC_METRIC_DESCRIPTIONS = {
- totalCount: '当前筛选条件下的设施总数',
- totalLength: '当前筛选条件下的管网总长度',
- averageDiameter: '当前筛选条件下的管径平均值',
- designCapacity: '水厂设计供水能力',
- currentCapacity: '水厂实际供水能力',
- capacityUtilization: '实际供水能力与设计供水能力的比值',
- pumpCount: '泵站内水泵总数量',
- designFlow: '泵站设计流量',
- designHead: '泵站设计扬程',
- powerCapacity: '泵站装机总容量',
- annualWaterConsumption: '用水户年度用水量',
- materialDistribution: '按管材统计管网数量',
- diameterDistribution: '按管径区间统计管网数量',
- layingYearDistribution: '按建设年代统计管网数量',
- levelDistribution: '按等级统计管网数量',
- statusDistribution: '按业务状态统计设施数量',
- waterSourceTypeDistribution: '按水源类型统计水厂数量',
- sourceTypeDistribution: '按水源地类型统计数量',
- qualityDistribution: '按水质等级统计水源地数量',
- protectionDistribution: '按保护等级统计水源地数量',
- userTypeDistribution: '按用水户类型统计数量',
- consumptionDistribution: '按用水量区间统计用水户数量'
- }
- // 分布类统计的原始码值翻译;未登记的纯英文码值不直接展示,统一归入「其他」。
- export const DISTRIBUTION_VALUE_LABELS = {
- materialDistribution: {
- PE: '聚乙烯',
- HDPE: '高密度聚乙烯',
- PVC: '聚氯乙烯',
- 'PVC-U': '硬聚氯乙烯',
- PVCU: '硬聚氯乙烯',
- PP: '聚丙烯',
- PPR: '无规共聚聚丙烯',
- 'PE-X': '交联聚乙烯',
- PEX: '交联聚乙烯',
- ABS: '工程塑料',
- FRP: '玻璃钢管',
- GRP: '玻璃钢管'
- }
- }
- const UNKNOWN_GROUP_LABEL = '未填报'
- const UNKNOWN_METRIC_LABEL = '其他指标'
- const UNKNOWN_METRIC_DESCRIPTION = '按当前筛选条件统计'
- const UNKNOWN_SECTION_LABEL = '总览'
- const UNKNOWN_MATERIAL_LABEL = '其他管材'
- const STATISTIC_METRIC_UNIT = '项'
- // 码值识别:以字母开头的纯 ASCII 串视为编码(如 PE / PVC-U / HDPE);
- // 数字区间与含中文的值(100-299mm、Ⅳ类)保持原样展示。
- const ASCII_CODE_PATTERN = /^[A-Za-z][A-Za-z0-9._/-]*$/
- export function normalizeStatisticKey(key) {
- return String(key ?? '')
- .trim()
- .replace(/_([A-Za-z0-9])/g, (match, char) => char.toUpperCase())
- }
- export function resolveStatisticMetricLabel(key) {
- return STATISTIC_METRIC_LABELS[normalizeStatisticKey(key)] || UNKNOWN_METRIC_LABEL
- }
- export function resolveStatisticMetricDescription(key) {
- return STATISTIC_METRIC_DESCRIPTIONS[normalizeStatisticKey(key)] || UNKNOWN_METRIC_DESCRIPTION
- }
- export function resolveFacilitySectionLabel(key) {
- return FACILITY_SECTION_LABELS[key] || UNKNOWN_SECTION_LABEL
- }
- export function resolveDistributionValueLabel(metricKey, rawName) {
- const value = rawName === null || rawName === undefined ? '' : String(rawName).trim()
- if (!value) return UNKNOWN_GROUP_LABEL
- const labels = DISTRIBUTION_VALUE_LABELS[metricKey]
- if (labels && labels[value]) return labels[value]
- if (ASCII_CODE_PATTERN.test(value)) return labels ? UNKNOWN_MATERIAL_LABEL : UNKNOWN_GROUP_LABEL
- return value
- }
- export const STATISTIC_ROW_KIND = {
- METRIC: 'metric',
- DISTRIBUTION: 'distribution'
- }
- // 把后端 dashboard 的嵌套结构摊平成统计明细行。
- // 数组 => 分布分组(kind=distribution);标量 => 指标值(kind=metric),
- // 这样嵌套对象的 value/unit 这类结构键不会作为分组名进入表格。
- export function flattenStatisticMetrics(section, value) {
- if (Array.isArray(value)) {
- return value.map(item => ({ ...item, section, kind: STATISTIC_ROW_KIND.DISTRIBUTION }))
- }
- if (!value || typeof value !== 'object') {
- return [{ name: section, value, unit: STATISTIC_METRIC_UNIT, section: '', kind: STATISTIC_ROW_KIND.METRIC }]
- }
- return Object.entries(value).flatMap(([name, metric]) => {
- if (Array.isArray(metric)) {
- return metric.map(item => ({
- ...item,
- section: `${section}/${name}`,
- kind: STATISTIC_ROW_KIND.DISTRIBUTION
- }))
- }
- if (metric && typeof metric === 'object') {
- return flattenStatisticMetrics(`${section}/${name}`, metric)
- }
- return [{ name, value: metric, unit: STATISTIC_METRIC_UNIT, section, kind: STATISTIC_ROW_KIND.METRIC }]
- })
- }
- export function formatStatisticRow(section, item, options = {}) {
- const levelLabel = typeof options.levelLabel === 'function' ? options.levelLabel : value => value
- const [facilityKey, metricKey] = String(section ?? '').split('/')
- const facilityType = FACILITY_SECTION_TYPES[facilityKey] || facilityKey
- const facilityLabel = resolveFacilitySectionLabel(facilityKey)
- const rawMetricKey = metricKey || item.name
- const metricLabel = resolveStatisticMetricLabel(rawMetricKey)
- const isDistribution = item.kind === STATISTIC_ROW_KIND.DISTRIBUTION
- const isStatusDistribution = isDistribution && metricKey === 'statusDistribution'
- const isLevelDistribution = isDistribution && metricKey === 'levelDistribution'
- const name = isStatusDistribution
- ? resolveFacilityStatusLabel(facilityType, item.name)
- : isLevelDistribution
- ? levelLabel(item.name)
- : isDistribution
- ? resolveDistributionValueLabel(metricKey, item.name)
- : metricLabel
- return {
- section: `${facilityLabel} - ${metricLabel}`,
- name,
- tagType: isStatusDistribution ? resolveFacilityStatusTagType(facilityType, item.name) : undefined,
- value: item.value ?? item.totalCount ?? 0,
- unit: item.unit || STATISTIC_METRIC_UNIT,
- description: resolveStatisticMetricDescription(rawMetricKey)
- }
- }
- export function buildPipeNetworkStatisticsQuery({ facilityTypes = [], status = '' } = {}) {
- const query = {}
- const types = Array.isArray(facilityTypes)
- ? facilityTypes.map(type => String(type).trim()).filter(Boolean)
- : []
- const normalizedStatus = String(status ?? '').trim()
- if (types.length) query.facilityTypes = types.join(',')
- if (normalizedStatus) query.status = normalizedStatus
- return query
- }
- export function getFacilityStatusOptions(facilityTypes = []) {
- const types = FACILITY_TYPE_ORDER.filter(type => facilityTypes.includes(type))
- const statusValues = new Set()
- types.forEach(type => {
- Object.keys(FACILITY_STATUS_LABELS[type] || {}).forEach(status => statusValues.add(status))
- })
- return [...statusValues].sort().map(status => {
- const labels = types
- .map(type => ({
- type,
- label: FACILITY_STATUS_LABELS[type]?.[status]
- }))
- .filter(item => item.label)
- const distinctLabels = [...new Set(labels.map(item => item.label))]
- const label = types.length === 1
- ? `${FACILITY_TYPE_LABELS[types[0]]}: ${distinctLabels[0]}`
- : distinctLabels.join(' / ')
- return { value: status, label }
- })
- }
- export function resolveFacilityStatusLabel(type, status) {
- const value = status === null || status === undefined ? '' : String(status)
- return FACILITY_STATUS_LABELS[type]?.[value] || unknownStatus.label
- }
- export function resolveFacilityStatusTagType(type, status) {
- const value = status === null || status === undefined ? '' : String(status)
- return FACILITY_STATUS_TAG_TYPES[type]?.[value] || unknownStatus.tagType
- }
|