diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java index 1f850882..37718d3a 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java @@ -551,7 +551,9 @@ public class DcDeviceOnlineController extends BaseController { //光纤在线监测14 SOLAR_PANEL("15", "离网光伏供电"), REMOTE_COMPUTER("16", "远端机"), - INTEGRATED_CABINET("17", "一体机柜"); + INTEGRATED_CABINET("17", "一体机柜"), + INTEGRATED_CABINET_AIR_CONDITIONER("18", "一体机柜空调"); + private final String value; private final String description; diff --git a/zc-business/src/main/java/com/zc/business/controller/DcWarningController.java b/zc-business/src/main/java/com/zc/business/controller/DcWarningController.java index b651abf6..8cfc37c4 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcWarningController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcWarningController.java @@ -297,7 +297,7 @@ public class DcWarningController extends BaseController @GetMapping("/video/{id}") public AjaxResult getRadarIncidentVideo(@PathVariable("id") String id)throws Exception{ - return AjaxResult.success(dcWarningService.getRadarIncidentVideo(id)); + return AjaxResult.success(dcWarningService.getRadarIncidentVideoUrl(id)); } //首页气象预警,最近三天的数据 @@ -323,6 +323,12 @@ public class DcWarningController extends BaseController return getDataTable(updatedList); } - + @ApiOperation("查询雷达事件视频回放列表") + // @PreAuthorize("@ss.hasPermi('business:warning:list')") + @GetMapping("/radarList") + public TableDataInfo radarList(DcWarning dcWarning) + { + return getDataTable(dcWarningService.radarList(dcWarning)) ; + } } 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 new file mode 100644 index 00000000..9c93ba26 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/controller/RadarController.java @@ -0,0 +1,208 @@ +package com.zc.business.controller; + +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.spring.SpringUtils; +import com.ruoyi.system.service.ISysConfigService; +import com.zc.business.domain.DcWarning; +import com.zc.business.service.IDcWarningService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.net.ftp.FTP; +import org.apache.commons.net.ftp.FTPClient; +import org.springframework.stereotype.Component; + +import java.io.BufferedInputStream; +import java.io.Closeable; +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.List; + +/** + * + */ +@Component() +@Slf4j +public class RadarController { + ISysConfigService configService = SpringUtils.getBean(ISysConfigService.class); + IDcWarningService dcWarningService = SpringUtils.getBean(IDcWarningService.class); + + public void radarDownload() { + + // 获取当前时间 + LocalDateTime now = LocalDateTime.now(); + // 定义格式 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + // 获取当前时间前5分钟的时间点 + LocalDateTime fifteenMinutesAgo = now.minus(Duration.ofMinutes(5)); + String FifteenMinutesAgo = fifteenMinutesAgo.format(formatter); + + // 获取当前时间前20分钟的时间点 + LocalDateTime twentyMinutesAgo = now.minus(Duration.ofMinutes(20)); + 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); + } + + } + }); + } + + + 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; + InputStream inputStream = null; + String URL = "https://10.0.111.11/eventAi"; + try { + // 空格编码并构建URL + String encodedUrl = encodeUriComponent(baseUrl); + 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(); + + if (responseCode == HttpURLConnection.HTTP_OK) { + log.info("成功连接到HTTP服务器"); + // 连接到FTP服务器 + ftpClient.connect(ftpServer, port); + boolean loginResult = ftpClient.login(user, pass); + if (!loginResult) { + throw new IOException("FTP登录失败"); + } + log.info("成功登录到FTP服务器"); + // 设置为二进制传输模式和被动模式 + ftpClient.setFileType(FTP.BINARY_FILE_TYPE); + ftpClient.enterLocalPassiveMode(); // 使用被动模式 + // 创建输入流 + inputStream = new BufferedInputStream(httpConn.getInputStream()); + + // 创建远程目录 + if (!remotePath.isEmpty()) { + // 将路径拆分为各个部分,逐级创建目录 + for (String part : remotePath.split("/")) { + if (!part.isEmpty()) { + if (!ftpClient.changeWorkingDirectory(part)) { + if (ftpClient.makeDirectory(part)) { + log.info("成功创建远程目录: " + part); + if (!ftpClient.changeWorkingDirectory(part)) { + log.info("无法切换到新创建的远程目录: " + part); + } + } else { + log.info("无法创建远程目录: " + part); + } + } + } + } + // 确认最终工作目录 + log.info("最终工作目录: " + ftpClient.printWorkingDirectory()); + } + // 上传文件到FTP服务器 + boolean done = ftpClient.storeFile(fileName, inputStream); + if (done) { + log.info("文件上传成功"); + return URL+ftpClient.printWorkingDirectory()+"/" + fileName; + } else {// 文件上传失败 + return null; + } + } else { + throw new IOException("无法从HTTP服务器获取文件,响应码:" + responseCode); + } + } finally { + // 关闭资源 + closeQuietly(inputStream); + if (httpConn != null) { + httpConn.disconnect(); + } + if (ftpClient.isConnected()) { + try { + ftpClient.logout(); + ftpClient.disconnect(); + } catch (IOException ignored) { + } + } + } + } + + // 安全关闭流的方法 + private static void closeQuietly(Closeable closeable) { + if (closeable != null) { + try { + closeable.close(); + } catch (IOException ignored) { + } + } + } + + // + + /* + private static String encodeUriComponent(String component, java.nio.charset.Charset charset) { + try { + return java.net.URLEncoder.encode(component, charset.toString()) + .replaceAll("\\+", "%20") // 将空格替换为 %20 + .replaceAll("%2F", "/"); // 保留斜杠 + } catch (Exception e) { + throw new RuntimeException(e); + } + } + */ +//保留 URL 中的特殊字符如 : / 等 + private static String encodeUriComponent(String component) { + try { + URI uri = new URI(null, null, component, null); + return uri.toASCIIString(); + } catch (URISyntaxException e) { + throw new RuntimeException("URI编码错误", e); + } + } + + +} 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 b4fcb900..707389bf 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 @@ -881,7 +881,7 @@ public class VideoController extends BaseController { if (HttpStatus.SUCCESS == jsonResult.getInteger("code")) { Map data = jsonResult.getJSONObject("data"); String fileUrl = data.get("fileUrl").toString(); - fileUrl = configService.selectConfigByKey("dc.cameraUrl") + fileUrl.substring(UniversalEnum.SEVEN.getNumber()); + // fileUrl = configService.selectConfigByKey("dc.cameraUrl") + fileUrl.substring(UniversalEnum.SEVEN.getNumber()); data.put("fileUrl",fileUrl); jsonResult.put("data",data); } else if (UNAUTHORIZED.equals(jsonResult.getInteger("code"))) { @@ -892,7 +892,7 @@ public class VideoController extends BaseController { if (HttpStatus.SUCCESS == jsonResult.getInteger("code")) { Map data = jsonResult.getJSONObject("data"); String fileUrl = data.get("fileUrl").toString(); - fileUrl = configService.selectConfigByKey("cameraUrl") + fileUrl.substring(UniversalEnum.SEVEN.getNumber()); + //fileUrl = configService.selectConfigByKey("cameraUrl") + fileUrl.substring(UniversalEnum.SEVEN.getNumber()); data.put("liveUrl",fileUrl); jsonResult.put("data",data); } diff --git a/zc-business/src/main/java/com/zc/business/domain/DcWarning.java b/zc-business/src/main/java/com/zc/business/domain/DcWarning.java index 094b8bc6..5860167b 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcWarning.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcWarning.java @@ -177,6 +177,15 @@ public class DcWarning extends BaseEntity private Long facilityId; private String fileUrl; + private String radarUrl; + + public String getRadarUrl() { + return radarUrl; + } + + public void setRadarUrl(String radarUrl) { + this.radarUrl = radarUrl; + } public String getFileUrl() { return fileUrl; diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java index 04dbcb95..b2a22bfc 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java @@ -174,4 +174,7 @@ public interface DcWarningMapper List videoReviewEventTimeList(DcWarning dcWarning); + List radarList(DcWarning dcWarning); + + DcWarning selectRadarIncidentVideoUrl(String id); } diff --git a/zc-business/src/main/java/com/zc/business/service/IDcWarningService.java b/zc-business/src/main/java/com/zc/business/service/IDcWarningService.java index 0ed7c59e..c206f1ec 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcWarningService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcWarningService.java @@ -129,4 +129,8 @@ Map selectVideoReviewSectionDistribution(DcWarning dcWarning); Map videoReviewEventTime(DcWarning dcWarning); List videoReviewEventTimeList(DcWarning dcWarning); + + List radarList(DcWarning dcWarning); + + String getRadarIncidentVideoUrl(String id); } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java index c6996e2f..4c301e29 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java @@ -1653,6 +1653,19 @@ public class DcWarningServiceImpl implements IDcWarningService { List dcWarningList = dcWarningMapper.videoReviewEventTimeList(dcWarning); return dcWarningList; } +//雷达数据 + @Override + public List radarList(DcWarning dcWarning) { + List radarList = dcWarningMapper.radarList(dcWarning); + + return radarList; + } + + @Override + public String getRadarIncidentVideoUrl(String id) { + DcWarning dcWarnings = dcWarningMapper.selectRadarIncidentVideoUrl(id); + return dcWarnings.getRadarUrl(); + } private Map groupByMonth(List dcWarningsOne, List dcWarningsTwo) { // 分别对两个列表按月份分组 diff --git a/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml b/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml index c284bfb9..0062a0be 100644 --- a/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml @@ -28,6 +28,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -229,6 +230,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" other_config = #{otherConfig}, lane = #{lane}, vehicle_type = #{vehicleType}, + radar_url = #{radarUrl}, where id = #{id} @@ -578,4 +580,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + +