From 298e75c24c0f790f8f1af0fae40e5783b4590953 Mon Sep 17 00:00:00 2001
From: whycxzp <perryhsu@163.com>
Date: 星期五, 14 十月 2022 10:10:06 +0800
Subject: [PATCH] 更新

---
 src/main/java/com/whyc/service/ExcelExportService.java |  181 +++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 164 insertions(+), 17 deletions(-)

diff --git a/src/main/java/com/whyc/service/ExcelExportService.java b/src/main/java/com/whyc/service/ExcelExportService.java
index 7485329..18ee709 100644
--- a/src/main/java/com/whyc/service/ExcelExportService.java
+++ b/src/main/java/com/whyc/service/ExcelExportService.java
@@ -1,23 +1,31 @@
 package com.whyc.service;
 
+import cn.afterturn.easypoi.entity.ImageEntity;
 import cn.afterturn.easypoi.excel.ExcelExportUtil;
 import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
 import com.google.common.collect.Maps;
-import com.whyc.dto.ResTestReportDTO;
+import com.whyc.dto.BattGroupStationInfoWithFileParam;
+import com.whyc.dto.Response;
+import com.whyc.pojo.BattgroupData;
 import com.whyc.pojo.FileParam;
+import com.whyc.pojo.StationInfo;
+import com.whyc.util.MathUtil;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Service;
+import sun.misc.BASE64Decoder;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.net.URLEncoder;
+import java.text.ParseException;
+import java.text.ParsePosition;
+import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 public class ExcelExportService {
@@ -28,27 +36,166 @@
     @Autowired
     private BattGroupDataService battGroupDataService;
 
-    public void resTestReport(String fileId, HttpServletResponse response) {
-        HashMap<String, Object> map = Maps.newHashMap();
-        List list = new LinkedList<>();
-        ResTestReportDTO dto = new ResTestReportDTO();
-        dto.setP1("excel妯℃澘");
-        list.add(dto);
-        //鍩虹娴嬭瘯鏁版嵁
-        //battGroupDataService.getListWithTestTime(fileId);
-        //鏂囦欢鎵�灞炵殑鐢垫睜缁勪俊鎭�
-        FileParam fileParam = fileParamService.getByFileId(fileId);
+    @Autowired
+    private StationInfoService stationInfoService;
 
-        map.put("dto", list);
+    public void resTestReport(BattGroupStationInfoWithFileParam info, HttpServletResponse response) throws IOException {
+        HashMap<String, Object> map = Maps.newHashMap();
+        //鎬讳綋璇勪环:鍐呴樆/鐢靛帇/杩炴帴鏉�/?瀹归噺
+        int resGoodCount = 0;
+        int volGoodCount = 0;
+        int chainResGoodCount = 0;
+        FileParam fileParam = info.getFileParam();
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+        fileParam.setTestTimeStr(format.format(fileParam.getTestTime()));
+        List<BattgroupData> dataList = info.getDataList();
+        for(BattgroupData data : dataList){
+            data.setMonNumStr("#"+data.getMonNum());
+            if(!data.isHighResFlag1() && !data.isHighResFlag2()){
+                resGoodCount +=1;
+                data.setResEvaluation("浼�");
+            }else if(data.isHighResFlag1()){
+                data.setResEvaluation("宸�");
+            }else{
+                data.setResEvaluation("寰堝樊");
+            }
+            if(!data.isLowVolFlag() && !data.isHighVolFlag()){
+                volGoodCount +=1;
+            }
+            if(!data.isHighChainResFlag()){
+                chainResGoodCount +=1;
+            }
+        };
+        info.setResGoodCount(resGoodCount);
+        info.setVolGoodCount(volGoodCount);
+        info.setChainResGoodCount(chainResGoodCount);
+
+        map.put("dto", info);
+        //鍥剧墖
+        BASE64Decoder decoder = new BASE64Decoder();
+        ImageEntity volImage = new ImageEntity();
+        volImage.setData(decoder.decodeBuffer(info.getVolPic().substring(info.getVolPic().indexOf(",")+1)));
+        volImage.setColspan(7);
+        volImage.setRowspan(17);
+
+        ImageEntity resImage = new ImageEntity();
+        resImage.setData(decoder.decodeBuffer(info.getResPic().substring(info.getResPic().indexOf(",")+1)));
+        resImage.setColspan(7);
+        resImage.setRowspan(16);
+
+        map.put("volImage",volImage);
+        map.put("resImage",resImage);
+
+        //map.put("volImage","volImage");
+        //map.put("resImage","resImage");
+
         //鑾峰彇瀵煎嚭妯℃澘鍦板潃
-        ClassPathResource classPathResource = new ClassPathResource("excel_templates/rest_test_report_single_template.xls");
+        ClassPathResource classPathResource = new ClassPathResource("excel_templates/res_test_report_single_template.xls");
         String path = classPathResource.getPath();
         TemplateExportParams templateExportParams1 = new TemplateExportParams(path);
         Workbook wb = ExcelExportUtil.exportExcel(templateExportParams1, map);
         String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy_MM_dd_HH_mm_ss"));
         String fileName = "鍐呴樆璁℃祴璇�"+time+".xls";
         try {
-            response.setContentType("application/octet-stream;charset=utf-8");
+            //response.setContentType("application/octet-stream;charset=utf-8");
+            response.setContentType("application/vnd.ms-excel");
+            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8"));
+            response.flushBuffer();
+            wb.write(response.getOutputStream());
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void resTestCompareReport(String fileId, String fileId2, BattGroupStationInfoWithFileParam dto, HttpServletResponse response) throws IOException {
+        Map<String,Object> map = new HashMap<>();
+        Response comparedList = battGroupDataService.getComparedList(fileId, fileId2);
+        List<BattgroupData> dataList = (List<BattgroupData>) comparedList.getData();
+        List<BattgroupData> dataList2 = (List<BattgroupData>) comparedList.getData2();
+        Map<String,List<String>> data3 = (Map<String, List<String>>) comparedList.getData3();
+        //鍙樺寲鐜�
+        List<String> resChangeRateList = data3.get("resChangeRate");
+        List<String> volChangeRateList = data3.get("volChangeRate");
+        //鍧囦竴鎬�:res/vol
+        List<String> resBalanceRateList = data3.get("resBalanceRate");
+        List<String> volBalanceRateList = data3.get("volBalanceRate");
+        //鍧囦竴鎬�:chainRes/?瀹归噺/bs(鐢靛)
+        List<Float> chainResList = dataList2.stream().map(BattgroupData::getCr).collect(Collectors.toList());
+        List<Float> bsList = dataList2.stream().map(BattgroupData::getBs).collect(Collectors.toList());
+        String chainResBalanceRate = MathUtil.getStandardDeviation(chainResList) * 10000 / 100 + "%";
+        String bsBalanceRate = MathUtil.getStandardDeviation(bsList) * 10000 / 100 + "%";
+        //鑾峰彇FileParam鍜孲tationInfo
+        StationInfo stationInfo = stationInfoService.getByFileId(fileId2);
+        FileParam param = fileParamService.getByFileId(fileId2);
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        param.setTestTimeStr(format.format(param.getTestTime()));
+
+        FileParam paramBase = fileParamService.getByFileId(fileId);
+        String testTimeStrBase = format.format(paramBase.getTestTime());
+        //鍥剧墖
+        BASE64Decoder decoder = new BASE64Decoder();
+        ImageEntity volImage = new ImageEntity();
+        volImage.setData(decoder.decodeBuffer(dto.getVolPic().substring(dto.getVolPic().indexOf(",")+1)));
+        volImage.setColspan(7);
+        volImage.setRowspan(17);
+
+        ImageEntity resImage = new ImageEntity();
+        resImage.setData(decoder.decodeBuffer(dto.getResPic().substring(dto.getResPic().indexOf(",")+1)));
+        resImage.setColspan(7);
+        resImage.setRowspan(16);
+
+        map.put("volImage",volImage);
+        map.put("resImage",resImage);
+
+        map.put("fileParam",param);
+        map.put("stationInfo",stationInfo);
+        //鎬讳綋璇勪环:鍐呴樆/鐢靛帇/杩炴帴鏉�/?瀹归噺
+        int resGoodCount = 0;
+        int volGoodCount = 0;
+        int chainResGoodCount = 0;
+        for(BattgroupData data : dataList2){
+            data.setMonNumStr("#"+data.getMonNum());
+            if(!data.isHighResFlag1() && !data.isHighResFlag2()){
+                resGoodCount +=1;
+                data.setResEvaluation("浼�");
+            }else if(data.isHighResFlag1()){
+                data.setResEvaluation("宸�");
+            }else{
+                data.setResEvaluation("寰堝樊");
+            }
+            if(!data.isLowVolFlag() && !data.isHighVolFlag()){
+                volGoodCount +=1;
+            }
+            if(!data.isHighChainResFlag()){
+                chainResGoodCount +=1;
+            }
+        };
+        map.put("resGoodCount",resGoodCount);
+        map.put("volGoodCount",volGoodCount);
+        map.put("chainResGoodCount",chainResGoodCount);
+
+        map.put("dataList",dataList);
+        map.put("dataList2",dataList2);
+
+        map.put("stdDevBv",volBalanceRateList.get(1));
+        map.put("stdDevBr",resBalanceRateList.get(1));
+        map.put("stdDevCr",chainResBalanceRate);
+        map.put("stdDevBs",bsBalanceRate);
+        map.put("testTimeStrBase",testTimeStrBase);
+
+
+        //鑾峰彇瀵煎嚭妯℃澘鍦板潃
+        ClassPathResource classPathResource = new ClassPathResource("excel_templates/res_test_report_compare_template.xls");
+        String path = classPathResource.getPath();
+        TemplateExportParams templateExportParams1 = new TemplateExportParams(path);
+        templateExportParams1.setColForEach(true);
+        Workbook wb = ExcelExportUtil.exportExcel(templateExportParams1, map);
+        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy_MM_dd_HH_mm_ss"));
+        String fileName = "鍐呴樆璁℃祴璇�"+time+".xls";
+        try {
+            //response.setContentType("application/octet-stream;charset=utf-8");
+            response.setContentType("application/vnd.ms-excel");
             response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8"));
             response.flushBuffer();
             wb.write(response.getOutputStream());

--
Gitblit v1.9.1