[测评系统]--测评系统核心代码库
linzhijie
2023-05-17 ce7c778150b82b7106e9edebbb6d69036bd389f3
src/main/java/com/ots/project/tool/ShellTool.java
@@ -1,10 +1,41 @@
package com.ots.project.tool;
import com.ots.common.utils.spring.SpringUtils;
import com.ots.common.utils.text.CharsetKit;
import com.ots.project.tool.libreoffice.Office2PDFUtils;
import lombok.extern.slf4j.Slf4j;
import org.jodconverter.core.DocumentConverter;
import org.jodconverter.core.office.OfficeException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.io.*;
import java.util.concurrent.ScheduledExecutorService;
@Slf4j
@Component
public class ShellTool {
//    @Autowired
//    private DocumentConverter documentConverter;
    @Autowired
    private Office2PDFUtils office2PDFUtils;
    private static ShellTool shellTool;
    @PostConstruct
    public void init(){
        shellTool = this;
        //shellTool.documentConverter = documentConverter;
        shellTool.office2PDFUtils = office2PDFUtils;
    }
    public static ShellTool builder(){
        return shellTool;
    }
    public static String execLibreofficeCommand(String type, String sourcePath, String targetPath) {
        String os = System.getProperty("os.name");
        StringBuilder builder = new StringBuilder();
@@ -25,10 +56,18 @@
                file.delete();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info("执行命令:{}",builder.toString());
        return exec(builder.toString());
    }
    public static void execNewLibreofficeCommand(String type, String sourcePath, String targetPath) throws OfficeException {
        //使用文件方式转换成PDF
        //shellTool.documentConverter.convert(new File(sourcePath)).to(new File(targetPath)).execute();
        shellTool.office2PDFUtils.office2Pdf(sourcePath,targetPath);
    }
    private static String exec(String command) {
        String returnString = "";
        Runtime runTime = Runtime.getRuntime();