Browse Source

Merge remote-tracking branch 'origin/develop' into develop

develop
mengff 3 weeks ago
parent
commit
6cf308a163
  1. 13
      zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java
  2. 104
      zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java
  3. 9
      zc-business/src/main/resources/mapper/business/DcWarningMapper.xml

13
zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java

@ -431,6 +431,8 @@ public class DcDeviceController extends BaseController {
Map<String, Double> deviceHourlyAggregates = new TreeMap<>();
List<Map<String, Object>> list = new ArrayList<>();
DecimalFormat decimalFormat = new DecimalFormat("#.##");
decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
// 处理每个数据点
for (Object o : dataArray) {
@ -452,9 +454,10 @@ public class DcDeviceController extends BaseController {
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 formatValue = Double.parseDouble(valueWithoutUnit);
double formatValue = Double.parseDouble(decimalFormat.format(valueWithoutUnit));
// 汇总每个小时的数据
deviceHourlyAggregates.merge(key, formatValue, Double::sum);
@ -489,7 +492,8 @@ public class DcDeviceController extends BaseController {
);
List<DcDevice> dcDevices = dcDeviceService.devicePileNumberQueryDevice(parameters);
Map<String, Double> attributeMap = new HashMap<>();
DecimalFormat decimalFormat = new DecimalFormat("#.##");
decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
for (DcDevice dcDevice : dcDevices) {
String deviceId = dcDevice.getIotDeviceId();
for (String propertyId : propertyIds) {
@ -501,13 +505,12 @@ public class DcDeviceController extends BaseController {
String property = data.get("property").getAsString();
String formatValueStr = data.get("formatValue").getAsString();
String valueWithoutUnit = formatValueStr.replaceAll("[^\\d.]", "");
double value = Double.parseDouble(valueWithoutUnit);
double value = Double.parseDouble(decimalFormat.format(valueWithoutUnit));
attributeMap.merge(property, value, (oldVal, newVal) -> oldVal + newVal);
}
}
}
DecimalFormat decimalFormat = new DecimalFormat("#.##");
decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
// 计算碳减排 碳减排(kg)=光伏发电量(kWh)*0.7119
double carbonEmissionReduction = attributeMap.getOrDefault("theAccumulatedChargeOfTheYear", 0.0) * 0.7119;

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

@ -1,8 +1,6 @@
package com.zc.business.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
@ -11,6 +9,7 @@ import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StakeMarkUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.zc.business.domain.*;
import com.zc.business.domain.export.*;
import com.zc.business.enums.LocationEnum;
@ -19,6 +18,7 @@ import com.zc.business.enums.UniversalEnum;
import com.zc.business.request.DcTrafficMetricsDataRequest;
import com.zc.business.request.DcTrafficSectionDataRequest;
import com.zc.business.service.*;
import com.zc.business.service.impl.DcNoStakeWarningTableServiceImpl;
import com.zc.common.core.httpclient.exception.HttpException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -26,19 +26,19 @@ import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -47,7 +47,7 @@ import java.util.stream.Collectors;
*
* @author xiepufeng
*/
@Component
@Api(tags = "交通数据统计")
@RestController
@RequestMapping("/business/traffic-statistics")
@ -68,6 +68,63 @@ public class DcTrafficStatisticsController extends BaseController {
@Autowired
private IDcGantryMetricsStatisticsDataService dcGantryMetricsStatisticsDataService;
public void TrafficFlowAnomalies() throws HttpException {
IDcTrafficStatisticsService ben = SpringUtils.getBean(IDcTrafficStatisticsService.class);
DcNoStakeWarningTableServiceImpl dcNoStakeWarningTableService = SpringUtils.getBean(DcNoStakeWarningTableServiceImpl.class);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDate date = LocalDate.now();
// 获取一天的开始时间
LocalDateTime startOfDay = LocalDateTime.of(date, LocalTime.MIN);
// 获取一天的结束时间
LocalDateTime endOfDay = LocalDateTime.of(date, LocalTime.of(23, 59, 59));
// 格式化为字符串
String startOfDayStr = startOfDay.format(formatter);
String endOfDayStr = endOfDay.format(formatter);
JSONArray mapList = ben.exampleQueryTrafficFlowAnomalies(startOfDayStr, endOfDayStr);
mapList.forEach(item -> {
// 设置时区
ZoneId zoneId = ZoneId.of("Asia/Shanghai");
Map<String, Object> map = (Map<String, Object>) item;
long occur_time = (long) map.get("occur_time");
long end_time = (long) map.get("end_time");
// 创建一个SimpleDateFormat对象,定义你想要的日期格式
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 使用Date对象将时间戳转换为日期
Date date2 = new Date(occur_time);
Date date3 = new Date(end_time);
// 将Date对象格式化为字符串
String occurTime = sdf.format(date2);
String endTime = sdf.format(date3);
String stakeNum = (String) map.get("opma_stake_num");
int direction = (int) map.get("direction");
DcNoStakeWarningTable dcNoStakeWarningTable = new DcNoStakeWarningTable();
String description = direction == 1 ? "菏泽方向" : "济南方向";
dcNoStakeWarningTable.setWarningDescription(occurTime + " " + stakeNum + " " + description + "发生交通流异常事件");
dcNoStakeWarningTable.setWarningType("3");
Date warningTime = getDate(occurTime, formatter);// 获取开始时间
dcNoStakeWarningTable.setWarningTime(warningTime);
List<DcNoStakeWarningTable> dcNoStakeWarningTables = dcNoStakeWarningTableService.listDcNoStakeWarningTable(dcNoStakeWarningTable, getDate(endOfDayStr, formatter), getDate(startOfDayStr, formatter));
if (dcNoStakeWarningTables.isEmpty()) {
dcNoStakeWarningTableService.addDcNoStakeWarningTable(dcNoStakeWarningTable);
}
});
}
private static Date getDate(String occurTime, DateTimeFormatter formatter) {
// 解析字符串为 LocalDateTime
LocalDateTime localDateTime = LocalDateTime.parse(occurTime, formatter);
// 转换为 Date 对象
Date warningTime = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
return warningTime;
}
/**
* 获取当前交通截面数据
*
@ -192,6 +249,7 @@ public class DcTrafficStatisticsController extends BaseController {
/**
* 交通流统计 列表
*
* @param startDate
* @param endDate
* @param direction
@ -208,9 +266,9 @@ public class DcTrafficStatisticsController extends BaseController {
}
/**
* 全路段双向实时车流量
*
* @param startDate 时间
* @param direction 方向
* @param periodType 时间粒子
@ -225,6 +283,7 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
/**
* 导出全路段双向实时车流量
*
* @param startDate 时间
* @param direction 方向
* @param periodType 时间粒子
@ -290,8 +349,10 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
util.exportExcel(response, list, UniversalEnum.THE_WHOLE_SECTION_TWO_WAY_REAL_TIME_TRAFFIC_FLOW.getValue());
// 将查询结果封装为成功响应并返回
}
/**
* 车流量时段分析
*
* @param startDate 时间
* @param direction 方向
* @param periodType 时间粒子
@ -303,8 +364,10 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
// 将查询结果封装为成功响应并返回
return AjaxResult.success(mapList);
}
/**
* 车流量异常事件流量查询
*
* @param eventId 事件id
*/
@ApiOperation("车流量异常事件流量查询")
@ -314,6 +377,7 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
// 将查询结果封装为成功响应并返回
return AjaxResult.success(mapList);
}
/**
* 交通流统计分析重点数据查询交通流异常信息
*/
@ -327,6 +391,7 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
/**
* 导出车流量时段分析
*
* @param startDate 时间
* @param direction 方向
* @param periodType 时间粒子
@ -401,9 +466,9 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
}
/**
* 导出断面车流量排名
*
* @param startDate 时间
* @param direction 方向
* @param periodType 时间粒子
@ -428,11 +493,11 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
/**
* sectionTrafficIndexAnalysis
*
* @param startDate 时间
* @param direction 方向
* @param periodType 时间粒子
* @param ranking 排名 1 饱和度 2拥挤度 3交通特征指数
*
*/
@ApiOperation("路段交通指标分析")
@GetMapping("/history/sectionTrafficIndexAnalysis")
@ -712,8 +777,7 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
//@PreAuthorize("@ss.hasPermi('system:event:export')")
@Log(title = "导出综合指标", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, @RequestBody ComprehensiveIndexQuery comprehensiveIndexQuery)
{
public void export(HttpServletResponse response, @RequestBody ComprehensiveIndexQuery comprehensiveIndexQuery) {
List<ComprehensiveIndexQuery> list = dcGantryMetricsStatisticsDataService.comprehensiveIndexQuery(comprehensiveIndexQuery);
ExcelUtil<ComprehensiveIndexQuery> util = new ExcelUtil<ComprehensiveIndexQuery>(ComprehensiveIndexQuery.class);
util.exportExcel(response, list, UniversalEnum.EVENT_INFORMATION_DATA.getValue());
@ -798,7 +862,6 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
/**
* 获取车道占有率信息
*
*/
@ApiOperation("获取车道占有率信息")
@GetMapping("/history/lane-occupancy")
@ -808,6 +871,7 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
// 将获取到的交通指标数据封装为成功的结果并返回
return AjaxResult.success(jsonArray);
}
/**
* 断面小时车流量分车型
*/
@ -819,7 +883,9 @@ public AjaxResult sectionHourlyTrafficFlow(String startDate, String endDate) thr
// 将获取到的交通指标数据封装为成功的结果并返回
return AjaxResult.success(jsonArray);
}/**
}
/**
* 各收费站入口分车型车流量
*/
@ApiOperation("各收费站入口分车型小时车流量")
@ -830,6 +896,7 @@ public AjaxResult trafficFlowAtTollStationEntranceHour(String startDate, String
// 将获取到的交通指标数据封装为成功的结果并返回
return AjaxResult.success(jsonArray);
}
/**
* 各收费站入口分车型车流量
*/
@ -948,7 +1015,8 @@ public AjaxResult trafficFlowAtTollStationEntranceHour(String startDate, String
cell.setCellStyle(headerStyle);
cell = row.createCell(UniversalEnum.TWO.getNumber());
cell.setCellValue(UniversalEnum.EMPTY_STRING.getValue());
cell.setCellStyle(headerStyle);;
cell.setCellStyle(headerStyle);
;
cell = row.createCell(UniversalEnum.THREE.getNumber());
cell.setCellValue(UniversalEnum.EXIT.getValue());
cell.setCellStyle(headerStyle);
@ -1056,6 +1124,7 @@ public AjaxResult trafficFlowAtTollStationEntrance(String startDate, String endD
return AjaxResult.success(jsonArray);
}
/**
* 全路段双向实时车流量
*/
@ -1066,6 +1135,7 @@ public AjaxResult trafficFlowAtTollStationEntrance(String startDate, String endD
// 将查询结果封装为成功响应并返回
return AjaxResult.success(mapList);
}
@ApiOperation("按照桩号查询门架数据 ")
@GetMapping("/history/queryTheGantryDataByPileNumber")
public AjaxResult queryTheGantryDataByPileNumber(String startDate, String stakeMark) throws HttpException, IOException {
@ -1073,8 +1143,10 @@ public AjaxResult trafficFlowAtTollStationEntrance(String startDate, String endD
// 将查询结果封装为成功响应并返回
return AjaxResult.success(mapList);
}
/**
* 获取据库中 收费站统计数据
*
* @param startDate 时间
* @param accessType 出入口 1入 2出
* @param periodType 方向
@ -1086,6 +1158,7 @@ public AjaxResult trafficFlowAtTollStationEntrance(String startDate, String endD
// 将查询结果封装为成功响应并返回
return AjaxResult.success(mapList);
}
@ApiOperation("获取据库中收费站数数据")
@GetMapping("/history/TollBoothStatisticsList")
public AjaxResult TollBoothStatisticsList(String startDate, String accessType, String periodType) throws HttpException, IOException {
@ -1157,7 +1230,8 @@ public AjaxResult trafficFlowAtTollStationEntrance(String startDate, String endD
cell.setCellStyle(headerStyle);
cell = row.createCell(UniversalEnum.TWO.getNumber());
cell.setCellValue(UniversalEnum.EMPTY_STRING.getValue());
cell.setCellStyle(headerStyle);;
cell.setCellStyle(headerStyle);
;
cell = row.createCell(UniversalEnum.THREE.getNumber());
cell.setCellValue(UniversalEnum.DIRECTION_OF_HEZE.getValue());
cell.setCellStyle(headerStyle);

9
zc-business/src/main/resources/mapper/business/DcWarningMapper.xml

@ -457,8 +457,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
UNION ALL
SELECT 'Weather Warning' AS WarningTypeSource, id, warning_description, warning_type, warning_time, create_time, other_config
FROM dc_no_stake_warning_table
WHERE warning_type = 2
AND warning_time >= DATE_SUB(CURDATE(), INTERVAL 3 DAY)
WHERE warning_type = 2 AND warning_time >= DATE_SUB(CURDATE(), INTERVAL 3 DAY)
UNION ALL
SELECT 'TrafficFlow' AS WarningTypeSource, id, warning_description, warning_type, warning_time, create_time, other_config
FROM dc_no_stake_warning_table
WHERE warning_type = 3
AND warning_time >= DATE_SUB(CURDATE(), INTERVAL 2 DAY)
ORDER BY warning_time DESC
</select>

Loading…
Cancel
Save