whyclxw
3 天以前 b1405e0efc09388682d83c4a6be2666b26567882
拦截放行验证码,实时数据统计曲线-交流单元修改
6个文件已修改
151 ■■■■ 已修改文件
src/main/java/com/whyc/dto/RealDataStatic/ResRealDataAc.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/dto/RealDataStatic/SticRealDataAc.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/filter/AccessFilter.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/PwrdevHistorydataIdService.java 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/SubTablePageInfoService.java 69 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/util/DateUtil.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/dto/RealDataStatic/ResRealDataAc.java
@@ -11,6 +11,6 @@
public class ResRealDataAc {
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date recordDatetime;
    private Integer recordNum;
    private Map<String,Map<String, Float>> propertyInfo;
}
src/main/java/com/whyc/dto/RealDataStatic/SticRealDataAc.java
@@ -10,4 +10,5 @@
    private Integer battgroupId;
    private Integer powerId;
    private Map<String,List<String>> propertyInfo;
    private Integer sticTime;//1:月,2:季度,3年
}
src/main/java/com/whyc/filter/AccessFilter.java
@@ -43,6 +43,8 @@
                            || requestURI.contains("loginCheck")
                            //软件升级申请请求
                            || requestURI.contains("software/upgradeApply")
                             //验证码
                            || requestURI.contains("message/getFontDynamicCode")
                            //options请求
                            || request.getMethod().toUpperCase().equals("OPTIONS")
                        ))) {
src/main/java/com/whyc/service/PwrdevHistorydataIdService.java
@@ -31,6 +31,7 @@
import java.text.ParseException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadPoolExecutor;
@@ -307,29 +308,17 @@
    public Response getSticRealAcData(SticRealDataAc stic) throws ParseException, InterruptedException {
        //获取前笔数*时间间隔
        PowerheartParam heartParam=heartService.getHeartParamByPowerId(stic.getPowerId());
        Integer interverCount=100*5;//默认值
        Integer granularity=5;//默认值
        if(heartParam!=null){
            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);
        // 格式化输出
        String halfHourAgoTime=halfHourAgo.format(formatter);
        Date startTime=ActionUtil.sdf.parse(halfHourAgoTime);
        Integer granularity=2;//默认值
        Map<String,Date> startAndEndTime=DateUtil.getStartAndEndTime(stic.getSticTime());
        //获取两个时间分割多少张表
        List<List<Date>> monthTimeList = DateUtil.getMonthTime(startTime,endTime);
        List<List<Date>> monthTimeList = DateUtil.getMonthTime(startAndEndTime.get("startTime"),startAndEndTime.get("endTime"));
        List<ResRealDataAc> 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;
            Map<String,List<String>> propertyInfo=stic.getPropertyInfo();
            pool.execute(() -> {
                int finalII = finalI;
                Date recordDatetime=monthTimeList.get(finalII).get(0);
@@ -348,7 +337,31 @@
                        maxRecordNum=(Integer)recordNums.get(0);
                        minRecordNum=(Integer)recordNums.get(1);
                    }
                    list=subTablePageInfoService.getSticRealAcData(tableName, finalGranularity,recordDatetime,recordDatetime1,maxRecordNum,minRecordNum,stic.getPropertyInfo());
                    //先按照频率查询出正常数据
                    list=subTablePageInfoService.getSticRealAcData(tableName, finalGranularity,recordDatetime,recordDatetime1,maxRecordNum,minRecordNum,propertyInfo);
                    //所有属性的异动点
                    List<Integer> allChangeNums=new ArrayList<>();
                    List< Map<String,List<Integer>>> allChangeNumMap=new ArrayList<>();
                    //获取指定时间取出每个参数的异动次数和异动的recordNum
                    for (Map.Entry<String, List<String>> entry : propertyInfo.entrySet()) {
                        String param = entry.getKey();
                        List<String> valueList = entry.getValue();
                        Map<String,List<Integer>> changeNumMap=new HashMap<>();
                        for (String value : valueList) {
                            float upperLimit=250;
                            float lowerLimit=50;
                            //查询电源字段的异动
                            List<Integer> changeNums= subTablePageInfoService.getChangesRecordNum(tableName,recordDatetime,recordDatetime1,value,upperLimit,lowerLimit);
                            allChangeNums.addAll(changeNums);
                            changeNumMap.put(value,changeNums);
                            allChangeNumMap.add(changeNumMap);
                        }
                    }
                    if(allChangeNums.size()>0){//只有存在异动点采取查询异动数据
                        //查询大类参数下所有异动recordNum的记录之和
                        List<ResRealDataAc> paramList=subTablePageInfoService.getPropertyChangesByRecordNum(tableName,recordDatetime,recordDatetime1,allChangeNums,propertyInfo);
                        list.addAll(paramList);
                    }
                }
                dataList.addAll(list);
                latch.countDown();
@@ -356,7 +369,10 @@
            sleep(200);
        }
        latch.await(10, TimeUnit.MINUTES);
        List dataListSorted = dataList.stream().sorted(Comparator.comparing(ResRealDataAc::getRecordDatetime)).collect(Collectors.toList());
        return new Response().setII(1,dataList.size()>0,dataListSorted,"获取半小时内交流输入统计");
        List<ResRealDataAc> uniqueList = dataList.stream()
                .distinct()
                .collect(Collectors.toList());
        List dataListSorted = uniqueList.stream().sorted(Comparator.comparing(ResRealDataAc::getRecordNum)).collect(Collectors.toList());
        return new Response().setII(1,dataList.size()>0,dataListSorted,"实时数据数据曲线统计-交流单元");
    }
}
src/main/java/com/whyc/service/SubTablePageInfoService.java
@@ -699,13 +699,79 @@
        });
        return list;
    }
    //查询电源字段的异动的记录
    public List<Integer> getChangesRecordNum(String tableName, Date recordDatetime, Date recordDatetime1, String value, float upperLimit, float lowerLimit) {
        String sql=" select  distinct record_datetime,record_num "+
                " from "+tableName+" where record_datetime>='"+ActionUtil.sdf.format(recordDatetime)+"'" +
                "                    and record_datetime<='"+ActionUtil.sdf.format(recordDatetime1)+"'" +
                " and "+value+">"+upperLimit+" or "+value+"<"+lowerLimit+" ";
        sql+="  order by record_num asc";
        List<Integer> list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                List<Integer> list=new ArrayList<>();
                while (rs.next()){
                    list.add(rs.getInt("record_num"));
                }
                return list;
            }
        });
        return list;
    }
    //查询电源字段的异动
    public List<ResRealDataAc> getPropertyChangesByRecordNum(String tableName, Date recordDatetime, Date recordDatetime1, List<Integer> allChangeNums, Map<String, List<String>> propertyInfo) {
        String  propertyStr = propertyInfo.values().stream()
                .flatMap(List::stream)
                .collect(Collectors.joining(","));
        String sql=" select  distinct record_datetime,record_num, "+propertyStr+
                " from "+tableName+" where record_datetime>='"+ActionUtil.sdf.format(recordDatetime)+"'" +
                "                    and record_datetime<='"+ActionUtil.sdf.format(recordDatetime1)+"'";
        if (allChangeNums.size() > 0) {
            //去除重复项
            List<Integer> uniqueList = allChangeNums.stream()
                    .distinct()
                    .collect(Collectors.toList());
            //拼接生成sql
            String changeNumsStr = uniqueList.stream()
                    .map(String::valueOf)
                    .collect(Collectors.joining(","));
            sql += " and record_num in (" + changeNumsStr + ")";
        }
        sql += " order by record_datetime asc";
        List<ResRealDataAc> list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                List<ResRealDataAc> list=new ArrayList<>();
                while (rs.next()){
                    ResRealDataAc data=new ResRealDataAc();
                    data.setRecordNum(rs.getInt("record_num"));
                    data.setRecordDatetime(rs.getTimestamp("record_datetime"));
                    Map<String,Map<String,Float>>dataMap=new HashMap<>();
                    for (Map.Entry<String, List<String>> entry : propertyInfo.entrySet()) {
                        String key = entry.getKey();
                        List<String> valueList = entry.getValue();
                        Map<String,Float> propertyMap=new HashMap<>();
                        for (String value : valueList) {
                            Float propertyValue = rs.getFloat(value);
                            propertyMap.put(value,propertyValue);
                        }
                        dataMap.put(key,propertyMap);
                    }
                    data.setPropertyInfo(dataMap);
                    list.add(data);
                }
                return list;
            }
        });
        return list;
    }
    //实时数据数据曲线统计-交流单元
    public List<ResRealDataAc> getSticRealAcData(String tableName, Integer granularity, Date recordDatetime, Date recordDatetime1
            , Integer maxRecordNum, Integer minRecordNum, Map<String, List<String>> propertyInfo) {
        String  propertyStr = propertyInfo.values().stream()
                .flatMap(List::stream)
                .collect(Collectors.joining(","));
        String sql=" select  distinct record_datetime,"+propertyStr+" "+
        String sql=" select  distinct record_datetime,record_num,"+propertyStr+" "+
                " from "+tableName+" where record_datetime>='"+ActionUtil.sdf.format(recordDatetime)+"'" +
                "                    and record_datetime<='"+ActionUtil.sdf.format(recordDatetime1)+
                "' and (record_num-"+minRecordNum+")%"+granularity+"=0  or record_num="+minRecordNum+" or record_num="+maxRecordNum;
@@ -716,6 +782,7 @@
                List<ResRealDataAc> list=new ArrayList<>();
                while (rs.next()){
                    ResRealDataAc data=new ResRealDataAc();
                    data.setRecordNum(rs.getInt("record_num"));
                    data.setRecordDatetime(rs.getTimestamp("record_datetime"));
                    Map<String,Map<String,Float>>dataMap=new HashMap<>();
                    for (Map.Entry<String, List<String>> entry : propertyInfo.entrySet()) {
src/main/java/com/whyc/util/DateUtil.java
@@ -750,4 +750,27 @@
    public static Date convertToDate(LocalDateTime localDateTime) {
        return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
    }
    //1月/2季度/3年得到开始时间到当前月的结束时间
    public static Map<String,Date> getStartAndEndTime(Integer sticTime) throws ParseException {
        Map<String,Date> map=new HashMap();
        // 获取当前时间
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime startDate=now;//默认
        // 获取本月的最后一天
        LocalDateTime endtDate=now.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59).withNano(0);
        //指定年月获取这个月的开始时间和结束时间
        if(sticTime==1){
            startDate=DateUtil.getStartOfMonth();
        }
        if(sticTime==2){
            startDate=DateUtil.getStartOfQuarter();
        }
        if(sticTime==3){
            startDate=DateUtil.getStartOfYear();
        }
        map.put("startTime",DateUtil.convertToDate(startDate));
        map.put("endTime",DateUtil.convertToDate(endtDate));
        return map;
    }
}