Browse Source

hj212 2005

zjs 1 week ago
parent
commit
abe9b564e8
1 changed files with 21 additions and 11 deletions
  1. 21 11
      src/main/java/com/cn/esermis/utils/HJ212MsgUtils.java

+ 21 - 11
src/main/java/com/cn/esermis/utils/HJ212MsgUtils.java

@@ -1,6 +1,7 @@
1
 package com.cn.esermis.utils;
1
 package com.cn.esermis.utils;
2
 
2
 
3
 import com.alibaba.fastjson2.JSONObject;
3
 import com.alibaba.fastjson2.JSONObject;
4
+import com.cn.esermis.coding.PollutionGas;
4
 import com.cn.esermis.constant.Constant;
5
 import com.cn.esermis.constant.Constant;
5
 import lombok.extern.slf4j.Slf4j;
6
 import lombok.extern.slf4j.Slf4j;
6
 
7
 
@@ -22,6 +23,8 @@ public class HJ212MsgUtils {
22
      * @param msg hj212
23
      * @param msg hj212
23
      * @return json
24
      * @return json
24
      */
25
      */
26
+
27
+
25
     public static JSONObject dealMsg1(String msg) {
28
     public static JSONObject dealMsg1(String msg) {
26
         JSONObject data = new JSONObject();
29
         JSONObject data = new JSONObject();
27
         try {
30
         try {
@@ -67,7 +70,7 @@ public class HJ212MsgUtils {
67
                     .replace(",", "\",\"").replace(";", "\",\"");
70
                     .replace(",", "\",\"").replace(";", "\",\"");
68
             data.put("SIZE", headStr.substring(0, 4));
71
             data.put("SIZE", headStr.substring(0, 4));
69
             data.putAll(JSONObject.parseObject("{\"" + headStr.substring(4) + "\"}"));
72
             data.putAll(JSONObject.parseObject("{\"" + headStr.substring(4) + "\"}"));
70
-            if (!Constant.COMMAND.contains(data.getString("CN"))){
73
+            if (!Constant.COMMAND.contains(data.getString("CN"))) {
71
                 return null;
74
                 return null;
72
             }
75
             }
73
             // 清洗数据体基本数据
76
             // 清洗数据体基本数据
@@ -79,17 +82,24 @@ public class HJ212MsgUtils {
79
                 // 如果是时间信息,则直接放到外层
82
                 // 如果是时间信息,则直接放到外层
80
                 if (paramStr.contains("DataTime")) {
83
                 if (paramStr.contains("DataTime")) {
81
                     data.putAll(JSONObject.parseObject("{\"" + paramStr + "\"}"));
84
                     data.putAll(JSONObject.parseObject("{\"" + paramStr + "\"}"));
82
-                } else if (paramStr.contains("PNUM")){
85
+                } else if (paramStr.contains("PNUM")) {
83
                     data.putAll(JSONObject.parseObject("{\"" + paramStr + "\"}"));
86
                     data.putAll(JSONObject.parseObject("{\"" + paramStr + "\"}"));
84
-                }
85
-                else if(paramStr.contains("PNO"))
86
-                {  //PNO
87
+                } else if (paramStr.contains("PNO")) {  //PNO
87
                     data.putAll(JSONObject.parseObject("{\"" + paramStr + "\"}"));
88
                     data.putAll(JSONObject.parseObject("{\"" + paramStr + "\"}"));
88
-                }
89
-                else {
89
+                } else {
90
                     String[] ele = getPollutionSource(paramStr);
90
                     String[] ele = getPollutionSource(paramStr);
91
                     JSONObject jsonObject = JSONObject.parseObject("{\"" + ele[1] + "\"}");
91
                     JSONObject jsonObject = JSONObject.parseObject("{\"" + ele[1] + "\"}");
92
-                    jsonObject.put("factor",ele[0]);
92
+//                    PollutionGas pollutionGas = PollutionGas.valueOf(ele[0]);
93
+                    PollutionGas[] values = PollutionGas.values();
94
+                    jsonObject.put("factor", ele[0]);
95
+                    if (ele[0].length() < 6){
96
+                        for (PollutionGas value : values) {
97
+                            if (value.oldCode().equals(ele[0])) {
98
+                                jsonObject.put("factor", value.code());
99
+                                break;
100
+                            }
101
+                        }
102
+                    }
93
                     cp.add(jsonObject);
103
                     cp.add(jsonObject);
94
                 }
104
                 }
95
             }
105
             }
@@ -110,7 +120,7 @@ public class HJ212MsgUtils {
110
      * 解析污染源数据,获取污染源编号
120
      * 解析污染源数据,获取污染源编号
111
      */
121
      */
112
     private static String[] getPollutionSource(String data) {
122
     private static String[] getPollutionSource(String data) {
113
-        if (data.contains("-")){
123
+        if (data.contains("-")) {
114
             String key = data.substring(0, data.indexOf("-"));
124
             String key = data.substring(0, data.indexOf("-"));
115
             data = data.replaceAll(key + "-", "");
125
             data = data.replaceAll(key + "-", "");
116
 
126
 
@@ -118,8 +128,8 @@ public class HJ212MsgUtils {
118
             result[0] = key;
128
             result[0] = key;
119
             result[1] = data;
129
             result[1] = data;
120
             return result;
130
             return result;
121
-        }else {
122
-            if (data.contains(":")){
131
+        } else {
132
+            if (data.contains(":")) {
123
                 String[] split = data.split(":");
133
                 String[] split = data.split(":");
124
                 return split;
134
                 return split;
125
             }
135
             }