| | |
| | | import { ref } from 'vue' |
| | | import { closeWarningException, getWarningExceptions, type WarningExceptionRecord } from '@/api/tests' |
| | | import { formatBusinessTime } from '@/utils/businessTime' |
| | | |
| | | export type ExceptionStatus = '待处理' | '已处理' |
| | | |
| | |
| | | const records = ref<ExceptionRecord[]>([]) |
| | | |
| | | function mapRecord(item: WarningExceptionRecord): ExceptionRecord { |
| | | const offline = item.exceptionType === 'DEVICE_OFFLINE' |
| | | let normalValue = '-' |
| | | try { const rule = JSON.parse(item.ruleSnapshot || '{}'); normalValue = rule.maxValue != null ? `≤ ${rule.maxValue} ${item.unit}` : rule.minValue != null ? `≥ ${rule.minValue} ${item.unit}` : '-' } catch { /* 快照不可解析时仍展示异常事实 */ } |
| | | return { id: item.exceptionId, testId: item.testId, testName: item.testName || `测试 #${item.testId}`, testTime: item.firstOccurredAtUtc, source: `${item.sourceType}${item.sourceIdentity ? ` · ${item.sourceIdentity}` : ''}`, exceptionItem: item.metricCode, abnormalValue: `${item.abnormalValue} ${item.unit}`, normalValue, generatedAt: item.lastOccurredAtUtc, processor: item.handledByName || '', handledAt: item.handledAtUtc || '-', status: item.exceptionStatus === 'OPEN' ? '待处理' : '已处理', handleRemark: item.handlingNote || '' } |
| | | const sourceLabel = ({ CABINET: '检测柜', CABINET_CHANNEL: '检测柜通道', COLLECTOR: '采集器' } as Record<string, string>)[item.sourceType] || item.sourceType |
| | | return { |
| | | id: item.exceptionId, testId: item.testId, testName: item.testName || `测试 #${item.testId}`, |
| | | testTime: formatBusinessTime(item.firstOccurredAtUtc), |
| | | source: `${sourceLabel}${item.sourceIdentity ? ` · ${item.sourceIdentity}` : ''}`, |
| | | exceptionItem: offline ? '设备离线' : item.metricCode, |
| | | abnormalValue: offline ? '离线' : item.abnormalValue == null ? '-' : `${item.abnormalValue} ${item.unit}`, |
| | | normalValue: offline ? '在线' : normalValue, |
| | | generatedAt: formatBusinessTime(item.lastOccurredAtUtc), processor: item.handledByName || '', |
| | | handledAt: formatBusinessTime(item.handledAtUtc), status: item.exceptionStatus === 'OPEN' ? '待处理' : '已处理', |
| | | handleRemark: item.handlingNote || '', |
| | | } |
| | | } |
| | | |
| | | export function useExceptions() { |