refactor: 移除旧版的录像诊断卡片与辅助函数
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
import type { Station } from '@/apis';
|
||||
import type { NvrRecordDiag } from './record-check';
|
||||
import { downloadByData, formatDuration } from '@/utils';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
export const exportRecordDiagCsv = (recordDiags: NvrRecordDiag[], stationName: Station['name']) => {
|
||||
const csvHeader = '通道名称,开始时间,结束时间,持续时长\n';
|
||||
const csvRows = recordDiags
|
||||
.map((channel) => {
|
||||
if (channel.lostChunks.length === 0) {
|
||||
return `${channel.channelName},,,`;
|
||||
}
|
||||
return channel.lostChunks
|
||||
.map((loss) => {
|
||||
const duration = formatDuration(loss.startTime, loss.endTime);
|
||||
const startTime = dayjs(loss.startTime).format('YYYY-MM-DD HH:mm:ss');
|
||||
const endTime = dayjs(loss.endTime).format('YYYY-MM-DD HH:mm:ss');
|
||||
return `${channel.channelName},${startTime},${endTime},${duration}`;
|
||||
})
|
||||
.join('\n');
|
||||
})
|
||||
.join('\n');
|
||||
const csvContent = csvHeader.concat(csvRows);
|
||||
const time = dayjs().format('YYYY-MM-DD_HH-mm-ss');
|
||||
downloadByData(csvContent, `${stationName}_录像缺失记录_${time}.csv`, 'text/csv;charset=utf-8', '\ufeff');
|
||||
};
|
||||
@@ -1,5 +1,3 @@
|
||||
export * from './device-alarm';
|
||||
export * from './export-record-diag-csv';
|
||||
export * from './nvr-cluster';
|
||||
export * from './record-check';
|
||||
export * from './switch-port';
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
import type { NdmRecordCheck, RecordInfo, RecordItem } from '@/apis';
|
||||
import dayjs from 'dayjs';
|
||||
import destr from 'destr';
|
||||
export type NvrRecordDiag = {
|
||||
gbCode: string;
|
||||
channelName: string;
|
||||
recordDuration: RecordItem;
|
||||
lostChunks: RecordItem[];
|
||||
};
|
||||
|
||||
// 解析出丢失的录像时间段
|
||||
export const transformRecordChecks = (rawRecordChecks: NdmRecordCheck[]): NvrRecordDiag[] => {
|
||||
// 解析diagInfo
|
||||
const parsedRecordChecks = rawRecordChecks.map((recordCheck) => ({
|
||||
...recordCheck,
|
||||
diagInfo: destr<RecordInfo>(recordCheck.diagInfo),
|
||||
}));
|
||||
// 使用 Map 按国标码分组,保留插入顺序
|
||||
const recordChecksMap = new Map<string, typeof parsedRecordChecks>();
|
||||
parsedRecordChecks.forEach((recordCheck) => {
|
||||
if (!recordChecksMap.has(recordCheck.gbCode)) {
|
||||
recordChecksMap.set(recordCheck.gbCode, []);
|
||||
}
|
||||
recordChecksMap.get(recordCheck.gbCode)!.push(recordCheck);
|
||||
});
|
||||
|
||||
// 初始化每个通道的录像诊断数据结构
|
||||
const recordDiags = Array.from(recordChecksMap.entries())
|
||||
.map(([gbCode, recordChecks]) => {
|
||||
return {
|
||||
gbCode,
|
||||
channelName: recordChecks.at(-1)?.name ?? '',
|
||||
records: recordChecks.flatMap((check) => check.diagInfo.recordList),
|
||||
lostChunks: [] as RecordItem[],
|
||||
};
|
||||
})
|
||||
.sort((diag1, diag2) => {
|
||||
return diag1.gbCode.localeCompare(diag2.gbCode);
|
||||
});
|
||||
// 过滤掉没有录像记录的通道
|
||||
const filteredRecordDiags = recordDiags.filter((recordDiag) => recordDiag.records.length > 0);
|
||||
// 计算每个通道丢失的录像时间片段
|
||||
filteredRecordDiags.forEach((recordDiag) => {
|
||||
recordDiag.records.forEach((record, index, records) => {
|
||||
const nextRecordItem = records.at(index + 1);
|
||||
if (!!nextRecordItem) {
|
||||
// 如果下一段录像的开始时间不等于当前录像的结束时间,则判定为丢失
|
||||
const nextStartTime = nextRecordItem.startTime;
|
||||
const currEndTime = record.endTime;
|
||||
if (nextStartTime !== currEndTime) {
|
||||
recordDiag.lostChunks.push({
|
||||
startTime: currEndTime,
|
||||
endTime: nextStartTime,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
return recordDiags.map((recordDiag) => {
|
||||
const firstRecord = recordDiag.records.at(0);
|
||||
const startTime = firstRecord ? dayjs(firstRecord.startTime).format('YYYY-MM-DD HH:mm:ss') : '';
|
||||
const lastRecord = recordDiag.records.at(-1);
|
||||
const endTime = lastRecord ? dayjs(lastRecord.endTime).format('YYYY-MM-DD HH:mm:ss') : '';
|
||||
return {
|
||||
gbCode: recordDiag.gbCode,
|
||||
channelName: recordDiag.channelName,
|
||||
recordDuration: { startTime, endTime },
|
||||
lostChunks: recordDiag.lostChunks,
|
||||
};
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user