提交 54b7058e authored 作者: yucaiwei's avatar yucaiwei

--no commit message

上级 01cf8854
......@@ -20,6 +20,8 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
......@@ -51,6 +53,7 @@ import com.zrqx.core.model.file.FileInfo;
import com.zrqx.core.util.datatype.ArrayUtils;
import com.zrqx.core.util.datatype.UUIDUtil;
import com.zrqx.core.util.download.DownloadUtil;
import com.zrqx.core.util.file.Txt2Pdf;
import com.zrqx.core.util.page.PageInfo;
import com.zrqx.core.util.page.PageParam;
import com.zrqx.core.util.response.CallBack;
......@@ -94,6 +97,15 @@ public class FileController {
if(!service.insert(entity)){
throw new BaseException("上传失败!");
}
// 文件解析
String suffix = entity.getSuffixName();
if(suffix.equalsIgnoreCase(".txt") || suffix.equalsIgnoreCase(".pdf")){
String filePath = rootPath + entity.getPath() + "/" + entity.getFileName() + entity.getSuffixName();
String pdfPath = rootPath + entity.getPath() + "/" + entity.getFileName() + ".pdf";
entity.setPdfPath("/" + entity.getPath() + "/" + entity.getFileName() + ".pdf");
// 文件2pdf
this.file2Pdf(filePath, pdfPath);
}
return entity;
}
// 处理文件上传
......@@ -742,4 +754,23 @@ public class FileController {
}
return response;
}
private void file2Pdf(String filePath, String pdfPath){
ExecutorService executor = Executors.newCachedThreadPool();
executor.submit(() -> {
Boolean isTrue = false;
String suffix = filePath.substring(filePath.lastIndexOf("."), filePath.length());
if(suffix.equalsIgnoreCase(".txt")){
logger.info("开始转换txt:"+filePath+"-----"+pdfPath);
File file = new File(filePath);
logger.info("文件大小:"+file.length());
isTrue = Txt2Pdf.txtToPdf(filePath, pdfPath);
logger.info("isTrue:"+isTrue);
}
if(isTrue){
logger.info(filePath.subSequence(filePath.lastIndexOf("/") + 1, filePath.length())+"成功转换成pdf");
}
});
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论