|
|
@ -23,10 +23,7 @@ import org.springframework.stereotype.Service; |
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsService { |
|
|
@ -509,5 +506,104 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
return new JSONArray(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 断面小时车流量分车型 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public JSONArray sectionHourlyTrafficFlow(String startDate, String endDate) throws HttpException, IOException { |
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
|
|
|
|
requestParams.put("sysid", sysid); |
|
|
|
|
|
|
|
JSONObject parameters = new JSONObject() { |
|
|
|
{ |
|
|
|
put("start_date", startDate); |
|
|
|
put("end_date", endDate); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
requestParams.put("parameters", parameters.toJSONString()); |
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
headers.put("Authorization", getAccessToken()); |
|
|
|
|
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(headers) |
|
|
|
.url(baseUrl + "/api/dc/query/rd_jihe_d_vehtypeflowbydatesection") // 请求地址
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
.post(); // 请求方法
|
|
|
|
|
|
|
|
ResponseBody body = response.body(); |
|
|
|
if (body != null) { |
|
|
|
return JSON.parseArray(body.string()); |
|
|
|
} |
|
|
|
|
|
|
|
return new JSONArray(); |
|
|
|
} |
|
|
|
/** |
|
|
|
* 各收费站入口分车型小时车流量 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<Map<String, String>> trafficFlowAtTollStationEntrance(String startDate, String endDate,String stationType) throws HttpException, IOException { |
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
|
|
|
|
requestParams.put("sysid", sysid); |
|
|
|
|
|
|
|
JSONObject parameters = new JSONObject() { |
|
|
|
{ |
|
|
|
put("start_date", startDate); |
|
|
|
put("end_date", endDate); |
|
|
|
put("station_type", stationType); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
requestParams.put("parameters", parameters.toJSONString()); |
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
headers.put("Authorization", getAccessToken()); |
|
|
|
|
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(headers) |
|
|
|
.url(baseUrl + "/api/dc/query/ts_jihe_d_vehtypeflowbyhourstation") // 请求地址
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
.post(); // 请求方法
|
|
|
|
|
|
|
|
ResponseBody body = response.body(); |
|
|
|
if (body != null) { |
|
|
|
JSONArray jsonArray = JSON.parseArray(body.string()); |
|
|
|
|
|
|
|
// 使用HashMap来分组并求和
|
|
|
|
Map<String, Integer> sumByName = new HashMap<>(); |
|
|
|
List<Map<String, String>> list = new ArrayList(); |
|
|
|
|
|
|
|
for (Object item : jsonArray) { // 这里做了微调,直接遍历jsonArray的Object
|
|
|
|
JSONObject jsonObject = (JSONObject) item; |
|
|
|
String name = jsonObject.getString("ts_name"); // 更安全的取值方式
|
|
|
|
int totalFlow = jsonObject.getInteger("total_flow"); // 专门针对Integer类型
|
|
|
|
sumByName.put(name, sumByName.getOrDefault(name, 0) + totalFlow); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 输出结果
|
|
|
|
// 输出结果
|
|
|
|
// 正确创建新的映射对象并添加到list中
|
|
|
|
for (Map.Entry<String, Integer> entry : sumByName.entrySet()) { |
|
|
|
Map<String, String> singleResult = new HashMap<>(); // 每次循环都创建一个新的映射
|
|
|
|
singleResult.put("name", entry.getKey()); |
|
|
|
singleResult.put("value", entry.getValue().toString()); |
|
|
|
list.add(singleResult); |
|
|
|
System.out.println(entry.getKey() + " 的 total_flow 总和为: " + entry.getValue()); |
|
|
|
} |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
return new ArrayList(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|