convertedList = redissonClient.getMapCache(REDIS_FILE_PREVIEW_PDF_KEY);
+ convertedList.fastPut(fileName, value);
+ }
+
+ /**
+ * 判断文件编码格式
+ * @param path
+ * @return
+ */
+ public String getFileEncodeUTFGBK(String path){
+ String enc = Charset.forName("GBK").name();
+ File file = new File(path);
+ InputStream in= null;
+ try {
+ in = new FileInputStream(file);
+ byte[] b = new byte[3];
+ in.read(b);
+ in.close();
+ if (b[0] == -17 && b[1] == -69 && b[2] == -65) {
+ enc = Charset.forName("UTF-8").name();
+ }
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ System.out.println("文件编码格式为:" + enc);
+ return enc;
+ }
+
+ /**
+ * 对转换后的文件进行操作(改变编码方式)
+ * @param outFilePath
+ */
+ public void doActionConvertedFile(String outFilePath) {
+ StringBuffer sb = new StringBuffer();
+ try (InputStream inputStream = new FileInputStream(outFilePath);
+ BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, charset))){
+ String line;
+ while(null != (line = reader.readLine())){
+ if (line.contains("charset=gb2312")) {
+ line = line.replace("charset=gb2312", "charset=utf-8");
+ }
+ sb.append(line);
+ }
+ // 添加sheet控制头
+ sb.append("");
+ sb.append("");
+ sb.append("");
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ // 重新写入文件
+ try(FileOutputStream fos = new FileOutputStream(outFilePath);
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos))){
+ writer.write(sb.toString());
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/com/yudianbank/utils/OfficeToPdf.java b/src/main/java/com/yudianbank/utils/OfficeToPdf.java
new file mode 100644
index 000000000..7f8334463
--- /dev/null
+++ b/src/main/java/com/yudianbank/utils/OfficeToPdf.java
@@ -0,0 +1,129 @@
+package com.yudianbank.utils;
+import org.artofsolving.jodconverter.OfficeDocumentConverter;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import java.io.File;
+@Component
+public class OfficeToPdf {
+ /**
+ * 获取OpenOffice.org 3的安装目录
+ *
+ * @return OpenOffice.org 3的安装目录
+ */
+ @Value("${openOfficePath}")
+ private String openOfficePath;
+ @Autowired
+ ConverterUtils converterUtils;
+ /**
+ * 使Office2003-2007全部格式的文档(.doc|.docx|.xls|.xlsx|.ppt|.pptx) 转化为pdf文件
+ *
+ * @param inputFilePath
+ * 源文件路径,如:"e:/test.docx"
+ * @param outputFilePath
+ * 目标文件路径,如:"e:/test_docx.pdf"
+ * @return
+ */
+ public boolean openOfficeToPDF(String inputFilePath, String outputFilePath) {
+ return office2pdf(inputFilePath, outputFilePath);
+ }
+
+
+
+ /**
+ * 连接OpenOffice.org 并且启动OpenOffice.org
+ *
+ * @return
+ */
+ /*public OfficeManager getOfficeManager() {
+ DefaultOfficeManagerConfiguration config = new DefaultOfficeManagerConfiguration();
+ // 获取OpenOffice.org 3的安装目录
+ String officeHome = openOfficePath;
+ config.setOfficeHome(officeHome);
+ // 启动OpenOffice的服务
+ OfficeManager officeManager = config.buildOfficeManager();
+ officeManager.start();
+ return officeManager;
+ }*/
+
+ /**
+ * 转换文件
+ *
+ * @param inputFile
+ * @param outputFilePath_end
+ * @param inputFilePath
+ * @param outputFilePath
+ * @param converter
+ */
+ public static void converterFile(File inputFile, String outputFilePath_end,
+ String inputFilePath, String outputFilePath,
+ OfficeDocumentConverter converter) {
+ File outputFile = new File(outputFilePath_end);
+ // 假如目标路径不存在,则新建该路径
+ if (!outputFile.getParentFile().exists()) {
+ outputFile.getParentFile().mkdirs();
+ }
+ converter.convert(inputFile, outputFile);
+ }
+
+ /**
+ * 使Office2003-2007全部格式的文档(.doc|.docx|.xls|.xlsx|.ppt|.pptx) 转化为pdf文件
+ *
+ * @param inputFilePath
+ * 源文件路径,如:"e:/test.docx"
+ * @param outputFilePath
+ * 目标文件路径,如:"e:/test_docx.pdf"
+ * @return
+ */
+ public boolean office2pdf(String inputFilePath, String outputFilePath) {
+ boolean flag = false;
+ OfficeDocumentConverter converter = converterUtils.getDocumentConverter();
+ if (null != inputFilePath) {
+ File inputFile = new File(inputFilePath);
+ // 判断目标文件路径是否为空
+ if (null == outputFilePath) {
+ // 转换后的文件路径
+ String outputFilePath_end = getOutputFilePath(inputFilePath);
+ if (inputFile.exists()) {// 找不到源文件, 则返回
+ converterFile(inputFile, outputFilePath_end, inputFilePath,
+ outputFilePath, converter);
+ flag = true;
+ }
+ } else {
+ if (inputFile.exists()) {// 找不到源文件, 则返回
+ converterFile(inputFile, outputFilePath, inputFilePath,
+ outputFilePath, converter);
+ flag = true;
+ }
+ }
+// officeManager.stop();
+ } else {
+ flag = false;
+ }
+ return flag;
+ }
+
+ /**
+ * 获取输出文件
+ *
+ * @param inputFilePath
+ * @return
+ */
+ public static String getOutputFilePath(String inputFilePath) {
+ String outputFilePath = inputFilePath.replaceAll("."
+ + getPostfix(inputFilePath), ".pdf");
+ return outputFilePath;
+ }
+
+ /**
+ * 获取inputFilePath的后缀名,如:"e:/test.pptx"的后缀名为:"pptx"
+ *
+ * @param inputFilePath
+ * @return
+ */
+ public static String getPostfix(String inputFilePath) {
+ return inputFilePath.substring(inputFilePath.lastIndexOf(".") + 1);
+ }
+
+}
diff --git a/src/main/java/com/yudianbank/utils/PoiExcelToHtml.java b/src/main/java/com/yudianbank/utils/PoiExcelToHtml.java
new file mode 100644
index 000000000..e08883bf3
--- /dev/null
+++ b/src/main/java/com/yudianbank/utils/PoiExcelToHtml.java
@@ -0,0 +1,194 @@
+package com.yudianbank.utils;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.poi.hssf.converter.ExcelToHtmlConverter;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hwpf.converter.PicturesManager;
+import org.apache.poi.hwpf.converter.WordToHtmlConverter;
+import org.apache.poi.hwpf.usermodel.Picture;
+import org.apache.poi.hwpf.usermodel.PictureType;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.w3c.dom.Document;
+
+
+public class PoiExcelToHtml {
+// String path = getClass().getClassLoader().getResource(".").getPath()+File.separator+"static"+File.separator;
+ public static void excelConvert(URL url) {
+ try {
+ String path = "";
+
+// http://keking.ufile.ucloud.com.cn/20171101152525_左晓晖2017年9.xls?UCloudPublicKey=ucloudtangshd@weifenf.com14355492830001993909323&Expires=&Signature=1n8ASiYMcfiF30YHxwpzwfqmlM0=
+// URL url = new URL("http://keking.ufile.ucloud.com.cn/20171101150322_运费贷信审资料(给予客户收集版).xlsx?UCloudPublicKey=ucloudtangshd@weifenf.com14355492830001993909323&Expires=&Signature=RRVFIICITMNFed1LQgB10WdKHiE=");
+ HttpURLConnection conn = (HttpURLConnection)url.openConnection();
+ //设置超时间为3秒
+ conn.setConnectTimeout(3*1000);
+ //防止屏蔽程序抓取而返回403错误
+ conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
+ //得到输入流
+ InputStream inputStream = conn.getInputStream();
+ HSSFWorkbook excelBook = new HSSFWorkbook(inputStream);
+ ExcelToHtmlConverter excelToHtmlConverter = new ExcelToHtmlConverter(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument());
+ excelToHtmlConverter.processWorkbook(excelBook);
+ List pics = excelBook.getAllPictures();
+ if (pics != null) {
+ for (int i = 0; i < pics.size(); i++) {
+ Picture pic = (Picture) pics.get(i);
+ try {
+ pic.writeImageContent(new FileOutputStream(path + pic.suggestFullFileName()));
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ Document htmlDocument = excelToHtmlConverter.getDocument();
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+ DOMSource domSource = new DOMSource(htmlDocument);
+ StreamResult streamResult = new StreamResult(outStream);
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer serializer = tf.newTransformer();
+ serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
+ serializer.setOutputProperty(OutputKeys.INDENT, "yes");
+ serializer.setOutputProperty(OutputKeys.METHOD, "html");
+ serializer.transform(domSource, streamResult);
+ outStream.close();
+
+ String content = new String(outStream.toByteArray());
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ } catch (TransformerException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * excel07转html
+ * filename:要读取的文件所在文件夹
+ * filepath:文件名
+ * htmlname:生成html名称
+ * path:html存放路径
+ * */
+ public static void excelToHtml () throws Exception{
+ String htmlname="exportExcel"+"07Test"+".html";
+
+
+ URL url = new URL("http://keking.ufile.ucloud.com.cn/20171101150322_运费贷信审资料(给予客户收集版).xlsx?UCloudPublicKey=ucloudtangshd@weifenf.com14355492830001993909323&Expires=&Signature=RRVFIICITMNFed1LQgB10WdKHiE=");
+ HttpURLConnection conn = (HttpURLConnection)url.openConnection();
+ //设置超时间为3秒
+ conn.setConnectTimeout(3*1000);
+ //防止屏蔽程序抓取而返回403错误
+ conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
+ //得到输入流
+ InputStream is = conn.getInputStream();
+
+ Workbook workbook = null;
+// InputStream is = new FileInputStream(filename+"/"+filepath);
+ try {
+ String html="";
+ workbook = new XSSFWorkbook(is);
+ for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) {
+ Sheet sheet = workbook.getSheetAt(numSheet);
+ if (sheet == null) {
+ continue;
+ }
+ html+="=======================" + sheet.getSheetName() + "=========================
";
+
+ int firstRowIndex = sheet.getFirstRowNum();
+ int lastRowIndex = sheet.getLastRowNum();
+ html+="";
+ Row firstRow = sheet.getRow(firstRowIndex);
+ for (int i = firstRow.getFirstCellNum(); i <= firstRow.getLastCellNum(); i++) {
+ Cell cell = firstRow.getCell(i);
+ String cellValue = getCellValue(cell, true);
+ html+="" + cellValue + " | ";
+ }
+
+
+ //行
+ for (int rowIndex = firstRowIndex + 1; rowIndex <= lastRowIndex; rowIndex++) {
+ Row currentRow = sheet.getRow(rowIndex);
+ html+="";
+ if(currentRow!=null){
+
+ int firstColumnIndex = currentRow.getFirstCellNum();
+ int lastColumnIndex = currentRow.getLastCellNum();
+ //列
+ for (int columnIndex = firstColumnIndex; columnIndex <= lastColumnIndex; columnIndex++) {
+ Cell currentCell = currentRow.getCell(columnIndex);
+ String currentCellValue = getCellValue(currentCell, true);
+ html+=""+currentCellValue + " | ";
+ }
+ }else{
+ html+=" ";
+ }
+ html+="
";
+ }
+ html+="
";
+
+
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+ DOMSource domSource = new DOMSource ();
+ StreamResult streamResult = new StreamResult (outStream);
+
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer serializer = tf.newTransformer();
+ serializer.setOutputProperty (OutputKeys.ENCODING, "utf-8");
+ serializer.setOutputProperty (OutputKeys.INDENT, "yes");
+ serializer.setOutputProperty (OutputKeys.METHOD, "html");
+ serializer.transform (domSource, streamResult);
+ outStream.close();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ * 读取单元格
+ *
+ */
+ private static String getCellValue(Cell cell, boolean treatAsStr) {
+ if (cell == null) {
+ return "";
+ }
+
+ if (treatAsStr) {
+ cell.setCellType(Cell.CELL_TYPE_STRING);
+ }
+
+ if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
+ return String.valueOf(cell.getBooleanCellValue());
+ } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
+ return String.valueOf(cell.getNumericCellValue());
+ } else {
+ return String.valueOf(cell.getStringCellValue());
+ }
+ }
+}
diff --git a/src/main/java/com/yudianbank/utils/ShedulerClean.java b/src/main/java/com/yudianbank/utils/ShedulerClean.java
new file mode 100644
index 000000000..761a464df
--- /dev/null
+++ b/src/main/java/com/yudianbank/utils/ShedulerClean.java
@@ -0,0 +1,19 @@
+package com.yudianbank.utils;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.io.File;
+
+@Component
+public class ShedulerClean {
+ @Value("${file.dir}")
+ String fileDir;
+
+ @Scheduled(cron = "0 0 23 * * ?") //每晚23点执行一次
+ public void clean(){
+ System.out.println("执行一次清空文件夹");
+ DeleteFileUtil.deleteDirectory(fileDir);
+ }
+}
diff --git a/src/main/java/com/yudianbank/utils/WordToHtml.java b/src/main/java/com/yudianbank/utils/WordToHtml.java
new file mode 100644
index 000000000..9184e28d1
--- /dev/null
+++ b/src/main/java/com/yudianbank/utils/WordToHtml.java
@@ -0,0 +1,61 @@
+package com.yudianbank.utils;
+
+import java.io.*;
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.ToDoubleFunction;
+import java.util.function.ToIntFunction;
+import java.util.function.ToLongFunction;
+
+import com.github.junrar.Archive;
+import com.github.junrar.exception.RarException;
+import com.github.junrar.rarfile.FileHeader;
+import org.apache.commons.compress.archivers.ArchiveException;
+import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
+import org.apache.commons.compress.archivers.zip.ZipFile;
+import org.apache.poi.xwpf.converter.core.FileImageExtractor;
+import org.apache.poi.xwpf.converter.core.FileURIResolver;
+import org.apache.poi.xwpf.converter.xhtml.XHTMLConverter;
+import org.apache.poi.xwpf.converter.xhtml.XHTMLOptions;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+
+public class WordToHtml {
+ /** 这是2007版本 转html 已测试成功的代码 07和03版要用两种代码转 但因为后面说要用
+ * 38 * 2007版本word转换成html
+ * 39 * @throws IOException
+ * 40
+ */
+
+ public static String Word2007ToHtml(InputStream inputStream) throws IOException {
+ // 1) 加载word文档生成 XWPFDocument对象
+ XWPFDocument document = new XWPFDocument(inputStream);
+
+ // 2) 解析 XHTML配置 (这里设置IURIResolver来设置图片存放的目录)
+// File imageFolderFile = new File("/Users/zuoxiaohui/IdeaProjects/yudian-preview-boot/yudian-preview-boot/src/main/resources/picture/");
+ File imageFolderFile = new File("/Users/zuoxiaohui/IdeaProjects/yudian-preview-boot/yudian-preview-boot/src/main/resources/static/");
+ XHTMLOptions options = XHTMLOptions.create().URIResolver(new FileURIResolver(imageFolderFile));
+ options.setExtractor(new FileImageExtractor(imageFolderFile));
+ options.setIgnoreStylesIfUnused(false);
+ options.setFragment(true);
+
+ File file = new File("/Users/zuoxiaohui/Test/" + "test.html");
+ // 3) 将 XWPFDocument转换成XHTML
+ OutputStream out = new FileOutputStream(file);
+ XHTMLConverter.getInstance().convert(document, out, options);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ XHTMLConverter.getInstance().convert(document, baos, options);
+ String content = baos.toString();
+ System.out.println(content);
+ baos.close();
+ return content;
+
+
+ }
+
+ public static void main(String[] args) throws IOException, ArchiveException, RarException {
+ File file = new File("C:\\Users\\yudian-it\\Downloads\\Downloads.zip");
+ System.out.println("Objects.equals(new Integer(1000), new Integer(1000)) :" + Objects.equals(new Integer(1000), new Integer(1000)));
+ System.out.println(Integer.valueOf("-129") == Integer.valueOf("-129"));
+ }
+
+}
diff --git a/src/main/java/com/yudianbank/utils/ZipReader.java b/src/main/java/com/yudianbank/utils/ZipReader.java
new file mode 100644
index 000000000..2f774eac3
--- /dev/null
+++ b/src/main/java/com/yudianbank/utils/ZipReader.java
@@ -0,0 +1,392 @@
+package com.yudianbank.utils;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.github.junrar.Archive;
+import com.github.junrar.exception.RarException;
+import com.github.junrar.rarfile.FileHeader;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
+import org.apache.commons.compress.archivers.zip.ZipFile;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import java.io.*;
+import java.util.*;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ *
+ * @author yudian-it
+ * @date 2017/11/27
+ */
+@Component
+public class ZipReader {
+
+ @Autowired
+ FileUtils fileUtils;
+ @Value("${file.dir}")
+ String fileDir;
+
+ ExecutorService executors = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
+
+ /**
+ * 读取压缩文件
+ * 文件压缩到统一目录fileDir下,并且命名使用压缩文件名+文件名因为文件名
+ * 可能会重复(在系统中对于同一种类型的材料压缩文件内的文件是一样的,如果文件名
+ * 重复,那么这里会被覆盖[同一个压缩文件中的不同目录中的相同文件名暂时不考虑])
+ * 注:
+ *
+ * 文件名命名中的参数的说明:
+ * 1.archiveName,为避免解压的文件中有重名的文件会彼此覆盖,所以加上了archiveName,因为在ufile中archiveName
+ * 是不会重复的。
+ * 2.level,这里层级结构的列表我是通过一个map来构造的,map的key是文件的名字,值是对应的文件,这样每次向map中
+ * 加入节点的时候都会获取父节点是否存在,存在则会获取父节点的value并将当前节点加入到父节点的childList中(这里利用
+ * 的是java语言的引用的特性)。
+ *
+ * @param filePath
+ */
+ public String readZipFile(String filePath) {
+ String archiveSeparator = "/";
+ Map appender = Maps.newHashMap();
+ String archiveFileName = fileUtils.getFileNameFromPath(filePath);
+ try {
+ ZipFile zipFile = new ZipFile(filePath, fileUtils.getFileEncodeUTFGBK(filePath));
+ Enumeration entries = zipFile.getEntries();
+ // 排序
+ entries = sortZipEntries(entries);
+ List