Browse Source

交通流首页 全路段车流量分析

develop
王兴琳 3 months ago
parent
commit
8e95f0f5c3
  1. 8
      zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java
  2. 52
      zc-business/src/main/java/com/zc/business/enums/TrafficFlowDoorFrameSection.java
  3. 3
      zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java
  4. 93
      zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java

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

@ -969,6 +969,14 @@ public class DcTrafficStatisticsController extends BaseController {
// 将获取到的交通指标数据封装为成功的结果并返回 // 将获取到的交通指标数据封装为成功的结果并返回
return AjaxResult.success(a); return AjaxResult.success(a);
} }
@ApiOperation("收费站日累计车流辆分车型")
@GetMapping("/history/trafficFlowAtTollTypes")
public AjaxResult trafficFlowAtTollTypes(String startDate) throws HttpException, IOException {
// 调用服务层方法,获取当前交通指标数据
Map<String,Integer> a = dcTrafficStatisticsService.trafficFlowAtTollTypes(startDate);
// 将获取到的交通指标数据封装为成功的结果并返回
return AjaxResult.success(a);
}
@ApiOperation("收费站昨日累计车流辆") @ApiOperation("收费站昨日累计车流辆")
@GetMapping("/history/yesterdayTrafficFlowAtToll") @GetMapping("/history/yesterdayTrafficFlowAtToll")

52
zc-business/src/main/java/com/zc/business/enums/TrafficFlowDoorFrameSection.java

@ -0,0 +1,52 @@
package com.zc.business.enums;
/**
*
*/
public enum TrafficFlowDoorFrameSection {
ONE(57354, 57586, 1,"殷家林枢纽-长清大学城"),
TWO(70796, 70939,2, "长清大学城-长清虚"),
THREE(74902, 74989,3, "长清虚-松竹枢纽"),
FOUR(97470, 97593,4, "孝里虚-平阴北虚"),
FIVE(102782, 102908,5, "平阴北虚-平阴虚"),
SIX(107996, 108102, 6,"平阴虚-孔村枢纽"),
SEVEN(123944, 124074,7, "孔村枢纽-平阴南虚"),
EIGHT(128101, 128204,8, "平阴南虚-魏雪枢纽"),
NINE(147847, 147949, 9,"东平虚-东济济广枢纽"),
WEIXUE_JUNCTION(171803, 171903, 10,"东济济广枢纽-梁山东虚"),
TEN(175649, 175749, 11,"梁山东虚-梁山虚"),
DONGPING_LAKE_HUB(180847,180952,12,"梁山虚-信楼枢纽"),
LIANGSHANDONG_INTERCHANGE(192299,192403,13,"嘉祥西虚-王官屯枢纽");
private final int stakeMark;
private final int endMark;
private final int identification;
private final String description;
public int getStakeMark() {
return stakeMark;
}
public int getEndMark() {
return endMark;
}
public String getDescription() {
return description;
}
public int getIdentification() {
return identification;
}
TrafficFlowDoorFrameSection(int stakeMark, int endMark, int identification, String description) {
this.stakeMark = stakeMark;
this.endMark = endMark;
this.identification = identification;
this.description = description;
}
}

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

@ -71,4 +71,7 @@ public interface IDcTrafficStatisticsService {
* 交通流统计分析重点数据查询交通流异常信息 * 交通流统计分析重点数据查询交通流异常信息
*/ */
JSONArray exampleQueryTrafficFlowAnomalies(String startTime, String endTime) throws HttpException; JSONArray exampleQueryTrafficFlowAnomalies(String startTime, String endTime) throws HttpException;
Map<String,Integer> trafficFlowAtTollTypes(String startDate);
} }

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

@ -12,6 +12,7 @@ import com.zc.business.constant.RedisKeyConstants;
import com.zc.business.domain.*; import com.zc.business.domain.*;
import com.zc.business.enums.LocationEnum; import com.zc.business.enums.LocationEnum;
import com.zc.business.enums.StakeMarkRange; import com.zc.business.enums.StakeMarkRange;
import com.zc.business.enums.TrafficFlowDoorFrameSection;
import com.zc.business.enums.UniversalEnum; import com.zc.business.enums.UniversalEnum;
import com.zc.business.service.IDcDeviceService; import com.zc.business.service.IDcDeviceService;
import com.zc.business.service.IDcFacilityService; import com.zc.business.service.IDcFacilityService;
@ -932,7 +933,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
// 初始化计数器和描述映射 // 初始化计数器和描述映射
Map<Integer, Integer> flowCounts = new HashMap<>(); Map<Integer, Integer> flowCounts = new HashMap<>();
Map<Integer, String> descriptions = new HashMap<>(); Map<Integer, String> descriptions = new HashMap<>();
for (int i = UniversalEnum.ONE.getNumber(); i <= 16; i++) { for (int i = UniversalEnum.ONE.getNumber(); i <= 13; i++) {
flowCounts.put(i, UniversalEnum.ZERO.getNumber()); flowCounts.put(i, UniversalEnum.ZERO.getNumber());
descriptions.put(i, UniversalEnum.EMPTY_STRING.getValue()); descriptions.put(i, UniversalEnum.EMPTY_STRING.getValue());
} }
@ -957,12 +958,12 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
.anyMatch(dcFacility -> dcFacility.getId().equals(dcFacility2.getId())); .anyMatch(dcFacility -> dcFacility.getId().equals(dcFacility2.getId()));
if (exists) { if (exists) {
int extractedNumber = Integer.parseInt(extract(stakeMark)); int extractedNumber = Integer.parseInt(extract(stakeMark));
int identification = Arrays.stream(StakeMarkRange.values()) int identification = Arrays.stream(TrafficFlowDoorFrameSection.values())
.filter(smRange -> extractedNumber >= smRange.getStakeMark() && extractedNumber <= smRange.getEndMark()) .filter(smRange -> extractedNumber >= smRange.getStakeMark() && extractedNumber <= smRange.getEndMark())
.mapToInt(StakeMarkRange::getIdentification) .mapToInt(TrafficFlowDoorFrameSection::getIdentification)
.findFirst() .findFirst()
.orElse(UniversalEnum.ZERO.getNumber()); .orElse(UniversalEnum.ZERO.getNumber());
String description = getDescriptionByIdentification(identification); String description = getTrafficFlowDoorFrameSection(identification);
descriptions.put(identification, description); descriptions.put(identification, description);
flowCounts.put(identification, flowCounts.get(identification) + totalFlow); flowCounts.put(identification, flowCounts.get(identification) + totalFlow);
} }
@ -971,9 +972,9 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
} }
// 构建结果列表 // 构建结果列表
List<Map<String, Object>> mapList = new ArrayList<>(); List<Map<String, Object>> mapList = new ArrayList<>();
for (int i = UniversalEnum.ONE.getNumber(); i <= 16; i++) { for (int i = UniversalEnum.ONE.getNumber(); i <= 13; i++) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("name", getDescriptionByIdentification(i)); map.put("name", getTrafficFlowDoorFrameSection(i));
map.put("totalFlow", flowCounts.get(i)); map.put("totalFlow", flowCounts.get(i));
mapList.add(map); mapList.add(map);
} }
@ -1039,6 +1040,14 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
} }
return UniversalEnum.EMPTY_STRING.getValue(); return UniversalEnum.EMPTY_STRING.getValue();
} }
public static String getTrafficFlowDoorFrameSection(int identification) {
for (TrafficFlowDoorFrameSection range : TrafficFlowDoorFrameSection.values()) {
if (range.getIdentification() == identification) {
return range.getDescription();
}
}
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 {
@ -1474,6 +1483,78 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
} }
} }
@Override
public Map<String, Integer> trafficFlowAtTollTypes(String startDate) {
Map<String, Integer> map = new HashMap<>();
try {
Response response = getResponseTrafficFlowAtToll(startDate, UniversalEnum.ONE.getValue());
Response responseTwo = getResponseTrafficFlowAtToll(startDate, UniversalEnum.TWO.getValue());
ResponseBody body = response.body();
ResponseBody bodyTwo = responseTwo.body();
Integer bus;
Integer truck;
Integer bus1_flow = UniversalEnum.ZERO.getNumber();
Integer bus2_flow = UniversalEnum.ZERO.getNumber();
Integer bus3_flow = UniversalEnum.ZERO.getNumber();
Integer bus4_flow = UniversalEnum.ZERO.getNumber();
Integer truck1_flow = UniversalEnum.ZERO.getNumber();
Integer truck2_flow = UniversalEnum.ZERO.getNumber();
Integer truck3_flow = UniversalEnum.ZERO.getNumber();
Integer truck4_flow = UniversalEnum.ZERO.getNumber();
Integer truck5_flow = UniversalEnum.ZERO.getNumber();
Integer truck6_flow = UniversalEnum.ZERO.getNumber();
if (body != null) {
String jsonString = body.string();
if (JSON.isValidArray(jsonString)) {
JSONArray jsonArray = JSON.parseArray(jsonString);
for (Object item : jsonArray) {
JSONObject jsonObject = (JSONObject) item;
bus1_flow = bus1_flow + jsonObject.getInteger("bus1_flow");
bus2_flow = bus2_flow + jsonObject.getInteger("bus2_flow");
bus3_flow = bus3_flow + jsonObject.getInteger("bus3_flow");
bus4_flow = bus4_flow + jsonObject.getInteger("bus4_flow");
truck1_flow = truck1_flow + jsonObject.getInteger("truck1_flow");
truck2_flow = truck2_flow + jsonObject.getInteger("truck2_flow");
truck3_flow = truck3_flow + jsonObject.getInteger("truck3_flow");
truck4_flow = truck4_flow + jsonObject.getInteger("truck4_flow");
truck5_flow = truck5_flow + jsonObject.getInteger("truck5_flow");
truck6_flow = truck6_flow + jsonObject.getInteger("truck6_flow");
}
}
}
if (bodyTwo != null) {
String jsonString = bodyTwo.string();
if (JSON.isValidArray(jsonString)) {
JSONArray jsonArray = JSON.parseArray(jsonString);
for (Object item : jsonArray) {
JSONObject jsonObject = (JSONObject) item;
bus1_flow = bus1_flow + jsonObject.getInteger("bus1_flow");
bus2_flow = bus2_flow + jsonObject.getInteger("bus2_flow");
bus3_flow = bus3_flow + jsonObject.getInteger("bus3_flow");
bus4_flow = bus4_flow + jsonObject.getInteger("bus4_flow");
truck1_flow = truck1_flow + jsonObject.getInteger("truck1_flow");
truck2_flow = truck2_flow + jsonObject.getInteger("truck2_flow");
truck3_flow = truck3_flow + jsonObject.getInteger("truck3_flow");
truck4_flow = truck4_flow + jsonObject.getInteger("truck4_flow");
truck5_flow = truck5_flow + jsonObject.getInteger("truck5_flow");
truck6_flow = truck6_flow + jsonObject.getInteger("truck6_flow");
}
}
}
bus = bus1_flow + bus2_flow + bus3_flow + bus4_flow;
truck = truck1_flow + truck2_flow + truck3_flow + truck4_flow + truck5_flow + truck6_flow;
map.put("bus", bus);
map.put("truck", truck);
return map;
} catch (IOException e) {
// 处理异常
e.printStackTrace();
return map;
} catch (HttpException e) {
throw new RuntimeException(e);
}
}
private Response getResponseTrafficFlowAtToll(String startDate, String stationType) throws HttpException, IOException { private Response getResponseTrafficFlowAtToll(String startDate, String stationType) throws HttpException, IOException {
// 创建OkHttpClient.Builder实例 // 创建OkHttpClient.Builder实例

Loading…
Cancel
Save