refactor(framework): 更新注解和流操作以提高代码质量
This commit is contained in:
+4
-3
@@ -15,10 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package cn.odboy.framework.context;
|
package cn.odboy.framework.context;
|
||||||
|
|
||||||
|
import jakarta.annotation.Nonnull;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.NonNull;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
@@ -136,9 +136,10 @@ public class KitSpringBeanHolder implements ApplicationContextAware, DisposableB
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException {
|
public void setApplicationContext(@Nonnull ApplicationContext applicationContext) throws BeansException {
|
||||||
if (KitSpringBeanHolder.applicationContext != null) {
|
if (KitSpringBeanHolder.applicationContext != null) {
|
||||||
log.warn("SpringContextHolder中的ApplicationContext被覆盖, 原有ApplicationContext为:{}", KitSpringBeanHolder.applicationContext);
|
log.warn("SpringContextHolder中的ApplicationContext被覆盖, 原有ApplicationContext为:{}",
|
||||||
|
KitSpringBeanHolder.applicationContext);
|
||||||
}
|
}
|
||||||
KitSpringBeanHolder.applicationContext = applicationContext;
|
KitSpringBeanHolder.applicationContext = applicationContext;
|
||||||
if (addCallback) {
|
if (addCallback) {
|
||||||
|
|||||||
+1
-1
@@ -180,7 +180,7 @@ public class KitMpQUtil {
|
|||||||
*/
|
*/
|
||||||
private static <R> void handleBlurryQuery(QueryWrapper<R> queryWrapper, String blurry, Object fieldVal) {
|
private static <R> void handleBlurryQuery(QueryWrapper<R> queryWrapper, String blurry, Object fieldVal) {
|
||||||
List<String> blurryList =
|
List<String> blurryList =
|
||||||
Arrays.stream(blurry.split(",")).filter(StrUtil::isNotBlank).distinct().collect(Collectors.toList());
|
Arrays.stream(blurry.split(",")).filter(StrUtil::isNotBlank).distinct().toList();
|
||||||
queryWrapper.and(wrapper -> {
|
queryWrapper.and(wrapper -> {
|
||||||
for (String blurryItem : blurryList) {
|
for (String blurryItem : blurryList) {
|
||||||
String column = StrUtil.toUnderlineCase(blurryItem);
|
String column = StrUtil.toUnderlineCase(blurryItem);
|
||||||
|
|||||||
+3
-3
@@ -16,13 +16,13 @@
|
|||||||
|
|
||||||
package cn.odboy.framework.quartz.config;
|
package cn.odboy.framework.quartz.config;
|
||||||
|
|
||||||
|
import jakarta.annotation.Nonnull;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.quartz.spi.TriggerFiredBundle;
|
import org.quartz.spi.TriggerFiredBundle;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.lang.NonNull;
|
|
||||||
import org.springframework.scheduling.quartz.AdaptableJobFactory;
|
import org.springframework.scheduling.quartz.AdaptableJobFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -47,9 +47,9 @@ public class QuartzConfig {
|
|||||||
this.autowireCapableBeanFactory = autowireCapableBeanFactory;
|
this.autowireCapableBeanFactory = autowireCapableBeanFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
protected Object createJobInstance(@NonNull TriggerFiredBundle triggerFiredBundle) throws Exception {
|
protected Object createJobInstance(@Nonnull TriggerFiredBundle triggerFiredBundle) throws Exception {
|
||||||
try {
|
try {
|
||||||
// 调用父类的方法, 把Job注入Spring中
|
// 调用父类的方法, 把Job注入Spring中
|
||||||
Object jobInstance = super.createJobInstance(triggerFiredBundle);
|
Object jobInstance = super.createJobInstance(triggerFiredBundle);
|
||||||
|
|||||||
+1
-2
@@ -280,8 +280,7 @@ public class KitRedisHelper {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (value instanceof List<?>) {
|
if (value instanceof List<?> list) {
|
||||||
List<?> list = (List<?>) value;
|
|
||||||
// 检查每个元素是否为指定类型
|
// 检查每个元素是否为指定类型
|
||||||
if (list.stream().allMatch(clazz::isInstance)) {
|
if (list.stream().allMatch(clazz::isInstance)) {
|
||||||
return list.stream().map(clazz::cast).collect(Collectors.toList());
|
return list.stream().map(clazz::cast).collect(Collectors.toList());
|
||||||
|
|||||||
+9
-9
@@ -19,7 +19,11 @@ import cn.odboy.framework.properties.AppProperties;
|
|||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.alibaba.fastjson2.JSONFactory;
|
import com.alibaba.fastjson2.JSONFactory;
|
||||||
import com.alibaba.fastjson2.JSONWriter;
|
import com.alibaba.fastjson2.JSONWriter;
|
||||||
import lombok.NonNull;
|
import jakarta.annotation.Nonnull;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.codec.digest.MurmurHash3;
|
import org.apache.commons.codec.digest.MurmurHash3;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -40,10 +44,6 @@ import org.springframework.data.redis.serializer.RedisSerializationContext;
|
|||||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||||
import org.springframework.data.redis.serializer.SerializationException;
|
import org.springframework.data.redis.serializer.SerializationException;
|
||||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Configuration
|
@Configuration
|
||||||
@@ -127,25 +127,25 @@ public class RedisConfiguration {
|
|||||||
public CacheErrorHandler errorHandler() {
|
public CacheErrorHandler errorHandler() {
|
||||||
return new SimpleCacheErrorHandler() {
|
return new SimpleCacheErrorHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void handleCacheGetError(@NonNull RuntimeException exception, @NonNull Cache cache, @NonNull Object key) {
|
public void handleCacheGetError(@Nonnull RuntimeException exception, @Nonnull Cache cache, @Nonnull Object key) {
|
||||||
// 处理缓存读取错误
|
// 处理缓存读取错误
|
||||||
log.error("Cache Get Error: {}", exception.getMessage());
|
log.error("Cache Get Error: {}", exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCachePutError(@NonNull RuntimeException exception, @NonNull Cache cache, @NonNull Object key, Object value) {
|
public void handleCachePutError(@Nonnull RuntimeException exception, @Nonnull Cache cache, @Nonnull Object key, Object value) {
|
||||||
// 处理缓存写入错误
|
// 处理缓存写入错误
|
||||||
log.error("Cache Put Error: {}", exception.getMessage());
|
log.error("Cache Put Error: {}", exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCacheEvictError(@NonNull RuntimeException exception, @NonNull Cache cache, @NonNull Object key) {
|
public void handleCacheEvictError(@Nonnull RuntimeException exception, @Nonnull Cache cache, @Nonnull Object key) {
|
||||||
// 处理缓存删除错误
|
// 处理缓存删除错误
|
||||||
log.error("Cache Evict Error: {}", exception.getMessage());
|
log.error("Cache Evict Error: {}", exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCacheClearError(@NonNull RuntimeException exception, @NonNull Cache cache) {
|
public void handleCacheClearError(@Nonnull RuntimeException exception, @Nonnull Cache cache) {
|
||||||
// 处理缓存清除错误
|
// 处理缓存清除错误
|
||||||
log.error("Cache Clear Error: {}", exception.getMessage());
|
log.error("Cache Clear Error: {}", exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ public final class KitListUtil {
|
|||||||
*/
|
*/
|
||||||
public static <T, K> List<T> distinctByArgs(List<T> items, Function<? super T, ? extends K> classifier) {
|
public static <T, K> List<T> distinctByArgs(List<T> items, Function<? super T, ? extends K> classifier) {
|
||||||
return items.stream().collect(Collectors.groupingBy(classifier)).values().stream()
|
return items.stream().collect(Collectors.groupingBy(classifier)).values().stream()
|
||||||
.map(monitorItem -> monitorItem.iterator().next()).collect(Collectors.toList());
|
.map(List::getFirst).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+2
-2
@@ -208,7 +208,7 @@ public class SystemDeptService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 编辑部门时不显示自己以及自己下级的数据, 避免出现PID数据环形问题
|
// 编辑部门时不显示自己以及自己下级的数据, 避免出现PID数据环形问题
|
||||||
depts = depts.stream().filter(i -> !ids.contains(i.getId())).collect(Collectors.toList());
|
depts = depts.stream().filter(i -> !ids.contains(i.getId())).toList();
|
||||||
}
|
}
|
||||||
deptSet1.addAll(depts);
|
deptSet1.addAll(depts);
|
||||||
}
|
}
|
||||||
@@ -216,7 +216,7 @@ public class SystemDeptService {
|
|||||||
// 构建部门树
|
// 构建部门树
|
||||||
Set<SystemDeptVo> trees = new LinkedHashSet<>();
|
Set<SystemDeptVo> trees = new LinkedHashSet<>();
|
||||||
Set<SystemDeptVo> deptSet = new LinkedHashSet<>();
|
Set<SystemDeptVo> deptSet = new LinkedHashSet<>();
|
||||||
List<String> deptNames = deptList.stream().map(SystemDeptTb::getName).collect(Collectors.toList());
|
List<String> deptNames = deptList.stream().map(SystemDeptTb::getName).toList();
|
||||||
|
|
||||||
boolean isChild;
|
boolean isChild;
|
||||||
List<SystemDeptVo> systemDeptVos = KitBeanUtil.copyToList(deptList, SystemDeptVo.class);
|
List<SystemDeptVo> systemDeptVos = KitBeanUtil.copyToList(deptList, SystemDeptVo.class);
|
||||||
|
|||||||
@@ -57,9 +57,7 @@ spring:
|
|||||||
db-type: com.alibaba.druid.pool.DruidDataSource
|
db-type: com.alibaba.druid.pool.DruidDataSource
|
||||||
# sql监控
|
# sql监控
|
||||||
driverClassName: com.p6spy.engine.spy.P6SpyDriver
|
driverClassName: com.p6spy.engine.spy.P6SpyDriver
|
||||||
url: jdbc:p6spy:mysql://127.0.0.1:3306/cutejava?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
|
url: jdbc:p6spy:mysql://127.0.0.1:3306/cutejava?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&rewriteBatchedStatements=true
|
||||||
# driverClassName: com.mysql.cj.jdbc.Driver
|
|
||||||
# url: jdbc:mysql://127.0.0.1:3306/cutejava?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
|
|
||||||
username: root
|
username: root
|
||||||
password: kd123456
|
password: kd123456
|
||||||
# 初始连接数,建议设置为与最小空闲连接数相同
|
# 初始连接数,建议设置为与最小空闲连接数相同
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ spring:
|
|||||||
db-type: com.alibaba.druid.pool.DruidDataSource
|
db-type: com.alibaba.druid.pool.DruidDataSource
|
||||||
# sql监控
|
# sql监控
|
||||||
driverClassName: com.mysql.cj.jdbc.Driver
|
driverClassName: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://127.0.0.1:23306/cutejava?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
|
url: jdbc:mysql://127.0.0.1:23306/cutejava?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&rewriteBatchedStatements=true
|
||||||
username: root
|
username: root
|
||||||
password: kd123456
|
password: kd123456
|
||||||
# 初始连接数,建议设置为与最小空闲连接数相同
|
# 初始连接数,建议设置为与最小空闲连接数相同
|
||||||
|
|||||||
Reference in New Issue
Block a user