|
@@ -5,9 +5,12 @@ import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.exceptions.ExceptionUtil;
|
|
import cn.hutool.core.exceptions.ExceptionUtil;
|
|
import cn.hutool.core.lang.Pair;
|
|
import cn.hutool.core.lang.Pair;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
+import com.github.junrar.Archive;
|
|
|
|
+import com.github.junrar.exception.RarException;
|
|
|
|
+import com.github.junrar.rarfile.FileHeader;
|
|
import com.simuwang.base.common.conts.DateConst;
|
|
import com.simuwang.base.common.conts.DateConst;
|
|
import com.simuwang.base.common.conts.EmailDataDirectionConst;
|
|
import com.simuwang.base.common.conts.EmailDataDirectionConst;
|
|
-import com.simuwang.base.pojo.dto.EmailContentInfoDTO;
|
|
|
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
import org.apache.pdfbox.Loader;
|
|
import org.apache.pdfbox.Loader;
|
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
@@ -26,9 +29,7 @@ import java.nio.file.Paths;
|
|
import java.text.NumberFormat;
|
|
import java.text.NumberFormat;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
import org.apache.commons.compress.archivers.ArchiveEntry;
|
|
import org.apache.commons.compress.archivers.ArchiveEntry;
|
|
import org.apache.commons.compress.archivers.ArchiveInputStream;
|
|
import org.apache.commons.compress.archivers.ArchiveInputStream;
|
|
@@ -59,6 +60,9 @@ public class ExcelUtil {
|
|
public static boolean isHTML(String fileName) {
|
|
public static boolean isHTML(String fileName) {
|
|
return StrUtil.isNotBlank(fileName) && fileName.endsWith("html");
|
|
return StrUtil.isNotBlank(fileName) && fileName.endsWith("html");
|
|
}
|
|
}
|
|
|
|
+ public static boolean isRAR(String fileName) {
|
|
|
|
+ return StrUtil.isNotBlank(fileName) && (fileName.endsWith("rar") || fileName.endsWith("RAR"));
|
|
|
|
+ }
|
|
|
|
|
|
public static Sheet getSheet(File file, int sheetIndex) {
|
|
public static Sheet getSheet(File file, int sheetIndex) {
|
|
if (file == null || !file.exists()) {
|
|
if (file == null || !file.exists()) {
|
|
@@ -245,6 +249,36 @@ public class ExcelUtil {
|
|
return filePathList;
|
|
return filePathList;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static List<String> extractRar(String inputFilePath, String outputDirPath){
|
|
|
|
+ List<String> fileList = new ArrayList<>();
|
|
|
|
+ // 创建Archive对象,用于读取rar压缩文件格式
|
|
|
|
+ try{
|
|
|
|
+ Archive archive = new Archive(new FileInputStream(inputFilePath));
|
|
|
|
+ // 读取压缩文件中的所有子目录或子文件(FileHeader对象)
|
|
|
|
+ List<FileHeader> fileHeaderList = archive.getFileHeaders();
|
|
|
|
+ // 遍历子目录和子文件
|
|
|
|
+ for (FileHeader fd:fileHeaderList) {
|
|
|
|
+ System.out.println(fd.getFileName());
|
|
|
|
+ File f = new File(outputDirPath+"/"+fd.getFileName());
|
|
|
|
+ if(fd.isDirectory()){
|
|
|
|
+ // 创建新子目录
|
|
|
|
+ f.mkdirs();
|
|
|
|
+ }else{
|
|
|
|
+ // 创建新子文件
|
|
|
|
+ f.createNewFile();
|
|
|
|
+ // 获取压缩包中的子文件输出流
|
|
|
|
+ InputStream in = archive.getInputStream(fd);
|
|
|
|
+ // 复制文件输入流至新子文件
|
|
|
|
+ FileUtils.copyInputStreamToFile(in,f);
|
|
|
|
+ fileList.add(f.getAbsolutePath());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ logger.error(e.getMessage(),e);
|
|
|
|
+ }
|
|
|
|
+ return fileList;
|
|
|
|
+ }
|
|
|
|
+
|
|
public static void writeDataToSheet(Sheet sheet, Elements rows) {
|
|
public static void writeDataToSheet(Sheet sheet, Elements rows) {
|
|
int rowSize = rows.size();
|
|
int rowSize = rows.size();
|
|
for (int rowNum = 0; rowNum < rowSize; rowNum++) {
|
|
for (int rowNum = 0; rowNum < rowSize; rowNum++) {
|