Browse Source

拥堵路段 距离计算(修改)

develop
王兴琳 8 months ago
parent
commit
184234949f
  1. 2
      zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java
  2. 2
      zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java
  3. 18
      zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java

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

@ -576,7 +576,7 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
@GetMapping("/current/getTheCurrentCongestedSection")
public AjaxResult getTheCurrentCongestedSection() throws HttpException, IOException {
// 调用服务层方法,获取当前交通指标数据
JSONObject jsonArray = dcTrafficStatisticsService.getTheCurrentCongestedSection();
JSONArray jsonArray = dcTrafficStatisticsService.getTheCurrentCongestedSection();
// 将获取到的交通指标数据封装为成功的结果并返回
return AjaxResult.success(jsonArray);
}

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

@ -56,6 +56,6 @@ public interface IDcTrafficStatisticsService {
Map<String,List<Map<String, Object>>> realTimeTrafficFlowHour() throws HttpException, IOException;
List<Map<String,Object>> queryTheGantryDataByPileNumber(String startDate,String stakeMark) throws HttpException, IOException;
JSONObject getTheCurrentCongestedSection()throws HttpException, IOException;
JSONArray getTheCurrentCongestedSection()throws HttpException, IOException;
}

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

@ -907,7 +907,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
* @throws IOException
*/
@Override
public JSONObject getTheCurrentCongestedSection() throws HttpException, IOException {
public JSONArray getTheCurrentCongestedSection() throws HttpException, IOException {
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams();
@ -927,10 +927,12 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
ResponseBody body = response.body();
if (body != null) {
JSONArray jsonArray = JSON.parseArray(body.string());
JSONObject jsonObject = (JSONObject) jsonArray.get(0);
for (Object object : jsonArray) {
JSONObject jsonObject = (JSONObject) object;
Integer asOneRoad = jsonObject.getInteger("as_one_road");
if (asOneRoad == UniversalEnum.ONE.getNumber()){
//as_one_road
//是否为同一条路,1-是,0-否
if (asOneRoad == UniversalEnum.ZERO.getNumber()){
String string = jsonObject.getString("list_link_info");
JSONArray jsonlist = JSON.parseArray(string);
@ -962,14 +964,14 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
//System.out.printf("两点之间的距离为: %.2f 米%n", distanceMeters);
jsonObject.put("jam_dist",distanceMeters);//当前拥堵距离
return jsonObject;
}else {
}
}
return jsonArray;
}
return new JSONObject();
return new JSONArray();
}
@ -1019,6 +1021,8 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
// 计算两点间的距离
double distance = EARTH_RADIUS * c;
// 保留两位小数,四舍五入
distance= Double.parseDouble(String.format("%.5f", distance));
return distance;
}

Loading…
Cancel
Save