Browse Source

设备在线率,交通流事件

develop
王兴琳 4 weeks ago
parent
commit
fa67860723
  1. 9
      zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java
  2. 21
      zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java
  3. 8
      zc-business/src/main/java/com/zc/business/domain/OnlineSum.java
  4. 5
      zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java
  5. 6
      zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java
  6. 91
      zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java

9
zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java

@ -151,7 +151,11 @@ public class DcDeviceOnlineController extends BaseController {
for (String type : types) { for (String type : types) {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
List<OnlineSum> listOfType = stringListMap.getOrDefault(type, new ArrayList<>()); List<OnlineSum> listOfType = stringListMap.getOrDefault(type, new ArrayList<>());
Map<LocalDate, List<OnlineSum>> localDateListMap = listOfType.stream()
.collect(Collectors.groupingBy(onlineSum -> onlineSum.getStatisticalDate().toLocalDate()));
/*
Map<LocalDate, List<OnlineSum>> localDateListMap = listOfType.stream().collect(Collectors.groupingBy(OnlineSum::getStatisticalDate)); Map<LocalDate, List<OnlineSum>> localDateListMap = listOfType.stream().collect(Collectors.groupingBy(OnlineSum::getStatisticalDate));
*/
for (LocalDate date = start.toLocalDate(); date.isBefore(end.toLocalDate().plusDays(1)); date = date.plusDays(1)) { for (LocalDate date = start.toLocalDate(); date.isBefore(end.toLocalDate().plusDays(1)); date = date.plusDays(1)) {
List<OnlineSum> dayList = localDateListMap.getOrDefault(date, new ArrayList<>()); List<OnlineSum> dayList = localDateListMap.getOrDefault(date, new ArrayList<>());
map.put(date.toString(), MathUtil.doubleTwoDecimalStr(dayList.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0)) + "%"); map.put(date.toString(), MathUtil.doubleTwoDecimalStr(dayList.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0)) + "%");
@ -191,7 +195,8 @@ public class DcDeviceOnlineController extends BaseController {
List<OnlineSum> listOfType = stringListMap.getOrDefault(type, new ArrayList<>()); List<OnlineSum> listOfType = stringListMap.getOrDefault(type, new ArrayList<>());
// 按日期分组 // 按日期分组
Map<LocalDate, List<OnlineSum>> localDateListMap = listOfType.stream().collect(Collectors.groupingBy(OnlineSum::getStatisticalDate)); Map<LocalDate, List<OnlineSum>> localDateListMap = listOfType.stream() .collect(Collectors.groupingBy(onlineSum -> onlineSum.getStatisticalDate().toLocalDate()));
// 按日期统计 // 按日期统计
for (LocalDate date = start.toLocalDate(); date.isBefore(end.toLocalDate().plusDays(1)); date = date.plusDays(1)) { for (LocalDate date = start.toLocalDate(); date.isBefore(end.toLocalDate().plusDays(1)); date = date.plusDays(1)) {
@ -203,7 +208,7 @@ public class DcDeviceOnlineController extends BaseController {
LocalDateTime startHour = LocalDateTime.of(date, LocalTime.of(hour, 0)); LocalDateTime startHour = LocalDateTime.of(date, LocalTime.of(hour, 0));
LocalDateTime endHour = startHour.plusHours(1); LocalDateTime endHour = startHour.plusHours(1);
List<OnlineSum> hourList = dayList.stream() List<OnlineSum> hourList = dayList.stream()
.filter(os -> os.getStatisticalDate().isAfter(ChronoLocalDate.from(startHour)) && os.getStatisticalDate().isBefore(ChronoLocalDate.from(endHour))) .filter(os -> os.getStatisticalDate().toLocalDate().isAfter(ChronoLocalDate.from(startHour)) && os.getStatisticalDate().toLocalDate().isBefore(ChronoLocalDate.from(endHour)))
.collect(Collectors.toList()); .collect(Collectors.toList());
double averageRate = hourList.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0); double averageRate = hourList.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0);

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

@ -303,6 +303,27 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
// 将查询结果封装为成功响应并返回 // 将查询结果封装为成功响应并返回
return AjaxResult.success(mapList); return AjaxResult.success(mapList);
} }
/**
* 车流量异常事件流量查询
* @param eventId 事件id
*/
@ApiOperation("车流量异常事件流量查询")
@GetMapping("/history/eventtrafficflowcnt")
public AjaxResult eventtrafficflowcnt(String eventId ) throws HttpException {
JSONArray mapList = dcTrafficStatisticsService.eventtrafficflowcnt(eventId);
// 将查询结果封装为成功响应并返回
return AjaxResult.success(mapList);
}
/**
* 交通流统计分析重点数据查询交通流异常信息
*/
@ApiOperation("交通流统计分析重点数据查询交通流异常信息")
@GetMapping("/history/exampleQueryTrafficFlowAnomalies")
public AjaxResult exampleQueryTrafficFlowAnomalies(String startTime,String endTime ) throws HttpException {
JSONArray mapList = dcTrafficStatisticsService.exampleQueryTrafficFlowAnomalies(startTime,endTime);
// 将查询结果封装为成功响应并返回
return AjaxResult.success(mapList);
}
/** /**
* 导出车流量时段分析 * 导出车流量时段分析

8
zc-business/src/main/java/com/zc/business/domain/OnlineSum.java

@ -39,7 +39,7 @@ public class OnlineSum implements java.io.Serializable {
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "统计日期", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") @Excel(name = "统计日期", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private LocalDate statisticalDate;//统计日期 private LocalDateTime statisticalDate;//统计日期
private String deviceType;//设备类型 private String deviceType;//设备类型
private int totalCount;//当天总次数 private int totalCount;//当天总次数
private int sendCount;//发送数据包总数 private int sendCount;//发送数据包总数
@ -134,11 +134,11 @@ public class OnlineSum implements java.io.Serializable {
this.networkQuality = networkQuality; this.networkQuality = networkQuality;
} }
public LocalDate getStatisticalDate() { public LocalDateTime getStatisticalDate() {
return statisticalDate; return statisticalDate;
} }
public void setStatisticalDate(LocalDate statisticalDate) { public void setStatisticalDate(LocalDateTime statisticalDate) {
this.statisticalDate = statisticalDate; this.statisticalDate = statisticalDate;
} }
@ -296,7 +296,7 @@ public class OnlineSum implements java.io.Serializable {
this.networkQuality = onlineLog.getNetworkQuality(); this.networkQuality = onlineLog.getNetworkQuality();
if(this.deviceStatus.equals(DcDevice.ONLINE)) if(this.deviceStatus.equals(DcDevice.ONLINE))
this.lastOnlineTime = onlineLog.getMonitorTime(); this.lastOnlineTime = onlineLog.getMonitorTime();
this.statisticalDate = onlineLog.getMonitorTime().toLocalDate(); this.statisticalDate = onlineLog.getMonitorTime();
return this; return this;
} }

5
zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java

@ -1789,6 +1789,11 @@ RADAR_ASSOCIATED_MONITORING_POINT_QUERY_INTERFACE(0,"/api/radar/v1/selectRelateB
// 全路段双向实时车流量 /api/dc/query/gan_jihe_d_vehtypeflow // 全路段双向实时车流量 /api/dc/query/gan_jihe_d_vehtypeflow
THE_WHOLE_SECTION_TWO_WAY_REAL_TIME_TRAFFIC_FLOW_URL(0, "/api/dc/query/gan_jihe_d_vehtypeflow"), THE_WHOLE_SECTION_TWO_WAY_REAL_TIME_TRAFFIC_FLOW_URL(0, "/api/dc/query/gan_jihe_d_vehtypeflow"),
//车流量异常事件流量查询
QUERY_TRAFFIC_OF_ABNORMAL_TRAFFIC_EVENTS(0,"/api/dc/query/gan_jihe_d_eventtrafficflowcnt"),
// *交通流统计分析重点数据查询交通流异常信息
TRAFFIC_FLOW_STATISTICAL_KEY_DATA_QUERY(0,"/api/dc/query/gan_jihe_d_trafficexception"),
// 雷达数据 http://www.nmc.cn/publish/radar/chinaall.html // 雷达数据 http://www.nmc.cn/publish/radar/chinaall.html
RADAR_DATA(0, "http://www.nmc.cn/publish/radar/chinaall.html"), RADAR_DATA(0, "http://www.nmc.cn/publish/radar/chinaall.html"),

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

@ -65,4 +65,10 @@ public interface IDcTrafficStatisticsService {
int trafficFlowAtToll(String startDate)throws HttpException, IOException; int trafficFlowAtToll(String startDate)throws HttpException, IOException;
int yesterdayTrafficFlowAtToll(String startDate)throws HttpException, IOException; int yesterdayTrafficFlowAtToll(String startDate)throws HttpException, IOException;
JSONArray eventtrafficflowcnt(String eventId) throws HttpException;
/**
* 交通流统计分析重点数据查询交通流异常信息
*/
JSONArray exampleQueryTrafficFlowAnomalies(String startTime, String endTime) throws HttpException;
} }

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

@ -1368,6 +1368,97 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
} }
@Override
public JSONArray eventtrafficflowcnt(String eventId) throws HttpException {
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams();
requestParams.put("sysid", sysid);
JSONObject parameters = new JSONObject() {
{
put("event_id", eventId);
}
};
requestParams.put("parameters", parameters.toJSONString());
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", getAccessToken());
try {
Response response // 请求响应
= okHttp
.headers(headers)
.url(baseUrl + UniversalEnum.QUERY_TRAFFIC_OF_ABNORMAL_TRAFFIC_EVENTS.getValue()) // 请求地址
.data(requestParams) // 请求参数
.post(); // 请求方法
ResponseBody body = response.body();
if (body != null) {
String jsonString = body.string();
if (JSON.isValidArray(jsonString)) {
return JSON.parseArray(jsonString);
} else {
return new JSONArray();
}
}
return new JSONArray();
} catch (IOException e) {
// 处理异常
e.printStackTrace();
return new JSONArray();
}
}
/**
* 交通流统计分析重点数据查询交通流异常信息
*/
@Override
public JSONArray exampleQueryTrafficFlowAnomalies(String startTime, String endTime) throws HttpException {
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams();
requestParams.put("sysid", sysid);
JSONObject parameters = new JSONObject() {
{
put("start_time", startTime);
put("end_time", endTime);
}
};
requestParams.put("parameters", parameters.toJSONString());
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", getAccessToken());
try {
Response response // 请求响应
= okHttp
.headers(headers)
.url(baseUrl + UniversalEnum.TRAFFIC_FLOW_STATISTICAL_KEY_DATA_QUERY.getValue()) // 请求地址
.data(requestParams) // 请求参数
.post(); // 请求方法
ResponseBody body = response.body();
if (body != null) {
String jsonString = body.string();
if (JSON.isValidArray(jsonString)) {
return JSON.parseArray(jsonString);
} else {
return new JSONArray();
}
}
return new JSONArray();
} catch (IOException e) {
// 处理异常
e.printStackTrace();
return new JSONArray();
}
}
private Response getResponseTrafficFlowAtToll(String startDate, String stationType) throws HttpException, IOException { private Response getResponseTrafficFlowAtToll(String startDate, String stationType) throws HttpException, IOException {
// 创建OkHttpClient.Builder实例 // 创建OkHttpClient.Builder实例
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder(); OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();

Loading…
Cancel
Save