|
@ -1,14 +1,57 @@ |
|
|
package com.zc.business.service.impl; |
|
|
package com.zc.business.service.impl; |
|
|
|
|
|
|
|
|
import com.zc.business.domain.DcStatisticsData; |
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
|
import com.zc.business.domain.*; |
|
|
|
|
|
import com.zc.business.service.IDcFacilityService; |
|
|
|
|
|
import com.zc.business.service.IDcRoadSectionService; |
|
|
import com.zc.business.service.IDcTrafficStatisticsService; |
|
|
import com.zc.business.service.IDcTrafficStatisticsService; |
|
|
|
|
|
import com.zc.business.utils.StakeMarkUtils; |
|
|
|
|
|
import com.zc.common.core.httpclient.OkHttp; |
|
|
|
|
|
import com.zc.common.core.httpclient.exception.HttpException; |
|
|
|
|
|
import com.zc.common.core.httpclient.request.RequestParams; |
|
|
|
|
|
import okhttp3.Call; |
|
|
|
|
|
import okhttp3.Callback; |
|
|
|
|
|
import okhttp3.Response; |
|
|
|
|
|
import okhttp3.ResponseBody; |
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
import org.springframework.stereotype.Service; |
|
|
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.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsService { |
|
|
public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsService { |
|
|
|
|
|
|
|
|
|
|
|
// 智慧高速平台token
|
|
|
|
|
|
private JSONObject token = null; |
|
|
|
|
|
private final String sysid = "sdgs_it_hs_jihe"; |
|
|
|
|
|
|
|
|
|
|
|
private String baseUrl = "http://10.166.139.16:8080"; |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
private IDcFacilityService facilityService; |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
private IDcRoadSectionService roadSectionService; |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
private IDcRoadSectionService dcRoadSectionService; |
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
|
|
public void init() { |
|
|
|
|
|
refreshAccessToken(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 根据传入的统计请求数据,查询历史累计车流量数据。 |
|
|
* 根据传入的统计请求数据,查询历史累计车流量数据。 |
|
|
* |
|
|
* |
|
@ -20,4 +63,451 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
// TODO
|
|
|
// TODO
|
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 定时刷新访问令牌的函数。 |
|
|
|
|
|
* 该方法使用Cron表达式定时执行,即每5小时执行一次。 |
|
|
|
|
|
* 无参数和返回值。 |
|
|
|
|
|
* 主要步骤包括: |
|
|
|
|
|
* 1. 构建OkHttp客户端。 |
|
|
|
|
|
* 2. 使用POST方法向指定URL发送请求,以获取新的访问令牌。 |
|
|
|
|
|
* 3. 在请求成功时,解析响应体中的令牌信息并更新本地存储的令牌。 |
|
|
|
|
|
*/ |
|
|
|
|
|
@Scheduled(cron = "0 0 */5 * * ?") |
|
|
|
|
|
public void refreshAccessToken() { |
|
|
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
try { |
|
|
|
|
|
// 构建请求并设置URL,携带appId和clientSecret进行身份验证
|
|
|
|
|
|
okHttp.url(baseUrl + "/auth/client/token?appId=sdgs_it_hs_jihe&clientSecret=sdgs_it_hs_jihe") |
|
|
|
|
|
.post(new Callback() { |
|
|
|
|
|
// 请求失败时的回调处理,此处未实现具体逻辑
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onFailure(Call call, IOException e) {} |
|
|
|
|
|
|
|
|
|
|
|
// 请求成功时的回调处理
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onResponse(Call call, Response response) { |
|
|
|
|
|
try { |
|
|
|
|
|
// 判断响应体是否非空,非空则解析令牌信息
|
|
|
|
|
|
if (response.body() != null) { |
|
|
|
|
|
token = JSON.parseObject(response.body().string()); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
// 解析异常转为运行时异常抛出
|
|
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} catch (HttpException e) { |
|
|
|
|
|
// 处理HTTP请求异常,转为运行时异常抛出
|
|
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取访问令牌。 |
|
|
|
|
|
* <p> |
|
|
|
|
|
* 这个方法会尝试从存储的token中提取访问令牌。如果token存在,会组合token类型和访问令牌返回。 |
|
|
|
|
|
* 如果token不存在,方法将返回null。 |
|
|
|
|
|
* |
|
|
|
|
|
* @return 如果存在有效的token,则返回构建的访问令牌字符串(包括token类型和访问令牌)。如果不存在有效的token,则返回null。 |
|
|
|
|
|
*/ |
|
|
|
|
|
public String getAccessToken() { |
|
|
|
|
|
// 检查token是否存在
|
|
|
|
|
|
if (token != null) { |
|
|
|
|
|
// 组合并返回token类型和访问令牌
|
|
|
|
|
|
return token.getString("token_type") + " " + token.getString("access_token"); |
|
|
|
|
|
} |
|
|
|
|
|
// 如果token不存在,返回null
|
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取在途车辆流量(分车型) |
|
|
|
|
|
*/ |
|
|
|
|
|
@Override |
|
|
|
|
|
public JSONArray vehiclesInTransit() throws HttpException, IOException { |
|
|
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
|
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
|
|
|
|
|
|
|
|
requestParams.put("sysid", sysid); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
|
|
headers.put("Authorization", getAccessToken()); |
|
|
|
|
|
|
|
|
|
|
|
Response response // 请求响应
|
|
|
|
|
|
= okHttp |
|
|
|
|
|
.headers(headers) |
|
|
|
|
|
.url(baseUrl + "/api/dc/query/rd_jihe_d_vehtypeonwayflow") // 请求地址
|
|
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
|
|
.post(); // 请求方法
|
|
|
|
|
|
|
|
|
|
|
|
ResponseBody body = response.body(); |
|
|
|
|
|
if (body != null) { |
|
|
|
|
|
return JSON.parseArray(body.string()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new JSONArray(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 在途车路段门架平均车速 |
|
|
|
|
|
*/ |
|
|
|
|
|
@Override |
|
|
|
|
|
public JSONArray currentAverageSpeed() throws IOException, HttpException { |
|
|
|
|
|
|
|
|
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
|
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
|
|
|
|
|
|
|
|
requestParams.put("sysid", sysid); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
|
|
headers.put("Authorization", getAccessToken()); |
|
|
|
|
|
|
|
|
|
|
|
Response response // 请求响应
|
|
|
|
|
|
= okHttp |
|
|
|
|
|
.headers(headers) |
|
|
|
|
|
.url(baseUrl + "/api/dc/query/rd_jihe_d_ganonwayavgspeed") // 请求地址
|
|
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
|
|
.post(); // 请求方法
|
|
|
|
|
|
|
|
|
|
|
|
ResponseBody body = response.body(); |
|
|
|
|
|
|
|
|
|
|
|
JSONArray jsonArray = null; |
|
|
|
|
|
|
|
|
|
|
|
if (body != null) { |
|
|
|
|
|
jsonArray = JSON.parseArray(body.string()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Integer> map = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
if (jsonArray != null) { |
|
|
|
|
|
jsonArray.forEach(jsonObject -> { |
|
|
|
|
|
if (jsonObject instanceof JSONObject) { |
|
|
|
|
|
String gantryId = ((JSONObject) jsonObject).getString("gantry_id"); |
|
|
|
|
|
map.put(gantryId, ((JSONObject) jsonObject).getInteger("avg_speed")); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (map.isEmpty()) { |
|
|
|
|
|
return new JSONArray(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<DcFacility> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
|
|
|
|
|
|
|
queryWrapper.in(DcFacility::getFacilityCode, map.keySet()); |
|
|
|
|
|
|
|
|
|
|
|
List<DcFacility> facilities = facilityService.list(queryWrapper); |
|
|
|
|
|
|
|
|
|
|
|
if (facilities == null || facilities.isEmpty()) { |
|
|
|
|
|
return new JSONArray(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<DcRoadSection> roadSections = roadSectionService.selectDcRoadSectionListAll(null); |
|
|
|
|
|
|
|
|
|
|
|
JSONArray jsonArray1 = new JSONArray(); |
|
|
|
|
|
|
|
|
|
|
|
roadSections.forEach(item -> { |
|
|
|
|
|
Integer startStakeMark = StakeMarkUtils.stakeMarkToInt(item.getStartStakeMark()); |
|
|
|
|
|
Integer endStakeMark = StakeMarkUtils.stakeMarkToInt(item.getEndStakeMark()); |
|
|
|
|
|
|
|
|
|
|
|
for (DcFacility facility : facilities) { |
|
|
|
|
|
Integer stakeMark = StakeMarkUtils.stakeMarkToInt(facility.getStakeMark()); |
|
|
|
|
|
|
|
|
|
|
|
if (stakeMark >= startStakeMark && stakeMark <= endStakeMark) { |
|
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
|
|
jsonObject.put("sectionId", item.getId()); |
|
|
|
|
|
jsonObject.put("sectionName", item.getSectionName()); |
|
|
|
|
|
jsonObject.put("avgSpeed", map.get(facility.getFacilityCode())); |
|
|
|
|
|
jsonObject.put("facilityCode", facility.getFacilityCode()); |
|
|
|
|
|
jsonArray1.add(jsonObject); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return jsonArray1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取当前拥堵事件信息 |
|
|
|
|
|
*/ |
|
|
|
|
|
@Override |
|
|
|
|
|
public JSONArray currentEventCongested() throws IOException, HttpException { |
|
|
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
|
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
|
|
|
|
|
|
|
|
requestParams.put("sysid", sysid); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
|
|
headers.put("Authorization", getAccessToken()); |
|
|
|
|
|
|
|
|
|
|
|
Response response // 请求响应
|
|
|
|
|
|
= okHttp |
|
|
|
|
|
.headers(headers) |
|
|
|
|
|
.url(baseUrl + "/api/dc/query/rd_tr_congestion_jh") // 请求地址
|
|
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
|
|
.post(); // 请求方法
|
|
|
|
|
|
|
|
|
|
|
|
ResponseBody body = response.body(); |
|
|
|
|
|
if (body != null) { |
|
|
|
|
|
return JSON.parseArray(body.string()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new JSONArray(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取当前路段拥堵情况。 |
|
|
|
|
|
* 该方法首先调用currentEventCongested()获取当前所有拥堵事件的信息,然后根据这些信息和道路路段的信息, |
|
|
|
|
|
* 统计出每个路段的上行和下行的拥堵情况。 |
|
|
|
|
|
* |
|
|
|
|
|
* @return List<DcRoadSectionCongestion> 当前路段拥堵情况列表 |
|
|
|
|
|
* @throws HttpException 抛出HttpException异常,当HTTP请求发生错误时。 |
|
|
|
|
|
* @throws IOException 抛出IOException异常,当发生输入/输出错误时。 |
|
|
|
|
|
*/ |
|
|
|
|
|
@Override |
|
|
|
|
|
public List<DcRoadSectionCongestion> currentSectionCongested() throws HttpException, IOException { |
|
|
|
|
|
|
|
|
|
|
|
// 调用方法获取当前拥堵事件信息
|
|
|
|
|
|
JSONArray currentEventCongested = currentEventCongested(); |
|
|
|
|
|
|
|
|
|
|
|
// 如果没有拥堵事件,则直接返回空列表
|
|
|
|
|
|
if (currentEventCongested == null || currentEventCongested.isEmpty()) { |
|
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 初始化用于存储结果的列表
|
|
|
|
|
|
List<DcRoadSectionCongestion> list = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
// 获取所有道路路段信息
|
|
|
|
|
|
List<DcRoadSection> dcRoadSections = dcRoadSectionService.selectDcRoadSectionListAll(null); |
|
|
|
|
|
|
|
|
|
|
|
// 遍历每个道路路段,分别计算上行和下行的拥堵情况
|
|
|
|
|
|
dcRoadSections.forEach(dcRoadSection -> { |
|
|
|
|
|
|
|
|
|
|
|
// 初始化拥堵信息
|
|
|
|
|
|
DcRoadSectionCongestion dcRoadSectionCongestion = new DcRoadSectionCongestion(); |
|
|
|
|
|
|
|
|
|
|
|
BeanUtil.copyProperties(dcRoadSection, dcRoadSectionCongestion); |
|
|
|
|
|
dcRoadSectionCongestion.setUpCongestionSections(new ArrayList<>()); |
|
|
|
|
|
dcRoadSectionCongestion.setDownCongestionSections(new ArrayList<>()); |
|
|
|
|
|
|
|
|
|
|
|
// 遍历当前拥堵事件,计算每个路段的拥堵情况
|
|
|
|
|
|
for (Object object :currentEventCongested) { |
|
|
|
|
|
if (object instanceof JSONObject) { |
|
|
|
|
|
JSONObject jsonObject = (JSONObject) object; |
|
|
|
|
|
calculateSectionCongestion(jsonObject, dcRoadSectionCongestion); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
list.add(dcRoadSectionCongestion); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return list; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 根据给定的JSON对象计算路段的拥堵情况。 |
|
|
|
|
|
* |
|
|
|
|
|
* @param jsonObject 包含拥堵信息的JSON对象,包括拥堵开始桩号、结束桩号和拥堵距离。 |
|
|
|
|
|
* @param dcRoadSectionCongestion 包含路段基本信息和拥堵情况的对象,需要根据计算结果更新拥堵信息。 |
|
|
|
|
|
*/ |
|
|
|
|
|
private void calculateSectionCongestion(JSONObject jsonObject, DcRoadSectionCongestion dcRoadSectionCongestion){ |
|
|
|
|
|
|
|
|
|
|
|
// 根据方向,计算对应方向的路段拥堵情况
|
|
|
|
|
|
String dirCode = jsonObject.getString("dir_code"); |
|
|
|
|
|
|
|
|
|
|
|
List<DcCongestionSection> congestionSections; |
|
|
|
|
|
|
|
|
|
|
|
if (dirCode.equals("UP")) { |
|
|
|
|
|
congestionSections = dcRoadSectionCongestion.getUpCongestionSections(); |
|
|
|
|
|
} else { |
|
|
|
|
|
congestionSections = dcRoadSectionCongestion.getDownCongestionSections(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 拥堵开始桩号
|
|
|
|
|
|
double startPileNo = jsonObject.getDouble("start_pile_no") * 1000; |
|
|
|
|
|
// 拥堵结束桩号
|
|
|
|
|
|
double endPileNo = jsonObject.getDouble("end_pile_no") * 1000; |
|
|
|
|
|
|
|
|
|
|
|
// 拥堵距离
|
|
|
|
|
|
int jamDist = jsonObject.getInteger("jam_dist"); |
|
|
|
|
|
|
|
|
|
|
|
// 如果拥堵开始桩号大于拥堵结束桩号,则交换它们的值
|
|
|
|
|
|
if (startPileNo > endPileNo) { |
|
|
|
|
|
endPileNo = startPileNo - jamDist; |
|
|
|
|
|
double tempStartPileNo = startPileNo; |
|
|
|
|
|
startPileNo = endPileNo; |
|
|
|
|
|
endPileNo = tempStartPileNo; |
|
|
|
|
|
} else { |
|
|
|
|
|
endPileNo = startPileNo + jamDist; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 路段开始桩号
|
|
|
|
|
|
int startStakeMark = StakeMarkUtils.stakeMarkToInt(dcRoadSectionCongestion.getStartStakeMark()); |
|
|
|
|
|
// 路段结束桩号
|
|
|
|
|
|
int endStakeMark = StakeMarkUtils.stakeMarkToInt(dcRoadSectionCongestion.getEndStakeMark()); |
|
|
|
|
|
|
|
|
|
|
|
DcCongestionSection congestionSection = new DcCongestionSection(); |
|
|
|
|
|
|
|
|
|
|
|
// 拥堵状态
|
|
|
|
|
|
int pubRunStatus = jsonObject.getInteger("pub_run_status"); |
|
|
|
|
|
|
|
|
|
|
|
// 拥堵状态
|
|
|
|
|
|
congestionSection.setCongestionStatus(pubRunStatus); |
|
|
|
|
|
|
|
|
|
|
|
// -|-------startPileNo-----------------endPileNo------------|-
|
|
|
|
|
|
// 路段包含拥堵
|
|
|
|
|
|
if (startStakeMark <= startPileNo && endPileNo <= endStakeMark) { |
|
|
|
|
|
congestionSection.setCongestionStartStakeMark((int) startPileNo); |
|
|
|
|
|
congestionSection.setCongestionEndStakeMark((int) endPileNo); |
|
|
|
|
|
congestionSection.setCongestionDistance(jamDist); |
|
|
|
|
|
congestionSections.add(congestionSection); |
|
|
|
|
|
|
|
|
|
|
|
if (pubRunStatus > dcRoadSectionCongestion.getCongestionStatus()) { |
|
|
|
|
|
dcRoadSectionCongestion.setCongestionStatus(pubRunStatus); |
|
|
|
|
|
} |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// --startPileNo---|--------------------------|---endPileNo---
|
|
|
|
|
|
// 拥堵包含路段
|
|
|
|
|
|
if (startPileNo <= startStakeMark && endPileNo >= endStakeMark) { |
|
|
|
|
|
congestionSection.setCongestionStartStakeMark(startStakeMark); |
|
|
|
|
|
congestionSection.setCongestionEndStakeMark(endStakeMark); |
|
|
|
|
|
congestionSection.setCongestionDistance(endStakeMark - startStakeMark); |
|
|
|
|
|
congestionSections.add(congestionSection); |
|
|
|
|
|
|
|
|
|
|
|
if (pubRunStatus > dcRoadSectionCongestion.getCongestionStatus()) { |
|
|
|
|
|
dcRoadSectionCongestion.setCongestionStatus(pubRunStatus); |
|
|
|
|
|
} |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// -|-----------------startPileNo-------------------|---endPileNo---
|
|
|
|
|
|
// 路段包含开始拥堵桩号不包含结束拥堵桩号
|
|
|
|
|
|
if (startPileNo >= startStakeMark && startPileNo <= endStakeMark && endPileNo >= endStakeMark) { |
|
|
|
|
|
congestionSection.setCongestionStartStakeMark((int) startPileNo); |
|
|
|
|
|
congestionSection.setCongestionEndStakeMark(endStakeMark); |
|
|
|
|
|
congestionSection.setCongestionDistance((int) (endStakeMark - startPileNo)); |
|
|
|
|
|
congestionSections.add(congestionSection); |
|
|
|
|
|
|
|
|
|
|
|
if (pubRunStatus > dcRoadSectionCongestion.getCongestionStatus()) { |
|
|
|
|
|
dcRoadSectionCongestion.setCongestionStatus(pubRunStatus); |
|
|
|
|
|
} |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ---startPileNo---|-----------------endPileNo-------------------|-
|
|
|
|
|
|
// 路段包含结束拥堵桩号不包含开始拥堵桩号
|
|
|
|
|
|
if (endPileNo >= startStakeMark && endPileNo <= endStakeMark && startPileNo <= startStakeMark) { |
|
|
|
|
|
congestionSection.setCongestionStartStakeMark(startStakeMark); |
|
|
|
|
|
congestionSection.setCongestionEndStakeMark((int)endPileNo); |
|
|
|
|
|
congestionSection.setCongestionDistance((endStakeMark - startStakeMark)); |
|
|
|
|
|
congestionSections.add(congestionSection); |
|
|
|
|
|
|
|
|
|
|
|
if (pubRunStatus > dcRoadSectionCongestion.getCongestionStatus()) { |
|
|
|
|
|
dcRoadSectionCongestion.setCongestionStatus(pubRunStatus); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* private void calculateSectionCongestion(JSONObject jsonObject, DcRoadSectionCongestion dcRoadSectionCongestion){ |
|
|
|
|
|
|
|
|
|
|
|
// 根据方向,计算对应方向的路段拥堵情况
|
|
|
|
|
|
String dirCode = jsonObject.getString("dir_code"); |
|
|
|
|
|
|
|
|
|
|
|
List<DcCongestionSection> congestionSections; |
|
|
|
|
|
|
|
|
|
|
|
if (dirCode.equals("UP")) { |
|
|
|
|
|
congestionSections = dcRoadSectionCongestion.getUpCongestionSections(); |
|
|
|
|
|
} else { |
|
|
|
|
|
congestionSections = dcRoadSectionCongestion.getDownCongestionSections(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 拥堵开始桩号
|
|
|
|
|
|
double startPileNo = jsonObject.getDouble("start_pile_no") * 1000; |
|
|
|
|
|
// 拥堵结束桩号
|
|
|
|
|
|
double endPileNo = jsonObject.getDouble("end_pile_no") * 1000; |
|
|
|
|
|
|
|
|
|
|
|
// 拥堵距离
|
|
|
|
|
|
int jamDist = jsonObject.getInteger("jam_dist"); |
|
|
|
|
|
|
|
|
|
|
|
// 路段开始桩号
|
|
|
|
|
|
int startStakeMark = StakeMarkUtils.stakeMarkToInt(dcRoadSectionCongestion.getStartStakeMark()); |
|
|
|
|
|
// 路段结束桩号
|
|
|
|
|
|
int endStakeMark = StakeMarkUtils.stakeMarkToInt(dcRoadSectionCongestion.getEndStakeMark()); |
|
|
|
|
|
|
|
|
|
|
|
DcCongestionSection congestionSection = new DcCongestionSection(); |
|
|
|
|
|
|
|
|
|
|
|
// 拥堵状态
|
|
|
|
|
|
int pubRunStatus = jsonObject.getInteger("pub_run_status"); |
|
|
|
|
|
|
|
|
|
|
|
// 拥堵状态
|
|
|
|
|
|
congestionSection.setCongestionStatus(pubRunStatus); |
|
|
|
|
|
|
|
|
|
|
|
// 路段包含拥堵
|
|
|
|
|
|
if (startStakeMark <= startPileNo && startPileNo <= endStakeMark) { |
|
|
|
|
|
congestionSection.setCongestionStartStakeMark((int) startPileNo); |
|
|
|
|
|
congestionSection.setCongestionEndStakeMark((int) endPileNo); |
|
|
|
|
|
congestionSection.setCongestionDistance(jamDist); |
|
|
|
|
|
congestionSections.add(congestionSection); |
|
|
|
|
|
|
|
|
|
|
|
if (pubRunStatus > dcRoadSectionCongestion.getCongestionStatus()) { |
|
|
|
|
|
dcRoadSectionCongestion.setCongestionStatus(pubRunStatus); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取车道占有率信息 |
|
|
|
|
|
*/ |
|
|
|
|
|
@Override |
|
|
|
|
|
public JSONArray laneOccupancy(String startDate, String endDate) throws HttpException, IOException { |
|
|
|
|
|
OkHttp okHttp = new OkHttp(10); |
|
|
|
|
|
|
|
|
|
|
|
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_gantryoccupationbyhour") // 请求地址
|
|
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
|
|
.post(); // 请求方法
|
|
|
|
|
|
|
|
|
|
|
|
ResponseBody body = response.body(); |
|
|
|
|
|
if (body != null) { |
|
|
|
|
|
return JSON.parseArray(body.string()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new JSONArray(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|