|
@ -243,7 +243,10 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
JSONArray jsonArray = null; |
|
|
JSONArray jsonArray = null; |
|
|
|
|
|
|
|
|
if (body != null) { |
|
|
if (body != null) { |
|
|
jsonArray = JSON.parseArray(body.string()); |
|
|
String jsonString = body.string(); |
|
|
|
|
|
if (JSON.isValidArray(jsonString)) { |
|
|
|
|
|
jsonArray = JSON.parseArray(jsonString); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Map<String, Integer> map = new HashMap<>(); |
|
|
Map<String, Integer> map = new HashMap<>(); |
|
@ -704,37 +707,39 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
|
|
|
|
|
ResponseBody body = response.body(); |
|
|
ResponseBody body = response.body(); |
|
|
if (body != null) { |
|
|
if (body != null) { |
|
|
JSONArray jsonArray = JSON.parseArray(body.string()); |
|
|
String jsonString = body.string(); |
|
|
Map<String, Integer> sumByName = new LinkedHashMap<>(); |
|
|
if (JSON.isValidArray(jsonString)) { |
|
|
Integer totalFlow1 = 0; |
|
|
JSONArray jsonArray = JSON.parseArray(jsonString); |
|
|
List<Map<String, String>> list = new ArrayList(); |
|
|
Map<String, Integer> sumByName = new LinkedHashMap<>(); |
|
|
for (Object item : jsonArray) { // 这里做了微调,直接遍历jsonArray的Object
|
|
|
Integer totalFlow1 = 0; |
|
|
JSONObject jsonObject = (JSONObject) item; |
|
|
List<Map<String, String>> list = new ArrayList(); |
|
|
|
|
|
for (Object item : jsonArray) { // 这里做了微调,直接遍历jsonArray的Object
|
|
|
|
|
|
JSONObject jsonObject = (JSONObject) item; |
|
|
|
|
|
|
|
|
totalFlow1 = totalFlow1 + jsonObject.getInteger("total_flow"); |
|
|
totalFlow1 = totalFlow1 + jsonObject.getInteger("total_flow"); |
|
|
|
|
|
|
|
|
// 获取当前时间
|
|
|
// 获取当前时间
|
|
|
LocalTime now = LocalTime.now(); |
|
|
LocalTime now = LocalTime.now(); |
|
|
// 获取当前小时数(24小时制)
|
|
|
// 获取当前小时数(24小时制)
|
|
|
int currentHour = now.getHour(); |
|
|
int currentHour = now.getHour(); |
|
|
if (jsonObject.getInteger("data_hour") == currentHour) { |
|
|
if (jsonObject.getInteger("data_hour") == currentHour) { |
|
|
String name = jsonObject.getString("ts_name"); // 更安全的取值方式
|
|
|
String name = jsonObject.getString("ts_name"); // 更安全的取值方式
|
|
|
int totalFlow = jsonObject.getInteger("total_flow"); // 专门针对Integer类型
|
|
|
int totalFlow = jsonObject.getInteger("total_flow"); // 专门针对Integer类型
|
|
|
|
|
|
|
|
|
sumByName.put(name, totalFlow); |
|
|
sumByName.put(name, totalFlow); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
System.out.println("总数===:" + totalFlow1); |
|
|
|
|
|
// 正确创建新的映射对象并添加到list中
|
|
|
|
|
|
for (Map.Entry<String, Integer> entry : sumByName.entrySet()) { |
|
|
|
|
|
Map<String, String> singleResult = new LinkedHashMap<>(); // 每次循环都创建一个新的映射
|
|
|
|
|
|
singleResult.put("name", entry.getKey()); |
|
|
|
|
|
singleResult.put("value", entry.getValue().toString()); |
|
|
|
|
|
list.add(singleResult); |
|
|
|
|
|
} |
|
|
|
|
|
return list; |
|
|
} |
|
|
} |
|
|
System.out.println("总数===:" + totalFlow1); |
|
|
|
|
|
// 正确创建新的映射对象并添加到list中
|
|
|
|
|
|
for (Map.Entry<String, Integer> entry : sumByName.entrySet()) { |
|
|
|
|
|
Map<String, String> singleResult = new LinkedHashMap<>(); // 每次循环都创建一个新的映射
|
|
|
|
|
|
singleResult.put("name", entry.getKey()); |
|
|
|
|
|
singleResult.put("value", entry.getValue().toString()); |
|
|
|
|
|
list.add(singleResult); |
|
|
|
|
|
} |
|
|
|
|
|
return list; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return new ArrayList(); |
|
|
return new ArrayList(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|