feat(core): 完善自动填充机制和时间格式化处理

- 替换 ServiceImpl 继承为 BaseService 以支持自动填充功能
- 在 HisBaseEntity 中添加 JsonFormat 注解统一时间格式化
- 重构 MybastisColumnsHandler 实现完整的自动填充逻辑,包括 createTime、updateTime、createBy、updateBy 和 tenantId 字段
- 添加详细的日志记录和异常处理机制
- 在 PractitionerAppServiceImpl 中增强租户ID和审计字段的设置逻辑
- 优化时间解析工具类 openhis.js 以正确处理 ISO 8601 格式时间字符串
- 更新数据库映射文件以支持下划线字段名映射
- 重构 SysUserServiceImpl 实现完整的审计字段自动填充机制
This commit is contained in:
2026-01-25 23:13:04 +08:00
parent ca043de624
commit ffce6f81c3
12 changed files with 372 additions and 158 deletions

View File

@@ -18,13 +18,42 @@ export function parseTime(time, pattern) {
if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
time = parseInt(time)
} else if (typeof time === 'string') {
time = time.replace(new RegExp(/-/gm), '/').replace('T', ' ').replace(new RegExp(/\.[\d]{3}/gm), '');
// 处理 ISO 8601 格式的时间字符串,保留时区信息
// 例如:"2026-01-19T01:59:27.239+08:00"
if (time.includes('T')) {
// 直接使用 ISO 8601 格式的字符串创建日期对象
date = new Date(time)
// 如果日期无效,尝试其他格式
if (isNaN(date.getTime())) {
// 移除毫秒部分但保留时区信息
time = time.replace(/\.\d{3}/, '')
date = new Date(time)
}
} else {
// 处理其他格式的字符串
time = time.replace(new RegExp(/-/gm), '/').replace('T', ' ').replace(new RegExp(/\.[\d]{3}/gm), '');
}
}
if (!date || isNaN(date.getTime())) {
// 如果还没有创建有效的日期对象,则基于处理后的字符串创建
if (typeof time === 'string') {
date = new Date(time)
}
}
if ((typeof time === 'number') && (time.toString().length === 10)) {
time = time * 1000
}
date = new Date(time)
if (!date || isNaN(date.getTime())) {
// 最终尝试使用原始时间值
date = new Date(time)
}
}
// 检查日期是否有效
if (isNaN(date.getTime())) {
return null
}
const formatObj = {
y: date.getFullYear(),
m: date.getMonth() + 1,