Quellcode durchsuchen

Merge branch 'master' of http://47.100.37.243:10080/ZHOU/yunsu

# Conflicts:
#	cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldFileServiceImpl.java
vor 5 Jahren
Ursprung
Commit
2c2d525b91

+ 19 - 10
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldFileServiceImpl.java

@@ -120,7 +120,10 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                     //上传完,需要生成pdf
                     String dFile1 = path+UUID.randomUUID().toString().replaceAll("-", "")+".pdf";
                     openOfficeService.start();
-                    openOfficeService.office2PDF(path + fileName,dFile1);
+                    File testFile = new File(dFile1);
+                    if(!testFile .exists()){
+                        openOfficeService.office2PDF(path + fileName,dFile1);
+                    }
                     //模具报废情况下,设置files2
                     String dFile2 = "";
                     if (blongType == 5 && file2 != null && !file2.isEmpty()) {
@@ -139,7 +142,10 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                             saveFile2.createNewFile();
                             file2.transferTo(saveFile2);
                             dFile2 = path+UUID.randomUUID().toString().replaceAll("-", "")+".pdf";
-                            openOfficeService.office2PDF(path + fileName,dFile2);
+                             testFile = new File(dFile2);
+                            if(!testFile .exists()){
+                                openOfficeService.office2PDF(path + fileName,dFile2);
+                            }
                         } catch (IOException e) {
                             e.printStackTrace();
                             projectFile = null;
@@ -730,14 +736,17 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                     file.transferTo(saveFile);
                     //上传完,需要生成pdf
                     String dFile1 = path+UUID.randomUUID().toString().replaceAll("-", "")+".pdf";
-                    openOfficeService.office2PDF(path + fileName,dFile1);
-                    PdfFile pdfFile = new PdfFile();
-                    pdfFile.setPdfUrl("/upload/"+dFile1);
-                    pdfFile.setFileId(partFile.getId());
-                    pdfFile.setType(1);
-                    pdfFile.setRafId(partFile.getModelId());
-                    pdfFile.setSourceFileUrl(partFile.getFileUrl());
-                    pdfFileMapper.insert(pdfFile);
+                    File newFile = new File(dFile1);
+                    if(!newFile .exists()){
+                        openOfficeService.office2PDF(path + fileName,dFile1);
+                        PdfFile pdfFile = new PdfFile();
+                        pdfFile.setPdfUrl("/upload/"+dFile1);
+                        pdfFile.setFileId(partFile.getId());
+                        pdfFile.setType(1);
+                        pdfFile.setRafId(partFile.getModelId());
+                        pdfFile.setSourceFileUrl(partFile.getFileUrl());
+                        pdfFileMapper.insert(pdfFile);
+                    }
                 } catch (IOException e) {
                     e.printStackTrace();
                     partFile = null;

+ 11 - 8
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/ProjectFileServiceImpl.java

@@ -83,14 +83,17 @@ public class ProjectFileServiceImpl extends ServiceImpl<ProjectFileMapper, Proje
                         //上传完,需要生成pdf
                         String dFile1 = path+UUID.randomUUID().toString().replaceAll("-", "")+".pdf";
                         openOfficeService.start();
-                        openOfficeService.office2PDF(path + fileName,dFile1);
-                        PdfFile pdfFile = new PdfFile();
-                        pdfFile.setPdfUrl("/upload/"+dFile1);
-                        pdfFile.setFileId(projectFile.getId());
-                        pdfFile.setType(1);
-                        pdfFile.setRafId(projectFile.getProjectId());
-                        pdfFile.setSourceFileUrl(projectFile.getUrl());
-                        pdfFileMapper.insert(pdfFile);
+                        File newFile = new File(dFile1);
+                        if(!newFile .exists()){
+                            openOfficeService.office2PDF(path + fileName,dFile1);
+                            PdfFile pdfFile = new PdfFile();
+                            pdfFile.setPdfUrl("/upload/"+dFile1);
+                            pdfFile.setFileId(projectFile.getId());
+                            pdfFile.setType(1);
+                            pdfFile.setRafId(projectFile.getProjectId());
+                            pdfFile.setSourceFileUrl(projectFile.getUrl());
+                            pdfFileMapper.insert(pdfFile);
+                        }
                         openOfficeService.shutdown();
                     } catch (IOException e) {
                         e.printStackTrace();

+ 9 - 3
cloud-model/src/main/java/com/hssx/cloudmodel/util/OpenOfficeService.java

@@ -67,7 +67,7 @@ public class OpenOfficeService {
 	 * @param destFile
 	 * @return 0-转换成,-1转换失败
 	 */
-	public static int office2PDF(String inputFilePath, String destFile) {
+	public  int office2PDF(String inputFilePath, String destFile) {
 		//txt后缀需要改成odt再进行转换
 		if (inputFilePath.endsWith(".txt")) {
 			String tempFilePath = inputFilePath.replaceAll(".txt", ".odt");
@@ -108,9 +108,15 @@ public class OpenOfficeService {
 	public static void main(String[] args) {
 		OpenOfficeService service = new OpenOfficeService();
 		String sFile = "D:\\wttxls.xls";
-		String dFile = "D:\\wttxls555.pdf";
+		String dFile = "D:\\wttxls.pdf";
 		service.start();
-		service.office2PDF(sFile,dFile);
+		File testFile = new File(dFile);
+		if(!testFile .exists()){
+			System.out.println("测试文件不存在,开始转换......");
+			service.office2PDF(sFile,dFile);
+		}else{
+			System.out.println("测试文件已存在");
+		}
 		service.shutdown();
 	}
 }