115 lines
5.4 KiB
TypeScript
115 lines
5.4 KiB
TypeScript
import {
|
|
ndmClient,
|
|
userClient,
|
|
type ImportMsg,
|
|
type NdmSecurityBoxPageQuery,
|
|
type NdmSecurityBoxResultVO,
|
|
type NdmSecurityBoxSaveVO,
|
|
type NdmSecurityBoxUpdateVO,
|
|
type PageParams,
|
|
type PageResult,
|
|
type Station,
|
|
} from '@/apis';
|
|
import { unwrapResponse } from '@/utils';
|
|
|
|
export const pageSecurityBoxApi = async (pageQuery: PageParams<NdmSecurityBoxPageQuery>, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
|
|
const { stationCode, signal } = options ?? {};
|
|
const client = stationCode ? ndmClient : userClient;
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const endpoint = `${prefix}/api/ndm/ndmSecurityBox/page`;
|
|
const resp = await client.post<PageResult<NdmSecurityBoxResultVO>>(endpoint, pageQuery, { signal });
|
|
const data = unwrapResponse(resp);
|
|
return data;
|
|
};
|
|
|
|
export const detailSecurityBoxApi = async (id: string, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
|
|
const { stationCode, signal } = options ?? {};
|
|
const client = stationCode ? ndmClient : userClient;
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const endpoint = `${prefix}/api/ndm/ndmSecurityBox/detail`;
|
|
const resp = await client.get<NdmSecurityBoxResultVO>(endpoint, { params: { id }, signal });
|
|
const data = unwrapResponse(resp);
|
|
return data;
|
|
};
|
|
|
|
export const saveSecurityBoxApi = async (saveVO: NdmSecurityBoxSaveVO, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
|
|
const { stationCode, signal } = options ?? {};
|
|
const client = stationCode ? ndmClient : userClient;
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const endpoint = `${prefix}/api/ndm/ndmSecurityBox`;
|
|
const resp = await client.post<NdmSecurityBoxResultVO>(endpoint, saveVO, { signal });
|
|
const data = unwrapResponse(resp);
|
|
return data;
|
|
};
|
|
|
|
export const updateSecurityBoxApi = async (updateVO: NdmSecurityBoxUpdateVO, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
|
|
const { stationCode, signal } = options ?? {};
|
|
const client = stationCode ? ndmClient : userClient;
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const endpoint = `${prefix}/api/ndm/ndmSecurityBox`;
|
|
const resp = await client.put<NdmSecurityBoxResultVO>(endpoint, updateVO, { signal });
|
|
const data = unwrapResponse(resp);
|
|
return data;
|
|
};
|
|
|
|
export const deleteSecurityBoxApi = async (ids: string[], options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
|
|
const { stationCode, signal } = options ?? {};
|
|
const client = stationCode ? ndmClient : userClient;
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const endpoint = `${prefix}/api/ndm/ndmSecurityBox`;
|
|
const resp = await client.delete<boolean>(endpoint, ids, { signal });
|
|
const data = unwrapResponse(resp);
|
|
return data;
|
|
};
|
|
|
|
export const exportSecurityBoxApi = async (pageQuery: PageParams<NdmSecurityBoxPageQuery>, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
|
|
const { stationCode, signal } = options ?? {};
|
|
const client = stationCode ? ndmClient : userClient;
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const endpoint = `${prefix}/api/ndm/ndmSecurityBox/defaultExportByTemplate`;
|
|
const resp = await client.post<Blob>(endpoint, pageQuery, { responseType: 'blob', retRaw: true, signal });
|
|
const data = unwrapResponse(resp);
|
|
return data;
|
|
};
|
|
|
|
export const importSecurityBoxApi = async (file: File, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
|
|
const { stationCode, signal } = options ?? {};
|
|
const client = stationCode ? ndmClient : userClient;
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const endpoint = `${prefix}/api/ndm/ndmSecurityBox/importReturnMsg`;
|
|
const formData = new FormData();
|
|
formData.append('file', file);
|
|
const resp = await client.post<ImportMsg>(endpoint, formData, { signal, upload: true });
|
|
const data = unwrapResponse(resp);
|
|
return data;
|
|
};
|
|
|
|
export const probeSecurityBoxApi = async (ids: string[], options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
|
|
const { stationCode, signal } = options ?? {};
|
|
const client = stationCode ? ndmClient : userClient;
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const endpoint = `${prefix}/api/ndm/ndmSecurityBox/probeByIds`;
|
|
const resp = await client.post<void>(endpoint, ids, { signal });
|
|
unwrapResponse(resp);
|
|
};
|
|
|
|
export const turnCitcuitStatusApi = async (ipAddress: string, circuitIndex: number, status: number, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
|
|
const { stationCode, signal } = options ?? {};
|
|
const client = stationCode ? ndmClient : userClient;
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const endpoint = `${prefix}/api/ndm/ndmSecurityBox/turnStatus`;
|
|
const resp = await client.post<boolean>(endpoint, { community: 'public', ipAddress, circuit: `${circuitIndex}`, status }, { signal });
|
|
const data = unwrapResponse(resp);
|
|
return data;
|
|
};
|
|
|
|
export const rebootSecurityBoxApi = async (ipAddress: string, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
|
|
const { stationCode, signal } = options ?? {};
|
|
const client = stationCode ? ndmClient : userClient;
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const endpoint = `${prefix}/api/ndm/ndmSecurityBox/reboot`;
|
|
const resp = await client.post<boolean>(endpoint, { community: 'public', ipAddress }, { signal });
|
|
const data = unwrapResponse(resp);
|
|
return data;
|
|
};
|