sendJobActions.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. import axiosInstance from '../interceptor';
  2. import type { PacsNode, PacsNodeListData } from './pacsNodeActions';
  3. import { SendJob } from '@/domain/output/sendJob';
  4. /**
  5. * Echo 测试请求参数
  6. */
  7. export interface EchoTestRequest {
  8. /** 返回详细信息 */
  9. verbose?: boolean;
  10. /** 返回调试信息 */
  11. debug?: boolean;
  12. /** IPv4 地址,且不能为 0.0.0.0 */
  13. address: string;
  14. /** 端口号 (1-65536) */
  15. port: number;
  16. /** 被叫节点名 (AE Title, 长度 1-16) */
  17. aet: string;
  18. /** 主叫节点名 (AE Calling, 长度 1-16) */
  19. aec: string;
  20. }
  21. /**
  22. * Echo 测试响应数据
  23. */
  24. export interface EchoReplyData {
  25. /** 类型标识 */
  26. '@type': string;
  27. /** 是否成功 */
  28. ok: boolean;
  29. /** 输出信息 */
  30. output: string;
  31. }
  32. /**
  33. * Echo 测试响应
  34. */
  35. export interface EchoTestResponse {
  36. /** 响应码 */
  37. code: string;
  38. /** 描述信息 */
  39. description: string;
  40. /** 解决方案 */
  41. solution: string;
  42. /** 数据内容 */
  43. data: EchoReplyData;
  44. }
  45. /**
  46. * 发送队列项(类型别名,用于向后兼容)
  47. * @deprecated 请使用 SendJob 类型
  48. */
  49. export type SendQueueItem = SendJob;
  50. /**
  51. * 发送队列响应
  52. */
  53. export interface SendQueueResponse {
  54. /** 响应码 */
  55. code: string;
  56. /** 描述信息 */
  57. description: string;
  58. /** 解决方案 */
  59. solution: string;
  60. /** 发送队列列表 */
  61. data: SendJob[];
  62. }
  63. /**
  64. * 获取发送队列查询参数
  65. */
  66. export interface GetSendQueueParams {
  67. /** 开始时间 (RFC3339Nano 格式) */
  68. start_time?: string;
  69. /** 结束时间 (RFC3339Nano 格式) */
  70. end_time?: string;
  71. }
  72. /**
  73. * 删除发送任务请求参数
  74. */
  75. export interface DeleteSendTaskRequest {
  76. /** 任务 ID 列表 */
  77. task_ids: string[];
  78. }
  79. /**
  80. * 重试发送任务请求参数
  81. */
  82. export interface RetrySendTaskRequest {
  83. /** 任务 ID */
  84. task_id: string;
  85. }
  86. /**
  87. * 存储响应数据
  88. */
  89. export interface StoreReplyData {
  90. /** 类型标识 */
  91. '@type': string;
  92. /** 是否成功 */
  93. ok: boolean;
  94. /** 输出信息 */
  95. output: string;
  96. }
  97. /**
  98. * 重试发送任务响应
  99. */
  100. export interface RetrySendTaskResponse {
  101. /** 响应码 */
  102. code: string;
  103. /** 描述信息 */
  104. description: string;
  105. /** 解决方案 */
  106. solution: string;
  107. /** 数据内容 */
  108. data: StoreReplyData;
  109. }
  110. /**
  111. * PACS 节点列表响应 (用于传输队列)
  112. */
  113. export interface SendQueuePacsListResponse {
  114. /** 响应码 */
  115. code: string;
  116. /** 描述信息 */
  117. description: string;
  118. /** 解决方案 */
  119. solution: string;
  120. /** 数据内容 */
  121. data: PacsNodeListData;
  122. }
  123. /**
  124. * 基础响应
  125. */
  126. export interface BaseResponse {
  127. /** 响应码 */
  128. code: string;
  129. /** 描述信息 */
  130. description: string;
  131. /** 解决方案 */
  132. solution: string;
  133. /** 数据内容 */
  134. data: Record<string, any>;
  135. }
  136. /**
  137. * 节点连通性测试
  138. * @param request Echo 测试请求参数
  139. * @returns Echo 测试结果,包含成功状态和输出信息
  140. * @throws 当测试失败时抛出错误
  141. *
  142. * @example
  143. * ```typescript
  144. * const result = await echoTest({
  145. * address: '192.168.1.3',
  146. * port: 6299,
  147. * aet: 'testscp',
  148. * aec: 'testscu',
  149. * verbose: false,
  150. * debug: false
  151. * });
  152. * console.log('连通性测试:', result.data.ok);
  153. * ```
  154. */
  155. export const echoTest = async (
  156. request: EchoTestRequest
  157. ): Promise<EchoTestResponse> => {
  158. try {
  159. const response = await axiosInstance.post<EchoTestResponse>(
  160. '/auth/scp/echo',
  161. {
  162. verbose: request.verbose ?? false,
  163. debug: request.debug ?? false,
  164. address: request.address,
  165. port: request.port,
  166. aet: request.aet,
  167. aec: request.aec,
  168. }
  169. );
  170. if (response.data.code !== '0x000000') {
  171. throw new Error(`节点连通性测试失败: ${response.data.description}`);
  172. }
  173. return response.data;
  174. } catch (error) {
  175. console.error('Error testing node connectivity:', error);
  176. throw error;
  177. }
  178. };
  179. /**
  180. * 获取传输队列的 PACS 节点列表
  181. * @returns PACS 节点列表
  182. * @throws 当请求失败时抛出错误
  183. *
  184. * @example
  185. * ```typescript
  186. * const result = await getSendQueuePacsList();
  187. * console.log('PACS 节点列表:', result.data.scp);
  188. * ```
  189. */
  190. export const getSendQueuePacsList = async (): Promise<SendQueuePacsListResponse> => {
  191. try {
  192. const response = await axiosInstance.get<SendQueuePacsListResponse>(
  193. '/auth/scp/pacs'
  194. );
  195. if (response.data.code !== '0x000000') {
  196. throw new Error(`获取 PACS 节点列表失败: ${response.data.description}`);
  197. }
  198. return response.data;
  199. } catch (error) {
  200. console.error('Error fetching send queue PACS list:', error);
  201. throw error;
  202. }
  203. };
  204. /**
  205. * 获取发送队列
  206. * @param params 查询参数 (可选)
  207. * @returns 发送队列列表
  208. * @throws 当请求失败时抛出错误
  209. *
  210. * @example
  211. * ```typescript
  212. * // 获取所有发送任务
  213. * const allTasks = await getSendQueue();
  214. *
  215. * // 按时间范围查询
  216. * const tasksInRange = await getSendQueue({
  217. * start_time: '2025-10-10T00:00:00.000+08:00',
  218. * end_time: '2025-10-10T23:59:59.999+08:00'
  219. * });
  220. * console.log('发送队列:', tasksInRange.data);
  221. * ```
  222. */
  223. export const getSendQueue = async (
  224. params?: GetSendQueueParams
  225. ): Promise<SendQueueResponse> => {
  226. try {
  227. const response = await axiosInstance.get<SendQueueResponse>(
  228. '/auth/scp/store',
  229. {
  230. params: {
  231. start_time: params?.start_time,
  232. end_time: params?.end_time,
  233. },
  234. }
  235. );
  236. if (response.data.code !== '0x000000') {
  237. throw new Error(`获取发送队列失败: ${response.data.description}`);
  238. }
  239. return response.data;
  240. } catch (error) {
  241. console.error('Error fetching send queue:', error);
  242. throw error;
  243. }
  244. };
  245. /**
  246. * 删除发送任务
  247. * @param taskIds 任务 ID 列表
  248. * @returns 删除结果
  249. * @throws 当删除失败时抛出错误
  250. *
  251. * @example
  252. * ```typescript
  253. * const result = await deleteSendTask([
  254. * '0199cd46-82f0-76c5-b1d3-9399668a1a05',
  255. * '0199cd46-460d-770e-ac8e-549939a4a7d4'
  256. * ]);
  257. * console.log('删除成功:', result);
  258. * ```
  259. */
  260. export const deleteSendTask = async (
  261. taskIds: string[]
  262. ): Promise<BaseResponse> => {
  263. try {
  264. const response = await axiosInstance.delete<BaseResponse>(
  265. '/auth/scp/task',
  266. {
  267. data: taskIds,
  268. }
  269. );
  270. if (response.data.code !== '0x000000') {
  271. throw new Error(`删除发送任务失败: ${response.data.description}`);
  272. }
  273. return response.data;
  274. } catch (error) {
  275. console.error('Error deleting send task:', error);
  276. throw error;
  277. }
  278. };
  279. /**
  280. * 重试发送任务
  281. * @param taskId 任务 ID
  282. * @returns 重试结果,包含成功状态和输出信息
  283. * @throws 当重试失败时抛出错误
  284. *
  285. * @example
  286. * ```typescript
  287. * const result = await retrySendTask(
  288. * '0199cd46-82f0-76c5-b1d3-9399668a1a05'
  289. * );
  290. * console.log('重试成功:', result.data.ok);
  291. * ```
  292. */
  293. export const retrySendTask = async (
  294. taskId: string
  295. ): Promise<RetrySendTaskResponse> => {
  296. try {
  297. const response = await axiosInstance.post<RetrySendTaskResponse>(
  298. '/auth/scp/store_reply',
  299. {
  300. instance_uid: taskId,
  301. }
  302. );
  303. if (response.data.code !== '0x000000') {
  304. throw new Error(`重试发送任务失败: ${response.data.description}`);
  305. }
  306. return response.data;
  307. } catch (error) {
  308. console.error('Error retrying send task:', error);
  309. throw error;
  310. }
  311. };