Browse Source

Merge remote-tracking branch 'origin/develop' into develop

develop
wangsixiang 8 months ago
parent
commit
2de96bef80
  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. 37
      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") @GetMapping("/current/getTheCurrentCongestedSection")
public AjaxResult getTheCurrentCongestedSection() throws HttpException, IOException { public AjaxResult getTheCurrentCongestedSection() throws HttpException, IOException {
// 调用服务层方法,获取当前交通指标数据 // 调用服务层方法,获取当前交通指标数据
JSONObject jsonArray = dcTrafficStatisticsService.getTheCurrentCongestedSection(); JSONArray jsonArray = dcTrafficStatisticsService.getTheCurrentCongestedSection();
// 将获取到的交通指标数据封装为成功的结果并返回 // 将获取到的交通指标数据封装为成功的结果并返回
return AjaxResult.success(jsonArray); 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; Map<String,List<Map<String, Object>>> realTimeTrafficFlowHour() throws HttpException, IOException;
List<Map<String,Object>> queryTheGantryDataByPileNumber(String startDate,String stakeMark) 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;
} }

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

@ -734,6 +734,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
return map; return map;
} }
//处理 接口响应数据 //处理 接口响应数据
private List<Map<String, Object>> getMaps(String direction, JSONArray jsonArray) throws IOException { private List<Map<String, Object>> getMaps(String direction, JSONArray jsonArray) throws IOException {
@ -792,6 +793,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
} }
return mapList; return mapList;
} }
// 获取车流量接口 返回 jsonArray // 获取车流量接口 返回 jsonArray
private JSONArray getResponseBody(String startDate, RequestParams requestParams, OkHttp okHttp) throws HttpException, IOException { private JSONArray getResponseBody(String startDate, RequestParams requestParams, OkHttp okHttp) throws HttpException, IOException {
JSONObject parameters = new JSONObject() { JSONObject parameters = new JSONObject() {
@ -902,12 +904,13 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
/** /**
* 获取路况信息 * 获取路况信息
*
* @return * @return
* @throws HttpException * @throws HttpException
* @throws IOException * @throws IOException
*/ */
@Override @Override
public JSONObject getTheCurrentCongestedSection() throws HttpException, IOException { public JSONArray getTheCurrentCongestedSection() throws HttpException, IOException {
OkHttp okHttp = new OkHttp(); OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams(); RequestParams requestParams = new RequestParams();
@ -927,10 +930,19 @@ 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()); 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"); Integer asOneRoad = jsonObject.getInteger("as_one_road");
double endPileNo = jsonObject.getDouble("end_pile_no");
double startPileNo = jsonObject.getDouble("start_pile_no");
String stakeMark = formatNumber(startPileNo);
String endMark = formatNumber(endPileNo);
jsonObject.put("stakeMark", stakeMark);//当前拥堵距离
jsonObject.put("endMark", endMark);//当前拥堵距离
if (asOneRoad == UniversalEnum.ONE.getNumber()){ //as_one_road
//是否为同一条路,1-是,0-否
if (asOneRoad == UniversalEnum.ZERO.getNumber()) {
String string = jsonObject.getString("list_link_info"); String string = jsonObject.getString("list_link_info");
JSONArray jsonlist = JSON.parseArray(string); JSONArray jsonlist = JSON.parseArray(string);
@ -962,14 +974,14 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
//System.out.printf("两点之间的距离为: %.2f 米%n", distanceMeters); //System.out.printf("两点之间的距离为: %.2f 米%n", distanceMeters);
jsonObject.put("jam_dist", distanceMeters);//当前拥堵距离 jsonObject.put("jam_dist", distanceMeters);//当前拥堵距离
return jsonObject; }
}else {
} }
return jsonArray;
} }
return new JSONObject(); return new JSONArray();
} }
@ -997,6 +1009,17 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
return nearestFacility; // 返回最近的桩号信息 return nearestFacility; // 返回最近的桩号信息
} }
//桩号转换
public static String formatNumber(double number) {
//将数字分成整数和四舍五入的小数部分
int integerPart = (int) number;
int decimalPart = (int) Math.round((number - integerPart) * 1000); // 四舍五入到最接近的整数
// 将数字格式化为 "K 000+000"
String formattedString = String.format("K%03d+%03d", integerPart, decimalPart);
return formattedString;
}
//经纬度计算距离 //经纬度计算距离
public static double calculateDistance(double startLat, double startLon, double endLat, double endLon) { public static double calculateDistance(double startLat, double startLon, double endLat, double endLon) {
@ -1019,6 +1042,8 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
// 计算两点间的距离 // 计算两点间的距离
double distance = EARTH_RADIUS * c; double distance = EARTH_RADIUS * c;
// 保留两位小数,四舍五入
distance = Double.parseDouble(String.format("%.5f", distance));
return distance; return distance;
} }

Loading…
Cancel
Save