whyclxw
3 小时以前 e196f42e9a977c0b2f8452dce875b110fb76e92f
src/main/java/com/whyc/service/BattRealdataIdService.java
@@ -1,10 +1,7 @@
package com.whyc.service;
import com.whyc.dto.Real.*;
import com.whyc.dto.RealDataStatic.ResRealDataAc;
import com.whyc.dto.RealDataStatic.ResRealDataMon;
import com.whyc.dto.RealDataStatic.SticRealDataAc;
import com.whyc.dto.RealDataStatic.SticRealDataBatt;
import com.whyc.dto.RealDataStatic.*;
import com.whyc.dto.Response;
import com.whyc.factory.ThreadPoolExecutorFactory;
import com.whyc.mapper.CommonMapper;
@@ -280,19 +277,19 @@
        return new Response().setIII(1, dataListSorted!=null,dataListSorted,map,"历史实时查询");
    }
    //实时数据统计曲线--核容设备
    public Response getSticRealHrData(SticRealDataAc stic) throws ParseException, InterruptedException {
        Integer granularity=5;//默认值
    public Response getSticRealHrData(SticRealDataBatt stic) throws ParseException, InterruptedException {
        Integer granularity=2;//默认值
        Map<String,Date> startAndEndTime=DateUtil.getStartAndEndTime(stic.getSticTime());
        //获取两个时间分割多少张表
        List<List<Date>> monthTimeList = DateUtil.getMonthTime(startAndEndTime.get("startTime"),startAndEndTime.get("endTime"));
        List<ResRealDataAc> dataList = new LinkedList<>();
        List<ResRealDataHr> dataList = new LinkedList<>();
        Map<String, Map<String,List<String>>> allTimeMap=new HashMap<>();
        ThreadPoolExecutor pool = ThreadPoolExecutorFactory.getPoolExecutor();
        CountDownLatch latch = new CountDownLatch(monthTimeList.size());
        for (int i = 0; i < monthTimeList.size(); i++) {
            int finalI = i;
            Integer finalGranularity = granularity;
            Map<String,List<String>> propertyInfo=stic.getPropertyInfo();
           List<String> propertyList=stic.getPropertyList();
            pool.execute(() -> {
                int finalII = finalI;
                Date recordDatetime=monthTimeList.get(finalII).get(0);
@@ -302,7 +299,7 @@
                String tableName="db_data_history.tb_batt_realdata_"+table;
                //判断表是否存在
                int tableNum = subTablePageInfoService.judgeTable_realdata(table);
                List<ResRealDataAc> list = new ArrayList();
                List<ResRealDataHr> list = new ArrayList();
                Map<String,List<String>> timeMap=new HashMap<>();
                if (tableNum > 0) {
                    //获取指定时间段内最大最小recordNum确保数据的完整
@@ -313,23 +310,21 @@
                        maxRecordNum=(Integer)recordNums.get(0);
                        minRecordNum=(Integer)recordNums.get(1);
                    }
                    list = subTablePageInfoService.getSticRealHrData(tableName, finalGranularity,recordDatetime,recordDatetime1,maxRecordNum,minRecordNum,propertyInfo);
                    list = subTablePageInfoService.getSticRealHrData(tableName, finalGranularity,recordDatetime,recordDatetime1,maxRecordNum,minRecordNum);
                    //所有属性的异动点
                    List<Integer> allChangeNums=new ArrayList<>();
                    if(propertyList!=null){
                        for (String value:propertyList) {
                    //获取指定时间取出每个参数的异动次数和异动的recordNum
                    for (Map.Entry<String, List<String>> entry : propertyInfo.entrySet()) {
                        String param = entry.getKey();
                        List<String> valueList = entry.getValue();
                        for (String value : valueList) {
                            float upperLimit=550;
                            float lowerLimit=50;
                            float upperLimit=3.5f;
                            float lowerLimit=2.0f;
                            //查询电源字段的异动
                            List changes= subTablePageInfoService.getBattChangesRecordNum(tableName,recordDatetime,recordDatetime1,value,upperLimit,lowerLimit);
                            List<Integer> numList= (List<Integer>) changes.get(0);//record_num的集合
                            List<String> timeList= (List<String>) changes.get(1);//record_datetime的集合
                            if(numList!=null&&numList.size()>0){
                                allChangeNums.addAll(numList);
                            }
                            List<String> timeList= (List<String>) changes.get(1);//record_datetime的集合
                            //存放每个参数的异动时间点
                            timeMap.put(value,timeList);
                        }
@@ -337,7 +332,7 @@
                    //只有存在异动点采取查询异动数据
                    if(allChangeNums.size()>0){
                        //查询大类参数下所有异动recordNum的记录之和
                        List<ResRealDataAc> paramList=subTablePageInfoService.getBattPropertyChangesByRecordNum(tableName,recordDatetime,recordDatetime1,allChangeNums,propertyInfo);
                        List<ResRealDataHr> paramList=subTablePageInfoService.getHrPropertyChangesByRecordNum(tableName,recordDatetime,recordDatetime1,allChangeNums);
                        list.addAll(paramList);
                    }
                }
@@ -348,10 +343,10 @@
            sleep(200);
        }
        latch.await(10, TimeUnit.MINUTES);
        List<ResRealDataAc> uniqueList = dataList.stream()
        List<ResRealDataHr> uniqueList = dataList.stream()
                .distinct()
                .collect(Collectors.toList());
        List dataListSorted = uniqueList.stream().sorted(Comparator.comparing(ResRealDataAc::getRecordNum)).collect(Collectors.toList());
        List dataListSorted = uniqueList.stream().sorted(Comparator.comparing(ResRealDataHr::getRecordNum)).collect(Collectors.toList());
        //所有异动点合并去重
        Map<String, List<String>> mergedMap =ActionUtil.getMergeMap(allTimeMap);
        return new Response().setIII(1,dataList.size()>0,dataListSorted,mergedMap,"实时数据统计曲线--核容设备");