From dbba9c3fc5187432c34329a2a18e07feca729de5 Mon Sep 17 00:00:00 2001
From: whyclxw <810412026@qq.com>
Date: 星期二, 24 六月 2025 11:25:11 +0800
Subject: [PATCH] 2.5.1蓄电池对比分析同一时间同一品牌

---
 src/main/java/com/whyc/service/BatttestdataInfService.java |  164 +++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 107 insertions(+), 57 deletions(-)

diff --git a/src/main/java/com/whyc/service/BatttestdataInfService.java b/src/main/java/com/whyc/service/BatttestdataInfService.java
index 759b222..2ba3085 100644
--- a/src/main/java/com/whyc/service/BatttestdataInfService.java
+++ b/src/main/java/com/whyc/service/BatttestdataInfService.java
@@ -57,6 +57,9 @@
     @Autowired(required = false)
     private PwrdevHistorydataIdService pwrHisdataIdService;
 
+    @Autowired(required = false)
+    private BattresdataInfService battResdataInfService;
+
 
 
 
@@ -113,7 +116,8 @@
         wrapper.eq("battgroup_id", battgroupId);
         wrapper.eq("test_type", 3);
         wrapper.eq("test_starttype", 3);
-        wrapper.last("  and test_timelong >= 7200 ORDER BY test_starttime DESC ");
+        wrapper.eq("data_available", 1);//涓�娆℃湁鏁堢殑璁板綍
+        wrapper.last(" ORDER BY test_starttime DESC ");
         wrapper.last("limit 1");
         BatttestdataInf tinf = mapper.selectOne(wrapper);
         tinf.setTestStoptypeReason(StopReasonEnum.getValue(tinf.getTestStoptype()));
@@ -132,8 +136,9 @@
         if(testEndTime!=null){
             wrapper.lt("test_starttime",testEndTime);
         }
-        wrapper.last("  and test_timelong >= 7200 ORDER BY test_starttime DESC ");
-        wrapper.last("limit 1");
+        wrapper.eq("data_available", 1);//涓�娆℃湁鏁堢殑璁板綍
+        wrapper.last("  ORDER BY test_starttime DESC ");
+        wrapper.last(" limit  1 ");
         BatttestdataInf tinf = mapper.selectOne(wrapper);
         return tinf;
     }
@@ -258,8 +263,8 @@
         }
     }
     /*钃勭數姹犵粍瀵规瘮鍒嗘瀽鐣岄潰锛堝悓涓�鍝佺墝鍚屼竴鏃堕棿锛�
-     *1.鏌ヨ鍑虹鍚堟潯浠剁殑鐢垫睜缁勪俊鎭�
-     * 2.璁$畻鐢垫睜缁勭殑棰勪及鍓╀綑瀹归噺
+     *1.鏌ヨ鍑虹鍚堟潯浠剁殑鐢垫睜缁勪俊鎭紙鍚屼竴鍝佺墝鍚屼竴鎶曡繍鏃堕棿锛�
+     * 2.璁$畻鐢垫睜缁勭殑鏈�杩戜竴娆℃爣鍑嗘牳瀹规斁鐢电殑棰勪及瀹归噺
      *3.鍒ゆ柇鎬ц兘鍜岀櫨鍒嗘瘮
      * 4.鍒嗛〉
      */
@@ -276,15 +281,26 @@
                 if(param.getParamNamePsx().equals("batt_mon_damage_val")){
                     damageValue=param.getParamValue();
                 }
-
             }
         }
+        Map<String,Object> map=new HashMap<>();//鍙充晶鍥捐〃
+        map.put("avgCap",0f);
+        map.put("standCapDiff",0f);
+        Float sumCap=0f;
+        Float maxCap=0f;
+        Float standCapDiff=0f;
+        List<ComPareChart> capList=new ArrayList<>();
+        List<ComPareChart> resList=new ArrayList<>();
+        List<ComPareChart> flotVolList=new ArrayList<>();
+        map.put("capList",capList);
+        map.put("resList",resList);
+        map.put("flotVolList",flotVolList);
         //1鏌ヨ绗﹀悎鏉′欢鐨勭數姹犵粍
         List<BattInf> binfList=battInfService.getBattCompare15Statistic(stic);
         if(binfList==null||binfList.size()==0){
             return new Response().set(1,false,"褰撳墠鐢ㄦ埛鏈鐞嗘弧瓒虫潯浠剁殑鐢垫睜缁�");
         }
-        List<SticCompare15Res> reslist=new ArrayList<>();
+        List<SticCompare15Res> comparelist=new ArrayList<>();
         for (BattInf binf:binfList) {
             SticCompare15Res res=new SticCompare15Res();
             res.setProvice(binf.getProvice());
@@ -304,54 +320,71 @@
             BatttestdataInf tinf =getLastStandardTestDataByTime(binf.getBattgroupId(),stic.getTestStartTime(),stic.getTestEndTime());
             if(tinf==null){
                 res.setRealCap(0f);
-                res.setPrecentCap("0");
+                res.setPrecentCap("0.00000");
                 res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_4.getStateId()));
-                continue;
-            }
-            //鎵捐繖娆℃斁鐢电殑鏈�鍚庝竴绗旀暟鎹�
-            List<BatttestdataId> idDataList=battTestdataIdService.getLastDataByBattgroupId(tinf.getBattgroupId(),tinf.getTestRecordCount(),tinf.getRecordNum());
-            if(idDataList==null||idDataList.size()==0){
-                res.setRealCap(0f);
-                res.setPrecentCap("0");
-                res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_4.getStateId()));
-                continue;
-            }
-            Float moncapStd=binf.getMoncapstd();
-            int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
-            Float grouprealCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Real);
-            //Float restCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), 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);
-            List<Integer> monNums=new ArrayList<>();
-            for (BatttestdataId data:idDataList) {//姹傚崟浣撶殑 瀹為檯瀹归噺锛屾渶灏忓�煎氨鏄崟浣撶殑鍗曚綋鐢靛帇
-                Float monrealCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), data.getMonVol(), tinf.getGroupVol(), BattCapFactory.CapType_Real);
-                if (monrealCap <= moncapStd * damageValue) {//鎹熷潖鐨�
-                    monNums.add(data.getMonNum());
+                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(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Real);
+                    //Float restCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), 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);
+                    sumCap+=grouprealCap;
+                    standCapDiff=grouprealCap-maxCap;
+                    if(grouprealCap>=maxCap){
+                        maxCap=grouprealCap;
+                    }
                 }
             }
-            res.setMonNums(monNums);
             if(stic.getPerformance()==null){
-                reslist.add(res);
+                comparelist.add(res);
             }else{
                 if(res.getCapperformance().equals(BattCapperformanceEnum.getValue(stic.getPerformance()))){
-                    reslist.add(res);
+                    comparelist.add(res);
                 }
             }
-
+            ComPareChart capChart=new ComPareChart();
+            capChart.setBattgroupId(binf.getBattgroupId());
+            capChart.setBattgroupName(binf.getBattgroupName());
+            capChart.setValue(res.getRealCap());
+            capList.add(capChart);
+            ComPareChart floatVolChart=new ComPareChart();
+            floatVolChart.setBattgroupId(binf.getBattgroupId());
+            floatVolChart.setBattgroupName(binf.getBattgroupName());
+            floatVolChart.setValue(res.getFloatGroupVol());
+            flotVolList.add(floatVolChart);
+            //缁熻鍐呴樆娴嬭瘯
+            ComPareChart resChart=battResdataInfService.getMaxResData(binf);
+            resList.add(resChart);
         }
-        PageInfo pageInfo=PageInfoUtils.list2PageInfo(reslist, stic.getPageNum(), stic.getPageSize());
-        return new Response().setII(1,reslist.size()>0,pageInfo,"钃勭數姹犵粍瀵规瘮鍒嗘瀽鐣岄潰锛堝悓涓�鍝佺墝鍚屼竴鏃堕棿锛�");
+        map.put("avgCap",sumCap/binfList.size());
+        map.put("standCapDiff",standCapDiff);
+
+        PageInfo pageInfo=PageInfoUtils.list2PageInfo(comparelist, stic.getPageNum(), stic.getPageSize());
+        return new Response().setIII(1,comparelist.size()>0,pageInfo,map,"钃勭數姹犵粍瀵规瘮鍒嗘瀽鐣岄潰锛堝悓涓�鍝佺墝鍚屼竴鏃堕棿锛�");
     }
 
     //钃勭數姹犵粍瀵规瘮鍒嗘瀽鐣岄潰锛堜笉鍚屽搧鐗屽悓涓�鏃堕棿锛�(1.2.16)
@@ -581,13 +614,12 @@
             dto.setMoncapstd(binf.getMoncapstd());
             dto.setMonCount(binf.getMoncount());
             dto.setMonvolstd(binf.getMonvolstd());
+            dto.setFloatchartVol(tinf.getFloatGroupVol());
             if(battRtstate!=null){
                 Float restTime= BattCapFactory.getTheoryTime(battRtstate.getLoadCurr(), realCap, binf.getMoncapstd());
                 dto.setRestTime(restTime);
-                dto.setFloatchartVol(battRtstate.getGroupVol());
             }else{
                 dto.setRestTime(0f);
-                dto.setFloatchartVol(0f);
             }
             //鎵捐繖娆℃斁鐢电殑鎸囧畾涓�绗旀暟鎹�
             List<BatttestdataId> idDataList=battTestdataIdService.getLastDataByBattgroupId(tinf.getBattgroupId(),tinf.getTestRecordCount(),1);
@@ -941,16 +973,18 @@
    //浼樿壇鐢垫簮鏁伴噺缁熻(1.2.7)
     public Response getPwr7Statistic(Pwr7Stic stic) throws NoSuchFieldException, IllegalAccessException {
         Date inuseTimeStart =new Date();
-        if(stic.getInuseYear()==1){
-            //鎶曞叆浣跨敤鏃堕棿鏉′欢绛涢��
-            LocalDateTime startTime = LocalDateTime.now().minusYears(5);
-            inuseTimeStart = DateUtil.convertToDate(startTime);
-        }else{
-            //鎶曞叆浣跨敤鏃堕棿鏉′欢绛涢��
-            LocalDateTime startTime = LocalDateTime.now().minusYears(stic.getInuseYear());
-            inuseTimeStart = DateUtil.convertToDate(startTime);
+        if(stic.getInuseYear()!=null){
+            if(stic.getInuseYear()==1){
+                //鎶曞叆浣跨敤鏃堕棿鏉′欢绛涢��
+                LocalDateTime startTime = LocalDateTime.now().minusYears(5);
+                inuseTimeStart = DateUtil.convertToDate(startTime);
+            }else{
+                //鎶曞叆浣跨敤鏃堕棿鏉′欢绛涢��
+                LocalDateTime startTime = LocalDateTime.now().minusYears(stic.getInuseYear());
+                inuseTimeStart = DateUtil.convertToDate(startTime);
+            }
+            stic.setPwrInUseTime(inuseTimeStart);
         }
-        stic.setPwrInUseTime(inuseTimeStart);
         //1鏌ヨ绗﹀悎鏉′欢鐨勭數姹犵粍
         List<PowerInf> pinfList=powerInfService.getPwr7Statistic(stic);
         if(pinfList==null||pinfList.size()==0){
@@ -994,4 +1028,20 @@
     public int getHrDisCount(Integer userId, Date startTime, Date endTime) {
         return mapper.getHrDisCount(userId, startTime, endTime);
     }
+    //鑾峰彇杩欎竴娆$殑鏀剧數淇℃伅
+    public BatttestdataInf getTinfByTestRecordCount(Integer battgroupId, Integer testRecordCount) {
+        QueryWrapper wrapper=new QueryWrapper();
+        wrapper.eq("battgroup_id",battgroupId);
+        wrapper.eq("test_record_count",testRecordCount);
+        wrapper.last(" limit 1");
+        return mapper.selectOne(wrapper);
+    }
+    //鍘嗗彶娴嬭瘯鏁版嵁瀵煎嚭
+    public BatttestdataInf exportTinfDataByTestRecordCount(Integer battgroupId, Integer testRecordCount) {
+        QueryWrapper wrapper =new QueryWrapper();
+        wrapper.eq("battgroup_id",battgroupId);
+        wrapper.eq("test_record_count",testRecordCount);
+        wrapper.last(" limit 1");
+        return mapper.selectOne(wrapper);
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.1