Merge remote-tracking branch 'origin/master'

This commit is contained in:
liyawei
2022-06-10 09:43:18 +08:00
7 changed files with 121 additions and 30 deletions
@@ -1729,7 +1729,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
String wordContent = null; String wordContent = null;
try { try {
wordContent = ReadWordUtil.readWord(ossFile.getUrl()); wordContent = ReadWordUtil.readWord(ossFile.getUrl(),uploadpath);
} catch (Exception e) { } catch (Exception e) {
log.error("文档库: 读取word内容失败"); log.error("文档库: 读取word内容失败");
} }
@@ -1872,7 +1872,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|| ossFile.getFileName().endsWith(".DOCX")) { || ossFile.getFileName().endsWith(".DOCX")) {
String wordContent = null; String wordContent = null;
try { try {
wordContent = ReadWordUtil.readWord(ossFile.getUrl()); wordContent = ReadWordUtil.readWord(ossFile.getUrl(),uploadpath);
} catch (Exception e) { } catch (Exception e) {
log.error("文档库:读取word内容失败"); log.error("文档库:读取word内容失败");
} }
@@ -2665,7 +2665,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|| ossFile.getFileName().endsWith(".DOCX")) { || ossFile.getFileName().endsWith(".DOCX")) {
String wordContent = null; String wordContent = null;
try { try {
wordContent = ReadWordUtil.readWord(ossFile.getUrl()); wordContent = ReadWordUtil.readWord(ossFile.getUrl(),uploadpath);
} catch (Exception e) { } catch (Exception e) {
log.error("文档库:读取word文件内容失败"); log.error("文档库:读取word文件内容失败");
} }
@@ -5715,7 +5715,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
public String getTitle(String id,String cut) { public String getTitle(String id,String cut) {
LambdaQueryWrapper<BussDocumentLibraryEO> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<BussDocumentLibraryEO> wrapper = new LambdaQueryWrapper<>();
wrapper.in(BussDocumentLibraryEO::getId,id); wrapper.in(BussDocumentLibraryEO::getId,id);
List<Map<String, Object>> mapList = this.listMaps(); List<Map<String, Object>> mapList = this.listMaps(wrapper);
String title = ""; String title = "";
if(mapList.size() != 0){ if(mapList.size() != 0){
if(CutEnum.CN.getValue().equals(cut)){ if(CutEnum.CN.getValue().equals(cut)){
@@ -1,13 +1,13 @@
package com.jero.modules.document.utils; package com.jero.modules.document.utils;
import com.jero.common.exception.JeroBootException; import com.jero.common.exception.JeroBootException;
import com.jero.common.util.oss.CosBootUtil;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException;
import org.apache.pdfbox.text.PDFTextStripper; import org.apache.pdfbox.text.PDFTextStripper;
import org.apache.pdfbox.text.PDFTextStripperByArea; import org.apache.pdfbox.text.PDFTextStripperByArea;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
/** /**
* @description * @description
@@ -17,24 +17,48 @@ import java.io.IOException;
public class ReadPdfUtil { public class ReadPdfUtil {
public static String readPdf(String path) { public static String readPdf(String path) {
// path="E:\\DeskTop\\4444.pdf"; if(CosBootUtil.doesObjectExist(path)){
try (PDDocument document = PDDocument.load(new File(path))) { InputStream in = CosBootUtil.download(path);
document.getClass(); try (PDDocument document = PDDocument.load(in)) {
document.getClass();
// if(!document.isEncrypted()) { // if(!document.isEncrypted()) {
PDFTextStripperByArea stripper = new PDFTextStripperByArea(); PDFTextStripperByArea stripper = new PDFTextStripperByArea();
stripper.setSortByPosition(true); stripper.setSortByPosition(true);
PDFTextStripper tStripper = new PDFTextStripper(); PDFTextStripper tStripper = new PDFTextStripper();
String pdfFileInText = tStripper.getText(document); String pdfFileInText = tStripper.getText(document);
return pdfFileInText; return pdfFileInText;
// String[] lines = pdfFileInText.split("\\r?\\n"); // String[] lines = pdfFileInText.split("\\r?\\n");
// for(String line : lines) { // for(String line : lines) {
// System.out.println(line); // System.out.println(line);
// } // }
// } // }
}catch (IOException e) { }catch (IOException e) {
throw new JeroBootException("文件内容读取失败"); throw new JeroBootException("文件内容读取失败");
}
} }
return null;
} }
// public static String readPdf(String path) {
//// path="E:\\DeskTop\\4444.pdf";
// try (PDDocument document = PDDocument.load(new File(path))) {
// document.getClass();
//// if(!document.isEncrypted()) {
// PDFTextStripperByArea stripper = new PDFTextStripperByArea();
// stripper.setSortByPosition(true);
// PDFTextStripper tStripper = new PDFTextStripper();
//
// String pdfFileInText = tStripper.getText(document);
// return pdfFileInText;
//
//// String[] lines = pdfFileInText.split("\\r?\\n");
//// for(String line : lines) {
//// System.out.println(line);
//// }
//// }
// }catch (IOException e) {
// throw new JeroBootException("文件内容读取失败");
// }
// }
} }
@@ -1,6 +1,7 @@
package com.jero.modules.document.utils; package com.jero.modules.document.utils;
import com.jero.common.exception.JeroBootException; import com.jero.common.exception.JeroBootException;
import com.jero.common.util.oss.CosBootUtil;
import org.apache.poi.POIXMLDocument; import org.apache.poi.POIXMLDocument;
import org.apache.poi.POIXMLTextExtractor; import org.apache.poi.POIXMLTextExtractor;
import org.apache.poi.hwpf.extractor.WordExtractor; import org.apache.poi.hwpf.extractor.WordExtractor;
@@ -8,32 +9,50 @@ import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor; import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream; import java.io.InputStream;
import static com.jero.modules.document.service.impl.BussDocumentLibraryEOServiceImpl.copyFile;
/** /**
* @description * @description
* @date 2022/3/21 17:04 * @date 2022/3/21 17:04
* @auth zhn * @auth zhn
*/ */
public class ReadWordUtil { public class ReadWordUtil {
public static String readWord(String path,String uploadpath) {
public static String readWord(String path) {
// String path = "E:\\DeskTop\\1111.doc"; // String path = "E:\\DeskTop\\1111.doc";
// path = "E:\\DeskTop\\22222.docx"; // path = "E:\\DeskTop\\22222.docx";
// String path = "E:\\DeskTop\\标准所ISO-用户手册.doc"; // String path = "E:\\DeskTop\\标准所ISO-用户手册.doc";
String str = ""; String str = "";
try { try {
if (path.endsWith(".doc")) { if (path.endsWith(".doc")) {
InputStream is = new FileInputStream(new File(path)); if(CosBootUtil.doesObjectExist(path)){
WordExtractor ex = new WordExtractor(is); InputStream in = CosBootUtil.download(path);
str = ex.getText(); WordExtractor ex = new WordExtractor(in);
ex.close(); str = ex.getText();
ex.close();
}
} else if (path.endsWith("docx")) { } else if (path.endsWith("docx")) {
OPCPackage opcPackage = POIXMLDocument.openPackage(path); //先把文件存到本地, 用完后在删除
POIXMLTextExtractor extractor = new XWPFWordExtractor(opcPackage); if(CosBootUtil.doesObjectExist(path)){
str = extractor.getText(); InputStream in = CosBootUtil.download(path);
extractor.close(); String fileNowPath = uploadpath + "/tempZip/" ;
File file = new File(fileNowPath);
if (file.exists()) {
file.delete();
}
file.mkdirs();
File fileOld = new File(path);
long currentTime = System.currentTimeMillis();
copyFile(in, fileNowPath + File.separator + currentTime + fileOld.getName());
File fileTemp = new File(fileNowPath + File.separator + currentTime + fileOld.getName());
String pathTemp = fileTemp.getPath();
OPCPackage opcPackage = POIXMLDocument.openPackage(pathTemp);
POIXMLTextExtractor extractor = new XWPFWordExtractor(opcPackage);
str = extractor.getText().trim();
extractor.close();
fileTemp.delete();
}
} else { } else {
throw new JeroBootException("此文件不是word文件"); throw new JeroBootException("此文件不是word文件");
} }
@@ -44,4 +63,30 @@ public class ReadWordUtil {
throw new JeroBootException("文件内容读取失败"); throw new JeroBootException("文件内容读取失败");
} }
} }
// public static String readWord(String path) {
//// String path = "E:\\DeskTop\\1111.doc";
//// path = "E:\\DeskTop\\22222.docx";
//// String path = "E:\\DeskTop\\标准所ISO-用户手册.doc";
// String str = "";
// try {
// if (path.endsWith(".doc")) {
// InputStream is = new FileInputStream(new File(path));
// WordExtractor ex = new WordExtractor(is);
// str = ex.getText();
// ex.close();
// } else if (path.endsWith("docx")) {
// OPCPackage opcPackage = POIXMLDocument.openPackage(path);
// POIXMLTextExtractor extractor = new XWPFWordExtractor(opcPackage);
// str = extractor.getText();
// extractor.close();
// } else {
// throw new JeroBootException("此文件不是word文件");
// }
// return str;
// } catch (Exception e) {
// throw new JeroBootException("文件内容读取失败");
// }catch (NoSuchFieldError e){
// throw new JeroBootException("文件内容读取失败");
// }
// }
} }
@@ -231,7 +231,6 @@ public class DummyInventoryInfoEOEn implements Serializable {
private String verifyDeliverableType; private String verifyDeliverableType;
/**验证符合性确认-交付物模板*/ /**验证符合性确认-交付物模板*/
@ApiModelProperty(value = "验证符合性确认-交付物模板") @ApiModelProperty(value = "验证符合性确认-交付物模板")
private String verifyDeliverableTemplate; private String verifyDeliverableTemplate;
@@ -5322,7 +5322,6 @@ public class ProjectLawsInventoryEOServiceImpl extends ServiceImpl<ProjectLawsIn
*/ */
@Override @Override
public void downloadDocxReport(Map<String, Object> params, HttpServletRequest req, HttpServletResponse resp) { public void downloadDocxReport(Map<String, Object> params, HttpServletRequest req, HttpServletResponse resp) {
File templateFile = null;
File exportFile = null; File exportFile = null;
InputStream fin = null; InputStream fin = null;
ServletOutputStream out = null; ServletOutputStream out = null;
@@ -5463,7 +5462,27 @@ public class ProjectLawsInventoryEOServiceImpl extends ServiceImpl<ProjectLawsIn
dataMap.put("REGULATION_ENG", StringUtils.isNotEmpty(regulationOwnerName) ? regulationOwnerName : ""); dataMap.put("REGULATION_ENG", StringUtils.isNotEmpty(regulationOwnerName) ? regulationOwnerName : "");
log.debug("导出word报告,查询数据结束 ============================================================================="); log.debug("导出word报告,查询数据结束 =============================================================================");
log.debug("导出word报告,获取模板开始 ============================================================================="); log.debug("导出word报告,获取模板开始 =============================================================================");
templateFile = new File(exportPdfTempPath + "temp/ComplianceReportTemplate.docx"); File templateFile = new File(exportPdfTempPath + "temp/ComplianceReportTemplate.docx");
InputStream inputStream = ProjectLawsInventoryEOServiceImpl.class.getClassLoader().getResourceAsStream("exportPdfTemp/ComplianceReportTemplate.docx");
try {
FileUtils.copyInputStreamToFile(inputStream, templateFile);
} catch (IOException e) {
e.printStackTrace();
}
//
// try {
// OutputStream os = new FileOutputStream(templateFile);
// int bytesRead = 0;
// byte[] buffer = new byte[8192];
// while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {
// os.write(buffer, 0, bytesRead);
// }
// os.close();
// inputStream.close();
// } catch (Exception e) {
// e.printStackTrace();
// }
log.debug("导出word报告,获取模板结束 ============================================================================="); log.debug("导出word报告,获取模板结束 =============================================================================");
if(templateFile != null){ if(templateFile != null){
try { try {
@@ -5479,6 +5498,7 @@ public class ProjectLawsInventoryEOServiceImpl extends ServiceImpl<ProjectLawsIn
exportFile = new File(outFile); exportFile = new File(outFile);
FileOutputStream os = new FileOutputStream(outFile); FileOutputStream os = new FileOutputStream(outFile);
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new FileInputStream(templateFile)); WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new FileInputStream(templateFile));
// WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(inputStream);
//验证符合性流程实例id //验证符合性流程实例id
String verifyPId = projectTaskInventoryEO.getVerifyPId(); String verifyPId = projectTaskInventoryEO.getVerifyPId();
+3
View File
@@ -355,6 +355,9 @@
<nonFilteredFileExtension>eot</nonFilteredFileExtension> <nonFilteredFileExtension>eot</nonFilteredFileExtension>
<nonFilteredFileExtension>ttf</nonFilteredFileExtension> <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
<nonFilteredFileExtension>svg</nonFilteredFileExtension> <nonFilteredFileExtension>svg</nonFilteredFileExtension>
<nonFilteredFileExtension>svg</nonFilteredFileExtension>
<nonFilteredFileExtension>doc</nonFilteredFileExtension>
<nonFilteredFileExtension>docx</nonFilteredFileExtension>
</nonFilteredFileExtensions> </nonFilteredFileExtensions>
</configuration> </configuration>
</plugin> </plugin>