refactor(framework): 更新注解和流操作以提高代码质量

This commit is contained in:
2026-02-27 16:08:41 +08:00
parent dc3fb8fdfc
commit 1b1bb10089
10 changed files with 124 additions and 126 deletions
+101 -101
View File
@@ -1,101 +1,101 @@
# cutejava-ui
## 前端模板
初始模板基于: [https://github.com/PanJiaChen/vue-element-admin](https://github.com/PanJiaChen/vue-element-admin)
模板文档: [https://panjiachen.github.io/vue-element-admin-site/zh/guide/](https://panjiachen.github.io/vue-element-admin-site/zh/guide/)
## 快速开始
#### 环境要求
**推荐 node 版本:16**
#### 安装依赖
``` bash
# 安装依赖(依赖python)
npm install --registry https://registry.npmmirror.com
```
#### 启动服务
```bash
# 启动服务 localhost:8013
npm run dev
# (或) 启动服务 localhost:8013
IDEA -> Current File -> Edit Configurations... -> Add New Configuration -> npm -> Script选dev -> Apply -> Ok
# 构建生产环境
npm run build:prod
# 本地预览生产环境
npm run preview
```
## 命令说明
#### 开发相关
```shell
# 启动本地开发服务器,默认端口 8013,支持热重载
npm run dev
# Windows 系统启动开发服务器,设置 OpenSSL 兼容性选项
npm run dev-win
# Linux 系统启动开发服务器,设置 OpenSSL 兼容性选项
npm run dev-linux
```
#### 构建相关
```shell
# 构建开发环境版本,输出到 dist 目录
npm run build:dev
# 构建预发布环境版本,输出到 dist 目录
npm run build:stage
# 构建生产环境版本,输出到 dist 目录
npm run build:prod
# 构建生产环境版本(无特定模式)
npm run build:production
```
#### 辅助命令
```shell
# 预览构建后的静态文件,启动本地服务器查看构建结果
npm run preview
# 检查 src 目录下 .js 和 .vue 文件的代码规范
npm run lint
# 运行单元测试,先清除缓存再执行测试
npm run test:unit
# 优化 src/assets/icons/svg 目录下的 SVG 文件
npm run svgo
# 使用 plop 创建新文件模板
npm run new
```
## 常见问题
1、linux 系统在安装依赖的时候会出现 node-sass 无法安装的问题
解决方案:
```
1. 单独安装:npm install --unsafe-perm node-sass
2. 直接使用:npm install --unsafe-perm
```
2、加速node-sass安装
https://www.ydyno.com/archives/1219.html
# cutejava-ui
## 前端模板
初始模板基于: [https://github.com/PanJiaChen/vue-element-admin](https://github.com/PanJiaChen/vue-element-admin)
模板文档: [https://panjiachen.github.io/vue-element-admin-site/zh/guide/](https://panjiachen.github.io/vue-element-admin-site/zh/guide/)
## 快速开始
#### 环境要求
**推荐 node 版本:16**
#### 安装依赖
``` bash
# 安装依赖(依赖python)
npm install --registry https://registry.npmmirror.com
```
#### 启动服务
```bash
# 启动服务 localhost:8013
npm run dev
# (或) 启动服务 localhost:8013
IDEA -> Current File -> Edit Configurations... -> Add New Configuration -> npm -> Script选dev -> Apply -> Ok
# 构建生产环境
npm run build:prod
# 本地预览生产环境
npm run preview
```
## 命令说明
#### 开发相关
```shell
# 启动本地开发服务器,默认端口 8013,支持热重载
npm run dev
# Windows 系统启动开发服务器,设置 OpenSSL 兼容性选项
npm run dev-win
# Linux 系统启动开发服务器,设置 OpenSSL 兼容性选项
npm run dev-linux
```
#### 构建相关
```shell
# 构建开发环境版本,输出到 dist 目录
npm run build:dev
# 构建预发布环境版本,输出到 dist 目录
npm run build:stage
# 构建生产环境版本,输出到 dist 目录
npm run build:prod
# 构建生产环境版本(无特定模式)
npm run build:production
```
#### 辅助命令
```shell
# 预览构建后的静态文件,启动本地服务器查看构建结果
npm run preview
# 检查 src 目录下 .js 和 .vue 文件的代码规范
npm run lint
# 运行单元测试,先清除缓存再执行测试
npm run test:unit
# 优化 src/assets/icons/svg 目录下的 SVG 文件
npm run svgo
# 使用 plop 创建新文件模板
npm run new
```
## 常见问题
1、linux 系统在安装依赖的时候会出现 node-sass 无法安装的问题
解决方案:
```
1. 单独安装:npm install --unsafe-perm node-sass
2. 直接使用:npm install --unsafe-perm
```
2、加速node-sass安装
https://www.ydyno.com/archives/1219.html
@@ -15,10 +15,10 @@
*/
package cn.odboy.framework.context;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
@@ -136,9 +136,10 @@ public class KitSpringBeanHolder implements ApplicationContextAware, DisposableB
}
@Override
public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException {
public void setApplicationContext(@Nonnull ApplicationContext applicationContext) throws BeansException {
if (KitSpringBeanHolder.applicationContext != null) {
log.warn("SpringContextHolder中的ApplicationContext被覆盖, 原有ApplicationContext为:{}", KitSpringBeanHolder.applicationContext);
log.warn("SpringContextHolder中的ApplicationContext被覆盖, 原有ApplicationContext为:{}",
KitSpringBeanHolder.applicationContext);
}
KitSpringBeanHolder.applicationContext = applicationContext;
if (addCallback) {
@@ -180,7 +180,7 @@ public class KitMpQUtil {
*/
private static <R> void handleBlurryQuery(QueryWrapper<R> queryWrapper, String blurry, Object fieldVal) {
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 -> {
for (String blurryItem : blurryList) {
String column = StrUtil.toUnderlineCase(blurryItem);
@@ -16,13 +16,13 @@
package cn.odboy.framework.quartz.config;
import jakarta.annotation.Nonnull;
import lombok.extern.slf4j.Slf4j;
import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.lang.NonNull;
import org.springframework.scheduling.quartz.AdaptableJobFactory;
import org.springframework.stereotype.Component;
@@ -47,9 +47,9 @@ public class QuartzConfig {
this.autowireCapableBeanFactory = autowireCapableBeanFactory;
}
@NonNull
@Nonnull
@Override
protected Object createJobInstance(@NonNull TriggerFiredBundle triggerFiredBundle) throws Exception {
protected Object createJobInstance(@Nonnull TriggerFiredBundle triggerFiredBundle) throws Exception {
try {
// 调用父类的方法, 把Job注入Spring中
Object jobInstance = super.createJobInstance(triggerFiredBundle);
@@ -280,8 +280,7 @@ public class KitRedisHelper {
if (value == null) {
return null;
}
if (value instanceof List<?>) {
List<?> list = (List<?>) value;
if (value instanceof List<?> list) {
// 检查每个元素是否为指定类型
if (list.stream().allMatch(clazz::isInstance)) {
return list.stream().map(clazz::cast).collect(Collectors.toList());
@@ -19,7 +19,11 @@ import cn.odboy.framework.properties.AppProperties;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONFactory;
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 org.apache.commons.codec.digest.MurmurHash3;
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.SerializationException;
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
@Configuration
@@ -127,25 +127,25 @@ public class RedisConfiguration {
public CacheErrorHandler errorHandler() {
return new SimpleCacheErrorHandler() {
@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());
}
@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());
}
@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());
}
@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());
}
@@ -40,7 +40,7 @@ public final class KitListUtil {
*/
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()
.map(monitorItem -> monitorItem.iterator().next()).collect(Collectors.toList());
.map(List::getFirst).collect(Collectors.toList());
}
/**
@@ -208,7 +208,7 @@ public class SystemDeptService {
}
}
// 编辑部门时不显示自己以及自己下级的数据, 避免出现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);
}
@@ -216,7 +216,7 @@ public class SystemDeptService {
// 构建部门树
Set<SystemDeptVo> trees = 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;
List<SystemDeptVo> systemDeptVos = KitBeanUtil.copyToList(deptList, SystemDeptVo.class);
@@ -57,9 +57,7 @@ spring:
db-type: com.alibaba.druid.pool.DruidDataSource
# sql监控
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
# driverClassName: com.mysql.cj.jdbc.Driver
# url: jdbc: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
username: root
password: kd123456
# 初始连接数,建议设置为与最小空闲连接数相同
@@ -68,7 +68,7 @@ spring:
db-type: com.alibaba.druid.pool.DruidDataSource
# sql监控
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
password: kd123456
# 初始连接数,建议设置为与最小空闲连接数相同