Browse Source

Merge branch 'develop' of http://39.106.31.193:9211/mengff/jihe-dc into develop

develop
xiepufeng 1 year ago
parent
commit
7673acdfee
  1. 2
      ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java
  2. 44
      ruoyi-common/src/main/java/com/ruoyi/common/utils/StakeMarkUtils.java
  3. 109
      zc-business/src/main/java/com/zc/business/controller/DcTrafficIncidentsController.java
  4. 181
      zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java
  5. 147
      zc-business/src/main/java/com/zc/business/controller/StatusController.java
  6. 319
      zc-business/src/main/java/com/zc/business/controller/VideoController.java
  7. 2
      zc-business/src/main/java/com/zc/business/domain/DcEventAccident.java
  8. 65
      zc-business/src/main/java/com/zc/business/domain/Device.java
  9. 205
      zc-business/src/main/java/com/zc/business/domain/Status.java
  10. 91
      zc-business/src/main/java/com/zc/business/mapper/DcTrafficIncidentsMapper.java
  11. 16
      zc-business/src/main/java/com/zc/business/mapper/DeviceMapper.java
  12. 21
      zc-business/src/main/java/com/zc/business/mapper/StatusMapper.java
  13. 94
      zc-business/src/main/java/com/zc/business/service/IDcTrafficIncidentsService.java
  14. 304
      zc-business/src/main/java/com/zc/business/service/impl/DcTrafficIncidentsServiceImpl.java
  15. 23
      zc-business/src/main/java/com/zc/business/service/impl/DeviceService.java
  16. 192
      zc-business/src/main/java/com/zc/business/service/impl/ExcelExportService.java
  17. 33
      zc-business/src/main/java/com/zc/business/service/impl/StatusService.java
  18. 296
      zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml
  19. 16
      zc-business/src/main/resources/mapper/business/DeviceMapper.xml
  20. 94
      zc-business/src/main/resources/mapper/business/StatusMapper.xml

2
ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java

@ -157,7 +157,7 @@ public class Constants
/**
* 定时任务白名单配置仅允许访问的包名如其他需要可以自行添加
*/
public static final String[] JOB_WHITELIST_STR = { "com.ruoyi" };
public static final String[] JOB_WHITELIST_STR = { "com.ruoyi","com.zc" };
/**
* 定时任务违规的字符

44
ruoyi-common/src/main/java/com/ruoyi/common/utils/StakeMarkUtils.java

@ -0,0 +1,44 @@
package com.ruoyi.common.utils;
import java.math.BigDecimal;
import java.math.RoundingMode;
/**
* @Description 桩号距离计算工具
*
* @author liuwenge
* @date 2024/1/17 14:43
*/
public class StakeMarkUtils {
/**
* @Description 计算桩号距离(公里)
*
* @author liuwenge
* @date 2024/1/17 14:45
* @param startStakeMark 开始桩号
* @param endStakeMark 结束桩号
* @return java.math.BigDecimal 距离
*/
public static BigDecimal getKilometre(String startStakeMark, String endStakeMark){
String start = startStakeMark.toLowerCase().replace("k","").replace("+",".");
String end = endStakeMark.toLowerCase().replace("k","").replace("+",".");
return new BigDecimal(end).subtract(new BigDecimal(start)).setScale(3, RoundingMode.HALF_UP);
}
/**
* @Description 计算桩号距离()
*
* @author liuwenge
* @date 2024/1/17 15:04
* @param startStakeMark 开始桩号
* @param endStakeMark 结束桩号
* @return java.math.BigDecimal 距离
*/
public static BigDecimal getMetre(String startStakeMark, String endStakeMark){
String start = startStakeMark.toLowerCase().replace("k","").replace("+",".");
String end = endStakeMark.toLowerCase().replace("k","").replace("+",".");
return new BigDecimal(end).subtract(new BigDecimal(start)).multiply(new BigDecimal("1000")).setScale(0, RoundingMode.HALF_UP);
}
}

109
zc-business/src/main/java/com/zc/business/controller/DcTrafficIncidentsController.java

@ -6,10 +6,9 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* @Description 交通事件统计
@ -82,16 +81,114 @@ public class DcTrafficIncidentsController {
}
/**
* @Description 路网管控-事件管控分析-统计各类型的交通事件数量
* @Description 路网管控-事件管控分析-事件类型分析占比
*
* @author liuwenge
* @date 2024/1/13 15:07
* @param
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@ApiOperation("统计各类型的交通事件数量")
@ApiOperation("事件类型分析占比")
@GetMapping("/getAllEventNum")
public AjaxResult getAllEventNum(){
return trafficIncidentsService.getAllEventNum();
}
/**
* @Description 路网管控-事件管控分析-事件源分析占比
*
* @author liuwenge
* @date 2024/1/13 15:07
* @param
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@ApiOperation("事件源分析占比")
@GetMapping("/getEventSourceRatio")
public AjaxResult getEventSourceRatio(){
return trafficIncidentsService.getEventSourceRatio();
}
/**
* @Description 路网管控-事件管控分析-今日事件趋势
*
* @author liuwenge
* @date 2024/1/15 14:30
* @param
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@ApiOperation("今日事件趋势")
@GetMapping("/getEventTrend")
public AjaxResult getEventTrend(){
return trafficIncidentsService.getEventTrend();
}
/**
* @Description 路网管控-事件管控分析-事故车型分析
*
* @author liuwenge
* @date 2024/1/15 15:38
* @param
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@ApiOperation("事故车型分析")
@GetMapping("/getAccidentVehicleAnalysis")
public AjaxResult getAccidentVehicleAnalysis(){
return trafficIncidentsService.getAccidentVehicleAnalysis();
}
/**
* @Description 路网管控-事件管控分析-收费站统计分析table
*
* @author liuwenge
* @date 2024/1/15 17:31
* @param params
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@ApiOperation("收费站统计分析table")
@PostMapping("/selectTollStationAnalysis")
public AjaxResult selectTollStationAnalysis(@RequestBody Map<String,Object> params){
return trafficIncidentsService.selectTollStationAnalysis(params);
}
/**
* @Description 路网管控-事件管控分析-收费站统计分析echarts(当月)
*
* @author liuwenge
* @date 2024/1/16 11:09
* @param
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@ApiOperation("收费站统计分析echarts(当月)")
@GetMapping("/getTollStationAnalysis")
public AjaxResult getTollStationAnalysis(){
return trafficIncidentsService.getTollStationAnalysis();
}
/**
* @Description 路网管控-事件管控分析-事故多发路段分析
*
* @author liuwenge
* @date 2024/1/16 15:52
* @param params
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@ApiOperation("事故多发路段分析")
@PostMapping("/selectRoadSectionAnalysis")
public AjaxResult selectRoadSectionAnalysis(@RequestBody Map<String,Object> params){
return trafficIncidentsService.selectRoadSectionAnalysis(params);
}
/**
* @Description 路网管控-事件管控分析-事故类型分析
*
* @author liuwenge
* @date 2024/1/16 15:52
* @param params
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@ApiOperation("事故类型分析")
@PostMapping("/selectEventTypeAnalysis")
public AjaxResult selectEventTypeAnalysis(@RequestBody Map<String,Object> params){
return trafficIncidentsService.selectEventTypeAnalysis(params);
}
}

181
zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java

@ -0,0 +1,181 @@
package com.zc.business.controller;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.zc.business.service.impl.DeviceService;
import com.zc.business.service.impl.ExcelExportService;
import com.zc.business.service.impl.StatusService;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;
import com.zc.business.domain.Status;
import com.zc.business.domain.Device;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;
import java.util.stream.Collectors;
@Component
@EnableScheduling
public class DeviceStatus {
@Autowired
private DeviceService deviceService;
@Autowired
private StatusService statusService;
@Autowired
private ExcelExportService excelExportService;
//每天凌晨0点到晚上23点整点测试设备状态
// @Scheduled(cron = "0 0 0-23 * * ?")
// @Scheduled(cron = "0 0 1,5,7,8,11,14,17,19,21,23")
public void deviceStatus() {
DeviceService deviceService= SpringUtils.getBean(DeviceService.class);
StatusService statusService= SpringUtils.getBean(StatusService.class);
ExecutorService executor = Executors.newFixedThreadPool(100);
List<Device> deviceList = deviceService.SelectList();
List<Future<Void>> futures = new ArrayList<>();
for (Device device : deviceList) {
Callable<Void> task = () -> {
try {
Status status = new Status();
InetAddress address = InetAddress.getByName(device.getDeviceIp());
String lostRate = getPingPacketLossRate(device.getDeviceIp());
boolean reachable = address.isReachable(5000); // Timeout: 5 seconds
status.setDeviceNo(device.getDeviceNo());
status.setDeviceName(device.getDeviceName());
status.setDeviceIp(device.getDeviceIp());
LocalDateTime localDateTime = LocalDateTime.now();
status.setTime(localDateTime);
status.setLostRate(lostRate);
if (reachable) {
status.setDeviceStatus(1);
status.setSuccessRate("100.00%");
} else {
status.setDeviceStatus(0);
status.setSuccessRate("0.00%");
}
statusService.Add(status);
} catch (IOException e) {
System.out.println("Error pinging " + device.getDeviceIp() + ": " + e.getMessage());
}
return null;
};
futures.add(executor.submit(task));
}
for (Future<Void> future : futures) {
try {
future.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
executor.shutdown();
}
/**
* 计算丢包率
*/
public String getPingPacketLossRate(String ipAddress) {
try {
// Execute the ping command
Process process = Runtime.getRuntime().exec("ping -c 4 " + ipAddress); // Sending 4 ICMP Echo Request packets
// Read the output of the command
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
int packetsSent = 0;
int packetsLost = 0;
while ((line = reader.readLine()) != null) {
// Check for lines containing packet loss information
if (line.contains("packets transmitted")) {
// Extract the number of packets sent and lost
String[] stats = line.split(", ");
packetsSent = Integer.parseInt(stats[0].split(" ")[0]);
packetsLost = Integer.parseInt(stats[0].split(" ")[0])-Integer.parseInt(stats[1].split(" ")[0]);
}
}
// Calculate and return the packet loss rate
if (packetsSent > 0) {
return String.format("%.2f%%", (double) packetsLost / packetsSent * 100);
} else {
return "0.00%"; // No packets sent
}
} catch (IOException e) {
e.printStackTrace();
return "-1.00%"; // Error occurred
}
}
/**
* 成功率和丢包率按小时分组
* 每天17点 23点 30分导出excel表
*/
// @Scheduled(cron = "0 30 17,23 * * ?")
public void calculateSuccessRate() {
StatusService statusService= SpringUtils.getBean(StatusService.class);
ExcelExportService excelExportService= SpringUtils.getBean(ExcelExportService.class);
LocalDateTime todayStart = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
LocalDateTime currentTime = LocalDateTime.now();
Status status = new Status();
status.setStartTime(todayStart);
status.setTime(currentTime);
List<Status> listStatus = statusService.list(status);
//根据时间分组
Map<Integer, List<Status>> map = listStatus.stream()
.collect(Collectors.groupingBy(Status -> Status.getTime().getHour()));
//根据类型分组
Map<String, List<Status>> maps = listStatus.stream().filter(iteam->iteam.getType()!=null).collect(Collectors.groupingBy(Status::getType));
String filePath=CreateNamedExcel();
excelExportService.exportDataToExcel(map,maps,filePath);
}
public String CreateNamedExcel() {
LocalDateTime dateTime = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateTime = dateTime.format(formatter);
//修改成服务器地址
String filePath = "/Users/mengfanfeng/Downloads/excel/"+formattedDateTime+"--deviceStatus.xlsx";
try (Workbook workbook = new XSSFWorkbook()) {
FileOutputStream fileOut = new FileOutputStream(filePath);
workbook.write(fileOut);
System.out.println("Empty named Excel created successfully.");
} catch (IOException e) {
e.printStackTrace();
}
return filePath;
}
}

147
zc-business/src/main/java/com/zc/business/controller/StatusController.java

@ -0,0 +1,147 @@
package com.zc.business.controller;
import com.ruoyi.common.core.domain.AjaxResult;
import com.zc.business.domain.Status;
import com.zc.business.service.impl.StatusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
@Api("设备状态")
@RestController
@RequestMapping("/system/status")
public class StatusController {
@Autowired
private StatusService statusService;
//设备列表
@ApiOperation("设备状态柱状按时间和类型")
@GetMapping ("/tablist")
public AjaxResult getTabList(Status status)
{
LocalDateTime todayStart = status.getStartTime().truncatedTo(ChronoUnit.DAYS);
LocalDateTime currentTime = status.getTime().truncatedTo(ChronoUnit.DAYS).plusDays(1);
status.setStartTime(todayStart);
status.setTime(currentTime);
List<Status> listStatus = statusService.list(status);
return AjaxResult.success(listStatus);
}
//按时间划分设备柱状图
@ApiOperation("设备状态列表按时间和类型")
@GetMapping ("/list")
public AjaxResult getStatusList(Status status)
{
LocalDateTime todayStart = status.getStartTime().truncatedTo(ChronoUnit.DAYS);
LocalDateTime currentTime = status.getTime().truncatedTo(ChronoUnit.DAYS).plusDays(1);
status.setStartTime(todayStart);
status.setTime(currentTime);
String type=status.getType();
List<Status> listStatus = statusService.list(status);
List<Status> listStatu=listStatus.stream().filter(iteam ->iteam.getType()!=null && iteam.getType().equals(type)).collect(Collectors.toList());
//根据时间分组
Map<String, List<Status>> map = listStatu.stream()
.collect(Collectors.groupingBy(Status -> (Status.getTime().getYear()+"-"+Status.getTime().getMonthValue()+"-"+Status.getTime().getDayOfYear())));
//根据类型分组
// Map<String, List<Status>> maps = listStatu.stream().filter(iteam->iteam.getType()!=null).collect(Collectors.groupingBy(Status::getType));
//生成有序map
Map<String, List<Status>> mapTime = new TreeMap<>(map);
Map<String,String> mapSort=new TreeMap<>();
for (Map.Entry<String, List<Status>> entry : mapTime.entrySet()) {
List<Status> groupItems = entry.getValue();
long count = groupItems.stream().filter(iteam -> iteam.getDeviceStatus() == 1).count();
String onlineRate=String.format("%.2f%%", (double) count / groupItems.size() * 100);
mapSort.put(entry.getKey(),onlineRate);
}
// Map<String, List<Status>> mapStatus = new TreeMap<>(maps);
return AjaxResult.success(mapSort);
}
//按类型划分设备
@ApiOperation("设备状态列表按类型")
@GetMapping ("/type")
public AjaxResult getTypeList()
{
HashMap<String, String> itemTypeMap = new HashMap<>();
itemTypeMap.put("1", "高清网络枪型固定摄像机");
itemTypeMap.put("2", "高清网络球形摄像机");
itemTypeMap.put("3", "桥下高清网络球形摄像机");
itemTypeMap.put("4", "360°全景摄像机");
itemTypeMap.put("5", "180°全景摄像机");
itemTypeMap.put("6", "门架式可变信息标志");
itemTypeMap.put("7", "雨棚可变信息标志");
itemTypeMap.put("8", "站前悬臂式可变信息标志");
itemTypeMap.put("9", "气象检测器");
itemTypeMap.put("10", "路段语音广播系统");
itemTypeMap.put("11", "护栏碰撞预警系统");
itemTypeMap.put("12", "毫米波雷达");
itemTypeMap.put("13", "合流区预警系统");
itemTypeMap.put("14", "激光疲劳唤醒");
itemTypeMap.put("15", "一类交通量调查站");
itemTypeMap.put("16", "智能行车诱导系统");
itemTypeMap.put("17", "智能设备箱");
LocalDateTime todayStart = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
LocalDateTime currentTime = LocalDateTime.now();
Status status = new Status();
status.setStartTime(todayStart);
status.setTime(currentTime);
List<Status> listStatus = statusService.list(status);
//根据时间分组
Map<Integer, List<Status>> map = listStatus.stream()
.collect(Collectors.groupingBy(Status -> Status.getTime().getHour()));
Map<Integer, List<Status>> ipMap = new TreeMap<>(map);
Integer lastKey = Collections.max(ipMap.keySet());
List<Status> lastEntry = ipMap.get(lastKey);
Map<String, List<Status>> typeMap = lastEntry.stream().filter(iteam -> iteam.getType() != null).collect(Collectors.groupingBy(Status::getType));
Map<String,Map<String,String>> subMap=new HashMap<>();
for (Map.Entry<String, List<Status>> entrys : typeMap.entrySet()) {
Map<String, String> maps=new HashMap<>();
List<Status> groupItems = entrys.getValue();
double lostRate = groupItems.stream()
.mapToDouble(Status -> Double.parseDouble(Status.getLostRate().replace("%", ""))) // 去掉%,并转换为double
.average().getAsDouble();
double sucessRate = groupItems.stream()
.mapToDouble(Status -> Double.parseDouble(Status.getSuccessRate().replace("%", ""))) // 去掉%,并转换为double
.average().getAsDouble();
String failRate=String.format("%.2f", (100-sucessRate))+"%";
//丢包率
maps.put("lostRate",String.format("%.2f", lostRate)+"%");
//在线率
maps.put("sucessRate",String.format("%.2f", sucessRate)+"%");
//离线率
maps.put("failRate",failRate);
//总数
maps.put("sum",String.valueOf(groupItems.size()));
subMap.put(itemTypeMap.get(entrys.getKey()),maps);
}
Map<String, String> maps=new HashMap<>();
double lostRate = lastEntry.stream()
.mapToDouble(Status -> Double.parseDouble(Status.getLostRate().replace("%", ""))) // 去掉%,并转换为double
.average().getAsDouble();
double sucessRate = lastEntry.stream()
.mapToDouble(Status -> Double.parseDouble(Status.getSuccessRate().replace("%", ""))) // 去掉%,并转换为double
.average().getAsDouble();
String failRate=String.format("%.2f", (100-sucessRate))+"%";
//丢包率
maps.put("lostRate",String.format("%.2f", lostRate)+"%");
//在线率
maps.put("sucessRate",String.format("%.2f", sucessRate)+"%");
//离线率
maps.put("failRate",failRate);
//总数
maps.put("sum",String.valueOf(lastEntry.size()));
subMap.put("全部设备",maps);
return AjaxResult.success(subMap);
}
}

319
zc-business/src/main/java/com/zc/business/controller/VideoController.java

@ -0,0 +1,319 @@
package com.zc.business.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.zc.common.core.httpclient.OkHttp;
import com.zc.common.core.httpclient.exception.HttpException;
import com.zc.common.core.httpclient.request.RequestParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import okhttp3.Response;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.ruoyi.common.constant.Constants.HTTP;
/**
* License
*
* @author Athena-xiepufeng
*/
@Api(tags = "视频接口")
@RestController
@RequestMapping("/video")
public class VideoController extends BaseController {
private static final String USERNAME = "jhgskj";
private static final String PASSWORD = "jhgskj@2023";
private static String TOKEN;
private final static String URL = HTTP + "10.166.147.60:9021";
public static final Integer UNAUTHORIZED = 401;
public static final Integer ERROR = 500;
/**
* 查询附近相机
*/
@ApiOperation("查询附近相机")
@GetMapping(value = "/nearCamListDistance")
public JSONObject nearCamListDistance(@ApiParam(value = "纬度", name = "devLat",required = true)String devLat,
@ApiParam(value = "经度", name = "devLon",required = true)String devLon) throws HttpException, IOException {
JSONObject jsonResult = null;
// 1000 米
String distance = "1000";
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams();
requestParams.put("devLat", devLat);
requestParams.put("devLon", devLon);
requestParams.put("distance", distance);
Map<String, String> header = new HashMap<>();
if (VideoController.TOKEN == null) {
getToken();
}
header.put("Authorization", TOKEN);
Response response // 请求响应
= okHttp
.headers(header)
.url(URL + "/videoInfo/api/nearCamListDistance") // 请求地址
.data(requestParams) // 请求参数
.get(); // 请求方法
if (response.body() != null) {
jsonResult = JSONObject.parseObject(response.body().string());
if (jsonResult.containsKey("code") && UNAUTHORIZED.equals(jsonResult.getInteger("code"))) {
getToken();
okHttp.get();
if (response.body() != null) {
jsonResult = JSONObject.parseObject(response.body().string());
}
}
}
return jsonResult;
}
/**
* 根据桩号查询附近相机
*/
@ApiOperation("根据桩号查询附近相机")
@GetMapping(value = "/nearCamListPileNum")
public Object nearCamListPileNum(@ApiParam(value = "桩号", name = "pileNum", required = true) String pileNum) throws HttpException, IOException {
// 获取济菏运管中心相机信息
JSONObject camInfo = getCamByDept("1301730");
if (!camInfo.containsKey("data")) {
return camInfo;
}
JSONArray camData = camInfo.getJSONArray("data");
List<Object> resultList = new ArrayList<>();
camData.forEach(item -> {
JSONObject jsonObject = (JSONObject) item;
if (isNearbyPileNum(pileNum, jsonObject.getString("pileNum"))) {
resultList.add(item);
}
});
return AjaxResult.success(resultList);
}
/**
* 获取视频流信息
*/
@ApiOperation("获取视频流信息")
@GetMapping(value = "/externalVideoStreaming")
public JSONObject externalVideoStreaming(@ApiParam(value = "摄像头标识", name = "camId", required = true) String camId) throws HttpException, IOException {
JSONObject jsonResult = null;
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams();
requestParams.put("type", "1");
requestParams.put("camId", camId);
Map<String, String> header = new HashMap<>();
if (VideoController.TOKEN == null) {
getToken();
}
header.put("Authorization", TOKEN);
Response response // 请求响应
= okHttp
.headers(header)
.url(URL + "/videoInfo/api/externalVideoStreaming") // 请求地址
.data(requestParams) // 请求参数
.post(); // 请求方法
if (response.body() != null) {
jsonResult = JSONObject.parseObject(response.body().string());
if (jsonResult.containsKey("code") && UNAUTHORIZED.equals(jsonResult.getInteger("code"))) {
getToken();
okHttp.post();
if (response.body() != null) {
jsonResult = JSONObject.parseObject(response.body().string());
}
}
}
return jsonResult;
}
/**
* 云平台控制
*/
@ApiOperation("云平台控制")
@GetMapping(value = "/PTZControl")
public JSONObject PTZControl(@ApiParam(value = "相机id", name = "camId", required = true) String camId,
@ApiParam(value = "相机类型", name = "cmdType", required = true) String cmdType,
@ApiParam(value = "速度", name = "speed", required = true) String speed) throws HttpException, IOException {
JSONObject jsonResult = null;
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams();
requestParams.put("msgType", "3");
requestParams.put("camId", camId);
requestParams.put("cmdType", cmdType);
requestParams.put("speed", speed);
Map<String, String> header = new HashMap<>();
if (VideoController.TOKEN == null) {
getToken();
}
header.put("Authorization", TOKEN);
Response response // 请求响应
= okHttp
.headers(header)
.url(URL + "/videoInfo/api/PTZControl") // 请求地址
.data(requestParams) // 请求参数
.get(); // 请求方法
if (response.body() != null) {
jsonResult = JSONObject.parseObject(response.body().string());
if (jsonResult.containsKey("code") && UNAUTHORIZED.equals(jsonResult.getInteger("code"))) {
getToken();
okHttp.get();
if (response.body() != null) {
jsonResult = JSONObject.parseObject(response.body().string());
}
}
}
return jsonResult;
}
public void getToken() throws HttpException, IOException {
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams();
requestParams.put("username", USERNAME);
requestParams.put("password", PASSWORD);
Response response // 请求响应
= okHttp
.url(URL + "/apiLogin") // 请求地址
.data(requestParams) // 请求参数
.post(); // 请求方法
if (response.body() != null) {
JSONObject jsonResult = JSONObject.parseObject(response.body().string());
if (jsonResult.containsKey("token")) {
VideoController.TOKEN = jsonResult.getString("token");
}
}
}
/**
* 根据组织机构获取摄像机信息
*
* @param deptId 机构id
* @return
*/
public JSONObject getCamByDept(String deptId) throws HttpException, IOException {
JSONObject jsonResult = null;
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams();
requestParams.put("deptId", deptId);
Map<String, String> header = new HashMap<>();
if (VideoController.TOKEN == null) {
getToken();
}
header.put("Authorization", TOKEN);
Response response // 请求响应
= okHttp
.headers(header)
.url(URL + "/system/camera/camList") // 请求地址
.data(requestParams) // 请求参数
.get(); // 请求方法
if (response.body() != null) {
jsonResult = JSONObject.parseObject(response.body().string());
if (jsonResult.containsKey("code") && UNAUTHORIZED.equals(jsonResult.getInteger("code"))) {
getToken();
okHttp.get();
if (response.body() != null) {
jsonResult = JSONObject.parseObject(response.body().string());
}
}
}
return jsonResult;
}
/**
* 判断是否是附近桩号
*
* @return
*/
private boolean isNearbyPileNum(String centralPileNum, String nearbyPileNum) {
int centralPileNumMetre = pileNumTransformMetre(centralPileNum);
int nearbyPileNumMetre = pileNumTransformMetre(nearbyPileNum);
return (nearbyPileNumMetre <= centralPileNumMetre + 1000) && (nearbyPileNumMetre >= centralPileNumMetre - 1000);
}
/**
* 转换转换成米
*
* @param pileNum 桩号
* @return
*/
private int pileNumTransformMetre(String pileNum) {
String[] parts = pileNum.split("[+ ]");
if (parts.length < 2) {
return 0;
}
int kilometer = Integer.parseInt(parts[0].substring(1)); // 移除开头的字母
int meter = Integer.parseInt(parts[1]);
return kilometer * 1000 + meter;
}
}

2
zc-business/src/main/java/com/zc/business/domain/DcEventAccident.java

@ -65,7 +65,7 @@ public class DcEventAccident extends BaseEntity {
* 压车(公里)
*/
@ApiModelProperty("压车(公里)")
private Long trafficJam;
private Float trafficJam;
/**
* 天气情况

65
zc-business/src/main/java/com/zc/business/domain/Device.java

@ -0,0 +1,65 @@
package com.zc.business.domain;
/**
* @author mengff
* @Date 2020/03/03
*/
public class Device {
private long id;
public String getDeviceNo() {
return deviceNo;
}
public void setDeviceNo(String deviceNo) {
this.deviceNo = deviceNo;
}
public String getDeviceName() {
return deviceName;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
public String getDeviceIp() {
return deviceIp;
}
@Override
public String toString() {
return "Device{" +
"id=" + id +
", deviceNo='" + deviceNo + '\'' +
", deviceName='" + deviceName + '\'' +
", deviceIp='" + deviceIp + '\'' +
'}';
}
public Device(long id, String deviceNo, String deviceName, String deviceIp) {
this.id = id;
this.deviceNo = deviceNo;
this.deviceName = deviceName;
this.deviceIp = deviceIp;
}
public void setDeviceIp(String deviceIp) {
this.deviceIp = deviceIp;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
private String deviceNo;
private String deviceName;
private String deviceIp;
private String type;
}

205
zc-business/src/main/java/com/zc/business/domain/Status.java

@ -0,0 +1,205 @@
package com.zc.business.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
/**
* @author mengff
* @Date 2024/01/04
*/
public class Status {
public String getDeviceIp() {
return deviceIp;
}
public void setDeviceIp(String deviceIp) {
this.deviceIp = deviceIp;
}
public LocalDateTime getStartTime() {
return startTime;
}
public Status(long id, String deviceNo, String deviceName, int deviceStatus, LocalDateTime time, LocalDateTime startTime, String deviceIp, String successRate, String lostRate, String direction, String production, String model, String network, String content, String type) {
this.id = id;
this.deviceNo = deviceNo;
this.deviceName = deviceName;
this.deviceStatus = deviceStatus;
this.time = time;
this.startTime = startTime;
this.deviceIp = deviceIp;
this.successRate = successRate;
this.lostRate = lostRate;
this.direction = direction;
this.production = production;
this.model = model;
this.network = network;
this.content = content;
this.type = type;
}
public void setStartTime(LocalDateTime startTime) {
this.startTime = startTime;
}
@Override
public String toString() {
return "Status{" +
"id=" + id +
", deviceNo='" + deviceNo + '\'' +
", deviceName='" + deviceName + '\'' +
", deviceStatus=" + deviceStatus +
", time=" + time +
", startTime=" + startTime +
", deviceIp='" + deviceIp + '\'' +
", successRate='" + successRate + '\'' +
", lostRate='" + lostRate + '\'' +
", direction='" + direction + '\'' +
", production='" + production + '\'' +
", model='" + model + '\'' +
", network='" + network + '\'' +
", content='" + content + '\'' +
", type='" + type + '\'' +
'}';
}
public LocalDateTime getTime() {
return time;
}
public void setTime(LocalDateTime time) {
this.time = time;
}
public String getDeviceNo() {
return deviceNo;
}
public Status(long id, String deviceNo, String deviceName, int deviceStatus) {
this.id = id;
this.deviceNo = deviceNo;
this.deviceName = deviceName;
this.deviceStatus = deviceStatus;
}
public Status() {
}
public void setDeviceNo(String deviceNo) {
this.deviceNo = deviceNo;
}
public String getDeviceName() {
return deviceName;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
public int getDeviceStatus() {
return deviceStatus;
}
public void setDeviceStatus(int deviceStatus) {
this.deviceStatus = deviceStatus;
}
private long id;
private String deviceNo;
private String deviceName;
private int deviceStatus;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern ="yyyy-MM-dd HH:mm:ss")
private LocalDateTime time;
public String getSuccessRate() {
return successRate;
}
public void setSuccessRate(String successRate) {
this.successRate = successRate;
}
public String getLostRate() {
return lostRate;
}
public void setLostRate(String lostRate) {
this.lostRate = lostRate;
}
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern ="yyyy-MM-dd HH:mm:ss")
private LocalDateTime startTime;
private String deviceIp;
private String successRate;
private String lostRate;
private String direction;
private String production;
public String getDirection() {
return direction;
}
public void setDirection(String direction) {
this.direction = direction;
}
public String getProduction() {
return production;
}
public void setProduction(String production) {
this.production = production;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getNetwork() {
return network;
}
public void setNetwork(String network) {
this.network = network;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
private String model;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
private String network;
private String content;
private String type;
}

91
zc-business/src/main/java/com/zc/business/mapper/DcTrafficIncidentsMapper.java

@ -1,5 +1,7 @@
package com.zc.business.mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
@ -121,5 +123,94 @@ public interface DcTrafficIncidentsMapper {
*/
List<Map<String,Object>> selectStatusCountByEventType(String eventType);
/**
* @Description 路网管控-事件管控分析-事件类型分析占比
*
* @author liuwenge
* @date 2024/1/13 17:42
* @param
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
*/
List<Map<String, Object>> getEventTypeRatio();
/**
* @Description 路网管控-事件管控分析-事件源分析占比
*
* @author liuwenge
* @date 2024/1/13 17:42
* @param
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
*/
List<Map<String, Object>> getEventSourceRatio();
/**
* @Description 当日交通事件趋势
*
* @author liuwenge
* @date 2024/1/15 14:33
* @param
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
*/
List<Map<String, Object>> getTrafficTrend();
/**
* @Description 当日感知事件趋势
*
* @author liuwenge
* @date 2024/1/15 14:33
* @param
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
*/
List<Map<String, Object>> getPerceptionTrend();
/**
* @Description 事故车型分析
*
* @author liuwenge
* @date 2024/1/15 15:41
* @param
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
*/
List<Map<String,Long>> getAccidentVehicleAnalysis();
/**
* @Description 收费站统计分析table
*
* @author liuwenge
* @date 2024/1/16 14:18
* @param params
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
*/
List<Map<String,Object>> selectTollStationAnalysis(Map<String,Object> params);
/**
* @Description 收费站统计分析echarts
*
* @author liuwenge
* @date 2024/1/16 14:18
* @param
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
*/
List<Map<String,Object>> getTollStationAnalysis();
/**
* @Description 事故多发路段分析
*
* @author liuwenge
* @date 2024/1/17 14:18
* @param params
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
*/
List<Map<String,Object>> selectRoadSectionAnalysis(Map<String,Object> params);
/**
* @Description 事故类型分析
*
* @author liuwenge
* @date 2024/1/17 14:18
* @param params
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
*/
List<Map<String,Object>> selectEventTypeAnalysis(Map<String,Object> params);
}

16
zc-business/src/main/java/com/zc/business/mapper/DeviceMapper.java

@ -0,0 +1,16 @@
package com.zc.business.mapper;
import com.zc.business.domain.Device;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @author mengff
* @Date 2024/01/04
*/
@Repository
public interface DeviceMapper {
List<Device> SelectList();
}

21
zc-business/src/main/java/com/zc/business/mapper/StatusMapper.java

@ -0,0 +1,21 @@
package com.zc.business.mapper;
import com.zc.business.domain.Status;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @author mengff
* @Date 2024/01/04
*/
@Repository
public interface StatusMapper {
int Add(@Param("status")Status status);
List<Status> listStatus(@Param("status")Status status);
}

94
zc-business/src/main/java/com/zc/business/service/IDcTrafficIncidentsService.java

@ -1,6 +1,11 @@
package com.zc.business.service;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.Map;
/**
* @Description 交通事件统计Service接口
@ -11,52 +16,113 @@ import com.ruoyi.common.core.domain.AjaxResult;
public interface IDcTrafficIncidentsService {
/**
* @param
* @return com.ruoyi.common.core.domain.AjaxResult
* @Description 首页-重点数据
*
* @author liuwenge
* @date 2024/1/13 10:09
* @param
* @return com.ruoyi.common.core.domain.AjaxResult
*/
AjaxResult getKeyData();
/**
* @param eventType
* @return com.ruoyi.common.core.domain.AjaxResult
* @Description 首页-事件专题-根据事件类型获取事件列表
*
* @author liuwenge
* @date 2024/1/13 14:26
* @param eventType
* @return com.ruoyi.common.core.domain.AjaxResult
*/
AjaxResult getEventListByType(String eventType);
/**
* @param eventId
* @return com.ruoyi.common.core.domain.AjaxResult
* @Description 首页-事件专题-根据事件id获取详情
*
* @author liuwenge
* @date 2024/1/13 14:43
* @param eventId
* @return com.ruoyi.common.core.domain.AjaxResult
*/
AjaxResult getEventInfo(String eventId);
/**
* @param
* @return com.ruoyi.common.core.domain.AjaxResult
* @Description 首页-状况统计-获取日年的交通事件数量
*
* @author liuwenge
* @date 2024/1/13 15:08
*/
AjaxResult getTrafficIncidentsNum();
/**
* @param
* @return com.ruoyi.common.core.domain.AjaxResult
* @Description 路网管控-事件管控分析-事件类型分析占比
* @author liuwenge
* @date 2024/1/13 15:46
*/
AjaxResult getTrafficIncidentsNum();
AjaxResult getAllEventNum();
/**
* @param
* @return com.ruoyi.common.core.domain.AjaxResult
* @Description 路网管控-事件管控分析-事件源分析占比
* @author liuwenge
* @date 2024/1/13 17:37
*/
AjaxResult getEventSourceRatio();
/**
* @param
* @return com.ruoyi.common.core.domain.AjaxResult
* @Description 路网管控-事件管控分析-今日事件趋势
* @author liuwenge
* @date 2024/1/15 14:30
*/
AjaxResult getEventTrend();
/**
* @param
* @return com.ruoyi.common.core.domain.AjaxResult
* @Description 路网管控-事件管控分析-事故车型分析
* @author liuwenge
* @date 2024/1/15 15:38
*/
AjaxResult getAccidentVehicleAnalysis();
/**
* @param params
* @return com.ruoyi.common.core.domain.AjaxResult
* @Description 路网管控-事件管控分析-收费站统计分析table
* @author liuwenge
* @date 2024/1/15 17:31
*/
AjaxResult selectTollStationAnalysis(Map<String, Object> params);
/**
* @Description 路网管控-事件管控分析-统计各类型的交通事件数量
* @Description 路网管控-事件管控分析-收费站统计分析echarts(当月)
*
* @author liuwenge
* @date 2024/1/13 15:46
* @date 2024/1/16 11:11
* @param
* @return com.ruoyi.common.core.domain.AjaxResult
*/
AjaxResult getAllEventNum();
AjaxResult getTollStationAnalysis();
/**
* @Description 路网管控-事件管控分析-事故多发路段分析
*
* @author liuwenge
* @date 2024/1/16 15:52
* @param params
* @return com.ruoyi.common.core.domain.AjaxResult
*/
AjaxResult selectRoadSectionAnalysis(Map<String,Object> params);
/**
* @Description 路网管控-事件管控分析-事故类型分析
*
* @author liuwenge
* @date 2024/1/16 15:52
* @param params
* @return com.ruoyi.common.core.domain.AjaxResult
*/
AjaxResult selectEventTypeAnalysis(Map<String,Object> params);
}

304
zc-business/src/main/java/com/zc/business/service/impl/DcTrafficIncidentsServiceImpl.java

@ -1,6 +1,7 @@
package com.zc.business.service.impl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StakeMarkUtils;
import com.zc.business.domain.DcEvent;
import com.zc.business.domain.DcEventType;
import com.zc.business.mapper.DcTrafficIncidentsMapper;
@ -8,9 +9,12 @@ import com.zc.business.service.IDcTrafficIncidentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.Year;
import java.util.*;
/**
* @Description 交通事件统计Service业务层处理
@ -101,7 +105,7 @@ public class DcTrafficIncidentsServiceImpl implements IDcTrafficIncidentsService
}
/**
* @Description 路网管控-事件管控分析-统计各类型的交通事件数量
* @Description 路网管控-事件管控分析-事件类型分析占比
*
* @author liuwenge
* @date 2024/1/13 15:46
@ -110,7 +114,7 @@ public class DcTrafficIncidentsServiceImpl implements IDcTrafficIncidentsService
*/
@Override
public AjaxResult getAllEventNum(){
//事件类型
/*//事件类型
List<Map<String,Object>> eventTypeList = trafficIncidentsMapper.selectEventTypeList();
for (Map<String, Object> eventType : eventTypeList) {
@ -135,19 +139,305 @@ public class DcTrafficIncidentsServiceImpl implements IDcTrafficIncidentsService
total += Integer.parseInt(eventTypeData.get("num").toString());
}
eventType.put("total",total);
} else {
}
if (!eventType.containsKey("unconfirmed")){
//待确认
eventType.put("unconfirmed", "0");
} else if (!eventType.containsKey("processing")){
//处理中
eventType.put("processing", "0");
} else if (!eventType.containsKey("finished")){
//已完成
eventType.put("finished", "0");
} else if (!eventType.containsKey("total")){
//总数
eventType.put("total", "0");
}
}*/
List<Map<String,Object>> eventTypeRatio = trafficIncidentsMapper.getEventTypeRatio();
return AjaxResult.success(eventTypeRatio);
}
/**
* @Description 路网管控-事件管控分析-事件源分析占比
*
* @author liuwenge
* @date 2024/1/13 17:38
* @param
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@Override
public AjaxResult getEventSourceRatio(){
List<Map<String,Object>> eventSourceRatio = trafficIncidentsMapper.getEventSourceRatio();
return AjaxResult.success(eventSourceRatio);
}
/**
* @Description 路网管控-事件管控分析-今日事件趋势
*
* @author liuwenge
* @date 2024/1/15 14:31
* @param
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@Override
public AjaxResult getEventTrend(){
Map<String,Object> result = new HashMap<>();
//交通事件趋势
List<Map<String,Object>> traffic = trafficIncidentsMapper.getTrafficTrend();
//感知世间趋势
List<Map<String,Object>> perception = trafficIncidentsMapper.getPerceptionTrend();
result.put("traffic",traffic);
result.put("perception",perception);
return AjaxResult.success(result);
}
/**
* @Description 路网管控-事件管控分析-事故车型分析
*
* @author liuwenge
* @date 2024/1/15 15:38
* @param
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@Override
public AjaxResult getAccidentVehicleAnalysis(){
List<Map<String,Long>> list = trafficIncidentsMapper.getAccidentVehicleAnalysis();
Map<String,Object> smallCar = new HashMap<>();
smallCar.put("type","smallCar");
smallCar.put("num",0);
smallCar.put("allTime",0);
Map<String,Object> trucks = new HashMap<>();
trucks.put("type","trucks");
trucks.put("num",0);
trucks.put("allTime",0);
Map<String,Object> buses = new HashMap<>();
buses.put("type","buses");
buses.put("num",0);
buses.put("allTime",0);
Map<String,Object> tankers = new HashMap<>();
tankers.put("type","tankers");
tankers.put("num",0);
tankers.put("allTime",0);
//计算各车型总处理时长
for (Map<String, Long> data : list) {
if (data.get("smallCar") > 0){
smallCar.put("num",Integer.parseInt(smallCar.get("num").toString()) + 1);
smallCar.put("allTime",Long.parseLong(smallCar.get("allTime").toString()) + data.get("minuteTime"));
}
if (data.get("trucks") > 0){
trucks.put("num",Integer.parseInt(trucks.get("num").toString()) + 1);
trucks.put("allTime",Long.parseLong(trucks.get("allTime").toString()) + data.get("minuteTime"));
}
if (data.get("buses") > 0){
buses.put("num",Integer.parseInt(buses.get("num").toString()) + 1);
buses.put("allTime",Long.parseLong(buses.get("allTime").toString()) + data.get("minuteTime"));
}
if (data.get("tankers") > 0){
tankers.put("num",Integer.parseInt(tankers.get("num").toString()) + 1);
tankers.put("allTime",Long.parseLong(tankers.get("allTime").toString()) + data.get("minuteTime"));
}
}
List<Map<String,Object>> result = new ArrayList<>();
//小型车平均时长
if (Long.parseLong(smallCar.get("num").toString()) > 0){
smallCar.put("avgTime",Long.parseLong(smallCar.get("allTime").toString()) / Long.parseLong(smallCar.get("num").toString()));
} else {
smallCar.put("avgTime",0);
}
result.add(smallCar);
//货车平均时长
if (Long.parseLong(trucks.get("num").toString()) > 0){
trucks.put("avgTime",Long.parseLong(trucks.get("allTime").toString()) / Long.parseLong(trucks.get("num").toString()));
} else {
trucks.put("avgTime",0);
}
result.add(trucks);
//客车平均时长
if (Long.parseLong(buses.get("num").toString()) > 0){
buses.put("avgTime",Long.parseLong(buses.get("allTime").toString()) / Long.parseLong(buses.get("num").toString()));
} else {
buses.put("avgTime",0);
}
result.add(buses);
//罐车平均时长
if (Long.parseLong(tankers.get("num").toString()) > 0){
tankers.put("avgTime",Long.parseLong(tankers.get("allTime").toString()) / Long.parseLong(tankers.get("num").toString()));
} else {
tankers.put("avgTime",0);
}
result.add(tankers);
return AjaxResult.success(result);
}
/**
* @Description 路网管控-事件管控分析-收费站统计分析table
* @param params
* @return com.ruoyi.common.core.domain.AjaxResult
* @author liuwenge
* @date 2024/1/15 17:31
*/
@Override
public AjaxResult selectTollStationAnalysis(Map<String, Object> params){
//目标时段
List<Map<String,Object>> list = trafficIncidentsMapper.selectTollStationAnalysis(params);
BigDecimal allNum = BigDecimal.ZERO;
BigDecimal allTime = BigDecimal.ZERO;
for (Map<String, Object> data : list) {
allNum = allNum.add(new BigDecimal(data.get("num").toString()));
allTime = allTime.add(new BigDecimal(data.get("minuteTime").toString()));
}
for (Map<String, Object> data : list) {
//计算站次占比
if (allNum.compareTo(BigDecimal.ZERO) > 0){
BigDecimal numRatio = new BigDecimal(data.get("num").toString()).multiply(new BigDecimal("100")).divide(allNum,2, RoundingMode.HALF_UP);
data.put("numRatio",numRatio);
} else {
data.put("numRatio",0);
}
//计算时长占比
if (allTime.compareTo(BigDecimal.ZERO) > 0){
BigDecimal timeRatio = new BigDecimal(data.get("minuteTime").toString()).multiply(new BigDecimal("100")).divide(allTime,2, RoundingMode.HALF_UP);
data.put("timeRatio",timeRatio);
} else {
data.put("timeRatio",0);
}
}
//去年同期
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
Date startDate = dateFormat.parse(params.get("startTime").toString());
cal.setTime(startDate);
cal.add(Calendar.YEAR,-1);
String lastStartTime = dateFormat.format(cal.getTime());
Date endDate = dateFormat.parse(params.get("endTime").toString());
cal.setTime(endDate);
cal.add(Calendar.YEAR,-1);
String lastEndTime = dateFormat.format(cal.getTime());
params.put("startTime",lastStartTime);
params.put("endTime",lastEndTime);
List<Map<String,Object>> lastList = trafficIncidentsMapper.selectTollStationAnalysis(params);
BigDecimal lastAllNum = BigDecimal.ZERO;
BigDecimal lastAllTime = BigDecimal.ZERO;
for (int i = 0; i < lastList.size(); i++) {
//去年同期站次
lastAllNum = lastAllNum.add(new BigDecimal(lastList.get(i).get("num").toString()));
list.get(i).put("lastYearNum",lastList.get(i).get("num").toString());
//去年同期时长
lastAllTime = lastAllTime.add(new BigDecimal(lastList.get(i).get("minuteTime").toString()));
list.get(i).put("lastYearTime",lastList.get(i).get("minuteTime").toString());
}
for (int i = 0; i < lastList.size(); i++) {
//去年同期站次占比
if (lastAllNum.compareTo(BigDecimal.ZERO) > 0){
BigDecimal numRatio = new BigDecimal(lastList.get(i).get("num").toString()).multiply(new BigDecimal("100")).divide(lastAllNum,2, RoundingMode.HALF_UP);
list.get(i).put("lastYearNumRatio",numRatio);
} else {
list.get(i).put("lastYearNumRatio",0);
}
////去年同期时长占比
if (lastAllTime.compareTo(BigDecimal.ZERO) > 0) {
BigDecimal timeRatio = new BigDecimal(lastList.get(i).get("minuteTime").toString()).multiply(new BigDecimal("100")).divide(lastAllTime, 2, RoundingMode.HALF_UP);
list.get(i).put("lastYearTimeRatio", timeRatio);
} else {
list.get(i).put("lastYearTimeRatio", 0);
}
}
//同比
for (Map<String, Object> map : list) {
//站次同比
if (new BigDecimal(map.get("lastYearNum").toString()).compareTo(BigDecimal.ZERO) > 0){
BigDecimal yearNumRatio = new BigDecimal(map.get("num").toString()).multiply(new BigDecimal("100")).divide(new BigDecimal(map.get("lastYearNum").toString()),2, RoundingMode.HALF_UP);
map.put("yearNumRatio",yearNumRatio);
} else {
map.put("ratio",0);
}
//时长同比
if (new BigDecimal(map.get("lastYearTime").toString()).compareTo(BigDecimal.ZERO) > 0){
BigDecimal yearTimeRatio = new BigDecimal(map.get("minuteTime").toString()).multiply(new BigDecimal("100")).divide(new BigDecimal(map.get("lastYearTime").toString()),2, RoundingMode.HALF_UP);
map.put("yearTimeRatio",yearTimeRatio);
} else {
map.put("yearTimeRatio",0);
}
}
} catch (Exception e){
e.printStackTrace();
}
return AjaxResult.success(eventTypeList);
return AjaxResult.success(list);
}
/**
* @Description 路网管控-事件管控分析-收费站统计分析echarts(当月)
*
* @author liuwenge
* @date 2024/1/16 11:11
* @param
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@Override
public AjaxResult getTollStationAnalysis(){
List<Map<String,Object>> list = trafficIncidentsMapper.getTollStationAnalysis();
return AjaxResult.success(list);
}
/**
* @Description 路网管控-事件管控分析-事故多发路段分析
*
* @author liuwenge
* @date 2024/1/16 15:52
* @param params
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@Override
public AjaxResult selectRoadSectionAnalysis(Map<String,Object> params){
List<Map<String,Object>> list = trafficIncidentsMapper.selectRoadSectionAnalysis(params);
return AjaxResult.success(list);
}
/**
* @Description 路网管控-事件管控分析-事故类型分析
*
* @author liuwenge
* @date 2024/1/16 15:52
* @param params
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@Override
public AjaxResult selectEventTypeAnalysis(Map<String,Object> params){
List<Map<String,Object>> list = trafficIncidentsMapper.selectEventTypeAnalysis(params);
return AjaxResult.success(list);
}
}

23
zc-business/src/main/java/com/zc/business/service/impl/DeviceService.java

@ -0,0 +1,23 @@
package com.zc.business.service.impl;
import com.zc.business.domain.Device;
import com.zc.business.mapper.DeviceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author mengff
* @Date 2024/01/04
*/
@Service
public class DeviceService {
@Autowired
DeviceMapper deviceMapper;
public List<Device> SelectList() {
return deviceMapper.SelectList();
}
}

192
zc-business/src/main/java/com/zc/business/service/impl/ExcelExportService.java

@ -0,0 +1,192 @@
package com.zc.business.service.impl;
import com.zc.business.domain.Status;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;
@Service
public class ExcelExportService {
public void exportDataToExcel(Map<Integer, List<Status>> ipMap, Map<String, List<Status> >categoryMap, String filePath) {
Workbook workbook = new XSSFWorkbook();
Map<Integer, List<Status>> map = new TreeMap<>(ipMap);
Sheet sheet = workbook.createSheet("设备故障率分时统计页");
int rowNum = 0;
Row row0 = sheet.createRow(0);
row0.createCell(0).setCellValue("设备名称");
row0.createCell(1).setCellValue("设备IP");
row0.createCell(2).setCellValue("设备桩号");
row0.createCell(3).setCellValue("设备方向");
row0.createCell(4).setCellValue("设备厂家");
row0.createCell(5).setCellValue("设备型号");
row0.createCell(6).setCellValue("备注");
sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 2));
sheet.addMergedRegion(new CellRangeAddress(0, 1, 3, 3));
sheet.addMergedRegion(new CellRangeAddress(0, 1, 4, 4));
sheet.addMergedRegion(new CellRangeAddress(0, 1, 5, 5));
sheet.addMergedRegion(new CellRangeAddress(0, 1, 6, 6));
int i=0;
boolean flag = true;
Row row1= sheet.createRow(1);
for (Map.Entry<Integer, List<Status>> entry : map.entrySet()) {
row0.createCell(2*i+7).setCellValue(entry.getKey()+"时");
sheet.addMergedRegion(new CellRangeAddress(0, 0, 2*i+7, 2*i+8));
row1.createCell(2*i+7).setCellValue("在线率");
row1.createCell(2*i+8).setCellValue("丢包率");
rowNum = 2;
List<Status> groupItems = entry.getValue();
for (Status ignored : groupItems) {
int a=rowNum++;
Row row = sheet.getRow(a); // 获取指定索引的行
if (row == null) { // 如果行不存在,则创建新行
row = sheet.createRow(a);
}
if(flag) {
row.createCell(0).setCellValue(ignored.getDeviceName());
row.createCell(1).setCellValue(ignored.getDeviceIp());
row.createCell(2).setCellValue(ignored.getDeviceNo());
row.createCell(3).setCellValue(ignored.getDirection());
row.createCell(4).setCellValue(ignored.getProduction());
row.createCell(5).setCellValue(ignored.getModel());
row.createCell(6).setCellValue(ignored.getContent());
}
row.createCell(2*i+7).setCellValue(ignored.getSuccessRate());
row.createCell(2*i+8).setCellValue(ignored.getLostRate());
}
i++;
flag = false;
}
Sheet sheets = workbook.createSheet("设备故障率汇总页");
createSheet(sheets,categoryMap);
Sheet sheet1 = workbook.createSheet("设备故障率分时汇总页");
createSheet1(sheet1,ipMap);
try (FileOutputStream outputStream = new FileOutputStream(filePath)) {
workbook.write(outputStream);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("excel写入成功!!!!!!");
}
public void createSheet1(Sheet sheet,Map<Integer, List<Status>> ipMap){
Map<Integer, List<Status>> map = new TreeMap<>(ipMap);
int rowNum = 0;
Row row0 = sheet.createRow(rowNum);
row0.createCell(0).setCellValue("设备分类");
sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
int i=0;
boolean flag = true;
Row row1= sheet.createRow(1);
for (Map.Entry<Integer, List<Status>> entry : map.entrySet()) {
row0.createCell(3 * i + 1).setCellValue(entry.getKey() + "时");
sheet.addMergedRegion(new CellRangeAddress(0, 0, 3 * i + 1, 3 * i + 3));
row1.createCell(3 * i + 1).setCellValue("总统计数");
row1.createCell(3 * i + 2).setCellValue("在线统计数");
row1.createCell(3 * i + 3).setCellValue("在线率");
rowNum = 2;
List<Status> groupItem = entry.getValue();
Map<String, List<Status>> maps = groupItem.stream().filter(iteam -> iteam.getType() != null).collect(Collectors.groupingBy(Status::getType));
for (Map.Entry<String, List<Status>> entrys : maps.entrySet()) {
List<Status> groupItems = entrys.getValue();
long b = groupItems.stream().filter(iteam -> iteam.getDeviceStatus() == 1).count();
// for (Status ignored : groupItems) {
int a = rowNum++;
Row row = sheet.getRow(a); // 获取指定索引的行
if (row == null) { // 如果行不存在,则创建新行
row = sheet.createRow(a);
}
HashMap<String, String> itemTypeMap = new HashMap<>();
itemTypeMap.put("1", "高清网络枪型固定摄像机");
itemTypeMap.put("2", "高清网络球形摄像机");
itemTypeMap.put("3", "桥下高清网络球形摄像机");
itemTypeMap.put("4", "360°全景摄像机");
itemTypeMap.put("5", "180°全景摄像机");
itemTypeMap.put("6", "门架式可变信息标志");
itemTypeMap.put("7", "雨棚可变信息标志");
itemTypeMap.put("8", "站前悬臂式可变信息标志");
itemTypeMap.put("9", "气象检测器");
itemTypeMap.put("10", "路段语音广播系统");
itemTypeMap.put("11", "护栏碰撞预警系统");
itemTypeMap.put("12", "毫米波雷达");
itemTypeMap.put("13", "合流区预警系统");
itemTypeMap.put("14", "激光疲劳唤醒");
itemTypeMap.put("15", "一类交通量调查站");
itemTypeMap.put("16", "智能行车诱导系统");
itemTypeMap.put("17", "智能设备箱");
String type = groupItems.get(0).getType();
String description = itemTypeMap.get(type);
if (flag) {
row.createCell(0).setCellValue(description);
}
row.createCell(3 * i + 1).setCellValue(groupItems.size());
row.createCell(3 * i + 2).setCellValue(b);
row.createCell(3 * i + 3).setCellValue(String.format("%.2f%%", (double) b / groupItems.size() * 100));
}
i++;
flag = false;
// }
}
}
public void createSheet(Sheet sheet,Map<String, List<Status> >categoryMap){
int rowNum = 0;
Row row = sheet.createRow(rowNum);
row.createCell(0).setCellValue("设备分类");
row.createCell(1).setCellValue("总统计数");
row.createCell(2).setCellValue("在线统计数");
row.createCell(3).setCellValue("在线率");
rowNum = 1;
for (Map.Entry<String, List<Status>> entry : categoryMap.entrySet()) {
List<Status> groupItems = entry.getValue();
long a=groupItems.stream().filter(iteam->iteam.getDeviceStatus()==1).count();
row = sheet.createRow(rowNum++);
HashMap<String, String> itemTypeMap = new HashMap<>();
itemTypeMap.put("1", "高清网络枪型固定摄像机");
itemTypeMap.put("2", "高清网络球形摄像机");
itemTypeMap.put("3", "桥下高清网络球形摄像机");
itemTypeMap.put("4", "360°全景摄像机");
itemTypeMap.put("5", "180°全景摄像机");
itemTypeMap.put("6", "门架式可变信息标志");
itemTypeMap.put("7", "雨棚可变信息标志");
itemTypeMap.put("8", "站前悬臂式可变信息标志");
itemTypeMap.put("9", "气象检测器");
itemTypeMap.put("10", "路段语音广播系统");
itemTypeMap.put("11", "护栏碰撞预警系统");
itemTypeMap.put("12", "毫米波雷达");
itemTypeMap.put("13", "合流区预警系统");
itemTypeMap.put("14", "激光疲劳唤醒");
itemTypeMap.put("15", "一类交通量调查站");
itemTypeMap.put("16", "智能行车诱导系统");
itemTypeMap.put("17", "智能设备箱");
String type = groupItems.get(0).getType();
String description = itemTypeMap.get(type);
row.createCell(0).setCellValue(description);
row.createCell(1).setCellValue(groupItems.size());
row.createCell(2).setCellValue(a);
row.createCell(3).setCellValue(String.format("%.2f%%", (double) a / groupItems.size() * 100));
}
}
}

33
zc-business/src/main/java/com/zc/business/service/impl/StatusService.java

@ -0,0 +1,33 @@
package com.zc.business.service.impl;
import com.zc.business.domain.Status;
import com.zc.business.mapper.StatusMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author mengff
* @Date 2024/01/04
*/
@Service
public class StatusService {
@Autowired
StatusMapper statusMapper;
public String Add(Status status) {
int a = statusMapper.Add(status);
if (a == 1) {
return "添加成功";
} else {
return "添加失败";
}
}
public List<Status> list(Status status) {
List<Status> list = statusMapper.listStatus(status);
return list;
}
}

296
zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml

@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zc.business.mapper.DcTrafficIncidentsMapper">
<select id="getTrafficIncidentsProcessing" resultType="Integer">
select count(*) from dc_event
where event_type = '1' and event_state != '2' and date_format(create_time,'%y%m%d') = date_format(now(),'%y%m%d')
where event_type = '1' and event_state != '2' and date_format(start_time,'%y%m%d') = date_format(now(),'%y%m%d')
</select>
<select id="getTrafficIncidentsAll" resultType="Integer">
select count(*) from dc_event
where event_type = '1' and date_format(create_time,'%y%m%d') = date_format(now(),'%y%m%d')
where event_type = '1' and date_format(start_time,'%y%m%d') = date_format(now(),'%y%m%d')
</select>
<select id="getConstructionNum" resultType="java.lang.Integer">
@ -29,22 +29,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectTrafficIncidentsDay" resultType="Long">
select count(*) from dc_event
where date_format(create_time,'%y%m%d') = date_format(now(),'%y%m%d')
where date_format(start_time,'%y%m%d') = date_format(now(),'%y%m%d')
</select>
<select id="selectTrafficIncidentsWeek" resultType="Long">
select count(*) from dc_event
where YEARWEEK(create_time, 1) = YEARWEEK(now(), 1)
where YEARWEEK(start_time, 1) = YEARWEEK(now(), 1)
</select>
<select id="selectTrafficIncidentsMonth" resultType="Long">
select count(*) from dc_event
where date_format(create_time,'%y%m') = date_format(now(),'%y%m')
where date_format(start_time,'%y%m') = date_format(now(),'%y%m')
</select>
<select id="selectTrafficIncidentsYear" resultType="Long">
select count(*) from dc_event
where date_format(create_time,'%y') = date_format(now(),'%y')
where date_format(start_time,'%y') = date_format(now(),'%y')
</select>
<select id="selectTrafficIncidentsAllProcessing" resultType="java.lang.Long">
@ -58,8 +58,286 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectStatusCountByEventType" resultType="java.util.Map" parameterType="String">
select event_state eventState,count(*) num from dc_event
where event_type = #{eventType} and date_format(create_time,'%y%m%d') = date_format(now(),'%y%m%d')
where event_type = #{eventType} and date_format(start_time,'%y%m%d') = date_format(now(),'%y%m%d')
group by event_state
</select>
<select id="getEventTypeRatio" resultType="java.util.Map">
select t1.event_type eventType,t1.event_name eventName,IFNULL(num,0) num
FROM dc_event_type t1
left join
(select event_type eventType, count(*) num
from dc_event
where date_format(start_time,'%y%m%d') = date_format(now(),'%y%m%d')
group by event_type) t2
on t1.event_type = t2.eventType
</select>
<select id="getEventSourceRatio" resultType="java.util.Map">
select t1.eventSource,t1.eventSourceName,IFNULL(t2.num,0) num from
(select '1' as eventSource,'96659' as eventSourceName
UNION ALL select '2' as eventSource,'交警转接' as eventSourceName
UNION ALL select '3' as eventSource,'道路巡查' as eventSourceName
UNION ALL select '4' as eventSource,'视频巡查' as eventSourceName
UNION ALL select '5' as eventSource,'视频AI' as eventSourceName
UNION ALL select '6' as eventSource,'一键救援' as eventSourceName
UNION ALL select '7' as eventSource,'其他' as eventSourceName) t1
LEFT JOIN
(select event_source eventSource,count(*) num
from dc_event
where date_format(start_time,'%y%m%d') = date_format(now(),'%y%m%d')
group by event_source) t2
on t1.eventSource = t2.eventSource
</select>
<select id="getTrafficTrend" resultType="java.util.Map">
SELECT t1.hours, ifnull(t2.num, 0) num
FROM
(SELECT 0 hours
UNION ALL SELECT 1 hours
UNION ALL SELECT 2 hours
UNION ALL SELECT 3 hours
UNION ALL SELECT 4 hours
UNION ALL SELECT 5 hours
UNION ALL SELECT 6 hours
UNION ALL SELECT 7 hours
UNION ALL SELECT 8 hours
UNION ALL SELECT 9 hours
UNION ALL SELECT 10 hours
UNION ALL SELECT 11 hours
UNION ALL SELECT 12 hours
UNION ALL SELECT 13 hours
UNION ALL SELECT 14 hours
UNION ALL SELECT 15 hours
UNION ALL SELECT 16 hours
UNION ALL SELECT 17 hours
UNION ALL SELECT 18 hours
UNION ALL SELECT 19 hours
UNION ALL SELECT 20 hours
UNION ALL SELECT 21 hours
UNION ALL SELECT 22 hours
UNION ALL SELECT 23 hours
) t1
LEFT JOIN
(SELECT
hour(create_time) hours,
count(*) num
FROM dc_event
WHERE date_format(start_time, '%Y-%m-%d') = current_date
GROUP BY date_format(start_time, '%Y%m%d-%H'), hours
) t2
ON t1.hours = t2.hours
where HOUR(now()) >= t1.hours
ORDER BY hours
</select>
<select id="getPerceptionTrend" resultType="java.util.Map">
SELECT t1.hours, ifnull(t2.num, 0) num
FROM
(SELECT 0 hours
UNION ALL SELECT 1 hours
UNION ALL SELECT 2 hours
UNION ALL SELECT 3 hours
UNION ALL SELECT 4 hours
UNION ALL SELECT 5 hours
UNION ALL SELECT 6 hours
UNION ALL SELECT 7 hours
UNION ALL SELECT 8 hours
UNION ALL SELECT 9 hours
UNION ALL SELECT 10 hours
UNION ALL SELECT 11 hours
UNION ALL SELECT 12 hours
UNION ALL SELECT 13 hours
UNION ALL SELECT 14 hours
UNION ALL SELECT 15 hours
UNION ALL SELECT 16 hours
UNION ALL SELECT 17 hours
UNION ALL SELECT 18 hours
UNION ALL SELECT 19 hours
UNION ALL SELECT 20 hours
UNION ALL SELECT 21 hours
UNION ALL SELECT 22 hours
UNION ALL SELECT 23 hours
) t1
LEFT JOIN
(SELECT
hour(create_time) hours,count(*) num
FROM dc_warning
WHERE date_format(create_time, '%Y-%m-%d') = current_date
GROUP BY date_format(create_time, '%Y%m%d-%H'), hours) t2
ON t1.hours = t2.hours
where HOUR(now()) >= t1.hours
ORDER BY hours
</select>
<select id="getAccidentVehicleAnalysis" resultType="java.util.Map">
select t1.id,
case when ISNULL(end_time) then TIMESTAMPDIFF(MINUTE,start_time,now()) else TIMESTAMPDIFF(MINUTE,start_time,end_time) end minuteTime,
ifNull(t2.small_car,0) smallCar,
ifNull(t2.trucks,0) trucks,
ifNull(t2.buses,0) buses,
ifNull(t2.tankers,0) tankers
from dc_event t1
left join dc_event_vehicle_accident t2 on t1.id = t2.id
where event_type = '1' and date_format(start_time,'%Y-%m-%d') = current_date
</select>
<select id="selectTollStationAnalysis" resultType="java.util.Map">
select t3.control_cause controlCause,t3.cause_type causeType,controlCauseName,causeTypeName,IFNULL(t4.num,0) num,ifNull(t4.minuteTime,0) minuteTime
from
(select 1 control_cause,'' cause_type,'车流量大' controlCauseName,'' causeTypeName
UNION ALL select 2 control_cause,'' cause_type,'交通事故' controlCauseName,'' causeTypeName
UNION ALL select 3 control_cause,'3-1' cause_type,'恶劣天气' controlCauseName,'雨' causeTypeName
UNION ALL select 3 control_cause,'3-2' cause_type,'恶劣天气' controlCauseName,'雪' causeTypeName
UNION ALL select 3 control_cause,'3-3' cause_type,'恶劣天气' controlCauseName,'雾' causeTypeName
UNION ALL select 3 control_cause,'3-4' cause_type,'恶劣天气' controlCauseName,'道路积水' causeTypeName
UNION ALL select 3 control_cause,'3-5' cause_type,'恶劣天气' controlCauseName,'道路湿滑' causeTypeName
UNION ALL select 3 control_cause,'3-6' cause_type,'恶劣天气' controlCauseName,'道路结冰' causeTypeName
UNION ALL select 3 control_cause,'3-7' cause_type,'恶劣天气' controlCauseName,'沙尘暴' causeTypeName
UNION ALL select 4 control_cause,'' cause_type,'施工' controlCauseName,'' causeTypeName
UNION ALL select 5 control_cause,'' cause_type,'警备任务' controlCauseName,'' causeTypeName
UNION ALL select 6 control_cause,'' cause_type,'其他' controlCauseName,'' causeTypeName) t3
LEFT JOIN
(select t2.control_type,t2.control_cause,t2.cause_type,count(*) num,sum(
case when date_format(#{startTime},'%Y-%m-%d %H:%i:%s') >= date_format(t1.start_time,'%Y-%m-%d %H:%i:%s')
and (DATE_FORMAT(t1.end_time,'%Y-%m-%d %H:%i:%s') >= DATE_FORMAT(#{endTime},'%Y-%m-%d %H:%i:%s') or ISNULL(t1.end_time))
then TIMESTAMPDIFF(MINUTE,t1.start_time,now())
when date_format(#{startTime},'%Y-%m-%d %H:%i:%s') >= date_format(t1.start_time,'%Y-%m-%d %H:%i:%s')
and DATE_FORMAT(t1.end_time,'%Y-%m-%d %H:%i:%s') &lt;= DATE_FORMAT(#{endTime},'%Y-%m-%d %H:%i:%s')
then TIMESTAMPDIFF(MINUTE,#{startTime},t1.end_time)
when date_format(#{startTime},'%Y-%m-%d %H:%i:%s') &lt;= date_format(t1.start_time,'%Y-%m-%d %H:%i:%s')
and (DATE_FORMAT(t1.end_time,'%Y-%m-%d %H:%i:%s') >= DATE_FORMAT(#{endTime},'%Y-%m-%d %H:%i:%s') or ISNULL(t1.end_time))
then TIMESTAMPDIFF(MINUTE,t1.start_time,#{endTime})
when date_format(#{startTime},'%Y-%m-%d %H:%i:%s') &lt;= date_format(t1.start_time,'%Y-%m-%d %H:%i:%s')
and DATE_FORMAT(t1.end_time,'%Y-%m-%d %H:%i:%s') &lt;= DATE_FORMAT(#{endTime},'%Y-%m-%d %H:%i:%s')
then TIMESTAMPDIFF(MINUTE,t1.start_time,t1.end_time)
else 0 end) minuteTime
from dc_event t1 LEFT JOIN dc_event_traffic_control t2 on t1.id = t2.id
where
t1.event_type = '3' and t1.event_subclass = '3-2' and t2.control_type = #{controlType}
and date_format(t1.start_time,'%Y-%m-%d %H:%i:%s') &lt;= date_format(#{endTime},'%Y-%m-%d %H:%i:%s')
and (date_format(t1.end_time,'%Y-%m-%d %H:%i:%s') > date_format(#{startTime},'%Y-%m-%d %H:%i:%s') or ISNULL(t1.end_time))
GROUP BY t2.control_cause,t2.cause_type) t4
on t3.control_cause = t4.control_cause and t3.cause_type = t4.cause_type
ORDER BY t3.control_cause, t3.cause_type
</select>
<select id="getTollStationAnalysis" resultType="java.util.Map">
select t3.facility_name facilityName,ifNull(t4.trafficClose,0) trafficClose, ifnull(t4.trafficRestriction,0) trafficRestriction
from
(select * from dc_facility where facility_type = '1' ) t3
LEFT JOIN
(select t2.facility_id facilityId,sum(case when t2.control_type = '1' then 1 else 0 end) trafficClose,
sum(case when t2.control_type = '2' then 1 else 0 end) trafficRestriction
from dc_event t1 left join dc_event_traffic_control t2 on t1.id = t2.id
where (DATE_FORMAT(t1.start_time,'%Y-%m') = DATE_FORMAT(now(),'%Y-%m') or DATE_FORMAT(t1.end_time,'%Y-%m') = DATE_FORMAT(now(),'%Y-%m') or ISNULL(t1.end_time))
and t1.event_type = '3' and t1.event_subclass = '3-2'
GROUP BY t2.facility_id) t4
on t3.id = t4.facilityId
</select>
<select id="selectRoadSectionAnalysis" resultType="java.util.Map">
select t3.section_name,t3.mileage,IFNULL(t4.num,0) num,IFNULL(t5.lastNum,0) lastNum,
ROUND(IFNULL( t4.num / t3.mileage * 100, 0 ),2) avgNum
from
(select * from dc_road_section) t3
LEFT JOIN
(select t2.section_id, count(*) num
from dc_event t1
left join dc_stake_mark t2 on t1.stake_mark = t2.id and t1.direction = t2.direction
where
t1.event_type = '1' and t1.direction = #{direction}
<if test="type != null and type == '1'.toString">
and DATE_FORMAT(t1.start_time,'%Y%m%d') = DATE_FORMAT(#{startTime},'%Y%m%d')
</if>
<if test="type != null and type == '2'.toString">
and DATE_FORMAT(t1.start_time,'%Y%m') = DATE_FORMAT(#{startTime},'%Y%m')
</if>
<if test="type != null and type == '3'.toString">
and YEAR(t1.start_time) = YEAR(#{startTime}) and QUARTER(t1.start_time) = QUARTER(#{startTime})
</if>
<if test="type != null and type == '4'.toString">
and YEAR(t1.start_time) = YEAR(#{startTime})
</if>
GROUP BY t2.section_id) t4
on t3.id = t4.section_id
LEFT JOIN
(select t2.section_id, count(*) lastNum
from dc_event t1
left join dc_stake_mark t2 on t1.stake_mark = t2.id and t1.direction = t2.direction
where
t1.event_type = '1' and t1.direction = #{direction}
<if test="type != null and type == '1'.toString">
and DATE_FORMAT(t1.start_time,'%Y%m%d') = DATE_FORMAT(DATE_SUB(#{startTime},INTERVAL 1 DAY),'%Y%m%d')
</if>
<if test="type != null and type == '2'.toString">
and DATE_FORMAT(t1.start_time,'%Y%m') = DATE_FORMAT(DATE_SUB(#{startTime},INTERVAL 1 MONTH),'%Y%m')
</if>
<if test="type != null and type == '3'.toString">
and YEAR(t1.start_time) = YEAR(DATE_SUB(#{startTime},INTERVAL 1 QUARTER)) and QUARTER(t1.start_time) = QUARTER(DATE_SUB(#{startTime},INTERVAL 1 QUARTER))
</if>
<if test="type != null and type == '4'.toString">
and YEAR(t1.start_time) = YEAR(DATE_SUB(#{startTime},INTERVAL 1 YEAR))
</if>
GROUP BY t2.section_id) t5
on t3.id = t5.section_id
</select>
<select id="selectEventTypeAnalysis" resultType="java.util.Map">
select t1.eventSubclass,t1.eventSubclassName,
IFNULL(t2.minuteTime,0) minuteTime,ROUND(IFNULL(t2.minuteTime/t2.num,0)) avgTime,
IFNULL(t3.minuteTime,0) lastMinuteTime,ROUND(IFNULL(t3.minuteTime/t3.num,0)) lastAvgTime
from
(select '1-1' eventSubclass, '追尾' eventSubclassName
UNION ALL select '1-2' eventSubclass, '侧翻' eventSubclassName
UNION ALL select '1-3' eventSubclass, '撞护栏' eventSubclassName
UNION ALL select '1-4' eventSubclass, '自燃' eventSubclassName
UNION ALL select '1-5' eventSubclass, '其他事故' eventSubclassName) t1
LEFT JOIN
(select event_subclass, count(*) num ,
sum(case when ISNULL(end_time)
then TIMESTAMPDIFF(MINUTE,start_time,now())
else TIMESTAMPDIFF(MINUTE,start_time,end_time)
end) minuteTime
from dc_event
where event_type = '1'
<if test="type != null and type == '1'.toString">
and DATE_FORMAT(start_time,'%Y%m%d') = DATE_FORMAT(#{startTime},'%Y%m%d')
</if>
<if test="type != null and type == '2'.toString">
and DATE_FORMAT(start_time,'%Y%m') = DATE_FORMAT(#{startTime},'%Y%m')
</if>
<if test="type != null and type == '3'.toString">
and YEAR(start_time) = YEAR(#{startTime}) and QUARTER(start_time) = QUARTER(#{startTime})
</if>
<if test="type != null and type == '4'.toString">
and YEAR(start_time) = YEAR(#{startTime})
</if>
group by event_subclass) t2
on t1.eventSubclass = t2.event_subclass
LEFT JOIN
(select event_subclass, count(*) num ,
sum(case when ISNULL(end_time)
then TIMESTAMPDIFF(MINUTE,start_time,now())
else TIMESTAMPDIFF(MINUTE,start_time,end_time)
end) minuteTime
from dc_event
where event_type = '1'
<if test="type != null and type == '1'.toString">
and DATE_FORMAT(start_time,'%Y%m%d') = DATE_FORMAT(DATE_SUB(#{startTime},INTERVAL 1 DAY),'%Y%m%d')
</if>
<if test="type != null and type == '2'.toString">
and DATE_FORMAT(start_time,'%Y%m') = DATE_FORMAT(DATE_SUB(#{startTime},INTERVAL 1 MONTH),'%Y%m')
</if>
<if test="type != null and type == '3'.toString">
and YEAR(start_time) = YEAR(DATE_SUB(#{startTime},INTERVAL 1 QUARTER)) and QUARTER(start_time) = QUARTER(DATE_SUB(#{startTime},INTERVAL 1 QUARTER))
</if>
<if test="type != null and type == '4'.toString">
and YEAR(start_time) = YEAR(DATE_SUB(#{startTime},INTERVAL 1 YEAR))
</if>
group by event_subclass) t3 on t1.eventSubclass = t3.event_subclass
</select>
</mapper>

16
zc-business/src/main/resources/mapper/business/DeviceMapper.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zc.business.mapper.DeviceMapper">
<resultMap id="BaseResultMap" type="com.zc.business.domain.Device">
<result column="id" jdbcType="BIGINT" property="id"/>
<result column="device_no" jdbcType="VARCHAR" property="deviceNo"/>
<result column="device_name" jdbcType="VARCHAR" property="deviceName"/>
<result column="device_ip" jdbcType="VARCHAR" property="deviceIp"/>
</resultMap>
<select id="SelectList" resultType="com.zc.business.domain.Device">
select * from device
</select>
</mapper>

94
zc-business/src/main/resources/mapper/business/StatusMapper.xml

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zc.business.mapper.StatusMapper">
<resultMap id="BaseResultMap" type="com.zc.business.domain.Status">
<result column="id" jdbcType="BIGINT" property="id"/>
<result column="device_no" jdbcType="VARCHAR" property="deviceNo"/>
<result column="device_name" jdbcType="VARCHAR" property="deviceName"/>
<result column="device_status" jdbcType="INTEGER" property="deviceStatus"/>
<result column="device_ip" jdbcType="VARCHAR" property="deviceIp"/>
<result column="success_rate" jdbcType="VARCHAR" property="successRate"/>
<result column="lost_rate" jdbcType="VARCHAR" property="lostRate"/>
<result column="direction" jdbcType="VARCHAR" property="direction"/>
<result column="production" jdbcType="VARCHAR" property="production"/>
<result column="model" jdbcType="VARCHAR" property="model"/>
<result column="network" jdbcType="VARCHAR" property="network"/>
<result column="content" jdbcType="VARCHAR" property="content"/>
<result column="type" jdbcType="VARCHAR" property="type"/>
</resultMap>
<insert id="Add" parameterType="com.zc.business.domain.Status">
INSERT INTO status
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="status.deviceNo != null">
device_no,
</if>
<if test="status.deviceName != null">
device_name,
</if>
<if test="status.deviceStatus != null">
device_status,
</if>
<if test="status.time != null">
time,
</if>
<if test="status.successRate != null">
success_rate,
</if>
<if test="status.lostRate != null">
lost_rate,
</if>
<if test="status.deviceIp != null">
device_ip,
</if>
</trim>
<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
<if test="status.deviceNo != null">
#{status.deviceNo,jdbcType=VARCHAR},
</if>
<if test="status.deviceName != null">
#{status.deviceName,jdbcType=VARCHAR},
</if>
<if test="status.deviceStatus != null">
#{status.deviceStatus,jdbcType=INTEGER},
</if>
<if test="status.time != null">
#{status.time,jdbcType=DATE},
</if>
<if test="status.successRate != null">
#{status.successRate,jdbcType=VARCHAR},
</if>
<if test="status.lostRate != null">
#{status.lostRate,jdbcType=VARCHAR},
</if>
<if test="status.deviceIp != null">
#{status.deviceIp,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<sql id="selectStatus">
select id, device_no, device_name, device_status, time from status
</sql>
<select id="listStatus" parameterType="com.zc.business.domain.Status" resultMap="BaseResultMap">
select s.id, s.device_no, s.device_name, s.device_status,s.time, d.device_ip,s.success_rate,s.lost_rate,d.direction,d.production,d.model,d.network,d.content,d.type
from status s
LEFT JOIN device d on s.device_ip = d.device_ip
<where>
<if test="status.time != null">
AND s.time BETWEEN #{status.startTime,jdbcType=DATE} AND #{status.time,jdbcType=DATE}
</if>
<if test="status.deviceNo != null">
AND s.device_no = #{status.deviceNo}
</if>
</where>
</select>
</mapper>
Loading…
Cancel
Save