From 26d894ba1cdc9215e21810eebc2a5984853ef615 Mon Sep 17 00:00:00 2001 From: yangsy Date: Thu, 25 Dec 2025 01:28:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=9A=84=E7=BB=84=E5=90=88API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/request/biz/composed/index.ts | 1 + .../request/biz/composed/update-device.ts | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/apis/request/biz/composed/update-device.ts diff --git a/src/apis/request/biz/composed/index.ts b/src/apis/request/biz/composed/index.ts index ebe61f1..64f238e 100644 --- a/src/apis/request/biz/composed/index.ts +++ b/src/apis/request/biz/composed/index.ts @@ -3,3 +3,4 @@ export * from './detail-device'; export * from './export-device'; export * from './import-device'; export * from './probe-device'; +export * from './update-device'; diff --git a/src/apis/request/biz/composed/update-device.ts b/src/apis/request/biz/composed/update-device.ts new file mode 100644 index 0000000..8281ada --- /dev/null +++ b/src/apis/request/biz/composed/update-device.ts @@ -0,0 +1,59 @@ +import { + updateAlarmHostApi, + updateCameraApi, + updateDecoderApi, + updateKeyboardApi, + updateMediaServerApi, + updateNvrApi, + updateSecurityBoxApi, + updateSwitchApi, + updateVideoServerApi, + type NdmDeviceResultVO, + type Station, +} from '@/apis'; +import { DEVICE_TYPE_LITERALS, tryGetDeviceType } from '@/enums'; + +export const updateDeviceApi = async (device: NdmDeviceResultVO, options?: { stationCode?: Station['code']; signal?: AbortSignal }): Promise => { + const { stationCode, signal } = options ?? {}; + const { id, deviceType: deviceTypeCode } = device; + if (!id || !deviceTypeCode) throw new Error('未知的设备'); + const deviceType = tryGetDeviceType(deviceTypeCode); + if (!deviceType) throw new Error('未知的设备'); + if (deviceType === DEVICE_TYPE_LITERALS.ndmAlarmHost) { + await updateAlarmHostApi(device, { stationCode, signal }); + return; + } + if (deviceType === DEVICE_TYPE_LITERALS.ndmCamera) { + await updateCameraApi(device, { stationCode, signal }); + return; + } + if (deviceType === DEVICE_TYPE_LITERALS.ndmDecoder) { + await updateDecoderApi(device, { stationCode, signal }); + return; + } + if (deviceType === DEVICE_TYPE_LITERALS.ndmKeyboard) { + await updateKeyboardApi(device, { stationCode, signal }); + return; + } + if (deviceType === DEVICE_TYPE_LITERALS.ndmMediaServer) { + await updateMediaServerApi(device, { stationCode, signal }); + return; + } + if (deviceType === DEVICE_TYPE_LITERALS.ndmNvr) { + await updateNvrApi(device, { stationCode, signal }); + return; + } + if (deviceType === DEVICE_TYPE_LITERALS.ndmSecurityBox) { + await updateSecurityBoxApi(device, { stationCode, signal }); + return; + } + if (deviceType === DEVICE_TYPE_LITERALS.ndmSwitch) { + await updateSwitchApi(device, { stationCode, signal }); + return; + } + if (deviceType === DEVICE_TYPE_LITERALS.ndmVideoServer) { + await updateVideoServerApi(device, { stationCode, signal }); + return; + } + return undefined; +};