whyclxw
2025-05-28 e16302f9d475c7cc4dd18c5abf1a23cb5502e362
src/main/java/com/whyc/service/BatttestdataInfService.java
@@ -11,11 +11,13 @@
import com.whyc.pojo.*;
import com.whyc.util.ActionUtil;
import com.whyc.util.MessageUtils;
import com.whyc.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.Year;
import java.util.*;
import java.util.stream.Collectors;
@@ -43,6 +45,13 @@
    @Autowired
    private PageParamService pageParamService;
    @Autowired
    private SubTablePageInfoService subService;
    @Resource
    private BaoJiGroupMapper baoJiGroupMapper;
    //在线监测-历史监控-获取充放电记录
    public Response searchBattTestInfDataById(int battGroupId, int fbsDeviceId) {
        //查询出 4种类型的过滤时间值
@@ -56,7 +65,6 @@
        if (judgeNum > 0) {
            List<BatttestdataInf> list = mapper.selectList(wrapper);
            //过滤
            list = list.stream().filter(data->{
                Integer testType = data.getTestType();
                Integer testStarttype = data.getTestStarttype();
@@ -107,9 +115,12 @@
            }).collect(Collectors.toList());
            list.stream().forEach(tinf -> {
                //放电终止原因
                if (fbsDeviceId / 100000 == 6185) {
                if (fbsDeviceId / 10000 == 61850) {
                    //61850设备放电停止原因
                    tinf.setTestStoptypeReason(BattTestData.getStopType_6185(tinf.getTestStoptype()));
                }else if(fbsDeviceId / 10000 == 61852) {
                    //61852设备放电停止原因
                    tinf.setTestStoptypeReason(BattTestData.getStopType_61852(tinf.getTestStoptype()));
                } else if (fbsDeviceId / 100000 == 4016) {
                    //6度设备放电停止原因
                    tinf.setTestStoptypeReason(BattTestData.getStopType_4016(tinf.getTestStoptype()));
@@ -134,7 +145,15 @@
                } else if (fbsDeviceId / 100000 == 4815) {
                    //FBO4815设备放电停止原因
                    tinf.setTestStoptypeReason(BattTestData.getStopType_4815(tinf.getTestStoptype()));
                } else {
                }  else if (fbsDeviceId / 100000 == 6001) {
                    //6001设备放电停止原因
                    tinf.setTestStoptypeReason(BattTestData.getStopType_6001(tinf.getTestStoptype()));
                }else if ((fbsDeviceId / 10000 == 61853)||(fbsDeviceId / 100000 == 6186)||(fbsDeviceId / 100000 == 6286)) {
                    //61853设备放电停止原因
                    tinf.setTestStoptypeReason(BattTestData.getStopType_61853(tinf.getTestStoptype()));
                }else if((fbsDeviceId / 100000 == 6183)||(fbsDeviceId / 100000 == 6184)){
                    tinf.setTestStoptypeReason(BattTestData.getStopType_6183_4(tinf.getTestStoptype()));
                }else {
                    tinf.setTestStoptypeReason(BattTestData.getStopType(tinf.getTestStarttype(), tinf.getTestStoptype()));
                }
            });
@@ -158,9 +177,12 @@
        List<BattTestDataStop> list = new ArrayList<BattTestDataStop>();
        if (tinf != null) {
            //放电终止原因
            if (devId / 100000 == 6185) {
            if (devId / 10000 == 61850) {
                //61850设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_6185(tinf.getTestStoptype()));
            }else if(devId / 10000 == 61852) {
                //61852设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_61852(tinf.getTestStoptype()));
            } else if (devId / 100000 == 4016) {
                //6度设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_4016(tinf.getTestStoptype()));
@@ -185,13 +207,87 @@
            } else if (devId / 100000 == 4815) {
                //FBO4815设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_4815(tinf.getTestStoptype()));
            } else if (devId / 100000 == 6001) {
                //6001设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_6001(tinf.getTestStoptype()));
            } else if ((devId / 10000 == 61853)|| (devId / 100000 == 6186)|| (devId / 100000 == 6286)) {
                //61853设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_61853(tinf.getTestStoptype()));
            } else if (devId / 100000 == 9149) {
                //FBO9149设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_9149(tinf.getTestStoptype()));
            }else if (devId / 100000 == 9150) {
                //山东定制9150设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_9150(tinf.getTestStoptype()));
            }else if((devId / 100000 == 6183)||(devId / 100000 == 6184)){
                tinf.setTestStoptypeReason(BattTestData.getStopType_6183_4(tinf.getTestStoptype()));
            }else {
                tinf.setTestStoptypeReason(BattTestData.getStopType(tinf.getTestStarttype(), tinf.getTestStoptype()));
            }
            //list = stopMapper.getTestDataStop(tinf.getBattGroupId(), tinf.getTestStarttime());
            list = subService.getTestDataStop(tinf.getBattGroupId(), tinf.getTestStarttime());
            tinf.setBatttestdataList(list);
        }
        return new Response().setII(1, tinf != null ? true : false, tinf, "");
    }
    //最后一次核容放电数据
    public Response searchBattLastHrDataByIdDbs(int battGroupId, int devId, String lang) {
        PageHelper.startPage(1, 1);
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("BattGroupId", battGroupId);
        wrapper.eq("data_available", 1);
        wrapper.eq("test_type", 3);
        wrapper.eq("test_starttype", 3);
        wrapper.last(" and (test_stoptype in (3, 4, 6) or (test_stoptype = 2 and test_timelong >= 7200)) ORDER BY test_starttime DESC ");
        BatttestdataInf tinf = mapper.selectOne(wrapper);
        List<BattTestDataStop> list = new ArrayList<BattTestDataStop>();
        if (tinf != null) {
            //放电终止原因
            if (devId / 10000 == 61850) {//dbs为多宝山专用
                //61850设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_6185DBS(tinf.getTestStoptype()));
            }else if(devId / 10000 == 61852) {
                //61852设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_61852(tinf.getTestStoptype()));
            } else if (devId / 100000 == 4016) {
                //6度设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_4016(tinf.getTestStoptype()));
            } else if (devId / 100000 == 9110) {
                //假负载设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_9110(tinf.getTestStoptype()));
            } else if ((devId / 100000 == 9120) || (devId / 100000 == 9140)) {
                // 逆变设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_9120(tinf.getTestStoptype()));
            } else if (devId / 100000 == 8059) {
                //一体机设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_8059(tinf.getTestStoptype()));
            } else if(devId / 100000 == 6087) {
                //电操核容设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_6087(tinf.getTestStoptype()));
            }else if (devId / 100000 == 4830) {
                // FBO4830设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_4830(tinf.getTestStoptype()));
            } else if (devId / 100000 == 4831) {
                // FBO4830设备放电停止原因
                tinf.setTestStoptypeReason(MessageUtils.getMessageSocket(BattTestData.getStopType_4831(tinf.getTestStoptype()), lang));
            } else if (devId / 100000 == 4815) {
                //FBO4815设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_4815(tinf.getTestStoptype()));
            } else if (devId / 100000 == 6001) {
                //6001设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_6001(tinf.getTestStoptype()));
            } else if ((devId / 10000 == 61853)|| (devId / 100000 == 6186)|| (devId / 100000 == 6286)) {
                //61853设备放电停止原因和6186
                tinf.setTestStoptypeReason(BattTestData.getStopType_61853(tinf.getTestStoptype()));
            } else if (devId / 100000 == 9149) {
                //FBO9149设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_9149(tinf.getTestStoptype()));
            } else {
                tinf.setTestStoptypeReason(BattTestData.getStopType(tinf.getTestStarttype(), tinf.getTestStoptype()));
            }
            list = stopMapper.getTestDataStop(tinf.getBattGroupId(), tinf.getTestStarttime());
            //list = stopMapper.getTestDataStop(tinf.getBattGroupId(), tinf.getTestStarttime());
            list = subService.getTestDataStop(tinf.getBattGroupId(), tinf.getTestStarttime());
            tinf.setBatttestdataList(list);
        }
        return new Response().setII(1, tinf != null ? true : false, tinf, "");
@@ -214,8 +310,36 @@
    }
    //1.4电池组性能评估(根据电池组id查询所有的放电记录求出放电总次数,最高历史容量,最低历史容量,平均容量,最新测试容量)
    public Map<String, Object> searchDischargeTest(Integer battGroupId, float monCapStd, float monVolStd, Date recordStartTime, Date recordEndTime) {
        List<BatttestdataInf> list = mapper.searchDischargeTest(battGroupId, recordStartTime, recordEndTime);
    public Map<String, Object> searchDischargeTest(Integer battGroupId, float monCapStd, float monVolStd, Date recordStartTime, Date recordEndTime,int wj) {
        List<BatttestdataInf> list = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        if(wj==0){//本年
            list=mapper.searchDischargeTest(battGroupId, recordStartTime, recordEndTime);
            if( list.size()==0){
                map.put("wj", "N");
            }else{
                map.put("wj", "J");
            }
        }else if(wj==1){//往年
            list = mapper.searchDischargeTest_WJ(battGroupId, recordStartTime);
            if( list.size()==0){
                map.put("wj", "N");
            }else{
                map.put("wj", "W");
            }
        }else if(wj==-1){//全部
            list=mapper.searchDischargeTest(battGroupId, recordStartTime, recordEndTime);
            if( list.size()==0){
                list = mapper.searchDischargeTest_WJ(battGroupId, recordStartTime);
                if( list.size()==0){
                    map.put("wj", "N");
                }else{
                    map.put("wj", "W");
                }
            }else{
                map.put("wj", "J");
            }
        }
        List<BatttestdataInf> testList = new LinkedList<>();
        int sum = 0;//总测试次数
        float cap = 0f;//实际容量
@@ -228,12 +352,6 @@
            BatttestdataInf binf = list.get(i);
            int hourRate = BattCapFactory.GetHourRate(monCapStd, binf.getTestCurr());
            cap = (float) BattCapFactory.GetMonomerCap(monCapStd, hourRate, binf.getTestCap(), binf.getMaxMonvol(), binf.getMinMonvol(), monVolStd, BattCapFactory.CapType_Real);
           /* float testcap = binf.getTestCap();
            float maxMonvol = binf.getMaxMonvol();
            float minMonvol = binf.getMinMonvol();
            if (battGroupId == 1000145) {
                System.out.println(battGroupId + " " + monCapStd + " " + hourRate + " " + testcap + " " + maxMonvol + " " + minMonvol + " " + monVolStd + " " + BattCapFactory.CapType_Real + " ");
            }*/
            binf.setRealCap(cap);
            testList.add(binf);
            if (sum == 0) {
@@ -254,7 +372,6 @@
            avgCap = 0;
            minCap = 0;
        }
        Map<String, Object> map = new HashMap<>();
        map.put("battGroupid", battGroupId);
        map.put("sum", sum);
        map.put("maxCap", maxCap);
@@ -417,6 +534,7 @@
        }
    }*/
    public Map<String, Integer> analysisTestData(List<BatttestdataInf> list) {
        List<PageParam> pageParamList = pageParamService.getList2ByCategoryId(14);
        Map<String, Integer> map = new HashMap<>();
        int hrdisNum = 0;//核容放电
        int jcdisNum = 0;//监测放电
@@ -437,7 +555,9 @@
                            dddisNum += 1;
                        }
                        if (tinf.getTestDatatype() == 0) {
                            jcdisNum += 1;
                            if(tinf.getTestTimelong()>=pageParamList.get(2).getStatus()*60) {
                                jcdisNum += 1;
                            }
                        }
                    }
                } else if (tinf.getTestType() == 2) {
@@ -445,7 +565,9 @@
                    if (tinf.getTestStarttype() == 3) {
                        hrchNum += 1;
                    } else {
                        jcchNum += 1;
                        if(tinf.getTestTimelong()>=pageParamList.get(3).getStatus()*60) {
                            jcchNum += 1;
                        }
                    }
                }
            }
@@ -484,6 +606,13 @@
        return hrQuarter;
    }
    //山西晋源特定接口
    public int getHrQuarterZCJY() {
        int hrQuarter = mapper.getHrQuarterZCJY();
        return hrQuarter;
    }
    //蓄电池组优劣分析(用蓄电池组组后评估的统计)
    public Response getGroupAnalysis(int userId) {
        try {
@@ -511,30 +640,44 @@
            int goodSum = 0;
            //未正常
            int noHrDisNum = 0;
            //实际容量
            float cap = 0f;
            //去年的数据----------------
            //小于capAlarm
            int oldalarmNum = 0;
            //小于capChange
            int oldchangeNum = 0;
            //放电正常
            int oldgoodSum = 0;
            //未正常
            int oldnoHrDisNum = 0;
            //0.查询所有的电池组
            List<Battinf> binfList = binfMapper.getBinfList(userId);
            if (binfList != null && binfList.size() > 0) {
                for (Battinf binf : binfList) {
                    //实际容量
                    float cap = 0f;
                    //实际容量去年
                    float oldcap = 0f;
                    int battgroupId = binf.getBattGroupId();
                    float monCapStd = binf.getMonCapStd();
                    float monVolstd = binf.getMonVolStd();
                    //放电次数
                    int disNum = 0;
                    //1.查出符合条件的电池组(核容数据)按照时间倒叙排序的第一个
                    int olddisNum = 0;
                    //1.查出符合条件的电池组(核容数据)按照时间倒叙排序的第一个(本年度)
                    BatttestdataInf inf = mapper.getGroupAnalysisQB(battgroupId);
                    //1.查出符合条件的电池组(核容数据)按照时间倒叙排序的第一个(上一年度)
                    BatttestdataInf oldinf = mapper.getGroupAnalysisQBOld(battgroupId);
                    if (inf != null) {
                        disNum = 1;
                        int hourRate = BattCapFactory.GetHourRate(monCapStd, inf.getTestCurr());
                        cap = (float) BattCapFactory.GetMonomerCap(monCapStd, hourRate, inf.getTestCap(), inf.getMaxMonvol(), inf.getMinMonvol(), monVolstd, BattCapFactory.CapType_Real);
                        /*float testcap = inf.getTestCap();
                        float maxMonvol = inf.getMaxMonvol();
                        float minMonvol = inf.getMinMonvol();
                        if (battgroupId == 1000145) {
                            System.out.println(battgroupId + " " + monCapStd + " " + hourRate + " " + testcap + " " + maxMonvol + " " + minMonvol + " " + monVolstd + " " + BattCapFactory.CapType_Real + " ");
                        }*/
                    }
                    if(oldinf!=null){
                        olddisNum=1;
                        int oldhourRate = BattCapFactory.GetHourRate(monCapStd, oldinf.getTestCurr());
                        oldcap = (float) BattCapFactory.GetMonomerCap(monCapStd, oldhourRate, oldinf.getTestCap(), oldinf.getMaxMonvol(), oldinf.getMinMonvol(), monVolstd, BattCapFactory.CapType_Real);
                    }
                    //查询电池告警(劣化:内阻过高重要,电压过低重要;损坏:内阻过高紧急,电压过低紧急)
                    List listALmSH = alarmDataMapper.getAlm(battgroupId, 3);
@@ -563,6 +706,31 @@
                    } else {
                        noHrDisNum += 1;
                    }
                    //去年-----------------的数据
                    //先判断是否损坏
                    if ((olddisNum != 0 && oldcap < capChange * monCapStd) || (listALmSH != null && listALmSH.size() > 0)) {
                        if (olddisNum == 0) {
                            oldnoHrDisNum += 1;
                        }
                       oldchangeNum = oldchangeNum + 1;
                    }//在判断是否劣化
                    else if (
                            (olddisNum != 0 && oldcap <= capAlarm * monCapStd && oldcap >= capChange * monCapStd
                            )
                                    || (listALmLH != null && listALmLH.size() > 0)) {
                        if (olddisNum == 0) {
                            oldnoHrDisNum += 1;
                        }
                        oldalarmNum = oldalarmNum + 1;
                    }//再判断是否放电正常
                    else if (olddisNum != 0 && oldcap > capAlarm * monCapStd) {
                        if (olddisNum == 0) {
                            oldnoHrDisNum += 1;
                        }
                        oldgoodSum = oldgoodSum + 1;
                    } else {
                        oldnoHrDisNum += 1;
                    }
                }
            }
            Map<String, Integer> numMap = new HashMap<>();
@@ -585,12 +753,358 @@
                6-组端电压下限到终止*/
            //int hrDisNum = mapper.getHrQuarterZC(userId);
            numMap.put("noHrDisNum", noHrDisNum);
            return new Response().setII(1, true, numMap, "蓄电池组优劣分析");
           //去年----------------------------统计
            Map<String, Integer> oldnumMap = new HashMap<>();
            oldnumMap.put("alarmNum", oldalarmNum);
            oldnumMap.put("changeNum", oldchangeNum);
            //总电池组(分类)
            oldnumMap.put("groupNum", groupNum);
            //蓄电池优良(已经放电数-告警数)
            oldnumMap.put("goodSum", oldgoodSum);
             /*本年度已核容放电电池组(testdate_inf中test_type=3,test_startType=3)
             int hrDisNum = testInfService.getHrQuarter(userId);
            * 修改为:领导层本年度已放数 仅需要统计放电正常停止的 正常停止的条件如下:
                stop_type:
                2-放电时间到终止并且放电时间超过2小时
                3-放电容量到终止
                4-单体电压下限到终止
                6-组端电压下限到终止*/
            oldnumMap.put("noHrDisNum", oldnoHrDisNum);
            return new Response().setIII(1, true, numMap,oldnumMap, "蓄电池组优劣分析");
        } catch (Exception e) {
            return new Response<>().set(1, false, "发生异常:" + e.getCause());
        }
    }
    //蓄电池组优劣分析(用蓄电池组组后评估的统计)
    public Response getGroupAnalysis2(int userId) {
        try {
            //0.查询劣化(告警)和损坏(更换)的阈值
            QueryWrapper<AlarmParam> alarmWrapper = new QueryWrapper();
            alarmWrapper.and(wrapper -> {
                return wrapper.eq("alm_name", "Batt_Alarm_Type_CapAlarm").or().eq("alm_name", "Batt_Alarm_Type_CapChange");
            });
            alarmWrapper.orderByAsc("alm_id");
            List<AlarmParam> paramList = alarmParamMapper.selectList(alarmWrapper);
            float capAlarm = 0f;
            float capChange = 0f;
            if (paramList != null && paramList.size() > 0) {
                capAlarm = paramList.get(0).getAlmLowCoe();//劣化参数0.8
                capChange = paramList.get(1).getAlmLowCoe();//损坏参数0.6
            } else {
                capAlarm = 0.8f;
                capChange = 0.6f;
            }
            //获取当前年
            int year = Year.now().getValue();
            Date nowDateStart=ThreadLocalUtil.parse(year+"-01-01 00:00:00",1);
            Date nowDateEnd=ThreadLocalUtil.parse(year+"-12-31 23:59:59",1);
            Date oldDateStart=ThreadLocalUtil.parse((year-1)+"-01-01 00:00:00",1);
            Date oldDateEnd=ThreadLocalUtil.parse((year-1)+"-12-31 23:59:59",1);
            //小于capAlarm
            int alarmNum = 0;
            //小于capChange
            int changeNum = 0;
            //放电正常
            int goodSum = 0;
            //未正常
            int noHrDisNum = 0;
            //去年的数据----------------
            //小于capAlarm
            int oldalarmNum = 0;
            //小于capChange
            int oldchangeNum = 0;
            //放电正常
            int oldgoodSum = 0;
            //未正常
            int oldnoHrDisNum = 0;
            //0.查询所有的电池组
            List<Battinf> binfList = binfMapper.getBinfList(userId);
            if (binfList != null && binfList.size() > 0) {
                for (Battinf binf : binfList) {
                    //实际容量
                    float cap = 0f;
                    float oldcap = 0f;
                    //放电次数
                    int disNum = 0;
                    int olddisNum = 0;
                    int battgroupId = binf.getBattGroupId();
                    float monCapStd = binf.getMonCapStd();
                    float monVolstd = binf.getMonVolStd();
                    //1.查出符合条件的电池组(核容数据)按照时间倒叙排序的第一个(本年度)
                    BatttestdataInf inf = mapper.getGroupAnalysisQB_WJ(battgroupId,nowDateStart,nowDateEnd);
                    //1.查出符合条件的电池组(核容数据)按照时间倒叙排序的第一个(上一年度)
                    BatttestdataInf oldinf = mapper.getGroupAnalysisQB_WJ(battgroupId,oldDateStart,oldDateEnd);
                    if (inf != null) {
                        disNum=1;
                        int hourRate = BattCapFactory.GetHourRate(monCapStd, inf.getTestCurr());
                        cap = (float) BattCapFactory.GetMonomerCap(monCapStd, hourRate, inf.getTestCap(), inf.getMaxMonvol(), inf.getMinMonvol(), monVolstd, BattCapFactory.CapType_Real);
                    }
                    if(oldinf!=null){
                        olddisNum=1;
                        int oldhourRate = BattCapFactory.GetHourRate(monCapStd, oldinf.getTestCurr());
                        oldcap = (float) BattCapFactory.GetMonomerCap(monCapStd, oldhourRate, oldinf.getTestCap(), oldinf.getMaxMonvol(), oldinf.getMinMonvol(), monVolstd, BattCapFactory.CapType_Real);
                    }
                    //查询电池告警内阻告警
                    List listALmRes = alarmDataMapper.getAlm2(battgroupId);
                        //未放电:本年度未放电,且无内阻告警<13,14>(预告警(重要),告警(紧急))-----本年度
                        if( (disNum==0) ){
                            noHrDisNum+=1;
                        }
                        //优秀:本年度已放电,且容量健康,无内阻告警(预告警(重要),告警(紧急))
                        if( (disNum>0)&&(cap > capAlarm * monCapStd)&&(listALmRes.size()<=0)){
                            goodSum+=1;
                        }
                        /*劣化:本年度未放电,内阻告警(预告警(重要),告警(紧急))
                         *容量小于劣化阈值,大于损坏阈值,内阻告警(预告警,告警)
                         *     容量小于劣化阈值,内阻正常
                         *     容量正常,内阻告警(预告警,告警)
                         */
                        if (((disNum==0)&&(listALmRes.size()>0))
                                ||((disNum>0)&&(cap <= capAlarm * monCapStd && cap >= capChange * monCapStd)&&(listALmRes.size()>0))
                                ||((disNum>0)&&(cap <= capAlarm * monCapStd)&&(listALmRes.size()<=0))
                                ||(disNum>0)&&(cap > capAlarm * monCapStd)&&(listALmRes.size()>0)){
                            alarmNum+=1;
                        }
                        //损坏:容量低,内阻告警
                        if((disNum>0)&&(cap< capChange * monCapStd)&&(listALmRes.size()>0)){
                            changeNum+=1;
                        }
                        //未放电:本年度未放电,且无内阻告警<13,14>(预告警(重要),告警(紧急))-----其他年度
                        if( (olddisNum==0) ){
                            oldnoHrDisNum+=1;
                        }
                        //优秀:本年度已放电,且容量健康,无内阻告警(预告警(重要),告警(紧急))
                        if( (olddisNum>0)&&(oldcap > capAlarm * monCapStd)&&(listALmRes.size()<=0)){
                            oldgoodSum+=1;
                        }
                        /*劣化:本年度未放电,内阻告警(预告警(重要),告警(紧急))
                         *容量小于劣化阈值,大于损坏阈值,内阻告警(预告警,告警)
                         *     容量小于劣化阈值,内阻正常
                         *     容量正常,内阻告警(预告警,告警)
                         */
                        if (((olddisNum==0)&&(listALmRes.size()>0))
                                ||((olddisNum>0)&&(oldcap <= capAlarm * monCapStd && oldcap >= capChange * monCapStd)&&(listALmRes.size()>0))
                                ||((olddisNum>0)&&(oldcap <= capAlarm * monCapStd)&&(listALmRes.size()<=0))
                                ||(olddisNum>0)&&(oldcap > capAlarm * monCapStd)&&(listALmRes.size()>0)){
                            oldalarmNum+=1;
                        }
                        //损坏:容量低,内阻告警
                        if((olddisNum>0)&&(oldcap< capChange * monCapStd)&&(listALmRes.size()>0)){
                            oldchangeNum+=1;
                        }
                    }
            }
            Map<String, Integer> numMap = new HashMap<>();
            numMap.put("alarmNum", alarmNum);
            numMap.put("changeNum", changeNum);
            //总电池组(分类)
            int groupNum = binfMapper.geGroupCount(userId);
            numMap.put("groupNum", groupNum);
            /*//已放电电池组数
            int inDischargeNum = binfMapper.searchInDischarge(userId);*/
            //蓄电池优良(已经放电数-告警数)
            numMap.put("goodSum", goodSum);
             /*本年度已核容放电电池组(testdate_inf中test_type=3,test_startType=3)
             int hrDisNum = testInfService.getHrQuarter(userId);
            * 修改为:领导层本年度已放数 仅需要统计放电正常停止的 正常停止的条件如下:
                stop_type:
                2-放电时间到终止并且放电时间超过2小时
                3-放电容量到终止
                4-单体电压下限到终止
                6-组端电压下限到终止*/
            //int hrDisNum = mapper.getHrQuarterZC(userId);
            numMap.put("noHrDisNum", noHrDisNum);
            //去年----------------------------统计
            Map<String, Integer> oldnumMap = new HashMap<>();
            oldnumMap.put("alarmNum", oldalarmNum);
            oldnumMap.put("changeNum", oldchangeNum);
            //总电池组(分类)
            oldnumMap.put("groupNum", groupNum);
            //蓄电池优良(已经放电数-告警数)
            oldnumMap.put("goodSum", oldgoodSum);
             /*本年度已核容放电电池组(testdate_inf中test_type=3,test_startType=3)
             int hrDisNum = testInfService.getHrQuarter(userId);
            * 修改为:领导层本年度已放数 仅需要统计放电正常停止的 正常停止的条件如下:
                stop_type:
                2-放电时间到终止并且放电时间超过2小时
                3-放电容量到终止
                4-单体电压下限到终止
                6-组端电压下限到终止*/
            oldnumMap.put("noHrDisNum", oldnoHrDisNum);
            return new Response().setIII(1, true, numMap,oldnumMap, "蓄电池组优劣分析");
        } catch (Exception e) {
            return new Response<>().set(1, false, "发生异常:" + e.getCause());
        }
    }
    //蓄电池组优劣分析(用蓄电池组组后评估的统计)
    public Response getGroupAnalysis3(int userId) {
        try {
            //0.查询劣化(告警)和损坏(更换)的阈值
            QueryWrapper<AlarmParam> alarmWrapper = new QueryWrapper();
            alarmWrapper.and(wrapper -> {
                return wrapper.eq("alm_name", "Batt_Alarm_Type_CapAlarm").or().eq("alm_name", "Batt_Alarm_Type_CapChange");
            });
            alarmWrapper.orderByAsc("alm_id");
            List<AlarmParam> paramList = alarmParamMapper.selectList(alarmWrapper);
            float capAlarm = 0f;
            float capChange = 0f;
            if (paramList != null && paramList.size() > 0) {
                capAlarm = paramList.get(0).getAlmLowCoe();//劣化参数0.8
                capChange = paramList.get(1).getAlmLowCoe();//损坏参数0.6
            } else {
                capAlarm = 0.8f;
                capChange = 0.6f;
            }
            //获取当前年
            int year = Year.now().getValue();
            Date nowDateStart=ThreadLocalUtil.parse(year+"-01-01 00:00:00",1);
            Date nowDateEnd=ThreadLocalUtil.parse(year+"-12-31 23:59:59",1);
            Date oldDateStart=ThreadLocalUtil.parse((year-1)+"-01-01 00:00:00",1);
            Date oldDateEnd=ThreadLocalUtil.parse((year-1)+"-12-31 23:59:59",1);
            //小于capAlarm
            int alarmNum = 0;
            //小于capChange
            int changeNum = 0;
            //放电正常
            int goodSum = 0;
            //未正常
            int noHrDisNum = 0;
            //去年的数据----------------
            //小于capAlarm
            int oldalarmNum = 0;
            //小于capChange
            int oldchangeNum = 0;
            //放电正常
            int oldgoodSum = 0;
            //未正常
            int oldnoHrDisNum = 0;
            //0.查询所有的电池组
            List<Battinf> binfList = binfMapper.getBinfList(userId);
            if (binfList != null && binfList.size() > 0) {
                for (Battinf binf : binfList) {
                    //实际容量
                    float cap = 0f;
                    float oldcap = 0f;
                    //放电次数
                    int disNum = 0;
                    int olddisNum = 0;
                    int battgroupId = binf.getBattGroupId();
                    float monCapStd = binf.getMonCapStd();
                    float monVolstd = binf.getMonVolStd();
                    //1.查出符合条件的电池组(核容数据)按照时间倒叙排序的第一个(本年度)
                    BatttestdataInf inf = mapper.getGroupAnalysisQB_WJ(battgroupId,nowDateStart,nowDateEnd);
                    //1.查出符合条件的电池组(核容数据)按照时间倒叙排序的第一个(上一年度)
                    BatttestdataInf oldinf = mapper.getGroupAnalysisQB_WJ(battgroupId,oldDateStart,oldDateEnd);
                    if (inf != null) {
                        disNum=1;
                        int hourRate = BattCapFactory.GetHourRate(monCapStd, inf.getTestCurr());
                        cap = (float) BattCapFactory.GetMonomerCap(monCapStd, hourRate, inf.getTestCap(), inf.getMaxMonvol(), inf.getMinMonvol(), monVolstd, BattCapFactory.CapType_Real);
                    }
                    if(oldinf!=null){
                        olddisNum=1;
                        int oldhourRate = BattCapFactory.GetHourRate(monCapStd, oldinf.getTestCurr());
                        oldcap = (float) BattCapFactory.GetMonomerCap(monCapStd, oldhourRate, oldinf.getTestCap(), oldinf.getMaxMonvol(), oldinf.getMinMonvol(), monVolstd, BattCapFactory.CapType_Real);
                    }
                    //未放电:本年度未放电,且无内阻告警<13,14>(预告警(重要),告警(紧急))-----本年度
                    if( (disNum==0) ){
                        noHrDisNum+=1;
                    }
                    //优秀:本年度已放电,且容量健康)
                    if( (disNum>0)&&(cap > capAlarm * monCapStd)){
                        goodSum+=1;
                    }
                    /*劣化:
                     *容量小于劣化阈值,大于损坏阈值
                     */
                    if (((disNum>0)&&(cap <= capAlarm * monCapStd && cap >= capChange * monCapStd))){
                        alarmNum+=1;
                    }
                    //损坏:容量低
                    if((disNum>0)&&(cap< capChange * monCapStd)){
                        changeNum+=1;
                    }
                    //未放电:本年度未放电,且无内阻告警<13,14>(预告警(重要),告警(紧急))-----其他年度
                    if( (olddisNum==0) ){
                        oldnoHrDisNum+=1;
                    }
                    //优秀:本年度已放电,且容量健康)
                    if( (olddisNum>0)&&(oldcap > capAlarm * monCapStd)){
                        oldgoodSum+=1;
                    }
                    /*劣化
                     *容量小于劣化阈值,大于损坏阈值
                     *
                     */
                    if (((olddisNum>0)&&(oldcap <= capAlarm * monCapStd && oldcap >= capChange * monCapStd))){
                        oldalarmNum+=1;
                    }
                    //损坏:容量低
                    if((olddisNum>0)&&(oldcap< capChange * monCapStd)){
                        oldchangeNum+=1;
                    }
                }
            }
            Map<String, Integer> numMap = new HashMap<>();
            numMap.put("alarmNum", alarmNum);
            numMap.put("changeNum", changeNum);
            //总电池组(分类)
            int groupNum = binfMapper.geGroupCount(userId);
            numMap.put("groupNum", groupNum);
            /*//已放电电池组数
            int inDischargeNum = binfMapper.searchInDischarge(userId);*/
            //蓄电池优良(已经放电数-告警数)
            numMap.put("goodSum", goodSum);
             /*本年度已核容放电电池组(testdate_inf中test_type=3,test_startType=3)
             int hrDisNum = testInfService.getHrQuarter(userId);
            * 修改为:领导层本年度已放数 仅需要统计放电正常停止的 正常停止的条件如下:
                stop_type:
                2-放电时间到终止并且放电时间超过2小时
                3-放电容量到终止
                4-单体电压下限到终止
                6-组端电压下限到终止*/
            //int hrDisNum = mapper.getHrQuarterZC(userId);
            numMap.put("noHrDisNum", noHrDisNum);
            //去年----------------------------统计
            Map<String, Integer> oldnumMap = new HashMap<>();
            oldnumMap.put("alarmNum", oldalarmNum);
            oldnumMap.put("changeNum", oldchangeNum);
            //总电池组(分类)
            oldnumMap.put("groupNum", groupNum);
            //蓄电池优良(已经放电数-告警数)
            oldnumMap.put("goodSum", oldgoodSum);
             /*本年度已核容放电电池组(testdate_inf中test_type=3,test_startType=3)
             int hrDisNum = testInfService.getHrQuarter(userId);
            * 修改为:领导层本年度已放数 仅需要统计放电正常停止的 正常停止的条件如下:
                stop_type:
                2-放电时间到终止并且放电时间超过2小时
                3-放电容量到终止
                4-单体电压下限到终止
                6-组端电压下限到终止*/
            oldnumMap.put("noHrDisNum", oldnoHrDisNum);
            return new Response().setIII(1, true, numMap,oldnumMap, "蓄电池组优劣分析");
        } catch (Exception e) {
            return new Response<>().set(1, false, "发生异常:" + e.getCause());
        }
    }
    //获取本年已核容放电电池组最新一次数据详情
    public Response getHrYeardisBattInfo() {
        int userId = Integer.parseInt(ActionUtil.getUser().getUId().toString());
@@ -667,9 +1181,12 @@
                        float cap = (float) BattCapFactory.GetMonomerCap(inf.getMonCapStd(), hourRate, inf.getTestCap(), inf.getMaxMonvol(), inf.getMinMonvol(), inf.getMonVolStd(), BattCapFactory.CapType_Real);
                        inf.setRealCap(cap);
                        //放电终止原因
                        if (inf.getFBSDeviceId() / 100000 == 6185) {
                        if (inf.getFBSDeviceId() / 10000 == 61850) {
                            //61850设备放电停止原因
                            inf.setTestStoptypeReason(BattTestData.getStopType_6185(inf.getTestStoptype()));
                        }else if(inf.getFBSDeviceId() / 10000 == 61852) {
                            //61852设备放电停止原因
                            inf.setTestStoptypeReason(BattTestData.getStopType_61852(inf.getTestStoptype()));
                        } else if (inf.getFBSDeviceId() / 100000 == 4016) {
                            //6度设备放电停止原因
                            inf.setTestStoptypeReason(BattTestData.getStopType_4016(inf.getTestStoptype()));
@@ -694,6 +1211,12 @@
                        } else if (inf.getFBSDeviceId() / 100000 == 4815) {
                            //FBO4815设备放电停止原因
                            inf.setTestStoptypeReason(BattTestData.getStopType_4815(inf.getTestStoptype()));
                        } else if (inf.getFBSDeviceId() / 100000 == 6001) {
                            //6001设备放电停止原因
                            inf.setTestStoptypeReason(BattTestData.getStopType_6001(inf.getTestStoptype()));
                        } else if ((inf.getFBSDeviceId() / 10000 == 61853)||(inf.getFBSDeviceId() / 100000 == 6186)||(inf.getFBSDeviceId() / 100000 == 6286)) {
                            //61853设备放电停止原因
                            inf.setTestStoptypeReason(BattTestData.getStopType_61853(inf.getTestStoptype()));
                        } else if (inf.getFBSDeviceId() / 100000 == 9149) {
                            //FBO4815设备放电停止原因
                            inf.setTestStoptypeReason(BattTestData.getStopType_9149(inf.getTestStoptype()));
@@ -721,4 +1244,127 @@
        }
        return new Response().setII(1, true, testNumber, "本年度上一次正常核容的放电记录编号");
    }
    //能效统计
    public Response getEnergyStatistics(int year) {
        Calendar calendar = Calendar.getInstance();
        int nowYear= calendar.get(Calendar.YEAR);
        int lastYear=nowYear-year+1;
        Date date1 = ThreadLocalUtil.parse(lastYear+"-01-01 00:00:00",1 );
        Date date2 = ThreadLocalUtil.parse(nowYear+"-12-31 23:59:59",1 );
        List<GroupTestCapRes> list=mapper.getEnergyStatistics(date1,date2);
        Map<Integer,Integer> sCountMap=new HashMap<>();
        Map<Integer,String> sCapMap=new HashMap<>();
        for (int i=0;i<year;i++){
            sCountMap.put(lastYear+i,0);
            sCapMap.put(lastYear+i,"0");
        }
        Map<Integer, List<GroupTestCapRes>> yearMap = list.stream().collect(Collectors.groupingBy(GroupTestCapRes::getYearTime));
        for (Integer yearTime : yearMap.keySet()) {
            sCountMap.put(yearTime,yearMap.get(yearTime).size());
            List<GroupTestCapRes> groupList=yearMap.get(yearTime);
            Double sum = groupList.stream().collect(Collectors.summingDouble(GroupTestCapRes::getTestCap));
            sCapMap.put(yearTime,String.format("%.3f",sum));
        }
        return new Response().setIII(1, true, sCountMap,sCapMap, "能效统计");
    }
    //能效统计分班组
    public Response getEnergyStatisticsInBaojiGroup(int year) {
        Calendar calendar = Calendar.getInstance();
        int nowYear= calendar.get(Calendar.YEAR);
        int lastYear=nowYear-year+1;
        Date date1 = ThreadLocalUtil.parse(lastYear+"-01-01 00:00:00",1 );
        Date date2 = ThreadLocalUtil.parse(nowYear+"-12-31 23:59:59",1 );
        //1.查询出所有的班组
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("discharge_plan_flag",1);
        List<BaoJiGroup> listbj=baoJiGroupMapper.selectList(wrapper);
        List<EnergyStatisticDto> listeg=new ArrayList<>();
        if(listbj!=null&&listbj.size()>0){
            for (BaoJiGroup bj:listbj) {
                EnergyStatisticDto egDto=new EnergyStatisticDto();
                egDto.setBaoJiGroup(bj);
                Long bjGroupId=bj.getBaoJiGroupId();
                List<GroupTestCapRes> list=mapper.getEnergyStatisticsInBaojiGroup(date1,date2,bjGroupId);
                Map<Integer,Integer> sCountMap=new HashMap<>();
                Map<Integer,String> sCapMap=new HashMap<>();
                for (int i=0;i<year;i++){
                    sCountMap.put(lastYear+i,0);
                    sCapMap.put(lastYear+i,"0");
                }
                egDto.setSCountMap(sCountMap);
                Map<Integer, List<GroupTestCapRes>> yearMap = list.stream().collect(Collectors.groupingBy(GroupTestCapRes::getYearTime));
                for (Integer yearTime : yearMap.keySet()) {
                    sCountMap.put(yearTime,yearMap.get(yearTime).size());
                    List<GroupTestCapRes> groupList=yearMap.get(yearTime);
                    Double sum = groupList.stream().collect(Collectors.summingDouble(GroupTestCapRes::getTestCap));
                    sCapMap.put(yearTime,String.format("%.3f",sum));
                }
                egDto.setSCapMap(sCapMap);
                listeg.add(egDto);
            }
        }
        return new Response().setII(1, true, listeg, "能效统计分班组");
    }
    //能效统计分班组
    public Response getEnergyStatisticsInBaojiGroupWithOutYear(int year) {
        Calendar calendar = Calendar.getInstance();
        int nowYear= calendar.get(Calendar.YEAR);
        int lastYear=nowYear-year+1;
        Date date1 = ThreadLocalUtil.parse(lastYear+"-01-01 00:00:00",1 );
        Date date2 = ThreadLocalUtil.parse(nowYear+"-12-31 23:59:59",1 );
        //1.查询出所有的班组
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("discharge_plan_flag",1);
        List<BaoJiGroup> listbj=baoJiGroupMapper.selectList(wrapper);
        Map<String,Integer> sCountMap=new HashMap<>();
        Map<String,String> sCapMap=new HashMap<>();
        if(listbj!=null&&listbj.size()>0){
            for (BaoJiGroup bj:listbj) {
                Long bjGroupId=bj.getBaoJiGroupId();
                List<GroupTestCapRes> list=mapper.getEnergyStatisticsInBaojiGroup(date1,date2,bjGroupId);
                sCountMap.put(bj.getBaoJiGroupName(),list.size());
                Double sum = list.stream().collect(Collectors.summingDouble(GroupTestCapRes::getTestCap));
                sCapMap.put(bj.getBaoJiGroupName(),String.format("%.3f",sum));
            }
        }
        return new Response().setIII(1, true, sCountMap,sCapMap, "能效统计");
    }
    //能效统计--南京websocket首页
    public Response getEnergyStatistics_nj(int year,int userId) {
        Calendar calendar = Calendar.getInstance();
        int nowYear= calendar.get(Calendar.YEAR);
        int lastYear=nowYear-year+1;
        Date date1 = ThreadLocalUtil.parse(lastYear+"-01-01 00:00:00",1 );
        Date date2 = ThreadLocalUtil.parse(nowYear+"-12-31 23:59:59",1 );
        List<GroupTestCapRes> list=mapper.getEnergyStatistics_nj(date1,date2,userId);
        Map<Integer,Integer> sCountMap=new HashMap<>();
        Map<Integer,String> sCapMap=new HashMap<>();
        for (int i=0;i<year;i++){
            sCountMap.put(lastYear+i,0);
            sCapMap.put(lastYear+i,"0");
        }
        Map<Integer, List<GroupTestCapRes>> yearMap = list.stream().collect(Collectors.groupingBy(GroupTestCapRes::getYearTime));
        for (Integer yearTime : yearMap.keySet()) {
            sCountMap.put(yearTime,yearMap.get(yearTime).size());
            List<GroupTestCapRes> groupList=yearMap.get(yearTime);
            Double sum = groupList.stream().collect(Collectors.summingDouble(GroupTestCapRes::getTestCap));
            sCapMap.put(yearTime,String.format("%.3f",sum));
        }
        return new Response().setIII(1, true, sCountMap,sCapMap, "能效统计");
    }
    //1.获取当前最大的放电信息testRecordCount
    public BatttestdataInf getMaxRecord(int battGroupId) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("battGroupId",battGroupId);
        wrapper.last("limit 1");
        wrapper.orderByDesc("test_record_count");
        BatttestdataInf tinf=mapper.selectOne(wrapper);
        return tinf;
    }
    //3.将tinf补齐
    public void insertTinf(BatttestdataInf tinf) {
        mapper.insert(tinf);
    }
}