refactor(util): 移除废弃类并优化验证工具类

- 删除 TaskTemplateInfoVo 类
- 删除 ServerException 类
- 删除 KitDistributedIdUtil 类
- 删除 SystemQuartzJobVo 类
- 在 KitBigDecimalUtil 中新增格式化金额方法
- 在 KitDateUtil 中新增获取周几方法
- 在 KitCollUtil 中修复空集合验证逻辑
- 移除 KitStringUtil 中的日期相关代码
- 在 KitValidUtil 中新增多种验证方法
- 修改 SystemMenuController 中的菜单保存逻辑
- 优化 SystemQuartzJobController 中的定时任务操作方法
- 为 SystemQuartzJobTb 添加扩展字段 uuid
This commit is contained in:
2026-01-24 09:50:13 +08:00
parent 9b61ab35b6
commit eb2d0e02a8
129 changed files with 1757 additions and 1077 deletions
@@ -13,13 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.framework.exception;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import lombok.Getter;
import org.springframework.http.HttpStatus;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
/**
* 统一异常处理
@@ -13,13 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.framework.exception;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
import lombok.Getter;
import org.springframework.http.HttpStatus;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
@Getter
public class ServerException extends RuntimeException {
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.framework.exception.handler;
import lombok.Data;
@@ -42,5 +41,3 @@ public final class ApiError {
return apiError;
}
}
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.framework.exception.handler;
import cn.hutool.core.exceptions.ExceptionUtil;
@@ -77,8 +76,8 @@ public class GlobalExceptionHandler {
log.error(ExceptionUtil.stacktraceToString(e));
ObjectError objectError = e.getBindingResult().getAllErrors().get(0);
String message = objectError.getDefaultMessage();
if (objectError instanceof FieldError fieldError) {
message = fieldError.getField() + ": " + message;
if (objectError instanceof FieldError) {
message = ((FieldError) objectError).getField() + ": " + message;
}
return buildResponseEntity(ApiError.error(message));
}
@@ -0,0 +1,52 @@
/*
* Copyright 2021-2026 Odboy
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.framework.properties;
import cn.odboy.framework.properties.model.CaptchaModel;
import cn.odboy.framework.properties.model.ContentRsaEncodeSettingModel;
import cn.odboy.framework.properties.model.JwtAuthSettingModel;
import cn.odboy.framework.properties.model.StorageOSSModel;
import cn.odboy.framework.properties.model.SwaggerApiDocSettingModel;
import cn.odboy.framework.properties.model.ThreadPoolSettingModel;
import cn.odboy.framework.properties.model.UserLoginSettingModel;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 应用配置
*
* @author odboy
* @date 2025-04-13
*/
@Data
@Component
@ConfigurationProperties(prefix = "app")
public class AppProperties {
private ContentRsaEncodeSettingModel rsa;
private JwtAuthSettingModel jwt;
private UserLoginSettingModel login;
private SwaggerApiDocSettingModel swagger;
private ThreadPoolSettingModel asyncTaskPool;
private CaptchaModel captcha;
private StorageOSSModel oss;
/**
* 自动识别json对象白名单配置(仅允许解析的包名, 范围越小越安全)<br/> 未配置可能导致, 登录失败, 反复登录等问题
*/
private List<String> serialWhiteList;
}
@@ -0,0 +1,30 @@
/*
* Copyright 2021-2026 Odboy
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.framework.properties.model;
import cn.odboy.base.KitObject;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class CaptchaModel extends KitObject {
/**
* 验证码有效时间, 单位: 秒
*/
private Long expireTime;
}
@@ -0,0 +1,30 @@
/*
* Copyright 2021-2026 Odboy
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.framework.properties.model;
import cn.odboy.base.KitObject;
import lombok.Getter;
import lombok.Setter;
/**
* 密码加密传输, 前端公钥加密,后端私钥解密
*/
@Getter
@Setter
public class ContentRsaEncodeSettingModel extends KitObject {
private String privateKey;
}
@@ -0,0 +1,45 @@
/*
* Copyright 2021-2026 Odboy
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.framework.properties.model;
import cn.odboy.base.KitObject;
import lombok.Getter;
import lombok.Setter;
/**
* Jwt参数配置
*/
@Getter
@Setter
public class JwtAuthSettingModel extends KitObject {
/**
* 必须使用最少88位的Base64对该令牌进行编码
*/
private String base64Secret;
/**
* 令牌过期时间 此处单位/毫秒
*/
private Long tokenValidityInSeconds;
/**
* token 续期检查
*/
private Long detect;
/**
* 续期时间
*/
private Long renew;
}
@@ -0,0 +1,42 @@
/*
* Copyright 2021-2026 Odboy
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.framework.properties.model;
import cn.odboy.base.KitObject;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class OSSConfigModel extends KitObject {
/**
* 服务地址
*/
private String endpoint;
/**
* 存储桶名称
*/
private String bucketName;
/**
* Access Key
*/
private String accessKey;
/**
* Secret Key
*/
private String secretKey;
}
@@ -0,0 +1,30 @@
/*
* Copyright 2021-2026 Odboy
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.framework.properties.model;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class StorageOSSModel {
/**
* 上传大小, 单位: M
*/
private Long maxSize;
private OSSConfigModel minio;
}
@@ -0,0 +1,31 @@
/*
* Copyright 2021-2026 Odboy
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.framework.properties.model;
import cn.odboy.base.KitObject;
import lombok.Getter;
import lombok.Setter;
/**
* @author odboy
* @date 2025-04-13
*/
@Getter
@Setter
public class SwaggerApiDocSettingModel extends KitObject {
private Boolean enabled;
}
@@ -0,0 +1,48 @@
/*
* Copyright 2021-2026 Odboy
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.framework.properties.model;
import cn.odboy.base.KitObject;
import lombok.Getter;
import lombok.Setter;
/**
* 线程池 配置
*
* @author odboy
* @date 2025-04-13
*/
@Getter
@Setter
public class ThreadPoolSettingModel extends KitObject {
/**
* 核心线程池大小
*/
private int corePoolSize;
/**
* 最大线程数
*/
private int maxPoolSize;
/**
* 活跃时间
*/
private int keepAliveSeconds;
/**
* 队列容量
*/
private int queueCapacity;
}
@@ -0,0 +1,126 @@
/*
* Copyright 2021-2026 Odboy
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.framework.properties.model;
import cn.hutool.core.util.StrUtil;
import cn.odboy.base.KitObject;
import cn.odboy.constant.CaptchaCodeEnum;
import cn.odboy.framework.exception.BadRequestException;
import com.wf.captcha.ArithmeticCaptcha;
import com.wf.captcha.ChineseCaptcha;
import com.wf.captcha.ChineseGifCaptcha;
import com.wf.captcha.GifCaptcha;
import com.wf.captcha.SpecCaptcha;
import com.wf.captcha.base.Captcha;
import lombok.Getter;
import lombok.Setter;
import java.awt.*;
/**
* 验证码配置
*
* @author odboy
*/
@Getter
@Setter
public class UserLoginCaptchaSettingModel extends KitObject {
private CaptchaCodeEnum codeType;
/**
* 验证码有效期 分钟
*/
private Long expiration = 5L;
/**
* 验证码内容长度
*/
private int length = 4;
/**
* 验证码宽度
*/
private int width = 111;
/**
* 验证码高度
*/
private int height = 36;
/**
* 验证码字体
*/
private String fontName;
/**
* 字体大小
*/
private int fontSize = 25;
/**
* 依据配置信息生产验证码
*
* @return /
*/
public Captcha getCaptcha() {
Captcha captcha;
switch (codeType) {
case ARITHMETIC:
// 算术类型 https://gitee.com/whvse/EasyCaptcha
captcha = new FixedArithmeticCaptcha(width, height);
// 几位数运算, 默认是两位
captcha.setLen(length);
break;
case CHINESE:
captcha = new ChineseCaptcha(width, height);
captcha.setLen(length);
break;
case CHINESE_GIF:
captcha = new ChineseGifCaptcha(width, height);
captcha.setLen(length);
break;
case GIF:
captcha = new GifCaptcha(width, height);
captcha.setLen(length);
break;
case SPEC:
captcha = new SpecCaptcha(width, height);
captcha.setLen(length);
break;
default:
throw new BadRequestException("验证码配置信息错误!正确配置查看 LoginCodeEnum ");
}
if (StrUtil.isNotBlank(fontName)) {
captcha.setFont(new Font(fontName, Font.PLAIN, fontSize));
}
return captcha;
}
static class FixedArithmeticCaptcha extends ArithmeticCaptcha {
public FixedArithmeticCaptcha(int width, int height) {
super(width, height);
}
@Override
protected char[] alphas() {
// 生成随机数字和运算符
int n1 = num(1, 10), n2 = num(1, 10);
int opt = num(3);
// 计算结果
int res = new int[]{n1 + n2, n1 - n2, n1 * n2}[opt];
// 转换为字符运算符
char optChar = "+-x".charAt(opt);
this.setArithmeticString(String.format("%s%c%s=?", n1, optChar, n2));
this.chars = String.valueOf(res);
return chars.toCharArray();
}
}
}
@@ -0,0 +1,36 @@
/*
* Copyright 2021-2026 Odboy
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.framework.properties.model;
import cn.odboy.base.KitObject;
import lombok.Getter;
import lombok.Setter;
/**
* 登录配置
*
* @author odboy
*/
@Getter
@Setter
public class UserLoginSettingModel extends KitObject {
/**
* 账号单用户 登录
*/
private boolean single = false;
private UserLoginCaptchaSettingModel captchaSetting;
}
@@ -17,6 +17,14 @@ package cn.odboy.util;
import cn.odboy.annotation.AnonymousAccess;
import cn.odboy.constant.RequestMethodEnum;
import lombok.experimental.UtilityClass;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.condition.PathPatternsRequestCondition;
import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -24,13 +32,6 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import lombok.experimental.UtilityClass;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
/**
* 匿名标记工具
@@ -45,10 +46,9 @@ public class KitAnonTagUtil {
* @return /
*/
public static Map<String, Set<String>> getAnonymousUrl(final ApplicationContext applicationContext) {
RequestMappingHandlerMapping requestMappingHandlerMapping =
(RequestMappingHandlerMapping) applicationContext.getBean("requestMappingHandlerMapping");
RequestMappingHandlerMapping requestMappingHandlerMapping = (RequestMappingHandlerMapping) applicationContext.getBean("requestMappingHandlerMapping");
Map<RequestMappingInfo, HandlerMethod> handlerMethodMap = requestMappingHandlerMapping.getHandlerMethods();
Map<String, java.util.Set<String>> anonymousUrls = new HashMap<>(8);
Map<String, Set<String>> anonymousUrls = new HashMap<>(8);
// 获取匿名标记
Set<String> get = new HashSet<>();
Set<String> post = new HashSet<>();
@@ -60,30 +60,28 @@ public class KitAnonTagUtil {
HandlerMethod handlerMethod = infoEntry.getValue();
AnonymousAccess anonymousAccess = handlerMethod.getMethodAnnotation(AnonymousAccess.class);
if (null != anonymousAccess && infoEntry.getKey() != null) {
List<RequestMethod> requestMethods =
new ArrayList<>(infoEntry.getKey().getMethodsCondition().getMethods());
RequestMethodEnum request = RequestMethodEnum.find(
requestMethods.isEmpty() ? RequestMethodEnum.ALL.getType() : requestMethods.get(0).name());
PatternsRequestCondition patternsCondition = infoEntry.getKey().getPatternsCondition();
List<RequestMethod> requestMethods = new ArrayList<>(infoEntry.getKey().getMethodsCondition().getMethods());
RequestMethodEnum request = RequestMethodEnum.find(requestMethods.isEmpty() ? RequestMethodEnum.ALL.getType() : requestMethods.get(0).name());
PathPatternsRequestCondition patternsCondition = infoEntry.getKey().getPathPatternsCondition();
if (patternsCondition != null) {
switch (Objects.requireNonNull(request)) {
case GET:
get.addAll(patternsCondition.getPatterns());
get.addAll(patternsCondition.getPatternValues());
break;
case POST:
post.addAll(patternsCondition.getPatterns());
post.addAll(patternsCondition.getPatternValues());
break;
case PUT:
put.addAll(patternsCondition.getPatterns());
put.addAll(patternsCondition.getPatternValues());
break;
case PATCH:
patch.addAll(patternsCondition.getPatterns());
patch.addAll(patternsCondition.getPatternValues());
break;
case DELETE:
delete.addAll(patternsCondition.getPatterns());
delete.addAll(patternsCondition.getPatternValues());
break;
default:
all.addAll(patternsCondition.getPatterns());
all.addAll(patternsCondition.getPatternValues());
break;
}
}
@@ -17,8 +17,8 @@ package cn.odboy.util;
import cn.hutool.core.codec.Base64Encoder;
import cn.hutool.core.util.IdUtil;
import java.nio.charset.StandardCharsets;
import lombok.experimental.UtilityClass;
import java.nio.charset.StandardCharsets;
/**
* 加密令牌生成工具
@@ -17,10 +17,10 @@ package cn.odboy.util;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import lombok.experimental.UtilityClass;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import lombok.experimental.UtilityClass;
/**
* Bean拷贝相关
@@ -15,9 +15,10 @@
*/
package cn.odboy.util;
import lombok.experimental.UtilityClass;
import java.math.BigDecimal;
import java.math.RoundingMode;
import lombok.experimental.UtilityClass;
import java.text.NumberFormat;
/**
* 计算类
@@ -133,6 +134,23 @@ public final class KitBigDecimalUtil {
return yuan.multiply(BigDecimal.valueOf(100)).setScale(0, RoundingMode.HALF_UP).longValue();
}
/**
* 格式化为 xxx,xxx,xxx 格式
*
* @param obj 金额
* @return /
*/
public static String formatGroupingAmount(Object obj) {
if (obj == null) {
return "0";
}
BigDecimal bigDecimal = toBigDecimal(obj);
NumberFormat nf = NumberFormat.getInstance();
// 启用千位分隔符
nf.setGroupingUsed(true);
return nf.format(bigDecimal.setScale(0, RoundingMode.HALF_UP));
}
public static void main(String[] args) {
BigDecimal num1 = new BigDecimal("10.123");
BigDecimal num2 = new BigDecimal("2.456");
@@ -17,11 +17,11 @@ package cn.odboy.util;
import cn.hutool.http.useragent.UserAgent;
import cn.hutool.http.useragent.UserAgentUtil;
import java.net.InetAddress;
import java.net.UnknownHostException;
import jakarta.servlet.http.HttpServletRequest;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import jakarta.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.UnknownHostException;
/**
* 浏览器 相关
@@ -15,10 +15,10 @@
*/
package cn.odboy.util;
import lombok.experimental.UtilityClass;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import lombok.experimental.UtilityClass;
/**
* 类 相关
@@ -15,8 +15,8 @@
*/
package cn.odboy.util;
import java.io.Closeable;
import lombok.experimental.UtilityClass;
import java.io.Closeable;
/**
* 用于关闭各种连接, 缺啥补啥
@@ -15,10 +15,9 @@
*/
package cn.odboy.util;
import cn.hutool.core.collection.CollUtil;
import cn.odboy.base.KitSelectOptionVo;
import cn.odboy.framework.exception.BadRequestException;
import com.alibaba.fastjson2.JSON;
import lombok.experimental.UtilityClass;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.math.RoundingMode;
@@ -31,7 +30,6 @@ import java.util.Objects;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import lombok.experimental.UtilityClass;
/**
* 集合工具
@@ -194,7 +192,7 @@ public final class KitCollUtil extends cn.hutool.core.collection.CollUtil {
* @return /
*/
public static BigDecimal streamBigDecimalAvg(List<BigDecimal> data) {
KitValidUtil.notEmpty(data, "data");
KitValidUtil.isEmpty(data, "data");
return data.stream().filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)
.divide(BigDecimal.valueOf(data.size()), 6, RoundingMode.FLOOR);
}
@@ -17,8 +17,9 @@ package cn.odboy.util;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import java.util.Date;
import lombok.experimental.UtilityClass;
import java.util.Calendar;
import java.util.Date;
/**
* 时间相关工具
@@ -129,4 +130,22 @@ public class KitDateUtil {
}
return result.toString();
}
/**
* 获得当天是周几
*/
public static String getWeekDay() {
String[] weekDays = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0) {
w = 0;
}
return weekDays[w];
}
public static void main(String[] args) {
System.err.println(getWeekDay());
}
}
@@ -15,13 +15,13 @@
*/
package cn.odboy.util;
import java.nio.charset.StandardCharsets;
import lombok.experimental.UtilityClass;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
import lombok.experimental.UtilityClass;
import java.nio.charset.StandardCharsets;
/**
* DES加密
@@ -15,11 +15,6 @@
*/
package cn.odboy.util;
import static cn.odboy.constant.SystemConst.SYMBOL_ADD;
import static cn.odboy.constant.SystemConst.SYMBOL_AT;
import static cn.odboy.constant.SystemConst.SYMBOL_EQUAL;
import static cn.odboy.constant.SystemConst.SYMBOL_SUBTRACT;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.IdUtil;
@@ -29,6 +24,11 @@ import cn.hutool.poi.excel.ExcelUtil;
import cn.odboy.constant.FileTypeEnum;
import cn.odboy.constant.SystemConst;
import cn.odboy.framework.exception.BadRequestException;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.springframework.web.multipart.MultipartFile;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@@ -46,11 +46,10 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.springframework.web.multipart.MultipartFile;
import static cn.odboy.constant.SystemConst.SYMBOL_ADD;
import static cn.odboy.constant.SystemConst.SYMBOL_AT;
import static cn.odboy.constant.SystemConst.SYMBOL_EQUAL;
import static cn.odboy.constant.SystemConst.SYMBOL_SUBTRACT;
/**
* File工具类, 扩展 hutool 工具包
@@ -16,12 +16,12 @@
package cn.odboy.util;
import cn.odboy.framework.context.KitSpringBeanHolder;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
import lombok.experimental.UtilityClass;
import net.dreamlu.mica.ip2region.core.Ip2regionSearcher;
import net.dreamlu.mica.ip2region.core.IpInfo;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
/**
* IP地址 相关
@@ -17,9 +17,9 @@ package cn.odboy.util;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.TypeReference;
import lombok.experimental.UtilityClass;
import java.util.List;
import java.util.Map;
import lombok.experimental.UtilityClass;
/**
* Json工具
@@ -17,11 +17,11 @@ package cn.odboy.util;
import cn.hutool.core.date.DateTime;
import cn.odboy.base.KitBaseUserTimeTb;
import lombok.experimental.UtilityClass;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.experimental.UtilityClass;
/**
* List 工具
@@ -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(List::getFirst).collect(Collectors.toList());
.map(monitorItem -> monitorItem.iterator().next()).collect(Collectors.toList());
}
/**
@@ -17,9 +17,9 @@ package cn.odboy.util;
import cn.odboy.base.KitPageResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.experimental.UtilityClass;
import java.util.Collections;
import java.util.List;
import lombok.experimental.UtilityClass;
/**
* 分页工具
@@ -15,13 +15,13 @@
*/
package cn.odboy.util;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
/**
* 返回值处理 工具
@@ -15,6 +15,9 @@
*/
package cn.odboy.util;
import lombok.experimental.UtilityClass;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import java.io.ByteArrayOutputStream;
import java.security.KeyFactory;
import java.security.KeyPair;
@@ -26,9 +29,6 @@ import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import javax.crypto.Cipher;
import lombok.experimental.UtilityClass;
import org.apache.commons.codec.binary.Base64;
/**
* Rsa 工具类, 公钥私钥生成, 加解密
@@ -15,8 +15,6 @@
*/
package cn.odboy.util;
import java.util.Calendar;
import java.util.Date;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
@@ -97,19 +95,4 @@ public final class KitStringUtil {
}
return sb.toString();
}
/**
* 获得当天是周几
*/
public static String getWeekDay() {
// String[] weekDays = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
String[] weekDays = {"星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"};
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0) {
w = 0;
}
return weekDays[w];
}
}
@@ -0,0 +1,17 @@
package cn.odboy.util;
import cn.hutool.core.thread.ThreadUtil;
public class KitThreadUtil {
/**
* 可中断的睡眠
*/
public static void interruptSleep(int i) throws InterruptedException {
Thread.sleep(i);
}
public static void safeSleep(int i) {
ThreadUtil.safeSleep(i);
}
}
@@ -18,16 +18,16 @@ package cn.odboy.util;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.odboy.framework.exception.BadRequestException;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.experimental.UtilityClass;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.groups.Default;
import lombok.experimental.UtilityClass;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* Bean验证工具
@@ -46,6 +46,12 @@ public final class KitValidUtil {
}
}
/**
* 验证实体是否通过校验 <br/> 实体内通过 javax.validation.constraints 中的表达式限制参数 <br/>
*
* @param object /
* @param <T> /
*/
public static <T> void validate(T object) {
Set<ConstraintViolation<T>> violations = VALIDATOR.validate(object, Default.class);
if (!violations.isEmpty()) {
@@ -54,39 +60,125 @@ public final class KitValidUtil {
}
}
public static void notNull(Object value) {
/**
* 参数为null,抛异常
*
* @param value 参数值
*/
public static void isNull(Object value) {
if (value == null) {
throw new BadRequestException("参数必填");
}
}
public static void isNull(Object value) {
if (value != null) {
throw new BadRequestException("参数非必填");
}
}
public static void notNull(Object value, @NotNull String name, @NotNull String code) {
/**
* 参数为空,抛异常
*
* @param value 参数值
* @param name 参数名称
* @param code 参数编码
*/
public static void isNull(Object value, @NotNull String name, @NotNull String code) {
if (value == null) {
throw new BadRequestException(String.format("参数 %s(%s) 必填", name, code));
}
}
public static void isBlank(CharSequence value, @NotNull String name, @NotNull String code) {
if (StrUtil.isNotBlank(value)) {
throw new BadRequestException(String.format("参数 %s(%s) 非必填", name, code));
/**
* 参数为空,抛异常
*
* @param value 参数值
* @param message 异常信息
*/
public static void isNull(Object value, @NotNull String message) {
if (value == null) {
throw new BadRequestException(message);
}
}
public static void notBlank(CharSequence value, @NotNull String name, @NotNull String code) {
/**
* 参数为空,抛异常
*
* @param value 参数值
* @param code 参数编码
*/
public static void isNullF(Object value, @NotNull String code) {
if (value == null) {
throw new BadRequestException(String.format("参数 %s 必填", code));
}
}
/**
* 参数为空字符串,抛异常
*
* @param value 参数值
* @param name 参数名称
* @param code 参数编码
*/
public static void isBlank(CharSequence value, @NotNull String name, @NotNull String code) {
if (StrUtil.isBlank(value)) {
throw new BadRequestException(String.format("参数 %s(%s) 必填", name, code));
}
}
public static void notEmpty(List<?> data, @NotNull String code) {
/**
* 集合为空,抛异常
*
* @param data 集合值
* @param code 参数编码
*/
public static void isEmpty(List<?> data, @NotNull String code) {
if (CollUtil.isEmpty(data)) {
throw new BadRequestException(String.format("参数 %s 必填", code));
}
}
/**
* 集合为空,抛异常
*
* @param data 集合值
* @param name 参数名称
* @param code 参数编码
*/
public static void isEmpty(List<?> data, @NotNull String name, @NotNull String code) {
if (CollUtil.isEmpty(data)) {
throw new BadRequestException(String.format("参数 %s(%s) 必填", name, code));
}
}
/**
* 表达式为true,抛异常
*
* @param condition 表达式
* @param message 异常信息
*/
public static void isTrue(boolean condition, String message) {
if (condition) {
throw new BadRequestException(message);
}
}
/**
* 表达式为false,抛异常
*
* @param condition 表达式
* @param message 异常信息
*/
public static void isFalse(boolean condition, String message) {
if (!condition) {
throw new BadRequestException(message);
}
}
/**
* 参数为空字符串,抛异常
*
* @param value 参数值
* @param message 异常信息
*/
public static void isBlank(String value, String message) {
if (StrUtil.isBlank(value)) {
throw new BadRequestException(message);
}
}
}
@@ -3,12 +3,12 @@ package cn.odboy.util.xlsx;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.idev.excel.EasyExcel;
import jakarta.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
/**
* EasyExcel 导出增强工具类 (支持普通/分页模式)
@@ -6,14 +6,14 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.idev.excel.FastExcel;
import cn.odboy.framework.exception.BadRequestException;
import lombok.experimental.UtilityClass;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import lombok.experimental.UtilityClass;
/**
* xlsx文件导出工具