From 68b92dfe316c12de96c43921e1a49982c0ecc57c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=8E=E4=BD=97?= Date: Mon, 8 Jun 2026 22:12:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Bug#705=20=E6=AD=BB=E4=BA=A1=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=97=A5=E6=9C=9F=E6=A0=BC=E5=BC=8F=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=20=E2=80=94=20DTO=E6=94=B9String+Service=E5=B1=82=E8=A7=A3?= =?UTF-8?q?=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:前端el-date-picker发送yyyy/MM/dd格式,后端Jackson无法解析 根因:Jackson全局simpleDateFormat覆盖字段级@JsonDeserialize,SimpleModule注册Date反序列化器在Spring Boot 4.x中不生效 修复: - PatientBaseInfoDto.deceasedDate: Date → String(绕过Jackson日期解析) - PatientInformationServiceImpl.handlePatientInfo: 手动解析String→Date,兼容yyyy-MM-dd和yyyy/MM/dd格式 - ApplicationConfig: 恢复干净状态,移除无效的自定义Date反序列化器 - systemd service: 修正jar路径 openhis → healthlink-his --- .../framework/config/ApplicationConfig.java | 38 +++---------------- .../impl/PatientInformationServiceImpl.java | 15 +++++++- .../patientmanage/dto/PatientBaseInfoDto.java | 3 +- 3 files changed, 20 insertions(+), 36 deletions(-) diff --git a/healthlink-his-server/core-framework/src/main/java/com/core/framework/config/ApplicationConfig.java b/healthlink-his-server/core-framework/src/main/java/com/core/framework/config/ApplicationConfig.java index 5af5ebeb3..3845efa45 100755 --- a/healthlink-his-server/core-framework/src/main/java/com/core/framework/config/ApplicationConfig.java +++ b/healthlink-his-server/core-framework/src/main/java/com/core/framework/config/ApplicationConfig.java @@ -19,20 +19,12 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.TimeZone; -/** - * 程序注解配置 - * - * @author system - */ @Configuration -// 表示通过aop框架暴露该代理对象,AopContext能够访问 @EnableAspectJAutoProxy(exposeProxy = true) -// 指定要扫描的Mapper类的包的路径 @MapperScan({"com.core.**.mapper", "com.healthlink.his.**.mapper"}) public class ApplicationConfig { private static final Logger log = LoggerFactory.getLogger(ApplicationConfig.class); - /** 支持多种日期格式的反序列化器 */ private static final JsonDeserializer LOCAL_DATE_TIME_DESERIALIZER = new JsonDeserializer() { private static final DateTimeFormatter ISO_FORMATTER = DateTimeFormatter.ISO_LOCAL_DATE_TIME; private static final DateTimeFormatter SIMPLE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); @@ -41,43 +33,23 @@ public class ApplicationConfig { @Override public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { String text = p.getText(); - if (text == null || text.isEmpty()) { - return null; - } - // 去除时区后缀 Z/z 和偏移量 +HH:MM/+HHMM(LocalDateTime 不含时区信息) + if (text == null || text.isEmpty()) return null; String cleaned = text.replaceAll("[Zz]$", "").replaceAll("[+-]\\d{2}:?\\d{2}$", ""); - // 尝试 ISO 8601 格式(yyyy-MM-ddTHH:mm:ss.SSS) - try { - return LocalDateTime.parse(cleaned, ISO_FORMATTER); - } catch (Exception ignored) { - // intentionally ignored - } - // 尝试简单格式(yyyy-MM-dd HH:mm:ss) - try { - return LocalDateTime.parse(cleaned, SIMPLE_FORMATTER); - } catch (Exception ignored) { - // intentionally ignored - } - // 尝试斜杠格式(yyyy/M/d HH:mm:ss) + try { return LocalDateTime.parse(cleaned, ISO_FORMATTER); } catch (Exception ignored) {} + try { return LocalDateTime.parse(cleaned, SIMPLE_FORMATTER); } catch (Exception ignored) {} return LocalDateTime.parse(cleaned, SLASH_FORMATTER); } }; - /** - * 时区配置 - */ @Bean public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() { return builder -> { - // 设置默认时区 builder.timeZone(TimeZone.getDefault()); - // 设置日期格式为 yyyy/M/d HH:mm:ss,支持多种格式反序列化 - builder.simpleDateFormat("yyyy/M/d HH:mm:ss"); - // 添加JavaTimeModule支持,用于LocalDateTime + builder.simpleDateFormat("yyyy-MM-dd HH:mm:ss"); JavaTimeModule javaTimeModule = new JavaTimeModule(); javaTimeModule.addDeserializer(LocalDateTime.class, LOCAL_DATE_TIME_DESERIALIZER); builder.modules(javaTimeModule); - builder.serializerByType(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy/M/d HH:mm:ss"))); + builder.serializerByType(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); }; } } diff --git a/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/patientmanage/appservice/impl/PatientInformationServiceImpl.java b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/patientmanage/appservice/impl/PatientInformationServiceImpl.java index cf217739d..62cd36967 100755 --- a/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/patientmanage/appservice/impl/PatientInformationServiceImpl.java +++ b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/patientmanage/appservice/impl/PatientInformationServiceImpl.java @@ -36,6 +36,8 @@ import jakarta.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -310,7 +312,18 @@ public class PatientInformationServiceImpl implements IPatientInformationService patient.setBloodAbo(patientInfoDto.getBloodAbo()); // 血型ABO patient.setBloodRh(patientInfoDto.getBloodRh()); // 血型RH patient.setMaritalStatusEnum(patientInfoDto.getMaritalStatusEnum()); // 婚姻状态 - patient.setDeceasedDate(patientInfoDto.getDeceasedDate()); // 死亡时间 + // 死亡时间:支持 yyyy-MM-dd HH:mm:ss 和 yyyy/MM/dd HH:mm:ss 格式 + if (patientInfoDto.getDeceasedDate() != null && !patientInfoDto.getDeceasedDate().isEmpty()) { + String dateStr = patientInfoDto.getDeceasedDate(); + String[] patterns = {"yyyy-MM-dd HH:mm:ss", "yyyy/MM/dd HH:mm:ss", "yyyy/M/d HH:mm:ss"}; + Date parsedDate = null; + for (String pat : patterns) { + try { parsedDate = new SimpleDateFormat(pat).parse(dateStr); break; } catch (Exception ignored) {} + } + patient.setDeceasedDate(parsedDate); + } else { + patient.setDeceasedDate(null); + } patient.setNationalityCode(patientInfoDto.getNationalityCode());// 民族 patient.setActiveFlag(patientInfoDto.getActiveFlag());// 活动标识 patient.setCountryCode(patientInfoDto.getCountryCode());// 国家编码 diff --git a/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/patientmanage/dto/PatientBaseInfoDto.java b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/patientmanage/dto/PatientBaseInfoDto.java index 101b57014..40d4fdb4b 100755 --- a/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/patientmanage/dto/PatientBaseInfoDto.java +++ b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/patientmanage/dto/PatientBaseInfoDto.java @@ -145,8 +145,7 @@ public class PatientBaseInfoDto { /** * 死亡时间 */ - @JsonDeserialize(using = FlexibleDateDeserializer.class) - private Date deceasedDate; + private String deceasedDate; /** * 病人证件信息集合