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

@@ -92,6 +92,20 @@ public class PractitionerAppServiceImpl implements IPractitionerAppService {
bizUser.setPassword(SecurityUtils.encryptPassword(userAndPractitionerDto.getPassword())); // 密码
bizUser.setStatus(userAndPractitionerDto.getStatus()); // 状态
bizUser.setRemark(userAndPractitionerDto.getRemark()); // 备注
// 确保tenantId被设置如果自动填充机制未能正确填充
if (bizUser.getTenantId() == null) {
try {
bizUser.setTenantId(SecurityUtils.getLoginUser().getTenantId());
} catch (Exception e) {
// 如果无法获取当前登录用户则使用默认租户ID
bizUser.setTenantId(1); // 默认租户ID
}
}
// 确保审计字段被设置
com.core.common.utils.AuditFieldUtil.setCreateInfo(bizUser);
iBizUserService.save(bizUser);
Long userId =
iBizUserService.getOne(new LambdaQueryWrapper<BizUser>().eq(BizUser::getUserName, userName)).getUserId(); // 用户id
@@ -119,6 +133,17 @@ public class PractitionerAppServiceImpl implements IPractitionerAppService {
practitioner.setAddress(userAndPractitionerDto.getAddress()); // 地址
practitioner.setYbNo(userAndPractitionerDto.getYbNo()); // 医保码
practitioner.setUserId(userId); // 系统用户id
// 确保tenantId被设置如果自动填充机制未能正确填充
if (practitioner.getTenantId() == null) {
try {
practitioner.setTenantId(SecurityUtils.getLoginUser().getTenantId());
} catch (Exception e) {
// 如果无法获取当前登录用户则使用默认租户ID
practitioner.setTenantId(1); // 默认租户ID
}
}
// 责任科室
List<PractitionerOrgAndLocationDto> responsibilityOrgDtoList =
userAndPractitionerDto.getResponsibilityOrgDtoList();
@@ -295,6 +320,20 @@ public class PractitionerAppServiceImpl implements IPractitionerAppService {
bizUser.setSex(sex); // 性别
bizUser.setStatus(userAndPractitionerDto.getStatus()); // 状态
bizUser.setRemark(userAndPractitionerDto.getRemark()); // 备注
// 确保tenantId被设置如果自动填充机制未能正确填充
if (bizUser.getTenantId() == null) {
try {
bizUser.setTenantId(SecurityUtils.getLoginUser().getTenantId());
} catch (Exception e) {
// 如果无法获取当前登录用户则使用默认租户ID
bizUser.setTenantId(1); // 默认租户ID
}
}
// 确保审计字段被设置
com.core.common.utils.AuditFieldUtil.setUpdateInfo(bizUser);
iBizUserService.update(bizUser, new LambdaQueryWrapper<BizUser>().eq(BizUser::getUserId, userId));
// 先删除,再新增 sys_user_role
practitionerAppAppMapper.delUserRole(userId);
@@ -316,6 +355,17 @@ public class PractitionerAppServiceImpl implements IPractitionerAppService {
practitioner.setAddress(userAndPractitionerDto.getAddress()); // 地址
practitioner.setYbNo(userAndPractitionerDto.getYbNo()); // 医保码
practitioner.setUserId(userId); // 系统用户id
// 确保tenantId被设置如果自动填充机制未能正确填充
if (practitioner.getTenantId() == null) {
try {
practitioner.setTenantId(SecurityUtils.getLoginUser().getTenantId());
} catch (Exception e) {
// 如果无法获取当前登录用户则使用默认租户ID
practitioner.setTenantId(1); // 默认租户ID
}
}
// 责任科室
List<PractitionerOrgAndLocationDto> responsibilityOrgDtoList =
userAndPractitionerDto.getResponsibilityOrgDtoList();
@@ -446,6 +496,17 @@ public class PractitionerAppServiceImpl implements IPractitionerAppService {
Practitioner practitioner = new Practitioner();
practitioner.setId(practitionerId);
practitioner.setOrgId(orgId);
// 确保tenantId被设置如果自动填充机制未能正确填充
if (practitioner.getTenantId() == null) {
try {
practitioner.setTenantId(SecurityUtils.getLoginUser().getTenantId());
} catch (Exception e) {
// 如果无法获取当前登录用户则使用默认租户ID
practitioner.setTenantId(1); // 默认租户ID
}
}
iPractitionerService.updateById(practitioner);
return R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00004, new Object[] {"切换科室"}));
}

View File

@@ -112,6 +112,12 @@ public class UserAndPractitionerDto {
private Long orgId;
private String orgId_dictText;
/**
* 创建时间
*/
@com.fasterxml.jackson.annotation.JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/**
* 责任科室
*/

View File

@@ -23,7 +23,8 @@
T3.org_id,
T3.phar_prac_cert_no,
T3.dr_profttl_code,
T3.signature
T3.signature,
T3.create_time
from (
SELECT T1.tenant_id,
T1.id AS practitioner_id,
@@ -43,7 +44,8 @@
T1.org_id,
T1.phar_prac_cert_no,
T1.dr_profttl_code,
T1.signature
T1.signature,
T2.create_time
FROM adm_practitioner AS T1
LEFT JOIN sys_user AS T2 ON T2.user_id = T1.user_id
AND T2.delete_flag = '0'

View File

@@ -15,7 +15,7 @@
<setting name="logImpl" value="SLF4J"/>
<!-- <setting name="logImpl" value="org.apache.ibatis.logging.stdout.StdOutImpl"/>-->
<!-- 使用驼峰命名法转换字段 -->
<!-- <setting name="mapUnderscoreToCamelCase" value="true"/> -->
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
</configuration>