Browse Source

交通流,设备

develop
王兴琳 1 month ago
parent
commit
67ff06bf3c
  1. 6
      zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java
  2. 55
      zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java
  3. 3
      zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java
  4. 17
      zc-business/src/main/java/com/zc/business/service/impl/DcGantryStatisticsDataImpl.java
  5. 81
      zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java

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

@ -120,6 +120,10 @@ public class DcDeviceOnlineController extends BaseController {
params.setStakeMark(stakeMark.replace(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.PLUS_SIGN.getValue()));
}
List<OnlineSum> sums = onlineSumService.queryByDeviceTypesOfToday(params);
// 按桩号排序
List<OnlineSum> sortedSums = sums.stream()
.sorted(Comparator.comparing(OnlineSum::getStakeMark))
.collect(Collectors.toList());
/*Map<String,OnlineSum> onlineSumMap = redisCache.getCacheMap(RedisKeyConstants.DEVICE_ONLINE);
String date = LocalDate.now().toString();*/
/*for (OnlineSum sum : sums) {
@ -132,7 +136,7 @@ public class DcDeviceOnlineController extends BaseController {
sum.setLastOnlineTime(onlineSumMap.get(hKey).getLastOnlineTime());
sum.setDeviceStatus(onlineSumMap.get(hKey).getDeviceStatus());
}*/
return getDataTable(sums);
return getDataTable(sortedSums);
}
//按时间划分设备柱状图

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

@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
@ -958,6 +959,60 @@ public class DcTrafficStatisticsController extends BaseController {
return AjaxResult.success(jsonArray);
}
/**
* 各收费站入口
* @param startDate
* @param endDate
* @param stationType
* @return
* @throws HttpException
* @throws IOException
*/
@ApiOperation("各收费站入口")
@GetMapping("/history/entranceToEachTollStation")
public void entranceToEachTollStation(
@RequestParam String startDate,
@RequestParam String endDate,
@RequestParam String stationType,
HttpServletResponse response) throws IOException, HttpException {
// 调用服务层方法,获取当前交通指标数据
TreeMap<String, Integer> sortedMap = dcTrafficStatisticsService.entranceToEachTollStation(startDate, endDate, stationType);
// 创建一个新的工作簿和表单
try (Workbook workbook = new XSSFWorkbook()) {
Sheet sheet = workbook.createSheet("每小时流量");
// 创建表头
Row headerRow = sheet.createRow(0);
Cell headerCellHour = headerRow.createCell(0);
headerCellHour.setCellValue("小时");
Cell headerCellFlow = headerRow.createCell(1);
headerCellFlow.setCellValue("总流");
// 填充数据
int rowNum = 1;
for (Map.Entry<String, Integer> entry : sortedMap.entrySet()) {
Row row = sheet.createRow(rowNum++);
Cell cellHour = row.createCell(0);
cellHour.setCellValue(entry.getKey());
Cell cellFlow = row.createCell(1);
cellFlow.setCellValue(entry.getValue());
}
// 自动调整列宽
sheet.autoSizeColumn(0);
sheet.autoSizeColumn(1);
// 设置响应内容类型和头部信息,让浏览器知道这是一个文件下载请求
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment; filename=收费站车流量.xlsx");
// 将工作簿写入HTTP响应输出流
workbook.write(response.getOutputStream());
response.getOutputStream().flush();
}
}
/**
* 各收费站入口分车型车流量
*/

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

@ -6,8 +6,10 @@ import com.zc.business.domain.DcRoadSectionCongestion;
import com.zc.common.core.httpclient.exception.HttpException;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
public interface IDcTrafficStatisticsService {
@ -49,6 +51,7 @@ public interface IDcTrafficStatisticsService {
* 各收费站入口分车型小时车流量
*/
List<Map<String, String>>trafficFlowAtTollStationEntrance(String startDate, String endDate, String stationType) throws HttpException, IOException;
TreeMap<String, Integer> entranceToEachTollStation(String startDate, String endDate, String stationType) throws HttpException, IOException;
JSONArray trafficFlowAtTollStationEntranceHour(String startDate, String endDate, String stationType)throws HttpException, IOException;

17
zc-business/src/main/java/com/zc/business/service/impl/DcGantryStatisticsDataImpl.java

@ -26,6 +26,7 @@ import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
/**
* 门架数据统计服务实现类
@ -212,7 +213,13 @@ public class DcGantryStatisticsDataImpl extends ServiceImpl<DcGantryStatisticsDa
*/
@Override
public List<Map<String, String>> realTimeTrafficFlow(String startDate, String direction, String periodType ) {
return dcGantryStatisticsDataMapper.realTimeTrafficFlow(startDate,direction,periodType);
List<Map<String, String>> mapList = dcGantryStatisticsDataMapper.realTimeTrafficFlow(startDate, direction, periodType);
// 过滤孝里虚-平阴北虚 和 平阴北虚-孝里虚的数据
List<Map<String, String>> filteredList = mapList.stream()
.filter(map -> "孝里虚-平阴北虚".equals(map.get("name")) || "平阴北虚-孝里虚".equals(map.get("name")))
.collect(Collectors.toList());
return filteredList;
}
/**
* 车流量时段分析
@ -239,7 +246,13 @@ public class DcGantryStatisticsDataImpl extends ServiceImpl<DcGantryStatisticsDa
@Override
public List<Map<String, String>> sectionTrafficRanking(String startDate, String direction, String periodType) {
return dcGantryStatisticsDataMapper.sectionTrafficRanking(startDate,direction,periodType);
List<Map<String, String>> mapList = dcGantryStatisticsDataMapper.sectionTrafficRanking(startDate, direction, periodType);
// 孝里虚-平阴北虚 或 平阴北虚-孝里虚的数据
List<Map<String, String>> filteredList = mapList.stream()
.filter(map -> "孝里虚-平阴北虚".equals(map.get("facilityName")) || "平阴北虚-孝里虚".equals(map.get("facilityName")))
.collect(Collectors.toList());
return filteredList;
}
public List<Map<String, String>> aggregateTrafficVolume(List<Map<String, Object>> dataList) {

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

@ -815,6 +815,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
// 直接基于原始数据映射和LocationEnum构建最终结果列表
List<Map<String, String>> resultList = Arrays.stream(LocationEnum.values())
.filter(location -> !location.getName().equals("平阴北"))// 先过滤掉平阴北
.map(location -> {
Map<String, String> defaultData = new HashMap<String, String>() {{
put("value", "0");
@ -837,6 +838,74 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
return new ArrayList();
}
}
@Override
public TreeMap<String, Integer> entranceToEachTollStation(String startDate, String endDate, String stationType) throws HttpException, IOException {
// 创建OkHttpClient.Builder实例
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
// 添加重试拦截器到OkHttpClient
httpClientBuilder.addInterceptor(new RetryInterceptorUtil());
// 构建最终的OkHttpClient实例
OkHttpClient okHttpClient = httpClientBuilder.build();
// 现在使用带有重试机制的OkHttpClient发起请求
Map<String, Object> requestParams = new HashMap<>();
requestParams.put("sysid", sysid);
JSONObject parameters = new JSONObject();
parameters.put("start_date", startDate);
parameters.put("end_date", endDate);
parameters.put("station_type", stationType);
requestParams.put("parameters", parameters);
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", getAccessToken());
Gson gson = new Gson();
String requestParamsJson = gson.toJson(requestParams);
try {
Request request = new Request.Builder()
.url(baseUrl + UniversalEnum.EACH_TOLL_STATION_ENTRANCE_BY_TYPE_OF_HOURLY_TRAFFIC_FLOW.getValue())
.headers(Headers.of(headers))
.post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), requestParamsJson))
.build();
Response response = okHttpClient.newCall(request).execute();
ResponseBody body = response.body();
if (body != null) {
String jsonString = body.string();
JSONArray jsonArray = JSON.parseArray(jsonString);
Map<Integer, Integer> flowPerHour = jsonArray.stream()
.map(item -> (JSONObject) item)
.collect(Collectors.groupingBy(
item -> item.getInteger("data_hour"),
Collectors.reducing(
0,
item -> item.getInteger("total_flow"),
Integer::sum
)
));
TreeMap<String, Integer> hashMap = new TreeMap<>();
// 示例输出结果
flowPerHour.forEach((hour, totalFlow) ->
hashMap.put(hour.toString(), totalFlow));
// 使用带有自定义Comparator的TreeMap进行排序
TreeMap<String, Integer> sortedMap = new TreeMap<>((o1, o2) -> {
int hour1 = Integer.parseInt(o1);
int hour2 = Integer.parseInt(o2);
return Integer.compare(hour1, hour2);
});
// 将数据放入TreeMap中
sortedMap.putAll(hashMap);
return sortedMap;
}
return new TreeMap<>();
} catch (IOException e) {
// 处理异常
e.printStackTrace();
return new TreeMap();
}
}
@Override
@ -973,10 +1042,14 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
// 构建结果列表
List<Map<String, Object>> mapList = new ArrayList<>();
for (int i = UniversalEnum.ONE.getNumber(); i <= 13; i++) {
Map<String, Object> map = new HashMap<>();
map.put("name", getTrafficFlowDoorFrameSection(i));
map.put("totalFlow", flowCounts.get(i));
mapList.add(map);
// 只添加不为0的车流量数据,后续删除
if (!getTrafficFlowDoorFrameSection(i).equals("孝里虚-平阴北虚")){
Map<String, Object> map = new HashMap<>();
map.put("name", getTrafficFlowDoorFrameSection(i));
map.put("totalFlow", flowCounts.get(i));
mapList.add(map);
}
}
return mapList;
}

Loading…
Cancel
Save