Sfoglia il codice sorgente

1.优化查询速度

wangt 11 mesi fa
parent
commit
a1262ef30e

+ 10 - 10
TwoParameterWeibullProbabilityPlotOutput.txt

@@ -1,25 +1,25 @@
 Two Parameter Weibull Probability Plot
 
-Monday, 22 January 2024, 9.36
+Wednesday, 22 May 2024, 15.41
 
 Unweighted constrained simplex regression
 
-Gradient:  1.0123        s.e. 0.1434
-Intercept: -0.1064       s.e. 1.2217
+Gradient:  1.0089        s.e. 0.0024
+Intercept: -0.0709       s.e. 0.0175
 
-Correlation Coefficient, r: 0.9547
-Critical Value for r:       0.3365
+Correlation Coefficient, r: 0.9965
+Critical Value for r:       0.0119
 Significance level used:    5.0%
-Sum of squares:             2.3631
+Sum of squares:             613.3209
 
 Best Estimates of the Parameters
-sigma:  8.9982      'pseudo-linear' s.e. 0.2148
-gamma:  6.619       'pseudo-linear' s.e. 0.9988
+sigma:  7.4932      'pseudo-linear' s.e. 0.0079
+gamma:  2.357       'pseudo-linear' s.e. 0.0065
 
 The 'pseudo-linear' s.e.s are a lower limit to the s.e. and may significantly underestimate the s.e.
 See documentation, http://www.ee.ucl.ac.uk/~mflanaga/java/ProbabilityPlot.html, for details
 
 'Pseudo-linear' Parameter-Parameter Correlation Coefficients
         sigma       gamma       
-sigma   1.0         -0.1817     
-gamma   -0.1817     1.0         
+sigma   1.0         0.3525      
+gamma   0.3525      1.0         

+ 10 - 7
neim-biz/src/main/java/com/jiayue/biz/mapper/ProphaseAnemometryDataMapper.java

@@ -1,6 +1,5 @@
 package com.jiayue.biz.mapper;
 
-import cn.hutool.db.Entity;
 import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.jiayue.biz.domain.ProphaseAnemometryData;
@@ -10,7 +9,6 @@ import org.apache.ibatis.annotations.Select;
 
 import java.sql.Timestamp;
 import java.util.List;
-import java.util.Map;
 
 /**
  * ProphaseAnemometryDataMapper
@@ -23,6 +21,7 @@ public interface ProphaseAnemometryDataMapper extends BaseMapper<ProphaseAnemome
     //单条插入
     @Insert("INSERT INTO anemometry_${equipmentId}_${layerHeight} USING prophase_anemometry_data TAGS(#{equipmentId}, #{layerHeight}) VALUES(#{ts}, #{wsInst}, #{wsMax}, #{wsMin}, #{wsAve}, #{wsGust}, #{wsSta}, #{wdInst}, #{wdMax}, #{wdMin}, #{wdAve}, #{wdSta})")
     int insertOneWithNew(ProphaseAnemometryData one);
+
     //批量插入
     @Insert("<script>" +
             "insert into anemometry_${equipmentId}_${layerHeight} USING prophase_anemometry_data TAGS(#{equipmentId}, #{layerHeight}) values " +
@@ -30,7 +29,7 @@ public interface ProphaseAnemometryDataMapper extends BaseMapper<ProphaseAnemome
             "(#{p.ts},#{p.wsInst},#{p.wsMax},#{p.wsMin},#{p.wsAve},#{p.wsGust},#{p.wsSta},#{p.wdInst},#{p.wdMax},#{p.wdMin},#{p.wdAve},#{p.wdSta}) " +
             "</foreach> " +
             "</script>")
-    int insertSplice(@Param("prophaseAnemometryData") List<ProphaseAnemometryData> prophaseAnemometryData,@Param("equipmentId") String equipmentId,@Param("layerHeight") String layerHeight);
+    int insertSplice(@Param("prophaseAnemometryData") List<ProphaseAnemometryData> prophaseAnemometryData, @Param("equipmentId") String equipmentId, @Param("layerHeight") String layerHeight);
 
     //所有层高风速风向平均值
     @Select("SELECT * FROM prophase_anemometry_data t1 where  t1.equipment_id = #{equipmentId} and  t1.ts >= #{startTime} and t1.ts <= #{endTime}")
@@ -51,19 +50,23 @@ public interface ProphaseAnemometryDataMapper extends BaseMapper<ProphaseAnemome
 
     //根据层高和设备编号查询风速
     @Select("SELECT t1.ts,t1.ws_ave FROM prophase_anemometry_data t1 where t1.layer_height = #{height} and t1.equipment_id = #{equipmentId} and  t1.ts >= #{startTime} and t1.ts <= #{endTime}")
-    List<ProphaseAnemometryData> selectWsAveForHeight(@Param("equipmentId") String equipmentId, @Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime,@Param("height") String height);
+    List<ProphaseAnemometryData> selectWsAveForHeight(@Param("equipmentId") String equipmentId, @Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime, @Param("height") String height);
 
     //根据层高和设备编号查询风向
     @Select("SELECT t1.ts,t1.wd_ave FROM prophase_anemometry_data t1 where t1.layer_height = #{height} and t1.equipment_id = #{equipmentId} and  t1.ts >= #{startTime} and t1.ts <= #{endTime}")
-    List<ProphaseAnemometryData> selectWdAveForHeight(@Param("equipmentId") String equipmentId, @Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime,@Param("height") String height);
+    List<ProphaseAnemometryData> selectWdAveForHeight(@Param("equipmentId") String equipmentId, @Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime, @Param("height") String height);
 
     //根据层高和设备编号查询风向、风速、标差
     @Select("SELECT t1.ts,t1.ws_ave,t1.ws_sta,t1.wd_ave FROM prophase_anemometry_data t1 where t1.layer_height = #{height} and t1.equipment_id = #{equipmentId} and  t1.ts >= #{startTime} and t1.ts <= #{endTime}")
-    List<ProphaseAnemometryData> selectWdAveAndWdAveAndWsStaForHeight(@Param("equipmentId") String equipmentId, @Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime,@Param("height") String height);
-
+    List<ProphaseAnemometryData> selectWdAveAndWdAveAndWsStaForHeight(@Param("equipmentId") String equipmentId, @Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime, @Param("height") String height);
 
     //查询设备编号查询所有层高风向 风速 风速标差
     @Select("SELECT t1.ts,t1.ws_ave,t1.ws_sta,t1.wd_ave,t1.layer_height FROM prophase_anemometry_data t1 where  t1.equipment_id = #{equipmentId} and  t1.ts >= #{startTime} and t1.ts <= #{endTime}")
     List<ProphaseAnemometryData> selectWdAveAndWdAveAndWsSta(@Param("equipmentId") String equipmentId, @Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime);
 
+
+    //根据层高和设备编号查询风向、风速、标差
+    @Select("SELECT t1.ts,t1.ws_ave,t1.wd_ave FROM prophase_anemometry_data t1 where t1.layer_height = #{height} and t1.equipment_id = #{equipmentId} and  t1.ts >= #{startTime} and t1.ts <= #{endTime}")
+    List<ProphaseAnemometryData> selectWdAveAndWsAveAndForHeight(@Param("equipmentId") String equipmentId, @Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime, @Param("height") String height);
+
 }

+ 2 - 0
neim-biz/src/main/java/com/jiayue/biz/service/ProphaseAnemometryDataService.java

@@ -40,6 +40,8 @@ public interface ProphaseAnemometryDataService extends IService<ProphaseAnemomet
     //根据层高和设备编号查询风向、风速、标差
     List<ProphaseAnemometryData> selectWdAveAndWdAveAndWsStaForHeight(String equipmentId, Timestamp startTime, Timestamp endTime, String height);
 
+    List<ProphaseAnemometryData> selectWdAveAndWsAveAndForHeight(String equipmentId, Timestamp startTime, Timestamp endTime, String height);
+
     //查询设备编号查询所有层高风向 风速 风速标差
     List<ProphaseAnemometryData> selectWdAveAndWdAveAndWsSta(String equipmentId, Timestamp startTime, Timestamp endTime);
 

+ 66 - 50
neim-biz/src/main/java/com/jiayue/biz/service/impl/PdfServiceImpl.java

@@ -76,6 +76,7 @@ public class PdfServiceImpl extends ServiceImpl<WindTowerDataParentTableMapper,
         //计算完整性
         List<Entity> entities = prophaseWeatherDataService.selectCount(equipmentId);
 
+        log.info("设备:{} 生成报告,数据查询完成时间:{}", equipmentId, cn.hutool.core.date.DateUtil.now());
         for (Entity entity : entities) {
             //过滤非时间区间的数据累加;只要时间范围内的
             if (((Timestamp) entity.get("_wstart")).compareTo(startDay) > -1 && ((Timestamp) entity.get("_wstart")).compareTo(endDay) <= 0) {
@@ -85,57 +86,83 @@ public class PdfServiceImpl extends ServiceImpl<WindTowerDataParentTableMapper,
         }
         //按照设备编号分组
         Map<String, List<WindTowerCalculationData>> weatherCollectMonthMap = windTowerCalculationDatas.stream().collect(Collectors.groupingBy(x -> x.getEbId()));
+        //如果查询月份等于当前时间月份就拿数据库最后一天数据的时间作为结束时间
+        if (endDay.getMonth() == new Date().getMonth()) {
+            List<Entity> lastData = prophaseWeatherDataService.getLastData(windTowerInfos.get(0).getEquipmentNo());
+            Timestamp timestamp = new Timestamp(new Date().getTime());
+            if (lastData != null && lastData.size() > 0) {
+                timestamp = (Timestamp) lastData.get(0).get("last (ts)");
+            }
+            endDay = new Date(timestamp.getTime());
+        }
         //测风塔信息概要
         Map<String, Object> windTowerInfo = getWindTowerInfo(weatherCollectMonthMap, equipmentAttributeMap, windTowerInfos, height, realityCount, startDay, endDay);
         map.put("windTowerInfo", windTowerInfo);
+        log.info("设备:{} 生成报告,测风塔信息概要 完成时间:{}", equipmentId, cn.hutool.core.date.DateUtil.now());
         //测风塔统计概要概要
         Map<String, Object> statisticsData = statisticsWindTowerStatusData(weatherCollectMonthMap, equipmentAttributeMap, windTowerInfos, realityCount, startDay, endDay);
         map.put("statisticsData", statisticsData);
+        log.info("设备:{} 生成报告,测风塔统计概要概要 完成时间:{}", equipmentId, cn.hutool.core.date.DateUtil.now());
         //风速和风功率密度时间曲线图 (时间序列)
         Map<String, Object> wsAndWpd = getWsAndWpd(weatherCollectMonthMap, equipmentAttributeMap, height, startDay, endDay);
         map.put("wsAndWpd", wsAndWpd);
+        log.info("设备:{} 生成报告,风速和风功率密度时间曲线图 (时间序列) 完成时间:{}", equipmentId, cn.hutool.core.date.DateUtil.now());
         //风速和风速标准差时间曲线图
         Map<String, Object> wsAndWsStaData = wsAndWsSta(weatherCollectMonthMap, equipmentAttributeMap, height, startDay, endDay);
         map.put("wsAndWsStaData", wsAndWsStaData);
+        log.info("设备:{} 生成报告,风速和风速标准差时间曲线图 完成时间:{}", equipmentId, cn.hutool.core.date.DateUtil.now());
         //风速和风速密度日变化
         Map<String, Object> windPowerDensityAndAverageWindSpeed = getWindPowerDensityAndAverageWindSpeed(weatherCollectMonthMap, equipmentAttributeMap, windTowerInfos, height);
         map.put("windPowerDensityAndAverageWindSpeed", windPowerDensityAndAverageWindSpeed);
+        log.info("设备:{} 生成报告,速和风速密度日变化 完成时间:{}", equipmentId, cn.hutool.core.date.DateUtil.now());
         //风速和风速密度各月日变化
         List<Map<String, Object>> MonthWsAndWpd = getMonthWsAndWpd(weatherCollectMonthMap, equipmentAttributeMap, height, startDay, endDay);
         map.put("MonthWsAndWpd", MonthWsAndWpd);
+        log.info("设备:{} 生成报告,风速和风速密度各月日变化 完成时间:{}", equipmentId, cn.hutool.core.date.DateUtil.now());
         //风速和风速密度年变化曲线
         Map<String, Object> yearWsAndWpd = getYearWsAndWpd(weatherCollectMonthMap, equipmentAttributeMap, height, startDay, endDay);
         map.put("yearWsAndWpd", yearWsAndWpd);
+        log.info("设备:{} 生成报告,风速和风速密度年变化曲线 完成时间:{}", equipmentId, cn.hutool.core.date.DateUtil.now());
         //风速和风速密度各月日变化表格
         Map<String, Object> monthWpdTable = getMonthWpdTable(weatherCollectMonthMap, equipmentAttributeMap, windTowerInfos, startDay, endDay);
         map.put("monthWpdTable", monthWpdTable);
+        log.info("设备:{} 生成报告,风速和风速密度各月日变化表格 完成时间:{}", equipmentId, cn.hutool.core.date.DateUtil.now());
         //pdf威布尔
         Map<String, Object> weibull = pdfWeibull(equipmentAttributeMap, equipmentId, weatherCollectMonthMap, height);
         map.put("weibull", weibull);
+        log.info("设备:{} 生成报告,pdf威布尔 完成时间:{}", equipmentId, cn.hutool.core.date.DateUtil.now());
         //一年玫瑰图
         Map<String, Object> roseChart = roseCharts(windDirectionStatisticsDataList, equipmentAttributeMap, height);
         map.put("roseChart", roseChart);
+        log.info("设备:{} 生成报告,一年玫瑰图 完成时间:{}", equipmentId, cn.hutool.core.date.DateUtil.now());
         //各月玫瑰图
         Map<String, Object> monthRoseCharts = getMonthRoseCharts(windDirectionStatisticsDataList, equipmentAttributeMap, height);
         map.put("monthRoseCharts", monthRoseCharts);
+        log.info("设备:{} 生成报告,各月玫瑰图 完成时间:{}", equipmentId, cn.hutool.core.date.DateUtil.now());
         //空气密度
         Map<String, Object> airDensity = getAirDensity(weatherCollectMonthMap, equipmentAttributeMap, startDay, endDay);
         map.put("airDensity", airDensity);
+        log.info("设备:{} 生成报告,空气密度 完成时间:{}", equipmentId, cn.hutool.core.date.DateUtil.now());
         //获取风切变指数(风向玫瑰图)
         List<Map<String, Object>> windShearRose = getWindShearRose(windDirectionStatisticsDataList, equipmentAttributeMap, height);
         map.put("windShearRose", windShearRose);
+        log.info("设备:{} 生成报告,获取风切变指数(风向玫瑰图) 完成时间:{}", equipmentId, cn.hutool.core.date.DateUtil.now());
         //风切变日/年变化
         Map<String, Object> windShear = getWindShear(weatherCollectMonthMap, equipmentAttributeMap, height);
         map.put("windShear", windShear);
+        log.info("设备:{} 生成报告,风切变日/年变化 完成时间:{}", equipmentId, cn.hutool.core.date.DateUtil.now());
         //湍流曲线
         List<List<BigDecimal>> turIntensityCharts = getTurIntensityCharts(weatherCollectMonthMap, equipmentAttributeMap, height);
         map.put("turIntensityCharts", turIntensityCharts);
+        log.info("设备:{} 生成报告,湍流曲线 完成时间:{}", equipmentId, cn.hutool.core.date.DateUtil.now());
         //湍流日/年变化
         Map<String, Object> turIntensity = getTurIntensity(weatherCollectMonthMap, equipmentAttributeMap, height);
         map.put("turIntensity", turIntensity);
+        log.info("设备:{} 生成报告,湍流日/年变化 完成时间:{}", equipmentId, cn.hutool.core.date.DateUtil.now());
         //获取湍流(风向玫瑰图)
         Map<String, Object> turIntensityRose = getTurIntensityRose(windDirectionStatisticsDataList, equipmentAttributeMap, windTowerInfos.get(0), height);
         map.put("turIntensityRose", turIntensityRose);
+        log.info("设备:{} 生成报告,获取湍流(风向玫瑰图) 完成时间:{}", equipmentId, cn.hutool.core.date.DateUtil.now());
         return map;
     }
 
@@ -156,15 +183,7 @@ public class PdfServiceImpl extends ServiceImpl<WindTowerDataParentTableMapper,
             /*数据记录信息*/
             Map<String, Object> dataMap = new HashMap<>();
             SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-            //如果查询月份等于当前时间月份就拿数据库最后一天数据的时间作为结束时间
-            if (endDay.getMonth() == new Date().getMonth()) {
-                List<Entity> lastData = prophaseWeatherDataService.getLastData(windTowerInfos.get(0).getEquipmentNo());
-                Timestamp timestamp = new Timestamp(new Date().getTime());
-                if (lastData != null && lastData.size() > 0) {
-                    timestamp = (Timestamp) lastData.get(0).get("last (ts)");
-                }
-                endDay = new Date(timestamp.getTime());
-            }
+
             Date dayLastTime = DateTimeUtil.getDayLastTime(endDay.getTime());
             long count = (dayLastTime.getTime() + 1000 - startDay.getTime()) / (86400000);
             long totalCount = count * 144;//时间范围内的总条数
@@ -218,15 +237,7 @@ public class PdfServiceImpl extends ServiceImpl<WindTowerDataParentTableMapper,
         Map<String, Object> map = new HashMap<>();
         try {
             List<Map<String, Object>> dataList = new ArrayList<>();
-            //如果查询月份等于当前时间月份就拿数据库最后一天数据的时间作为结束时间
-            if (endDay.getMonth() == new Date().getMonth()) {
-                List<Entity> lastData = prophaseWeatherDataService.getLastData(windTowerInfos.get(0).getEquipmentNo());
-                Timestamp timestamp = new Timestamp(new Date().getTime());
-                if (lastData != null && lastData.size() > 0) {
-                    timestamp = (Timestamp) lastData.get(0).get("last (ts)");
-                }
-                endDay = new Date(timestamp.getTime());
-            }
+
             Date dayLastTime = DateTimeUtil.getDayLastTime(endDay.getTime());
             long count = (dayLastTime.getTime() + 1000 - startDay.getTime()) / (86400000);
             long totalCount = count * 144;//时间范围内的总条数
@@ -236,7 +247,6 @@ public class PdfServiceImpl extends ServiceImpl<WindTowerDataParentTableMapper,
                 heights = "10,30,50,60,70,80,90,100,110,120,140,150";
             }
 
-
             String[] heightStrs = heights.split(",");
             for (String height : heightStrs) {
 
@@ -333,12 +343,12 @@ public class PdfServiceImpl extends ServiceImpl<WindTowerDataParentTableMapper,
             //做平均值
             if (null != paMaxData && paMaxData.size() > 0) {
                 BigDecimal paMaxDataMax = paMaxData.stream().map(WindTowerCalculationData::getValue).max((x1, x2) -> x1.compareTo(x2)).get();
-                BigDecimal paMaxDataMax1 = paMaxData.stream().max(Comparator.comparing(x -> x.getValue())).orElse(null).getValue();
+                // BigDecimal paMaxDataMax1 = paMaxData.stream().max(Comparator.comparing(x -> x.getValue())).orElse(null).getValue();
                 paMap.put("max", paMaxDataMax);
             }
             if (null != paMinData && paMinData.size() > 0) {
                 BigDecimal paMinDataMin = paMinData.stream().map(WindTowerCalculationData::getValue).min((x1, x2) -> x1.compareTo(x2)).get();
-                BigDecimal paMinDataMin1 = paMaxData.stream().min(Comparator.comparing(x -> x.getValue())).orElse(null).getValue();
+                //BigDecimal paMinDataMin1 = paMaxData.stream().min(Comparator.comparing(x -> x.getValue())).orElse(null).getValue();
                 paMap.put("min", paMinDataMin);
             }
             if (null != paAveData && paAveData.size() > 0) {
@@ -481,18 +491,26 @@ public class PdfServiceImpl extends ServiceImpl<WindTowerDataParentTableMapper,
                 return map;
             }
             String wsEbId = wsDayAtt.getId();
-
+            List<WindTowerCalculationData> wsListValue = weatherCollectMonthMap.get(wsEbId);
+            Map<Date, List<WindTowerCalculationData>> windTowerCalculationDataMap = wsListValue.stream().collect(Collectors.groupingBy(x -> x.getTime()));
             // 过滤一周数据
             List<List<Object>> wsDataList = new ArrayList<>();
             List<List<Object>> wpdDataList = new ArrayList<>();
-
+            String wpdFieldName = height + "wpdDay";
+            EquipmentAttribute wpdMonthAtt = equipmentAttributeMap.get(wpdFieldName);
+            if (null == wpdMonthAtt) {
+                log.error("未查询到属性:{} ", wpdFieldName);
+                return map;
+            }
+            String wpdEbId = wpdMonthAtt.getId();
+            List<WindTowerCalculationData> wpdListValue = weatherCollectMonthMap.get(wpdEbId);
+            Map<Date, List<WindTowerCalculationData>> wpdDataMap = wpdListValue.stream().collect(Collectors.groupingBy(x -> x.getTime()));
             for (Long l = startDay.getTime(); l <= endDay.getTime(); l += 86400000L) {
                 Date finalL = DateTimeUtil.getDayStartTime(l);
-                List<WindTowerCalculationData> wsListValue = weatherCollectMonthMap.get(wsEbId);
                 if (null != wsListValue && wsListValue.size() > 0) {
-                    List<WindTowerCalculationData> wsList = wsListValue.stream().filter(w -> w.getTime().equals(finalL)).collect(Collectors.toList());
+                    List<WindTowerCalculationData> wsList = windTowerCalculationDataMap.get(finalL);
                     List<Object> list = new ArrayList<>();
-                    if (!wsList.isEmpty()) {
+                    if (null != wsList && !wsList.isEmpty()) {
                         list.add(sdf.format(wsList.get(0).getTime()));
                         list.add(wsList.get(0).getValue());
                         wsDataList.add(list);
@@ -502,18 +520,12 @@ public class PdfServiceImpl extends ServiceImpl<WindTowerDataParentTableMapper,
                         wsDataList.add(list);
                     }
                 }
-                String wpdFieldName = height + "wpdDay";
-                EquipmentAttribute wpdMonthAtt = equipmentAttributeMap.get(wpdFieldName);
-                if (null == wpdMonthAtt) {
-                    log.error("未查询到属性:{} ", wpdFieldName);
-                    return map;
-                }
-                String wpdEbId = wpdMonthAtt.getId();
-                List<WindTowerCalculationData> wpdListValue = weatherCollectMonthMap.get(wpdEbId);
+
+
                 if (null != wpdListValue && wpdListValue.size() > 0) {
-                    List<WindTowerCalculationData> wpdList = wpdListValue.stream().filter(w -> w.getTime().equals(finalL)).collect(Collectors.toList());
+                    List<WindTowerCalculationData> wpdList = wpdDataMap.get(finalL);
                     List<Object> listWpd = new ArrayList<>();
-                    if (!wpdList.isEmpty()) {
+                    if (null != wpdList && !wpdList.isEmpty()) {
                         listWpd.add(sdf.format(wpdList.get(0).getTime()));
                         listWpd.add(wpdList.get(0).getValue());
                         wpdDataList.add(listWpd);
@@ -555,6 +567,9 @@ public class PdfServiceImpl extends ServiceImpl<WindTowerDataParentTableMapper,
                 return map;
             }
             String wsEbId = wsEquipmentAttribute.getId();
+            List<WindTowerCalculationData> wsListValue = weatherCollectMonthMap.get(wsEbId);
+            Map<Date, List<WindTowerCalculationData>> windTowerCalculationDataMap = wsListValue.stream().collect(Collectors.groupingBy(x -> x.getTime()));
+
             //取出heigth层高的平均风速标差属性
             EquipmentAttribute staEquipmentAttribute = equipmentAttributeMap.get(height + "staDay");
             if (null == staEquipmentAttribute) {
@@ -562,16 +577,17 @@ public class PdfServiceImpl extends ServiceImpl<WindTowerDataParentTableMapper,
                 return map;
             }
             String staEbId = equipmentAttributeMap.get(height + "staDay").getId();
-
+            List<WindTowerCalculationData> wsStaListValue = weatherCollectMonthMap.get(staEbId);
+            Map<Date, List<WindTowerCalculationData>> wsStaListValueMap = wsListValue.stream().collect(Collectors.groupingBy(x -> x.getTime()));
             List<List<Object>> wsDataList = new ArrayList<>();
             List<List<Object>> wsStaDataList = new ArrayList<>();
             for (Long l = startDay.getTime(); l <= endDay.getTime(); l += 86400000L) {
                 Date finalL = DateTimeUtil.getDayStartTime(l);
-                List<WindTowerCalculationData> wsListValue = weatherCollectMonthMap.get(wsEbId);
+
                 if (null != wsListValue && wsListValue.size() > 0) {
-                    List<WindTowerCalculationData> wsList = wsListValue.stream().filter(w -> w.getTime().equals(finalL)).collect(Collectors.toList());
+                    List<WindTowerCalculationData> wsList = windTowerCalculationDataMap.get(finalL);
                     List<Object> list = new ArrayList<>();
-                    if (!wsList.isEmpty()) {
+                    if (null != wsList && !wsList.isEmpty()) {
                         list.add(sdf.format(wsList.get(0).getTime()));
                         list.add(wsList.get(0).getValue());
                         wsDataList.add(list);
@@ -582,11 +598,11 @@ public class PdfServiceImpl extends ServiceImpl<WindTowerDataParentTableMapper,
                     }
                 }
                 //计算风速标准差
-                List<WindTowerCalculationData> wsStaListValue = weatherCollectMonthMap.get(staEbId);
+
                 if (null != wsStaListValue && wsStaListValue.size() > 0) {
-                    List<WindTowerCalculationData> wsStaList = wsStaListValue.stream().filter(w -> w.getTime().equals(finalL)).collect(Collectors.toList());
+                    List<WindTowerCalculationData> wsStaList = wsStaListValueMap.get(finalL);
                     List<Object> listSta = new ArrayList<>();
-                    if (!wsStaList.isEmpty()) {
+                    if (null != wsStaList && !wsStaList.isEmpty()) {
                         listSta.add(sdf.format(wsStaList.get(0).getTime()));
                         listSta.add(wsStaList.get(0).getValue());
                         wsStaDataList.add(listSta);
@@ -752,6 +768,9 @@ public class PdfServiceImpl extends ServiceImpl<WindTowerDataParentTableMapper,
                 }
 
                 List<Long> intervalTimeByMonth = DateTimeUtil.getIntervalTimeByMonth(startDay, endDay);
+                Map<String, List<WindTowerCalculationData>> awsAllListMMMap = awsAllList.stream().collect(Collectors.groupingBy(x -> DateTimeUtil.getFormatDateStrForMonth(x.getTime().getTime())));
+                Map<String, List<WindTowerCalculationData>> wpdAllListMMMap = wpdAllList.stream().collect(Collectors.groupingBy(x -> DateTimeUtil.getFormatDateStrForMonth(x.getTime().getTime())));
+
                 for (int i = 1; i <= 12; i++) {
                     //平均风速集合
                     List<WindTowerCalculationData> awsList = new ArrayList<>();
@@ -761,19 +780,16 @@ public class PdfServiceImpl extends ServiceImpl<WindTowerDataParentTableMapper,
                     for (Long l : intervalTimeByMonth) {
                         //判断月份是否相等
                         if (String.valueOf(i).equals(sdf.format(new Date(l)))) {
-                            Date monthStartTime = DateTimeUtil.beginOfMonth(new Date(l));
-                            Date monthendTime = DateTimeUtil.endOfMonth(new Date(l));
-
-                            awsList = awsAllList.stream().filter(w -> w.getTime().compareTo(monthStartTime) >= 0 && w.getTime().compareTo(monthendTime) < 0).collect(Collectors.toList());
-                            wpdList = wpdAllList.stream().filter(w -> w.getTime().compareTo(monthStartTime) >= 0 && w.getTime().compareTo(monthendTime) < 0).collect(Collectors.toList());
+                            awsList = awsAllListMMMap.get(DateTimeUtil.getFormatDateStrForMonth(l));
+                            wpdList = wpdAllListMMMap.get(DateTimeUtil.getFormatDateStrForMonth(l));
                         }
                     }
-                    if (!awsList.isEmpty()) {
+                    if (null != awsList && !awsList.isEmpty()) {
                         dataMap.put("ws", CalculationUtil.getData24(awsList));
                     } else {
                         dataMap.put("ws", nullList);
                     }
-                    if (!wpdList.isEmpty()) {
+                    if (null != wpdList && !wpdList.isEmpty()) {
                         dataMap.put("wpd", CalculationUtil.getData24(wpdList));
                     } else {
                         dataMap.put("wpd", nullList);

+ 5 - 8
neim-biz/src/main/java/com/jiayue/biz/service/impl/ProphaseAnemometryDataServiceImpl.java

@@ -8,16 +8,9 @@ import com.jiayue.biz.domain.ProphaseAnemometryData;
 import com.jiayue.biz.mapper.ProphaseAnemometryDataMapper;
 import com.jiayue.biz.service.ProphaseAnemometryDataService;
 import lombok.AllArgsConstructor;
-import lombok.SneakyThrows;
-import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.annotations.Select;
 import org.springframework.stereotype.Service;
 
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
 import java.sql.Timestamp;
-import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -89,6 +82,11 @@ public class ProphaseAnemometryDataServiceImpl extends ServiceImpl<ProphaseAnemo
         return this.filterData(baseMapper.selectWdAveAndWdAveAndWsStaForHeight(equipmentId, startTime, endTime, height));
     }
 
+    //根据层高和设备编号查询风向、风速、标差
+    public List<ProphaseAnemometryData> selectWdAveAndWsAveAndForHeight(String equipmentId, Timestamp startTime, Timestamp endTime, String height) {
+        return this.filterData(baseMapper.selectWdAveAndWsAveAndForHeight(equipmentId, startTime, endTime, height));
+    }
+
     //查询设备编号查询所有层高风向 风速 风速标差
     public List<ProphaseAnemometryData> selectWdAveAndWdAveAndWsSta(String equipmentId, Timestamp startTime, Timestamp endTime) {
         return this.filterData(baseMapper.selectWdAveAndWdAveAndWsSta(equipmentId, startTime, endTime));
@@ -102,5 +100,4 @@ public class ProphaseAnemometryDataServiceImpl extends ServiceImpl<ProphaseAnemo
     }
 
 
-
 }

+ 53 - 17
neim-biz/src/main/java/com/jiayue/biz/service/impl/RealTimeDisplayServiceImpl.java

@@ -1,6 +1,7 @@
 package com.jiayue.biz.service.impl;
 
 import cn.hutool.db.Entity;
+import com.google.common.collect.Maps;
 import com.jiayue.biz.domain.ProphaseAnemometryData;
 import com.jiayue.biz.domain.ProphaseWeatherData;
 import com.jiayue.biz.domain.WindTowerInfo;
@@ -522,17 +523,27 @@ public class RealTimeDisplayServiceImpl implements RealTimeDisplayService {
         BigDecimal sumWpd = BigDecimal.ZERO;
         BigDecimal sumWs = BigDecimal.ZERO;
         BigDecimal total = BigDecimal.ZERO;
+        Map<Long, List<ProphaseAnemometryData>> prooAnMap = prophaseAnemometryDataList.stream()
+                .collect(Collectors.groupingBy(x -> x.getTs().getTime()));
+
+        Map<String, List<ProphaseAnemometryData>> proAnemomentryDataDayHHMap = prophaseAnemometryDataList.stream().collect(Collectors.groupingBy(x -> DateTimeUtil.getFormatDateStrForHH(x.getTs().getTime())));
+        Map<String, List<ProphaseWeatherData>> prophaseWeatherDataDayHHMap = prophaseWeatherDataList.stream().collect(Collectors.groupingBy(x -> DateTimeUtil.getFormatDateStrForHH(x.getTs().getTime())));
+
         for (long i = startTime; i < endTime; i = i + 3600000) {
 
             long finalI = i;
-            List<ProphaseWeatherData> prophaseWeatherData = prophaseWeatherDataList.stream().filter(p -> p.getTs().getTime() >= finalI && p.getTs().getTime() < finalI + 3600000 - 1).collect(Collectors.toList());
-            List<ProphaseAnemometryData> prophaseAnemometryData = prophaseAnemometryDataList.stream().filter(p -> p.getTs().getTime() >= finalI && p.getTs().getTime() < finalI + 3600000 - 1).collect(Collectors.toList());
+            List<ProphaseWeatherData> prophaseWeatherData = prophaseWeatherDataDayHHMap.get(DateTimeUtil.getFormatDateStrForHH(finalI));
+
+            List<ProphaseAnemometryData> prophaseAnemometryData = proAnemomentryDataDayHHMap.get(DateTimeUtil.getFormatDateStrForHH(finalI));
+            if (null == prophaseWeatherData || null == prophaseAnemometryData) {
+                continue;
+            }
             BigDecimal tenMinuteWpdSum = BigDecimal.ZERO;
             BigDecimal tenMinuteWsSum = BigDecimal.ZERO;
 
             //计算小时风速和风功率密度的总值
             for (ProphaseWeatherData prophaseWeatherDatum : prophaseWeatherData) {
-                List<ProphaseAnemometryData> anemometryData = prophaseAnemometryData.stream().filter(p -> p.getTs().getTime() == prophaseWeatherDatum.getTs().getTime()).collect(Collectors.toList());
+                List<ProphaseAnemometryData> anemometryData = prooAnMap.get(prophaseWeatherDatum.getTs().getTime());
                 if (anemometryData.size() > 0) {
                     tenMinuteWpdSum = tenMinuteWpdSum.add(CalculationUtil.getWpdCalculate(CalculationUtil.getBigDecimal(prophaseWeatherDatum.getAirDensity()), CalculationUtil.getBigDecimal(anemometryData.get(0).getWsAve())));
                     tenMinuteWsSum = tenMinuteWsSum.add(BigDecimal.valueOf(anemometryData.get(0).getWsAve()));
@@ -550,8 +561,6 @@ public class RealTimeDisplayServiceImpl implements RealTimeDisplayService {
                 sumWs = sumWs.add(oneHourWs);
                 //计算数据个数
                 total = total.add(BigDecimal.ONE);
-
-
             }
             //风功率密度曲线图
             this.getMapForData(i, oneHourWpd, sdf, wpdOneHourMap);
@@ -564,8 +573,9 @@ public class RealTimeDisplayServiceImpl implements RealTimeDisplayService {
 
         }
 
-        ArrayList<ArrayList> windPowerDensity = getListEntry(wpdOneHourMap);
-        ArrayList<ArrayList> averageWindSpeed = getListEntry(wsOneHourMap);
+
+        ArrayList<ArrayList> windPowerDensity = getListEntry((HashMap<String, ArrayList<BigDecimal>>) sortByKey(wpdOneHourMap, false));
+        ArrayList<ArrayList> averageWindSpeed = getListEntry((HashMap<String, ArrayList<BigDecimal>>) sortByKey(wsOneHourMap, false));
         ArrayList<HashMap<String, Object>> wpdList = getMapEntry(wpdOneHourSdfMap);
         ArrayList<HashMap<String, Object>> awsList = getMapEntry(wsOneHourSdfMap);
         BigDecimal aveWpd = BigDecimal.ZERO;
@@ -589,6 +599,26 @@ public class RealTimeDisplayServiceImpl implements RealTimeDisplayService {
 
     }
 
+    /**
+     * 根据map的key排序
+     *
+     * @param map    待排序的map
+     * @param isDesc 是否降序,true:降序,false:升序
+     * @return 排序好的map
+     * @author zero 2019/04/08
+     */
+    public static <K extends Comparable<? super K>, V> Map<K, V> sortByKey(Map<K, V> map, boolean isDesc) {
+        Map<K, V> result = Maps.newLinkedHashMap();
+        if (isDesc) {
+            map.entrySet().stream().sorted(Map.Entry.<K, V>comparingByKey().reversed())
+                    .forEachOrdered(e -> result.put(e.getKey(), e.getValue()));
+        } else {
+            map.entrySet().stream().sorted(Map.Entry.<K, V>comparingByKey())
+                    .forEachOrdered(e -> result.put(e.getKey(), e.getValue()));
+        }
+        return result;
+    }
+
     public void getMapForData(Long time, BigDecimal data, SimpleDateFormat sdf, HashMap<String, ArrayList<BigDecimal>> dataMap) {
         if (dataMap.containsKey(sdf.format(new Date(time)))) {
             //判断是否为0  0为无效数据 防止getListEntry方法除0 问题
@@ -727,6 +757,10 @@ public class RealTimeDisplayServiceImpl implements RealTimeDisplayService {
         List<Map<String, Object>> list = new ArrayList<>();
         //获取低层高风速所有数据
         List<ProphaseAnemometryData> mixWindOrgList = anemometryData.stream().filter(a -> a.getLayerHeight().equals(heightMin)).collect(Collectors.toList());
+
+        Map<Long, List<ProphaseAnemometryData>> prooAnMap = mixWindOrgList.stream()
+                .collect(Collectors.groupingBy(x -> x.getTs().getTime()));
+
         for (WindDirectionEnum value : WindDirectionEnum.values()) {
             Map<String, Object> map = new HashMap<>();
             List<ProphaseAnemometryData> heightAndWindDirectionEnum = CalculationUtil.getForHeightAndWindDirectionEnum(anemometryData, value);
@@ -735,9 +769,10 @@ public class RealTimeDisplayServiceImpl implements RealTimeDisplayService {
             ArrayList<ProphaseAnemometryData> minWindList = new ArrayList<>();
             //遍历获取同一时间点 低层高的数据
             for (ProphaseAnemometryData wind : maxWindList) {
-                ProphaseAnemometryData prophaseAnemometryData = mixWindOrgList.stream().filter(m -> m.getTs().getTime() == wind.getTs().getTime()).collect(Collectors.toList()).get(0);
-                minWindList.add(prophaseAnemometryData);
-
+                List<ProphaseAnemometryData> prophaseAnemometryData = prooAnMap.get(wind.getTs().getTime());
+                if (null != prophaseAnemometryData && prophaseAnemometryData.size() > 0) {
+                    minWindList.add(prophaseAnemometryData.get(0));
+                }
             }
             //获取平均风速
             BigDecimal avgWindSpeed = CalculationUtil.getAvgWind(CalculationUtil.getWsForHeight(maxWindList, height));
@@ -772,7 +807,7 @@ public class RealTimeDisplayServiceImpl implements RealTimeDisplayService {
             Map<String, Object> map = new HashMap<>();
             List<ProphaseAnemometryData> heightAndWindDirectionOrg = CalculationUtil.getForHeightAndWindDirectionEnum(prophaseAnemometryDataList, value);
             //过滤数据中的-99
-            List<ProphaseAnemometryData> heightAndWindDirectionEnum = heightAndWindDirectionOrg.stream().filter(p -> p.getWsAve() != -99 && p.getWsSta() != -99).collect(Collectors.toList());
+            List<ProphaseAnemometryData> heightAndWindDirectionEnum = heightAndWindDirectionOrg.stream().filter(p -> null != p.getWsAve() && p.getWsAve() != -99 && null != p.getWsSta() && p.getWsSta() != -99).collect(Collectors.toList());
             //总风速
             double wsSum = heightAndWindDirectionEnum.stream().mapToDouble(ProphaseAnemometryData::getWsAve).sum();
             //总方差
@@ -806,10 +841,12 @@ public class RealTimeDisplayServiceImpl implements RealTimeDisplayService {
      */
     public List<Map<String, Object>> getWindEnergyDensity(Long startTime, Long endTime, String eqId, String height) {
         //查询风速数据
-        List<ProphaseAnemometryData> prophaseAnemometryDataList = prophaseAnemometryDataService.selectWdAveAndWdAveAndWsStaForHeight(eqId, new Timestamp(startTime), new Timestamp(endTime), height);
+        List<ProphaseAnemometryData> prophaseAnemometryDataList = prophaseAnemometryDataService.selectWdAveAndWsAveAndForHeight(eqId, new Timestamp(startTime), new Timestamp(endTime), height);
+
         //查询空气密度
         List<ProphaseWeatherData> prophaseWeatherDataList = prophaseWeatherDataService.selectAir(eqId, new Timestamp(startTime), new Timestamp(endTime));
-
+        Map<Long, List<ProphaseWeatherData>> propWeatherTsMap = prophaseWeatherDataList.stream()
+                .collect(Collectors.groupingBy(x -> x.getTs().getTime()));
         List<Map<String, Object>> list = new ArrayList<>();
         for (WindDirectionEnum value : WindDirectionEnum.values()) {
             Map<String, Object> map = new HashMap<>();
@@ -817,13 +854,12 @@ public class RealTimeDisplayServiceImpl implements RealTimeDisplayService {
             List<ProphaseAnemometryData> heightAndWindDirectionEnum = CalculationUtil.getForHeightAndWindDirectionEnum(prophaseAnemometryDataList, value);
             BigDecimal wpdSum = BigDecimal.ZERO;
             for (ProphaseAnemometryData p : heightAndWindDirectionEnum) {
-                List<ProphaseWeatherData> prophaseWeatherData = prophaseWeatherDataList.stream().filter(w -> w.getTs().getTime() == p.getTs().getTime()).collect(Collectors.toList());
-                if (prophaseWeatherData.size() > 0) {
+                List<ProphaseWeatherData> prophaseWeatherData = propWeatherTsMap.get(p.getTs().getTime());
+                if (null != prophaseWeatherData && prophaseWeatherData.size() > 0) {
                     wpdSum = wpdSum.add(BigDecimal.valueOf(prophaseWeatherData.get(0).getAirDensity()).multiply(BigDecimal.valueOf(0.5)).multiply(CalculationUtil.power(BigDecimal.valueOf(p.getWsAve()), 3)));
                 }
-
             }
-            if (prophaseWeatherDataList.size() > 0) {
+            if (null != prophaseWeatherDataList && prophaseWeatherDataList.size() > 0) {
                 BigDecimal wpdAve = wpdSum.divide(BigDecimal.valueOf(prophaseWeatherDataList.size()), 2, RoundingMode.HALF_UP);
                 map.put(value.name(), wpdAve);
                 list.add(map);