whyclxw
2025-06-10 84403b5ebe123b200f4bfba5848dd8307d99e8d2
src/main/java/com/whyc/service/BatttestdataInfService.java
@@ -3,21 +3,27 @@
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.constant.PowerAlarmEnum;
import com.whyc.constant.StopReasonEnum;
import com.whyc.dto.Real.TestDataDto;
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.*;
import com.whyc.factory.BattCapFactory;
import com.whyc.mapper.BattInfMapper;
import com.whyc.mapper.BatttestdataInfMapper;
import com.whyc.pojo.db_batt_testdata.BatttestdataId;
import com.whyc.pojo.db_batt_testdata.BatttestdataInf;
import com.whyc.pojo.db_param.AppParam;
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.pojo.db_user.Baojigroup;
import com.whyc.util.PageInfoUtils;
import com.whyc.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.*;
@Service
public class BatttestdataInfService {
@@ -28,10 +34,21 @@
    private BattRtstateService rtstateService;
    @Autowired(required = false)
    private BattRtdataService rtdataService;
    @Autowired(required = false)
    private BattInfService battInfService;
    @Autowired(required = false)
    private BatttestdataIdService battTestdataIdService;
    @Autowired(required = false)
    private AppParamService appParamService;
    @Autowired(required = false)
    private BaojigroupService bjService;
@@ -70,7 +87,7 @@
                BattInf binf=battInfService.getBinfByBattgroupId(tinf.getBattgroupId());
                //实时组端电流,剩余容量,标称容量
                if(battRtstate!=null){
                    Float restTime= BattCapFactory.getTheoryTime(battRtstate.getGroupCurr(), restCap, binf.getMoncapstd());
                    Float restTime= BattCapFactory.getTheoryTime(battRtstate.getLoadCurr(), restCap, binf.getMoncapstd());
                    tinf.setRestTime(restTime);
                }
                //保留5位小数
@@ -86,11 +103,29 @@
    public BatttestdataInf getLastStandardTestData(Integer battgroupId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("battgroup_id", battgroupId);
        wrapper.eq("data_available", 1);
        wrapper.eq("test_type", 3);
        wrapper.eq("test_starttype", 3);
        wrapper.last("limit 1");
        wrapper.last("  and test_timelong >= 7200 ORDER BY test_starttime DESC ");
        wrapper.last("limit 1");
        BatttestdataInf tinf = mapper.selectOne(wrapper);
        tinf.setTestStoptypeReason(StopReasonEnum.getValue(tinf.getTestStoptype()));
        return tinf;
    }
    //获取电池组在给定时间段的放电记录(指定时间段的标准核容放电)
    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);
        if(testStartTime!=null){
            wrapper.gt("test_starttime",testStartTime);
        }
        if(testEndTime!=null){
            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;
    }
@@ -100,21 +135,752 @@
      3然后找到判断优秀,劣化,损坏的参数,得到结果。
      4浮充电压图,需要显示单体+实时数据的单体电压,单体内阻
    */
    public Response getMonStatistic(MonStic stic) {
    public Map getMonStatistic(MonStic stic) {
        Map<String,Object> map=new HashMap<>();
        List<SticMonRes> goodlist=new ArrayList();
        List<SticMonRes> badlist=new ArrayList();
        List<SticMonRes> damagelist=new ArrayList();
        map.put("goodlist",goodlist);
        map.put("badlist",badlist);
        map.put("damagelist",damagelist);
        map.put("goodlistNum",0);
        map.put("badlistNum",0);
        map.put("damagelistNum",0);
        //获取核容优劣,损坏参数
        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();
                }
            }
        }
        List<BattInf> binfList=battInfService.getMonStatistic(stic);
        if(binfList!=null&&binfList.size()>0){
            for (BattInf binf:binfList) {
                BatttestdataInf tinf =getLastStandardTestData(binf.getBattgroupId());
                if(tinf!=null){
                    //找这次放电的最后一笔数据
                    List<BatttestdataId> idDataList=battTestdataIdService.getLastDataByBattgroupId(tinf.getBattgroupId(),tinf.getTestRecordCount(),tinf.getRecordNum());
                    for (BatttestdataId data:idDataList) {
                        int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
                        Float realCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Real);
        Float realCap=0f;
        if(binfList==null){
           return map;
        }
        for (BattInf binf:binfList) {
            BatttestdataInf tinf =getLastStandardTestData(binf.getBattgroupId());
            if(tinf==null){
                //将不满足条件的电池组的所有单体放入damage中
                setDamage(damagelist,binf);
                continue;
            }
            //找这次放电的最后一笔数据
            List<BatttestdataId> idDataList=battTestdataIdService.getLastDataByBattgroupId(tinf.getBattgroupId(),tinf.getTestRecordCount(),tinf.getRecordNum());
            if(idDataList==null||idDataList.size()==0){
                //将不满足条件的电池组的所有单体放入damage中
                setDamage(damagelist,binf);
                continue;
            }
            int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
            Float moncapStd=binf.getMoncapstd();
            for (BatttestdataId data:idDataList) {//求单体的 实际容量,最小值就是单体的单体电压
                realCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(),data.getMonVol() , tinf.getGroupVol(), BattCapFactory.CapType_Real);
                SticMonRes res=new SticMonRes();
                res.setBattgroupId(binf.getBattgroupId());
                res.setBattgroupName(binf.getBattgroupName());
                res.setStationName(binf.getStationName());
                res.setDevName(binf.getDevName());
                res.setMonNum(data.getMonNum());
                //获取单体的实时数据
                BattRtdata rtdata=rtdataService.getRtdataByNum(binf.getBattgroupId(),data.getMonNum());
                if(rtdata==null){
                    res.setMonVol(0f);
                    res.setMonRes(0f);
                }else{
                    res.setMonVol(rtdata.getMonVol());
                    res.setMonRes(rtdata.getMonRes());
                }
                if(realCap>=moncapStd*badValue){
                    goodlist.add(res);
                }
                if(realCap<=moncapStd*damageValue){
                    damagelist.add(res);
                }
                if((realCap>moncapStd*damageValue)&&(realCap<moncapStd*badValue)){
                    badlist.add(res);
                }
            }
        }
        map.put("goodlist",goodlist);
        map.put("badlist",badlist);
        map.put("damagelist",damagelist);
        map.put("goodlistNum",goodlist.size());
        map.put("badlistNum",badlist.size());
        map.put("damagelistNum",damagelist.size());
        return map;
    }
    //将不满足条件的电池组的所有单体放入damage中
    private void setDamage(List damagelist, BattInf binf) {
        //获取电池组的实时数据
        List<BattRtdata> rtdataList=rtdataService.getRtdataRealInfo(binf.getBattgroupId());
        if(rtdataList==null||rtdataList.size()==0){
            for (int i=0;i<binf.getMoncount();i++){
                SticMonRes res=new SticMonRes();
                res.setBattgroupId(binf.getBattgroupId());
                res.setBattgroupName(binf.getBattgroupName());
                res.setStationName(binf.getStationName());
                res.setDevName(binf.getDevName());
                res.setMonNum(i+1);
                res.setMonVol(0f);
                res.setMonRes(0f);
                damagelist.add(res);
            }
        }else {
            for (BattRtdata rtdata:rtdataList) {
                SticMonRes res=new SticMonRes();
                res.setBattgroupId(binf.getBattgroupId());
                res.setBattgroupName(binf.getBattgroupName());
                res.setStationName(binf.getStationName());
                res.setDevName(binf.getDevName());
                res.setMonNum(rtdata.getMonNum());
                res.setMonVol(rtdata.getMonVol());
                res.setMonRes(rtdata.getMonRes());
                damagelist.add(res);
            }
        }
    }
    /*蓄电池组对比分析界面(同一品牌同一时间)
     *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<SticCompare15Res> reslist=new ArrayList<>();
        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.setMonvolstd(binf.getMonvolstd());
            res.setStationId(binf.getStationId());
            res.setPowerId(binf.getPowerId());
            res.setDevId(binf.getDevId());
            res.setBattgroupId(binf.getBattgroupId());
            //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_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(Capperformance.getValue(Capperformance.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(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()==null){
                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,"蓄电池组对比分析界面(同一品牌同一时间)");
    }
    //蓄电池组对比分析界面(不同品牌同一时间)(1.2.16)
    public Response getBattCompare16Statistic(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.getBattCompare16Statistic(stic);
        if(binfList==null||binfList.size()==0){
            return new Response().set(1,false,"当前用户未管理满足条件的电池组");
        }
        List<SticCompare16Res> reslist=new ArrayList<>();
        for (BattInf binf:binfList) {
            SticCompare16Res res=new SticCompare16Res();
            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.setMonvolstd(binf.getMonvolstd());
            res.setMoncapstd(binf.getMoncapstd());
            res.setStationId(binf.getStationId());
            res.setPowerId(binf.getPowerId());
            res.setDevId(binf.getDevId());
            res.setBattgroupId(binf.getBattgroupId());
            //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()));
                res.setStopReason("--");
                continue;
            }
            res.setStopReason(StopReasonEnum.getValue(tinf.getTestStoptype()));
            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.setScore(0f);
            res.setPrecentCap(precentCap);
            if(stic.getPerformance()==null){
                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,"蓄电池组对比分析界面(不同品牌同一时间)");
    }
    //蓄电池组对比分析界面(同一品牌不同时间)(1.2.17)
    public Response getBattCompare17Statistic(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.getBattCompare17Statistic(stic);
        if(binfList==null||binfList.size()==0){
            return new Response().set(1,false,"当前用户未管理满足条件的电池组");
        }
        List<SticCompare17Res> reslist=new ArrayList<>();
        for (BattInf binf:binfList) {
            //2.获取电池组在给定时间段的放电记录(指定时间段的标准核容放电)
            BatttestdataInf tinf =getLastStandardTestDataByTime(binf.getBattgroupId(),stic.getTestStartTime(),stic.getTestEndTime());
            if(tinf==null){
                //不存在放电记录则默认为实际预估容量全为0
                setSticCompare17Res(binf,reslist,stic.getPerformance());
                continue;
            }
            //找这次放电的最后一笔数据
            List<BatttestdataId> idDataList=battTestdataIdService.getLastDataByBattgroupId(tinf.getBattgroupId(),tinf.getTestRecordCount(),tinf.getRecordNum());
            if(idDataList==null||idDataList.size()==0){
                //不存在放电记录则默认为实际预估容量全为0
                setSticCompare17Res(binf,reslist,stic.getPerformance());
                continue;
            }
            Float moncapStd=binf.getMoncapstd();
            int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
            for (BatttestdataId data:idDataList) {//求单体的 实际容量,最小值就是单体的单体电压
                SticCompare17Res res=new SticCompare17Res();
                res.setProvice(binf.getProvice());
                res.setCity(binf.getCity());
                res.setCountry(binf.getCountry());
                res.setStationName(binf.getStationName());
                res.setDevName(binf.getDevName());
                res.setBattgroupName(binf.getBattgroupName());
                res.setProduct(binf.getProduct());
                res.setInuseTime(binf.getInuseTime());
                res.setMonvolstd(binf.getMonvolstd());
                res.setMonNum(data.getMonNum());
                res.setStationId(binf.getStationId());
                res.setPowerId(binf.getPowerId());
                res.setDevId(binf.getDevId());
                res.setBattgroupId(binf.getBattgroupId());
                Float monrealCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), data.getMonVol(), tinf.getGroupVol(), BattCapFactory.CapType_Real);
                res.setMonrealCap(monrealCap);
                //保留5位小数
                String monprecentCap = String.format("%.5f",(monrealCap/binf.getMoncapstd()*100));
                res.setMonprecentCap(monprecentCap);
                if(monrealCap>=moncapStd*badValue){
                    res.setMoncapperformance(Capperformance.getValue(Capperformance.BATTSTATE_1.getStateId()));
                }
                if (monrealCap <= moncapStd * damageValue) {//损坏的
                    res.setMoncapperformance(Capperformance.getValue(Capperformance.BATTSTATE_3.getStateId()));
                }
                if((monrealCap>moncapStd*damageValue)&&(monrealCap<moncapStd*badValue)){
                    res.setMoncapperformance(Capperformance.getValue(Capperformance.BATTSTATE_2.getStateId()));
                }
                if(stic.getPerformance()==null){
                    reslist.add(res);
                }else{
                    if(res.getMoncapperformance().equals(Capperformance.getValue(stic.getPerformance()))){
                        reslist.add(res);
                    }
                }
            }
        }
        return new Response().set(1,false,"");
        PageInfo pageInfo=PageInfoUtils.list2PageInfo(reslist, stic.getPageNum(), stic.getPageSize());
        return new Response().setII(1,reslist.size()>0,pageInfo,"蓄电池组对比分析界面(同一品牌同一时间)");
    }
    //不存在放电记录则默认为实际预估容量全为0
    private void setSticCompare17Res( BattInf binf, List<SticCompare17Res> reslist,Integer performance) {
        for (int i=0;i<binf.getMoncount();i++){
            SticCompare17Res res=new SticCompare17Res();
            res.setProvice(binf.getProvice());
            res.setCity(binf.getCity());
            res.setCountry(binf.getCountry());
            res.setStationName(binf.getStationName());
            res.setDevName(binf.getDevName());
            res.setBattgroupName(binf.getBattgroupName());
            res.setProduct(binf.getProduct());
            res.setInuseTime(binf.getInuseTime());
            res.setMonvolstd(binf.getMonvolstd());
            res.setStationId(binf.getStationId());
            res.setPowerId(binf.getPowerId());
            res.setDevId(binf.getDevId());
            res.setBattgroupId(binf.getBattgroupId());
            res.setMonNum(i+1);
            res.setMonrealCap(0f);
            res.setMonprecentCap("0");
            res.setMoncapperformance(Capperformance.getValue(Capperformance.BATTSTATE_4.getStateId()));
            if(performance==null){
                reslist.add(res);
            }else{
                if(res.getMoncapperformance().equals(Capperformance.getValue(performance))){
                    reslist.add(res);
                }
            }
        }
    }
    //历史测试记录
    public Response getBattTinf(Integer battgroupId) {
        Map<String,  Object> map=new HashMap<>();
        List<TestDataDto> List1=new ArrayList<>();
        List<TestDataDto> List2=new ArrayList<>();
        List<TestDataDto> List3=new ArrayList<>();
        List<TestDataDto> List4=new ArrayList<>();
        List<TestDataDto> List5=new ArrayList<>();
        map.put("1",List1);   //核容放电
        map.put("2",List2);   //核容充电
        map.put("3",List3);   //监测放电
        map.put("4",List4);   //监测充电
        map.put("5",List5);   //停电放电
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("battgroup_id",battgroupId);
        wrapper.orderByDesc("test_starttime");
        List<BatttestdataInf> list=mapper.selectList(wrapper);
        for (BatttestdataInf tinf:list) {
            TestDataDto dto=new TestDataDto();
            dto.setTestStarttime(tinf.getTestStarttime());
            dto.setBattgroupId(tinf.getBattgroupId());
            dto.setTestRecordCount(tinf.getTestRecordCount());
            dto.setRecordNum(tinf.getRecordNum());
            dto.setTestCap(tinf.getTestCap());
            dto.setTestTimeLong(tinf.getTestTimelong());
            int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
            Float realCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Real);
            dto.setRealCap(realCap);
            //实时获取电池组信息
            BattRtstate battRtstate = rtstateService.getBattRealInfo(tinf.getBattgroupId());
            //获取电池组信息
            BattInf binf = battInfService.getBinfByBattgroupId(tinf.getBattgroupId());
            dto.setMoncapstd(binf.getMoncapstd());
            dto.setMonCount(binf.getMoncount());
            dto.setMonvolstd(binf.getMonvolstd());
            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);
            if(idDataList!=null&&idDataList.size()>=0){
                BatttestdataId idData=idDataList.get(0);
                dto.setOnlineVol(idData.getOnlineVol());
                dto.setGroupCurr(idData.getTestCurr());
            }else {
                dto.setOnlineVol(0f);
                dto.setGroupCurr(0f);
            }
            if (tinf.getTestType() == 3) {
                // 测试类型为放电
                if (tinf.getTestStarttype() == 3) {
                    List1.add(dto);
                } else if(tinf.getTestStarttype() == 4){
                    List5.add(dto);
                }else {
                    List3.add(dto);
                }
            } else if (tinf.getTestType() == 2) {
                // 测试类型为充电
                if (tinf.getTestStarttype() == 3) {
                    List2.add(dto);
                } else {
                    List4.add(dto);
                }
            }
        }
        return new Response().setII(1,true,map,"历史测试记录");
    }
    //本年度已放电数量统计(1.2.5)
    public Response getDischr5Statistic(DisChargeStic stic) {
        Map<String,  Object> map=new HashMap<>();
        //查询出所有的班组并赋予初始值
        setBanZuDefault(map);
        //获取核容优劣,损坏参数
        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.getDischr5Statistic(stic);
        if(binfList==null||binfList.size()==0){
            return new Response().set(1,false,"当前用户未管理满足条件的电池组");
        }
        List<SticDischarge5Res> reslist=new ArrayList<>();
        for (BattInf binf:binfList) {
            //查询电池组所在的班组
            String  groupName=bjService.getGroupName(binf.getPowerId());
            SticDischarge5Res res=new SticDischarge5Res();
            res.setProvice(binf.getProvice());
            res.setCity(binf.getCity());
            res.setCountry(binf.getCountry());
            res.setStationName(binf.getStationName());
            res.setBattgroupName(binf.getBattgroupName());
            //2.获取电池组在给定时间段的放电记录(指定时间段的标准核容放电)
            BatttestdataInf tinf =getLastStandardTestDataByTime(binf.getBattgroupId(),stic.getTestStartTime(),stic.getTestEndTime());
            if(tinf==null){
                res.setRealCap(0f);
                res.setTestStartTime(ThreadLocalUtil.parse("1972-01-01 00:00:00",1));
                res.setTestTimelong(0);
                res.setTestCap(0f);
                res.setStopReason("");
                res.setCapperformance(Capperformance.getValue(Capperformance.BATTSTATE_4.getStateId()));
                res.setDisChargeType(2);
                if(!groupName.equals("none")){
                    BanZu bz= (BanZu) map.get(groupName);
                    int nochargeNum=bz.getNochargeNum();
                    bz.setNochargeNum(nochargeNum+1);
                    map.put(groupName,bz);
                }
                continue;
            }
            if(!groupName.equals("none")){
                BanZu bz= (BanZu) map.get(groupName);
                int dischargeNum=bz.getDischargeNum();
                bz.setDischargeNum(dischargeNum+1);
                map.put(groupName,bz);
            }
            res.setTestStartTime(tinf.getTestStarttime());
            res.setTestTimelong(tinf.getTestTimelong());
            res.setTestCap(tinf.getTestCap());
            res.setStopReason(StopReasonEnum.getValue(tinf.getTestStoptype()));
            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);
            res.setRealCap(grouprealCap);
            res.setDisChargeType(1);
            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()));
            }
            if(stic.getDisChargeType()==null){
                reslist.add(res);
            }else{
                if(res.getDisChargeType()==stic.getDisChargeType()){
                    reslist.add(res);
                }
            }
        }
        PageInfo pageInfo=PageInfoUtils.list2PageInfo(reslist, stic.getPageNum(), stic.getPageSize());
        return new Response().setIII(1,reslist.size()>0,pageInfo,map,"本年度已放电数量统计");
    }
    //查询出所有的班组并赋予初始值
    private void setBanZuDefault(Map<String, Object> map) {
        List<Baojigroup> banZuList=bjService.getGroupList();
        for (Baojigroup bj:banZuList) {
            BanZu bz=new BanZu();
            bz.setBaojiGroupId(bj.getBaojiGroupId());
            bz.setBaojiGroupName(bj.getBaojiGroupName());
            bz.setDischargeNum(0);
            bz.setNochargeNum(0);
            map.put(bj.getBaojiGroupName(),bz);
        }
    }
    //本年度未放电数量统计(1.2.6)
    public Response getDischr6Statistic(DisChargeStic stic) {
        Map<String,  Object> map=new HashMap<>();
        //查询出所有的班组并赋予初始值
        setBanZuDefault(map);
        //1查询符合条件的电池组
        List<BattInf> binfList=battInfService.getDischr6Statistic(stic);
        if(binfList==null||binfList.size()==0){
            return new Response().set(1,false,"当前用户未管理满足条件的电池组");
        }
        List<SticDischarge6Res> reslist=new ArrayList<>();
        for (BattInf binf:binfList) {
            //查询电池组所在的班组
            String  groupName=bjService.getGroupName(binf.getPowerId());
            SticDischarge6Res res=new SticDischarge6Res();
            res.setProvice(binf.getProvice());
            res.setCity(binf.getCity());
            res.setCountry(binf.getCountry());
            res.setStationName(binf.getStationName());
            res.setBattgroupName(binf.getBattgroupName());
            res.setMoncapstd(binf.getMoncapstd());
            res.setMonvolstd(binf.getMonvolstd());
            res.setMoncount(binf.getMoncount());
            res.setProduct(binf.getProduct());
            //获取电池组未放电记录(指定时间段的标准核容放电)
            getNoDischargeData(binf.getBattgroupId(),stic.getTestStartTime(),stic.getTestEndTime(),stic.getTypeList(),res);
            //2.获取电池组在给定时间段的放电记录(指定时间段的标准核容放电)
            BatttestdataInf tinf =getLastStandardTestDataByTime(binf.getBattgroupId(),stic.getTestStartTime(),stic.getTestEndTime());
            res.setTinf(tinf);
            if(stic.getStopReasonType()==0){
                reslist.add(res);
            }else {
                if(res.getStopReasonType()==stic.getStopReasonType()){
                    reslist.add(res);
                }
            }
            if(tinf==null){
                if(!groupName.equals("none")){
                    BanZu bz= (BanZu) map.get(groupName);
                    int nochargeNum=bz.getNochargeNum();
                    bz.setNochargeNum(nochargeNum+1);
                    map.put(groupName,bz);
                }
                continue;
            }
            if(!groupName.equals("none")){
                BanZu bz= (BanZu) map.get(groupName);
                int dischargeNum=bz.getDischargeNum();
                bz.setDischargeNum(dischargeNum+1);
                map.put(groupName,bz);
            }
        }
        PageInfo pageInfo=PageInfoUtils.list2PageInfo(reslist, stic.getPageNum(), stic.getPageSize());
        return new Response().setIII(1,reslist.size()>0,pageInfo,map,"本年度未放电数量统计");
    }
    //2.获取电池组未放电记录(指定时间段的标准核容放电)
    private void getNoDischargeData(Integer battgroupId, Date testStartTime, Date testEndTime, List<Integer> typeList, SticDischarge6Res res) {
        List<BatttestdataInf> tinfList=mapper.getNoDischargeData(battgroupId,testStartTime,testEndTime,typeList);
        List<String> stopList=new ArrayList<>();
        if(tinfList!=null&&tinfList.size()>0){
            res.setErrorNum(tinfList.size());
            res.setStopReasonType(1);
            for (BatttestdataInf tinf:tinfList) {
                String stopReason=StopReasonEnum.getValue(tinf.getTestStoptype());
                stopList.add(stopReason);
            }
            res.setStopList(stopList);
        }else {
            res.setErrorNum(0);
            res.setStopList(new ArrayList<>());
            res.setStopReasonType(0);
        }
    }
    //获取核容停止原因类型(下拉)
    public Response getStopReasonType() {
        Map<String,Map<Integer,String>> map= StopReasonEnum.getOpInfo();
        return new Response().setII(1,true,map,"获取核容停止原因类型(下拉)");
    }
    //电池组电池性能统计(未放电,优秀,劣化,损坏)统计(1.2.8/9/10)
    public Response getPerformanceStatistic(PerformanceStic 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<SticCompare15Res> reslist=new ArrayList<>();
        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.setMonvolstd(binf.getMonvolstd());
            res.setStationId(binf.getStationId());
            res.setPowerId(binf.getPowerId());
            res.setDevId(binf.getDevId());
            res.setBattgroupId(binf.getBattgroupId());
            //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_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(Capperformance.getValue(Capperformance.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(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()==null){
                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,"蓄电池组对比分析界面(同一品牌同一时间)");*/
        return null;
    }
}