import axiosInstance from '../interceptor'; import type { PacsNode, PacsNodeListData } from './pacsNodeActions'; import { SendJob } from '@/domain/output/sendJob'; /** * Echo 测试请求参数 */ export interface EchoTestRequest { /** 返回详细信息 */ verbose?: boolean; /** 返回调试信息 */ debug?: boolean; /** IPv4 地址,且不能为 0.0.0.0 */ address: string; /** 端口号 (1-65536) */ port: number; /** 被叫节点名 (AE Title, 长度 1-16) */ aet: string; /** 主叫节点名 (AE Calling, 长度 1-16) */ aec: string; } /** * Echo 测试响应数据 */ export interface EchoReplyData { /** 类型标识 */ '@type': string; /** 是否成功 */ ok: boolean; /** 输出信息 */ output: string; } /** * Echo 测试响应 */ export interface EchoTestResponse { /** 响应码 */ code: string; /** 描述信息 */ description: string; /** 解决方案 */ solution: string; /** 数据内容 */ data: EchoReplyData; } /** * 发送队列项(类型别名,用于向后兼容) * @deprecated 请使用 SendJob 类型 */ export type SendQueueItem = SendJob; /** * 发送队列响应 */ export interface SendQueueResponse { /** 响应码 */ code: string; /** 描述信息 */ description: string; /** 解决方案 */ solution: string; /** 发送队列列表 */ data: SendJob[]; } /** * 获取发送队列查询参数 */ export interface GetSendQueueParams { /** 开始时间 (RFC3339Nano 格式) */ start_time?: string; /** 结束时间 (RFC3339Nano 格式) */ end_time?: string; } /** * 删除发送任务请求参数 */ export interface DeleteSendTaskRequest { /** 任务 ID 列表 */ task_ids: string[]; } /** * 重试发送任务请求参数 */ export interface RetrySendTaskRequest { /** 任务 ID */ task_id: string; } /** * 存储响应数据 */ export interface StoreReplyData { /** 类型标识 */ '@type': string; /** 是否成功 */ ok: boolean; /** 输出信息 */ output: string; } /** * 重试发送任务响应 */ export interface RetrySendTaskResponse { /** 响应码 */ code: string; /** 描述信息 */ description: string; /** 解决方案 */ solution: string; /** 数据内容 */ data: StoreReplyData; } /** * PACS 节点列表响应 (用于传输队列) */ export interface SendQueuePacsListResponse { /** 响应码 */ code: string; /** 描述信息 */ description: string; /** 解决方案 */ solution: string; /** 数据内容 */ data: PacsNodeListData; } /** * 基础响应 */ export interface BaseResponse { /** 响应码 */ code: string; /** 描述信息 */ description: string; /** 解决方案 */ solution: string; /** 数据内容 */ data: Record; } /** * 节点连通性测试 * @param request Echo 测试请求参数 * @returns Echo 测试结果,包含成功状态和输出信息 * @throws 当测试失败时抛出错误 * * @example * ```typescript * const result = await echoTest({ * address: '192.168.1.3', * port: 6299, * aet: 'testscp', * aec: 'testscu', * verbose: false, * debug: false * }); * console.log('连通性测试:', result.data.ok); * ``` */ export const echoTest = async ( request: EchoTestRequest ): Promise => { try { const response = await axiosInstance.post( '/auth/scp/echo', { verbose: request.verbose ?? false, debug: request.debug ?? false, address: request.address, port: request.port, aet: request.aet, aec: request.aec, } ); if (response.data.code !== '0x000000') { throw new Error(`节点连通性测试失败: ${response.data.description}`); } return response.data; } catch (error) { console.error('Error testing node connectivity:', error); throw error; } }; /** * 获取传输队列的 PACS 节点列表 * @returns PACS 节点列表 * @throws 当请求失败时抛出错误 * * @example * ```typescript * const result = await getSendQueuePacsList(); * console.log('PACS 节点列表:', result.data.scp); * ``` */ export const getSendQueuePacsList = async (): Promise => { try { const response = await axiosInstance.get( '/auth/scp/pacs' ); if (response.data.code !== '0x000000') { throw new Error(`获取 PACS 节点列表失败: ${response.data.description}`); } return response.data; } catch (error) { console.error('Error fetching send queue PACS list:', error); throw error; } }; /** * 获取发送队列 * @param params 查询参数 (可选) * @returns 发送队列列表 * @throws 当请求失败时抛出错误 * * @example * ```typescript * // 获取所有发送任务 * const allTasks = await getSendQueue(); * * // 按时间范围查询 * const tasksInRange = await getSendQueue({ * start_time: '2025-10-10T00:00:00.000+08:00', * end_time: '2025-10-10T23:59:59.999+08:00' * }); * console.log('发送队列:', tasksInRange.data); * ``` */ export const getSendQueue = async ( params?: GetSendQueueParams ): Promise => { try { const response = await axiosInstance.get( '/auth/scp/store', { params: { start_time: params?.start_time, end_time: params?.end_time, }, } ); if (response.data.code !== '0x000000') { throw new Error(`获取发送队列失败: ${response.data.description}`); } return response.data; } catch (error) { console.error('Error fetching send queue:', error); throw error; } }; /** * 删除发送任务 * @param taskIds 任务 ID 列表 * @returns 删除结果 * @throws 当删除失败时抛出错误 * * @example * ```typescript * const result = await deleteSendTask([ * '0199cd46-82f0-76c5-b1d3-9399668a1a05', * '0199cd46-460d-770e-ac8e-549939a4a7d4' * ]); * console.log('删除成功:', result); * ``` */ export const deleteSendTask = async ( taskIds: string[] ): Promise => { try { const response = await axiosInstance.delete( '/auth/scp/task', { data: taskIds, } ); if (response.data.code !== '0x000000') { throw new Error(`删除发送任务失败: ${response.data.description}`); } return response.data; } catch (error) { console.error('Error deleting send task:', error); throw error; } }; /** * 重试发送任务 * @param taskId 任务 ID * @returns 重试结果,包含成功状态和输出信息 * @throws 当重试失败时抛出错误 * * @example * ```typescript * const result = await retrySendTask( * '0199cd46-82f0-76c5-b1d3-9399668a1a05' * ); * console.log('重试成功:', result.data.ok); * ``` */ export const retrySendTask = async ( taskId: string ): Promise => { try { const response = await axiosInstance.post( '/auth/scp/store_reply', { instance_uid: taskId, } ); if (response.data.code !== '0x000000') { throw new Error(`重试发送任务失败: ${response.data.description}`); } return response.data; } catch (error) { console.error('Error retrying send task:', error); throw error; } };