Quellcode durchsuchen

修改首页风切变计算方式 修改入库逻辑 修改工具类中风功率计算方式

hxf vor 2 Jahren
Ursprung
Commit
a03bb287c3

+ 85 - 0
neim-biz/src/main/java/com/jiayue/biz/job/FileAnalysisJob.java

@@ -75,6 +75,91 @@ public class FileAnalysisJob {
         log.debug("声雷达文件解析定时任务执行完成");
 
     }
+//    @Scheduled(fixedDelay = 60000 * 6000)
+    public void test(){
+        List<WindTowerInfo> list1 = windTowerInfoService.lambdaQuery().list();
+        list1 =  list1.stream().filter(w -> !w.getEquipmentNo().equals("006171") && !w.getEquipmentNo().equals("5302")).collect(Collectors.toList());
+        for (WindTowerInfo windTowerInfo : list1) {
+            log.error("开始入库{}",windTowerInfo.getName());
+            Date date = new Date(1606752000000l);
+            String equipmentId = windTowerInfo.getEquipmentNo();
+            HashSet<String> dataSet = new HashSet<>();
+            String heights = windTowerInfo.getHeights();
+            String wdHeights = windTowerInfo.getWdHeights();
+            dataSet.addAll(Arrays.asList(heights.split(",")));
+            dataSet.addAll(Arrays.asList(wdHeights.split(",")));
+            for (long i = date.getTime(); i < 1682870400000l; i = DateUtil.offsetMonth(new Date(i), 1).getTime()) {
+                long l = DateUtil.offsetMonth(new Date(i), 1).getTime();
+                List<Map<String, Object>> mapList = windTowerDataParentTableService.selectByBetweenTimeAndEquipmetIdOld(new Date(i), new Date(l), equipmentId);
+                if (mapList.size() > 0) {
+                    ArrayList<ProphaseWeatherData> prophaseAnemometryPublicDataArrayList = new ArrayList<>();
+                    for (Map<String, Object> map : mapList) {
+
+                        //公共部分
+                        ProphaseWeatherData prophaseAnemometryPublicData = new ProphaseWeatherData();
+                        prophaseAnemometryPublicData.setTs(new Timestamp(Long.parseLong(map.get("time").toString())));
+                        prophaseAnemometryPublicData.setTInst(!map.containsKey("t_inst") ? null : Float.parseFloat(map.get("t_inst").toString()));
+                        prophaseAnemometryPublicData.setTAve(!map.containsKey("t_ave") ? null : Float.parseFloat(map.get("t_ave").toString()));
+                        prophaseAnemometryPublicData.setTMax(!map.containsKey("t_max") ? null : Float.parseFloat(map.get("t_max").toString()));
+                        prophaseAnemometryPublicData.setTMin(!map.containsKey("t_min") ? null : Float.parseFloat(map.get("t_min").toString()));
+                        prophaseAnemometryPublicData.setTSta(!map.containsKey("t_sta") ? null : Float.parseFloat(map.get("t_sta").toString()));
+
+                        prophaseAnemometryPublicData.setRhInst(!map.containsKey("rh_inst") ? null : Float.parseFloat(map.get("rh_inst").toString()));
+                        prophaseAnemometryPublicData.setRhAve(!map.containsKey("rh_ave") ? null : Float.parseFloat(map.get("rh_ave").toString()));
+                        prophaseAnemometryPublicData.setRhMax(!map.containsKey("rh_max") ? null : Float.parseFloat(map.get("rh_max").toString()));
+                        prophaseAnemometryPublicData.setRhMin(!map.containsKey("rh_min") ? null : Float.parseFloat(map.get("rh_min").toString()));
+                        prophaseAnemometryPublicData.setRhSta(!map.containsKey("rh_sta") ? null : Float.parseFloat(map.get("rh_sta").toString()));
+
+                        prophaseAnemometryPublicData.setPaInst(!map.containsKey("pa_inst") ? null : Float.parseFloat(map.get("pa_inst").toString()));
+                        prophaseAnemometryPublicData.setPaAve(!map.containsKey("pa_ave") ? null : Float.parseFloat(map.get("pa_ave").toString()));
+                        prophaseAnemometryPublicData.setPaMax(!map.containsKey("pa_max") ? null : Float.parseFloat(map.get("pa_max").toString()));
+                        prophaseAnemometryPublicData.setPaMin(!map.containsKey("pa_min") ? null : Float.parseFloat(map.get("pa_min").toString()));
+                        prophaseAnemometryPublicData.setPaSta(!map.containsKey("pa_sta") ? null : Float.parseFloat(map.get("pa_sta").toString()));
+
+                        prophaseAnemometryPublicData.setAirDensity(!map.containsKey("air_density") ? null : Float.parseFloat(map.get("air_density").toString()));
+                        prophaseAnemometryPublicDataArrayList.add(prophaseAnemometryPublicData);
+                    }
+                    //切分List
+                    List<List<ProphaseWeatherData>> partition = ListUtil.partition(prophaseAnemometryPublicDataArrayList, 3000);
+                    //分批保存
+                    for (List<ProphaseWeatherData> prophaseAnemometryPublicDataList : partition) {
+                        prophaseWeatherDataMapper.insertSplice(prophaseAnemometryPublicDataList, equipmentId);
+                    }
+                    ArrayList<ProphaseAnemometryData> prophaseAnemometryDataArrayList = new ArrayList<>();
+                    for (String height : dataSet) {
+                        for (Map<String, Object> m : mapList) {
+                            //风速 风向
+                            ProphaseAnemometryData one = new ProphaseAnemometryData();
+                            //组装子表数据
+                            one.setWsAve(!m.containsKey("ws_ave" + height) ? null : CalculationUtil.getBigDecimal(m.get("ws_ave" + height)).setScale(2, RoundingMode.HALF_UP).floatValue());
+                            one.setWsMax(!m.containsKey("ws_max" + height) ? null : CalculationUtil.getBigDecimal(m.get("ws_max" + height)).setScale(2, RoundingMode.HALF_UP).floatValue());
+                            one.setWsMin(!m.containsKey("ws_min" + height) ? null : CalculationUtil.getBigDecimal(m.get("ws_min" + height)).setScale(2, RoundingMode.HALF_UP).floatValue());
+                            one.setWsSta(!m.containsKey("ws_sta" + height) ? null : CalculationUtil.getBigDecimal(m.get("ws_sta" + height)).setScale(2, RoundingMode.HALF_UP).floatValue());
+                            one.setWsInst(!m.containsKey("ws_inst" + height) ? null : CalculationUtil.getBigDecimal(m.get("ws_inst" + height)).setScale(2, RoundingMode.HALF_UP).floatValue());
+                            one.setWdAve(!m.containsKey("wd_ave" + height) ? null : CalculationUtil.getBigDecimal(m.get("wd_ave" + height)).setScale(2, RoundingMode.HALF_UP).floatValue());
+                            one.setWdMax(!m.containsKey("wd_max" + height) ? null : CalculationUtil.getBigDecimal(m.get("wd_max" + height)).setScale(2, RoundingMode.HALF_UP).floatValue());
+                            one.setWdMin(!m.containsKey("wd_min" + height) ? null : CalculationUtil.getBigDecimal(m.get("wd_min" + height)).setScale(2, RoundingMode.HALF_UP).floatValue());
+                            one.setWdSta(!m.containsKey("wd_sta" + height) ? null : CalculationUtil.getBigDecimal(m.get("wd_sta" + height)).setScale(2, RoundingMode.HALF_UP).floatValue());
+                            one.setWdInst(!m.containsKey("wd_inst" + height) ? null : CalculationUtil.getBigDecimal(m.get("wd_inst" + height)).setScale(2, RoundingMode.HALF_UP).floatValue());
+                            one.setLayerHeight(height);
+                            one.setEquipmentId(windTowerInfo.getEquipmentNo());
+                            one.setTs(new Timestamp(Long.parseLong(m.get("time").toString())));
+
+                            prophaseAnemometryDataMapper.insertOneWithNew(one);
+//                            prophaseAnemometryDataArrayList.add(one);
+                        }
+                        //切分List
+//                        List<List<ProphaseAnemometryData>> partition1 = ListUtil.partition(prophaseAnemometryDataArrayList, 3000);
+//                        //分批保存
+//                        for (List<ProphaseAnemometryData> prophaseAnemometryData : partition1) {
+//                            prophaseAnemometryDataMapper.insertSplice(prophaseAnemometryData, equipmentId, height);
+//                        }
+                    }
+                }
+            }
+            log.error("入库结束{}",windTowerInfo.getName());
+        }
+    }
 
 
 

+ 23 - 20
neim-biz/src/main/java/com/jiayue/biz/service/impl/HomePageServiceImpl.java

@@ -128,7 +128,7 @@ public class HomePageServiceImpl extends ServiceImpl<WindTowerDataParentTableMap
                     //过滤风速map
                     Map<Timestamp, Float> map = timeAndWsMap.entrySet().stream().filter(t -> t.getKey().getTime() == airAndTime.getKey().getTime()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
                     if (!map.isEmpty()) {
-                        BigDecimal wpdCalculate = CalculationUtil.getWpdCalculate(BigDecimal.valueOf(map.get(airAndTime.getKey())), BigDecimal.valueOf(airAndTime.getValue()));
+                        BigDecimal wpdCalculate = CalculationUtil.getWpdCalculate(BigDecimal.valueOf(airAndTime.getValue()), BigDecimal.valueOf(map.get(airAndTime.getKey())));
                         wpdSumList.add(wpdCalculate);
                         wsSumList.add(BigDecimal.valueOf(map.get(airAndTime.getKey())));
                     }
@@ -552,15 +552,12 @@ public class HomePageServiceImpl extends ServiceImpl<WindTowerDataParentTableMap
     public Map<String, Object> getAirAndPaAndT(String equipmentId, String month) {
         List<ProphaseWeatherData> weatherDataList = new ArrayList<>();
         List<ProphaseAnemometryData> anemometryDataList = new ArrayList<>();
+        //获取最新数据起止时间
         Map<String, Long> dataTimeStartAndEnd = prophaseWeatherDataService.getDataTimeStartAndEnd(equipmentId);
+        //获取测风塔基本信息
         WindTowerInfo windTowerInfo = windTowerInfoService.getByEquipmentNo(equipmentId).get(0);
-        String height;
-        String[] strings = windTowerInfo.getHeights().split(",");
-        height = CalculationUtil.getNumberFromString(strings[0]);
-        String minHeight = CalculationUtil.getNumberFromString(strings[strings.length - 1]); //最底层
-        if (windTowerInfo.getDisplayHeight() != null && !windTowerInfo.getDisplayHeight().equals("")) {
-            height = windTowerInfo.getDisplayHeight();
-        }
+        //获取层高
+        String[] heights = windTowerInfo.getHeights().split(",");
         //获取风向 层高 最高层
         String wdHeights = windTowerInfo.getWdHeights();
         String wdHeightMax = "";
@@ -596,26 +593,32 @@ public class HomePageServiceImpl extends ServiceImpl<WindTowerDataParentTableMap
         BigDecimal pa = BigDecimal.ZERO;
 
         // 风速集合
-        String finalHeight = height;
+        String finalHeight = CalculationUtil.getNumberFromString(heights[0]);
         List<BigDecimal> wsForHeight = anemometryDataList.stream().filter(a -> a.getLayerHeight().equals(finalHeight) && a.getWsAve() != null)
                 .map(h -> BigDecimal.valueOf(h.getWsAve()))
                 .collect(Collectors.toList());
-        //最小风速集合
-        List<BigDecimal> minWsForHeight = anemometryDataList.stream().filter(a -> a.getLayerHeight().equals(minHeight) && a.getWsAve() != null)
-                .map(h -> BigDecimal.valueOf(h.getWsAve()))
-                .collect(Collectors.toList());
         // 风速标准差集合
         List<BigDecimal> wsStaForHeight = anemometryDataList.stream().filter(a -> a.getLayerHeight().equals(finalHeight) && a.getWsSta() != null)
                 .map(h -> BigDecimal.valueOf(h.getWsSta()))
                 .collect(Collectors.toList());
 
         BigDecimal avgWs = CalculationUtil.getAvgWind(wsForHeight); // 风速平均值
-        BigDecimal avgMinWs = CalculationUtil.getAvgWind(minWsForHeight); // 最小风速平均值
         BigDecimal avgWsSta = CalculationUtil.getAvgWind(wsStaForHeight);// 风速标准差平均值
         BigDecimal turbulence = CalculationUtil.caTurbulenceIntensity(avgWsSta, avgWs); // 湍流
         BigDecimal windShear = BigDecimal.ZERO;
-        if (avgWs.compareTo(BigDecimal.ZERO) != 0) {
-            windShear = CalculationUtil.caWindShear(avgWs, avgMinWs, new BigDecimal(height), new BigDecimal(minHeight));// 风切变
+        BigDecimal totalShear = BigDecimal.ZERO;
+        //计算综合风切变
+        if (!anemometryDataList.isEmpty()) {
+            for (long i = DateUtil.beginOfDay(new Date(dataTimeStartAndEnd.get("endTime"))).getTime(); i < dataTimeStartAndEnd.get("endTime"); i = i + 600000) {
+                long finalI = i;
+                List<ProphaseAnemometryData> collect = anemometryDataList.stream().filter(a -> a.getTs().getTime() >= finalI && a.getTs().getTime() < finalI + 600000).collect(Collectors.toList());
+                BigDecimal windShear1 = CalculationUtil.getWindShear(collect, heights);
+                windShear = windShear.add(windShear1);
+                totalShear = totalShear.add(BigDecimal.ONE);
+            }
+            if (totalShear.compareTo(BigDecimal.ZERO) > 0) {
+                windShear = windShear.divide(totalShear, 2, RoundingMode.HALF_UP);
+            }
         }
         if (!weatherDataList.isEmpty()) {
 
@@ -670,7 +673,7 @@ public class HomePageServiceImpl extends ServiceImpl<WindTowerDataParentTableMap
         dataMap.put("pa", pa);
         dataMap.put("turbulence", turbulence);
         dataMap.put("windShear", windShear);
-        dataMap.put("height", height);
+        dataMap.put("height", finalHeight);
         return dataMap;
     }
 
@@ -828,14 +831,14 @@ public class HomePageServiceImpl extends ServiceImpl<WindTowerDataParentTableMap
             //有多条只添加一个其他都是一样的只需要替换id 多余的需要删除
             for (Map<String, Object> map : towerNo) {
                 HashMap<Object, Object> hashMap1 = new HashMap<>();
-                hashMap1.put("type",map.get("type"));
+                hashMap1.put("type", map.get("type"));
                 if (map.containsKey("projectId")) {
-                    hashMap1.put("id",map.get("projectId"));
+                    hashMap1.put("id", map.get("projectId"));
                     arrayList.add(hashMap1);
                 }
             }
             //替换id值
-            towerNo.get(0).put("projectId",arrayList);
+            towerNo.get(0).put("projectId", arrayList);
             listMap.add(towerNo.get(0));
         }
 

+ 8 - 3
neim-biz/src/main/java/com/jiayue/biz/service/impl/WindTowerDataParentTableServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateTime;
 import cn.hutool.core.lang.TypeReference;
 import cn.hutool.db.Entity;
 import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -113,7 +114,8 @@ public class WindTowerDataParentTableServiceImpl extends ServiceImpl<WindTowerDa
                     one.setWdMin(m.get("wdMin_" + height) == null ? null : CalculationUtil.getBigDecimal(m.get("wdMin_" + height)).setScale(2, RoundingMode.HALF_UP).floatValue());
                     one.setWdSta(m.get("wdSta_" + height) == null ? null : CalculationUtil.getBigDecimal(m.get("wdSta_" + height)).setScale(2, RoundingMode.HALF_UP).floatValue());
                     one.setWdInst(m.get("wdInst_" + height) == null ? null : CalculationUtil.getBigDecimal(m.get("wdInst_" + height)).setScale(2, RoundingMode.HALF_UP).floatValue());
-
+                    one.setLayerHeight(height);
+                    one.setEquipmentId(equipmentId);
                     prophaseAnemometryDataArrayList.add(one);
                     if (m.get("time") != null) {
                         try {
@@ -127,8 +129,11 @@ public class WindTowerDataParentTableServiceImpl extends ServiceImpl<WindTowerDa
                             log.error("时间转换异常:" + e);
                         }
                     }
+                    prophaseAnemometryDataMapper.insertOneWithNew(one);
                 }
-                prophaseAnemometryDataMapper.insertSplice(prophaseAnemometryDataArrayList, equipmentId, height);
+
+//                log.error("prophaseAnemometryDataArrayList = " + JSONUtil.toJsonPrettyStr(prophaseAnemometryDataArrayList));
+//                prophaseAnemometryDataMapper.insertSplice(prophaseAnemometryDataArrayList, equipmentId, height);
             }
 
             for (Map<String, Object> m : allData) {
@@ -180,7 +185,7 @@ public class WindTowerDataParentTableServiceImpl extends ServiceImpl<WindTowerDa
                 prophaseAnemometryPublicDataArrayList.add(prophaseAnemometryPublicData);
 
             }
-
+//            log.error("prophaseAnemometryPublicDataArrayList = " + JSONUtil.toJsonPrettyStr(prophaseAnemometryPublicDataArrayList));
             prophaseWeatherDataMapper.insertSplice(prophaseAnemometryPublicDataArrayList, equipmentId);
         } catch (Exception e) {
             e.printStackTrace();

+ 2 - 2
neim-biz/src/main/java/com/jiayue/biz/util/CalculationUtil.java

@@ -165,7 +165,7 @@ public class CalculationUtil {
 
 
     /**
-     * 计算风能密度(风功率玫瑰图) todo 旧
+     * 计算风能密度(风功率玫瑰图)
      *
      * @return 风能密度
      */
@@ -199,7 +199,7 @@ public class CalculationUtil {
     }
 
     //计算风功率密度公式
-    public static BigDecimal getWpdCalculate(BigDecimal wsAve, BigDecimal airAve) {
+    public static BigDecimal getWpdCalculate(BigDecimal airAve, BigDecimal wsAve) {
         return airAve.multiply(power(getBigDecimal(wsAve), 3)).multiply(BigDecimal.valueOf(0.5));
     }