whyclxw
3 天以前 d71e557ab43694ab40dc968f440a63ff97ea794c
src/main/java/com/whyc/service/AlmAnalysisParamService.java
@@ -1,6 +1,7 @@
package com.whyc.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.whyc.dto.AnalysisAlm.AnalysisChangeRes;
import com.whyc.dto.AnalysisAlm.ResAnalysis;
import com.whyc.dto.Real.RealDateDTO;
import com.whyc.dto.Response;
@@ -50,32 +51,29 @@
    }
    //预警分析管理-电源主属性和分析属性
    public Response getHisRealInAlm(Integer battgroupId,Integer powerId, String startTime, Integer almId,Integer intervalTime) throws ParseException, InterruptedException {
    public Response getHisRealInAlm(Integer battgroupId,Integer powerId, String startTime, Integer almId) throws ParseException, InterruptedException {
        Map<String,Object> map=new HashMap<>();
        map.put("batt",null);
        map.put("pwr",null);
        Integer cycleTime=0;
        //获取预警分析周期阈值
        if(intervalTime==null){
            AppParam appParam = appParamService.getAlarmAnalysisCycle();
            cycleTime=appParam.getParamValue().intValue();
        }else{
            cycleTime=intervalTime;
        }
        AppParam appParam = appParamService.getAlarmAnalysisCycle();
        Integer cycleTime=appParam.getParamValue().intValue();
        Date cyscleDate=ActionUtil.getDateAdd(ThreadLocalUtil.parse(startTime,1),cycleTime*(-1));
        Date endTime=ActionUtil.getDateAdd(ThreadLocalUtil.parse(startTime,1),60);
        //获取cyscleDate到现在所有的历史实时数据
        List<List<Date>> monthTimeList = DateUtil.getMonthTime(cyscleDate,new Date());
        //总的属性配置
        List<AlmSummaryParam> summaryList=summaryParamService.getInfo();
        List<List<Date>> monthTimeList = DateUtil.getMonthTime(cyscleDate,endTime);
        //获取告警almId对应的分析配置属性值
        AlmAnalysisParam almAnalysisParam=getAnalysisParam(almId);
        if(almAnalysisParam==null||almAnalysisParam.getMainFieldType()==null){
            return new Response().set(1,false,"无对应分析属性");
        }else{
            //分组查看需要查询电源/电池实时表的哪些数据
            Map<String,  Map<String,Integer>> groupmap=groupPwrAndBatt(almAnalysisParam);
            Map<String,Integer> battMap=groupmap.get("batt");
            Map<String,Integer> pwrMap=groupmap.get("pwr");
            Map<String,  Map<String,Object>> groupmap=groupPwrAndBatt(almAnalysisParam);
            Map<String,Object> battMap=groupmap.get("batt");
            Map<String,Object> pwrMap=groupmap.get("pwr");
            Map<String,Object> mainMap=groupmap.get("main");
            mainMap.put("pwr",pwrMap.size());
            mainMap.put("batt",battMap.size());
            if(battgroupId!=null){
                if(battMap!=null&&battMap.size()>0){
                    List battHislist=getBattRealData(battgroupId,monthTimeList,battMap);
@@ -88,21 +86,24 @@
                    map.put("pwr",pwrHislist);
                }
            }
            return new Response().setIII(1,true, map,summaryList,"预警分析管理-电源主属性和分析属性");
            return new Response().setIIII(1,true, map,mainMap,almAnalysisParam,"预警分析管理-电源主属性和分析属性");
        }
    }
    //分组查看需要查询电源/电池实时表的哪些数据
    private  Map<String,  Map<String,Integer>> groupPwrAndBatt(AlmAnalysisParam almAnalysisParam) {
        Map<String,  Map<String,Integer>> map = new HashMap<>();
        Map<String,Integer> battMap=new HashMap<>();
        Map<String,Integer> pwrMap=new HashMap<>();
    private  Map<String,  Map<String,Object>> groupPwrAndBatt(AlmAnalysisParam almAnalysisParam) {
        Map<String,  Map<String,Object>> map = new HashMap<>();
        Map<String,Object> battMap=new HashMap<>();
        Map<String,Object> pwrMap=new HashMap<>();
        Map<String,Object> mainMap=new HashMap<>();
        if(almAnalysisParam.getMainFieldType()==1||almAnalysisParam.getMainFieldType()==2||almAnalysisParam.getMainFieldType()==3){
            if(almAnalysisParam.getMainField()!=null||almAnalysisParam.getMainField().length()>0){
                pwrMap.put(almAnalysisParam.getMainField(),almAnalysisParam.getMainFieldType());
                mainMap.put("main","pwr");
            }
        }else{
            if(almAnalysisParam.getMainField()!=null||almAnalysisParam.getMainField().length()>0){
                battMap.put(almAnalysisParam.getMainField(),almAnalysisParam.getMainFieldType());
                mainMap.put("main","batt");
            }
        }
        if(almAnalysisParam.getMinorField1Type()==1||almAnalysisParam.getMinorField1Type()==2||almAnalysisParam.getMinorField1Type()==3){
@@ -143,10 +144,11 @@
        }
        map.put("pwr",pwrMap);
        map.put("batt",battMap);
        map.put("main",mainMap);
        return map;
    }
    //连接池获取电源历史实时数据
    public List getPwrRealData(Integer powerId,List<List<Date>> monthTimeList,Map<String,Integer> pwrMap) throws InterruptedException {
    public List getPwrRealData(Integer powerId,List<List<Date>> monthTimeList,Map<String,Object> pwrMap) throws InterruptedException {
        List<ResAnalysis> dataList = new LinkedList<>();
        ThreadPoolExecutor pool = ThreadPoolExecutorFactory.getPoolExecutor();
        CountDownLatch latch = new CountDownLatch(monthTimeList.size());
@@ -176,7 +178,7 @@
    }
    //电池告警点击具体告警信息查看从告警开始时间到现在的历史实时数据
    public List getBattRealData(Integer battgroupId, List<List<Date>> monthTimeList,Map<String,Integer> battMap) throws ParseException, InterruptedException {
    public List getBattRealData(Integer battgroupId, List<List<Date>> monthTimeList,Map<String,Object> battMap) throws ParseException, InterruptedException {
        List<ResAnalysis> dataList = new LinkedList<>();
        ThreadPoolExecutor pool = ThreadPoolExecutorFactory.getPoolExecutor();
        CountDownLatch latch = new CountDownLatch(monthTimeList.size());
@@ -204,5 +206,62 @@
        List dataListSorted = dataList.stream().sorted(Comparator.comparing(ResAnalysis::getRecordTime)).collect(Collectors.toList());
        return dataListSorted;
    }
    //预警分析管理-切换时间间隔和副属性
    public Response getHisRealWithChage(AnalysisChangeRes res) throws ParseException, InterruptedException {
        Map<String,Object> map=new HashMap<>();
        map.put("batt",null);
        map.put("pwr",null);
        Integer cycleTime=0;
        //获取预警分析周期阈值
        AppParam appParam = appParamService.getAlarmAnalysisCycle();
        cycleTime=appParam.getParamValue().intValue();
        Date cyscleDate=ActionUtil.getDateAdd(ThreadLocalUtil.parse(res.getStartTime(),1),cycleTime*(-1));
        Date endTime=ActionUtil.getDateAdd(ThreadLocalUtil.parse(res.getStartTime(),1),60);
        //获取cyscleDate到现在所有的历史实时数据
        List<List<Date>> monthTimeList = DateUtil.getMonthTime(cyscleDate,endTime);
        //获取告警almId对应的分析配置属性值
        AlmAnalysisParam almAnalysisParam=new AlmAnalysisParam();
        //将属性拷贝至almAnalysisParam中
        copyProperties(almAnalysisParam,res);
        //分组查看需要查询电源/电池实时表的哪些数据
        Map<String,  Map<String,Object>> groupmap=groupPwrAndBatt(almAnalysisParam);
        Map<String,Object> battMap=groupmap.get("batt");
        Map<String,Object> pwrMap=groupmap.get("pwr");
        Map<String,Object> mainMap=groupmap.get("main");
        mainMap.put("pwr",pwrMap.size());
        mainMap.put("batt",battMap.size());
        if(res.getBattgroupId()!=null){
            if(battMap!=null&&battMap.size()>0){
                List battHislist=getBattRealData(res.getBattgroupId(),monthTimeList,battMap);
                map.put("batt",battHislist);
            }
        }
        if(res.getPowerId()!=null){
            if(pwrMap!=null&&pwrMap.size()>0){
                List pwrHislist=getPwrRealData(res.getPowerId(),monthTimeList,pwrMap);
                map.put("pwr",pwrHislist);
            }
        }
        return new Response().setIIII(1,true, map,mainMap,almAnalysisParam,"预警分析管理-切换时间间隔和副属性");
    }
    //将属性拷贝至almAnalysisParam中
    private void copyProperties(AlmAnalysisParam almAnalysisParam, AnalysisChangeRes res) {
        almAnalysisParam.setMainField(res.getDataName1());
        almAnalysisParam.setMainFieldType(res.getDataType1());
        almAnalysisParam.setMinorField1(res.getDataName2());
        almAnalysisParam.setMinorField1Type(res.getDataType2());
        almAnalysisParam.setMinorField2(res.getDataName3());
        almAnalysisParam.setMinorField2Type(res.getDataType3());
        almAnalysisParam.setMinorField3(res.getDataName4());
        almAnalysisParam.setMinorField3Type(res.getDataType4());
        almAnalysisParam.setMinorField4(res.getDataName5());
        almAnalysisParam.setMinorField4Type(res.getDataType5());
    }
    //预警分析管理-查询所有的属性对应关系
    public Response getAlmSummaryParam() {
        //总的属性配置
        List<AlmSummaryParam> summaryList=summaryParamService.getInfo();
        return new Response().setII(1,true,summaryList,"预警分析管理-查询所有的属性对应关系");
    }
}