2 files added
1 files modified
| | |
| | | package com.moral.api.utils; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.ObjectUtils; |
| | |
| | | if (formula.contains("aqi")) { |
| | | Object aqiValue = null; |
| | | if (aqiMap != null) { |
| | | aqiValue = aqiMap.get(key); |
| | | String jsonStr = JsonUtil.readJsonFile("screen-api/src/main/resources/SensorContrast.json"); |
| | | JSONObject result = JSONObject.parseObject(jsonStr); |
| | | aqiValue = aqiMap.get(result.get(key)); |
| | | } |
| | | env.put("aqi", ObjectUtils.isEmpty(aqiValue) ? 0F : Float.parseFloat((String) aqiValue)); |
| | | } |
New file |
| | |
| | | package com.moral.api.utils; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.io.Reader; |
| | | |
| | | public class JsonUtil { |
| | | |
| | | /** |
| | | * 读取JSON文件转换为字符串 |
| | | * @param filePath |
| | | * @return |
| | | */ |
| | | public static String readJsonFile(String filePath) { |
| | | String jsonStr = ""; |
| | | try { |
| | | File jsonFile = new File(filePath); |
| | | Reader reader = new InputStreamReader(new FileInputStream(jsonFile), "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; |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
New file |
| | |
| | | { |
| | | "a34004": "PM2_5", |
| | | "a34002": "PM10", |
| | | "a05024": "O3", |
| | | "a21004": "NO2", |
| | | "a21005": "CO", |
| | | "a21026": "SO2" |
| | | } |