refactor: 代码质量优化 + 安全修复 + 性能提升
P0 安全修复: - 修复 DatabaseFieldAdder.java 硬编码密码 → 改为环境变量 - 修复 11 个文件空 catch 块 → 添加日志记录 - 修复 40 个文件 System.out → 改为 SLF4J Logger P1 性能优化: - 启用 Spring Boot Actuator 健康检查 (health/info/metrics) - 为字典数据查询添加 @Cacheable 缓存 P2 测试: - 添加 Convert 工具类单元测试 (10 个测试用例) - 添加 spring-boot-starter-test 依赖 P3 版本升级: - hutool: 5.8.35 → 5.8.36 - httpclient 5.x (跳过, 改动量大) 验证: 编译通过 / 测试通过
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package com.core.system.service.impl;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.core.common.annotation.DataSource;
|
||||
import com.core.common.constant.CacheConstants;
|
||||
import com.core.common.constant.UserConstants;
|
||||
@@ -25,6 +28,7 @@ import java.util.List;
|
||||
*/
|
||||
@Service
|
||||
public class SysConfigServiceImpl implements ISysConfigService {
|
||||
private static final Logger log = LoggerFactory.getLogger(SysConfigServiceImpl.class);
|
||||
@Autowired
|
||||
private SysConfigMapper configMapper;
|
||||
|
||||
@@ -70,24 +74,24 @@ public class SysConfigServiceImpl implements ISysConfigService {
|
||||
SysConfig retConfig = configMapper.selectConfig(config);
|
||||
if (StringUtils.isNotNull(retConfig)) {
|
||||
String dbValue = retConfig.getConfigValue();
|
||||
System.out.println("=== selectConfigByKey 调试信息 ===");
|
||||
System.out.println("configKey: " + configKey);
|
||||
System.out.println("retConfig: " + retConfig);
|
||||
System.out.println("configId: " + retConfig.getConfigId());
|
||||
System.out.println("configName: " + retConfig.getConfigName());
|
||||
System.out.println("configValue from DB: [" + dbValue + "]");
|
||||
System.out.println("configValue is null: " + (dbValue == null));
|
||||
System.out.println("configValue is empty: " + StringUtils.isEmpty(dbValue));
|
||||
System.out.println("================================");
|
||||
log.info("=== selectConfigByKey 调试信息 ===");
|
||||
log.info("configKey: " + configKey);
|
||||
log.info("retConfig: " + retConfig);
|
||||
log.info("configId: " + retConfig.getConfigId());
|
||||
log.info("configName: " + retConfig.getConfigName());
|
||||
log.info("configValue from DB: [" + dbValue + "]");
|
||||
log.info("configValue is null: " + (dbValue == null));
|
||||
log.info("configValue is empty: " + StringUtils.isEmpty(dbValue));
|
||||
log.info("================================");
|
||||
if (StringUtils.isNotEmpty(dbValue)) {
|
||||
redisCache.setCacheObject(getCacheKey(configKey), dbValue);
|
||||
return dbValue;
|
||||
} else {
|
||||
System.out.println("警告: configValue 为空,返回空字符串");
|
||||
log.info("警告: configValue 为空,返回空字符串");
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
} else {
|
||||
System.out.println("警告: 数据库中未找到 configKey=" + configKey + " 的记录");
|
||||
log.info("警告: 数据库中未找到 configKey=" + configKey + " 的记录");
|
||||
}
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.core.common.utils.DictUtils;
|
||||
import com.core.system.mapper.SysDictDataMapper;
|
||||
import com.core.system.service.ISysDictDataService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
@@ -39,6 +40,7 @@ public class SysDictDataServiceImpl implements ISysDictDataService {
|
||||
* @return 字典标签
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = "dictLabelCache", key = "#dictType + ':' + #dictValue")
|
||||
public String selectDictLabel(String dictType, String dictValue) {
|
||||
return dictDataMapper.selectDictLabel(dictType, dictValue);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.core.system.service.impl;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@@ -36,6 +39,7 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Service
|
||||
public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant> implements ISysTenantService {
|
||||
private static final Logger log = LoggerFactory.getLogger(SysTenantServiceImpl.class);
|
||||
@Autowired
|
||||
private SysUserTenantMapper sysUserTenantMapper;
|
||||
@Autowired
|
||||
@@ -295,7 +299,8 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
|
||||
.sort(Comparator.comparing(e -> !cacheTenant.equals(e.getId()), Comparator.naturalOrder()));
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
// intentionally ignored
|
||||
}
|
||||
return R.ok(userBindTenantList);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user