feat: get alarms from all stations
This commit is contained in:
@@ -1,18 +1,137 @@
|
||||
import type { Station } from '@/apis/domains';
|
||||
import type { NdmDeviceAlarmLogResultVO } from '@/apis/models/device';
|
||||
import { postNdmDeviceAlarmLogPage } from '@/apis/requests';
|
||||
import { DeviceType } from '@/enums/device-type';
|
||||
import { useStationStore } from '@/stores/station';
|
||||
import { useQuery } from '@tanstack/vue-query';
|
||||
import dayjs from 'dayjs';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed } from 'vue';
|
||||
|
||||
export function useLineDevicesQuery() {
|
||||
const AlarmCategory = {
|
||||
Occurred: '1',
|
||||
Recovered: '2',
|
||||
} as const;
|
||||
|
||||
export interface CategorizedAlarms {
|
||||
occurred: NdmDeviceAlarmLogResultVO[];
|
||||
recovered: NdmDeviceAlarmLogResultVO[];
|
||||
}
|
||||
|
||||
export interface StationAlarms {
|
||||
[DeviceType.Camera]: CategorizedAlarms;
|
||||
[DeviceType.Decoder]: CategorizedAlarms;
|
||||
[DeviceType.Keyboard]: CategorizedAlarms;
|
||||
[DeviceType.MediaServer]: CategorizedAlarms;
|
||||
[DeviceType.Nvr]: CategorizedAlarms;
|
||||
[DeviceType.SecurityBox]: CategorizedAlarms;
|
||||
[DeviceType.Switch]: CategorizedAlarms;
|
||||
[DeviceType.VideoServer]: CategorizedAlarms;
|
||||
unclassified: CategorizedAlarms;
|
||||
}
|
||||
|
||||
export interface LineAlarms {
|
||||
[stationCode: Station['code']]: StationAlarms;
|
||||
}
|
||||
|
||||
export function useLineAlarmsQuery() {
|
||||
const stationStore = useStationStore();
|
||||
const { updatedTime, stationList, onlineStationList } = storeToRefs(stationStore);
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['line-devices', updatedTime],
|
||||
queryKey: ['line-alarms', updatedTime],
|
||||
enabled: computed(() => onlineStationList.value.length > 0),
|
||||
queryFn: async () => {
|
||||
placeholderData: (prev) => prev,
|
||||
queryFn: async (): Promise<LineAlarms> => {
|
||||
const lineAlarms: LineAlarms = {};
|
||||
|
||||
if (!stationList?.value) {
|
||||
return lineAlarms;
|
||||
}
|
||||
|
||||
for (const station of stationList.value) {
|
||||
lineAlarms[station.code] = {
|
||||
[DeviceType.Camera]: { occurred: [], recovered: [] },
|
||||
[DeviceType.Decoder]: { occurred: [], recovered: [] },
|
||||
[DeviceType.Keyboard]: { occurred: [], recovered: [] },
|
||||
[DeviceType.MediaServer]: { occurred: [], recovered: [] },
|
||||
[DeviceType.Nvr]: { occurred: [], recovered: [] },
|
||||
[DeviceType.SecurityBox]: { occurred: [], recovered: [] },
|
||||
[DeviceType.Switch]: { occurred: [], recovered: [] },
|
||||
[DeviceType.VideoServer]: { occurred: [], recovered: [] },
|
||||
unclassified: { occurred: [], recovered: [] },
|
||||
};
|
||||
|
||||
try {
|
||||
// FIXME: 暂时采用固定的时间范围
|
||||
const now = dayjs();
|
||||
// const todayStart = now.startOf('date').format('YYYY-MM-DD HH:mm:ss');
|
||||
// const todayEnd = now.endOf('date').format('YYYY-MM-DD HH:mm:ss');
|
||||
const todayStart = '2025-08-13 00:00:00';
|
||||
const todayEnd = '2025-08-31 23:59:59';
|
||||
const { records: alarmList } = await postNdmDeviceAlarmLogPage(station.code, {
|
||||
model: {},
|
||||
extra: {
|
||||
createdTime_precisest: todayStart,
|
||||
createdTime_preciseed: todayEnd,
|
||||
},
|
||||
size: 50000,
|
||||
current: 1,
|
||||
sort: 'id',
|
||||
order: 'descending',
|
||||
});
|
||||
const cameraAlarms = alarmList.filter((device) => device.deviceType === DeviceType.Camera);
|
||||
const decoderAlarms = alarmList.filter((device) => device.deviceType === DeviceType.Decoder);
|
||||
const keyboardAlarms = alarmList.filter((device) => device.deviceType === DeviceType.Keyboard);
|
||||
const mediaServerAlarms = alarmList.filter((device) => device.deviceType === DeviceType.MediaServer);
|
||||
const nvrAlarms = alarmList.filter((device) => device.deviceType === DeviceType.Nvr);
|
||||
const securityBoxAlarms = alarmList.filter((device) => device.deviceType === DeviceType.SecurityBox);
|
||||
const switchAlarms = alarmList.filter((device) => device.deviceType === DeviceType.Switch);
|
||||
const videoServerAlarms = alarmList.filter((device) => device.deviceType === DeviceType.VideoServer);
|
||||
lineAlarms[station.code] = {
|
||||
[DeviceType.Camera]: {
|
||||
occurred: cameraAlarms.filter((alarm) => alarm.alarmCategory === AlarmCategory.Occurred),
|
||||
recovered: cameraAlarms.filter((alarm) => alarm.alarmCategory === AlarmCategory.Recovered),
|
||||
},
|
||||
[DeviceType.Decoder]: {
|
||||
occurred: decoderAlarms.filter((alarm) => alarm.alarmCategory === AlarmCategory.Occurred),
|
||||
recovered: decoderAlarms.filter((alarm) => alarm.alarmCategory === AlarmCategory.Recovered),
|
||||
},
|
||||
[DeviceType.Keyboard]: {
|
||||
occurred: keyboardAlarms.filter((alarm) => alarm.alarmCategory === AlarmCategory.Occurred),
|
||||
recovered: keyboardAlarms.filter((alarm) => alarm.alarmCategory === AlarmCategory.Recovered),
|
||||
},
|
||||
[DeviceType.MediaServer]: {
|
||||
occurred: mediaServerAlarms.filter((alarm) => alarm.alarmCategory === AlarmCategory.Occurred),
|
||||
recovered: mediaServerAlarms.filter((alarm) => alarm.alarmCategory === AlarmCategory.Recovered),
|
||||
},
|
||||
[DeviceType.Nvr]: {
|
||||
occurred: nvrAlarms.filter((alarm) => alarm.alarmCategory === AlarmCategory.Occurred),
|
||||
recovered: nvrAlarms.filter((alarm) => alarm.alarmCategory === AlarmCategory.Recovered),
|
||||
},
|
||||
[DeviceType.SecurityBox]: {
|
||||
occurred: securityBoxAlarms.filter((alarm) => alarm.alarmCategory === AlarmCategory.Occurred),
|
||||
recovered: securityBoxAlarms.filter((alarm) => alarm.alarmCategory === AlarmCategory.Recovered),
|
||||
},
|
||||
[DeviceType.Switch]: {
|
||||
occurred: switchAlarms.filter((alarm) => alarm.alarmCategory === AlarmCategory.Occurred),
|
||||
recovered: switchAlarms.filter((alarm) => alarm.alarmCategory === AlarmCategory.Recovered),
|
||||
},
|
||||
[DeviceType.VideoServer]: {
|
||||
occurred: videoServerAlarms.filter((alarm) => alarm.alarmCategory === AlarmCategory.Occurred),
|
||||
recovered: videoServerAlarms.filter((alarm) => alarm.alarmCategory === AlarmCategory.Recovered),
|
||||
},
|
||||
unclassified: {
|
||||
occurred: alarmList.filter((alarm) => alarm.alarmCategory === AlarmCategory.Occurred),
|
||||
recovered: alarmList.filter((alarm) => alarm.alarmCategory === AlarmCategory.Recovered),
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(`获取车站 ${station.name} 设备告警数据失败:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
return lineAlarms;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -19,11 +19,12 @@ export function useStationListQuery() {
|
||||
queryKey: ['station-list'],
|
||||
enabled: computed(() => pollingEnabled.value),
|
||||
queryFn: async () => {
|
||||
const { data: ndmStationList } = await axios.get<{ code: string; name: string }[]>(`/minio/ndm/ndm-stations.json?_t=${dayjs().unix()}`);
|
||||
const { data: ndmStationList } = await axios.get<{ code: string; name: string; deviceIdPrefix: string }[]>(`/minio/ndm/ndm-stations.json?_t=${dayjs().unix()}`);
|
||||
|
||||
const stations = ndmStationList.map<Station>((record) => ({
|
||||
code: record.code ?? '',
|
||||
name: record.name ?? '',
|
||||
const stations = ndmStationList.map<Station>((station) => ({
|
||||
code: station.code ?? '',
|
||||
name: station.name ?? '',
|
||||
deviceIdPrefix: station.deviceIdPrefix ?? '',
|
||||
online: false,
|
||||
}));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user