去除BaseDocumentService,方法都放到DocumentService

This commit is contained in:
2025-07-01 16:16:21 +08:00
parent 2be1b4acf9
commit 5e0c59f2f5
7 changed files with 86 additions and 146 deletions

View File

@@ -45,33 +45,28 @@
<build>
<plugins>
<!-- 1. 使用 maven-jar-plugin 打包当前模块的代码(不含依赖) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<!-- 可选:指定主类(如果需要可执行) -->
<archive>
<manifest>
<mainClass>com.example.MyApp</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- 2. 使用 maven-source-plugin 生成源码 JAR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<id>copy-resources</id>
<phase>process-resources</phase>
<goals>
<goal>jar-no-fork</goal>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>application.yml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

View File

@@ -9,6 +9,9 @@ import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
@Component
public class DocumentConverter {
@@ -29,10 +32,19 @@ public class DocumentConverter {
targetFile.delete();
}
String sourceExtension = sourceFile.getName().substring(sourceFile.getName().lastIndexOf("."));
String targetExtension = targetFile.getName().substring(targetFile.getName().lastIndexOf("."));
Map<String, Object> params = new HashMap<>();
params.put("callerName", "张三");
byte[] converted = documentService.convert(Files.readAllBytes(sourceFile.toPath()), sourceExtension, targetExtension);
Files.write(targetFile.toPath(), converted);
// 生成word并转为pdf
byte[] generatedWord = documentService.generateWord(Files.readAllBytes(sourceFile.toPath()), params);
byte[] wordedToPdf = documentService.wordToPdf(generatedWord, true);
Path pdfPath = targetFile.toPath();
Files.write(pdfPath, wordedToPdf);
// 生成的word转为图片
byte[] wordedToImage = documentService.wordToImage(generatedWord, "jpg");
File imageFile = new File(targetFile.getAbsolutePath().replace(".pdf", ".jpg"));
Path imagePath = imageFile.toPath();
Files.write(imagePath, wordedToImage);
}
}