增加测试项目
This commit is contained in:
80
document-test/pom.xml
Normal file
80
document-test/pom.xml
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.optima</groupId>
|
||||||
|
<artifactId>document</artifactId>
|
||||||
|
<version>2.0.0</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>document-test</artifactId>
|
||||||
|
<name>Document Test</name>
|
||||||
|
<description>文档操作测试</description>
|
||||||
|
<properties>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<!-- 引入文档操作API -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.optima</groupId>
|
||||||
|
<artifactId>document-api</artifactId>
|
||||||
|
<version>2.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 基础 Spring Boot Starter(不包含 Web) -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
<version>2.7.18</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 仅引入 spring-web(不引入 Tomcat/MVC) -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-web</artifactId>
|
||||||
|
<version>5.3.31</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 简化Getter/Setter -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.16.20</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-sources</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>jar-no-fork</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.optima.document.test;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class DocumentServerTest {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(DocumentServerTest.class, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.optima.document.test.bean;
|
||||||
|
|
||||||
|
import com.optima.document.api.DocumentService;
|
||||||
|
import com.optima.document.test.config.DocumentServiceConfig;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DocumentConverter {
|
||||||
|
@Resource
|
||||||
|
private DocumentServiceConfig documentServiceConfig;
|
||||||
|
@Resource
|
||||||
|
private DocumentService documentService;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() throws IOException {
|
||||||
|
String sourceFilePath = documentServiceConfig.getSourceFile();
|
||||||
|
String targetFilePath = documentServiceConfig.getTargetFile();
|
||||||
|
|
||||||
|
File sourceFile = new File(sourceFilePath);
|
||||||
|
File targetFile = new File(targetFilePath);
|
||||||
|
|
||||||
|
if (targetFile.exists()) {
|
||||||
|
targetFile.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
String sourceExtension = sourceFile.getName().substring(sourceFile.getName().lastIndexOf("."));
|
||||||
|
String targetExtension = targetFile.getName().substring(targetFile.getName().lastIndexOf("."));
|
||||||
|
|
||||||
|
byte[] converted = documentService.convert(Files.readAllBytes(sourceFile.toPath()), sourceExtension, targetExtension);
|
||||||
|
Files.write(targetFile.toPath(), converted);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.optima.document.test.config;
|
||||||
|
|
||||||
|
import com.optima.document.api.DocumentService;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
|
||||||
|
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "document")
|
||||||
|
public class DocumentServiceConfig {
|
||||||
|
private String server;
|
||||||
|
private String sourceFile;
|
||||||
|
private String targetFile;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Bean
|
||||||
|
public DocumentService documentService() {
|
||||||
|
// 创建客户端代理
|
||||||
|
HttpInvokerProxyFactoryBean factoryBean = new HttpInvokerProxyFactoryBean();
|
||||||
|
String serviceUrl;
|
||||||
|
if (server.endsWith("/")) {
|
||||||
|
serviceUrl = server + "document-service";
|
||||||
|
} else {
|
||||||
|
serviceUrl = server + "/document-service";
|
||||||
|
}
|
||||||
|
factoryBean.setServiceUrl(serviceUrl);
|
||||||
|
factoryBean.setServiceInterface(DocumentService.class);
|
||||||
|
factoryBean.afterPropertiesSet();
|
||||||
|
|
||||||
|
return (DocumentService) factoryBean.getObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
4
document-test/src/main/resources/application.yml
Normal file
4
document-test/src/main/resources/application.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
document:
|
||||||
|
server: http://127.0.0.1:9004
|
||||||
|
source-file: /Users/yanghuanglin/Downloads/test.docx
|
||||||
|
target-file: /Users/yanghuanglin/Downloads/test.pdf
|
||||||
1
pom.xml
1
pom.xml
@@ -10,6 +10,7 @@
|
|||||||
<description>文档操作模块</description>
|
<description>文档操作模块</description>
|
||||||
<modules>
|
<modules>
|
||||||
<module>document-api</module>
|
<module>document-api</module>
|
||||||
|
<module>document-test</module>
|
||||||
<module>document-server</module>
|
<module>document-server</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user