fix: Bug#705 死亡时间日期格式兼容 — DTO改String+Service层解析

问题:前端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
This commit is contained in:
2026-06-08 22:12:14 +08:00
parent c9e8729d07
commit 68b92dfe31
3 changed files with 20 additions and 36 deletions

View File

@@ -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<LocalDateTime> LOCAL_DATE_TIME_DESERIALIZER = new JsonDeserializer<LocalDateTime>() {
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/+HHMMLocalDateTime 不含时区信息)
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")));
};
}
}

View File

@@ -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());// 国家编码

View File

@@ -145,8 +145,7 @@ public class PatientBaseInfoDto {
/**
* 死亡时间
*/
@JsonDeserialize(using = FlexibleDateDeserializer.class)
private Date deceasedDate;
private String deceasedDate;
/**
* 病人证件信息集合