Browse Source

收费站日累计车流辆

develop
王兴琳 5 months ago
parent
commit
655b29c16a
  1. 11
      zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java
  2. 6
      zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java
  3. 70
      zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java

11
zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java

@ -803,6 +803,17 @@ public AjaxResult trafficFlowAtTollStationEntranceHour(String startDate, String
// 将获取到的交通指标数据封装为成功的结果并返回
return AjaxResult.success(jsonArray);
}
/**
* 各收费站入口分车型车流量
*/
@ApiOperation("收费站日累计车流辆")
@GetMapping("/history/trafficFlowAtToll")
public AjaxResult trafficFlowAtToll() throws HttpException, IOException {
// 调用服务层方法,获取当前交通指标数据
int a = dcTrafficStatisticsService.trafficFlowAtToll();
// 将获取到的交通指标数据封装为成功的结果并返回
return AjaxResult.success(a);
}
/**
* 导出收费站出入口实时车流量

6
zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java

@ -58,4 +58,10 @@ public interface IDcTrafficStatisticsService {
JSONArray getTheCurrentCongestedSection()throws HttpException, IOException;
/**
* 各收费站日累计车流辆
* @return
*/
int trafficFlowAtToll()throws HttpException, IOException;
}

70
zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java

@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.sun.xml.bind.v2.TODO;
import com.zc.business.constant.RedisKeyConstants;
import com.zc.business.domain.*;
import com.zc.business.enums.StakeMarkRange;
@ -683,9 +684,13 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
if (body != null) {
JSONArray jsonArray = JSON.parseArray(body.string());
Map<String, Integer> sumByName = new LinkedHashMap<>();
Integer totalFlow1=0;
List<Map<String, String>> list = new ArrayList();
for (Object item : jsonArray) { // 这里做了微调,直接遍历jsonArray的Object
JSONObject jsonObject = (JSONObject) item;
totalFlow1=totalFlow1+ jsonObject.getInteger("total_flow");
// 获取当前时间
LocalTime now = LocalTime.now();
// 获取当前小时数(24小时制)
@ -693,10 +698,11 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
if (jsonObject.getInteger("data_hour") == currentHour) {
String name = jsonObject.getString("ts_name"); // 更安全的取值方式
int totalFlow = jsonObject.getInteger("total_flow"); // 专门针对Integer类型
sumByName.put(name, totalFlow);
}
}
System.out.println("总数===:"+totalFlow1);
// 正确创建新的映射对象并添加到list中
for (Map.Entry<String, Integer> entry : sumByName.entrySet()) {
Map<String, String> singleResult = new LinkedHashMap<>(); // 每次循环都创建一个新的映射
@ -1036,6 +1042,68 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
return new JSONArray();
}
/**
* 各收费站日累计车流辆
* @return
*/
@Override
public int trafficFlowAtToll()throws HttpException, IOException {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(UniversalEnum.TIME_FORMAT_YEARS_MONTH_DAY.getValue());
LocalDate currentDate = LocalDate.now();
String startDate = currentDate.format(formatter);
Response response = getResponseTrafficFlowAtToll(startDate,UniversalEnum.ONE.getValue());
Response responseTwo = getResponseTrafficFlowAtToll(startDate,UniversalEnum.TWO.getValue());
ResponseBody body = response.body();
ResponseBody bodyTwo = responseTwo.body();
Integer totalFlow1=UniversalEnum.ZERO.getNumber();
Integer totalFlow2=UniversalEnum.ZERO.getNumber();
if (body != null) {
JSONArray jsonArray = JSON.parseArray(body.string());
for (Object item : jsonArray) {
JSONObject jsonObject = (JSONObject) item;
totalFlow1=totalFlow1+ jsonObject.getInteger("total_flow");
}
}
if (bodyTwo != null) {
JSONArray jsonArray = JSON.parseArray(bodyTwo.string());
for (Object item : jsonArray) {
JSONObject jsonObject = (JSONObject) item;
totalFlow2=totalFlow2+ jsonObject.getInteger("total_flow");
}
}
return totalFlow1+totalFlow2;
}
private Response getResponseTrafficFlowAtToll(String startDate,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", startDate);
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 + UniversalEnum.EACH_TOLL_STATION_ENTRANCE_BY_TYPE_OF_HOURLY_TRAFFIC_FLOW.getValue()) // 请求地址
.data(requestParams) // 请求参数
.post(); // 请求方法
return response;
}
public DcFacility findNearestFacility(List<DcFacility> dcFacilityList, String stakeMarkCode) {
// 将目标桩号转换为整数

Loading…
Cancel
Save