Просмотр исходного кода

新增 气象设备 折线图,列表,导出 增加雨量显示

zhaiyifei 9 месяцев назад
Родитель
Сommit
8534616ecb

+ 52 - 25
src/main/java/com/yunfeiyun/agmp/iot/common/constant/device/ElementFormatUtil.java

@@ -12,11 +12,13 @@ import com.yunfeiyun.agmp.iot.common.domain.dto.IotElementDto;
 import com.yunfeiyun.agmp.iot.common.enums.EnumAdznGssqElement;
 import com.yunfeiyun.agmp.iot.common.enums.EnumAdznGssqElement;
 import com.yunfeiyun.agmp.iot.common.enums.EnumYfQxzElement;
 import com.yunfeiyun.agmp.iot.common.enums.EnumYfQxzElement;
 import com.yunfeiyun.agmp.iot.common.util.dev.QxzTypeUtil;
 import com.yunfeiyun.agmp.iot.common.util.dev.QxzTypeUtil;
+import com.yunfeiyun.agmp.iot.common.util.dev.RainfallUtil;
 import com.yunfeiyun.agmp.iot.common.util.dev.WindUtil;
 import com.yunfeiyun.agmp.iot.common.util.dev.WindUtil;
 
 
 import java.util.*;
 import java.util.*;
 
 
 import static com.yunfeiyun.agmp.iot.common.enums.EnumYfQxzElement.TYPE6;
 import static com.yunfeiyun.agmp.iot.common.enums.EnumYfQxzElement.TYPE6;
+import static com.yunfeiyun.agmp.iot.common.enums.EnumYfQxzElement.TYPE7;
 
 
 public class ElementFormatUtil {
 public class ElementFormatUtil {
 
 
@@ -66,6 +68,54 @@ public class ElementFormatUtil {
         return iotElementDto;
         return iotElementDto;
     }
     }
 
 
+    private static IotElementDto setLabelName(IotElementDto iotElementDto){
+        String eNum = iotElementDto.getENum();
+        String eValue = iotElementDto.getEValue();
+        List<JSONObject> dataList = iotElementDto.getDataList();
+
+        if(StringUtils.isEmpty(eNum)){
+            return iotElementDto;
+        }
+
+        if(eNum.equals(TYPE7.geteNum())
+                || eNum.equals(EnumYfQxzElement.TYPE32.geteNum())
+                || eNum.equals(EnumYfQxzElement.TYPE33.geteNum())
+                || eNum.equals(EnumYfQxzElement.TYPE45.geteNum())
+                || eNum.equals(EnumYfQxzElement.TYPE8.geteNum())){
+            if(StringUtils.isNotEmpty(eValue)){
+                String labelName = WindUtil.getWindSpeedName(eValue);
+                if(eNum.equals(EnumYfQxzElement.TYPE8.geteNum())){
+                    labelName = WindUtil.getWindDirectionName(eValue);
+                }
+                iotElementDto.setEValue(eValue + " (" + labelName + ")");
+            }
+
+            if(dataList!= null && !dataList.isEmpty()){
+                for (JSONObject jsonObject : dataList) {
+                    String eNumber = jsonObject.getString("number");
+                    String labelName = WindUtil.getWindSpeedName(eNumber);
+                    if(eNum.equals(EnumYfQxzElement.TYPE8.geteNum())){
+                        labelName = WindUtil.getWindDirectionName(eNumber);
+                    }
+                    jsonObject.put("labelName", labelName);
+                }
+            }
+        }else if(eNum.equals(EnumYfQxzElement.TYPE4.geteNum()) || eNum.equals(EnumYfQxzElement.TYPE14.geteNum())){
+            if(StringUtils.isNotEmpty(eValue)){
+                String labelName = RainfallUtil.getRainfallName(eValue);
+                iotElementDto.setEValue(eValue + " (" + labelName + ")");
+            }
+            if(dataList!= null && !dataList.isEmpty()){
+                for (JSONObject jsonObject : dataList) {
+                    String eNumber = jsonObject.getString("number");
+                    jsonObject.put("labelName", RainfallUtil.getRainfallName(eNumber));
+                }
+            }
+        }
+        iotElementDto.setDataList(dataList);
+        return iotElementDto;
+    }
+
     /**
     /**
      * 云飞气象站,墒情站
      * 云飞气象站,墒情站
      * 新普惠mqtt设备 公用此要素
      * 新普惠mqtt设备 公用此要素
@@ -94,6 +144,7 @@ public class ElementFormatUtil {
         iotElementDto.setAddress(getAddress(eName, eKey));
         iotElementDto.setAddress(getAddress(eName, eKey));
         iotElementDto.setEUnit(eUnit);
         iotElementDto.setEUnit(eUnit);
         iotElementDto.setEValue(eValue);
         iotElementDto.setEValue(eValue);
+        iotElementDto.setDataList(dataList);
 
 
         if(eNum.equals(TYPE6.geteNum())
         if(eNum.equals(TYPE6.geteNum())
                 || eNum.equals(EnumYfQxzElement.TYPE6_7.geteNum())){
                 || eNum.equals(EnumYfQxzElement.TYPE6_7.geteNum())){
@@ -102,32 +153,8 @@ public class ElementFormatUtil {
                 elementMap.put(eNum, new ArrayList<>());
                 elementMap.put(eNum, new ArrayList<>());
             }
             }
             elementMap.get(eNum).add(Integer.parseInt(eKey.replace("e", "")));
             elementMap.get(eNum).add(Integer.parseInt(eKey.replace("e", "")));
-        }else if(eNum.equals(EnumYfQxzElement.TYPE7.geteNum())
-                || eNum.equals(EnumYfQxzElement.TYPE32.geteNum())
-                || eNum.equals(EnumYfQxzElement.TYPE33.geteNum())
-                || eNum.equals(EnumYfQxzElement.TYPE45.geteNum())
-                || eNum.equals(EnumYfQxzElement.TYPE8.geteNum())){
-            if(StringUtils.isNotEmpty(eValue)){
-                String labelName = WindUtil.getWindSpeed(eValue);
-                if(eNum.equals(EnumYfQxzElement.TYPE8.geteNum())){
-                    labelName = WindUtil.getWindDirection(eValue);
-                }
-                iotElementDto.setEValue(eValue + " (" + labelName + ")");
-            }
-
-            if(dataList!= null && !dataList.isEmpty()){
-                for (JSONObject jsonObject : dataList) {
-                    String eNumber = jsonObject.getString("number");
-                    String labelName = WindUtil.getWindSpeed(eNumber);
-                    if(eNum.equals(EnumYfQxzElement.TYPE8.geteNum())){
-                        labelName = WindUtil.getWindDirection(eNumber);
-                    }
-                    jsonObject.put("labelName", labelName);
-                }
-            }
         }
         }
-        iotElementDto.setDataList(dataList);
-        return iotElementDto;
+        return setLabelName(iotElementDto);
     }
     }
 
 
     private static IotElementDto getElement(IotDevice iotDevice, QxzDataDto dataitem, Map<String, List<Integer>> elementMap){
     private static IotElementDto getElement(IotDevice iotDevice, QxzDataDto dataitem, Map<String, List<Integer>> elementMap){

+ 34 - 0
src/main/java/com/yunfeiyun/agmp/iot/common/util/dev/RainfallUtil.java

@@ -0,0 +1,34 @@
+package com.yunfeiyun.agmp.iot.common.util.dev;
+
+import com.yunfeiyun.agmp.iot.common.util.BigDecimalUtil;
+
+import java.math.BigDecimal;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class RainfallUtil {
+    private static final int scale = 2;
+    public static String getRainfallName(String rainfall) {
+        Map<String, String> rainfallNameMap = new LinkedHashMap<>(); // 雨量等级对照表
+        rainfallNameMap.put("0.1", "无雨");
+        rainfallNameMap.put("9.9", "小雨");
+        rainfallNameMap.put("24.9", "中雨");
+        rainfallNameMap.put("49.9", "大雨");
+        rainfallNameMap.put("99.9", "暴雨");
+        rainfallNameMap.put("249.9", "大暴雨");
+        rainfallNameMap.put("1000", "特大暴雨");
+        String rainfallName = "未知";
+        try{
+            BigDecimal standValue = BigDecimalUtil.format(rainfall, scale);
+            for(Map.Entry<String, String> entry : rainfallNameMap.entrySet()) {
+                if (standValue.compareTo(BigDecimalUtil.format(entry.getKey(), scale)) <= 0) {
+                    rainfallName = entry.getValue();
+                    break;
+                }
+            }
+        }catch (Exception e){
+
+        }
+        return rainfallName;
+    }
+}

+ 2 - 2
src/main/java/com/yunfeiyun/agmp/iot/common/util/dev/WindUtil.java

@@ -13,7 +13,7 @@ public class WindUtil {
      * @param windDirection 风向
      * @param windDirection 风向
      * @return 风向
      * @return 风向
      */
      */
-    public static String getWindDirection(String windDirection) {
+    public static String getWindDirectionName(String windDirection) {
         Map<String, String> directionNameMap = new LinkedHashMap<>();
         Map<String, String> directionNameMap = new LinkedHashMap<>();
         directionNameMap.put("22.25", "北风");
         directionNameMap.put("22.25", "北风");
         directionNameMap.put("67.5", "东北风");
         directionNameMap.put("67.5", "东北风");
@@ -44,7 +44,7 @@ public class WindUtil {
      * @param windSpeed 风速
      * @param windSpeed 风速
      * @return 风速
      * @return 风速
      */
      */
-    public static String getWindSpeed(String windSpeed) {
+    public static String getWindSpeedName(String windSpeed) {
         Map<String, String> speedNameMap = new LinkedHashMap<>();
         Map<String, String> speedNameMap = new LinkedHashMap<>();
         speedNameMap.put("0.2", "0级 无风");
         speedNameMap.put("0.2", "0级 无风");
         speedNameMap.put("1.5", "1级 软风");
         speedNameMap.put("1.5", "1级 软风");