Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 26191b8

Browse files
Java: MultiDataSource 新增支持 CVAuto 导出测试报告 Excel 表格,解决 /delegate 代理接口调用次数过多后报错 500
1 parent 750ba8e commit 26191b8

File tree

7 files changed

+601
-11
lines changed

7 files changed

+601
-11
lines changed

‎APIJSON-Java-Server/APIJSONBoot-MultiDataSource/pom.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,33 @@
372372
<!-- <artifactId>moql-querier</artifactId>-->
373373
<!-- <version>1.2.3</version>-->
374374
<!-- <scope>compile</scope>-->
375+
<!-- </dependency>-->
376+
<dependency>
377+
<groupId>com.alibaba</groupId>
378+
<artifactId>easyexcel</artifactId>
379+
<version>4.0.3</version>
380+
<!-- <exclusions>-->
381+
<!-- <exclusion>-->
382+
<!-- <groupId>org.apache.poi</groupId>-->
383+
<!-- <artifactId>poi-ooxml-schemas</artifactId>-->
384+
<!-- </exclusion>-->
385+
<!-- <exclusion>-->
386+
<!-- <groupId>org.apache.xmlbeans</groupId>-->
387+
<!-- <artifactId>xmlbeans</artifactId>-->
388+
<!-- </exclusion>-->
389+
<!-- </exclusions>-->
390+
</dependency>
391+
392+
<!-- &lt;!&ndash; 重新引入合适版本 &ndash;&gt;-->
393+
<!-- <dependency>-->
394+
<!-- <groupId>org.apache.xmlbeans</groupId>-->
395+
<!-- <artifactId>xmlbeans</artifactId>-->
396+
<!-- <version>5.1.1</version>-->
397+
<!-- </dependency>-->
398+
<!-- <dependency>-->
399+
<!-- <groupId>org.apache.poi</groupId>-->
400+
<!-- <artifactId>poi-ooxml</artifactId>-->
401+
<!-- <version>5.2.5</version>-->
375402
<!-- </dependency>-->
376403

377404
</dependencies>
11.7 KB
Binary file not shown.
10.1 KB
Binary file not shown.
12.3 KB
Binary file not shown.

‎APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/java/apijson/ExcelUtil.java

Lines changed: 532 additions & 0 deletions
Large diffs are not rendered by default.

‎APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/java/apijson/boot/DemoController.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,20 +1858,22 @@ else if (recordType > 0) {
18581858
return rspBody;
18591859
}
18601860

1861+
public static final RestTemplate CLIENT = new RestTemplate();
1862+
static {
1863+
try { // 支持 PATCH 方法,需要 Maven 依赖 org.apache.httpcomponents.client5:httpclient5
1864+
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
1865+
CLIENT.setRequestFactory(requestFactory);
1866+
}
1867+
catch (Throwable e) {
1868+
e.printStackTrace();
1869+
}
1870+
}
1871+
18611872
protected String sendRequest(HttpSession session, HttpMethod method, String url, String body, HttpHeaders headers) {
18621873
String rspBody = null;
18631874
try {
1864-
RestTemplate client = new RestTemplate();
1865-
try { // 支持 PATCH 方法,需要 Maven 依赖 org.apache.httpcomponents.client5:httpclient5
1866-
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
1867-
client.setRequestFactory(requestFactory);
1868-
}
1869-
catch (Throwable e) {
1870-
e.printStackTrace();
1871-
}
1872-
18731875
HttpEntity<String> requestEntity = new HttpEntity<>(method == HttpMethod.GET ? null : body, headers);
1874-
ResponseEntity<String> entity = client.exchange(url, method, requestEntity, String.class);
1876+
ResponseEntity<String> entity = CLIENT.exchange(url, method, requestEntity, String.class);
18751877

18761878
HttpHeaders hhs = entity.getHeaders();
18771879
if (session != null && hhs != null) {

‎APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/java/apijson/boot/FileController.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
//import javax.annotation.PostConstruct;
1010

11+
import org.apache.commons.io.FileUtils;
1112
import org.springframework.core.io.InputStreamResource;
1213
import org.springframework.http.HttpHeaders;
1314
import org.springframework.http.MediaType;
@@ -68,6 +69,7 @@ public class FileController {
6869
}
6970
}
7071

72+
public static final List<String> VIDEO_SUFFIXES = Arrays.asList("mp4");
7173
public static final List<String> IMG_SUFFIXES = Arrays.asList("jpg", "jpeg", "png");
7274
private static List<String> fileNames = null;
7375
@GetMapping("/files")
@@ -82,7 +84,7 @@ public boolean accept(File file) {
8284
String name = file == null ? null : file.getName();
8385
int ind = name == null ? -1 : name.lastIndexOf(".");
8486
String suffix = ind < 0 ? null : name.substring(ind + 1);
85-
boolean isImg = suffix != null && IMG_SUFFIXES.contains(suffix.toLowerCase());
87+
boolean isImg = suffix != null;
8688
if (isImg) {
8789
names.add(name);
8890
}
@@ -145,6 +147,33 @@ public ResponseEntity<Object> download(@PathVariable(name = "fileName") String f
145147
return responseEntity;
146148
}
147149

150+
@GetMapping("/download/report/{reportId}/cv")
151+
@ResponseBody
152+
public ResponseEntity<Object> downloadCVReport(@PathVariable(name = "reportId") String reportId) throws FileNotFoundException, IOException {
153+
String name = "CVAuto_report_" + reportId + ".xlsx";
154+
File file = new File(fileUploadRootDir + name);
155+
long size = file.exists() ? file.length() : 0;
156+
if (size < 10*1024) {
157+
file.delete();
158+
}
159+
160+
if ((file.exists() ? file.length() : 0) < 10*1024) {
161+
String filePath = ExcelUtil.newCVAutoReportWithTemplate(fileUploadRootDir, name);
162+
if (! Objects.equals(filePath, fileUploadRootDir + name)) {
163+
try {
164+
File sourceFile = new File(filePath);
165+
File destFile = new File(fileUploadRootDir + name);
166+
if (! destFile.getAbsolutePath().equals(sourceFile.getAbsolutePath())) {
167+
FileUtils.copyFile(sourceFile, destFile);
168+
System.out.println("文件复制完成 (Commons IO): " + filePath + " -> " + fileUploadRootDir + name);
169+
}
170+
} catch (IOException e) {
171+
e.printStackTrace();
172+
}
173+
}
174+
}
148175

176+
return download(name);
177+
}
149178

150179
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /