zjs 2 nedēļas atpakaļ
vecāks
revīzija
abe9b564e8
1 mainītis faili ar 21 papildinājumiem un 11 dzēšanām
  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 1
 package com.cn.esermis.utils;
2 2
 
3 3
 import com.alibaba.fastjson2.JSONObject;
4
+import com.cn.esermis.coding.PollutionGas;
4 5
 import com.cn.esermis.constant.Constant;
5 6
 import lombok.extern.slf4j.Slf4j;
6 7
 
@@ -22,6 +23,8 @@ public class HJ212MsgUtils {
22 23
      * @param msg hj212
23 24
      * @return json
24 25
      */
26
+
27
+
25 28
     public static JSONObject dealMsg1(String msg) {
26 29
         JSONObject data = new JSONObject();
27 30
         try {
@@ -67,7 +70,7 @@ public class HJ212MsgUtils {
67 70
                     .replace(",", "\",\"").replace(";", "\",\"");
68 71
             data.put("SIZE", headStr.substring(0, 4));
69 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 74
                 return null;
72 75
             }
73 76
             // 清洗数据体基本数据
@@ -79,17 +82,24 @@ public class HJ212MsgUtils {
79 82
                 // 如果是时间信息,则直接放到外层
80 83
                 if (paramStr.contains("DataTime")) {
81 84
                     data.putAll(JSONObject.parseObject("{\"" + paramStr + "\"}"));
82
-                } else if (paramStr.contains("PNUM")){
85
+                } else if (paramStr.contains("PNUM")) {
83 86
                     data.putAll(JSONObject.parseObject("{\"" + paramStr + "\"}"));
84
-                }
85
-                else if(paramStr.contains("PNO"))
86
-                {  //PNO
87
+                } else if (paramStr.contains("PNO")) {  //PNO
87 88
                     data.putAll(JSONObject.parseObject("{\"" + paramStr + "\"}"));
88
-                }
89
-                else {
89
+                } else {
90 90
                     String[] ele = getPollutionSource(paramStr);
91 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 103
                     cp.add(jsonObject);
94 104
                 }
95 105
             }
@@ -110,7 +120,7 @@ public class HJ212MsgUtils {
110 120
      * 解析污染源数据,获取污染源编号
111 121
      */
112 122
     private static String[] getPollutionSource(String data) {
113
-        if (data.contains("-")){
123
+        if (data.contains("-")) {
114 124
             String key = data.substring(0, data.indexOf("-"));
115 125
             data = data.replaceAll(key + "-", "");
116 126
 
@@ -118,8 +128,8 @@ public class HJ212MsgUtils {
118 128
             result[0] = key;
119 129
             result[1] = data;
120 130
             return result;
121
-        }else {
122
-            if (data.contains(":")){
131
+        } else {
132
+            if (data.contains(":")) {
123 133
                 String[] split = data.split(":");
124 134
                 return split;
125 135
             }