From da5e1704cfa9785447d50ebab362cb29967ea666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=BA=91?= <赵云@gentronhealth.com> Date: Wed, 13 May 2026 13:59:58 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20Bug=20#400:=20=E9=97=A8=E8=AF=8A=E5=8C=BB?= =?UTF-8?q?=E7=94=9F=E7=AB=99=E7=82=B9=E5=87=BB=E3=80=90=E5=AE=8C=E8=AF=8A?= =?UTF-8?q?=E3=80=91=E5=90=8E=EF=BC=8Ctriage=5Fqueue=5Fitem=20=E8=A1=A8=20?= =?UTF-8?q?status=20=E5=AD=97=E6=AE=B5=E6=9C=AA=E6=8C=89=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=B8=BA=2030?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因分析: triage_queue_item.status 字段在 DDL 中定义为 VARCHAR(50),但 Java 实体 TriageQueueItem.status 为 Integer 类型,应用层使用 TriageQueueStatus 枚举值 (0/10/20/30/40) 进行读写。数据类型不匹配导致 MyBatis-Plus 无法正确映射 status 字段, 完诊时使用 LambdaUpdateWrapper 更新 status=30 操作失败。 修复方案: 1. 修正 DDL:将 status 字段类型从 VARCHAR(50) 改为 INTEGER 2. 新增迁移 SQL:修改已有数据库表的 status 字段类型为 INTEGER Co-Authored-By: Claude Opus 4.7 --- .../20260115_add_table_triage_queue_item.sql | 2 +- ..._400_fix_triage_queue_item_status_type.sql | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 openhis-server-new/sql/bug_400_fix_triage_queue_item_status_type.sql diff --git a/openhis-server-new/sql/20260115_add_table_triage_queue_item.sql b/openhis-server-new/sql/20260115_add_table_triage_queue_item.sql index f2253a22c..a7a158d1c 100755 --- a/openhis-server-new/sql/20260115_add_table_triage_queue_item.sql +++ b/openhis-server-new/sql/20260115_add_table_triage_queue_item.sql @@ -13,7 +13,7 @@ CREATE TABLE IF NOT EXISTS triage_queue_item ( patient_name VARCHAR(255), healthcare_name VARCHAR(255), practitioner_name VARCHAR(255), - status VARCHAR(50) NOT NULL, -- WAITING/CALLING/SKIPPED/COMPLETED + status INTEGER NOT NULL DEFAULT 0, -- 分诊队列状态: 0=WAITING(等待), 10=CALLING(叫号中), 20=IN_CLINIC(诊中), 30=COMPLETED(已完成), 40=SKIPPED(已跳过) queue_order INTEGER NOT NULL, create_time TIMESTAMP, update_time TIMESTAMP, diff --git a/openhis-server-new/sql/bug_400_fix_triage_queue_item_status_type.sql b/openhis-server-new/sql/bug_400_fix_triage_queue_item_status_type.sql new file mode 100644 index 000000000..7289a8241 --- /dev/null +++ b/openhis-server-new/sql/bug_400_fix_triage_queue_item_status_type.sql @@ -0,0 +1,30 @@ +-- Bug #400 修复:triage_queue_item.status 字段类型修正 +-- 原 DDL 将 status 定义为 VARCHAR(50),但 Java 实体 TriageQueueItem.status 为 Integer 类型, +-- 应用层使用 TriageQueueStatus 枚举值(0/10/20/30/40)写入,类型不匹配导致 MyBatis-Plus +-- 无法正确映射 status 字段,完诊时 status 更新为 30 失败。 +-- +-- 注意:必须在后端实际连接的 schema 中执行(dev=hisdev, test=histest, prd=hisprd) +-- 执行前请先确认:SET search_path TO hisdev; (或对应的 schema) + +-- 1. 先将已有的字符串值转换为对应的整数值 +-- 如果之前写入的是枚举 code(如 'waiting'、'completed'),需要先转换 +UPDATE triage_queue_item +SET status = CASE + WHEN status IN ('0', 'waiting', 'WAITING') THEN 0 + WHEN status IN ('10', 'calling', 'CALLING') THEN 10 + WHEN status IN ('20', 'in-clinic', 'IN_CLINIC', 'in-clinic') THEN 20 + WHEN status IN ('30', 'completed', 'COMPLETED') THEN 30 + WHEN status IN ('40', 'skipped', 'SKIPPED') THEN 40 + WHEN status IN ('50', 'refunded', 'REFUNDED') THEN 50 + WHEN status IN ('60', 'follow', 'FOLLOW') THEN 60 + ELSE 0 +END +WHERE status IS NOT NULL AND status !~ '^[0-9]+$'; + +-- 2. 修改字段类型为 INTEGER +ALTER TABLE triage_queue_item + ALTER COLUMN status TYPE INTEGER USING status::INTEGER; + +-- 3. 设置默认值 +ALTER TABLE triage_queue_item + ALTER COLUMN status SET DEFAULT 0;