yxh
yxh
10 天以前 09dc74e264b6262cbe41c9c8476e24705871d4a6
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
import request from '@/config/axios'
 
// 诊室和诊疗床 VO
export interface RoomVO {
  id: number | null  //
  roomId: number | null // 诊室编号
  roomName: string | null // 诊室名称
  bedNo: string | null // 诊疗床编号
  ip: string | null // 诊室工位IP
  status: number | null //开诊状态  0-关闭 1-关闭中 10-已开通 20-有医生 30-暂停
  docId: number | null
  docName: string | null
  checkTypes: number[] | null
  opType: number | null
  occupied?: boolean | null // 该工位是否已被医生占用(按IP匹配工位时用)
}
 
// 「选择工位模式」- 按本机IP匹配工位的候选工位
export interface RoomSelectBedItem {
  id: number // 工位主键 clinic_room.id
  roomId: number | null
  roomName: string | null
  bedNo: string | null
  ip: string | null
  docId: number | null
  docName: string | null
  opType: number | null
  checkTypes: number[] | null
  status: number | null
  occupied: boolean | null
  mine: boolean | null
}
 
// 「选择工位模式」- 按本机IP匹配工位的结果
export interface RoomSelectBedResp {
  clientIp: string | null // 后端实际识别到的来访IP(已规范化)
  ipValid: boolean | null // 该IP是否可用于绑定
  ipLoopback: boolean | null // 该IP是否是本机回环(127.x / ::1)→ 说明浏览器与服务在同一台机器
  ipv6: boolean | null // 该IP是否是 IPv6(本系统工位绑定仅采用 IPv4)
  ipBound: boolean | null // 该IP是否已绑定工位
  matched: boolean | null // 是否有可直接入座的工位
  beds: RoomSelectBedItem[]
}
 
/**
 * 该IP能否用于自动匹配/绑定工位。
 * **本系统工位绑定只采用 IPv4**:IPv6(含 ::1、fe80::、2408:: 等)一律不可用。
 * 空值、0.0.0.0、127.x 同样不可用;`::ffff:32.88.65.208` 由后端还原成 IPv4 后可用。
 */
export const isUsableSeatIp = (ip?: string | null): boolean => {
  const v = (ip || '').trim()
  if (!v || v === '0.0.0.0' || v.startsWith('127.')) return false
  if (v.includes(':')) return false // IPv6 不采用
  if (!/^(\d{1,3}\.){3}\d{1,3}$/.test(v)) return false
  return v.split('.').every((seg) => Number(seg) <= 255)
}
 
 
/**
 * 「工位入座」结果(自动入座 / 查询我的工位 共用)。
 *
 * reason 取值:
 *  - ip_invalid 本机IP不可用(回环/IPv6/未指定/非法)
 *  - nomatch    该IP没匹配到工位(工位没录IP 或 已关闭)
 *  - multi      该IP对应多个空闲工位,需人工点选
 *  - occupied   匹配到的工位已被**他人**占用(不挤掉)
 *  - error      入座写库未生效
 */
export interface RoomSeatResp {
  seated: boolean
  reason?: string | null
  clientIp?: string | null
  ownerName?: string | null
  id?: number | null
  roomId?: number | null
  roomName?: string | null
  bedNo?: string | null
  ip?: string | null
  status?: number | null
  docId?: number | null
  docName?: string | null
  checkTypes?: number[] | null
  opType?: number | null
}
 
export interface MonitorInfo {
  openingBedNum : number
  /** 在座工位数(一人多工位时会大于医生数) */
  docBedNum : number
  /** 【本需求·统计按人合并】在座医生数(按 doc_id 去重) */
  docNum : number
  routingBedNum : number
  openingFlag : number
  checkTypeBedInfo: object
}
 
// 诊室和诊疗床 API
export const RoomApi = {
  // 查询诊室和诊疗床分页
  getRoomPage: async (params: any) => {
    return await request.get({ url: `/clinic/room/page`, params })
  },
 
  // 查询诊室和诊疗床详情
  getRoom: async (id: number) => {
    return await request.get({ url: `/clinic/room/get?id=` + id })
  },
 
  // 查询诊室和诊疗床详情
  getRoomByIP: async (roomId :number) => {
    if (roomId == null || roomId === 0) {
      return await request.get({url: `/clinic/room/get-room-by-ip`})
    }
 
    return await request.get({url: `/clinic/room/get-room-by-ip?roomId=` + roomId})
  },
 
  // 新增诊室和诊疗床
  createRoom: async (data: RoomVO) => {
    return await request.post({ url: `/clinic/room/create`, data })
  },
 
  // 修改诊室和诊疗床
  updateRoom: async (data: RoomVO) => {
    return await request.put({ url: `/clinic/room/update`, data })
  },
 
  // 删除诊室和诊疗床
  deleteRoom: async (id: number) => {
    return await request.delete({ url: `/clinic/room/delete?id=` + id })
  },
 
  // 导出诊室和诊疗床 Excel
  exportRoom: async (params) => {
    return await request.download({ url: `/clinic/room/export-excel`, params })
  },
 
  // 获取部门精简信息列表 ECG 子部门
  getSimpleRoomList: async () => {
    return await request.get({ url: `/clinic/room/simple-list` })
  },
 
  // 获取诊室精简信息列表,用于医生选择登录的诊室
  getOpeningBedMap: async () => {
    return await request.get({ url: `/clinic/room/list-simple-room` })
  },
 
  // 获取诊床Map
  getAllBedMap: async () => {
    return await request.get({ url: `/clinic/room/list-all-bed` })
  },
 
  //
  resetRoom: async () => {
    return await request.get({ url: `/clinic/room/reset-room` })
  },
 
  //
  getMonitorInfo: async () => {
    return await request.get({ url: `/clinic/room/monitor` })
  },
 
  // 手动开诊
  startBiz: async () => {
    return await request.get({ url: `/clinic/room/start-biz` })
  },
 
  // 手动闭诊
  closeBiz: async () => {
    return await request.get({ url: `/clinic/room/close-biz` })
  },
 
  /**
   * 管理员强制清空工位(医生下班忘离座 / 换人使用同一工位)。
   *
   * 与医生自己的「离座」不同:这里可以清**任何人**占用的工位。
   * 后端只在该工位处于「医生在岗 / 暂停」且已被占用时才生效,空闲工位会报"状态不允许"。
   */
  forceClearBed: async (params: { roomId: number | null; bedNo: string | null }) => {
    return await request.post({ url: `/clinic/room/force-clear-bed`, params })
  },
 
  /** 「选择工位模式」按本机IP匹配工位(模式 1/3):返回后端识别到的IP + 候选工位(已排序) */
  getIpBed: async () => {
    return await request.get({ url: `/clinic/room/get-ip-bed` })
  },
 
  /**
   * 一键自动入座(模式 1/3):后端按来访IP匹配工位并直接落座。
   *
   * 相比原来「getIpBed → bindIpToBed → bedDoctorOn」三步拼装,这里只失败一次即可排查:
   * 返回体带 clientIp 与 reason(ip_invalid / nomatch / multi / occupied / error)。
   * 服务端保证:命中"我的工位"时幂等恢复;不会重复新增(一人多工位由前端切换)。
   */
  autoSeat: async () => {
    return await request.post({ url: `/clinic/room/auto-seat` })
  },
 
  /** 查询当前登录人已入座的工位(系统顶栏"当前工位"标签用,单值;多工位请用 getMySeats) */
  getMySeat: async () => {
    return await request.get({ url: `/clinic/room/my-seat` })
  },
 
  /**
   * 【本需求·一人多工位】查询当前登录人占据的**全部**工位(节假日值班多岗位)。
   * 返回数组,按 roomId + bedNo 升序;未占工位返回空数组。
   */
  getMySeats: async () => {
    return await request.get({ url: `/clinic/room/my-seats` })
  },
 
  /**
   * 【本需求·接班自助接管】把该工位从"别人占用"改为"我占用"。
   * 后端:审计日志 → 强制原占用人离座 → 立即让我入座(同一事务)。
   */
  takeOverBed: async (params: { roomId: number | null; bedNo: string | null }) => {
    return await request.post({ url: `/clinic/room/take-over-bed`, params })
  },
 
  /**
   * 客户端 IP 识别诊断:返回各代理头、直连地址、规范化结果、是否服务器自身地址、服务器网卡列表与结论。
   * 现场排查"工位绑定的 IP 不对"用(选工位页的「IP 诊断」按钮)。
   */
  ipDebug: async () => {
    return await request.get({ url: `/clinic/room/ip-debug` })
  },
 
  /**
   * 工位状态诊断:返回该工位**库内原始行**(含 bed_no 长度/HEX、status、doc_id、deleted)与结论。
   * 用于排查"工位明明空闲却入座失败(报状态异常)"。
   */
  bedState: async (params: { id?: number | null; roomId?: number | null; bedNo?: string | null }) => {
    const query: string[] = []
    if (params?.id != null) query.push(`id=${params.id}`)
    if (params?.roomId != null) query.push(`roomId=${params.roomId}`)
    if (params?.bedNo != null) query.push(`bedNo=${encodeURIComponent(params.bedNo)}`)
    return await request.get({ url: `/clinic/room/bed-state?${query.join('&')}` })
  },
 
  /**
   * 「选择工位模式」把本机IP绑定到指定工位(模式 2/3)。
   * force=false 时若该IP已绑在别的工位,返回 code=409 + 冲突工位信息,由界面确认后再带 force=true 覆盖。
   */
  bindIpToBed: async (id: number, force = false) => {
    return await request.post({
      url: `/clinic/room/bind-ip?id=${id}&force=${force}`
    })
  }
 
}