diff --git a/eladmin-common/pom.xml b/eladmin-common/pom.xml
index 49018491..c7467180 100644
--- a/eladmin-common/pom.xml
+++ b/eladmin-common/pom.xml
@@ -10,5 +10,6 @@
4.0.0
eladmin-common
+ 公共模块
\ No newline at end of file
diff --git a/eladmin-common/src/main/java/me/zhengjie/redis/RedisConfig.java b/eladmin-common/src/main/java/me/zhengjie/redis/RedisConfig.java
index a9486165..beb0170a 100644
--- a/eladmin-common/src/main/java/me/zhengjie/redis/RedisConfig.java
+++ b/eladmin-common/src/main/java/me/zhengjie/redis/RedisConfig.java
@@ -3,14 +3,14 @@ package me.zhengjie.redis;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.ParserConfig;
import lombok.extern.slf4j.Slf4j;
-import me.zhengjie.utils.StringUtils;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.cache.Cache;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.cache.interceptor.CacheErrorHandler;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -61,6 +61,7 @@ public class RedisConfig extends CachingConfigurerSupport {
// 建议使用这种方式,小范围指定白名单
ParserConfig.getGlobalInstance().addAccept("me.zhengjie.domain");
ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.system.service.dto");
+ ParserConfig.getGlobalInstance().addAccept("me.zhengjie.service.dto");
ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.system.domain");
ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.quartz.domain");
ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.monitor.domain");
@@ -73,8 +74,8 @@ public class RedisConfig extends CachingConfigurerSupport {
}
/**
- * 自定义缓存key生成策略
- * 使用方法 @Cacheable(keyGenerator="keyGenerator")
+ * 自定义缓存key生成策略,默认将使用该策略
+ * 使用方法 @Cacheable
* @return
*/
@Bean
@@ -90,4 +91,34 @@ public class RedisConfig extends CachingConfigurerSupport {
return sb.toString();
};
}
+
+ @Bean
+ @Override
+ public CacheErrorHandler errorHandler() {
+ // 异常处理,当Redis发生异常时,打印日志,但是程序正常走
+ log.info("初始化 -> [{}]", "Redis CacheErrorHandler");
+ CacheErrorHandler cacheErrorHandler = new CacheErrorHandler() {
+ @Override
+ public void handleCacheGetError(RuntimeException e, Cache cache, Object key) {
+ log.error("Redis occur handleCacheGetError:key -> [{}]", key, e);
+ }
+
+ @Override
+ public void handleCachePutError(RuntimeException e, Cache cache, Object key, Object value) {
+ log.error("Redis occur handleCachePutError:key -> [{}];value -> [{}]", key, value, e);
+ }
+
+ @Override
+ public void handleCacheEvictError(RuntimeException e, Cache cache, Object key) {
+ log.error("Redis occur handleCacheEvictError:key -> [{}]", key, e);
+ }
+
+ @Override
+ public void handleCacheClearError(RuntimeException e, Cache cache) {
+ log.error("Redis occur handleCacheClearError:", e);
+ }
+ };
+ return cacheErrorHandler;
+ }
+
}
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 5549b814..0bd59edd 100644
--- a/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java
+++ b/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java
@@ -1,10 +1,21 @@
package me.zhengjie.utils;
+import cn.hutool.core.codec.Base64;
+import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.IdUtil;
+import cn.hutool.poi.excel.BigExcelWriter;
+import cn.hutool.poi.excel.ExcelUtil;
+import cn.hutool.poi.excel.ExcelWriter;
+import me.zhengjie.exception.BadRequestException;
import org.springframework.web.multipart.MultipartFile;
-
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
/**
* File工具类,扩展 hutool 工具包
@@ -100,7 +111,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
* @param size
* @return
*/
- public static String getSize(int size){
+ public static String getSize(long size){
String resultSize = "";
if (size / GB >= 1) {
//如果当前Byte的值大于等于1GB
@@ -139,4 +150,91 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
ins.close();
return file;
}
+
+ /**
+ * 将文件名解析成文件的上传路径
+ *
+ * @param file
+ * @param filePath
+ * @return 上传到服务器的文件名
+ */
+ public static File upload(MultipartFile file, String filePath) {
+ Date date = new Date();
+ SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmssS");
+ String name = getFileNameNoEx(file.getOriginalFilename());
+ String suffix = getExtensionName(file.getOriginalFilename());
+ String nowStr = "-" + format.format(date);
+ try {
+ String fileName = name + nowStr + "." + suffix;
+ String path = filePath + fileName;
+ File dest = new File(path);
+ // 检测是否存在目录
+ if (!dest.getParentFile().exists()) {
+ dest.getParentFile().mkdirs();// 新建文件夹
+ }
+ String d = dest.getPath();
+ file.transferTo(dest);// 文件写入
+ return dest;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static String fileToBase64(File file) throws Exception {
+ FileInputStream inputFile = new FileInputStream(file);
+ String base64 =null;
+ byte[] buffer = new byte[(int)file.length()];
+ inputFile.read(buffer);
+ inputFile.close();
+ base64=new Base64().encode(buffer);
+ String encoded = base64.replaceAll("[\\s*\t\n\r]", "");
+ return encoded;
+ }
+
+ /**
+ * 导出excel
+ * @param list
+ * @return
+ * @throws Exception
+ */
+ public static void downloadExcel(List