zhaiyifei 8 месяцев назад
Родитель
Сommit
66e69b8f84

+ 45 - 36
src/main/java/com/yunfeiyun/agmp/iot/common/util/dev/RunHaoSfElementUtil.java

@@ -1,5 +1,6 @@
 package com.yunfeiyun.agmp.iot.common.util.dev;
 
+import com.alibaba.fastjson2.JSONObject;
 import com.yunfeiyun.agmp.iot.common.domain.IotSfElementfactor;
 import com.yunfeiyun.agmp.iot.common.enums.EnumSfElementType;
 
@@ -14,10 +15,10 @@ public class RunHaoSfElementUtil {
      */
     public static Map<String, EnumSfElementType> getPumpTypeMap() {
         Map<String, EnumSfElementType> sfElementMap = new HashMap<>();
-        sfElementMap.put("ggbs", EnumSfElementType.WATER_SOURCE);
-        sfElementMap.put("sfbs", EnumSfElementType.FERTILIZER);
-        sfElementMap.put("fs", EnumSfElementType.SUCTION);
-        sfElementMap.put("js", EnumSfElementType.MIXING);
+        sfElementMap.put("Btn-ggbs", EnumSfElementType.WATER_SOURCE);
+        sfElementMap.put("Btn-sfbs", EnumSfElementType.FERTILIZER);
+        sfElementMap.put("Btn-fs", EnumSfElementType.SUCTION);
+        sfElementMap.put("Btn-js", EnumSfElementType.MIXING);
 
         return sfElementMap;
     }
@@ -29,7 +30,7 @@ public class RunHaoSfElementUtil {
      */
     public static Map<String, EnumSfElementType> getGroupTypeMap() {
         Map<String, EnumSfElementType> sfElementMap = new HashMap<>();
-        sfElementMap.put("qx", EnumSfElementType.GROUP);
+        sfElementMap.put("Btn-qx", EnumSfElementType.GROUP);
 
         return sfElementMap;
     }
@@ -42,7 +43,7 @@ public class RunHaoSfElementUtil {
      */
     public static Map<String, EnumSfElementType> getValveTypeMap() {
         Map<String, EnumSfElementType> sfElementMap = new HashMap<>();
-        sfElementMap.put("fa", EnumSfElementType.SOLENOID_VALVE);
+        sfElementMap.put("Btn-fa", EnumSfElementType.SOLENOID_VALVE);
 
         return sfElementMap;
     }
@@ -54,10 +55,10 @@ public class RunHaoSfElementUtil {
      */
     public static Map<String, EnumSfElementType> getSensorTypeMap() {
         Map<String, EnumSfElementType> sfElementMap = new HashMap<>();
-        sfElementMap.put("ph", EnumSfElementType.SENSOR);
-        sfElementMap.put("ec", EnumSfElementType.SENSOR);
-        sfElementMap.put("sw", EnumSfElementType.SENSOR);
-        sfElementMap.put("gdyl", EnumSfElementType.SENSOR);
+        sfElementMap.put("Num-ph", EnumSfElementType.SENSOR);
+        sfElementMap.put("Num-ec", EnumSfElementType.SENSOR);
+        sfElementMap.put("Num-sw", EnumSfElementType.SENSOR);
+        sfElementMap.put("Num-gdyl", EnumSfElementType.SENSOR);
 
         return sfElementMap;
     }
@@ -69,10 +70,10 @@ public class RunHaoSfElementUtil {
      */
     public static Map<String, String> getPumpNameMap() {
         Map<String, String> sfElementMap = new HashMap<>();
-        sfElementMap.put("ggbs", "灌溉泵");
-        sfElementMap.put("sfbs", "施肥泵");
-        sfElementMap.put("fs", "肥阀");
-        sfElementMap.put("js", "搅拌电机");
+        sfElementMap.put("Btn-ggbs", "灌溉泵");
+        sfElementMap.put("Btn-sfbs", "施肥泵");
+        sfElementMap.put("Btn-fs", "肥阀");
+        sfElementMap.put("Btn-js", "搅拌电机");
 
         return sfElementMap;
     }
@@ -84,7 +85,7 @@ public class RunHaoSfElementUtil {
      */
     public static Map<String, String> getGroupNameMap() {
         Map<String, String> sfElementMap = new HashMap<>();
-        sfElementMap.put("qx", "区");
+        sfElementMap.put("Btn-qx", "区");
         return sfElementMap;
     }
 
@@ -96,7 +97,7 @@ public class RunHaoSfElementUtil {
      */
     public static Map<String, String> getValveNameMap() {
         Map<String, String> sfElementMap = new HashMap<>();
-        sfElementMap.put("fa", "井阀");
+        sfElementMap.put("Btn-fa", "井阀");
 
         return sfElementMap;
     }
@@ -108,10 +109,10 @@ public class RunHaoSfElementUtil {
      */
     public static Map<String, String> getSensorNameMap() {
         Map<String, String> sfElementMap = new HashMap<>();
-        sfElementMap.put("ph", "PH");
-        sfElementMap.put("ec", "EC");
-        sfElementMap.put("sw", "水温");
-        sfElementMap.put("gdyl", "管道压力");
+        sfElementMap.put("Num-ph", "PH");
+        sfElementMap.put("Num-ec", "EC");
+        sfElementMap.put("Num-sw", "水温");
+        sfElementMap.put("Num-gdyl", "管道压力");
         return sfElementMap;
     }
 
@@ -122,8 +123,6 @@ public class RunHaoSfElementUtil {
      * @return 设备元素因子对象,如果无法解析则返回null
      */
     public static IotSfElementfactor getPumpElementFactor(String key) {
-        String[] temp = key.split("-");
-        String suffix = temp[1];
 
         IotSfElementfactor sfElementfactor = new IotSfElementfactor();
         String sfName = null;
@@ -133,8 +132,8 @@ public class RunHaoSfElementUtil {
 
         for(Map.Entry<String, String> entry : sfNameMap.entrySet()){
             String sfKey = entry.getKey();
-            if(suffix.startsWith(sfKey)){
-                sfName = entry.getValue() + suffix.replace(sfKey, "");
+            if(key.startsWith(sfKey)){
+                sfName = entry.getValue() + key.replace(sfKey, "");
                 elementType = sfTypeMap.get(sfKey);
             }
         }
@@ -157,8 +156,6 @@ public class RunHaoSfElementUtil {
      * @return 设备元素因子对象,如果无法解析则返回null
      */
     public static IotSfElementfactor getValveElementFactor(String key) {
-        String[] temp = key.split("-");
-        String suffix = temp[1];
 
         IotSfElementfactor sfElementfactor = new IotSfElementfactor();
         String sfName = null;
@@ -168,8 +165,8 @@ public class RunHaoSfElementUtil {
 
         for(Map.Entry<String, String> entry : sfNameMap.entrySet()){
             String sfKey = entry.getKey();
-            if(suffix.startsWith(sfKey)){
-                sfName = entry.getValue() + suffix.replace(sfKey, "");
+            if(key.startsWith(sfKey)){
+                sfName = entry.getValue() + key.replace(sfKey, "");
                 elementType = sfTypeMap.get(sfKey);
             }
         }
@@ -192,8 +189,6 @@ public class RunHaoSfElementUtil {
      * @return 设备元素因子对象,如果无法解析则返回null
      */
     public static IotSfElementfactor getGroupElementFactor(String key) {
-        String[] temp = key.split("-");
-        String suffix = temp[1];
 
         IotSfElementfactor sfElementfactor = new IotSfElementfactor();
         String sfName = null;
@@ -203,8 +198,8 @@ public class RunHaoSfElementUtil {
 
         for(Map.Entry<String, String> entry : sfNameMap.entrySet()){
             String sfKey = entry.getKey();
-            if(suffix.startsWith(sfKey)){
-                sfName = suffix.replace(sfKey, "") + entry.getValue();
+            if(key.startsWith(sfKey)){
+                sfName = key.replace(sfKey, "") + entry.getValue();
                 elementType = sfTypeMap.get(sfKey);
             }
         }
@@ -227,8 +222,6 @@ public class RunHaoSfElementUtil {
      * @return 设备元素因子对象,如果无法解析则返回null
      */
     public static IotSfElementfactor getSensorElementFactor(String key) {
-        String[] temp = key.split("-");
-        String suffix = temp[1];
 
         IotSfElementfactor sfElementfactor = new IotSfElementfactor();
         String sfName = null;
@@ -238,8 +231,8 @@ public class RunHaoSfElementUtil {
 
         for(Map.Entry<String, String> entry : sfNameMap.entrySet()){
             String sfKey = entry.getKey();
-            if(suffix.startsWith(sfKey)){
-                sfName = entry.getValue() + suffix.replace(sfKey, "");
+            if(key.startsWith(sfKey)){
+                sfName = entry.getValue() + key.replace(sfKey, "");
                 elementType = sfTypeMap.get(sfKey);
             }
         }
@@ -312,4 +305,20 @@ public class RunHaoSfElementUtil {
         }
         return iotSfElementfactor;
     }
+
+    public static String getDataValue(String sfCode, JSONObject data) {
+        String value = data.getString(sfCode);
+        if(Objects.equals(value, "true")){
+            value = "1";
+        }else if(Objects.equals(value, "false")){
+            value = "0";
+        }else{
+            try{
+                value = String.valueOf((int)Math.floor(Double.parseDouble(value)));
+            }catch (Exception e){
+                value = "0";
+            }
+        }
+        return value;
+    }
 }