diff --git a/zc-business/src/main/java/com/zc/business/constant/RedisKeyConstants.java b/zc-business/src/main/java/com/zc/business/constant/RedisKeyConstants.java index c221f1e4..bf8b49d1 100644 --- a/zc-business/src/main/java/com/zc/business/constant/RedisKeyConstants.java +++ b/zc-business/src/main/java/com/zc/business/constant/RedisKeyConstants.java @@ -68,4 +68,9 @@ public class RedisKeyConstants * 设备离线记录 */ public static final String DC_DEVICE_OFFLINE_RECORD = "dc:deviceOfflineRecord"; + + /** + * 交调站小时数据 失败请求 + */ + public static final String TRAFFIC_SURVEY_HOURS_DATA = "trafficSurveyHoursData"; } diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java index 1f1d1073..c390e2ed 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java @@ -11,6 +11,7 @@ import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.utils.spring.SpringUtils; @@ -22,6 +23,7 @@ import com.zc.business.enums.UniversalEnum; import com.zc.business.interfaces.OperationLog; import com.zc.business.request.DeviceGetPropertiesOperateRequest; import com.zc.business.service.IDcDeviceService; +import com.zc.business.service.IDcWarningService; import com.zc.common.core.httpclient.OkHttp; import com.zc.common.core.httpclient.exception.HttpException; import com.zc.common.core.httpclient.request.RequestParams; @@ -63,7 +65,8 @@ import java.util.stream.Collectors; @RestController @RequestMapping("/business/device") public class DcDeviceController extends BaseController { - + @Resource + private RedisCache redisCache; @Resource private IDcDeviceService dcDeviceService; @Resource @@ -406,8 +409,130 @@ private VideoController videoController; } @ApiOperation("太阳能状况统计") @GetMapping("/properties/history/oneDay/{propertyId}") - public AjaxResult queryDevicePropertiesDay( - @PathVariable @Parameter(description = "属性ID") String propertyId) throws HttpException, IOException, ParseException { + public AjaxResult queryDevicePropertiesDay(@PathVariable @Parameter(description = "属性ID") String propertyId) throws HttpException, IOException, ParseException { +// HashMap props = new HashMap<>(); +// // 设置查询条件的键为“timestamp$BTW”,表示时间戳在一定范围内 +// props.put("terms[0].column", "timestamp$BTW"); +// ArrayList dateList = new ArrayList<>(); +// // 添加当前日期的开始和结束时间到列表,用于设定时间范围 +// dateList.add(DateUtil.beginOfDay(new Date()).toString()); +// dateList.add(DateUtil.endOfDay(new Date()).toString()); +// // 将日期列表以逗号分隔并设置为查询条件的值 +// props.put("terms[0].value", String.join(",", dateList)); +// props.put("paging", false); +// props.put("sorts[0].order", "asc"); +// props.put("sorts[0].name", "timestamp"); +// Map parameter = new HashMap<>(); +// String[] endStakeMark = {"208", "979"}; +// String[] startStakeMark = {"054", "378"}; +// parameter.put("deviceType", "15"); +// parameter.put("endStakeMark", endStakeMark); +// parameter.put("startStakeMark", startStakeMark); +// // parameter.put("deviceState","1"); +// // 创建一个映射来存储按小时汇总的数据 +// Map allDevicesHourlyAggregates = new TreeMap<>(); +// +// List dcDevices = dcDeviceService.devicePileNumberQueryDevice(parameter); +// for (DcDevice dcDevice : dcDevices) { +// AjaxResult ajaxResult = queryDeviceProperties(dcDevice.getIotDeviceId(), propertyId, props); +// if (!ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { +// return ajaxResult; +// } +// // 定义时间格式 +// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); +// +// Object data = JSON.parseObject(ajaxResult.get("data").toString()).get("data"); +// JSONArray dataArray = JSON.parseArray(data.toString()); +// // 创建一个映射来存储单个设备按小时汇总的数据 +// Map> deviceHourlyLatestData = new TreeMap<>(); +// +// DecimalFormat decimalFormat = new DecimalFormat("#.##"); +// decimalFormat.setRoundingMode(RoundingMode.HALF_UP); +// +// // 处理每个数据点 +// for (Object o : dataArray) { +// JSONObject jsonObject = JSON.parseObject(o.toString()); +// String formatValueStr = jsonObject.getString("formatValue"); +// String timestampStr = jsonObject.getString("timestamp"); +// +// // 将 Unix 时间戳转换为 Date 对象 +// long timestamp = Long.parseLong(timestampStr); +// Date date = new Date(timestamp); +// +// // 将 Date 对象格式化为字符串 +// String formattedTimestamp = sdf.format(date); +// Calendar calendar = Calendar.getInstance(); +// calendar.setTime(date); +// +// // 提取小时部分 +// int hour = calendar.get(Calendar.HOUR_OF_DAY); +// String key = String.format("%d-%02d-%02d %02d:00:00", +// calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, +// calendar.get(Calendar.DAY_OF_MONTH), hour); +// +// // 转换为 double 类型,去除单位 +// String valueWithoutUnit = formatValueStr.replaceAll("[^\\d.]", ""); +// double parsedValue = Double.parseDouble(valueWithoutUnit); +// // 保留两位小数 +// double formatValue = Double.parseDouble(decimalFormat.format(parsedValue)); +// +// // 检查当前小时是否有数据,如果没有则直接添加 +// if (!deviceHourlyLatestData.containsKey(key)) { +// Map dataPoint = new HashMap<>(); +// dataPoint.put("value", formatValue); +// dataPoint.put("timestamp", timestamp); +// deviceHourlyLatestData.put(key, dataPoint); +// } else { +// // 如果已经有数据,比较时间戳,保留最新的数据 +// long existingTimestamp = (long) deviceHourlyLatestData.get(key).get("timestamp"); +// if (timestamp > existingTimestamp) { +// Map dataPoint = new HashMap<>(); +// dataPoint.put("value", formatValue); +// dataPoint.put("timestamp", timestamp); +// deviceHourlyLatestData.put(key, dataPoint); +// } +// } +// } +// +// // 将设备的数据合并到所有设备的汇总数据中 +// for (String key : deviceHourlyLatestData.keySet()) { +// double latestValue = (double) deviceHourlyLatestData.get(key).get("value"); +// allDevicesHourlyAggregates.merge(key, latestValue, (oldVal, newVal) -> { +// double sum = oldVal + newVal; +// return Double.parseDouble(decimalFormat.format(sum)); +// }); +// } +// } + Map allDevicesHourlyAggregates= redisCache.getCacheObject(propertyId); + return AjaxResult.success(allDevicesHourlyAggregates); + } + + public void solarEnergyConditionStatisticsOne() { + RedisCache redisCache = SpringUtils.getBean(RedisCache.class); + Map stringDoubleMap = solarEnergyConditionStatistics("dailyAccumulatedCharge"); + if (stringDoubleMap != null) { + redisCache.setCacheObject("dailyAccumulatedCharge", stringDoubleMap); + } + } + public void solarEnergyConditionStatisticsTwo(){ + RedisCache redisCache = SpringUtils.getBean(RedisCache.class); + Map stringDoubleMap = solarEnergyConditionStatistics("cumulativeElectricityConsumptionOnTheDay"); + if (stringDoubleMap!=null) { + redisCache.setCacheObject("cumulativeElectricityConsumptionOnTheDay", stringDoubleMap); + } + } + public void solarEnergyConditionStatisticsThree(){ + RedisCache redisCache = SpringUtils.getBean(RedisCache.class); + Map stringDoubleMap = solarEnergyConditionStatistics("generatingPower"); + if (stringDoubleMap!=null){ + redisCache.setCacheObject("generatingPower", stringDoubleMap); + } + } + + public Map solarEnergyConditionStatistics (String propertyId) { + + IDcDeviceService dcDeviceService = SpringUtils.getBean(IDcDeviceService.class); + HashMap props = new HashMap<>(); // 设置查询条件的键为“timestamp$BTW”,表示时间戳在一定范围内 props.put("terms[0].column", "timestamp$BTW"); @@ -432,9 +557,17 @@ private VideoController videoController; List dcDevices = dcDeviceService.devicePileNumberQueryDevice(parameter); for (DcDevice dcDevice : dcDevices) { - AjaxResult ajaxResult = queryDeviceProperties(dcDevice.getIotDeviceId(), propertyId, props); + + AjaxResult ajaxResult = null; + try { + ajaxResult = queryDeviceProperties(dcDevice.getIotDeviceId(), propertyId, props); + } catch (HttpException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } if (!ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { - return ajaxResult; + return null; } // 定义时间格式 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -501,10 +634,8 @@ private VideoController videoController; }); } } - return AjaxResult.success(allDevicesHourlyAggregates); + return allDevicesHourlyAggregates; } - - @ApiOperation("太阳能重点数据") @GetMapping("/properties/latestOne") public AjaxResult getDeviceLatest() throws HttpException, IOException { diff --git a/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java b/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java index 36772366..27637ef2 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java @@ -969,6 +969,14 @@ public class DcTrafficStatisticsController extends BaseController { // 将获取到的交通指标数据封装为成功的结果并返回 return AjaxResult.success(a); } + @ApiOperation("收费站日累计车流辆分车型") + @GetMapping("/history/trafficFlowAtTollTypes") + public AjaxResult trafficFlowAtTollTypes(String startDate) throws HttpException, IOException { + // 调用服务层方法,获取当前交通指标数据 + Map a = dcTrafficStatisticsService.trafficFlowAtTollTypes(startDate); + // 将获取到的交通指标数据封装为成功的结果并返回 + return AjaxResult.success(a); + } @ApiOperation("收费站昨日累计车流辆") @GetMapping("/history/yesterdayTrafficFlowAtToll") diff --git a/zc-business/src/main/java/com/zc/business/controller/DcTrafficSurveyDataController.java b/zc-business/src/main/java/com/zc/business/controller/DcTrafficSurveyDataController.java index 1cb44f4d..f2137da0 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcTrafficSurveyDataController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcTrafficSurveyDataController.java @@ -1,6 +1,8 @@ package com.zc.business.controller; import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; import javax.annotation.Resource; @@ -11,7 +13,9 @@ import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.system.domain.SysLogininfor; +import com.zc.business.constant.RedisKeyConstants; import com.zc.business.domain.*; import com.zc.business.enums.UniversalEnum; import com.zc.common.core.httpclient.exception.HttpException; @@ -55,8 +59,20 @@ public class DcTrafficSurveyDataController extends BaseController @Resource private DcDeviceController dcDeviceController; - @Scheduled(cron = "0 5 * * * ?") - public void syncTrafficSectionData() throws HttpException, IOException { + @Resource + private RedisCache redisCache; + + /** + * 每小时执行一次 + * 如果请求失败则将当前设备、时间范围放入redis + * 下次执行时先处理redis中之前未成功的,最多执行三次 + */ + @Scheduled(cron = "0 13 * * * ?") + public void syncTrafficSectionData() throws HttpException, IOException, ParseException { + + + //先执行之前不成功的 + executeFailedData(); HashMap props = new HashMap<>(); // 设置查询条件的键为“timestamp$BTW”,表示时间戳在一定范围内 @@ -68,8 +84,10 @@ public class DcTrafficSurveyDataController extends BaseController Date lastHourStart = DateUtil.beginOfHour(DateUtil.offsetHour(now, -1)); Date lastHourEnd = DateUtil.endOfHour(DateUtil.offsetHour(now, -1)); // 将上一个小时的开始和结束时间添加到列表 - dateList.add(DateUtil.format(lastHourStart, "yyyy-MM-dd HH:mm:ss")); - dateList.add(DateUtil.format(lastHourEnd, "yyyy-MM-dd HH:mm:ss")); + String startTime = DateUtil.format(lastHourStart, "yyyy-MM-dd HH:mm:ss"); + String endTime = DateUtil.format(lastHourEnd, "yyyy-MM-dd HH:mm:ss"); + dateList.add(startTime); + dateList.add(endTime); // 将日期列表以逗号分隔并设置为查询条件的值 props.put("terms[0].value", String.join(UniversalEnum.COMMA.getValue(), dateList)); props.put("paging", false); @@ -83,7 +101,21 @@ public class DcTrafficSurveyDataController extends BaseController List batchData = new ArrayList<>(); for (DcDevice dcDevice : deviceList) { - Object data = JSON.parseObject(dcDeviceController.queryDeviceProperties(dcDevice.getIotDeviceId(), propertyId, props).get("data").toString()).get("data"); + Object data = null; + AjaxResult ajaxResult = dcDeviceController.queryDeviceProperties(dcDevice.getIotDeviceId(), propertyId, props); + if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber()) && ajaxResult.containsKey("data") && ajaxResult.get("data") != null) { + data = JSON.parseObject(ajaxResult.get("data").toString()).get("data"); + } else { + //超时、错误等异常状态,放入缓存下次定时执行时再次请求一遍 + Map cacheMap = new HashMap<>(); + cacheMap.put("iotDeviceId",dcDevice.getIotDeviceId()); + cacheMap.put("stakeMark",dcDevice.getStakeMark()); + cacheMap.put("startTime",startTime); + cacheMap.put("endTime",endTime); + cacheMap.put("count",3); //剩余请求次数 + redisCache.setCacheMapValue(RedisKeyConstants.TRAFFIC_SURVEY_HOURS_DATA,dcDevice.getIotDeviceId()+startTime,cacheMap); + break; + } JSONArray dataArray = JSON.parseArray(data.toString()); if (dataArray == null || dataArray.size() < 1){ break; @@ -151,6 +183,122 @@ public class DcTrafficSurveyDataController extends BaseController } + /** + * @Description 再次执行之前未成功请求的 + * + * @author liuwenge + * @date 2024/12/25 9:36 + * @param + * @return void + */ + public void executeFailedData() throws IOException, HttpException, ParseException { + Map> cache = redisCache.getCacheMap(RedisKeyConstants.TRAFFIC_SURVEY_HOURS_DATA); + if (cache == null || cache.size() == 0) { + return; + } + + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + List batchData = new ArrayList<>(); + for (Map value : cache.values()) { + + String iotDeviceId = value.get("iotDeviceId").toString(); + String stakeMark = value.get("stakeMark").toString(); + String startTime = value.get("startTime").toString(); + String endTime = value.get("endTime").toString(); + int count = Integer.parseInt(value.get("count").toString()); + + HashMap props = new HashMap<>(); + // 设置查询条件的键为“timestamp$BTW”,表示时间戳在一定范围内 + props.put("terms[0].column", "timestamp$BTW"); + ArrayList dateList = new ArrayList<>(); + dateList.add(startTime); + dateList.add(endTime); + // 将日期列表以逗号分隔并设置为查询条件的值 + props.put("terms[0].value", String.join(UniversalEnum.COMMA.getValue(), dateList)); + props.put("paging", false); + props.put("sorts[0].order", "asc"); + props.put("sorts[0].name", "timestamp"); + + Object data = null; + AjaxResult ajaxResult = dcDeviceController.queryDeviceProperties(iotDeviceId, "01", props); + if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber()) && ajaxResult.containsKey("data") && ajaxResult.get("data") != null) { + data = JSON.parseObject(ajaxResult.get("data").toString()).get("data"); + redisCache.delCacheMapValue(RedisKeyConstants.TRAFFIC_SURVEY_HOURS_DATA,iotDeviceId+startTime); + } else { + count--; + if (count < 1){ + redisCache.delCacheMapValue(RedisKeyConstants.TRAFFIC_SURVEY_HOURS_DATA,iotDeviceId+startTime); + } else { + value.put("count",count); + redisCache.setCacheMapValue(RedisKeyConstants.TRAFFIC_SURVEY_HOURS_DATA,iotDeviceId+startTime,value); + } + break; + } + JSONArray dataArray = JSON.parseArray(data.toString()); + if (dataArray == null || dataArray.size() < 1){ + break; + } + Integer hezeTotal = 0; + Integer jinanTotal = 0; + //一小时内所有的车道数据 + JSONArray lanesData = new JSONArray(); + for (Object o : dataArray) { + JSONObject jsonObject = JSON.parseObject(o.toString()); + JSONObject formatValue = JSON.parseObject(jsonObject.get("formatValue").toString()); + hezeTotal += Integer.parseInt(formatValue.get("1").toString()); + jinanTotal += Integer.parseInt(formatValue.get("3").toString()); + + //车道数据 + JSONArray lanes = formatValue.getJSONArray("lanes"); + lanesData.addAll(lanes); + } + + // 转换类型 以便使用stream + List lanesList = lanesData.toJavaList(JSONObject.class); + Map dataList = lanesList.stream() + .collect(Collectors.groupingBy( + item -> item.getString("laneNumber").substring(0, 1), // 提取 laneNumber 的第一个字符作为 key + Collectors.mapping(item -> item, + Collectors.collectingAndThen( + Collectors.toList(), + list -> { // 然后将 List 转换为 JSONArray + JSONArray jsonArray = new JSONArray(); + jsonArray.addAll(list); + return jsonArray; + } + ) + ) + )); + + //菏泽方向数据 + DcTrafficSurveyData hezeData = new DcTrafficSurveyData(); + hezeData.setIotDeviceId(iotDeviceId); + hezeData.setStakeMark(stakeMark); + hezeData.setDirection("1"); + hezeData.setTimestamp(formatter.parse(startTime)); + hezeData.setTrafficVolume(Long.valueOf(hezeTotal)); + //济南方向数据 + DcTrafficSurveyData jinanData = new DcTrafficSurveyData(); + jinanData.setIotDeviceId(iotDeviceId); + jinanData.setStakeMark(stakeMark); + jinanData.setDirection("3"); + jinanData.setTimestamp(formatter.parse(startTime)); + jinanData.setTrafficVolume(Long.valueOf(jinanTotal)); + //各方向车道级数据 + if (dataList != null && dataList.size() > 0){ + JSONArray hezeLanesData = dataList.get("1"); + dcTrafficSurveyDataService.formatTrafficSurveyData(hezeData,hezeLanesData); + JSONArray jinanLanesData = dataList.get("3"); + dcTrafficSurveyDataService.formatTrafficSurveyData(jinanData,jinanLanesData); + } + + batchData.add(hezeData); + batchData.add(jinanData); + } + dcTrafficSurveyDataService.batchInsert(batchData); + + } + /** * 查询一类交调数据列表 */ @@ -301,19 +449,35 @@ public class DcTrafficSurveyDataController extends BaseController public AjaxResult selectComprehensiveData(@RequestBody DcTrafficSurveyDataQueryParams dcTrafficSurveyDataQueryParams){ return dcTrafficSurveyDataService.selectComprehensiveData(dcTrafficSurveyDataQueryParams); } + + /** + * 导出综合查询 + */ @PostMapping("/exportComprehensiveData") public void exportComprehensiveData(HttpServletResponse response,@RequestBody DcTrafficSurveyDataQueryParams dcTrafficSurveyDataQueryParams) { AjaxResult ajaxResult = dcTrafficSurveyDataService.selectComprehensiveData(dcTrafficSurveyDataQueryParams); if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { if (dcTrafficSurveyDataQueryParams.getDataType().equals("1")){ - List dcTrafficVolumeData = (List) ajaxResult.get("data"); - ExcelUtil util = new ExcelUtil<>(DcTrafficVolumeData.class); - util.exportExcel(response, dcTrafficVolumeData, "综合查询"); + if (dcTrafficSurveyDataQueryParams.getDirection().equals("2")) { + List dcTrafficVolumeData = (List) ajaxResult.get("data"); + ExcelUtil util = new ExcelUtil<>(DcTrafficVolumeData.class); + util.exportExcel(response, dcTrafficVolumeData, "综合查询"); + } else if (dcTrafficSurveyDataQueryParams.getDirection().equals("1")) { + List dcTrafficVolumeData = (List) ajaxResult.get("data"); + ExcelUtil util = new ExcelUtil<>(DcTrafficVolumeDirectionData.class); + util.exportExcel(response, dcTrafficVolumeData, "综合查询"); + } } else { - List dcTrafficSpeedData = (List) ajaxResult.get("data"); - ExcelUtil util = new ExcelUtil<>(DcTrafficSpeedData.class); - util.exportExcel(response, dcTrafficSpeedData, "综合查询"); + if (dcTrafficSurveyDataQueryParams.getDirection().equals("2")) { + List dcTrafficSpeedData = (List) ajaxResult.get("data"); + ExcelUtil util = new ExcelUtil<>(DcTrafficSpeedData.class); + util.exportExcel(response, dcTrafficSpeedData, "综合查询"); + } else if (dcTrafficSurveyDataQueryParams.getDirection().equals("1")) { + List dcTrafficSpeedData = (List) ajaxResult.get("data"); + ExcelUtil util = new ExcelUtil<>(DcTrafficSpeedDirectionData.class); + util.exportExcel(response, dcTrafficSpeedData, "综合查询"); + } } } } diff --git a/zc-business/src/main/java/com/zc/business/controller/RadarController.java b/zc-business/src/main/java/com/zc/business/controller/RadarController.java index 9c93ba26..4f33ecda 100644 --- a/zc-business/src/main/java/com/zc/business/controller/RadarController.java +++ b/zc-business/src/main/java/com/zc/business/controller/RadarController.java @@ -22,6 +22,9 @@ import java.time.Duration; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; /** * @@ -42,57 +45,80 @@ public class RadarController { LocalDateTime fifteenMinutesAgo = now.minus(Duration.ofMinutes(5)); String FifteenMinutesAgo = fifteenMinutesAgo.format(formatter); - // 获取当前时间前20分钟的时间点 - LocalDateTime twentyMinutesAgo = now.minus(Duration.ofMinutes(20)); + // 获取当前时间前25分钟的时间点 + LocalDateTime twentyMinutesAgo = now.minus(Duration.ofMinutes(25)); String TwentyMinutesAgo = twentyMinutesAgo.format(formatter); DcWarning dcWarning = new DcWarning(); dcWarning.setStartDate(TwentyMinutesAgo); dcWarning.setEndDate(FifteenMinutesAgo); List radarList = dcWarningService.radarList(dcWarning); - radarList.forEach(radar -> { - if (radar.getId() != null) { - try { - //获取雷达事件视频 - String baseUrl = dcWarningService.getRadarIncidentVideo(radar.getId()); - // String baseUrl = "http://10.0.11.252:9021/profile/mp4/G35 长清大学城站 内广场_20241108_090235_60.mp4"; - String ftpServer= configService.selectConfigByKey("FTP-IP");//密钥 - // int port = 21; - int port= Integer.parseInt(configService.selectConfigByKey("FTP-PORT")); - //ftpuser - //String user = "1911390090@qq.com"; - String username= configService.selectConfigByKey("FTP-USER");//密钥 - //Dxc123!@# - String password= configService.selectConfigByKey("FPT-PASSWORD");//密钥 - /* String ftpServer = "10.168.71.135"; - int port = 21; - String username = "1911390090@qq.com"; - String password = "989878wxl";*/ - String[] split = StringUtils.split(baseUrl, "_"); - // 拼接文件名 - String fileName = radar.getStakeMark() + "_" + split[1] + "_" + split[2] + "_" + split[3]; - - DateTimeFormatter dirFormatter = DateTimeFormatter.ofPattern("yyyyMMdd"); - DateTimeFormatter hourFormatter = DateTimeFormatter.ofPattern("HH"); - String datePart = now.format(dirFormatter); - String hourPart = now.format(hourFormatter); - //文件路径 -// String remoteFilePath = "/path/to/remote/directory"; - String remoteFilePath = "/radar/" + datePart + "/" + hourPart; - String download = directDownloadToFtp(baseUrl, ftpServer, port, username, password, remoteFilePath, fileName); - DcWarning dcWarning1 = new DcWarning(); - dcWarning1.setId(radar.getId()); - dcWarning1.setRadarUrl(download); - int i = dcWarningService.updateDcWarning(dcWarning1); - } catch (Exception e) { - throw new RuntimeException(e); - } + // 创建一个固定大小的线程池 + ExecutorService executor = Executors.newFixedThreadPool(3); // 线程池大小 + try { + radarList.forEach(radar -> { + if (radar != null && radar.getId() != null) { + executor.submit(() -> processRadarEvent(radar, now)); + } + }); + + // 关闭线程池,并等待所有任务完成 + executor.shutdown(); + executor.awaitTermination(1, TimeUnit.HOURS); // 设置超时时间 + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); // 恢复中断状态 + log.error("线程池关闭过程中发生中断", e); + } finally { + if (!executor.isTerminated()) { + executor.shutdownNow(); // 强制关闭未完成的任务 } - }); + } } + private void processRadarEvent(DcWarning radar, LocalDateTime now) { + try { + // 获取雷达事件视频 + String baseUrl = dcWarningService.getRadarIncidentVideo(radar.getId()); + System.out.println("雷达视频地址:" + baseUrl); + if (baseUrl == null || baseUrl.isEmpty()) { + log.warn("雷达事件ID {} 没有对应的视频URL", radar.getId()); + return; + } + + String ftpServer= configService.selectConfigByKey("FTP-IP");//密钥 + int port= Integer.parseInt(configService.selectConfigByKey("FTP-PORT")); + String username= configService.selectConfigByKey("FTP-USER");//密钥 + String password= configService.selectConfigByKey("FPT-PASSWORD");//密钥 +// String ftpServer = "192.168.3.1"; +// int port = 21; +// String username = "1911390090@qq.com"; +// String password = "989878wxl"; + + String[] split = StringUtils.split(baseUrl, "/"); + // 拼接文件名 + String fileName = split[split.length - 1]; + + DateTimeFormatter dirFormatter = DateTimeFormatter.ofPattern("yyyyMMdd"); + DateTimeFormatter hourFormatter = DateTimeFormatter.ofPattern("HH"); + String datePart = now.format(dirFormatter); + String hourPart = now.format(hourFormatter); + // 文件路径 + String remoteFilePath = "/radar/" + datePart + "/" + hourPart; + String download = directDownloadToFtp(baseUrl, ftpServer, port, username, password, remoteFilePath, fileName); + + DcWarning dcWarning1 = new DcWarning(); + dcWarning1.setId(radar.getId()); + dcWarning1.setRadarUrl(download); + int i = dcWarningService.updateDcWarning(dcWarning1); + if (i <= 0) { + log.error("更新数据库失败,ID: {}", radar.getId()); + } + } catch (Exception e) { + log.error("处理雷达事件ID {} 时发生异常", radar.getId(), e); + } + } public static String directDownloadToFtp(String baseUrl, String ftpServer, int port, String user, String pass, String remotePath, String fileName) throws IOException, URISyntaxException, InterruptedException { FTPClient ftpClient = new FTPClient(); HttpURLConnection httpConn = null; @@ -104,8 +130,7 @@ public class RadarController { System.out.println("encodedUrl: " + encodedUrl); URI uri = new URI(encodedUrl); URL url = uri.toURL(); - // 睡眠3秒钟 - Thread.sleep(3000); // + httpConn = (HttpURLConnection) url.openConnection(); int responseCode = httpConn.getResponseCode(); @@ -115,7 +140,7 @@ public class RadarController { ftpClient.connect(ftpServer, port); boolean loginResult = ftpClient.login(user, pass); if (!loginResult) { - throw new IOException("FTP登录失败"); + log.info("FTP登录失败"); } log.info("成功登录到FTP服务器"); // 设置为二进制传输模式和被动模式 @@ -145,7 +170,7 @@ public class RadarController { log.info("最终工作目录: " + ftpClient.printWorkingDirectory()); } // 上传文件到FTP服务器 - boolean done = ftpClient.storeFile(fileName, inputStream); + boolean done = ftpClient.storeFile(new String(fileName.getBytes("GBK"),"ISO-8859-1"), inputStream); if (done) { log.info("文件上传成功"); return URL+ftpClient.printWorkingDirectory()+"/" + fileName; diff --git a/zc-business/src/main/java/com/zc/business/controller/VideoController.java b/zc-business/src/main/java/com/zc/business/controller/VideoController.java index 707389bf..52570789 100644 --- a/zc-business/src/main/java/com/zc/business/controller/VideoController.java +++ b/zc-business/src/main/java/com/zc/business/controller/VideoController.java @@ -633,6 +633,10 @@ public class VideoController extends BaseController { } } } + }else { + jsonResult.put("code",200); + jsonResult.put("data", new JSONObject()); + jsonResult.put("msg","摄像机连接失败"); } } }catch (Exception e) { diff --git a/zc-business/src/main/java/com/zc/business/domain/DcTrafficSpeedDirectionData.java b/zc-business/src/main/java/com/zc/business/domain/DcTrafficSpeedDirectionData.java new file mode 100644 index 00000000..cab712b5 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/domain/DcTrafficSpeedDirectionData.java @@ -0,0 +1,325 @@ +package com.zc.business.domain; + +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * 一类交调数据对象(分方向) dc_traffic_survey_data + * + * @author liuwenge + * @date 2024-10-29 + */ +public class DcTrafficSpeedDirectionData extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** $column.columnComment */ + private Long id; + + /** 物联设备主键 */ + private String iotDeviceId; + + /** 方向1-上行,2-中,3-下行 */ + private String direction; + + /** 时间 */ + @Excel(name = "时间") + private String time; + + /** 中小客车平均地点车速 */ + @Excel(name = "中小客车-菏泽") + private Integer inAndSmallAverageVehicleSpeedHZ; + + /** 中小客车平均地点车速 */ + @Excel(name = "中小客车-济南") + private Integer inAndSmallAverageVehicleSpeedJN; + + /** 大客车平均地点车速 */ + @Excel(name = "大客车-菏泽") + private Integer averageSpeedOfBusHZ; + + /** 大客车平均地点车速 */ + @Excel(name = "大客车-济南") + private Integer averageSpeedOfBusJN; + + /** 小型货车平均地点车速 */ + @Excel(name = "小型货车-菏泽") + private Integer smallTrucksAverageVehicleSpeedHZ; + + /** 小型货车平均地点车速 */ + @Excel(name = "小型货车-济南") + private Integer smallTrucksAverageVehicleSpeedJN; + + /** 中型货车平均地点车速 */ + @Excel(name = "中型货车-菏泽") + private Integer averageSpeedOfMediumSizeTrucksHZ; + + /** 中型货车平均地点车速 */ + @Excel(name = "中型货车-济南") + private Integer averageSpeedOfMediumSizeTrucksJN; + + /** 大型货车平均地点车速 */ + @Excel(name = "大型货车-菏泽") + private Integer averageSpeedOfLargeTrucksHZ; + + /** 大型货车平均地点车速 */ + @Excel(name = "大型货车-济南") + private Integer averageSpeedOfLargeTrucksJN; + + /** 特大型货车平均地点车速 */ + @Excel(name = "特大型货车-菏泽") + private Integer averageSpeedOfExtraLargeTrucksHZ; + + /** 特大型货车平均地点车速 */ + @Excel(name = "特大型货车-济南") + private Integer averageSpeedOfExtraLargeTrucksJN; + + /** 集装箱车平均地点车速 */ + @Excel(name = "集装箱车-菏泽") + private Integer averageSpeedOfContainerTruckHZ; + + /** 集装箱车平均地点车速 */ + @Excel(name = "集装箱车-济南") + private Integer averageSpeedOfContainerTruckJN; + + /** 摩托车平均地点车速 */ + @Excel(name = "摩托车-菏泽") + private Integer averageSpeedOfMotorcycleHZ; + + /** 摩托车平均地点车速 */ + @Excel(name = "摩托车-济南") + private Integer averageSpeedOfMotorcycleJN; + + /** 拖拉机平均地点车速 */ + @Excel(name = "拖拉机-菏泽") + private Integer averageSpeedOfTractorHZ; + + /** 拖拉机平均地点车速 */ + @Excel(name = "拖拉机-济南") + private Integer averageSpeedOfTractorJN; + + /** 平均地点车速 */ + @Excel(name = "平均车速-菏泽") + private Integer avgSpeedHZ; + + /** 平均地点车速 */ + @Excel(name = "平均车速-济南") + private Integer avgSpeedJN; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getIotDeviceId() { + return iotDeviceId; + } + + public void setIotDeviceId(String iotDeviceId) { + this.iotDeviceId = iotDeviceId; + } + + public String getDirection() { + return direction; + } + + public void setDirection(String direction) { + this.direction = direction; + } + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } + + public Integer getInAndSmallAverageVehicleSpeedHZ() { + return inAndSmallAverageVehicleSpeedHZ; + } + + public void setInAndSmallAverageVehicleSpeedHZ(Integer inAndSmallAverageVehicleSpeedHZ) { + this.inAndSmallAverageVehicleSpeedHZ = inAndSmallAverageVehicleSpeedHZ; + } + + public Integer getInAndSmallAverageVehicleSpeedJN() { + return inAndSmallAverageVehicleSpeedJN; + } + + public void setInAndSmallAverageVehicleSpeedJN(Integer inAndSmallAverageVehicleSpeedJN) { + this.inAndSmallAverageVehicleSpeedJN = inAndSmallAverageVehicleSpeedJN; + } + + public Integer getAverageSpeedOfBusHZ() { + return averageSpeedOfBusHZ; + } + + public void setAverageSpeedOfBusHZ(Integer averageSpeedOfBusHZ) { + this.averageSpeedOfBusHZ = averageSpeedOfBusHZ; + } + + public Integer getAverageSpeedOfBusJN() { + return averageSpeedOfBusJN; + } + + public void setAverageSpeedOfBusJN(Integer averageSpeedOfBusJN) { + this.averageSpeedOfBusJN = averageSpeedOfBusJN; + } + + public Integer getSmallTrucksAverageVehicleSpeedHZ() { + return smallTrucksAverageVehicleSpeedHZ; + } + + public void setSmallTrucksAverageVehicleSpeedHZ(Integer smallTrucksAverageVehicleSpeedHZ) { + this.smallTrucksAverageVehicleSpeedHZ = smallTrucksAverageVehicleSpeedHZ; + } + + public Integer getSmallTrucksAverageVehicleSpeedJN() { + return smallTrucksAverageVehicleSpeedJN; + } + + public void setSmallTrucksAverageVehicleSpeedJN(Integer smallTrucksAverageVehicleSpeedJN) { + this.smallTrucksAverageVehicleSpeedJN = smallTrucksAverageVehicleSpeedJN; + } + + public Integer getAverageSpeedOfMediumSizeTrucksHZ() { + return averageSpeedOfMediumSizeTrucksHZ; + } + + public void setAverageSpeedOfMediumSizeTrucksHZ(Integer averageSpeedOfMediumSizeTrucksHZ) { + this.averageSpeedOfMediumSizeTrucksHZ = averageSpeedOfMediumSizeTrucksHZ; + } + + public Integer getAverageSpeedOfMediumSizeTrucksJN() { + return averageSpeedOfMediumSizeTrucksJN; + } + + public void setAverageSpeedOfMediumSizeTrucksJN(Integer averageSpeedOfMediumSizeTrucksJN) { + this.averageSpeedOfMediumSizeTrucksJN = averageSpeedOfMediumSizeTrucksJN; + } + + public Integer getAverageSpeedOfLargeTrucksHZ() { + return averageSpeedOfLargeTrucksHZ; + } + + public void setAverageSpeedOfLargeTrucksHZ(Integer averageSpeedOfLargeTrucksHZ) { + this.averageSpeedOfLargeTrucksHZ = averageSpeedOfLargeTrucksHZ; + } + + public Integer getAverageSpeedOfLargeTrucksJN() { + return averageSpeedOfLargeTrucksJN; + } + + public void setAverageSpeedOfLargeTrucksJN(Integer averageSpeedOfLargeTrucksJN) { + this.averageSpeedOfLargeTrucksJN = averageSpeedOfLargeTrucksJN; + } + + public Integer getAverageSpeedOfExtraLargeTrucksHZ() { + return averageSpeedOfExtraLargeTrucksHZ; + } + + public void setAverageSpeedOfExtraLargeTrucksHZ(Integer averageSpeedOfExtraLargeTrucksHZ) { + this.averageSpeedOfExtraLargeTrucksHZ = averageSpeedOfExtraLargeTrucksHZ; + } + + public Integer getAverageSpeedOfExtraLargeTrucksJN() { + return averageSpeedOfExtraLargeTrucksJN; + } + + public void setAverageSpeedOfExtraLargeTrucksJN(Integer averageSpeedOfExtraLargeTrucksJN) { + this.averageSpeedOfExtraLargeTrucksJN = averageSpeedOfExtraLargeTrucksJN; + } + + public Integer getAverageSpeedOfContainerTruckHZ() { + return averageSpeedOfContainerTruckHZ; + } + + public void setAverageSpeedOfContainerTruckHZ(Integer averageSpeedOfContainerTruckHZ) { + this.averageSpeedOfContainerTruckHZ = averageSpeedOfContainerTruckHZ; + } + + public Integer getAverageSpeedOfContainerTruckJN() { + return averageSpeedOfContainerTruckJN; + } + + public void setAverageSpeedOfContainerTruckJN(Integer averageSpeedOfContainerTruckJN) { + this.averageSpeedOfContainerTruckJN = averageSpeedOfContainerTruckJN; + } + + public Integer getAverageSpeedOfMotorcycleHZ() { + return averageSpeedOfMotorcycleHZ; + } + + public void setAverageSpeedOfMotorcycleHZ(Integer averageSpeedOfMotorcycleHZ) { + this.averageSpeedOfMotorcycleHZ = averageSpeedOfMotorcycleHZ; + } + + public Integer getAverageSpeedOfMotorcycleJN() { + return averageSpeedOfMotorcycleJN; + } + + public void setAverageSpeedOfMotorcycleJN(Integer averageSpeedOfMotorcycleJN) { + this.averageSpeedOfMotorcycleJN = averageSpeedOfMotorcycleJN; + } + + public Integer getAverageSpeedOfTractorHZ() { + return averageSpeedOfTractorHZ; + } + + public void setAverageSpeedOfTractorHZ(Integer averageSpeedOfTractorHZ) { + this.averageSpeedOfTractorHZ = averageSpeedOfTractorHZ; + } + + public Integer getAverageSpeedOfTractorJN() { + return averageSpeedOfTractorJN; + } + + public void setAverageSpeedOfTractorJN(Integer averageSpeedOfTractorJN) { + this.averageSpeedOfTractorJN = averageSpeedOfTractorJN; + } + + public Integer getAvgSpeedHZ() { + return avgSpeedHZ; + } + + public void setAvgSpeedHZ(Integer avgSpeedHZ) { + this.avgSpeedHZ = avgSpeedHZ; + } + + public Integer getAvgSpeedJN() { + return avgSpeedJN; + } + + public void setAvgSpeedJN(Integer avgSpeedJN) { + this.avgSpeedJN = avgSpeedJN; + } + + public DcTrafficSpeedDirectionData(){} + + public DcTrafficSpeedDirectionData(Integer initData){ + this.inAndSmallAverageVehicleSpeedHZ = initData; + this.inAndSmallAverageVehicleSpeedJN = initData; + this.averageSpeedOfBusHZ = initData; + this.averageSpeedOfBusJN = initData; + this.smallTrucksAverageVehicleSpeedHZ = initData; + this.smallTrucksAverageVehicleSpeedJN = initData; + this.averageSpeedOfMediumSizeTrucksHZ = initData; + this.averageSpeedOfMediumSizeTrucksJN = initData; + this.averageSpeedOfLargeTrucksHZ = initData; + this.averageSpeedOfLargeTrucksJN = initData; + this.averageSpeedOfExtraLargeTrucksHZ = initData; + this.averageSpeedOfExtraLargeTrucksJN = initData; + this.averageSpeedOfContainerTruckHZ = initData; + this.averageSpeedOfContainerTruckJN = initData; + this.averageSpeedOfMotorcycleHZ = initData; + this.averageSpeedOfMotorcycleJN = initData; + this.averageSpeedOfTractorHZ = initData; + this.averageSpeedOfTractorJN = initData; + this.avgSpeedHZ = initData; + this.avgSpeedJN = initData; + } +} diff --git a/zc-business/src/main/java/com/zc/business/domain/DcTrafficVolumeData.java b/zc-business/src/main/java/com/zc/business/domain/DcTrafficVolumeData.java index 2d754aec..c6dab453 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcTrafficVolumeData.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcTrafficVolumeData.java @@ -25,6 +25,9 @@ public class DcTrafficVolumeData extends BaseEntity /** 物联设备主键 */ private String iotDeviceId; + /** 方向 */ + private String direction; + /** 时间 */ @Excel(name = "时间") private String time; @@ -85,6 +88,14 @@ public class DcTrafficVolumeData extends BaseEntity this.iotDeviceId = iotDeviceId; } + public String getDirection() { + return direction; + } + + public void setDirection(String direction) { + this.direction = direction; + } + public String getTime() { return time; } diff --git a/zc-business/src/main/java/com/zc/business/domain/DcTrafficVolumeDirectionData.java b/zc-business/src/main/java/com/zc/business/domain/DcTrafficVolumeDirectionData.java new file mode 100644 index 00000000..0e825ad0 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/domain/DcTrafficVolumeDirectionData.java @@ -0,0 +1,325 @@ +package com.zc.business.domain; + +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * 一类交调数据对象(区分方向) dc_traffic_survey_data + * + * @author liuwenge + * @date 2024-10-29 + */ +public class DcTrafficVolumeDirectionData extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** $column.columnComment */ + private Long id; + + /** 物联设备主键 */ + private String iotDeviceId; + + /** 方向 */ + private String direction; + + /** 时间 */ + @Excel(name = "时间") + private String time; + + /** 中小客车交通量 */ + @Excel(name = "中小客车-菏泽") + private Integer trafficNumberOfInAndSmallHZ; + + /** 中小客车交通量 */ + @Excel(name = "中小客车-济南") + private Integer trafficNumberOfInAndSmallJN; + + /** 大客车交通量 */ + @Excel(name = "大客车-菏泽") + private Integer busTrafficVolumeHZ; + + /** 大客车交通量 */ + @Excel(name = "大客车-济南") + private Integer busTrafficVolumeJN; + + /** 小型货车交通量 */ + @Excel(name = "小型货车-菏泽") + private Integer trafficVolumeOfSmallTrucksHZ; + + /** 小型货车交通量 */ + @Excel(name = "小型货车-济南") + private Integer trafficVolumeOfSmallTrucksJN; + + /** 中型货车交通量 */ + @Excel(name = "中型货车-菏泽") + private Integer mediumTruckTrafficVolumeHZ; + + /** 中型货车交通量 */ + @Excel(name = "中型货车-济南") + private Integer mediumTruckTrafficVolumeJN; + + /** 大型货车交通量 */ + @Excel(name = "大型货车-菏泽") + private Integer largeTruckTrafficVolumeHZ; + + /** 大型货车交通量 */ + @Excel(name = "大型货车-济南") + private Integer largeTruckTrafficVolumeJN; + + /** 特大型货车交通量 */ + @Excel(name = "特大型货车-菏泽") + private Integer extraLargeTrucksTrafficVolumeHZ; + + /** 特大型货车交通量 */ + @Excel(name = "特大型货车-济南") + private Integer extraLargeTrucksTrafficVolumeJN; + + /** 集装箱车交通量 */ + @Excel(name = "集装箱车-菏泽") + private Integer containerTruckTrafficVolumeHZ; + + /** 集装箱车交通量 */ + @Excel(name = "集装箱车-济南") + private Integer containerTruckTrafficVolumeJN; + + /** 摩托车交通量 */ + @Excel(name = "摩托车-菏泽") + private Integer motorcycleTrafficVolumeHZ; + + /** 摩托车交通量 */ + @Excel(name = "摩托车-济南") + private Integer motorcycleTrafficVolumeJN; + + /** 拖拉机交通量 */ + @Excel(name = "拖拉机-菏泽") + private Integer tractorTrafficVolumeHZ; + + /** 拖拉机交通量 */ + @Excel(name = "拖拉机-济南") + private Integer tractorTrafficVolumeJN; + + /** 合计 */ + @Excel(name = "合计-菏泽") + private Integer trafficVolumeHZ; + + /** 合计 */ + @Excel(name = "合计-济南") + private Integer trafficVolumeJN; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getIotDeviceId() { + return iotDeviceId; + } + + public void setIotDeviceId(String iotDeviceId) { + this.iotDeviceId = iotDeviceId; + } + + public String getDirection() { + return direction; + } + + public void setDirection(String direction) { + this.direction = direction; + } + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } + + public Integer getTrafficNumberOfInAndSmallJN() { + return trafficNumberOfInAndSmallJN; + } + + public void setTrafficNumberOfInAndSmallJN(Integer trafficNumberOfInAndSmallJN) { + this.trafficNumberOfInAndSmallJN = trafficNumberOfInAndSmallJN; + } + + public Integer getTrafficNumberOfInAndSmallHZ() { + return trafficNumberOfInAndSmallHZ; + } + + public void setTrafficNumberOfInAndSmallHZ(Integer trafficNumberOfInAndSmallHZ) { + this.trafficNumberOfInAndSmallHZ = trafficNumberOfInAndSmallHZ; + } + + public Integer getBusTrafficVolumeJN() { + return busTrafficVolumeJN; + } + + public void setBusTrafficVolumeJN(Integer busTrafficVolumeJN) { + this.busTrafficVolumeJN = busTrafficVolumeJN; + } + + public Integer getBusTrafficVolumeHZ() { + return busTrafficVolumeHZ; + } + + public void setBusTrafficVolumeHZ(Integer busTrafficVolumeHZ) { + this.busTrafficVolumeHZ = busTrafficVolumeHZ; + } + + public Integer getTrafficVolumeOfSmallTrucksJN() { + return trafficVolumeOfSmallTrucksJN; + } + + public void setTrafficVolumeOfSmallTrucksJN(Integer trafficVolumeOfSmallTrucksJN) { + this.trafficVolumeOfSmallTrucksJN = trafficVolumeOfSmallTrucksJN; + } + + public Integer getTrafficVolumeOfSmallTrucksHZ() { + return trafficVolumeOfSmallTrucksHZ; + } + + public void setTrafficVolumeOfSmallTrucksHZ(Integer trafficVolumeOfSmallTrucksHZ) { + this.trafficVolumeOfSmallTrucksHZ = trafficVolumeOfSmallTrucksHZ; + } + + public Integer getMediumTruckTrafficVolumeJN() { + return mediumTruckTrafficVolumeJN; + } + + public void setMediumTruckTrafficVolumeJN(Integer mediumTruckTrafficVolumeJN) { + this.mediumTruckTrafficVolumeJN = mediumTruckTrafficVolumeJN; + } + + public Integer getMediumTruckTrafficVolumeHZ() { + return mediumTruckTrafficVolumeHZ; + } + + public void setMediumTruckTrafficVolumeHZ(Integer mediumTruckTrafficVolumeHZ) { + this.mediumTruckTrafficVolumeHZ = mediumTruckTrafficVolumeHZ; + } + + public Integer getLargeTruckTrafficVolumeJN() { + return largeTruckTrafficVolumeJN; + } + + public void setLargeTruckTrafficVolumeJN(Integer largeTruckTrafficVolumeJN) { + this.largeTruckTrafficVolumeJN = largeTruckTrafficVolumeJN; + } + + public Integer getLargeTruckTrafficVolumeHZ() { + return largeTruckTrafficVolumeHZ; + } + + public void setLargeTruckTrafficVolumeHZ(Integer largeTruckTrafficVolumeHZ) { + this.largeTruckTrafficVolumeHZ = largeTruckTrafficVolumeHZ; + } + + public Integer getExtraLargeTrucksTrafficVolumeJN() { + return extraLargeTrucksTrafficVolumeJN; + } + + public void setExtraLargeTrucksTrafficVolumeJN(Integer extraLargeTrucksTrafficVolumeJN) { + this.extraLargeTrucksTrafficVolumeJN = extraLargeTrucksTrafficVolumeJN; + } + + public Integer getExtraLargeTrucksTrafficVolumeHZ() { + return extraLargeTrucksTrafficVolumeHZ; + } + + public void setExtraLargeTrucksTrafficVolumeHZ(Integer extraLargeTrucksTrafficVolumeHZ) { + this.extraLargeTrucksTrafficVolumeHZ = extraLargeTrucksTrafficVolumeHZ; + } + + public Integer getContainerTruckTrafficVolumeJN() { + return containerTruckTrafficVolumeJN; + } + + public void setContainerTruckTrafficVolumeJN(Integer containerTruckTrafficVolumeJN) { + this.containerTruckTrafficVolumeJN = containerTruckTrafficVolumeJN; + } + + public Integer getContainerTruckTrafficVolumeHZ() { + return containerTruckTrafficVolumeHZ; + } + + public void setContainerTruckTrafficVolumeHZ(Integer containerTruckTrafficVolumeHZ) { + this.containerTruckTrafficVolumeHZ = containerTruckTrafficVolumeHZ; + } + + public Integer getMotorcycleTrafficVolumeJN() { + return motorcycleTrafficVolumeJN; + } + + public void setMotorcycleTrafficVolumeJN(Integer motorcycleTrafficVolumeJN) { + this.motorcycleTrafficVolumeJN = motorcycleTrafficVolumeJN; + } + + public Integer getMotorcycleTrafficVolumeHZ() { + return motorcycleTrafficVolumeHZ; + } + + public void setMotorcycleTrafficVolumeHZ(Integer motorcycleTrafficVolumeHZ) { + this.motorcycleTrafficVolumeHZ = motorcycleTrafficVolumeHZ; + } + + public Integer getTractorTrafficVolumeJN() { + return tractorTrafficVolumeJN; + } + + public void setTractorTrafficVolumeJN(Integer tractorTrafficVolumeJN) { + this.tractorTrafficVolumeJN = tractorTrafficVolumeJN; + } + + public Integer getTractorTrafficVolumeHZ() { + return tractorTrafficVolumeHZ; + } + + public void setTractorTrafficVolumeHZ(Integer tractorTrafficVolumeHZ) { + this.tractorTrafficVolumeHZ = tractorTrafficVolumeHZ; + } + + public Integer getTrafficVolumeJN() { + return trafficVolumeJN; + } + + public void setTrafficVolumeJN(Integer trafficVolumeJN) { + this.trafficVolumeJN = trafficVolumeJN; + } + + public Integer getTrafficVolumeHZ() { + return trafficVolumeHZ; + } + + public void setTrafficVolumeHZ(Integer trafficVolumeHZ) { + this.trafficVolumeHZ = trafficVolumeHZ; + } + + public DcTrafficVolumeDirectionData(){} + + public DcTrafficVolumeDirectionData(Integer initData){ + this.trafficNumberOfInAndSmallJN = initData; + this.trafficNumberOfInAndSmallHZ = initData; + this.busTrafficVolumeJN = initData; + this.busTrafficVolumeHZ = initData; + this.trafficVolumeOfSmallTrucksJN = initData; + this.trafficVolumeOfSmallTrucksHZ = initData; + this.mediumTruckTrafficVolumeJN = initData; + this.mediumTruckTrafficVolumeHZ = initData; + this.largeTruckTrafficVolumeJN = initData; + this.largeTruckTrafficVolumeHZ = initData; + this.extraLargeTrucksTrafficVolumeJN = initData; + this.extraLargeTrucksTrafficVolumeHZ = initData; + this.containerTruckTrafficVolumeJN = initData; + this.containerTruckTrafficVolumeHZ = initData; + this.motorcycleTrafficVolumeJN = initData; + this.motorcycleTrafficVolumeHZ = initData; + this.tractorTrafficVolumeJN = initData; + this.tractorTrafficVolumeHZ = initData; + this.trafficVolumeJN = initData; + this.trafficVolumeHZ = initData; + } +} diff --git a/zc-business/src/main/java/com/zc/business/enums/TrafficFlowDoorFrameSection.java b/zc-business/src/main/java/com/zc/business/enums/TrafficFlowDoorFrameSection.java new file mode 100644 index 00000000..20758585 --- /dev/null +++ b/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; + } + +} diff --git a/zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java b/zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java index 9a5cb3c7..0e65fbb1 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java +++ b/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; + + Map trafficFlowAtTollTypes(String startDate); + } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcMeteorologicalDetectorDataServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcMeteorologicalDetectorDataServiceImpl.java index b1589c39..d9016490 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcMeteorologicalDetectorDataServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcMeteorologicalDetectorDataServiceImpl.java @@ -1,6 +1,7 @@ package com.zc.business.service.impl; import com.ruoyi.common.utils.DateUtils; +import com.zc.business.domain.DcDevice; import com.zc.business.domain.DcMeteorologicalDetectorData; import com.zc.business.enums.UniversalEnum; import com.zc.business.mapper.DcMeteorologicalDetectorDataMapper; @@ -8,8 +9,10 @@ import com.zc.business.service.IDcMeteorologicalDetectorDataService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.List; -import java.util.Map; +import javax.annotation.Resource; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; /** * 气象检测器数据Service业务层处理 @@ -22,7 +25,8 @@ public class DcMeteorologicalDetectorDataServiceImpl implements IDcMeteorologica { @Autowired private DcMeteorologicalDetectorDataMapper dcMeteorologicalDetectorDataMapper; - + @Resource + private DcDeviceServiceImpl dcDeviceServiceImpl; /** * 查询气象检测器数据 @@ -113,7 +117,36 @@ public class DcMeteorologicalDetectorDataServiceImpl implements IDcMeteorologica @Override public List selectlistAll(DcMeteorologicalDetectorData dcMeteorologicalDetectorData) { - return dcMeteorologicalDetectorDataMapper.selectlistAll(dcMeteorologicalDetectorData); + Map parameter =new HashMap<>(); + + parameter.put("deviceType","3"); + List dcDevices = dcDeviceServiceImpl.devicePileNumberQueryDevice(parameter); + Map deviceStateMap = dcDevices.stream() + .filter(Objects::nonNull) // DcDevice 对象不为空 + .collect(Collectors.toMap( + DcDevice::getIotDeviceId, + Function.identity(), + (existing, replacement) -> existing) // 重复键,默认保留第一个值 + ); + List dcMeteorologicalDetectorDataList = dcMeteorologicalDetectorDataMapper.selectlistAll(dcMeteorologicalDetectorData); + // 遍历气象检测数据并设置对应的设备状态和桩号 + for (DcMeteorologicalDetectorData data : dcMeteorologicalDetectorDataList) { + String iotDeviceId = data.getIotDeviceId(); + if (deviceStateMap.containsKey(iotDeviceId)) { + DcDevice device = deviceStateMap.get(iotDeviceId); + // 设置设备状态 + data.setDeviceState(device.getDeviceState()); + // 设置桩号 + data.setStakeMark(device.getStakeMark()); + } + } + + // 按照桩号排序 + List sortedList = dcMeteorologicalDetectorDataList.stream() + .sorted(Comparator.comparing(DcMeteorologicalDetectorData::getStakeMark)) + .collect(Collectors.toList()); + + return sortedList; } @Override diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java index ab730497..ad5af940 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java +++ b/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.enums.LocationEnum; import com.zc.business.enums.StakeMarkRange; +import com.zc.business.enums.TrafficFlowDoorFrameSection; import com.zc.business.enums.UniversalEnum; import com.zc.business.service.IDcDeviceService; import com.zc.business.service.IDcFacilityService; @@ -932,7 +933,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi // 初始化计数器和描述映射 Map flowCounts = new HashMap<>(); Map 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()); descriptions.put(i, UniversalEnum.EMPTY_STRING.getValue()); } @@ -957,12 +958,12 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi .anyMatch(dcFacility -> dcFacility.getId().equals(dcFacility2.getId())); if (exists) { 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()) - .mapToInt(StakeMarkRange::getIdentification) + .mapToInt(TrafficFlowDoorFrameSection::getIdentification) .findFirst() .orElse(UniversalEnum.ZERO.getNumber()); - String description = getDescriptionByIdentification(identification); + String description = getTrafficFlowDoorFrameSection(identification); descriptions.put(identification, description); flowCounts.put(identification, flowCounts.get(identification) + totalFlow); } @@ -971,9 +972,9 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi } // 构建结果列表 List> mapList = new ArrayList<>(); - for (int i = UniversalEnum.ONE.getNumber(); i <= 16; i++) { + for (int i = UniversalEnum.ONE.getNumber(); i <= 13; i++) { Map map = new HashMap<>(); - map.put("name", getDescriptionByIdentification(i)); + map.put("name", getTrafficFlowDoorFrameSection(i)); map.put("totalFlow", flowCounts.get(i)); mapList.add(map); } @@ -1039,6 +1040,14 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi } 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> queryTheGantryDataByPileNumber(String startDate, String stakeMark) throws HttpException, IOException { @@ -1474,6 +1483,78 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi } } + @Override + public Map trafficFlowAtTollTypes(String startDate) { + Map 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 { // 创建OkHttpClient.Builder实例 diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficSurveyDataServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficSurveyDataServiceImpl.java index 21f95942..c6f1ba1b 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficSurveyDataServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficSurveyDataServiceImpl.java @@ -274,101 +274,338 @@ public class DcTrafficSurveyDataServiceImpl implements IDcTrafficSurveyDataServi return AjaxResult.error("请选择时间类型"); } else if (StringUtils.isEmpty(dcTrafficSurveyDataQueryParams.getDataType())){ return AjaxResult.error("请选择数据类型"); + } else if (StringUtils.isEmpty(dcTrafficSurveyDataQueryParams.getDirection())){ + return AjaxResult.error("请选择方向"); } if (dcTrafficSurveyDataQueryParams.getDataType().equals("1")){ - List dcTrafficVolumeData = dcTrafficSurveyDataMapper.selectTrafficVolume(dcTrafficSurveyDataQueryParams); + //车流量 + List dcTrafficVolumeData = dcTrafficSurveyDataMapper.selectTrafficVolume(dcTrafficSurveyDataQueryParams); if (dcTrafficVolumeData.size() > 0){ - //自然合计值 - DcTrafficVolumeData naturalTotal = new DcTrafficVolumeData(0); - naturalTotal.setTime("自然合计值"); - for (DcTrafficVolumeData dcTrafficVolumeDatum : dcTrafficVolumeData) { - naturalTotal.setTrafficNumberOfInAndSmall(naturalTotal.getTrafficNumberOfInAndSmall() + dcTrafficVolumeDatum.getTrafficNumberOfInAndSmall()); - naturalTotal.setBusTrafficVolume(naturalTotal.getBusTrafficVolume() + dcTrafficVolumeDatum.getBusTrafficVolume()); - naturalTotal.setTrafficVolumeOfSmallTrucks(naturalTotal.getTrafficVolumeOfSmallTrucks() + dcTrafficVolumeDatum.getTrafficVolumeOfSmallTrucks()); - naturalTotal.setMediumTruckTrafficVolume(naturalTotal.getMediumTruckTrafficVolume() + dcTrafficVolumeDatum.getMediumTruckTrafficVolume()); - naturalTotal.setLargeTruckTrafficVolume(naturalTotal.getLargeTruckTrafficVolume() + dcTrafficVolumeDatum.getLargeTruckTrafficVolume()); - naturalTotal.setExtraLargeTrucksTrafficVolume(naturalTotal.getExtraLargeTrucksTrafficVolume() + dcTrafficVolumeDatum.getExtraLargeTrucksTrafficVolume()); - naturalTotal.setContainerTruckTrafficVolume(naturalTotal.getContainerTruckTrafficVolume() + dcTrafficVolumeDatum.getContainerTruckTrafficVolume()); - naturalTotal.setMotorcycleTrafficVolume(naturalTotal.getMotorcycleTrafficVolume() + dcTrafficVolumeDatum.getMotorcycleTrafficVolume()); - naturalTotal.setTractorTrafficVolume(naturalTotal.getTractorTrafficVolume() + dcTrafficVolumeDatum.getTractorTrafficVolume()); - naturalTotal.setTrafficVolume(naturalTotal.getTrafficVolume() + dcTrafficVolumeDatum.getTrafficVolume()); + + //判断是否区分方向 + if (dcTrafficSurveyDataQueryParams.getDirection().equals("1")){ + List result = new ArrayList<>(); + //区分方向时将两个方向的数据合并为一条 + Map> group = dcTrafficVolumeData.stream().collect(Collectors.groupingBy(DcTrafficVolumeData::getTime)); + + for (List value : group.values()) { + DcTrafficVolumeDirectionData dcTrafficVolumeDirectionData = new DcTrafficVolumeDirectionData(0); + dcTrafficVolumeDirectionData.setIotDeviceId(value.get(0).getIotDeviceId()); + dcTrafficVolumeDirectionData.setTime(value.get(0).getTime()); + for (DcTrafficVolumeData trafficVolumeData : value) { + if (trafficVolumeData.getDirection().equals("1")){ + dcTrafficVolumeDirectionData.setTrafficNumberOfInAndSmallHZ(trafficVolumeData.getTrafficNumberOfInAndSmall()); + dcTrafficVolumeDirectionData.setBusTrafficVolumeHZ(trafficVolumeData.getBusTrafficVolume()); + dcTrafficVolumeDirectionData.setTrafficVolumeOfSmallTrucksHZ(trafficVolumeData.getTrafficVolumeOfSmallTrucks()); + dcTrafficVolumeDirectionData.setMediumTruckTrafficVolumeHZ(trafficVolumeData.getMediumTruckTrafficVolume()); + dcTrafficVolumeDirectionData.setLargeTruckTrafficVolumeHZ(trafficVolumeData.getLargeTruckTrafficVolume()); + dcTrafficVolumeDirectionData.setExtraLargeTrucksTrafficVolumeHZ(trafficVolumeData.getExtraLargeTrucksTrafficVolume()); + dcTrafficVolumeDirectionData.setContainerTruckTrafficVolumeHZ(trafficVolumeData.getContainerTruckTrafficVolume()); + dcTrafficVolumeDirectionData.setMotorcycleTrafficVolumeHZ(trafficVolumeData.getMotorcycleTrafficVolume()); + dcTrafficVolumeDirectionData.setTractorTrafficVolumeHZ(trafficVolumeData.getTractorTrafficVolume()); + dcTrafficVolumeDirectionData.setTrafficVolumeHZ(trafficVolumeData.getTrafficVolume()); + } else if (trafficVolumeData.getDirection().equals("3")){ + dcTrafficVolumeDirectionData.setTrafficNumberOfInAndSmallJN(trafficVolumeData.getTrafficNumberOfInAndSmall()); + dcTrafficVolumeDirectionData.setBusTrafficVolumeJN(trafficVolumeData.getBusTrafficVolume()); + dcTrafficVolumeDirectionData.setTrafficVolumeOfSmallTrucksJN(trafficVolumeData.getTrafficVolumeOfSmallTrucks()); + dcTrafficVolumeDirectionData.setMediumTruckTrafficVolumeJN(trafficVolumeData.getMediumTruckTrafficVolume()); + dcTrafficVolumeDirectionData.setLargeTruckTrafficVolumeJN(trafficVolumeData.getLargeTruckTrafficVolume()); + dcTrafficVolumeDirectionData.setExtraLargeTrucksTrafficVolumeJN(trafficVolumeData.getExtraLargeTrucksTrafficVolume()); + dcTrafficVolumeDirectionData.setContainerTruckTrafficVolumeJN(trafficVolumeData.getContainerTruckTrafficVolume()); + dcTrafficVolumeDirectionData.setMotorcycleTrafficVolumeJN(trafficVolumeData.getMotorcycleTrafficVolume()); + dcTrafficVolumeDirectionData.setTractorTrafficVolumeJN(trafficVolumeData.getTractorTrafficVolume()); + dcTrafficVolumeDirectionData.setTrafficVolumeJN(trafficVolumeData.getTrafficVolume()); + } + } + + result.add(dcTrafficVolumeDirectionData); + } + + //自然合计值 + DcTrafficVolumeDirectionData naturalTotal = new DcTrafficVolumeDirectionData(0); + naturalTotal.setTime("自然合计值"); + for (DcTrafficVolumeDirectionData dcTrafficVolumeDirectionDatum : result) { + naturalTotal.setTrafficNumberOfInAndSmallHZ(naturalTotal.getTrafficNumberOfInAndSmallHZ() + dcTrafficVolumeDirectionDatum.getTrafficNumberOfInAndSmallHZ()); + naturalTotal.setTrafficNumberOfInAndSmallJN(naturalTotal.getTrafficNumberOfInAndSmallJN() + dcTrafficVolumeDirectionDatum.getTrafficNumberOfInAndSmallJN()); + naturalTotal.setBusTrafficVolumeHZ(naturalTotal.getBusTrafficVolumeHZ() + dcTrafficVolumeDirectionDatum.getBusTrafficVolumeHZ()); + naturalTotal.setBusTrafficVolumeJN(naturalTotal.getBusTrafficVolumeJN() + dcTrafficVolumeDirectionDatum.getBusTrafficVolumeJN()); + naturalTotal.setTrafficVolumeOfSmallTrucksHZ(naturalTotal.getTrafficVolumeOfSmallTrucksHZ() + dcTrafficVolumeDirectionDatum.getTrafficVolumeOfSmallTrucksHZ()); + naturalTotal.setTrafficVolumeOfSmallTrucksJN(naturalTotal.getTrafficVolumeOfSmallTrucksJN() + dcTrafficVolumeDirectionDatum.getTrafficVolumeOfSmallTrucksJN()); + naturalTotal.setMediumTruckTrafficVolumeHZ(naturalTotal.getMediumTruckTrafficVolumeHZ() + dcTrafficVolumeDirectionDatum.getMediumTruckTrafficVolumeHZ()); + naturalTotal.setMediumTruckTrafficVolumeJN(naturalTotal.getMediumTruckTrafficVolumeJN() + dcTrafficVolumeDirectionDatum.getMediumTruckTrafficVolumeJN()); + naturalTotal.setLargeTruckTrafficVolumeHZ(naturalTotal.getLargeTruckTrafficVolumeHZ() + dcTrafficVolumeDirectionDatum.getLargeTruckTrafficVolumeHZ()); + naturalTotal.setLargeTruckTrafficVolumeJN(naturalTotal.getLargeTruckTrafficVolumeJN() + dcTrafficVolumeDirectionDatum.getLargeTruckTrafficVolumeJN()); + naturalTotal.setExtraLargeTrucksTrafficVolumeHZ(naturalTotal.getExtraLargeTrucksTrafficVolumeHZ() + dcTrafficVolumeDirectionDatum.getExtraLargeTrucksTrafficVolumeHZ()); + naturalTotal.setExtraLargeTrucksTrafficVolumeJN(naturalTotal.getExtraLargeTrucksTrafficVolumeJN() + dcTrafficVolumeDirectionDatum.getExtraLargeTrucksTrafficVolumeJN()); + naturalTotal.setContainerTruckTrafficVolumeHZ(naturalTotal.getContainerTruckTrafficVolumeHZ() + dcTrafficVolumeDirectionDatum.getContainerTruckTrafficVolumeHZ()); + naturalTotal.setContainerTruckTrafficVolumeJN(naturalTotal.getContainerTruckTrafficVolumeJN() + dcTrafficVolumeDirectionDatum.getContainerTruckTrafficVolumeJN()); + naturalTotal.setMotorcycleTrafficVolumeHZ(naturalTotal.getMotorcycleTrafficVolumeHZ() + dcTrafficVolumeDirectionDatum.getMotorcycleTrafficVolumeHZ()); + naturalTotal.setMotorcycleTrafficVolumeJN(naturalTotal.getMotorcycleTrafficVolumeJN() + dcTrafficVolumeDirectionDatum.getMotorcycleTrafficVolumeJN()); + naturalTotal.setTractorTrafficVolumeHZ(naturalTotal.getTractorTrafficVolumeHZ() + dcTrafficVolumeDirectionDatum.getTractorTrafficVolumeHZ()); + naturalTotal.setTractorTrafficVolumeJN(naturalTotal.getTractorTrafficVolumeJN() + dcTrafficVolumeDirectionDatum.getTractorTrafficVolumeJN()); + naturalTotal.setTrafficVolumeHZ(naturalTotal.getTrafficVolumeHZ() + dcTrafficVolumeDirectionDatum.getTrafficVolumeHZ()); + naturalTotal.setTrafficVolumeJN(naturalTotal.getTrafficVolumeJN() + dcTrafficVolumeDirectionDatum.getTrafficVolumeJN()); + } + //折算值 + DcTrafficVolumeDirectionData conversionValue = new DcTrafficVolumeDirectionData(0); + conversionValue.setTime("折算值"); + conversionValue.setTrafficNumberOfInAndSmallHZ(naturalTotal.getTrafficNumberOfInAndSmallHZ()); + conversionValue.setTrafficNumberOfInAndSmallJN(naturalTotal.getTrafficNumberOfInAndSmallJN()); + conversionValue.setBusTrafficVolumeHZ((int) Math.round(naturalTotal.getBusTrafficVolumeHZ() * 1.5)); + conversionValue.setBusTrafficVolumeJN((int) Math.round(naturalTotal.getBusTrafficVolumeJN() * 1.5)); + conversionValue.setTrafficVolumeOfSmallTrucksHZ(naturalTotal.getTrafficVolumeOfSmallTrucksHZ()); + conversionValue.setTrafficVolumeOfSmallTrucksJN(naturalTotal.getTrafficVolumeOfSmallTrucksJN()); + conversionValue.setMediumTruckTrafficVolumeHZ((int) Math.round(naturalTotal.getMediumTruckTrafficVolumeHZ() * 1.5)); + conversionValue.setMediumTruckTrafficVolumeJN((int) Math.round(naturalTotal.getMediumTruckTrafficVolumeJN() * 1.5)); + conversionValue.setLargeTruckTrafficVolumeHZ(naturalTotal.getLargeTruckTrafficVolumeHZ() * 3); + conversionValue.setLargeTruckTrafficVolumeJN(naturalTotal.getLargeTruckTrafficVolumeJN() * 3); + conversionValue.setExtraLargeTrucksTrafficVolumeHZ(naturalTotal.getExtraLargeTrucksTrafficVolumeHZ() * 4); + conversionValue.setExtraLargeTrucksTrafficVolumeJN(naturalTotal.getExtraLargeTrucksTrafficVolumeJN() * 4); + conversionValue.setContainerTruckTrafficVolumeHZ(naturalTotal.getContainerTruckTrafficVolumeHZ() * 4); + conversionValue.setContainerTruckTrafficVolumeJN(naturalTotal.getContainerTruckTrafficVolumeJN() * 4); + conversionValue.setMotorcycleTrafficVolumeHZ(naturalTotal.getMotorcycleTrafficVolumeHZ()); + conversionValue.setMotorcycleTrafficVolumeJN(naturalTotal.getMotorcycleTrafficVolumeJN()); + conversionValue.setTractorTrafficVolumeHZ(naturalTotal.getTractorTrafficVolumeHZ()); + conversionValue.setTractorTrafficVolumeJN(naturalTotal.getTractorTrafficVolumeJN()); + + Integer trafficVolumeHZ = conversionValue.getTrafficNumberOfInAndSmallHZ() + conversionValue.getBusTrafficVolumeHZ() + + conversionValue.getTrafficVolumeOfSmallTrucksHZ() + conversionValue.getMediumTruckTrafficVolumeHZ() + + conversionValue.getLargeTruckTrafficVolumeHZ() + conversionValue.getExtraLargeTrucksTrafficVolumeHZ() + + conversionValue.getContainerTruckTrafficVolumeHZ() + conversionValue.getMotorcycleTrafficVolumeHZ() + + conversionValue.getTractorTrafficVolumeHZ(); + conversionValue.setTrafficVolumeHZ(trafficVolumeHZ); + + Integer trafficVolumeJN = conversionValue.getTrafficNumberOfInAndSmallJN() + conversionValue.getBusTrafficVolumeJN() + + conversionValue.getTrafficVolumeOfSmallTrucksJN() + conversionValue.getMediumTruckTrafficVolumeJN() + + conversionValue.getLargeTruckTrafficVolumeJN() + conversionValue.getExtraLargeTrucksTrafficVolumeJN() + + conversionValue.getContainerTruckTrafficVolumeJN() + conversionValue.getMotorcycleTrafficVolumeJN() + + conversionValue.getTractorTrafficVolumeJN(); + conversionValue.setTrafficVolumeJN(trafficVolumeJN); + + //自然平均值 + DcTrafficVolumeDirectionData naturalAvg = new DcTrafficVolumeDirectionData(0); + naturalAvg.setTime("自然平均值"); + naturalAvg.setTrafficNumberOfInAndSmallHZ(naturalTotal.getTrafficNumberOfInAndSmallHZ() / result.size()); + naturalAvg.setTrafficNumberOfInAndSmallJN(naturalTotal.getTrafficNumberOfInAndSmallJN() / result.size()); + naturalAvg.setBusTrafficVolumeHZ(naturalTotal.getBusTrafficVolumeHZ() / result.size()); + naturalAvg.setBusTrafficVolumeJN(naturalTotal.getBusTrafficVolumeJN() / result.size()); + naturalAvg.setTrafficVolumeOfSmallTrucksHZ(naturalTotal.getTrafficVolumeOfSmallTrucksHZ() / result.size()); + naturalAvg.setTrafficVolumeOfSmallTrucksJN(naturalTotal.getTrafficVolumeOfSmallTrucksJN() / result.size()); + naturalAvg.setMediumTruckTrafficVolumeHZ(naturalTotal.getMediumTruckTrafficVolumeHZ() / result.size()); + naturalAvg.setMediumTruckTrafficVolumeJN(naturalTotal.getMediumTruckTrafficVolumeJN() / result.size()); + naturalAvg.setLargeTruckTrafficVolumeHZ(naturalTotal.getLargeTruckTrafficVolumeHZ() / result.size()); + naturalAvg.setLargeTruckTrafficVolumeJN(naturalTotal.getLargeTruckTrafficVolumeJN() / result.size()); + naturalAvg.setExtraLargeTrucksTrafficVolumeHZ(naturalTotal.getExtraLargeTrucksTrafficVolumeHZ() / result.size()); + naturalAvg.setExtraLargeTrucksTrafficVolumeJN(naturalTotal.getExtraLargeTrucksTrafficVolumeJN() / result.size()); + naturalAvg.setContainerTruckTrafficVolumeHZ(naturalTotal.getContainerTruckTrafficVolumeHZ() / result.size()); + naturalAvg.setContainerTruckTrafficVolumeJN(naturalTotal.getContainerTruckTrafficVolumeJN() / result.size()); + naturalAvg.setMotorcycleTrafficVolumeHZ(naturalTotal.getMotorcycleTrafficVolumeHZ() / result.size()); + naturalAvg.setMotorcycleTrafficVolumeJN(naturalTotal.getMotorcycleTrafficVolumeJN() / result.size()); + naturalAvg.setTractorTrafficVolumeHZ(naturalTotal.getTractorTrafficVolumeHZ() / result.size()); + naturalAvg.setTractorTrafficVolumeJN(naturalTotal.getTractorTrafficVolumeJN() / result.size()); + Integer naturalAvgTrafficVolumeHZ = naturalAvg.getTrafficNumberOfInAndSmallHZ() + naturalAvg.getBusTrafficVolumeHZ() + + naturalAvg.getTrafficVolumeOfSmallTrucksHZ() + naturalAvg.getMediumTruckTrafficVolumeHZ() + + naturalAvg.getLargeTruckTrafficVolumeHZ() + naturalAvg.getExtraLargeTrucksTrafficVolumeHZ() + + naturalAvg.getContainerTruckTrafficVolumeHZ() + naturalAvg.getMotorcycleTrafficVolumeHZ() + + naturalAvg.getTractorTrafficVolumeHZ(); + naturalAvg.setTrafficVolumeHZ(naturalAvgTrafficVolumeHZ); + Integer naturalAvgTrafficVolumeJN = naturalAvg.getTrafficNumberOfInAndSmallJN() + naturalAvg.getBusTrafficVolumeJN() + + naturalAvg.getTrafficVolumeOfSmallTrucksJN() + naturalAvg.getMediumTruckTrafficVolumeJN() + + naturalAvg.getLargeTruckTrafficVolumeJN() + naturalAvg.getExtraLargeTrucksTrafficVolumeJN() + + naturalAvg.getContainerTruckTrafficVolumeJN() + naturalAvg.getMotorcycleTrafficVolumeJN() + + naturalAvg.getTractorTrafficVolumeJN(); + naturalAvg.setTrafficVolumeJN(naturalAvgTrafficVolumeJN); + + result = result.stream().sorted(Comparator.comparing(DcTrafficVolumeDirectionData::getTime)).collect(Collectors.toList()); + result.add(naturalTotal); + result.add(conversionValue); + result.add(naturalAvg); + return AjaxResult.success(result); + } else if (dcTrafficSurveyDataQueryParams.getDirection().equals("2")){ + //自然合计值 + DcTrafficVolumeData naturalTotal = new DcTrafficVolumeData(0); + naturalTotal.setTime("自然合计值"); + for (DcTrafficVolumeData dcTrafficVolumeDatum : dcTrafficVolumeData) { + naturalTotal.setTrafficNumberOfInAndSmall(naturalTotal.getTrafficNumberOfInAndSmall() + dcTrafficVolumeDatum.getTrafficNumberOfInAndSmall()); + naturalTotal.setBusTrafficVolume(naturalTotal.getBusTrafficVolume() + dcTrafficVolumeDatum.getBusTrafficVolume()); + naturalTotal.setTrafficVolumeOfSmallTrucks(naturalTotal.getTrafficVolumeOfSmallTrucks() + dcTrafficVolumeDatum.getTrafficVolumeOfSmallTrucks()); + naturalTotal.setMediumTruckTrafficVolume(naturalTotal.getMediumTruckTrafficVolume() + dcTrafficVolumeDatum.getMediumTruckTrafficVolume()); + naturalTotal.setLargeTruckTrafficVolume(naturalTotal.getLargeTruckTrafficVolume() + dcTrafficVolumeDatum.getLargeTruckTrafficVolume()); + naturalTotal.setExtraLargeTrucksTrafficVolume(naturalTotal.getExtraLargeTrucksTrafficVolume() + dcTrafficVolumeDatum.getExtraLargeTrucksTrafficVolume()); + naturalTotal.setContainerTruckTrafficVolume(naturalTotal.getContainerTruckTrafficVolume() + dcTrafficVolumeDatum.getContainerTruckTrafficVolume()); + naturalTotal.setMotorcycleTrafficVolume(naturalTotal.getMotorcycleTrafficVolume() + dcTrafficVolumeDatum.getMotorcycleTrafficVolume()); + naturalTotal.setTractorTrafficVolume(naturalTotal.getTractorTrafficVolume() + dcTrafficVolumeDatum.getTractorTrafficVolume()); + naturalTotal.setTrafficVolume(naturalTotal.getTrafficVolume() + dcTrafficVolumeDatum.getTrafficVolume()); + } + //折算值 + DcTrafficVolumeData conversionValue = new DcTrafficVolumeData(0); + conversionValue.setTime("折算值"); + conversionValue.setTrafficNumberOfInAndSmall(naturalTotal.getTrafficNumberOfInAndSmall()); + conversionValue.setBusTrafficVolume((int) Math.round(naturalTotal.getBusTrafficVolume() * 1.5)); + conversionValue.setTrafficVolumeOfSmallTrucks(naturalTotal.getTrafficVolumeOfSmallTrucks()); + conversionValue.setMediumTruckTrafficVolume((int) Math.round(naturalTotal.getMediumTruckTrafficVolume() * 1.5)); + conversionValue.setLargeTruckTrafficVolume(naturalTotal.getLargeTruckTrafficVolume() * 3); + conversionValue.setExtraLargeTrucksTrafficVolume(naturalTotal.getExtraLargeTrucksTrafficVolume() * 4); + conversionValue.setContainerTruckTrafficVolume(naturalTotal.getContainerTruckTrafficVolume() * 4); + conversionValue.setMotorcycleTrafficVolume(naturalTotal.getMotorcycleTrafficVolume()); + conversionValue.setTractorTrafficVolume(naturalTotal.getTractorTrafficVolume()); + + Integer trafficVolume = conversionValue.getTrafficNumberOfInAndSmall() + conversionValue.getBusTrafficVolume() + + conversionValue.getTrafficVolumeOfSmallTrucks() + conversionValue.getMediumTruckTrafficVolume() + + conversionValue.getLargeTruckTrafficVolume() + conversionValue.getExtraLargeTrucksTrafficVolume() + + conversionValue.getContainerTruckTrafficVolume() + conversionValue.getMotorcycleTrafficVolume() + + conversionValue.getTractorTrafficVolume(); + conversionValue.setTrafficVolume(trafficVolume); + + //自然平均值 + DcTrafficVolumeData naturalAvg = new DcTrafficVolumeData(0); + naturalAvg.setTime("自然平均值"); + naturalAvg.setTrafficNumberOfInAndSmall(naturalTotal.getTrafficNumberOfInAndSmall() / dcTrafficVolumeData.size()); + naturalAvg.setBusTrafficVolume(naturalTotal.getBusTrafficVolume() / dcTrafficVolumeData.size()); + naturalAvg.setTrafficVolumeOfSmallTrucks(naturalTotal.getTrafficVolumeOfSmallTrucks() / dcTrafficVolumeData.size()); + naturalAvg.setMediumTruckTrafficVolume(naturalTotal.getMediumTruckTrafficVolume() / dcTrafficVolumeData.size()); + naturalAvg.setLargeTruckTrafficVolume(naturalTotal.getLargeTruckTrafficVolume() / dcTrafficVolumeData.size()); + naturalAvg.setExtraLargeTrucksTrafficVolume(naturalTotal.getExtraLargeTrucksTrafficVolume() / dcTrafficVolumeData.size()); + naturalAvg.setContainerTruckTrafficVolume(naturalTotal.getContainerTruckTrafficVolume() / dcTrafficVolumeData.size()); + naturalAvg.setMotorcycleTrafficVolume(naturalTotal.getMotorcycleTrafficVolume() / dcTrafficVolumeData.size()); + naturalAvg.setTractorTrafficVolume(naturalTotal.getTractorTrafficVolume() / dcTrafficVolumeData.size()); + Integer naturalAvgTrafficVolume = naturalAvg.getTrafficNumberOfInAndSmall() + naturalAvg.getBusTrafficVolume() + + naturalAvg.getTrafficVolumeOfSmallTrucks() + naturalAvg.getMediumTruckTrafficVolume() + + naturalAvg.getLargeTruckTrafficVolume() + naturalAvg.getExtraLargeTrucksTrafficVolume() + + naturalAvg.getContainerTruckTrafficVolume() + naturalAvg.getMotorcycleTrafficVolume() + + naturalAvg.getTractorTrafficVolume(); + naturalAvg.setTrafficVolume(naturalAvgTrafficVolume); + + dcTrafficVolumeData.add(naturalTotal); + dcTrafficVolumeData.add(conversionValue); + dcTrafficVolumeData.add(naturalAvg); } - //折算值 - DcTrafficVolumeData conversionValue = new DcTrafficVolumeData(0); - conversionValue.setTime("折算值"); - conversionValue.setTrafficNumberOfInAndSmall(naturalTotal.getTrafficNumberOfInAndSmall()); - conversionValue.setBusTrafficVolume((int) Math.round(naturalTotal.getBusTrafficVolume() * 1.5)); - conversionValue.setTrafficVolumeOfSmallTrucks(naturalTotal.getTrafficVolumeOfSmallTrucks()); - conversionValue.setMediumTruckTrafficVolume((int) Math.round(naturalTotal.getMediumTruckTrafficVolume() * 1.5)); - conversionValue.setLargeTruckTrafficVolume(naturalTotal.getLargeTruckTrafficVolume() * 3); - conversionValue.setExtraLargeTrucksTrafficVolume(naturalTotal.getExtraLargeTrucksTrafficVolume() * 4); - conversionValue.setContainerTruckTrafficVolume(naturalTotal.getContainerTruckTrafficVolume() * 4); - conversionValue.setMotorcycleTrafficVolume(naturalTotal.getMotorcycleTrafficVolume()); - conversionValue.setTractorTrafficVolume(naturalTotal.getTractorTrafficVolume()); - - Integer trafficVolume = conversionValue.getTrafficNumberOfInAndSmall() + conversionValue.getBusTrafficVolume() + - conversionValue.getTrafficVolumeOfSmallTrucks() + conversionValue.getMediumTruckTrafficVolume() + - conversionValue.getLargeTruckTrafficVolume() + conversionValue.getExtraLargeTrucksTrafficVolume() + - conversionValue.getContainerTruckTrafficVolume() + conversionValue.getMotorcycleTrafficVolume() + - conversionValue.getTractorTrafficVolume(); - conversionValue.setTrafficVolume(trafficVolume); - - //自然平均值 - DcTrafficVolumeData naturalAvg = new DcTrafficVolumeData(0); - naturalAvg.setTime("自然平均值"); - naturalAvg.setTrafficNumberOfInAndSmall(naturalTotal.getTrafficNumberOfInAndSmall() / dcTrafficVolumeData.size()); - naturalAvg.setBusTrafficVolume(naturalTotal.getBusTrafficVolume() / dcTrafficVolumeData.size()); - naturalAvg.setTrafficVolumeOfSmallTrucks(naturalTotal.getTrafficVolumeOfSmallTrucks() / dcTrafficVolumeData.size()); - naturalAvg.setMediumTruckTrafficVolume(naturalTotal.getMediumTruckTrafficVolume() / dcTrafficVolumeData.size()); - naturalAvg.setLargeTruckTrafficVolume(naturalTotal.getLargeTruckTrafficVolume() / dcTrafficVolumeData.size()); - naturalAvg.setExtraLargeTrucksTrafficVolume(naturalTotal.getExtraLargeTrucksTrafficVolume() / dcTrafficVolumeData.size()); - naturalAvg.setContainerTruckTrafficVolume(naturalTotal.getContainerTruckTrafficVolume() / dcTrafficVolumeData.size()); - naturalAvg.setMotorcycleTrafficVolume(naturalTotal.getMotorcycleTrafficVolume() / dcTrafficVolumeData.size()); - naturalAvg.setTractorTrafficVolume(naturalTotal.getTractorTrafficVolume() / dcTrafficVolumeData.size()); - Integer naturalAvgTrafficVolume = naturalAvg.getTrafficNumberOfInAndSmall() + naturalAvg.getBusTrafficVolume() + - naturalAvg.getTrafficVolumeOfSmallTrucks() + naturalAvg.getMediumTruckTrafficVolume() + - naturalAvg.getLargeTruckTrafficVolume() + naturalAvg.getExtraLargeTrucksTrafficVolume() + - naturalAvg.getContainerTruckTrafficVolume() + naturalAvg.getMotorcycleTrafficVolume() + - naturalAvg.getTractorTrafficVolume(); - naturalAvg.setTrafficVolume(naturalAvgTrafficVolume); - - dcTrafficVolumeData.add(naturalTotal); - dcTrafficVolumeData.add(conversionValue); - dcTrafficVolumeData.add(naturalAvg); } return AjaxResult.success(dcTrafficVolumeData); } else { + //车速 List dcTrafficSpeedData = dcTrafficSurveyDataMapper.selectSpeed(dcTrafficSurveyDataQueryParams); if (dcTrafficSpeedData.size() > 0){ - DcTrafficSpeedData avgSpeed = new DcTrafficSpeedData(0); - avgSpeed.setTime("车速平均值"); - for (DcTrafficSpeedData dcTrafficSpeedDatum : dcTrafficSpeedData) { - avgSpeed.setInAndSmallAverageVehicleSpeed(avgSpeed.getInAndSmallAverageVehicleSpeed() + dcTrafficSpeedDatum.getInAndSmallAverageVehicleSpeed()); - avgSpeed.setAverageSpeedOfBus(avgSpeed.getAverageSpeedOfBus() + dcTrafficSpeedDatum.getAverageSpeedOfBus()); - avgSpeed.setSmallTrucksAverageVehicleSpeed(avgSpeed.getSmallTrucksAverageVehicleSpeed() + dcTrafficSpeedDatum.getSmallTrucksAverageVehicleSpeed()); - avgSpeed.setAverageSpeedOfMediumSizeTrucks(avgSpeed.getAverageSpeedOfMediumSizeTrucks() + dcTrafficSpeedDatum.getAverageSpeedOfMediumSizeTrucks()); - avgSpeed.setAverageSpeedOfLargeTrucks(avgSpeed.getAverageSpeedOfLargeTrucks() + dcTrafficSpeedDatum.getAverageSpeedOfLargeTrucks()); - avgSpeed.setAverageSpeedOfExtraLargeTrucks(avgSpeed.getAverageSpeedOfExtraLargeTrucks() + dcTrafficSpeedDatum.getAverageSpeedOfExtraLargeTrucks()); - avgSpeed.setAverageSpeedOfContainerTruck(avgSpeed.getAverageSpeedOfContainerTruck() + dcTrafficSpeedDatum.getAverageSpeedOfContainerTruck()); - avgSpeed.setAverageSpeedOfMotorcycle(avgSpeed.getAverageSpeedOfMotorcycle() + dcTrafficSpeedDatum.getAverageSpeedOfMotorcycle()); - avgSpeed.setAverageSpeedOfTractor(avgSpeed.getAverageSpeedOfTractor() + dcTrafficSpeedDatum.getAverageSpeedOfTractor()); - avgSpeed.setAvgSpeed(avgSpeed.getAvgSpeed() + dcTrafficSpeedDatum.getAvgSpeed()); - } + //判断是否区分方向 + if (dcTrafficSurveyDataQueryParams.getDirection().equals("1")) { + List result = new ArrayList<>(); + //区分方向时将两个方向的数据合并为一条 + Map> group = dcTrafficSpeedData.stream().collect(Collectors.groupingBy(DcTrafficSpeedData::getTime)); + + for (List value : group.values()) { + DcTrafficSpeedDirectionData dcTrafficSpeedDirectionData = new DcTrafficSpeedDirectionData(0); + dcTrafficSpeedDirectionData.setIotDeviceId(value.get(0).getIotDeviceId()); + dcTrafficSpeedDirectionData.setTime(value.get(0).getTime()); + + for (DcTrafficSpeedData trafficSpeedData : value) { + if (trafficSpeedData.getDirection().equals("1")){ + dcTrafficSpeedDirectionData.setInAndSmallAverageVehicleSpeedHZ(trafficSpeedData.getInAndSmallAverageVehicleSpeed()); + dcTrafficSpeedDirectionData.setAverageSpeedOfBusHZ(trafficSpeedData.getAverageSpeedOfBus()); + dcTrafficSpeedDirectionData.setSmallTrucksAverageVehicleSpeedHZ(trafficSpeedData.getSmallTrucksAverageVehicleSpeed()); + dcTrafficSpeedDirectionData.setAverageSpeedOfMediumSizeTrucksHZ(trafficSpeedData.getAverageSpeedOfMediumSizeTrucks()); + dcTrafficSpeedDirectionData.setAverageSpeedOfLargeTrucksHZ(trafficSpeedData.getAverageSpeedOfLargeTrucks()); + dcTrafficSpeedDirectionData.setAverageSpeedOfExtraLargeTrucksHZ(trafficSpeedData.getAverageSpeedOfExtraLargeTrucks()); + dcTrafficSpeedDirectionData.setAverageSpeedOfContainerTruckHZ(trafficSpeedData.getAverageSpeedOfContainerTruck()); + dcTrafficSpeedDirectionData.setAverageSpeedOfMotorcycleHZ(trafficSpeedData.getAverageSpeedOfMotorcycle()); + dcTrafficSpeedDirectionData.setAverageSpeedOfTractorHZ(trafficSpeedData.getAverageSpeedOfTractor()); + dcTrafficSpeedDirectionData.setAvgSpeedHZ(trafficSpeedData.getAvgSpeed()); + } else if (trafficSpeedData.getDirection().equals("3")){ + dcTrafficSpeedDirectionData.setInAndSmallAverageVehicleSpeedJN(trafficSpeedData.getInAndSmallAverageVehicleSpeed()); + dcTrafficSpeedDirectionData.setAverageSpeedOfBusJN(trafficSpeedData.getAverageSpeedOfBus()); + dcTrafficSpeedDirectionData.setSmallTrucksAverageVehicleSpeedJN(trafficSpeedData.getSmallTrucksAverageVehicleSpeed()); + dcTrafficSpeedDirectionData.setAverageSpeedOfMediumSizeTrucksJN(trafficSpeedData.getAverageSpeedOfMediumSizeTrucks()); + dcTrafficSpeedDirectionData.setAverageSpeedOfLargeTrucksJN(trafficSpeedData.getAverageSpeedOfLargeTrucks()); + dcTrafficSpeedDirectionData.setAverageSpeedOfExtraLargeTrucksJN(trafficSpeedData.getAverageSpeedOfExtraLargeTrucks()); + dcTrafficSpeedDirectionData.setAverageSpeedOfContainerTruckJN(trafficSpeedData.getAverageSpeedOfContainerTruck()); + dcTrafficSpeedDirectionData.setAverageSpeedOfMotorcycleJN(trafficSpeedData.getAverageSpeedOfMotorcycle()); + dcTrafficSpeedDirectionData.setAverageSpeedOfTractorJN(trafficSpeedData.getAverageSpeedOfTractor()); + dcTrafficSpeedDirectionData.setAvgSpeedJN(trafficSpeedData.getAvgSpeed()); + } + } + result.add(dcTrafficSpeedDirectionData); + } + + result = result.stream().sorted(Comparator.comparing(DcTrafficSpeedDirectionData::getTime)).collect(Collectors.toList()); + + DcTrafficSpeedDirectionData avgSpeed = new DcTrafficSpeedDirectionData(0); + avgSpeed.setTime("车速平均值"); + for (DcTrafficSpeedDirectionData dcTrafficSpeedDatum : result) { + avgSpeed.setInAndSmallAverageVehicleSpeedHZ(avgSpeed.getInAndSmallAverageVehicleSpeedHZ() + dcTrafficSpeedDatum.getInAndSmallAverageVehicleSpeedHZ()); + avgSpeed.setInAndSmallAverageVehicleSpeedJN(avgSpeed.getInAndSmallAverageVehicleSpeedJN() + dcTrafficSpeedDatum.getInAndSmallAverageVehicleSpeedJN()); + avgSpeed.setAverageSpeedOfBusHZ(avgSpeed.getAverageSpeedOfBusHZ() + dcTrafficSpeedDatum.getAverageSpeedOfBusHZ()); + avgSpeed.setAverageSpeedOfBusJN(avgSpeed.getAverageSpeedOfBusJN() + dcTrafficSpeedDatum.getAverageSpeedOfBusJN()); + avgSpeed.setSmallTrucksAverageVehicleSpeedHZ(avgSpeed.getSmallTrucksAverageVehicleSpeedHZ() + dcTrafficSpeedDatum.getSmallTrucksAverageVehicleSpeedHZ()); + avgSpeed.setSmallTrucksAverageVehicleSpeedJN(avgSpeed.getSmallTrucksAverageVehicleSpeedJN() + dcTrafficSpeedDatum.getSmallTrucksAverageVehicleSpeedJN()); + avgSpeed.setAverageSpeedOfMediumSizeTrucksHZ(avgSpeed.getAverageSpeedOfMediumSizeTrucksHZ() + dcTrafficSpeedDatum.getAverageSpeedOfMediumSizeTrucksHZ()); + avgSpeed.setAverageSpeedOfMediumSizeTrucksJN(avgSpeed.getAverageSpeedOfMediumSizeTrucksJN() + dcTrafficSpeedDatum.getAverageSpeedOfMediumSizeTrucksJN()); + avgSpeed.setAverageSpeedOfLargeTrucksHZ(avgSpeed.getAverageSpeedOfLargeTrucksHZ() + dcTrafficSpeedDatum.getAverageSpeedOfLargeTrucksHZ()); + avgSpeed.setAverageSpeedOfLargeTrucksJN(avgSpeed.getAverageSpeedOfLargeTrucksJN() + dcTrafficSpeedDatum.getAverageSpeedOfLargeTrucksJN()); + avgSpeed.setAverageSpeedOfExtraLargeTrucksHZ(avgSpeed.getAverageSpeedOfExtraLargeTrucksHZ() + dcTrafficSpeedDatum.getAverageSpeedOfExtraLargeTrucksHZ()); + avgSpeed.setAverageSpeedOfExtraLargeTrucksJN(avgSpeed.getAverageSpeedOfExtraLargeTrucksJN() + dcTrafficSpeedDatum.getAverageSpeedOfExtraLargeTrucksJN()); + avgSpeed.setAverageSpeedOfContainerTruckHZ(avgSpeed.getAverageSpeedOfContainerTruckHZ() + dcTrafficSpeedDatum.getAverageSpeedOfContainerTruckHZ()); + avgSpeed.setAverageSpeedOfContainerTruckJN(avgSpeed.getAverageSpeedOfContainerTruckJN() + dcTrafficSpeedDatum.getAverageSpeedOfContainerTruckJN()); + avgSpeed.setAverageSpeedOfMotorcycleHZ(avgSpeed.getAverageSpeedOfMotorcycleHZ() + dcTrafficSpeedDatum.getAverageSpeedOfMotorcycleHZ()); + avgSpeed.setAverageSpeedOfMotorcycleJN(avgSpeed.getAverageSpeedOfMotorcycleJN() + dcTrafficSpeedDatum.getAverageSpeedOfMotorcycleJN()); + avgSpeed.setAverageSpeedOfTractorHZ(avgSpeed.getAverageSpeedOfTractorHZ() + dcTrafficSpeedDatum.getAverageSpeedOfTractorHZ()); + avgSpeed.setAverageSpeedOfTractorJN(avgSpeed.getAverageSpeedOfTractorJN() + dcTrafficSpeedDatum.getAverageSpeedOfTractorJN()); + avgSpeed.setAvgSpeedHZ(avgSpeed.getAvgSpeedHZ() + dcTrafficSpeedDatum.getAvgSpeedHZ()); + avgSpeed.setAvgSpeedJN(avgSpeed.getAvgSpeedJN() + dcTrafficSpeedDatum.getAvgSpeedJN()); + } - avgSpeed.setInAndSmallAverageVehicleSpeed(avgSpeed.getInAndSmallAverageVehicleSpeed() / dcTrafficSpeedData.size()); - avgSpeed.setAverageSpeedOfBus(avgSpeed.getAverageSpeedOfBus() / dcTrafficSpeedData.size()); - avgSpeed.setSmallTrucksAverageVehicleSpeed(avgSpeed.getSmallTrucksAverageVehicleSpeed() / dcTrafficSpeedData.size()); - avgSpeed.setAverageSpeedOfMediumSizeTrucks(avgSpeed.getAverageSpeedOfMediumSizeTrucks() / dcTrafficSpeedData.size()); - avgSpeed.setAverageSpeedOfLargeTrucks(avgSpeed.getAverageSpeedOfLargeTrucks() / dcTrafficSpeedData.size()); - avgSpeed.setAverageSpeedOfExtraLargeTrucks(avgSpeed.getAverageSpeedOfExtraLargeTrucks() / dcTrafficSpeedData.size()); - avgSpeed.setAverageSpeedOfContainerTruck(avgSpeed.getAverageSpeedOfContainerTruck() / dcTrafficSpeedData.size()); - avgSpeed.setAverageSpeedOfMotorcycle(avgSpeed.getAverageSpeedOfMotorcycle() / dcTrafficSpeedData.size()); - avgSpeed.setAverageSpeedOfTractor(avgSpeed.getAverageSpeedOfTractor() / dcTrafficSpeedData.size()); - avgSpeed.setAvgSpeed(avgSpeed.getAvgSpeed() / dcTrafficSpeedData.size()); - dcTrafficSpeedData.add(avgSpeed); + avgSpeed.setInAndSmallAverageVehicleSpeedHZ(avgSpeed.getInAndSmallAverageVehicleSpeedHZ() / result.size()); + avgSpeed.setInAndSmallAverageVehicleSpeedJN(avgSpeed.getInAndSmallAverageVehicleSpeedJN() / result.size()); + avgSpeed.setAverageSpeedOfBusHZ(avgSpeed.getAverageSpeedOfBusHZ() / result.size()); + avgSpeed.setAverageSpeedOfBusJN(avgSpeed.getAverageSpeedOfBusJN() / result.size()); + avgSpeed.setSmallTrucksAverageVehicleSpeedHZ(avgSpeed.getSmallTrucksAverageVehicleSpeedHZ() / result.size()); + avgSpeed.setSmallTrucksAverageVehicleSpeedJN(avgSpeed.getSmallTrucksAverageVehicleSpeedJN() / result.size()); + avgSpeed.setAverageSpeedOfMediumSizeTrucksHZ(avgSpeed.getAverageSpeedOfMediumSizeTrucksHZ() / result.size()); + avgSpeed.setAverageSpeedOfMediumSizeTrucksJN(avgSpeed.getAverageSpeedOfMediumSizeTrucksJN() / result.size()); + avgSpeed.setAverageSpeedOfLargeTrucksHZ(avgSpeed.getAverageSpeedOfLargeTrucksHZ() / result.size()); + avgSpeed.setAverageSpeedOfLargeTrucksJN(avgSpeed.getAverageSpeedOfLargeTrucksJN() / result.size()); + avgSpeed.setAverageSpeedOfExtraLargeTrucksHZ(avgSpeed.getAverageSpeedOfExtraLargeTrucksHZ() / result.size()); + avgSpeed.setAverageSpeedOfExtraLargeTrucksJN(avgSpeed.getAverageSpeedOfExtraLargeTrucksJN() / result.size()); + avgSpeed.setAverageSpeedOfContainerTruckHZ(avgSpeed.getAverageSpeedOfContainerTruckHZ() / result.size()); + avgSpeed.setAverageSpeedOfContainerTruckJN(avgSpeed.getAverageSpeedOfContainerTruckJN() / result.size()); + avgSpeed.setAverageSpeedOfMotorcycleHZ(avgSpeed.getAverageSpeedOfMotorcycleHZ() / result.size()); + avgSpeed.setAverageSpeedOfMotorcycleJN(avgSpeed.getAverageSpeedOfMotorcycleJN() / result.size()); + avgSpeed.setAverageSpeedOfTractorHZ(avgSpeed.getAverageSpeedOfTractorHZ() / result.size()); + avgSpeed.setAverageSpeedOfTractorJN(avgSpeed.getAverageSpeedOfTractorJN() / result.size()); + avgSpeed.setAvgSpeedHZ(avgSpeed.getAvgSpeedHZ() / result.size()); + avgSpeed.setAvgSpeedJN(avgSpeed.getAvgSpeedJN() / result.size()); + result.add(avgSpeed); + + return AjaxResult.success(result); + } else { + DcTrafficSpeedData avgSpeed = new DcTrafficSpeedData(0); + avgSpeed.setTime("车速平均值"); + for (DcTrafficSpeedData dcTrafficSpeedDatum : dcTrafficSpeedData) { + avgSpeed.setInAndSmallAverageVehicleSpeed(avgSpeed.getInAndSmallAverageVehicleSpeed() + dcTrafficSpeedDatum.getInAndSmallAverageVehicleSpeed()); + avgSpeed.setAverageSpeedOfBus(avgSpeed.getAverageSpeedOfBus() + dcTrafficSpeedDatum.getAverageSpeedOfBus()); + avgSpeed.setSmallTrucksAverageVehicleSpeed(avgSpeed.getSmallTrucksAverageVehicleSpeed() + dcTrafficSpeedDatum.getSmallTrucksAverageVehicleSpeed()); + avgSpeed.setAverageSpeedOfMediumSizeTrucks(avgSpeed.getAverageSpeedOfMediumSizeTrucks() + dcTrafficSpeedDatum.getAverageSpeedOfMediumSizeTrucks()); + avgSpeed.setAverageSpeedOfLargeTrucks(avgSpeed.getAverageSpeedOfLargeTrucks() + dcTrafficSpeedDatum.getAverageSpeedOfLargeTrucks()); + avgSpeed.setAverageSpeedOfExtraLargeTrucks(avgSpeed.getAverageSpeedOfExtraLargeTrucks() + dcTrafficSpeedDatum.getAverageSpeedOfExtraLargeTrucks()); + avgSpeed.setAverageSpeedOfContainerTruck(avgSpeed.getAverageSpeedOfContainerTruck() + dcTrafficSpeedDatum.getAverageSpeedOfContainerTruck()); + avgSpeed.setAverageSpeedOfMotorcycle(avgSpeed.getAverageSpeedOfMotorcycle() + dcTrafficSpeedDatum.getAverageSpeedOfMotorcycle()); + avgSpeed.setAverageSpeedOfTractor(avgSpeed.getAverageSpeedOfTractor() + dcTrafficSpeedDatum.getAverageSpeedOfTractor()); + avgSpeed.setAvgSpeed(avgSpeed.getAvgSpeed() + dcTrafficSpeedDatum.getAvgSpeed()); + } + + avgSpeed.setInAndSmallAverageVehicleSpeed(avgSpeed.getInAndSmallAverageVehicleSpeed() / dcTrafficSpeedData.size()); + avgSpeed.setAverageSpeedOfBus(avgSpeed.getAverageSpeedOfBus() / dcTrafficSpeedData.size()); + avgSpeed.setSmallTrucksAverageVehicleSpeed(avgSpeed.getSmallTrucksAverageVehicleSpeed() / dcTrafficSpeedData.size()); + avgSpeed.setAverageSpeedOfMediumSizeTrucks(avgSpeed.getAverageSpeedOfMediumSizeTrucks() / dcTrafficSpeedData.size()); + avgSpeed.setAverageSpeedOfLargeTrucks(avgSpeed.getAverageSpeedOfLargeTrucks() / dcTrafficSpeedData.size()); + avgSpeed.setAverageSpeedOfExtraLargeTrucks(avgSpeed.getAverageSpeedOfExtraLargeTrucks() / dcTrafficSpeedData.size()); + avgSpeed.setAverageSpeedOfContainerTruck(avgSpeed.getAverageSpeedOfContainerTruck() / dcTrafficSpeedData.size()); + avgSpeed.setAverageSpeedOfMotorcycle(avgSpeed.getAverageSpeedOfMotorcycle() / dcTrafficSpeedData.size()); + avgSpeed.setAverageSpeedOfTractor(avgSpeed.getAverageSpeedOfTractor() / dcTrafficSpeedData.size()); + avgSpeed.setAvgSpeed(avgSpeed.getAvgSpeed() / dcTrafficSpeedData.size()); + dcTrafficSpeedData.add(avgSpeed); + } } return AjaxResult.success(dcTrafficSpeedData); } diff --git a/zc-business/src/main/resources/mapper/business/DcGantryStatisticsDataMapper.xml b/zc-business/src/main/resources/mapper/business/DcGantryStatisticsDataMapper.xml index 19622a37..ecba750a 100644 --- a/zc-business/src/main/resources/mapper/business/DcGantryStatisticsDataMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcGantryStatisticsDataMapper.xml @@ -5,7 +5,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + @@ -204,75 +204,49 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" diff --git a/zc-business/src/main/resources/mapper/business/DcMeteorologicalDetectorDataMapper.xml b/zc-business/src/main/resources/mapper/business/DcMeteorologicalDetectorDataMapper.xml index c04132fe..4adc7534 100644 --- a/zc-business/src/main/resources/mapper/business/DcMeteorologicalDetectorDataMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcMeteorologicalDetectorDataMapper.xml @@ -200,27 +200,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + +