From 560303799978bd141dc1e9553b7607012591fb42 Mon Sep 17 00:00:00 2001
From: 严智鑫 <test>
Date: 星期二, 17 六月 2025 17:02:53 +0800
Subject: [PATCH] 1.json文件优化 增加配置项:【1.触发点;2.逻辑线程时间间隔】 2.优化处理代码 【1.去除多余日志输出点;2.两个设备json文件进行根据codeId进行关联;3.调整代码先后顺序】 3.json文件路径提出jar包外,可在设备表上配置上配置路径。因原方式修改地址json 后需重新打包,实际调试中传递jar包比较浪费时间
---
ShangHaiMesParent/moduleService/plcConnectModule/src/main/java/com/mes/common/ReadFile.java | 19 +++++++++++--------
1 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/ShangHaiMesParent/moduleService/plcConnectModule/src/main/java/com/mes/common/ReadFile.java b/ShangHaiMesParent/moduleService/plcConnectModule/src/main/java/com/mes/common/ReadFile.java
index f3cbc35..a4f50d2 100644
--- a/ShangHaiMesParent/moduleService/plcConnectModule/src/main/java/com/mes/common/ReadFile.java
+++ b/ShangHaiMesParent/moduleService/plcConnectModule/src/main/java/com/mes/common/ReadFile.java
@@ -2,21 +2,24 @@
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
+import java.io.*;
public class ReadFile {
// 璇诲彇Json鏂囦欢鍐呭
- public static JSONObject readJson(String fileName) throws IOException {
+ public static JSONObject readJson(String fileUrl) throws IOException {
// 璧勬簮璺緞锛堢浉瀵逛簬resources鏍圭洰褰曪級
- String resourcePath = "jsonFile/"+fileName;
+ //String resourcePath = "jsonFile/"+fileName;
+ //String resourcePath = System.getProperty("user.dir") + "/JsonFile/"+fileName;
+ String resourcePath = fileUrl;
// 鑾峰彇绫诲姞杞藉櫒
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ //ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
// 璇诲彇璧勬簮
- try (InputStream inputStream = classLoader.getResourceAsStream(resourcePath)) {
+
+ try (InputStream inputStream = new FileInputStream(resourcePath)) {
+ //try (InputStream inputStream = classLoader.getResourceAsStream(resourcePath)) {
if (inputStream == null) {
throw new IOException("璧勬簮鏈壘鍒�: " + resourcePath);
}
--
Gitblit v1.8.0