import { ndmClient, userClient, type ImportMsg, type NdmSwitchPageQuery, type NdmSwitchResultVO, type NdmSwitchSaveVO, type NdmSwitchUpdateVO, type PageParams, type PageResult, type Station, } from '@/apis'; import { unwrapResponse } from '@/utils'; export const pageSwitchApi = async (pageQuery: PageParams, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => { const { stationCode, signal } = options ?? {}; const client = stationCode ? ndmClient : ndmClient; const prefix = stationCode ? `/${stationCode}` : ''; const endpoint = `${prefix}/api/ndm/ndmSwitch/page`; const resp = await client.post>(endpoint, pageQuery, { signal }); const data = unwrapResponse(resp); return data; }; export const detailSwitchApi = async (id: string, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => { const { stationCode, signal } = options ?? {}; const client = stationCode ? ndmClient : ndmClient; const prefix = stationCode ? `/${stationCode}` : ''; const endpoint = `${prefix}/api/ndm/ndmSwitch/detail`; const resp = await client.get(endpoint, { params: { id }, signal }); const data = unwrapResponse(resp); return data; }; export const saveSwitchApi = async (saveVO: NdmSwitchSaveVO, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => { const { stationCode, signal } = options ?? {}; const client = stationCode ? ndmClient : ndmClient; const prefix = stationCode ? `/${stationCode}` : ''; const endpoint = `${prefix}/api/ndm/ndmSwitch`; const resp = await client.post(endpoint, saveVO, { signal }); const data = unwrapResponse(resp); return data; }; export const updateSwitchApi = async (updateVO: NdmSwitchUpdateVO, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => { const { stationCode, signal } = options ?? {}; const client = stationCode ? ndmClient : ndmClient; const prefix = stationCode ? `/${stationCode}` : ''; const endpoint = `${prefix}/api/ndm/ndmSwitch`; const resp = await client.put(endpoint, updateVO, { signal }); const data = unwrapResponse(resp); return data; }; export const deleteSwitchApi = async (ids: string[], options?: { stationCode?: Station['code']; signal?: AbortSignal }) => { const { stationCode, signal } = options ?? {}; const client = stationCode ? ndmClient : ndmClient; const prefix = stationCode ? `/${stationCode}` : ''; const endpoint = `${prefix}/api/ndm/ndmSwitch`; const resp = await client.delete(endpoint, ids, { signal }); const data = unwrapResponse(resp); return data; }; export const exportSwitchApi = async (pageQuery: PageParams, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => { const { stationCode, signal } = options ?? {}; const client = stationCode ? ndmClient : ndmClient; const prefix = stationCode ? `/${stationCode}` : ''; const endpoint = `${prefix}/api/ndm/ndmSwitch/defaultExportByTemplate`; const resp = await client.post(endpoint, pageQuery, { responseType: 'blob', retRaw: true, signal }); const data = unwrapResponse(resp); return data; }; export const importSwitchApi = 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/ndmSwitch/importReturnMsg`; const formData = new FormData(); formData.append('file', file); const resp = await client.post(endpoint, formData, { signal, upload: true }); const data = unwrapResponse(resp); return data; }; export const probeSwitchApi = async (ids: string[], options?: { stationCode?: Station['code']; signal?: AbortSignal }) => { const { stationCode, signal } = options ?? {}; const client = stationCode ? ndmClient : ndmClient; const prefix = stationCode ? `/${stationCode}` : ''; const endpoint = `${prefix}/api/ndm/ndmSwitch/probeByIds`; const resp = await client.post(endpoint, ids, { signal }); unwrapResponse(resp); };