-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jarrett
committed
Nov 10, 2024
1 parent
8b864c0
commit 69d4077
Showing
9 changed files
with
263 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ public enum DocType { | |
PDF, | ||
// word文档 | ||
DOCX, | ||
PPT, | ||
PPTX, | ||
XLSX, | ||
// txt类的文档 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/com/jiaruiblog/task/executor/slider/PptExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.jiaruiblog.task.executor.slider; | ||
|
||
import com.jiaruiblog.entity.FileDocument; | ||
import com.jiaruiblog.entity.FileObj; | ||
import com.jiaruiblog.enums.FileFormatEnum; | ||
import com.jiaruiblog.task.data.TaskData; | ||
import com.jiaruiblog.task.exception.TaskRunException; | ||
import com.jiaruiblog.task.executor.TaskExecutor; | ||
import com.jiaruiblog.util.poi.Converter; | ||
import com.jiaruiblog.util.poi.PPTUtil; | ||
import com.jiaruiblog.util.poi.PptxToPDFConverter; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.UUID; | ||
|
||
import static com.jiaruiblog.task.executor.slider.PptxExecutor.getOutFileStream; | ||
|
||
/** | ||
* <p></p> | ||
* edit at 2024/11/11 6:47 | ||
* | ||
* @author Jarrett Luo | ||
* @version 1.0 | ||
*/ | ||
public class PptExecutor extends TaskExecutor { | ||
|
||
@Override | ||
protected void readText(InputStream is, String textFilePath) throws IOException { | ||
|
||
} | ||
|
||
@Override | ||
protected void makeThumb(InputStream is, String picPath) throws IOException { | ||
PPTUtil.extractFirstPPT(is, picPath); | ||
} | ||
|
||
@Override | ||
protected void makePreviewFile(InputStream inStream, TaskData taskData) { | ||
taskData.setPreviewFilePath(UUID.randomUUID() + ".pdf"); | ||
try { | ||
OutputStream outStream = getOutFileStream(taskData.getPreviewFilePath()); | ||
Converter converter = new PptxToPDFConverter(inStream, outStream, true, | ||
true); | ||
converter.convert(); | ||
} catch (Exception e) { | ||
throw new TaskRunException("转换预览文件报错", e); | ||
} | ||
// 解析出来的预览文件存储到文件系统中 | ||
String objId = saveFileToDFS(taskData.getPreviewFilePath(), FileFormatEnum.PDF, "preview-"); | ||
FileDocument fileDocument = taskData.getFileDocument(); | ||
fileDocument.setPreviewFileId(objId); | ||
} | ||
|
||
public void uploadFileToEs(InputStream is, FileDocument fileDocument, TaskData taskData) { | ||
try { | ||
FileObj fileObj = new FileObj(); | ||
fileObj.setId(fileDocument.getMd5()); | ||
fileObj.setName(fileDocument.getName()); | ||
fileObj.setType(fileDocument.getContentType()); | ||
fileObj.readFile(is); | ||
this.upload(fileObj); | ||
|
||
} catch (IOException | TaskRunException e) { | ||
throw new TaskRunException("存入es的过程中报错了", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.