东丽网口版透析机 socket- server 通讯
chenyc
2025-12-09 7cfe3332f016d7def7ca8ad25ed8bbdc33d23ed2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
{
  "openapi": "3.0.0",
  "info": {
    "title": "透析机IoT数据服务 HTTP API",
    "description": "透析机设备实时数据查询和管理接口",
    "version": "1.1.0",
    "contact": {
      "name": "技术支持",
      "email": "support@example.com"
    },
    "license": {
      "name": "MIT"
    }
  },
  "servers": [
    {
      "url": "http://localhost:8080",
      "description": "开发环境"
    },
    {
      "url": "http://production-server:8080",
      "description": "生产环境"
    }
  ],
  "paths": {
    "/api/health": {
      "get": {
        "summary": "健康检查",
        "description": "检查服务器是否正常运行",
        "operationId": "getHealth",
        "tags": ["系统"],
        "responses": {
          "200": {
            "description": "服务正常",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer",
                      "example": 200
                    },
                    "message": {
                      "type": "string",
                      "example": "success"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "string",
                          "example": "ok"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "服务不可用"
          }
        }
      }
    },
    "/api/device/data": {
      "get": {
        "summary": "获取单个设备数据",
        "description": "获取指定设备的实时数据。支持原始格式和映射格式(推荐)",
        "operationId": "getDeviceData",
        "tags": ["设备数据"],
        "parameters": [
          {
            "name": "deviceNumber",
            "in": "query",
            "description": "设备号,例如 D001",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "mapped",
            "in": "query",
            "description": "是否返回映射格式(推荐使用 true)",
            "required": false,
            "schema": {
              "type": "string",
              "enum": ["true", "false"],
              "default": "false"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "成功获取设备数据",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeviceDataResponse"
                }
              }
            }
          },
          "400": {
            "description": "参数错误"
          },
          "404": {
            "description": "设备不存在"
          },
          "429": {
            "description": "请求过于频繁,请稍后再试"
          }
        },
        "x-rate-limit": {
          "interval": "5秒",
          "max-requests": 1
        }
      }
    },
    "/api/device/all": {
      "get": {
        "summary": "获取所有设备数据",
        "description": "批量获取所有设备的实时数据",
        "operationId": "getAllDevices",
        "tags": ["设备数据"],
        "parameters": [
          {
            "name": "mapped",
            "in": "query",
            "description": "是否返回映射格式(推荐使用 true)",
            "required": false,
            "schema": {
              "type": "string",
              "enum": ["true", "false"],
              "default": "false"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "成功获取所有设备数据",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AllDevicesResponse"
                }
              }
            }
          },
          "429": {
            "description": "请求过于频繁,请稍后再试"
          }
        },
        "x-rate-limit": {
          "interval": "60秒",
          "max-requests": 1
        }
      }
    },
    "/api/device/list": {
      "get": {
        "summary": "获取设备列表",
        "description": "获取所有已连接设备的摘要信息",
        "operationId": "getDeviceList",
        "tags": ["设备数据"],
        "responses": {
          "200": {
            "description": "成功获取设备列表",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeviceListResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/device/idle": {
      "get": {
        "summary": "获取超时设备",
        "description": "获取超过指定时间未更新的设备列表",
        "operationId": "getIdleDevices",
        "tags": ["设备数据"],
        "parameters": [
          {
            "name": "timeout",
            "in": "query",
            "description": "超时时间(毫秒),例如 300000(5分钟)",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 300000
            }
          }
        ],
        "responses": {
          "200": {
            "description": "成功获取超时设备列表",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "timeout": {
                          "type": "integer"
                        },
                        "idleDevices": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/cache/stats": {
      "get": {
        "summary": "获取缓存统计",
        "description": "获取数据缓存的统计信息",
        "operationId": "getCacheStats",
        "tags": ["统计"],
        "responses": {
          "200": {
            "description": "成功获取缓存统计",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "totalDevices": {
                          "type": "integer"
                        },
                        "cachedProperties": {
                          "type": "integer"
                        },
                        "cacheSize": {
                          "type": "string"
                        },
                        "oldestData": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "newestData": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/ratelimit/stats": {
      "get": {
        "summary": "获取限流统计",
        "description": "获取请求限流的统计信息",
        "operationId": "getRateLimitStats",
        "tags": ["统计"],
        "responses": {
          "200": {
            "description": "成功获取限流统计",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "enabled": {
                          "type": "boolean"
                        },
                        "interval": {
                          "type": "integer",
                          "description": "单个设备限流间隔(毫秒)"
                        },
                        "allDevicesInterval": {
                          "type": "integer",
                          "description": "全局限流间隔(毫秒)"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "identifier": {
                                "type": "string"
                              },
                              "lastRequest": {
                                "type": "string",
                                "format": "date-time"
                              },
                              "requestCount": {
                                "type": "integer"
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/cache/clear": {
      "post": {
        "summary": "清空缓存",
        "description": "清空所有缓存的设备数据(需谨慎使用)",
        "operationId": "clearCache",
        "tags": ["缓存管理"],
        "responses": {
          "200": {
            "description": "缓存已清空",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/ratelimit/clear": {
      "post": {
        "summary": "清空限流记录",
        "description": "清空所有限流记录",
        "operationId": "clearRateLimit",
        "tags": ["缓存管理"],
        "responses": {
          "200": {
            "description": "限流记录已清空",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "DeviceProperty": {
        "type": "object",
        "properties": {
          "identifier": {
            "type": "string",
            "description": "属性标识符",
            "example": "A"
          },
          "name": {
            "type": "string",
            "description": "属性中文名称",
            "example": "脱水目标量"
          },
          "value": {
            "type": "string",
            "description": "属性值",
            "example": "50"
          }
        }
      },
      "DeviceDataResponse": {
        "type": "object",
        "properties": {
          "code": {
            "type": "integer",
            "example": 200
          },
          "message": {
            "type": "string",
            "example": "success"
          },
          "data": {
            "type": "object",
            "properties": {
              "deviceNumber": {
                "type": "string"
              },
              "timestamp": {
                "type": "string",
                "format": "date-time"
              },
              "properties": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/DeviceProperty"
                }
              },
              "format": {
                "type": "string",
                "enum": ["raw", "mapped"]
              }
            }
          }
        }
      },
      "AllDevicesResponse": {
        "type": "object",
        "properties": {
          "code": {
            "type": "integer"
          },
          "message": {
            "type": "string"
          },
          "data": {
            "type": "object",
            "properties": {
              "count": {
                "type": "integer"
              },
              "data": {
                "type": "object",
                "additionalProperties": {
                  "type": "object",
                  "properties": {
                    "timestamp": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "properties": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/DeviceProperty"
                      }
                    },
                    "format": {
                      "type": "string"
                    }
                  }
                }
              },
              "format": {
                "type": "string"
              }
            }
          }
        }
      },
      "DeviceListResponse": {
        "type": "object",
        "properties": {
          "code": {
            "type": "integer"
          },
          "message": {
            "type": "string"
          },
          "data": {
            "type": "object",
            "properties": {
              "count": {
                "type": "integer"
              },
              "devices": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "deviceNumber": {
                      "type": "string"
                    },
                    "lastUpdate": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "系统",
      "description": "系统级别的API"
    },
    {
      "name": "设备数据",
      "description": "设备数据查询接口"
    },
    {
      "name": "统计",
      "description": "统计信息接口"
    },
    {
      "name": "缓存管理",
      "description": "缓存和限流管理"
    }
  ]
}