sort;
+ }
+}
diff --git a/eladmin-system/src/main/java/me/zhengjie/config/WebSocketConfig.java b/eladmin-common/src/main/java/me/zhengjie/config/webConfig/WebSocketConfig.java
similarity index 93%
rename from eladmin-system/src/main/java/me/zhengjie/config/WebSocketConfig.java
rename to eladmin-common/src/main/java/me/zhengjie/config/webConfig/WebSocketConfig.java
index f55f5c60b..4751bb1cd 100644
--- a/eladmin-system/src/main/java/me/zhengjie/config/WebSocketConfig.java
+++ b/eladmin-common/src/main/java/me/zhengjie/config/webConfig/WebSocketConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019-2020 Zheng Jie
+ * Copyright 2019-2025 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package me.zhengjie.config;
+package me.zhengjie.config.webConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
diff --git a/eladmin-common/src/main/java/me/zhengjie/exception/BadConfigurationException.java b/eladmin-common/src/main/java/me/zhengjie/exception/BadConfigurationException.java
deleted file mode 100644
index ede3691f2..000000000
--- a/eladmin-common/src/main/java/me/zhengjie/exception/BadConfigurationException.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright 2019-2020 the original author or authors.
- *
- * 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 me.zhengjie.exception;
-
-/**
- * 统一关于错误配置信息 异常
- *
- * @author: liaojinlong
- * @date: 2020/6/10 18:06
- */
-public class BadConfigurationException extends RuntimeException {
- /**
- * Constructs a new runtime exception with {@code null} as its
- * detail message. The cause is not initialized, and may subsequently be
- * initialized by a call to {@link #initCause}.
- */
- public BadConfigurationException() {
- super();
- }
-
- /**
- * Constructs a new runtime exception with the specified detail message.
- * The cause is not initialized, and may subsequently be initialized by a
- * call to {@link #initCause}.
- *
- * @param message the detail message. The detail message is saved for
- * later retrieval by the {@link #getMessage()} method.
- */
- public BadConfigurationException(String message) {
- super(message);
- }
-
- /**
- * Constructs a new runtime exception with the specified detail message and
- * cause. Note that the detail message associated with
- * {@code cause} is not automatically incorporated in
- * this runtime exception's detail message.
- *
- * @param message the detail message (which is saved for later retrieval
- * by the {@link #getMessage()} method).
- * @param cause the cause (which is saved for later retrieval by the
- * {@link #getCause()} method). (A {@code null} value is
- * permitted, and indicates that the cause is nonexistent or
- * unknown.)
- * @since 1.4
- */
- public BadConfigurationException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Constructs a new runtime exception with the specified cause and a
- * detail message of {@code (cause==null ? null : cause.toString())}
- * (which typically contains the class and detail message of
- * {@code cause}). This constructor is useful for runtime exceptions
- * that are little more than wrappers for other throwables.
- *
- * @param cause the cause (which is saved for later retrieval by the
- * {@link #getCause()} method). (A {@code null} value is
- * permitted, and indicates that the cause is nonexistent or
- * unknown.)
- * @since 1.4
- */
- public BadConfigurationException(Throwable cause) {
- super(cause);
- }
-
- /**
- * Constructs a new runtime exception with the specified detail
- * message, cause, suppression enabled or disabled, and writable
- * stack trace enabled or disabled.
- *
- * @param message the detail message.
- * @param cause the cause. (A {@code null} value is permitted,
- * and indicates that the cause is nonexistent or unknown.)
- * @param enableSuppression whether or not suppression is enabled
- * or disabled
- * @param writableStackTrace whether or not the stack trace should
- * be writable
- * @since 1.7
- */
- protected BadConfigurationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
- super(message, cause, enableSuppression, writableStackTrace);
- }
-}
diff --git a/eladmin-common/src/main/java/me/zhengjie/exception/BadRequestException.java b/eladmin-common/src/main/java/me/zhengjie/exception/BadRequestException.java
index 900453bdf..1d6297b91 100644
--- a/eladmin-common/src/main/java/me/zhengjie/exception/BadRequestException.java
+++ b/eladmin-common/src/main/java/me/zhengjie/exception/BadRequestException.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019-2020 Zheng Jie
+ * Copyright 2019-2025 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/eladmin-common/src/main/java/me/zhengjie/exception/EntityExistException.java b/eladmin-common/src/main/java/me/zhengjie/exception/EntityExistException.java
index 03f9bf2ae..32d0e38f7 100644
--- a/eladmin-common/src/main/java/me/zhengjie/exception/EntityExistException.java
+++ b/eladmin-common/src/main/java/me/zhengjie/exception/EntityExistException.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019-2020 Zheng Jie
+ * Copyright 2019-2025 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/eladmin-common/src/main/java/me/zhengjie/exception/EntityNotFoundException.java b/eladmin-common/src/main/java/me/zhengjie/exception/EntityNotFoundException.java
index bcdc95628..4d9f4d964 100644
--- a/eladmin-common/src/main/java/me/zhengjie/exception/EntityNotFoundException.java
+++ b/eladmin-common/src/main/java/me/zhengjie/exception/EntityNotFoundException.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019-2020 Zheng Jie
+ * Copyright 2019-2025 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/eladmin-common/src/main/java/me/zhengjie/exception/handler/ApiError.java b/eladmin-common/src/main/java/me/zhengjie/exception/handler/ApiError.java
index 977788c72..aa377c4f3 100644
--- a/eladmin-common/src/main/java/me/zhengjie/exception/handler/ApiError.java
+++ b/eladmin-common/src/main/java/me/zhengjie/exception/handler/ApiError.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019-2020 Zheng Jie
+ * Copyright 2019-2025 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
* @date 2018-11-23
*/
@Data
-class ApiError {
+public class ApiError {
private Integer status = 400;
private Long timestamp;
diff --git a/eladmin-common/src/main/java/me/zhengjie/exception/handler/GlobalExceptionHandler.java b/eladmin-common/src/main/java/me/zhengjie/exception/handler/GlobalExceptionHandler.java
index 23cbb383f..4e4e7165a 100644
--- a/eladmin-common/src/main/java/me/zhengjie/exception/handler/GlobalExceptionHandler.java
+++ b/eladmin-common/src/main/java/me/zhengjie/exception/handler/GlobalExceptionHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019-2020 Zheng Jie
+ * Copyright 2019-2025 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/AnonTagUtils.java b/eladmin-common/src/main/java/me/zhengjie/utils/AnonTagUtils.java
new file mode 100644
index 000000000..9a2832ded
--- /dev/null
+++ b/eladmin-common/src/main/java/me/zhengjie/utils/AnonTagUtils.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2019-2020 the original author or authors.
+ *
+ * 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 me.zhengjie.utils;
+
+import me.zhengjie.annotation.rest.AnonymousAccess;
+import me.zhengjie.utils.enums.RequestMethodEnum;
+import org.springframework.context.ApplicationContext;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.method.HandlerMethod;
+import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
+import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
+
+import java.util.*;
+
+/**
+ * @author Zheng Jie
+ * @description 匿名标记工具
+ * @date 2025-01-13
+ **/
+public class AnonTagUtils {
+
+ /**
+ * 获取匿名标记的URL
+ * @param applicationContext /
+ * @return /
+ */
+ public static Map> getAnonymousUrl(ApplicationContext applicationContext){
+ RequestMappingHandlerMapping requestMappingHandlerMapping = (RequestMappingHandlerMapping) applicationContext.getBean("requestMappingHandlerMapping");
+ Map handlerMethodMap = requestMappingHandlerMapping.getHandlerMethods();
+ Map> anonymousUrls = new HashMap<>(8);
+ // 获取匿名标记
+ Set get = new HashSet<>();
+ Set post = new HashSet<>();
+ Set put = new HashSet<>();
+ Set patch = new HashSet<>();
+ Set delete = new HashSet<>();
+ Set all = new HashSet<>();
+ for (Map.Entry infoEntry : handlerMethodMap.entrySet()) {
+ HandlerMethod handlerMethod = infoEntry.getValue();
+ AnonymousAccess anonymousAccess = handlerMethod.getMethodAnnotation(AnonymousAccess.class);
+ if (null != anonymousAccess) {
+ List requestMethods = new ArrayList<>(infoEntry.getKey().getMethodsCondition().getMethods());
+ RequestMethodEnum request = RequestMethodEnum.find(requestMethods.isEmpty() ? RequestMethodEnum.ALL.getType() : requestMethods.get(0).name());
+ if (infoEntry.getKey().getPatternsCondition()!=null) {
+ switch (Objects.requireNonNull(request)) {
+ case GET:
+ get.addAll(infoEntry.getKey().getPatternsCondition().getPatterns());
+ break;
+ case POST:
+ post.addAll(infoEntry.getKey().getPatternsCondition().getPatterns());
+ break;
+ case PUT:
+ put.addAll(infoEntry.getKey().getPatternsCondition().getPatterns());
+ break;
+ case PATCH:
+ patch.addAll(infoEntry.getKey().getPatternsCondition().getPatterns());
+ break;
+ case DELETE:
+ delete.addAll(infoEntry.getKey().getPatternsCondition().getPatterns());
+ break;
+ default:
+ all.addAll(infoEntry.getKey().getPatternsCondition().getPatterns());
+ break;
+ }
+ }
+ }
+ }
+ anonymousUrls.put(RequestMethodEnum.GET.getType(), get);
+ anonymousUrls.put(RequestMethodEnum.POST.getType(), post);
+ anonymousUrls.put(RequestMethodEnum.PUT.getType(), put);
+ anonymousUrls.put(RequestMethodEnum.PATCH.getType(), patch);
+ anonymousUrls.put(RequestMethodEnum.DELETE.getType(), delete);
+ anonymousUrls.put(RequestMethodEnum.ALL.getType(), all);
+ return anonymousUrls;
+ }
+
+ /**
+ * 获取所有匿名标记的URL
+ * @param applicationContext /
+ * @return /
+ */
+ public static Set getAllAnonymousUrl(ApplicationContext applicationContext){
+ Set allUrl = new HashSet<>();
+ Map> anonymousUrls = getAnonymousUrl(applicationContext);
+ for (String key : anonymousUrls.keySet()) {
+ allUrl.addAll(anonymousUrls.get(key));
+ }
+ return allUrl;
+ }
+}
diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/BigDecimalUtils.java b/eladmin-common/src/main/java/me/zhengjie/utils/BigDecimalUtils.java
new file mode 100644
index 000000000..ff3d81fa2
--- /dev/null
+++ b/eladmin-common/src/main/java/me/zhengjie/utils/BigDecimalUtils.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2019-2020 the original author or authors.
+ *
+ * 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 me.zhengjie.utils;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+/**
+ * @author Zheng Jie
+ * @description 计算类
+ * @date 2024-12-27
+ **/
+public class BigDecimalUtils {
+
+ /**
+ * 将对象转换为 BigDecimal
+ * @param obj 输入对象
+ * @return 转换后的 BigDecimal
+ */
+ private static BigDecimal toBigDecimal(Object obj) {
+ if (obj instanceof BigDecimal) {
+ return (BigDecimal) obj;
+ } else if (obj instanceof Long) {
+ return BigDecimal.valueOf((Long) obj);
+ } else if (obj instanceof Integer) {
+ return BigDecimal.valueOf((Integer) obj);
+ } else if (obj instanceof Double) {
+ return new BigDecimal(String.valueOf(obj));
+ } else {
+ throw new IllegalArgumentException("Unsupported type");
+ }
+ }
+
+ /**
+ * 加法
+ * @param a 加数
+ * @param b 加数
+ * @return 两个加数的和,保留两位小数
+ */
+ public static BigDecimal add(Object a, Object b) {
+ BigDecimal bdA = toBigDecimal(a);
+ BigDecimal bdB = toBigDecimal(b);
+ return bdA.add(bdB).setScale(2, RoundingMode.HALF_UP);
+ }
+
+ /**
+ * 减法
+ * @param a 被减数
+ * @param b 减数
+ * @return 两数的差,保留两位小数
+ */
+ public static BigDecimal subtract(Object a, Object b) {
+ BigDecimal bdA = toBigDecimal(a);
+ BigDecimal bdB = toBigDecimal(b);
+ return bdA.subtract(bdB).setScale(2, RoundingMode.HALF_UP);
+ }
+
+ /**
+ * 乘法
+ * @param a 乘数
+ * @param b 乘数
+ * @return 两个乘数的积,保留两位小数
+ */
+ public static BigDecimal multiply(Object a, Object b) {
+ BigDecimal bdA = toBigDecimal(a);
+ BigDecimal bdB = toBigDecimal(b);
+ return bdA.multiply(bdB).setScale(2, RoundingMode.HALF_UP);
+ }
+
+ /**
+ * 除法
+ * @param a 被除数
+ * @param b 除数
+ * @return 两数的商,保留两位小数
+ */
+ public static BigDecimal divide(Object a, Object b) {
+ BigDecimal bdA = toBigDecimal(a);
+ BigDecimal bdB = toBigDecimal(b);
+ return bdA.divide(bdB, 2, RoundingMode.HALF_UP);
+ }
+
+ /**
+ * 除法
+ * @param a 被除数
+ * @param b 除数
+ * @param scale 保留小数位数
+ * @return 两数的商,保留两位小数
+ */
+ public static BigDecimal divide(Object a, Object b, int scale) {
+ BigDecimal bdA = toBigDecimal(a);
+ BigDecimal bdB = toBigDecimal(b);
+ return bdA.divide(bdB, scale, RoundingMode.HALF_UP);
+ }
+
+ /**
+ * 分转元
+ * @param obj 分的金额
+ * @return 转换后的元,保留两位小数
+ */
+ public static BigDecimal centsToYuan(Object obj) {
+ BigDecimal cents = toBigDecimal(obj);
+ return cents.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP);
+ }
+
+ /**
+ * 元转分
+ * @param obj 元的金额
+ * @return 转换后的分
+ */
+ public static Long yuanToCents(Object obj) {
+ BigDecimal yuan = toBigDecimal(obj);
+ return yuan.multiply(BigDecimal.valueOf(100)).setScale(0, RoundingMode.HALF_UP).longValue();
+ }
+
+ public static void main(String[] args) {
+ BigDecimal num1 = new BigDecimal("10.123");
+ BigDecimal num2 = new BigDecimal("2.456");
+
+ System.out.println("加法结果: " + add(num1, num2));
+ System.out.println("减法结果: " + subtract(num1, num2));
+ System.out.println("乘法结果: " + multiply(num1, num2));
+ System.out.println("除法结果: " + divide(num1, num2));
+
+ Long cents = 12345L;
+ System.out.println("分转元结果: " + centsToYuan(cents));
+
+ BigDecimal yuan = new BigDecimal("123.45");
+ System.out.println("元转分结果: " + yuanToCents(yuan));
+ }
+}
diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/CacheKey.java b/eladmin-common/src/main/java/me/zhengjie/utils/CacheKey.java
index 7485713f1..e8fb08609 100644
--- a/eladmin-common/src/main/java/me/zhengjie/utils/CacheKey.java
+++ b/eladmin-common/src/main/java/me/zhengjie/utils/CacheKey.java
@@ -16,9 +16,9 @@
package me.zhengjie.utils;
/**
- * @author: liaojinlong
- * @date: 2020/6/11 15:49
- * @apiNote: 关于缓存的Key集合
+ * @author liaojinlong
+ * @date 2020/6/11 15:49
+ * @description 关于缓存的Key集合
*/
public interface CacheKey {
@@ -26,31 +26,39 @@ public interface CacheKey {
* 用户
*/
String USER_ID = "user::id:";
+
/**
* 数据
*/
String DATA_USER = "data::user:";
+
/**
* 菜单
*/
String MENU_ID = "menu::id:";
String MENU_USER = "menu::user:";
+
/**
* 角色授权
*/
String ROLE_AUTH = "role::auth:";
+ String ROLE_USER = "role::user:";
+
/**
* 角色信息
*/
String ROLE_ID = "role::id:";
+
/**
* 部门
*/
String DEPT_ID = "dept::id:";
+
/**
* 岗位
*/
String JOB_ID = "job::id:";
+
/**
* 数据字典
*/
diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/CallBack.java b/eladmin-common/src/main/java/me/zhengjie/utils/CallBack.java
deleted file mode 100644
index 9b108127e..000000000
--- a/eladmin-common/src/main/java/me/zhengjie/utils/CallBack.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2019-2020 the original author or authors.
- *
- * 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 me.zhengjie.utils;
-
-/**
- * @author: liaojinlong
- * @date: 2020/6/9 17:02
- * @since: 1.0
- * @see {@link SpringContextHolder}
- * 针对某些初始化方法,在SpringContextHolder 初始化前时,
- * 可提交一个 提交回调任务。
- * 在SpringContextHolder 初始化后,进行回调使用
- */
-
-public interface CallBack {
- /**
- * 回调执行方法
- */
- void executor();
-
- /**
- * 本回调任务名称
- * @return /
- */
- default String getCallBackName() {
- return Thread.currentThread().getId() + ":" + this.getClass().getName();
- }
-}
-
diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/CloseUtil.java b/eladmin-common/src/main/java/me/zhengjie/utils/CloseUtil.java
index f39919f2c..b095ec63b 100644
--- a/eladmin-common/src/main/java/me/zhengjie/utils/CloseUtil.java
+++ b/eladmin-common/src/main/java/me/zhengjie/utils/CloseUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019-2020 Zheng Jie
+ * Copyright 2019-2025 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/ElConstant.java b/eladmin-common/src/main/java/me/zhengjie/utils/ElConstant.java
index 479b1e697..fa58845e0 100644
--- a/eladmin-common/src/main/java/me/zhengjie/utils/ElConstant.java
+++ b/eladmin-common/src/main/java/me/zhengjie/utils/ElConstant.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019-2020 Zheng Jie
+ * Copyright 2019-2025 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/EncryptUtils.java b/eladmin-common/src/main/java/me/zhengjie/utils/EncryptUtils.java
index 4f334aac1..83bf918f3 100644
--- a/eladmin-common/src/main/java/me/zhengjie/utils/EncryptUtils.java
+++ b/eladmin-common/src/main/java/me/zhengjie/utils/EncryptUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019-2020 Zheng Jie
+ * Copyright 2019-2025 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,20 +27,15 @@
* @author Zheng Jie
* @date 2018-11-23
*/
-
public class EncryptUtils {
private static final String STR_PARAM = "Passw0rd";
-
- private static Cipher cipher;
-
private static final IvParameterSpec IV = new IvParameterSpec(STR_PARAM.getBytes(StandardCharsets.UTF_8));
private static DESKeySpec getDesKeySpec(String source) throws Exception {
- if (source == null || source.length() == 0){
+ if (source == null || source.isEmpty()) {
return null;
}
- cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
String strKey = "Passw0rd";
return new DESKeySpec(strKey.getBytes(StandardCharsets.UTF_8));
}
@@ -49,18 +44,19 @@ private static DESKeySpec getDesKeySpec(String source) throws Exception {
* 对称加密
*/
public static String desEncrypt(String source) throws Exception {
+ Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
DESKeySpec desKeySpec = getDesKeySpec(source);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
cipher.init(Cipher.ENCRYPT_MODE, secretKey, IV);
- return byte2hex(
- cipher.doFinal(source.getBytes(StandardCharsets.UTF_8))).toUpperCase();
+ return byte2hex(cipher.doFinal(source.getBytes(StandardCharsets.UTF_8))).toUpperCase();
}
/**
* 对称解密
*/
public static String desDecrypt(String source) throws Exception {
+ Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
byte[] src = hex2byte(source.getBytes(StandardCharsets.UTF_8));
DESKeySpec desKeySpec = getDesKeySpec(source);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
@@ -76,7 +72,6 @@ private static String byte2hex(byte[] inStr) {
for (byte b : inStr) {
stmp = Integer.toHexString(b & 0xFF);
if (stmp.length() == 1) {
- // 如果是0至F的单位字符串,则添加0
out.append("0").append(stmp);
} else {
out.append(stmp);
@@ -87,7 +82,7 @@ private static String byte2hex(byte[] inStr) {
private static byte[] hex2byte(byte[] b) {
int size = 2;
- if ((b.length % size) != 0){
+ if ((b.length % size) != 0) {
throw new IllegalArgumentException("长度不是偶数");
}
byte[] b2 = new byte[b.length / 2];
diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java b/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java
index ca2b674d3..590f76b68 100644
--- a/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java
+++ b/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019-2020 Zheng Jie
+ * Copyright 2019-2025 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,22 +19,21 @@
import cn.hutool.core.util.IdUtil;
import cn.hutool.poi.excel.BigExcelWriter;
import cn.hutool.poi.excel.ExcelUtil;
+import lombok.extern.slf4j.Slf4j;
import me.zhengjie.exception.BadRequestException;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.streaming.SXSSFSheet;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
+import java.nio.file.Files;
import java.security.MessageDigest;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.stream.Collectors;
/**
* File工具类,扩展 hutool 工具包
@@ -42,10 +41,9 @@
* @author Zheng Jie
* @date 2018-12-27
*/
+@Slf4j
public class FileUtil extends cn.hutool.core.io.FileUtil {
- private static final Logger log = LoggerFactory.getLogger(FileUtil.class);
-
/**
* 系统临时目录
*
@@ -108,7 +106,7 @@ public static File toFile(MultipartFile multipartFile) {
* 获取文件扩展名,不带 .
*/
public static String getExtensionName(String filename) {
- if ((filename != null) && (filename.length() > 0)) {
+ if ((filename != null) && (!filename.isEmpty())) {
int dot = filename.lastIndexOf('.');
if ((dot > -1) && (dot < (filename.length() - 1))) {
return filename.substring(dot + 1);
@@ -121,9 +119,9 @@ public static String getExtensionName(String filename) {
* Java文件操作 获取不带扩展名的文件名
*/
public static String getFileNameNoEx(String filename) {
- if ((filename != null) && (filename.length() > 0)) {
+ if ((filename != null) && (!filename.isEmpty())) {
int dot = filename.lastIndexOf('.');
- if ((dot > -1) && (dot < (filename.length()))) {
+ if (dot > -1) {
return filename.substring(0, dot);
}
}
@@ -137,15 +135,15 @@ public static String getSize(long size) {
String resultSize;
if (size / GB >= 1) {
//如果当前Byte的值大于等于1GB
- resultSize = DF.format(size / (float) GB) + "GB ";
+ resultSize = DF.format(size / (float) GB) + "GB";
} else if (size / MB >= 1) {
//如果当前Byte的值大于等于1MB
- resultSize = DF.format(size / (float) MB) + "MB ";
+ resultSize = DF.format(size / (float) MB) + "MB";
} else if (size / KB >= 1) {
//如果当前Byte的值大于等于1KB
- resultSize = DF.format(size / (float) KB) + "KB ";
+ resultSize = DF.format(size / (float) KB) + "KB";
} else {
- resultSize = size + "B ";
+ resultSize = size + "B";
}
return resultSize;
}
@@ -160,7 +158,7 @@ static File inputStreamToFile(InputStream ins, String name){
}
OutputStream os = null;
try {
- os = new FileOutputStream(file);
+ os = Files.newOutputStream(file.toPath());
int bytesRead;
int len = 8192;
byte[] buffer = new byte[len];
@@ -168,7 +166,7 @@ static File inputStreamToFile(InputStream ins, String name){
os.write(buffer, 0, bytesRead);
}
} catch (Exception e) {
- e.printStackTrace();
+ log.error(e.getMessage(), e);
} finally {
CloseUtil.close(os);
CloseUtil.close(ins);
@@ -213,8 +211,25 @@ public static void downloadExcel(List