refactor: recordDiagStatistics
This commit is contained in:
@@ -14,7 +14,7 @@ import { computed, onMounted, ref, toRefs } from 'vue';
|
|||||||
|
|
||||||
type NvrRecordDiag = {
|
type NvrRecordDiag = {
|
||||||
gbCode: string;
|
gbCode: string;
|
||||||
recordName: string;
|
channelName: string;
|
||||||
recordDuration: RecordItem;
|
recordDuration: RecordItem;
|
||||||
lostRecordList: RecordItem[];
|
lostRecordList: RecordItem[];
|
||||||
};
|
};
|
||||||
@@ -36,7 +36,7 @@ const filterLostRecordList = (rawRecordChecks: NdmRecordCheck[]): NvrRecordDiag[
|
|||||||
// 4. 初始化每个通道的诊断数据结构
|
// 4. 初始化每个通道的诊断数据结构
|
||||||
let recordDiagList = channelGbCodes.map((gbCode, index) => ({
|
let recordDiagList = channelGbCodes.map((gbCode, index) => ({
|
||||||
gbCode,
|
gbCode,
|
||||||
recordName: groupedRecordChecks[index].at(-1)?.name ?? '',
|
channelName: groupedRecordChecks[index].at(-1)?.name ?? '',
|
||||||
records: [] as RecordItem[],
|
records: [] as RecordItem[],
|
||||||
lostRecords: [] as RecordItem[],
|
lostRecords: [] as RecordItem[],
|
||||||
}));
|
}));
|
||||||
@@ -64,7 +64,7 @@ const filterLostRecordList = (rawRecordChecks: NdmRecordCheck[]): NvrRecordDiag[
|
|||||||
});
|
});
|
||||||
return recordDiagList.map((recordDiag) => ({
|
return recordDiagList.map((recordDiag) => ({
|
||||||
gbCode: recordDiag.gbCode,
|
gbCode: recordDiag.gbCode,
|
||||||
recordName: recordDiag.recordName,
|
channelName: recordDiag.channelName,
|
||||||
recordDuration: {
|
recordDuration: {
|
||||||
startTime: recordDiag.records.at(0)?.startTime ?? '',
|
startTime: recordDiag.records.at(0)?.startTime ?? '',
|
||||||
endTime: recordDiag.records.at(-1)?.endTime ?? '',
|
endTime: recordDiag.records.at(-1)?.endTime ?? '',
|
||||||
@@ -89,36 +89,34 @@ const recordCheckList = ref<NdmRecordCheck[]>([]);
|
|||||||
const lostRecordList = computed(() => filterLostRecordList(recordCheckList.value));
|
const lostRecordList = computed(() => filterLostRecordList(recordCheckList.value));
|
||||||
|
|
||||||
const recordDiagStatistics = computed(() => {
|
const recordDiagStatistics = computed(() => {
|
||||||
// 总通道数:参与录像诊断的通道总数
|
const channelCount = lostRecordList.value.length;
|
||||||
const totalChannels = lostRecordList.value.length;
|
const channelWithLossCount = lostRecordList.value.filter((diag) => diag.lostRecordList.length > 0).length;
|
||||||
|
const lossCount = lostRecordList.value.reduce((count, diag) => count + diag.lostRecordList.length, 0);
|
||||||
|
|
||||||
// 有缺失通道数:存在录像缺失的通道数量
|
const totalLossDuration = lostRecordList.value.reduce((totalDuration, diag) => {
|
||||||
const channelsWithLoss = lostRecordList.value.filter((item) => item.lostRecordList.length > 0).length;
|
const channelLossDuration = diag.lostRecordList.reduce((duration, loss) => {
|
||||||
|
return duration + dayjs(loss.endTime).diff(dayjs(loss.startTime));
|
||||||
|
}, 0);
|
||||||
|
return totalDuration + channelLossDuration;
|
||||||
|
}, 0);
|
||||||
|
|
||||||
// 总缺失次数:所有通道的录像缺失次数总和
|
const formatTotalLossDuration = (duration: number) => {
|
||||||
const totalLossCount = lostRecordList.value.reduce((sum, item) => sum + item.lostRecordList.length, 0);
|
const dayjsDuration = dayjs.duration(duration);
|
||||||
|
const asHours = dayjsDuration.asHours();
|
||||||
// 计算总缺失时长(毫秒)
|
const h = Math.floor(asHours);
|
||||||
let totalLossDuration = 0;
|
const m = dayjsDuration.minutes();
|
||||||
lostRecordList.value.forEach((item) => {
|
const s = dayjsDuration.seconds();
|
||||||
item.lostRecordList.forEach((loss) => {
|
if (asHours >= 1) {
|
||||||
// 计算每个缺失时间段的持续时长并累加
|
return `${h}小时${m}分钟${s}秒`;
|
||||||
totalLossDuration += dayjs(loss.endTime).diff(dayjs(loss.startTime));
|
}
|
||||||
});
|
return `${m}分钟${s}秒`;
|
||||||
});
|
};
|
||||||
|
|
||||||
// 格式化总缺失时长为可读格式
|
|
||||||
// 根据时长大小选择合适的显示单位(小时分钟 或 分钟秒)
|
|
||||||
const formattedTotalDuration =
|
|
||||||
dayjs.duration(totalLossDuration).asHours() >= 1
|
|
||||||
? `${Math.floor(dayjs.duration(totalLossDuration).asHours())}小时${dayjs.duration(totalLossDuration).minutes()}分钟`
|
|
||||||
: `${dayjs.duration(totalLossDuration).minutes()}分钟${dayjs.duration(totalLossDuration).seconds()}秒`;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
totalChannels, // 总通道数
|
totalChannels: channelCount,
|
||||||
channelsWithLoss, // 有缺失通道数
|
channelsWithLoss: channelWithLossCount,
|
||||||
totalLossCount, // 总缺失次数
|
totalLossCount: lossCount,
|
||||||
formattedTotalDuration, // 格式化的总缺失时长
|
totalLossDuration: formatTotalLossDuration(totalLossDuration),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -193,7 +191,7 @@ onMounted(() => {
|
|||||||
<NStatistic label="缺失次数" :value="recordDiagStatistics.totalLossCount" />
|
<NStatistic label="缺失次数" :value="recordDiagStatistics.totalLossCount" />
|
||||||
</NGridItem>
|
</NGridItem>
|
||||||
<NGridItem>
|
<NGridItem>
|
||||||
<NStatistic label="缺失时长" :value="recordDiagStatistics.formattedTotalDuration" />
|
<NStatistic label="缺失时长" :value="recordDiagStatistics.totalLossDuration" />
|
||||||
</NGridItem>
|
</NGridItem>
|
||||||
</NGrid>
|
</NGrid>
|
||||||
|
|
||||||
@@ -206,7 +204,7 @@ onMounted(() => {
|
|||||||
<NIcon size="16" :color="channel.lostRecordList.length > 0 ? '#f5222d' : '#52c41a'">
|
<NIcon size="16" :color="channel.lostRecordList.length > 0 ? '#f5222d' : '#52c41a'">
|
||||||
<VideocamOutline />
|
<VideocamOutline />
|
||||||
</NIcon>
|
</NIcon>
|
||||||
<NText strong>{{ channel.recordName }}</NText>
|
<NText strong>{{ channel.channelName }}</NText>
|
||||||
<NTag :type="channel.lostRecordList.length > 0 ? 'error' : 'success'" size="small">
|
<NTag :type="channel.lostRecordList.length > 0 ? 'error' : 'success'" size="small">
|
||||||
{{ channel.lostRecordList.length > 0 ? `${channel.lostRecordList.length}次缺失` : '正常' }}
|
{{ channel.lostRecordList.length > 0 ? `${channel.lostRecordList.length}次缺失` : '正常' }}
|
||||||
</NTag>
|
</NTag>
|
||||||
|
|||||||
Reference in New Issue
Block a user