|
@@ -2,8 +2,10 @@ package com.huashe.park.core.service.impl;
|
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
@@ -268,11 +270,9 @@ public class ConsUnitInfoServiceImpl implements IConsUnitInfoService {
|
|
|
InputStream dwgFile = HttpRequest.post(cadForestCfg.getCadServer() + "/download").form("dwg_file", file)
|
|
|
.form("csv_file", csvFile).execute().bodyStream();
|
|
|
// 创建一个BufferedInputStream来缓冲输入流,提高读取效率
|
|
|
- BufferedInputStream bis = new BufferedInputStream(dwgFile);
|
|
|
- try {
|
|
|
-
|
|
|
+ try (BufferedInputStream bis = new BufferedInputStream(dwgFile);
|
|
|
+ ServletOutputStream outputStream = response.getOutputStream();) {
|
|
|
FileUtils.setAttachmentResponseHeader(response, file.getName());
|
|
|
- ServletOutputStream outputStream = response.getOutputStream();
|
|
|
byte[] buffer = new byte[1024]; // 定义一个缓冲区
|
|
|
int bytesRead;
|
|
|
|
|
@@ -286,14 +286,29 @@ public class ConsUnitInfoServiceImpl implements IConsUnitInfoService {
|
|
|
catch (IOException e) {
|
|
|
log.error("download input stream: {}", e.getMessage());
|
|
|
}
|
|
|
- finally {
|
|
|
- try {
|
|
|
- // 确保关闭输入流
|
|
|
- bis.close();
|
|
|
- }
|
|
|
- catch (IOException e) {
|
|
|
- log.error("Error closing input stream: {}", e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void exportConsUnitRes(ConsUnitInfo consUnitHole, HttpServletResponse response) {
|
|
|
+ ConsUnitInfo consUnitInfo = consUnitInfoMapper.selectConsUnitInfoById(consUnitHole.getId());
|
|
|
+ File csvFile = generatePileHoleFile(consUnitInfo);
|
|
|
+ writeFileToResponse(csvFile, response);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void writeFileToResponse(File file, HttpServletResponse response) {
|
|
|
+ // 读取文件内容并写入响应输出流
|
|
|
+ try (FileInputStream fis = new FileInputStream(file); OutputStream os = response.getOutputStream()) {
|
|
|
+ FileUtils.setAttachmentResponseHeader(response, file.getName());
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int bytesRead;
|
|
|
+ while ((bytesRead = fis.read(buffer)) != -1) {
|
|
|
+ os.write(buffer, 0, bytesRead);
|
|
|
}
|
|
|
+ // 刷新并关闭流
|
|
|
+ os.flush();
|
|
|
+ }
|
|
|
+ catch (IOException e) {
|
|
|
+ log.error("Error during file download: {}", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -340,7 +355,7 @@ public class ConsUnitInfoServiceImpl implements IConsUnitInfoService {
|
|
|
|
|
|
ProjectInfo projectInfo = projectInfos.get(0);
|
|
|
CsvWriteConfig csvWriteConfig = new CsvWriteConfig();
|
|
|
- Field[] fields = ReflectUtil.getFields(ConsUnitInfo.class);
|
|
|
+ Field[] fields = ReflectUtil.getFields(ResultCADCsv.class);
|
|
|
for (Field field : fields) {
|
|
|
CsvAlias annotation = field.getAnnotation(CsvAlias.class);
|
|
|
if (annotation != null) {
|
|
@@ -359,6 +374,7 @@ public class ConsUnitInfoServiceImpl implements IConsUnitInfoService {
|
|
|
});
|
|
|
|
|
|
List<PileMachineInfo> pileMachineInfos = pileMachineInfoService.qryUnitMachine(consUnitInfo.getId());
|
|
|
+ ConsUnitInfo consUnitInfo1 = consUnitInfoMapper.selectConsUnitInfoById(consUnitInfo.getId());
|
|
|
if (!CollectionUtils.isEmpty(pileMachineInfos)) {
|
|
|
List<String> machineNum = pileMachineInfos.stream().map(PileMachineInfo::getMachineNum)
|
|
|
.collect(Collectors.toList());
|
|
@@ -380,7 +396,7 @@ public class ConsUnitInfoServiceImpl implements IConsUnitInfoService {
|
|
|
});
|
|
|
}
|
|
|
header.add(new String[] {
|
|
|
- "Cluster Number :", ""
|
|
|
+ "Cluster Number :", consUnitInfo1.getName()
|
|
|
});
|
|
|
header.add(new String[] {
|
|
|
"Operator Name :", ""
|