诊疗下没有项目功能完善
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.openhis.sys.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.core.common.core.domain.model.LoginUser;
|
||||
import com.core.common.utils.SecurityUtils;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.openhis.sys.domain.OperationRecord;
|
||||
@@ -10,6 +12,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -44,6 +47,10 @@ public class OperationRecordServiceImpl extends ServiceImpl<OperationRecordMappe
|
||||
operationRecord.setDbOpType(dbOpType);
|
||||
operationRecord.setTableName(tableName);
|
||||
operationRecord.setParamJson(paramJson);
|
||||
|
||||
// 统一补全必填字段(create_by、tenant_id、create_time)
|
||||
setRequiredFields(operationRecord);
|
||||
|
||||
baseMapper.insert(operationRecord);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
@@ -65,6 +72,10 @@ public class OperationRecordServiceImpl extends ServiceImpl<OperationRecordMappe
|
||||
operationRecord.setDbOpType(dbOpType);
|
||||
operationRecord.setTableName(tableName);
|
||||
operationRecord.setParamJson(paramJson);
|
||||
|
||||
// 统一补全必填字段(create_by、tenant_id、create_time)
|
||||
setRequiredFields(operationRecord);
|
||||
|
||||
baseMapper.insert(operationRecord);
|
||||
}
|
||||
|
||||
@@ -80,4 +91,28 @@ public class OperationRecordServiceImpl extends ServiceImpl<OperationRecordMappe
|
||||
return objectMapper.writeValueAsString(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置操作记录的必需字段(tenant_id、create_by、create_time),确保插入时不为null
|
||||
*
|
||||
* @param operationRecord 操作记录对象
|
||||
*/
|
||||
private void setRequiredFields(OperationRecord operationRecord) {
|
||||
String createBy = "system";
|
||||
Integer tenantId = null;
|
||||
try {
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
if (loginUser != null) {
|
||||
createBy = loginUser.getUsername();
|
||||
tenantId = loginUser.getTenantId();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 如果获取失败,使用默认值
|
||||
}
|
||||
operationRecord.setCreateBy(createBy != null ? createBy : "system");
|
||||
operationRecord.setTenantId(tenantId != null ? tenantId : 1);
|
||||
if (operationRecord.getCreateTime() == null) {
|
||||
operationRecord.setCreateTime(new Date());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user