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. 77
      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;
}

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

@ -700,7 +700,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
}
@Override
public Map<String,List<Map<String, Object>>> realTimeTrafficFlowHour() throws HttpException, IOException {
public Map<String, List<Map<String, Object>>> realTimeTrafficFlowHour() throws HttpException, IOException {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(UniversalEnum.TIME_FORMAT_YEARS_MONTH_DAY.getValue());
LocalDate currentDate = LocalDate.now();
@ -717,24 +717,25 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
JSONArray body = getResponseBody(nowYear, requestParams, okHttp);
JSONArray bodylast = getResponseBody(lastYear, requestParams, okHttp);
Map<String,List<Map<String, Object>>> map = new HashMap<>();
Map<String, List<Map<String, Object>>> map = new HashMap<>();
if (body != null) {
List<Map<String, Object>> mapList = getMaps(UniversalEnum.ONE.getValue(), body);
map.put(UniversalEnum.ONE.getValue(),mapList);
map.put(UniversalEnum.ONE.getValue(), mapList);
List<Map<String, Object>> mapList2 = getMaps(UniversalEnum.THREE.getValue(), body);
map.put(UniversalEnum.TWO.getValue(),mapList2);
map.put(UniversalEnum.TWO.getValue(), mapList2);
}
if (bodylast != null) {
List<Map<String, Object>> mapList = getMaps(UniversalEnum.ONE.getValue(), bodylast);
map.put(UniversalEnum.THREE.getValue(),mapList);
map.put(UniversalEnum.THREE.getValue(), mapList);
List<Map<String, Object>> mapList2 = getMaps(UniversalEnum.THREE.getValue(), bodylast);
map.put(UniversalEnum.FOUR.getValue(),mapList2);
map.put(UniversalEnum.FOUR.getValue(), mapList2);
}
return map;
}
//处理 接口响应数据
//处理 接口响应数据
private List<Map<String, Object>> getMaps(String direction, JSONArray jsonArray) throws IOException {
@ -792,7 +793,8 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
}
return mapList;
}
// 获取车流量接口 返回 jsonArray
// 获取车流量接口 返回 jsonArray
private JSONArray getResponseBody(String startDate, RequestParams requestParams, OkHttp okHttp) throws HttpException, IOException {
JSONObject parameters = new JSONObject() {
{
@ -815,7 +817,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
return jsonArray;
}
//格式化桩号
//格式化桩号
private static String extract(String input) {
Pattern pattern = Pattern.compile("K(\\d{3})\\+(\\d{3})");
Matcher matcher = pattern.matcher(input);
@ -839,17 +841,17 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
return UniversalEnum.EMPTY_STRING.getValue();
}
public List<Map<String,Object>> queryTheGantryDataByPileNumber(String startDate,String stakeMark) throws HttpException, IOException {
public List<Map<String, Object>> queryTheGantryDataByPileNumber(String startDate, String stakeMark) throws HttpException, IOException {
if (stakeMark != null) {
//处理URl地址栏获取参数+号消失
stakeMark= stakeMark.replace(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.PLUS_SIGN.getValue());
stakeMark = stakeMark.replace(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.PLUS_SIGN.getValue());
}
List<Map<String,Object>> mapList =new ArrayList<>();
List<Map<String, Object>> mapList = new ArrayList<>();
DcFacility dcFacilityAll = new DcFacility();
dcFacilityAll.setFacilityType(UniversalEnum.TEN.getNumber());
List<DcFacility> dcFacilityList = facilityService.listFacility(dcFacilityAll);
DcFacility nearestFacility = findNearestFacility(dcFacilityList,stakeMark);
DcFacility nearestFacility = findNearestFacility(dcFacilityList, stakeMark);
OkHttp okHttp = new OkHttp();
@ -886,8 +888,8 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
Map<String, Object> map = new HashMap<>();
int totalFlow = jsonObject.getInteger("total_flow");
int data_hour = jsonObject.getInteger("data_hour");
map.put("hour",data_hour);
map.put("totalFlow",totalFlow);
map.put("hour", data_hour);
map.put("totalFlow", totalFlow);
mapList.add(map);
}
}
@ -902,12 +904,13 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
/**
* 获取路况信息
*
* @return
* @throws HttpException
* @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 +930,19 @@ 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");
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");
JSONArray jsonlist = JSON.parseArray(string);
@ -942,11 +954,11 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
String[] lngLatsString = lngLats.split(";");
double s = Double.parseDouble(lngLatsString[0].split(",")[0]);
double s2 = Double.parseDouble(lngLatsString[0].split(",")[1]);
double s3 = Double.parseDouble(lngLatsString[lngLatsString.length-1].split(",")[0]);
double s4 = Double.parseDouble(lngLatsString[lngLatsString.length-1].split(",")[1]);
double distanceM = calculateDistance(s2, s, s4, s3)* 1000;
double s3 = Double.parseDouble(lngLatsString[lngLatsString.length - 1].split(",")[0]);
double s4 = Double.parseDouble(lngLatsString[lngLatsString.length - 1].split(",")[1]);
double distanceM = calculateDistance(s2, s, s4, s3) * 1000;
// System.out.printf("最大距离为: %.2f 米%n", distanceM);
jsonObject.put("max_jam_dist",distanceM);//最大拥堵距离
jsonObject.put("max_jam_dist", distanceM);//最大拥堵距离
String[] split = string1.split(",");
double firstLon = Double.parseDouble(split[0]);
double firstLat = Double.parseDouble(split[1]);
@ -960,16 +972,16 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
double distanceKm = calculateDistance(firstLat, firstLon, lastLat, lastLon);
double distanceMeters = distanceKm * 1000; // 将距离转换为米
//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; // 返回最近的桩号信息
}
//桩号转换
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) {
@ -1019,6 +1042,8 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
// 计算两点间的距离
double distance = EARTH_RADIUS * c;
// 保留两位小数,四舍五入
distance = Double.parseDouble(String.format("%.5f", distance));
return distance;
}

Loading…
Cancel
Save