chen_xi
2022-09-22 707962b2002a90847b7d4839d9328e5b289512a4
大屏实时显示bug修改
2 files modified
27 ■■■■ changed files
screen-api/src/main/java/com/moral/api/utils/AdjustDataUtils.java 3 ●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/utils/JsonUtil.java 24 ●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/utils/AdjustDataUtils.java
@@ -77,7 +77,8 @@
                    if (formula.contains("aqi")) {
                        Object aqiValue = null;
                        if (aqiMap != null) {
                            String jsonStr = JsonUtil.readJsonFile("classpath:SensorContrast.json");
                            //String jsonStr = JsonUtil.readJsonFile("classpath:SensorContrast.json");
                            String jsonStr = JsonUtil.testReadFile("SensorContrast.json");
                            JSONObject result = JSONObject.parseObject(jsonStr);
                            aqiValue = aqiMap.get(result.get(key));
                            //aqiValue = aqiMap.get(SensorContrasts.sensorContrastMap.get(key));
screen-api/src/main/java/com/moral/api/utils/JsonUtil.java
@@ -1,9 +1,9 @@
package com.moral.api.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import java.io.*;
public class JsonUtil {
@@ -31,5 +31,21 @@
        }
    }
    public static String testReadFile(String filePath) throws IOException {
//        ClassPathResource classPathResource = new ClassPathResource("resource.properties");
        String jsonStr = "";
        Resource resource = new ClassPathResource(filePath);
        InputStream is = resource.getInputStream();
        Reader reader = new InputStreamReader(resource.getInputStream(), "utf-8");
        int ch = 0;
        StringBuffer sb = new StringBuffer();
        while ((ch = reader.read()) != -1) {
            sb.append((char) ch);
        }
        reader.close();
        jsonStr = sb.toString();
        return jsonStr;
    }
}