whyclxw
3 天以前 82d3504d93db29e2b04ed1137e541a19e0cba0f1
预警分析管理
4个文件已修改
104 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/RealContoller.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/AlmAnalysisParamService.java 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/PwrdevHistorydataIdService.java 46 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/SubTablePageInfoService.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/RealContoller.java
@@ -39,7 +39,7 @@
    @ApiOperation(value = "系统概览获取前一百比时间间隔数据直流输出统计")
    @GetMapping("getPwrHisDcoutData100")
    public Response getPwrHisDcoutData100(@RequestParam Integer powerId){
    public Response getPwrHisDcoutData100(@RequestParam Integer powerId) throws ParseException, InterruptedException {
        return pwrdevHistorydataIdService.getHalfHourPwrHisDcoutData(powerId);
    }
src/main/java/com/whyc/service/AlmAnalysisParamService.java
@@ -68,9 +68,12 @@
            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);
@@ -83,21 +86,24 @@
                    map.put("pwr",pwrHislist);
                }
            }
            return new Response().setII(1,true, map,"预警分析管理-电源主属性和分析属性");
            return new Response().setIII(1,true, map,mainMap,"预警分析管理-电源主属性和分析属性");
        }
    }
    //分组查看需要查询电源/电池实时表的哪些数据
    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){
@@ -138,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());
@@ -171,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());
@@ -218,9 +225,12 @@
        //将属性拷贝至almAnalysisParam中
        copyProperties(almAnalysisParam,res);
        //分组查看需要查询电源/电池实时表的哪些数据
        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("pwr");
        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);
@@ -233,7 +243,7 @@
                map.put("pwr",pwrHislist);
            }
        }
        return new Response().setII(1,true, map,"预警分析管理-切换时间间隔和副属性");
        return new Response().setIII(1,true, map,mainMap,"预警分析管理-切换时间间隔和副属性");
    }
    //将属性拷贝至almAnalysisParam中
    private void copyProperties(AlmAnalysisParam almAnalysisParam, AnalysisChangeRes res) {
src/main/java/com/whyc/service/PwrdevHistorydataIdService.java
@@ -106,11 +106,9 @@
        latch.await(10, TimeUnit.MINUTES);
        List dataListSorted = dataList.stream().sorted(Comparator.comparing(PwrHisRealAcInDto::getRecordDatetime)).collect(Collectors.toList());
        return new Response().setII(1,dataList.size()>0,dataListSorted,"获取半小时内交流输入统计");
    }
    //系统概览获取前N笔直流输出统计
    public Response getHalfHourPwrHisDcoutData(Integer powerId) {
        String dateTime = ActionUtil.sdfwithOutday.format(new Date());
    public Response getHalfHourPwrHisDcoutData(Integer powerId) throws InterruptedException, ParseException {
        //获取前笔数*时间间隔
        PowerheartParam heartParam=heartService.getHeartParamByPowerId(powerId);
        Integer interverCount=100*5;//默认值
@@ -119,26 +117,48 @@
            interverCount=heartParam.getAcinInterverCfg()*heartParam.getAcinCountCfg();
            granularity=heartParam.getAcinInterverCfg();
        }
        //获取前半个小时数据
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime now = LocalDateTime.now();
        // 计算半小时前的时间点
        String dateTime = now.format(formatter);
        Date endTime=ActionUtil.sdf.parse(dateTime);
        // 计算笔数*时间间隔的时间点
        LocalDateTime halfHourAgo = now.minusMinutes(interverCount);
        // 格式化输出
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String halfHourAgoTime=halfHourAgo.format(formatter);
        String tableName ="db_data_history.tb_pwrdev_historydata_"+powerId+"_"+dateTime;
        String existTableName = commonMapper.existTable("db_data_history", "tb_pwrdev_historydata_"+powerId+"_"+dateTime);
        if(existTableName == null){
            return new Response().set(1,false,"当前电源不存在前面小时数据");
        Date startTime=ActionUtil.sdf.parse(halfHourAgoTime);
        //获取两个时间分割多少张表
        List<List<Date>> monthTimeList = DateUtil.getMonthTime(startTime,endTime);
        List<PwrHisRealDcoutInDto> dataList = new LinkedList<>();
        ThreadPoolExecutor pool = ThreadPoolExecutorFactory.getPoolExecutor();
        CountDownLatch latch = new CountDownLatch(monthTimeList.size());
        for (int i = 0; i < monthTimeList.size(); i++) {
            int finalI = i;
            Integer finalGranularity = granularity;
            pool.execute(() -> {
                int finalII = finalI;
                Date recordDatetime=monthTimeList.get(finalII).get(0);
                Date recordDatetime1=monthTimeList.get(finalII).get(1);
                String table = powerId + "_" + ThreadLocalUtil.format(recordDatetime,2);
                String tableName="db_data_history.tb_pwrdev_historydata_"+table;
                //判断表是否存在
                int tableNum = subTablePageInfoService.judgeTable_pwrhis(table);
                List<PwrHisRealDcoutInDto> list = new ArrayList();
                if (tableNum > 0) {
                    list=subTablePageInfoService.getHalfHourPwrHisDcoutData(tableName, finalGranularity,recordDatetime,recordDatetime1);
                }
                dataList.addAll(list);
                latch.countDown();
            });
            sleep(200);
        }
        List<PwrHisRealDcoutInDto> datalist=subTablePageInfoService.getHalfHourPwrHisDcoutData(tableName,granularity,halfHourAgoTime);
        latch.await(10, TimeUnit.MINUTES);
        List dataListSorted = dataList.stream().sorted(Comparator.comparing(PwrHisRealDcoutInDto::getRecordDatetime)).collect(Collectors.toList());
        Long modelCfg=0l;
        PowerInf pinf=powerInfService.getPowerInfById(powerId);
        if(pinf!=null){
            modelCfg=pinf.getModelCfg();
        }
        return new Response().setIII(1,datalist.size()>0,datalist,modelCfg,"获取半小时内直流输出统计");
        return new Response().setIII(1,dataList.size()>0,dataListSorted,modelCfg,"获取半小时内直流输出统计");
    }
    //1.2.7优良电源统计上一季度的电源某一属性和参数阈值超过的次数
    public Integer getPwrQuarter7(Integer powerId,Integer powerType) throws NoSuchFieldException, IllegalAccessException {
src/main/java/com/whyc/service/SubTablePageInfoService.java
@@ -627,13 +627,11 @@
        return list;
    }
    public List<PwrHisRealDcoutInDto> getHalfHourPwrHisDcoutData(String tableName,Integer granularity,String halfHourAgoTime) {
    public List<PwrHisRealDcoutInDto> getHalfHourPwrHisDcoutData(String tableName,Integer granularity,Date recordDatetime,Date recordDatetime1) {
        String sql="select  distinct * " +
                "from (select a.*, (@i:= @i+1) as number " +
                "     from (select * from "+tableName+" "+
                "                    where record_datetime>='"+halfHourAgoTime+"') a, " +
                "                   (select @i:=0) b) c "+
                " where c.number%"+granularity+"=0 or c.number=1 ";
                " from "+tableName+" where record_datetime>='"+ActionUtil.sdf.format(recordDatetime)+"'" +
                "                    and record_datetime<='"+ActionUtil.sdf.format(recordDatetime1)+
                "' and record_num%"+granularity+"=0 or record_num=1 or record_num=100 ";
        sql+=" order by record_datetime asc";
        List<PwrHisRealDcoutInDto> list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
@@ -799,7 +797,7 @@
        return list;
    }
    //电池数据历史实时处理(预警分析)
    public List<ResAnalysis> getBattHisRealInAlm(BattRealdataId realdata, Map<String,Integer> battMap) {
    public List<ResAnalysis> getBattHisRealInAlm(BattRealdataId realdata, Map<String,Object> battMap) {
        String result = String.join(",", battMap.keySet());
        String sql=" select record_time,"+result+" " +
                "               from db_data_history.tb_batt_realdata_"+realdata.getTableName()+" " +
@@ -815,7 +813,7 @@
                    ph.setRecordTime(rs.getTimestamp("record_time"));
                    int i=1;
                    for (String key : battMap.keySet()) {
                        Integer dataType = battMap.get(key);
                        Integer dataType = (Integer) battMap.get(key);
                        try {
                            String propertyType = "dataType"+(i);
                            Field fieldType = ResAnalysis.class.getDeclaredField(propertyType);
@@ -848,7 +846,7 @@
    }
    //电源数据历史实时处理(预警分析)
    public List<ResAnalysis> getPwrHisRealInAlm(PwrdevHistorydataId pwrHis, Map<String,Integer> pwrMap) {
    public List<ResAnalysis> getPwrHisRealInAlm(PwrdevHistorydataId pwrHis, Map<String,Object> pwrMap) {
        String result = String.join(",", pwrMap.keySet());
        String sql=" select record_datetime,"+result+"  " +
                "               from db_data_history.tb_pwrdev_historydata_"+pwrHis.getTableName()+" " +
@@ -864,7 +862,7 @@
                    ph.setRecordTime(rs.getTimestamp("record_datetime"));
                    int i=1;
                    for (String key : pwrMap.keySet()) {
                        Integer dataType = pwrMap.get(key);
                        Integer dataType = (Integer) pwrMap.get(key);
                        try {
                            String propertyType = "dataType"+(i);
                            Field fieldType = ResAnalysis.class.getDeclaredField(propertyType);