123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- 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<string, any>;
- }
- /**
- * 节点连通性测试
- * @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<EchoTestResponse> => {
- try {
- const response = await axiosInstance.post<EchoTestResponse>(
- '/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<SendQueuePacsListResponse> => {
- try {
- const response = await axiosInstance.get<SendQueuePacsListResponse>(
- '/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<SendQueueResponse> => {
- try {
- const response = await axiosInstance.get<SendQueueResponse>(
- '/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<BaseResponse> => {
- try {
- const response = await axiosInstance.delete<BaseResponse>(
- '/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<RetrySendTaskResponse> => {
- try {
- const response = await axiosInstance.post<RetrySendTaskResponse>(
- '/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;
- }
- };
|