From 7a8d50965cb69ecc348a6b11d902409628012cd0 Mon Sep 17 00:00:00 2001
From: whyclxw <810412026@qq.com>
Date: 星期三, 25 六月 2025 17:15:10 +0800
Subject: [PATCH] 蓄电池对比分析导出

---
 src/main/java/com/whyc/dto/Statistic/BattCompareStic.java     |    7 ++
 src/main/java/com/whyc/service/BatttestdataInfService.java    |   93 ++++++++++++++++++++++++++++++
 src/main/java/com/whyc/dto/Statistic/SticCompare15Res.java    |    4 +
 src/main/java/com/whyc/service/ExportService.java             |   47 +++++++++++++++
 src/main/java/com/whyc/controller/ExportFileController.java   |    7 ++
 src/main/java/com/whyc/controller/BattCompareController.java  |    2 
 src/main/resources/excel_templates/batt_compare_template.xlsx |    0 
 7 files changed, 157 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/whyc/controller/BattCompareController.java b/src/main/java/com/whyc/controller/BattCompareController.java
index 85697ce..35432dd 100644
--- a/src/main/java/com/whyc/controller/BattCompareController.java
+++ b/src/main/java/com/whyc/controller/BattCompareController.java
@@ -32,7 +32,7 @@
     @Autowired
     private AppParamService appParamService;
 
-    @ApiOperation(value = "钃勭數姹犵粍瀵规瘮鍒嗘瀽鐣岄潰锛堝悓涓�鏃堕棿鍚屼竴鍝佺墝/鍚屼竴鏃堕棿涓嶅悓涓�鍝佺墝/涓嶅悓涓�鏃堕棿鍚屼竴鍝佺墝锛�(1.2.15/16/17)")
+    @ApiOperation(value = "钃勭數姹犵粍瀵规瘮鍒嗘瀽鐣岄潰锛堝悓涓�鏃堕棿鍚屼竴鍝佺墝/鍚屼竴鏃堕棿涓嶅悓涓�鍝佺墝/涓嶅悓涓�鏃堕棿鍚屼竴鍝佺墝锛�(2.5.1/2/3)")
     @PostMapping("getBattCompare15Statistic")
     public Response getBattCompare15Statistic(@RequestBody BattCompareStic stic) throws ParseException {
         User uinf= ActionUtil.getUser();
diff --git a/src/main/java/com/whyc/controller/ExportFileController.java b/src/main/java/com/whyc/controller/ExportFileController.java
index 9decf30..d0afccf 100644
--- a/src/main/java/com/whyc/controller/ExportFileController.java
+++ b/src/main/java/com/whyc/controller/ExportFileController.java
@@ -1,6 +1,7 @@
 package com.whyc.controller;
 
 import com.whyc.dto.Real.ExportTinfDataDto;
+import com.whyc.dto.Statistic.BattCompareStic;
 import com.whyc.dto.Statistic.MonStic;
 import com.whyc.service.ExportService;
 import io.swagger.annotations.Api;
@@ -31,4 +32,10 @@
     public void exportTinfDataByTestRecordCount(HttpServletRequest req, HttpServletResponse resp ,@RequestBody ExportTinfDataDto dto) throws ParseException, IOException {
         service.exportTinfDataByTestRecordCount(req,resp,dto);
     }
+
+    @PostMapping("exportBattCompare")
+    @ApiOperation(value = "钃勭數姹犵粍瀵规瘮鍒嗘瀽瀵煎嚭(2.5.1/2/3)")
+    public void exportBattCompare(HttpServletRequest req, HttpServletResponse resp ,@RequestBody BattCompareStic stic) throws ParseException, IOException {
+        service.exportBattCompare(req,resp,stic);
+    }
 }
\ No newline at end of file
diff --git a/src/main/java/com/whyc/dto/Statistic/BattCompareStic.java b/src/main/java/com/whyc/dto/Statistic/BattCompareStic.java
index f6ba1e2..95dffe4 100644
--- a/src/main/java/com/whyc/dto/Statistic/BattCompareStic.java
+++ b/src/main/java/com/whyc/dto/Statistic/BattCompareStic.java
@@ -28,4 +28,11 @@
     private Date inuseEndTime;//缁撴潫鏃堕棿
 
     private Integer inuseYear;//鎶曡繍鏃堕棿1~15骞�
+
+    //瀵煎嚭鏃朵娇鐢�
+    private Float avgCap;//瀵煎嚭鏃跺钩鍧囧閲�
+    private Float standCapDiff;//瀵煎嚭鏃跺閲忔爣鍑嗗樊
+    private String picCap;//瀹归噺鎶樼嚎鍥�
+    private String picRes;//鏈�楂樺唴闃绘姌绾垮浘
+    private String picFlotVol;//鐢垫睜缁勬诞鍏呯數鍘嬫姌绾垮浘
 }
\ No newline at end of file
diff --git a/src/main/java/com/whyc/dto/Statistic/SticCompare15Res.java b/src/main/java/com/whyc/dto/Statistic/SticCompare15Res.java
index d231bf1..3c0a1c9 100644
--- a/src/main/java/com/whyc/dto/Statistic/SticCompare15Res.java
+++ b/src/main/java/com/whyc/dto/Statistic/SticCompare15Res.java
@@ -13,12 +13,16 @@
     private String city;
     private String country;
     private String stationName;
+    private String fullName;
     private String battgroupName;
     private String devName;
     private String product;
     @JsonFormat(pattern = "yyyy-MM-dd")
     private Date inuseTime;
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    private String inuseTimeStr;
     private Float monvolstd;
+    private Float moncapstd;
     //private List<Integer> monNums;   //鎹熷潖鍗曚綋缂栧彿
     private Float realCap;          //瀹為檯瀹归噺
     private String precentCap;       //瀹归噺鐧惧垎姣�
diff --git a/src/main/java/com/whyc/service/BatttestdataInfService.java b/src/main/java/com/whyc/service/BatttestdataInfService.java
index 4d22fff..2d40379 100644
--- a/src/main/java/com/whyc/service/BatttestdataInfService.java
+++ b/src/main/java/com/whyc/service/BatttestdataInfService.java
@@ -316,11 +316,14 @@
             res.setDevName(binf.getDevName());
             res.setProduct(binf.getProduct());
             res.setInuseTime(binf.getInuseTime());
+            res.setInuseTimeStr(ActionUtil.sdfwithday.format(binf.getInuseTime()));
             res.setMonvolstd(binf.getMonvolstd());
+            res.setMoncapstd(binf.getMoncapstd());
             res.setStationId(binf.getStationId());
             res.setPowerId(binf.getPowerId());
             res.setDevId(binf.getDevId());
             res.setBattgroupId(binf.getBattgroupId());
+            res.setFullName(binf.getFullName());
             //2.鑾峰彇鐢垫睜缁勫湪缁欏畾鏃堕棿娈电殑鏀剧數璁板綍(鎸囧畾鏃堕棿娈电殑鏍囧噯鏍稿鏀剧數)
             BatttestdataInf tinf =getLastStandardTestDataByTime(binf.getBattgroupId(),stic.getTestStartTime(),stic.getTestEndTime());
             if(tinf==null){
@@ -389,11 +392,97 @@
         }
         map.put("avgCap",sumCap/binfList.size());
         map.put("standCapDiff",maxCap-minCap);
-
         PageInfo pageInfo=PageInfoUtils.list2PageInfo(comparelist, stic.getPageNum(), stic.getPageSize());
         return new Response().setIII(1,comparelist.size()>0,pageInfo,map,"钃勭數姹犵粍瀵规瘮鍒嗘瀽鐣岄潰锛堝悓涓�鍝佺墝鍚屼竴鏃堕棿锛�");
     }
-
+    /*钃勭數姹犵粍瀵规瘮鍒嗘瀽瀵煎嚭浣跨敤
+     */
+    public List<SticCompare15Res> exportBattCompare(BattCompareStic stic) {
+        //鑾峰彇鏍稿浼樺姡锛屾崯鍧忓弬鏁�
+        List<AppParam> paramList=appParamService.getHrParam();
+        Float badValue=0f;
+        Float damageValue=0f;
+        if(paramList!=null){
+            for (AppParam param:paramList) {
+                if(param.getParamNamePsx().equals("batt_mon_deteriorate_val")){
+                    badValue=param.getParamValue();
+                }
+                if(param.getParamNamePsx().equals("batt_mon_damage_val")){
+                    damageValue=param.getParamValue();
+                }
+            }
+        }
+        //1鏌ヨ绗﹀悎鏉′欢鐨勭數姹犵粍
+        List<BattInf> binfList=battInfService.getBattCompare15Statistic(stic);
+        List<SticCompare15Res> comparelist=new ArrayList<>();
+        if(binfList!=null&&binfList.size()>=0){
+            for (BattInf binf:binfList) {
+                SticCompare15Res res=new SticCompare15Res();
+                res.setProvice(binf.getProvice());
+                res.setCity(binf.getCity());
+                res.setCountry(binf.getCountry());
+                res.setStationName(binf.getStationName());
+                res.setBattgroupName(binf.getBattgroupName());
+                res.setDevName(binf.getDevName());
+                res.setProduct(binf.getProduct());
+                res.setInuseTime(binf.getInuseTime());
+                res.setInuseTimeStr(ActionUtil.sdfwithday.format(binf.getInuseTime()));
+                res.setMonvolstd(binf.getMonvolstd());
+                res.setMoncapstd(binf.getMoncapstd());
+                res.setStationId(binf.getStationId());
+                res.setPowerId(binf.getPowerId());
+                res.setDevId(binf.getDevId());
+                res.setBattgroupId(binf.getBattgroupId());
+                res.setFullName(binf.getFullName());
+                //2.鑾峰彇鐢垫睜缁勫湪缁欏畾鏃堕棿娈电殑鏀剧數璁板綍(鎸囧畾鏃堕棿娈电殑鏍囧噯鏍稿鏀剧數)
+                BatttestdataInf tinf =getLastStandardTestDataByTime(binf.getBattgroupId(),stic.getTestStartTime(),stic.getTestEndTime());
+                if(tinf==null){
+                    res.setRealCap(0f);
+                    res.setPrecentCap("0.00000");
+                    res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_4.getStateId()));
+                    res.setStopReason("--");
+                    res.setFloatGroupVol(0f);
+                }else{
+                    res.setStopReason(StopReasonEnum.getValue(tinf.getTestStoptype()));
+                    res.setFloatGroupVol(tinf.getFloatGroupVol());
+                    //鎵捐繖娆℃斁鐢电殑鏈�鍚庝竴绗旀暟鎹�
+                    List<BatttestdataId> idDataList=battTestdataIdService.getLastDataByBattgroupId(tinf.getBattgroupId(),tinf.getTestRecordCount(),tinf.getRecordNum());
+                    if(idDataList==null||idDataList.size()==0){
+                        res.setRealCap(0f);
+                        res.setPrecentCap("0.00000");
+                        res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_4.getStateId()));
+                        res.setFloatGroupVol(0f);
+                    }else{
+                        Float moncapStd=binf.getMoncapstd();
+                        int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
+                        Float grouprealCap = (float) BattCapFactory.GetMonomerCap(binf.getMoncapstd(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Real);
+                        //Float restCap = (float) BattCapFactory.GetMonomerCap(binf.getMoncapstd(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Rest);
+                        res.setRealCap(grouprealCap);
+                        if(grouprealCap>=moncapStd*badValue){
+                            res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_1.getStateId()));
+                        }
+                        if(grouprealCap<=moncapStd*damageValue){
+                            res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_3.getStateId()));
+                        }
+                        if((grouprealCap>moncapStd*damageValue)&&(grouprealCap<moncapStd*badValue)){
+                            res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_2.getStateId()));
+                        }
+                        //淇濈暀5浣嶅皬鏁�
+                        String precentCap = String.format("%.5f",(grouprealCap/binf.getMoncapstd()*100));
+                        res.setPrecentCap(precentCap);
+                    }
+                }
+                if(stic.getPerformance()==null){
+                    comparelist.add(res);
+                }else{
+                    if(res.getCapperformance().equals(BattCapperformanceEnum.getValue(stic.getPerformance()))){
+                        comparelist.add(res);
+                    }
+                }
+            }
+        }
+        return comparelist;
+    }
     //钃勭數姹犵粍瀵规瘮鍒嗘瀽鐣岄潰锛堜笉鍚屽搧鐗屽悓涓�鏃堕棿锛�(1.2.16)
     public Response getBattCompare16Statistic(BattCompareStic stic) {
         //鑾峰彇鏍稿浼樺姡锛屾崯鍧忓弬鏁�
diff --git a/src/main/java/com/whyc/service/ExportService.java b/src/main/java/com/whyc/service/ExportService.java
index 09ea1ea..3e92717 100644
--- a/src/main/java/com/whyc/service/ExportService.java
+++ b/src/main/java/com/whyc/service/ExportService.java
@@ -5,7 +5,9 @@
 import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
 import com.whyc.dto.Real.ExportTinfDataDto;
 import com.whyc.dto.Response;
+import com.whyc.dto.Statistic.BattCompareStic;
 import com.whyc.dto.Statistic.MonStic;
+import com.whyc.dto.Statistic.SticCompare15Res;
 import com.whyc.dto.Statistic.SticMonRes;
 import com.whyc.mapper.CommonMapper;
 import com.whyc.pojo.db_batt_testdata.BatttestdataId;
@@ -229,4 +231,49 @@
             e.printStackTrace();
         }
     }
+    //钃勭數姹犵粍瀵规瘮鍒嗘瀽瀵煎嚭(2.5.1/2/3)
+    public void exportBattCompare(HttpServletRequest req, HttpServletResponse resp, BattCompareStic stic) throws IOException {
+        Map<String,Object> map=new HashMap<>();
+        map.put("avgCap",stic.getAvgCap());
+        map.put("standCapDiff",stic.getStandCapDiff());
+        //琛ㄦ牸鏁版嵁
+        List<SticCompare15Res> dataList= battTinfService.exportBattCompare(stic);
+        map.put("dataList",dataList);
+        BASE64Decoder decoder = new BASE64Decoder();
+        if(!stic.getPicCap().equals("")) {
+            ImageEntity volImage = new ImageEntity();
+            volImage.setData(decoder.decodeBuffer(stic.getPicCap().substring(stic.getPicCap().indexOf(",") + 1)));
+            volImage.setColspan(6);
+            volImage.setRowspan(17);
+            map.put("picCap",volImage);
+        }
+        if(!stic.getPicRes().equals("")) {
+            ImageEntity volImage = new ImageEntity();
+            volImage.setData(decoder.decodeBuffer(stic.getPicRes().substring(stic.getPicRes().indexOf(",") + 1)));
+            volImage.setColspan(6);
+            volImage.setRowspan(17);
+            map.put("picRes",volImage);
+        }
+        if(!stic.getPicFlotVol().equals("")) {
+            ImageEntity volImage = new ImageEntity();
+            volImage.setData(decoder.decodeBuffer(stic.getPicFlotVol().substring(stic.getPicFlotVol().indexOf(",") + 1)));
+            volImage.setColspan(6);
+            volImage.setRowspan(17);
+            map.put("picFlotVol",volImage);
+        }
+        //鑾峰彇瀵煎嚭妯℃澘鍦板潃
+        ClassPathResource classPathResource = new ClassPathResource("excel_templates/batt_compare_template.xlsx");
+        String path = classPathResource.getPath();
+        TemplateExportParams templateExportParams1 = new TemplateExportParams(path,true);
+        Workbook wb = ExcelExportUtil.exportExcel(templateExportParams1, map);
+        try {
+            String fileName = "钃勭數姹犵粍瀵规瘮鏁版嵁.xls";
+            resp.setContentType("application/vnd.ms-excel");
+            resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8"));
+            resp.flushBuffer();
+            wb.write(resp.getOutputStream());
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 }
\ No newline at end of file
diff --git a/src/main/resources/excel_templates/batt_compare_template.xlsx b/src/main/resources/excel_templates/batt_compare_template.xlsx
new file mode 100644
index 0000000..5496887
--- /dev/null
+++ b/src/main/resources/excel_templates/batt_compare_template.xlsx
Binary files differ

--
Gitblit v1.9.1