From a7fae5f15fb4d278221e7e1c2ea428889fa79347 Mon Sep 17 00:00:00 2001
From: whyclxw <810412026@qq.com>
Date: 星期三, 04 六月 2025 16:03:05 +0800
Subject: [PATCH] 蓄电池组对比分析界面(同一品牌同一时间)

---
 src/main/java/com/whyc/service/BattInfService.java         |   13 ++
 src/main/java/com/whyc/dto/Statistic/BattCompareStic.java  |   23 ++++
 src/main/java/com/whyc/service/BatttestdataInfService.java |  116 +++++++++++++++++++++-
 src/main/java/com/whyc/controller/StatisticController.java |   14 ++
 src/main/java/com/whyc/dto/Statistic/SticCompareRes.java   |   24 ++++
 src/main/java/com/whyc/mapper/BattInfMapper.java           |    3 
 src/main/java/com/whyc/constant/Capperformance.java        |   46 +++++++++
 src/main/java/com/whyc/controller/ConditionController.java |    6 +
 src/main/resources/mapper/BattInfMapper.xml                |   31 ++++++
 9 files changed, 264 insertions(+), 12 deletions(-)

diff --git a/src/main/java/com/whyc/constant/Capperformance.java b/src/main/java/com/whyc/constant/Capperformance.java
new file mode 100644
index 0000000..4809963
--- /dev/null
+++ b/src/main/java/com/whyc/constant/Capperformance.java
@@ -0,0 +1,46 @@
+package com.whyc.constant;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public enum Capperformance {
+    BATTSTATE_1(1,"浼樼"),
+    BATTSTATE_2(2,"鍔e寲"),
+    BATTSTATE_3(3,"鎹熷潖"),
+    ;
+
+    private Integer stateId;
+    private String stateName;
+
+    Capperformance(Integer stateId, String stateName) {
+        this.stateId = stateId;
+        this.stateName = stateName;
+    }
+
+    public Integer getStateId() {
+        return stateId;
+    }
+
+    public String getStateName() {
+        return stateName;
+    }
+
+    public static String getValue(Integer stateId) {
+        if(stateId==null){
+            return "";
+        }
+        for (Capperformance ele : values()) {
+            if(ele.getStateId().equals(stateId)) {
+                return ele.getStateName();
+            }
+        }
+        return null;
+    }
+    public static Map<Integer,String> getOpInfo() {
+        Map<Integer,String> map=new HashMap<>();
+        for (Capperformance logOpEnum : Capperformance.values()) {
+            map.put(logOpEnum.getStateId(),logOpEnum.getStateName());
+        }
+        return map;
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/com/whyc/controller/ConditionController.java b/src/main/java/com/whyc/controller/ConditionController.java
index de224d6..1df03c8 100644
--- a/src/main/java/com/whyc/controller/ConditionController.java
+++ b/src/main/java/com/whyc/controller/ConditionController.java
@@ -163,6 +163,12 @@
         return pwrAlmService.getPwrAlmIdType();
     }
 
+    @ApiOperation(value = "鑾峰彇瀹归噺鎬ц兘(涓嬫媺)")
+    @GetMapping("getCapperformance")
+    public Response getCapperformance(){
+        return binfService.getCapperformance();
+    }
+
     @ApiOperation(value = "鑾峰彇璁惧宸ヤ綔绫诲瀷(涓嬫媺)")
     @GetMapping("getDevState")
     public Response getDevState(){
diff --git a/src/main/java/com/whyc/controller/StatisticController.java b/src/main/java/com/whyc/controller/StatisticController.java
index c45d3b4..d0db45b 100644
--- a/src/main/java/com/whyc/controller/StatisticController.java
+++ b/src/main/java/com/whyc/controller/StatisticController.java
@@ -1,10 +1,7 @@
 package com.whyc.controller;
 
 import com.whyc.dto.Response;
-import com.whyc.dto.Statistic.BattTinfStic;
-import com.whyc.dto.Statistic.DeviceStateStic;
-import com.whyc.dto.Statistic.MonStic;
-import com.whyc.dto.Statistic.StationStic;
+import com.whyc.dto.Statistic.*;
 import com.whyc.pojo.db_user.User;
 import com.whyc.service.*;
 import com.whyc.util.ActionUtil;
@@ -82,6 +79,13 @@
         stic.setUid(uinf.getId());
         return battTinfService.getBattTinfStatistic(stic);
     }
+    @ApiOperation(value = "钃勭數姹犵粍瀵规瘮鍒嗘瀽鐣岄潰锛堝悓涓�鍝佺墝鍚屼竴鏃堕棿锛�(1.2.15)")
+    @PostMapping("getBattCompare15Statistic")
+    public Response getBattCompare15Statistic(@RequestBody BattCompareStic stic){
+        User uinf= ActionUtil.getUser();
+        stic.setUid(uinf.getId());
+        return battTinfService.getBattCompare15Statistic(stic);
+    }
 
     @ApiOperation(value = "璁惧宸ヤ綔鐘舵�佺粺璁�(1.2.21)")
     @PostMapping("getDeviceStateStatistic")
@@ -90,4 +94,6 @@
         stic.setUid(uinf.getId());
         return deviceStateService.getDeviceStateStatistic(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
new file mode 100644
index 0000000..4a104c6
--- /dev/null
+++ b/src/main/java/com/whyc/dto/Statistic/BattCompareStic.java
@@ -0,0 +1,23 @@
+package com.whyc.dto.Statistic;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class BattCompareStic {
+    private String provice;
+    private String city;
+    private String country;
+    private String stationName;
+    private Integer uid;
+    private Integer pageNum;
+    private Integer pageSize;
+    private Integer performance;//鐢垫睜鎬ц兘锛�1浼樼锛�2鍔e寲锛�3鎹熷潖
+    private String product;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date testStartTime;//寮�濮嬫椂闂�
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date testEndTime;//缁撴潫鏃堕棿
+}
\ No newline at end of file
diff --git a/src/main/java/com/whyc/dto/Statistic/SticCompareRes.java b/src/main/java/com/whyc/dto/Statistic/SticCompareRes.java
new file mode 100644
index 0000000..acaa73e
--- /dev/null
+++ b/src/main/java/com/whyc/dto/Statistic/SticCompareRes.java
@@ -0,0 +1,24 @@
+package com.whyc.dto.Statistic;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import java.util.Date;
+import java.util.List;
+
+@Data
+public class SticCompareRes {
+    private String provice;
+    private String city;
+    private String country;
+    private String stationName;
+    private String battgroupName;
+    private String product;
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    private Date inuseTime;
+    private Float monvolstd;
+    private List<Integer> monNums;   //鎹熷潖鍗曚綋缂栧彿
+    private Float realCap;          //瀹為檯瀹归噺
+    private String precentCap;       //瀹归噺鐧惧垎姣�
+    private String capperformance; //鎬ц兘
+}
\ No newline at end of file
diff --git a/src/main/java/com/whyc/mapper/BattInfMapper.java b/src/main/java/com/whyc/mapper/BattInfMapper.java
index 539672d..80890ac 100644
--- a/src/main/java/com/whyc/mapper/BattInfMapper.java
+++ b/src/main/java/com/whyc/mapper/BattInfMapper.java
@@ -2,6 +2,7 @@
 
 import com.whyc.dto.BattDto;
 import com.whyc.dto.InfoDto;
+import com.whyc.dto.Statistic.BattCompareStic;
 import com.whyc.dto.Statistic.MonStic;
 import com.whyc.dto.Statistic.StationStic;
 import com.whyc.pojo.db_station.BattInf;
@@ -40,4 +41,6 @@
     List<BattInf> getBattStatistic(@Param("stic") StationStic stic);
     //鍗曚綋缁熻鏌ヨ绗﹀悎鏉′欢鐨勭數姹犵粍
     List<BattInf> getMonStatistic(@Param("stic") MonStic stic);
+    //钃勭數姹犵粍瀵规瘮鍒嗘瀽鐣岄潰
+    List<BattInf> getBattCompare15Statistic(@Param("stic") BattCompareStic stic);
 }
\ No newline at end of file
diff --git a/src/main/java/com/whyc/service/BattInfService.java b/src/main/java/com/whyc/service/BattInfService.java
index 74a6954..221859f 100644
--- a/src/main/java/com/whyc/service/BattInfService.java
+++ b/src/main/java/com/whyc/service/BattInfService.java
@@ -4,10 +4,13 @@
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.whyc.constant.Capperformance;
+import com.whyc.constant.PowerAlarmEnum;
 import com.whyc.dto.BattDto;
 import com.whyc.dto.InfoDto;
 import com.whyc.dto.Real.QuarterDto;
 import com.whyc.dto.Response;
+import com.whyc.dto.Statistic.BattCompareStic;
 import com.whyc.dto.Statistic.MonStic;
 import com.whyc.dto.Statistic.StationStic;
 import com.whyc.factory.InfoFactory;
@@ -26,6 +29,7 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 @Service
 public class BattInfService {
@@ -435,4 +439,13 @@
     public List<BattInf> getMonStatistic(MonStic stic) {
         return mapper.getMonStatistic(stic);
     }
+    //钃勭數姹犵粍瀵规瘮鍒嗘瀽鐣岄潰
+    public List<BattInf> getBattCompare15Statistic(BattCompareStic stic) {
+        return mapper.getBattCompare15Statistic(stic);
+    }
+    //鑾峰彇瀹归噺鎬ц兘(涓嬫媺)
+    public Response getCapperformance() {
+        Map<Integer,String> map= Capperformance.getOpInfo();
+        return new Response().setII(1,true,map,"鑾峰彇瀹归噺鎬ц兘(涓嬫媺)");
+    }
 }
\ No newline at end of file
diff --git a/src/main/java/com/whyc/service/BatttestdataInfService.java b/src/main/java/com/whyc/service/BatttestdataInfService.java
index 078f9bc..e8c549d 100644
--- a/src/main/java/com/whyc/service/BatttestdataInfService.java
+++ b/src/main/java/com/whyc/service/BatttestdataInfService.java
@@ -3,11 +3,9 @@
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.whyc.constant.Capperformance;
 import com.whyc.dto.Response;
-import com.whyc.dto.Statistic.BattTinfStic;
-import com.whyc.dto.Statistic.MonStic;
-import com.whyc.dto.Statistic.StationStic;
-import com.whyc.dto.Statistic.SticMonRes;
+import com.whyc.dto.Statistic.*;
 import com.whyc.factory.BattCapFactory;
 import com.whyc.mapper.BattInfMapper;
 import com.whyc.mapper.BatttestdataInfMapper;
@@ -17,13 +15,11 @@
 import com.whyc.pojo.db_ram_db.BattRtdata;
 import com.whyc.pojo.db_ram_db.BattRtstate;
 import com.whyc.pojo.db_station.BattInf;
+import com.whyc.util.PageInfoUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 @Service
 public class BatttestdataInfService {
@@ -219,4 +215,108 @@
             }
         }
     }
+    /*钃勭數姹犵粍瀵规瘮鍒嗘瀽鐣岄潰锛堝悓涓�鍝佺墝鍚屼竴鏃堕棿锛�
+     *1.鏌ヨ鍑虹鍚堟潯浠剁殑鐢垫睜缁勪俊鎭�
+     * 2.璁$畻鐢垫睜缁勭殑棰勪及鍓╀綑瀹归噺
+     *3.鍒ゆ柇鎬ц兘鍜岀櫨鍒嗘瘮
+     * 4.鍒嗛〉
+     */
+    public Response getBattCompare15Statistic(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);
+        if(binfList==null||binfList.size()==0){
+            return new Response().set(1,false,"褰撳墠鐢ㄦ埛鏈鐞嗘弧瓒虫潯浠剁殑鐢垫睜缁�");
+        }
+        List<SticCompareRes> reslist=new ArrayList<>();
+        for (BattInf binf:binfList) {
+            SticCompareRes res=new SticCompareRes();
+            res.setProvice(binf.getProvice());
+            res.setCity(binf.getCity());
+            res.setCountry(binf.getCountry());
+            res.setStationName(binf.getStationName());
+            res.setBattgroupName(binf.getBattgroupName());
+            res.setProduct(binf.getProduct());
+            res.setInuseTime(binf.getInuseTime());
+            res.setMonvolstd(binf.getMonvolstd());
+            //2.鑾峰彇鐢垫睜缁勫湪缁欏畾鏃堕棿娈电殑鏀剧數璁板綍(鎸囧畾鏃堕棿娈电殑鏍囧噯鏍稿鏀剧數)
+            BatttestdataInf tinf =getLastStandardTestDataByTime(binf.getBattgroupId(),stic.getTestStartTime(),stic.getTestEndTime());
+            if(tinf==null){
+                res.setRealCap(0f);
+                res.setPrecentCap("0");
+                res.setCapperformance(Capperformance.getValue(Capperformance.BATTSTATE_3.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(Capperformance.getValue(Capperformance.BATTSTATE_3.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(Capperformance.getValue(Capperformance.BATTSTATE_1.getStateId()));
+            }
+            if(grouprealCap<=moncapStd*damageValue){
+                res.setCapperformance(Capperformance.getValue(Capperformance.BATTSTATE_3.getStateId()));
+            }
+            if((grouprealCap>moncapStd*damageValue)&&(grouprealCap<moncapStd*badValue)){
+                res.setCapperformance(Capperformance.getValue(Capperformance.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.setMonNums(monNums);
+            if(stic.getPerformance()==0){
+                reslist.add(res);
+            }else{
+                if(res.getCapperformance().equals(Capperformance.getValue(stic.getPerformance()))){
+                    reslist.add(res);
+                }
+            }
+
+        }
+        PageInfo pageInfo=PageInfoUtils.list2PageInfo(reslist, stic.getPageNum(), stic.getPageSize());
+        return new Response().setII(1,reslist.size()>0,pageInfo,"钃勭數姹犵粍瀵规瘮鍒嗘瀽鐣岄潰锛堝悓涓�鍝佺墝鍚屼竴鏃堕棿锛�");
+    }
+    //鑾峰彇鐢垫睜缁勫湪缁欏畾鏃堕棿娈电殑鏀剧數璁板綍(鎸囧畾鏃堕棿娈电殑鏍囧噯鏍稿鏀剧數)
+    private BatttestdataInf getLastStandardTestDataByTime(Integer battgroupId, Date testStartTime, Date testEndTime) {
+        QueryWrapper wrapper = new QueryWrapper();
+        wrapper.eq("battgroup_id", battgroupId);
+        wrapper.eq("test_type", 3);
+        wrapper.eq("test_starttype", 3);
+        wrapper.gt("test_starttime",testStartTime);
+        wrapper.lt("test_starttime",testEndTime);
+        wrapper.last("  and test_timelong >= 7200 ORDER BY test_starttime DESC ");
+        wrapper.last("limit 1");
+        BatttestdataInf tinf = mapper.selectOne(wrapper);
+        return tinf;
+    }
 }
\ No newline at end of file
diff --git a/src/main/resources/mapper/BattInfMapper.xml b/src/main/resources/mapper/BattInfMapper.xml
index be47602..d1e1416 100644
--- a/src/main/resources/mapper/BattInfMapper.xml
+++ b/src/main/resources/mapper/BattInfMapper.xml
@@ -209,5 +209,36 @@
             </if>
         </where>
     </select>
+    <select id="getBattCompare15Statistic" resultType="com.whyc.pojo.db_station.BattInf">
+        select distinct tb_batt_inf.*
+        ,tb_station_inf.station_type,tb_station_inf.station_name,tb_station_inf.provice,tb_station_inf.city,tb_station_inf.country,tb_station_inf.full_name
+        from db_station.tb_batt_inf,db_station.tb_station_inf
+        <where>
+            tb_batt_inf.station_id=tb_station_inf.station_id
+            <if test="stic.provice!=null">
+                and tb_station_inf.provice=#{stic.provice}
+            </if>
+            <if test="stic.city!=null">
+                and tb_station_inf.city=#{stic.city}
+            </if>
+            <if test="stic.country!=null">
+                and tb_station_inf.country=#{stic.country}
+            </if>
+            <if test="stic.stationName!=null">
+                and tb_station_inf.station_name=#{stic.stationName}
+            </if>
+            <if test="stic.product!=null">
+                and tb_batt_inf.product=#{stic.product}
+            </if>
+            <if test="stic.uid>100">
+                and tb_batt_inf.station_id in(
+                select distinct station_id from db_user.tb_baojigroup_power,db_user.tb_baojigroup_usr
+                where   tb_baojigroup_power.baoji_group_id=tb_baojigroup_usr.baoji_group_id
+                and tb_baojigroup_usr.uid=#{stic.uid}
+                )
+            </if>
+            order by tb_batt_inf.dev_id asc,battgroup_id asc
+        </where>
+    </select>
 
 </mapper>
\ No newline at end of file

--
Gitblit v1.9.1