Kaynağa Gözat

* cad功能对接

chen.cheng 4 ay önce
ebeveyn
işleme
49b0614c8f

+ 6 - 0
bd-park/park-backend/park-application/src/main/java/com/huashe/park/application/web/controller/cons/ConsUnitInfoController.java

@@ -85,6 +85,12 @@ public class ConsUnitInfoController extends BaseController {
         consUnitInfoService.exportConsUnitHole(consUnitInfo, response);
     }
 
+    @Log(title = "施工单元", businessType = BusinessType.EXPORT)
+    @PostMapping("/export/csv")
+    public void exportCsv(HttpServletResponse response, ConsUnitInfo consUnitInfo) {
+        consUnitInfoService.exportConsUnitRes(consUnitInfo, response);
+    }
+
     /**
      * 获取施工单元详细信息
      */

+ 4 - 2
bd-park/park-backend/park-core/src/main/java/com/huashe/park/core/service/IConsUnitInfoService.java

@@ -2,11 +2,11 @@ package com.huashe.park.core.service;
 
 import java.util.List;
 
+import javax.servlet.http.HttpServletResponse;
+
 import com.huashe.park.domain.dto.cons.ConsUnitMachine;
 import com.huashe.park.domain.entity.ConsUnitInfo;
 
-import javax.servlet.http.HttpServletResponse;
-
 /**
  * 施工单元Service接口
  * 
@@ -72,6 +72,8 @@ public interface IConsUnitInfoService {
 
     void exportConsUnitHole(ConsUnitInfo consUnitHole, HttpServletResponse response);
 
+    void exportConsUnitRes(ConsUnitInfo consUnitHole, HttpServletResponse response);
+
     List<ConsUnitInfo> machineAssignedUnit(Long machineId);
 
 }

+ 29 - 13
bd-park/park-backend/park-core/src/main/java/com/huashe/park/core/service/impl/ConsUnitInfoServiceImpl.java

@@ -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 :", ""