Browse Source

fix: 防止中文乱码,解压之后的附件重命名

chenjianhua 3 tháng trước cách đây
mục cha
commit
3ede913b8c

+ 11 - 3
service-base/src/main/java/com/simuwang/base/common/util/ExcelUtil.java

@@ -232,7 +232,15 @@ public class ExcelUtil {
             ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(fis);
             ArchiveEntry entry;
             while ((entry = ais.getNextEntry()) != null) {
-                File entryFile = new File(destFilePath, entry.getName());
+                String uuid = UUID.randomUUID().toString().replaceAll("-","");
+                String entryName = entry.getName();
+                String fileName = null;
+                if(entryName.contains(".")){
+                    fileName = uuid + entryName.substring(entryName.lastIndexOf("."),entryName.length());
+                }else{
+                    fileName = uuid;
+                }
+                File entryFile = new File(destFilePath, fileName);
                 if (entry.isDirectory()) {
                     entryFile.mkdirs();
                     logger.info("解压子文件:{}",entryFile.getName());
@@ -243,14 +251,14 @@ public class ExcelUtil {
                         filePathList.add(entryFile.getPath());
                         logger.info("解压子文件:{}",entryFile.getPath());
                     }catch (Exception e){
-                        logger.error(e.getMessage());
+                        logger.error(e.getMessage(),e);
                     }
                 }
             }
         }catch (Exception e) {
             logger.error(zipFilePath+"======="+e.getMessage(),e);
         }
-        logger.info("开始结束================");
+        logger.info("解压结束================");
         return filePathList;
     }