浏览代码

Merge branch 'master' of http://116.63.33.55/git/industry-data-platform

lry 11 月之前
父节点
当前提交
cf6387ded6
共有 1 个文件被更改,包括 15 次插入2 次删除
  1. 15 2
      新采集器/fast-api/src/main/java/com/ws/fastapi/util/ConfUtil.java

+ 15 - 2
新采集器/fast-api/src/main/java/com/ws/fastapi/util/ConfUtil.java

@@ -155,7 +155,7 @@ public class ConfUtil {
                 type = "i";
             }
             builder.append("{name=\"").append(obj.getStr("itemName")).append("\", namespace=\"").append(obj.getStr("nodeIndex"))
-                    .append("\", identifier_type=\"").append(type).append("\", identifier=\"").append(obj.getStr("identifier"))
+                    .append("\", identifier_type=\"").append(type).append("\", identifier=\"").append(escapeStr(obj.getStr("identifier")))
                     .append("\", tags = [[\"DataSource\", \"").append(item.getStr("datasource")).append("\"], [\"ItemGroup\", \"")
                     .append(item.getStr("itemGroupId")).append("\"]]},\n");
         }
@@ -163,6 +163,19 @@ public class ConfUtil {
         return builder.toString();
     }
 
+    private static String escapeStr(String value){
+        if(StrUtil.isEmpty(value)){
+            return "";
+        }
+        if(!value.contains("\"")){
+            return value;
+        }
+        value = value.replace("\"", "\\\"");
+        return value;
+    }
+
+
+
     private static String createOpcUaFast(JSONObject item) {
         StringBuilder builder = new StringBuilder();
         builder.append("[[inputs.opcua_listener]]\n")
@@ -199,7 +212,7 @@ public class ConfUtil {
                 type = "i";
             }
             builder.append("{name=\"").append(obj.getStr("itemName")).append("\", namespace=\"").append(obj.getStr("nodeIndex"))
-                    .append("\", identifier_type=\"").append(type).append("\", identifier=\"").append(obj.getStr("identifier"))
+                    .append("\", identifier_type=\"").append(type).append("\", identifier=\"").append(escapeStr(obj.getStr("identifier")))
                     .append("\", tags = [[\"DataSource\", \"").append(item.getStr("datasource")).append("\"], [\"ItemGroup\", \"")
                     .append(item.getStr("itemGroupId")).append("\"]]},\n");