Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -74,6 +74,12 @@
|
|||||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
|
||||||
|
<version>3.5.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!--数据库相关********end-->
|
<!--数据库相关********end-->
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,7 @@
|
|||||||
<artifactId>pqs-influx</artifactId>
|
<artifactId>pqs-influx</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.njcn.device.biz.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.njcn.device.biz.pojo.po.Overlimit;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author xy
|
||||||
|
* @since 2022-01-04
|
||||||
|
*/
|
||||||
|
@DS("sjzx")
|
||||||
|
@Mapper
|
||||||
|
public interface OverLimitWlMapper extends BaseMapper<Overlimit> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -35,11 +35,11 @@ spring:
|
|||||||
- data-id: share-config.yaml
|
- data-id: share-config.yaml
|
||||||
refresh: true
|
refresh: true
|
||||||
#数据中心使用
|
#数据中心使用
|
||||||
# - data-Id: share-config-datasource-db.yaml
|
- data-Id: share-config-datasource-db.yaml
|
||||||
# refresh: true
|
|
||||||
#PMS使用
|
|
||||||
- data-Id: share-config-harmonic-db.yaml
|
|
||||||
refresh: true
|
refresh: true
|
||||||
|
#PMS使用
|
||||||
|
# - data-Id: share-config-harmonic-db.yaml
|
||||||
|
# refresh: true
|
||||||
main:
|
main:
|
||||||
allow-bean-definition-overriding: true
|
allow-bean-definition-overriding: true
|
||||||
servlet:
|
servlet:
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ import com.njcn.user.api.UserFeignClient;
|
|||||||
import com.njcn.user.pojo.po.User;
|
import com.njcn.user.pojo.po.User;
|
||||||
import com.njcn.web.utils.RequestUtil;
|
import com.njcn.web.utils.RequestUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.compress.utils.IOUtils;
|
import org.apache.commons.compress.utils.IOUtils;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
@@ -77,11 +78,12 @@ import static com.njcn.common.pojo.constant.LogInfo.UNKNOWN_USER;
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implements AuditService {
|
public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implements AuditService {
|
||||||
|
|
||||||
private final AuditMapper auditMapper;
|
private final AuditMapper auditMapper;
|
||||||
|
|
||||||
@Value("${spring.datasource.druid.url}")
|
@Value("${spring.datasource.dynamic.datasource.sjzx.url}")
|
||||||
private String urls;
|
private String urls;
|
||||||
|
|
||||||
private final GeneralInfo generalInfo;
|
private final GeneralInfo generalInfo;
|
||||||
@@ -435,8 +437,41 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Float getMemoInfo() {
|
public Float getMemoInfo() {
|
||||||
String schema = urls.substring(urls.lastIndexOf("/") + 1, urls.lastIndexOf("?"));
|
// 1. 判空兜底,防止@Value注入为空/空字符串
|
||||||
return this.baseMapper.getMemoInfo(schema);
|
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
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user