yxh
yxh
2026-11-08 09dc74e264b6262cbe41c9c8476e24705871d4a6
src/api/ecg/room/index.ts
@@ -6,17 +6,92 @@
  roomId: number | null // 诊室编号
  roomName: string | null // 诊室名称
  bedNo: string | null // 诊疗床编号
  ip: string | null // 诊室IP
  ip: string | null // 诊室工位IP
  status: number | null //开诊状态  0-关闭 1-关闭中 10-已开通 20-有医生 30-暂停
  docId: number | null
  docName: string | null
  checkTypes: number[]
  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 {
  queueNum : number
  activeQueueNum : number
  openingBedNum : number
  /** 在座工位数(一人多工位时会大于医生数) */
  docBedNum : number
  /** 【本需求·统计按人合并】在座医生数(按 doc_id 去重) */
  docNum : number
  routingBedNum : number
  openingFlag : number
  checkTypeBedInfo: object
}
// 诊室和诊疗床 API
@@ -32,8 +107,12 @@
  },
  // 查询诊室和诊疗床详情
  getRoomByIP: async () => {
    return await request.get({ url: `/clinic/room/get-room-by-ip`})
  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})
  },
  // 新增诊室和诊疗床
@@ -89,6 +168,83 @@
  // 手动闭诊
  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}`
    })
  }
}