动态数据源
This commit is contained in:
@@ -53,6 +53,7 @@ import com.njcn.user.api.UserFeignClient;
|
||||
import com.njcn.user.pojo.po.User;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
@@ -77,6 +78,7 @@ import static com.njcn.common.pojo.constant.LogInfo.UNKNOWN_USER;
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implements AuditService {
|
||||
|
||||
private final AuditMapper auditMapper;
|
||||
@@ -435,8 +437,41 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
||||
|
||||
@Override
|
||||
public Float getMemoInfo() {
|
||||
String schema = urls.substring(urls.lastIndexOf("/") + 1, urls.lastIndexOf("?"));
|
||||
return this.baseMapper.getMemoInfo(schema);
|
||||
// 1. 判空兜底,防止@Value注入为空/空字符串
|
||||
if (StrUtil.isBlank(urls)) {
|
||||
log.error("getMemoInfo error: 数据库链接地址urls为空,无法截取schema");
|
||||
return 0.0F;
|
||||
}
|
||||
String schema = null;
|
||||
try {
|
||||
// 2. 先获取最后一个/的下标,截取库名起始位
|
||||
int lastSlashIndex = urls.lastIndexOf("/");
|
||||
// 3. 先获取?的下标,截取库名结束位
|
||||
int questionMarkIndex = urls.indexOf("?");
|
||||
// 4. 兼容两种场景:有问号参数、无问号参数
|
||||
if (lastSlashIndex > -1) {
|
||||
if (questionMarkIndex > lastSlashIndex) {
|
||||
// 正常场景:url带?后缀参数 → 截取 / 和 ? 之间的库名
|
||||
schema = urls.substring(lastSlashIndex + 1, questionMarkIndex);
|
||||
} else {
|
||||
// 兼容场景:url不带?后缀参数 → 截取 / 之后的全部内容作为库名
|
||||
schema = urls.substring(lastSlashIndex + 1);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 5. 捕获所有异常(下标越界、格式异常等),兜底处理
|
||||
log.error("getMemoInfo 截取数据库schema失败,urls={}, 异常信息:{}", urls, e);
|
||||
return 0.0F;
|
||||
}
|
||||
// 6. 最终判空,防止截取结果为空
|
||||
if (StrUtil.isBlank(schema)) {
|
||||
log.error("getMemoInfo 截取到的数据库schema为空,urls={}", urls);
|
||||
return 0.0F;
|
||||
}
|
||||
// 7. 调用mapper查询,返回结果
|
||||
Float memoInfo = this.baseMapper.getMemoInfo(schema);
|
||||
// 8. 兼容mapper返回null的情况,避免接口返回null报错
|
||||
return ObjectUtil.isNull(memoInfo) ? 0.0F : memoInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user