From 2bb5386f806cd9418b18da9ad0c4137d0212695b Mon Sep 17 00:00:00 2001
From: whyclxw <810412026@qq.com>
Date: 星期五, 01 十一月 2024 12:02:39 +0800
Subject: [PATCH] 导出actm和a200测试数据,同时修改统计actm添加均衡统计

---
 src/main/java/com/whyc/service/ExcelExportService.java |  241 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 239 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/whyc/service/ExcelExportService.java b/src/main/java/com/whyc/service/ExcelExportService.java
index 4ace0f6..12b3498 100644
--- a/src/main/java/com/whyc/service/ExcelExportService.java
+++ b/src/main/java/com/whyc/service/ExcelExportService.java
@@ -1,7 +1,12 @@
 package com.whyc.service;
 
+import com.whyc.dto.A200stopReason;
+import com.whyc.dto.ActmstopReason;
 import com.whyc.pojo.db_batt_testdata.BatttestdataId;
+import com.whyc.pojo.db_batt_testdata.BatttestdataInf;
 import com.whyc.util.ActionUtil;
+import org.apache.poi.hssf.usermodel.HSSFCellStyle;
+import org.apache.poi.hssf.usermodel.HSSFFont;
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -20,11 +25,14 @@
     @Autowired(required = false)
     private SubTablePageInfoService subService;
 
+    @Autowired(required = false)
+    private BatttestdataInfService infService;
+
     //瀵煎嚭鏂囦欢
-    public void exportExcel(Integer devId,  Integer testRecordCount,HttpServletResponse response) {
+    public void exportExcel1(Integer devId,  Integer testRecordCount,HttpServletResponse response) {
         Workbook workbook = new XSSFWorkbook();
         Sheet sheet = workbook.createSheet("璁惧鍘嗗彶鏁版嵁");
-        String[] titiles=new String[]{"娴嬭瘯鏃堕棿","鐢垫睜缁勭紪鍙�","鍗曚綋缂栧彿","娴嬭瘯娆℃暟","娴嬭瘯绫诲瀷","娴嬭瘯瀹归噺"
+        String[] titiles=new String[]{"娴嬭瘯鏃堕棿","鐢垫睜缁勭紪鍙�","鍗曚綋缂栧彿","娴嬭瘯娆℃暟","娴嬭瘯绫诲瀷","娴嬭瘯璁板綍鏁�"
                                     ,"缁勭鐢靛帇(V)","娴嬭瘯鐢垫祦(A)","娴嬭瘯瀹归噺(AH)","鍗曚綋鐢靛帇(V)","鍗曚綋娓╁害(鈩�)"
                                     ,"鍗曚綋鐢垫祦(A)","鍗曚綋瀹归噺(AH)","鍗曚綋鑳介噺","鍗曚綋鐘舵��","鏁呴殰淇℃伅"};
         int rowNum=0;
@@ -84,4 +92,233 @@
             e.printStackTrace();
         }
     }
+
+    //瀵煎嚭鏂囦欢A200
+    public void exportExcelA200(Integer devId,  Integer testRecordCount,HttpServletResponse response) {
+        Workbook wb = new XSSFWorkbook();
+        //娴嬭瘯鎶ュ憡灏侀潰
+        exportExcelCoverA200(devId,testRecordCount,wb);
+        Sheet sheet = wb.createSheet("娴嬭瘯鏁版嵁璇︽儏");
+        // 鍒涘缓涓�涓崟鍏冩牸鏍峰紡锛屽苟璁剧疆瀛椾綋澶у皬涓�5
+        CellStyle cellStyle = wb.createCellStyle();
+        cellStyle.setAlignment(HorizontalAlignment.CENTER); // 璁剧疆姘村钩灞呬腑
+        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 璁剧疆鍨傜洿灞呬腑
+
+        Font font = wb.createFont();
+        font.setFontHeightInPoints((short)20);
+        cellStyle.setFont(font);
+
+        String[] titiles=new String[]{"Time(H:M:S)","Group V(V)","Group A(A)","Cap (AH)","Temp H(掳C)","Temp L(掳C)"};
+        List<BatttestdataId> list=subService.getTdataByIdWithListA200(devId,testRecordCount);
+
+        int rowNum=0;
+        // 鍒涘缓鏍囬琛�
+        Row row = sheet.createRow(rowNum);
+        row.setHeightInPoints(20.0f);
+        // 濉厖鏁版嵁
+        for(int i=0;i<titiles.length;i++){
+            row.createCell(i).setCellValue(titiles[i]);
+        }
+        if(list!=null&&list.size()>0){
+            List<Integer> monNums=list.get(0).getMonNums();
+            for (int i=0;i<monNums.size();i++){
+                row.createCell(i+titiles.length).setCellValue("V"+monNums.get(i));
+            }
+        }
+        rowNum++;
+
+        if(list!=null){
+            //鏁版嵁鏍�
+            for (int i = 0; i < list.size(); i++) {
+                Row row1 =  sheet.createRow(rowNum);  //鍒涘缓琛�
+                row1.setHeightInPoints(20.0f);
+                BatttestdataId tdata=list.get(i);
+                sheet.getRow(rowNum).createCell(0 ).setCellValue(ActionUtil.secToTime(tdata.getTestTimelong()));
+                sheet.getRow(rowNum).createCell(1).setCellValue(String.format("%.1f",tdata.getGroupVol()));
+                sheet.getRow(rowNum).createCell(2).setCellValue(String.format("%.1f",tdata.getTestCurr()));
+                sheet.getRow(rowNum).createCell(3).setCellValue(String.format("%.1f",tdata.getTestCap()));
+                sheet.getRow(rowNum).createCell(4).setCellValue(String.format("%.1f",tdata.getMaxTmp()));
+                sheet.getRow(rowNum).createCell(5).setCellValue(String.format("%.1f",tdata.getMinTmp()));
+                if (tdata.getMonVols() != null) {
+                    List<Float> monVols = tdata.getMonVols();
+                    for (int j = 0; j < monVols.size(); j++) {
+                        sheet.getRow(rowNum).createCell(6 + j).setCellValue(String.format("%.3f", monVols.get(j)));
+                    }
+                }
+                rowNum++;
+            }
+        }
+        try {
+            // 鍐欏叆鍒拌緭鍑烘祦
+            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+            wb.write(byteArrayOutputStream);
+            wb.close();
+
+            // 璁剧疆鍝嶅簲澶�
+            String filename = "璁惧鍘嗗彶鏁版嵁";
+            response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + URLEncoder.encode (filename, "utf-8") + ".xlsx");
+            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
+
+            // 鍐欏叆鍝嶅簲娴佸苟鍏抽棴
+            response.getOutputStream().write(byteArrayOutputStream.toByteArray());
+            response.getOutputStream().flush();
+            response.getOutputStream().close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+    //娴嬭瘯鎶ュ憡灏侀潰
+    private void exportExcelCoverA200(Integer devId, Integer testRecordCount, Workbook wb) {
+        Sheet sheet = wb.createSheet("娴嬭瘯鎶ュ憡灏侀潰");
+        // 鍒涘缓涓�涓崟鍏冩牸鏍峰紡锛屽苟璁剧疆瀛椾綋澶у皬涓�5
+        CellStyle cellStyle = wb.createCellStyle();
+        cellStyle.setAlignment(HorizontalAlignment.CENTER); // 璁剧疆姘村钩灞呬腑
+        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 璁剧疆鍨傜洿灞呬腑
+
+        Font font = wb.createFont();
+        font.setFontHeightInPoints((short)20);
+        cellStyle.setFont(font);
+
+        //鑾峰彇鏀剧數inf
+        BatttestdataInf tinf=infService.getTinfExport(devId,testRecordCount);
+        String[] titiles33=new String[]{"PACK/妯$粍鍙�:","娴嬭瘯寮�濮嬫椂闂�:","娴嬭瘯缁撴潫鏃堕棿:","鏁版嵁绫诲瀷:","鍋滄鍘熷洜:","棰勬斁瀹归噺(AH):"
+                ,"鏀剧數鐢垫祦(A):","娴嬭瘯鏃堕暱(h:m:s):","鍗曚覆涓嬮檺(V):","缁勭涓嬮檺(V):","鐢佃姱涓叉暟:","鏈�楂樻俯搴�(掳C):","鏈�浣庢俯搴�(掳C):","閲囬泦棰戠巼(绉�):"};
+        String[] titiles34=new String[]{tinf.getBatteryName(),ActionUtil.sdf.format(tinf.getTestStarttime()),ActionUtil.sdf.format(tinf.getRecordTime()), "鏀剧數鏁版嵁",A200stopReason.getStopReason(tinf.getTestStoptype()),String.format("%.1f",tinf.getTestCap())
+                ,String.format("%.1f",tinf.getTestCurr()),ActionUtil.secToTime(tinf.getTestTimelong()),String.format("%.1f",tinf.getMonVolLow()),String.format("%.1f",tinf.getGroupVolLow()),String.valueOf(tinf.getBatteryNumber())
+                ,String.format("%.1f",tinf.getMaxTemp()),String.format("%.1f",tinf.getMinTemp()),String.valueOf(tinf.getSaveInverter())};
+
+        String[] titiles23=new String[]{"PACK/妯$粍鍙�:","娴嬭瘯寮�濮嬫椂闂�:","娴嬭瘯缁撴潫鏃堕棿:","鏁版嵁绫诲瀷:","鍋滄鍘熷洜:","鍏呯數闄愭祦(A):"
+               ,"娴嬭瘯鏃堕暱(h:m:s):","鍗曚覆涓婇檺(V):","鐢垫祦闃�鍊�(A):","鐢佃姱涓叉暟:","鍏呯數闄愬帇(V)","鏈�楂樻俯搴�(掳C):","鏈�浣庢俯搴�(掳C):","閲囬泦棰戠巼(绉�):"};
+        String[] titiles24=new String[]{tinf.getBatteryName(),ActionUtil.sdf.format(tinf.getTestStarttime()),ActionUtil.sdf.format(tinf.getRecordTime()), "鍏呯數鏁版嵁",A200stopReason.getStopReason(tinf.getTestStoptype()),String.format("%.1f",tinf.getTestCurr())
+                ,ActionUtil.secToTime(tinf.getTestTimelong()),String.format("%.1f",tinf.getMonVolHigh()),String.format("%.1f",tinf.getTestcurrLimit()),String.valueOf(tinf.getBatteryNumber())
+                ,String.format("%.1f",tinf.getCharVoltage()),String.format("%.1f",tinf.getMaxTemp()),String.format("%.1f",tinf.getMinTemp()),String.valueOf(tinf.getSaveInverter())};
+
+
+        int rowNum=5;
+        if(tinf.getTestType()==3){//鏀剧數
+            for (int i=0;i<titiles33.length;i++){
+                Row row =  sheet.createRow(rowNum);  //鍒涘缓琛�
+                row.setHeightInPoints(20.0f);
+                row.createCell(3).setCellValue(titiles33[i]);
+                row.createCell(4).setCellValue(titiles34[i]);
+                rowNum++;
+            }
+        }else{
+            for (int i=0;i<titiles23.length;i++){
+                Row row =  sheet.createRow(rowNum);  //鍒涘缓琛�
+                row.setHeightInPoints(20.0f);
+                row.createCell(3).setCellValue(titiles23[i]);
+                row.createCell(4).setCellValue(titiles24[i]);
+                rowNum++;
+            }
+        }
+    }
+    //ACTM瀵煎嚭
+    public void exportExcelActm(Integer devId, Integer testRecordCount, HttpServletResponse response) {
+        Workbook wb = new XSSFWorkbook();
+        //娴嬭瘯鎶ュ憡灏侀潰
+        exportExcelCoverActm(devId,testRecordCount,wb);
+        Sheet sheet = wb.createSheet("娴嬭瘯鏁版嵁");
+        // 鍒涘缓涓�涓崟鍏冩牸鏍峰紡锛屽苟璁剧疆瀛椾綋澶у皬涓�5
+        CellStyle cellStyle = wb.createCellStyle();
+        cellStyle.setAlignment(HorizontalAlignment.CENTER); // 璁剧疆姘村钩灞呬腑
+        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 璁剧疆鍨傜洿灞呬腑
+
+        Font font = wb.createFont();
+        font.setFontHeightInPoints((short)20);
+        cellStyle.setFont(font);
+
+        String[] titiles=new String[]{"娴嬭瘯鏃堕暱"};
+        List<BatttestdataId> list=subService.getTdataByIdWithListActm(devId,testRecordCount);
+
+        int rowNum=0;
+        // 鍒涘缓鏍囬琛�
+        Row row = sheet.createRow(rowNum);
+        row.setHeightInPoints(20.0f);
+        // 濉厖鏁版嵁
+        for(int i=0;i<titiles.length;i++){
+            row.createCell(i).setCellValue(titiles[i]);
+        }
+        if(list!=null&&list.size()>0){
+            List<Integer> monNums=list.get(0).getMonNums();
+            for (int i=0;i<monNums.size();i++){
+                row.createCell(4*i+titiles.length).setCellValue(monNums.get(i)+"#鐢靛帇");
+                row.createCell(4*i+titiles.length+1).setCellValue(monNums.get(i)+"#鐢垫祦");
+                row.createCell(4*i+titiles.length+2).setCellValue(monNums.get(i)+"#瀹归噺锛圓H锛�");
+                row.createCell(4*i+titiles.length+3).setCellValue(monNums.get(i)+"#鑳介噺锛圵H锛�");
+            }
+        }
+        rowNum++;
+
+        if(list!=null){
+            //鏁版嵁鏍�
+            for (int i = 0; i < list.size(); i++) {
+                Row row1 =  sheet.createRow(rowNum);  //鍒涘缓琛�
+                row1.setHeightInPoints(20.0f);
+                BatttestdataId tdata=list.get(i);
+                sheet.getRow(rowNum).createCell(0 ).setCellValue(ActionUtil.secToTime(tdata.getTestTimelong()));
+                List<Float> monVols = tdata.getMonVols();
+                List<Float> monCurrs = tdata.getMonCurrs();
+                List<Float> monCaps = tdata.getMonCaps();
+                List<Float> monWhs = tdata.getMonWhs();
+                List<Integer> monNums=list.get(i).getMonNums();
+                for (int j = 0; j < monNums.size(); j++) {
+                    sheet.getRow(rowNum).createCell(4*j+1 ).setCellValue(String.format("%.3f", monVols.get(j)));
+                    sheet.getRow(rowNum).createCell(4*j+1+1).setCellValue(String.format("%.3f", monCurrs.get(j)));
+                    sheet.getRow(rowNum).createCell(4*j+1+2).setCellValue(String.format("%.3f", monCaps.get(j)));
+                    sheet.getRow(rowNum).createCell(4*j+1+3).setCellValue(String.format("%.3f", monWhs.get(j)));
+
+
+                }
+                rowNum++;
+            }
+        }
+        try {
+            // 鍐欏叆鍒拌緭鍑烘祦
+            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+            wb.write(byteArrayOutputStream);
+            wb.close();
+
+            // 璁剧疆鍝嶅簲澶�
+            String filename = "璁惧鍘嗗彶鏁版嵁";
+            response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + URLEncoder.encode (filename, "utf-8") + ".xlsx");
+            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
+
+            // 鍐欏叆鍝嶅簲娴佸苟鍏抽棴
+            response.getOutputStream().write(byteArrayOutputStream.toByteArray());
+            response.getOutputStream().flush();
+            response.getOutputStream().close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+    //娴嬭瘯鎶ュ憡灏侀潰
+    private void exportExcelCoverActm(Integer devId, Integer testRecordCount, Workbook wb) {
+        Sheet sheet = wb.createSheet("妯$粍閰嶇疆");
+        // 鍒涘缓涓�涓崟鍏冩牸鏍峰紡锛屽苟璁剧疆瀛椾綋澶у皬涓�5
+        CellStyle cellStyle = wb.createCellStyle();
+        cellStyle.setAlignment(HorizontalAlignment.CENTER); // 璁剧疆姘村钩灞呬腑
+        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 璁剧疆鍨傜洿灞呬腑
+
+        Font font = wb.createFont();
+        font.setFontHeightInPoints((short)20);
+        cellStyle.setFont(font);
+
+        //鑾峰彇鏀剧數inf
+        BatttestdataInf tinf=infService.getTinfExport(devId,testRecordCount);
+
+        String[] titiles3=new String[]{"鐢垫睜鍖呭簭鍙�:","妯$粍缂栧彿:","宸ヤ綔妯″紡:","鐢垫睜绫诲瀷:","鐢垫睜涓叉暟:","鐢靛帇闃�鍊�(v):"
+                ,"宸ヤ綔鐢垫祦(A):","寮�濮嬫祴璇曟椂闂�:","缁撴潫娴嬭瘯鏃堕棿:","鍋滄鍘熷洜:"};
+        String[] titiles4=new String[]{String.valueOf(tinf.getBattIdx()+1),tinf.getBatteryName(),ActmstopReason.getTestType(tinf.getTestType()),ActmstopReason.getBattType(tinf.getBattType()),String.valueOf(tinf.getBatteryNumber()),String.format("%.1f",tinf.getVolThreshold())
+                ,String.format("%.1f",tinf.getTestCurr()), ActionUtil.sdf.format(tinf.getTestStarttime()),ActionUtil.sdf.format(tinf.getRecordTime()), ActmstopReason.getStopReason(tinf.getTestStoptype())};
+
+        int rowNum=5;
+        for (int i=0;i<titiles3.length;i++){
+            Row row =  sheet.createRow(rowNum);  //鍒涘缓琛�
+            row.setHeightInPoints(20.0f);
+            row.createCell(3).setCellValue(titiles3[i]);
+            row.createCell(4).setCellValue(titiles4[i]);
+            rowNum++;
+        }
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.1