From 26cc054d9470d1a6bb9728bb220170c0c019656d Mon Sep 17 00:00:00 2001 From: linjj <850658129@qq.com> Date: Tue, 11 Nov 2025 15:46:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=BD=AE=E5=B7=9E=E4=BA=BA=E5=8C=BB=E6=82=A3?= =?UTF-8?q?=E8=80=85=E5=9F=BA=E7=A1=80=E4=BF=A1=E6=81=AF=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/encodings.xml | 7 + .idea/misc.xml | 14 ++ .idea/vcs.xml | 6 + .idea/workspace.xml | 155 ++++++++++++++++++++ pom.xml | 8 + src/main/java/com/chaozhou/ArchiveSync.java | 53 ++++--- src/main/resources/application.properties | 11 +- 7 files changed, 229 insertions(+), 25 deletions(-) create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..132404b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..8c1d8e3 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,155 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1758874595131 + + + 1760084026033 + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 4f6f0db..dc7c4e2 100644 --- a/pom.xml +++ b/pom.xml @@ -33,6 +33,14 @@ orai18n 21.3.0.0 + + + mysql + mysql-connector-java + 5.1.32 + + + com.microsoft.sqlserver diff --git a/src/main/java/com/chaozhou/ArchiveSync.java b/src/main/java/com/chaozhou/ArchiveSync.java index 8353a5a..6585006 100644 --- a/src/main/java/com/chaozhou/ArchiveSync.java +++ b/src/main/java/com/chaozhou/ArchiveSync.java @@ -30,35 +30,12 @@ public class ArchiveSync { "AND 出院日期 < TRUNC(SYSDATE) + 1"; // 明天 00:00:00(不含) -// /* 读取 9 月 25 日到今天的全部病例 */ -// private static final String SQL_ORA_TODAY = -// "SELECT ID号,住院号,住院次数,姓名,性别,入院时间,入院科室编码," + -// " 主管医生工号,年龄,身份证号,出院日期,当前科室编码 " + -// "FROM PORTAL_HIS.V_WZHGD_HZJCXX h " + -// "WHERE 出院日期 >= TO_DATE('2025-09-25', 'YYYY-MM-DD') " + -// "AND 出院日期 <= TRUNC(SYSDATE)"; - - - - - /* SQL Server:当天已归档主键 */ private static final String SQL_MSS_TODAY_KEYS = "SELECT inp_no + '|' + CAST(visit_id AS VARCHAR) AS key1 " + "FROM archive_master " + "WHERE CONVERT(date, discharge_date_time) = CONVERT(date, GETDATE())"; - -// /* SQL Server:9 月 25 日到今天已归档主键 */ -// private static final String SQL_MSS_TODAY_KEYS = -// "SELECT inp_no + '|' + CAST(visit_id AS VARCHAR) AS key1 " + -// "FROM archive_master " + -// "WHERE CONVERT(date, discharge_date_time) >= '2025-09-25' " + -// "AND CONVERT(date, discharge_date_time) <= CONVERT(date, GETDATE())"; - - - - /* 写入 SQL Server */ private static final String SQL_MSS_INSERT = "INSERT INTO archive_master " + @@ -67,6 +44,14 @@ public class ArchiveSync { " dept_name,id_card,ArchiveState,C1) " + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?, '64','ljj')"; + + + /* MySQL:根据工号查询医生姓名 */ + private static final String SQL_MYSQL_DOCTOR_NAME = + "SELECT name FROM power_user WHERE user_name = ?"; + + + /* 当前最大 id */ private static final String SQL_MAX_ID = "SELECT ISNULL(MAX(id), 0) FROM archive_master"; @@ -84,6 +69,7 @@ public class ArchiveSync { while (true) { try (Connection ora = getConn(cfg, "oracle"); Connection mss = getConn(cfg, "sqlserver"); + Connection mysql = getConn(cfg, "mysql"); // 新增 MySQL 连接 PreparedStatement psOra = ora.prepareStatement(SQL_ORA_TODAY); PreparedStatement psKeys = mss.prepareStatement(SQL_MSS_TODAY_KEYS); PreparedStatement psMaxId = mss.prepareStatement(SQL_MAX_ID); @@ -133,7 +119,26 @@ public class ArchiveSync { psIns.setNString(7, rs.getString("入院科室编码")); // dept_admission_to psIns.setTimestamp(8, rs.getTimestamp("入院时间")); // admission_date_time psIns.setTimestamp(9, rs.getTimestamp("出院日期")); // discharge_date_time - psIns.setString(10, rs.getString("主管医生工号")); // DOCTOR_IN_CHARGE + /* 查询 MySQL 获取医生姓名 */ + String doctorCode = rs.getString("主管医生工号"); + String doctorName = doctorCode; // 默认用编码 + if (doctorCode != null && !doctorCode.trim().isEmpty()) { + try (PreparedStatement psDoctor = mysql.prepareStatement(SQL_MYSQL_DOCTOR_NAME)) { + psDoctor.setString(1, doctorCode.trim()); + try (ResultSet rsDoctor = psDoctor.executeQuery()) { + if (rsDoctor.next()) { + String nameFromMysql = rsDoctor.getString("name"); + // 仅当查询到非空姓名时才替换 + if (nameFromMysql != null && !nameFromMysql.trim().isEmpty()) { + doctorName = nameFromMysql; + } + } + } catch (SQLException e) { + log.info("查询医生姓名失败,工号: {}", doctorCode, e); + } + } + } + psIns.setString(10, doctorName); // 将查询到的姓名存入 DOCTOR_IN_CHARGE 字段 psIns.setNString(11, rs.getString("年龄")); // SubAssort psIns.setString(12, rs.getString("身份证号")); // id_card psIns.setString(13, rs.getString("当前科室编码")); // dept_name diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b03830b..5213ae5 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -7,5 +7,14 @@ sqlserver.url=jdbc:sqlserver://localhost:1433;databaseName=emr_record;encrypt=fa sqlserver.user=sa sqlserver.password=docus@702 + + +# MySQL ????? +mysql.url=jdbc:mysql://localhost:3306/power?useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai +mysql.user=root +mysql.password=docus702 + + #??????? -poll.interval=300 \ No newline at end of file +poll.interval=300 +