fix: Bug#704 文化程度字典key修正 + 死亡时间日期格式兼容
问题: 1. 修改患者弹窗文化程度下拉无数据 根因:前端查询字典key为education_level,数据库实际为educational_level 2. 填写死亡时间保存时JSON解析报错 根因:el-date-picker用YYYY/MM/DD格式,后端期望yyyy-MM-dd HH:mm:ss 修复: - 前端:字典key修正为educational_level,降级数据与数据库对齐 - 前端:el-date-picker value-format改为YYYY-MM-DD HH:mm:ss - 前端:submitForm增加deceasedDate格式标准化兜底 - 后端:PatientBaseInfoDto deceasedDate改用FlexibleDateDeserializer兼容多格式 - 新增FlexibleDateDeserializer支持yyyy-MM-dd和yyyy/MM/dd等格式
This commit is contained in:
@@ -0,0 +1,42 @@
|
|||||||
|
package com.healthlink.his.web.patientmanage.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支持多种日期格式的反序列化器
|
||||||
|
* 兼容 yyyy-MM-dd HH:mm:ss 和 yyyy/MM/dd HH:mm:ss 等格式
|
||||||
|
*/
|
||||||
|
public class FlexibleDateDeserializer extends JsonDeserializer<Date> {
|
||||||
|
|
||||||
|
private static final String[] DATE_FORMATS = {
|
||||||
|
"yyyy-MM-dd HH:mm:ss",
|
||||||
|
"yyyy/MM/dd HH:mm:ss",
|
||||||
|
"yyyy/M/d HH:mm:ss",
|
||||||
|
"yyyy-MM-dd'T'HH:mm:ss",
|
||||||
|
"yyyy-MM-dd'T'HH:mm:ss.SSS",
|
||||||
|
"yyyy-MM-dd",
|
||||||
|
"yyyy/MM/dd"
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Date deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||||
|
String dateStr = p.getValueAsString();
|
||||||
|
if (dateStr == null || dateStr.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (String pattern : DATE_FORMATS) {
|
||||||
|
try {
|
||||||
|
return new SimpleDateFormat(pattern).parse(dateStr);
|
||||||
|
} catch (ParseException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IOException("无法解析日期: " + dateStr + ",支持格式: yyyy-MM-dd HH:mm:ss 或 yyyy/MM/dd HH:mm:ss");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.healthlink.his.web.patientmanage.dto;
|
package com.healthlink.his.web.patientmanage.dto;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
import com.healthlink.his.common.annotation.Dict;
|
import com.healthlink.his.common.annotation.Dict;
|
||||||
@@ -144,7 +145,7 @@ public class PatientBaseInfoDto {
|
|||||||
/**
|
/**
|
||||||
* 死亡时间
|
* 死亡时间
|
||||||
*/
|
*/
|
||||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
|
@JsonDeserialize(using = FlexibleDateDeserializer.class)
|
||||||
private Date deceasedDate;
|
private Date deceasedDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -702,12 +702,26 @@ const getGenderOptions = async () => {
|
|||||||
const getEducationLevelOptions = async () => {
|
const getEducationLevelOptions = async () => {
|
||||||
try {
|
try {
|
||||||
// 从字典管理获取文化程度数据
|
// 从字典管理获取文化程度数据
|
||||||
const response = await getDicts('education_level');
|
const response = await getDicts('educational_level');
|
||||||
console.log('获取到的文化程度原始数据:', response);
|
console.log('获取到的文化程度原始数据:', response);
|
||||||
|
|
||||||
// 确保数据是数组
|
// 确保数据是数组且非空
|
||||||
if (!response || response.code !== 200 || !Array.isArray(response.data)) {
|
if (!response || response.code !== 200 || !Array.isArray(response.data) || response.data.length === 0) {
|
||||||
console.error('文化程度数据格式错误:', response);
|
console.warn('文化程度数据为空或格式错误,使用默认数据:', response);
|
||||||
|
// 降级方案:使用默认的文化程度选项,按编码顺序排列
|
||||||
|
educationLevelList.value = [
|
||||||
|
{ value: '1', info: '大学本科' },
|
||||||
|
{ value: '2', info: '硕士研究生' },
|
||||||
|
{ value: '3', info: '博士研究生' },
|
||||||
|
{ value: '4', info: '初中毕业' },
|
||||||
|
{ value: '5', info: '大学专科结业' },
|
||||||
|
{ value: '6', info: '技工学院结业' },
|
||||||
|
{ value: '7', info: '职业高中结业' },
|
||||||
|
{ value: '8', info: '小学毕业' },
|
||||||
|
{ value: '9', info: '普通高中结业' },
|
||||||
|
{ value: '10', info: '中等专科结业' },
|
||||||
|
{ value: '99', info: '其他' }
|
||||||
|
];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const educationDict = response.data;
|
const educationDict = response.data;
|
||||||
@@ -743,17 +757,18 @@ const getEducationLevelOptions = async () => {
|
|||||||
console.error('获取文化程度字典数据失败:', error);
|
console.error('获取文化程度字典数据失败:', error);
|
||||||
// 降级方案:使用默认的文化程度选项,按编码顺序排列
|
// 降级方案:使用默认的文化程度选项,按编码顺序排列
|
||||||
educationLevelList.value = [
|
educationLevelList.value = [
|
||||||
{ value: '3912', info: '大学本科' },
|
{ value: '1', info: '大学本科' },
|
||||||
{ value: '3913', info: '硕士研究生' },
|
{ value: '2', info: '硕士研究生' },
|
||||||
{ value: '3914', info: '博士研究生' },
|
{ value: '3', info: '博士研究生' },
|
||||||
{ value: '3915', info: '初中毕业' },
|
{ value: '4', info: '初中毕业' },
|
||||||
{ value: '3916', info: '大学毕业' },
|
{ value: '5', info: '大学专科结业' },
|
||||||
{ value: '3917', info: '技工学校毕业' },
|
{ value: '6', info: '技工学院结业' },
|
||||||
{ value: '3918', info: '职业高中毕业' },
|
{ value: '7', info: '职业高中结业' },
|
||||||
{ value: '3919', info: '小学毕业' },
|
{ value: '8', info: '小学毕业' },
|
||||||
{ value: '3920', info: '普通高中毕业' },
|
{ value: '9', info: '普通高中结业' },
|
||||||
{ value: '3921', info: '中等专科毕业' }
|
{ value: '10', info: '中等专科结业' },
|
||||||
].sort((a, b) => parseInt(a.value) - parseInt(b.value)); // 确保默认选项也按编码排序
|
{ value: '99', info: '其他' }
|
||||||
|
];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const options = ref(pcas); // 地区数据
|
const options = ref(pcas); // 地区数据
|
||||||
@@ -1523,6 +1538,18 @@ function submitForm() {
|
|||||||
if (!form.value.identifierNo) {
|
if (!form.value.identifierNo) {
|
||||||
form.value.typeCode = undefined;
|
form.value.typeCode = undefined;
|
||||||
}
|
}
|
||||||
|
// 修复死亡时间日期格式:确保 yyyy-MM-dd HH:mm:ss 格式
|
||||||
|
if (form.value.deceasedDate) {
|
||||||
|
const d = form.value.deceasedDate;
|
||||||
|
if (d instanceof Date) {
|
||||||
|
const pad = (n) => String(n).padStart(2, '0');
|
||||||
|
form.value.deceasedDate = d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()) + ' ' + pad(d.getHours()) + ':' + pad(d.getMinutes()) + ':' + pad(d.getSeconds());
|
||||||
|
} else if (typeof d === 'string') {
|
||||||
|
// 将任何非标准格式转为 yyyy-MM-dd HH:mm:ss
|
||||||
|
const normalized = d.replace(/\//g, '-').replace(/T/, ' ').replace(/\.\d+Z?$/, '').trim();
|
||||||
|
form.value.deceasedDate = normalized;
|
||||||
|
}
|
||||||
|
}
|
||||||
// 拼接完整地址用于提交,但不覆写表单字段(避免弹窗关闭前显示全地址)
|
// 拼接完整地址用于提交,但不覆写表单字段(避免弹窗关闭前显示全地址)
|
||||||
const submitData = { ...form.value, address: getAddress(form) };
|
const submitData = { ...form.value, address: getAddress(form) };
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user