Pārlūkot izejas kodu

feat: 估值表解析增加RAR文件格式

chenjianhua 4 mēneši atpakaļ
vecāks
revīzija
fd076956ef

+ 44 - 33
service-base/src/main/java/com/simuwang/base/common/util/ExcelUtil.java

@@ -220,46 +220,57 @@ public class ExcelUtil {
         return cellValue;
     }
 
-    public static List<String> extractCompressedFiles(String zipFilePath, String destFilePath) {
+    public static List<String> extractCompressedFiles(String filePath, String destFilePath) {
         List<String> filePathList = CollUtil.newArrayList();
         try {
-            File destFile = new File(destFilePath);
-            if (!destFile.exists()) {
-                destFile.mkdirs();
-            }
-            logger.info("开始解压==================="+zipFilePath);
-            BufferedInputStream fis = new BufferedInputStream(new FileInputStream(zipFilePath));
-            ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(fis);
-            ArchiveEntry entry;
-            while ((entry = ais.getNextEntry()) != null) {
-                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;
+            if(ExcelUtil.isZip(filePath)){
+                File destFile = new File(destFilePath);
+                if (!destFile.exists()) {
+                    destFile.mkdirs();
                 }
-                File entryFile = new File(destFilePath, fileName);
-                if (entry.isDirectory()) {
-                    entryFile.mkdirs();
-                    logger.info("解压子文件:{}",entryFile.getName());
-                } else {
-                    try {
-                        FileOutputStream fos = new FileOutputStream(entryFile);
-                        IOUtils.copy(ais, fos);
-                        filePathList.add(entryFile.getPath());
-                        logger.info("解压子文件:{}",entryFile.getPath());
-                        fos.close();
-                    }catch (Exception e){
-                        logger.error(e.getMessage(),e);
+                logger.info("开始解压==================="+filePath);
+                BufferedInputStream fis = new BufferedInputStream(new FileInputStream(filePath));
+                ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(fis);
+                ArchiveEntry entry;
+                while ((entry = ais.getNextEntry()) != null) {
+                    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());
+                    } else {
+                        try {
+                            FileOutputStream fos = new FileOutputStream(entryFile);
+                            IOUtils.copy(ais, fos);
+                            filePathList.add(entryFile.getPath());
+                            logger.info("解压子文件:{}",entryFile.getPath());
+                            fos.close();
+                        }catch (Exception e){
+                            logger.error(e.getMessage(),e);
+                        }
+                    }
+                }
+                ais.close();
+                fis.close();
+            }
+            if(ExcelUtil.isRAR(filePath)){
+                String destPath = filePath.replaceAll(".rar", "").replaceAll(".RAR", "");
+                File destFile = new File(destPath);
+                if (!destFile.exists()) {
+                    destFile.mkdirs();
                 }
+                List<String> rarDir = ExcelUtil.extractRar(filePath, destPath);
+                filePathList.addAll(rarDir);
             }
-            ais.close();
-            fis.close();
         }catch (Exception e) {
-            logger.error(zipFilePath+"======="+e.getMessage(),e);
+            logger.error(filePath+"======="+e.getMessage(),e);
         }
         logger.info("解压结束================");
         return filePathList;

+ 7 - 5
service-daq/src/main/java/com/simuwang/daq/service/ValuationEmailParser.java

@@ -48,7 +48,8 @@ public class ValuationEmailParser extends AbstractEmailParser {
     public List<EmailFundNavDTO> parse(EmailContentInfoDTO emailContentInfoDTO, Map<String, List<String>> emailFieldMap) {
         List<EmailFundNavDTO> emailFundNavDTOList = CollUtil.newArrayList();
         boolean isSatisfiedParse = emailContentInfoDTO != null && StrUtil.isNotBlank(emailContentInfoDTO.getFileName())
-                && (ExcelUtil.isExcel(emailContentInfoDTO.getFileName()) || ExcelUtil.isPdf(emailContentInfoDTO.getFileName()) || ExcelUtil.isZip(emailContentInfoDTO.getFileName()));
+                && (ExcelUtil.isExcel(emailContentInfoDTO.getFileName()) || ExcelUtil.isPdf(emailContentInfoDTO.getFileName()) || ExcelUtil.isZip(emailContentInfoDTO.getFileName())
+                || ExcelUtil.isRAR(emailContentInfoDTO.getFileName()));
         if (!isSatisfiedParse) {
             return emailFundNavDTOList;
         }
@@ -75,7 +76,7 @@ public class ValuationEmailParser extends AbstractEmailParser {
     private List<ValuationNeedParseParam> buildValuationNeedParseParam(EmailContentInfoDTO emailContentInfoDTO) {
         String fileName = emailContentInfoDTO.getFileName();
         String filePath = emailContentInfoDTO.getFilePath();
-        if (StrUtil.isNotBlank(fileName) && ExcelUtil.isZip(fileName)) {
+        if (StrUtil.isNotBlank(fileName) && (ExcelUtil.isZip(fileName) || ExcelUtil.isRAR(fileName))) {
             List<String> filePathList = compressedFile(filePath, fileName);
             if (CollUtil.isEmpty(filePathList)) {
                 return CollUtil.newArrayList();
@@ -109,14 +110,15 @@ public class ValuationEmailParser extends AbstractEmailParser {
 
     private List<String> compressedFile(String filePath, String fileName) {
         List<String> filePathList = CollUtil.newArrayList();
-        String destPath = filePath.substring(0, filePath.indexOf(fileName)) + fileName.replaceAll(".zip", "").replaceAll(".ZIP", "");
+        String destPath = filePath.substring(0, filePath.indexOf(fileName)) + fileName.replaceAll(".zip", "").replaceAll(".ZIP", "")
+                .replaceAll(".rar", "").replaceAll(".RAR", "");
         List<String> compressedFiles = ExcelUtil.extractCompressedFiles(filePath, destPath);
         for (String path : compressedFiles) {
-            boolean isSatisfiedParse = ExcelUtil.isExcel(path) || ExcelUtil.isPdf(path) || ExcelUtil.isZip(path);
+            boolean isSatisfiedParse = ExcelUtil.isExcel(path) || ExcelUtil.isPdf(path) || ExcelUtil.isZip(path) || ExcelUtil.isRAR(path);
             if (!isSatisfiedParse) {
                 continue;
             }
-            if (ExcelUtil.isZip(path)) {
+            if (ExcelUtil.isZip(path) || ExcelUtil.isRAR(path)) {
                 filePathList.addAll(compressedFile(path, new File(path).getName()));
             }
             File file = new File(path);