sonarqube质量修复

This commit is contained in:
gaoqr
2025-10-29 15:54:09 +08:00
parent f1ac0bf2a4
commit d679409fbd
27 changed files with 75 additions and 137 deletions
@@ -1,22 +0,0 @@
package com.cf.imes.framework.common.core;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* Key Value 的键值对
*
* @author
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class KeyValue<K, V> implements Serializable {
private K key;
private V value;
}
@@ -1,7 +1,7 @@
package com.cf.imes.framework.common.util.collection;
import cn.hutool.core.collection.CollUtil;
import com.cf.imes.framework.common.core.KeyValue;
import cn.hutool.core.lang.Pair;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
@@ -56,7 +56,7 @@ public class MapUtils {
consumer.accept(value);
}
public static <K, V> Map<K, V> convertMap(List<KeyValue<K, V>> keyValues) {
public static <K, V> Map<K, V> convertMap(List<Pair<K, V>> keyValues) {
Map<K, V> map = Maps.newLinkedHashMapWithExpectedSize(keyValues.size());
keyValues.forEach(keyValue -> map.put(keyValue.getKey(), keyValue.getValue()));
return map;
@@ -131,7 +131,7 @@ public class HttpUtils {
}
// 如果两者非空,则返回
if (StrUtil.isNotEmpty(clientId) && StrUtil.isNotEmpty(clientSecret)) {
if (CharSequenceUtil.isNotEmpty(clientId) && CharSequenceUtil.isNotEmpty(clientSecret)) {
return new String[]{clientId, clientSecret};
}
return null;
@@ -29,7 +29,7 @@ public class ChenfengDataSourceAutoConfiguration {
DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();
// 提取 common.js 的配置路径
String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*";
String commonJsPattern = pattern.replaceAll("\\*", "js/common.js");
String commonJsPattern = pattern.replace("\\*", "js/common.js");
// 创建 DruidAdRemoveFilter Bean
FilterRegistrationBean<DruidAdRemoveFilter> registrationBean = new FilterRegistrationBean<>();
registrationBean.setFilter(new DruidAdRemoveFilter());
@@ -82,7 +82,7 @@ public class ChenfengCacheAutoConfiguration {
}
@Bean
public RedisLockUtil lockUtil(RedisTemplate<String, Object> redisTemplate, RedissonClient client) {
return new RedisLockUtil(redisTemplate, client);
public RedisLockUtil lockUtil(RedisTemplate<String, Object> redisTemplate) {
return new RedisLockUtil(redisTemplate);
}
}
@@ -3,8 +3,6 @@ package com.cf.imes.framework.redis.util;
import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.data.redis.core.RedisTemplate;
import java.util.concurrent.TimeUnit;
@@ -21,42 +19,6 @@ public class RedisLockUtil {
private RedisTemplate redisTemplate;
private RedissonClient redissonClient;
/**
* 加锁
*
* @param key rediskey
* @param timeout 锁的超时时间,传空则按照默认配置
* @param waitTime 等待获取锁的时间,传空则按照默认配置
* @return true拿到锁,反之没有做对应的业务提醒
*/
public boolean redissonLock(String key, Integer waitTime, Integer timeout) {
boolean getLock = false;
try {
RLock rLock = redissonClient.getLock(key);
return rLock.tryLock(waitTime, timeout, TimeUnit.MILLISECONDS);
} catch (Exception e) {
log.error("[RedisLockUtil][lock]加锁失败", e);
return getLock;
}
}
/**
* 解锁
* 使用注意:配合以上redisson的lock只能在当前线程中unlock,否则失败!!!
*
* @param key rediskey
*/
public void redissonReleaseLock(String key) {
try {
RLock rLock = redissonClient.getLock(key);
rLock.unlock();
} catch (Exception e) {
log.error("[RedisLockUtil][unlock]解锁失败", e);
}
}
/**
* 手动set nx ex加锁
* 使用注意:可用于跨服务
@@ -157,6 +157,9 @@ public class SecurityFrameworkUtils {
*/
public static boolean isSuperAdmin() {
LoginUser loginUser = getLoginUser();
if (loginUser == null) {
throw new ServiceException(GlobalErrorCodeConstants.UNAUTHORIZED);
}
return ObjectUtil.isNotNull(loginUser) && loginUser.getIsSupAdmin();
}
@@ -167,6 +170,9 @@ public class SecurityFrameworkUtils {
*/
public static boolean isManageEndPoint() {
LoginUser loginUser = getLoginUser();
if (loginUser == null) {
throw new ServiceException(GlobalErrorCodeConstants.UNAUTHORIZED);
}
return Objects.equals(loginUser.getUserType(), UserTypeEnum.ADMIN.getValue());
}
@@ -186,7 +192,7 @@ public class SecurityFrameworkUtils {
*/
public static Long getProductId() {
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
if (ObjectUtil.isNull(loginUser)) {
if (loginUser == null) {
throw new ServiceException(GlobalErrorCodeConstants.UNAUTHORIZED);
}
return loginUser.getProductId();