From ae32807a9620c10353035c624b6f84aabc7df85c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LAPTOP-S9HJSOEB=5C=E6=98=8A=E5=A4=A9?= Date: Mon, 6 Nov 2023 11:56:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=8D=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E4=BA=91=E7=AB=AF=20=E6=B5=81=E5=AA=92=E4=BD=93=E6=8C=89?= =?UTF-8?q?=E9=9C=80=E6=8B=89=E5=8F=96=20=E7=90=83=E6=9C=BA=E7=AB=AF?= =?UTF-8?q?=E5=8F=A3=E5=BC=80=E6=94=BE=20=E7=90=83=E6=9C=BA=E8=BE=85?= =?UTF-8?q?=E7=A0=81=E6=B5=81=E6=9F=A5=E7=9C=8B=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/leaper/web/config/ConfigProperties.java | 1 + .../leaper/web/controller/CameraController.java | 4 ++-- .../main/java/com/leaper/web/entity/Camera.java | 2 ++ .../web/lib/hik/HikCameraControlModuleImpl.java | 17 ++++++++++------- .../com/leaper/web/service/CameraService.java | 6 ++---- .../java/com/leaper/web/service/FtpsUtils.java | 7 +++++++ web/src/main/resources/application-prod.yml | 2 +- web/src/main/resources/application-test.yml | 10 ++++++++-- web/src/main/resources/application.yml | 3 ++- 9 files changed, 35 insertions(+), 17 deletions(-) diff --git a/web/src/main/java/com/leaper/web/config/ConfigProperties.java b/web/src/main/java/com/leaper/web/config/ConfigProperties.java index ba9ce6d..6215e43 100644 --- a/web/src/main/java/com/leaper/web/config/ConfigProperties.java +++ b/web/src/main/java/com/leaper/web/config/ConfigProperties.java @@ -74,6 +74,7 @@ public class ConfigProperties { @Data public static class SavePath{ + private Boolean isCloudSave = true; private Integer saveDays = 30; private String mediaPath; private String mp4Path; diff --git a/web/src/main/java/com/leaper/web/controller/CameraController.java b/web/src/main/java/com/leaper/web/controller/CameraController.java index 1426d5a..29a3500 100644 --- a/web/src/main/java/com/leaper/web/controller/CameraController.java +++ b/web/src/main/java/com/leaper/web/controller/CameraController.java @@ -182,7 +182,7 @@ public class CameraController { JSONObject streams = new JSONObject(); cameras.forEach(camera -> { JSONObject obj = new JSONObject(); - obj.put("on_demand",false); + obj.put("on_demand",true); obj.put("disable_audio",true); obj.put("url",camera.getRtsp()); streams.put("camera"+camera.getId(),obj); @@ -215,7 +215,7 @@ public class CameraController { JSONObject streams = new JSONObject(); cameraList.forEach(camera -> { JSONObject obj = new JSONObject(); - obj.put("on_demand",false); + obj.put("on_demand",true); obj.put("disable_audio",true); obj.put("url",camera.getRtsp()); streams.put("camera"+camera.getId(),obj); diff --git a/web/src/main/java/com/leaper/web/entity/Camera.java b/web/src/main/java/com/leaper/web/entity/Camera.java index e29cd7c..0eaa887 100644 --- a/web/src/main/java/com/leaper/web/entity/Camera.java +++ b/web/src/main/java/com/leaper/web/entity/Camera.java @@ -41,4 +41,6 @@ public class Camera { @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") private LocalDateTime updateTime; + + private Integer rtspPort; } diff --git a/web/src/main/java/com/leaper/web/lib/hik/HikCameraControlModuleImpl.java b/web/src/main/java/com/leaper/web/lib/hik/HikCameraControlModuleImpl.java index 1f75f28..b4d365e 100644 --- a/web/src/main/java/com/leaper/web/lib/hik/HikCameraControlModuleImpl.java +++ b/web/src/main/java/com/leaper/web/lib/hik/HikCameraControlModuleImpl.java @@ -252,9 +252,10 @@ public class HikCameraControlModuleImpl implements CameraControlModule { log.error("pic error:{},cameraId:{}", HikLoginModuleImpl.hcNetsdk.NET_DVR_GetLastError(),cameraId); } //上传到云服务器 - - FtpsUtils ftpsUtils = SpringContextUtil.getBean(FtpsUtils.class); - ftpsUtils.moveFile(true,10, path,savePath.getMediaPath() + path.replace(savePath.getMediaPathCache(),"")); + if(savePath.getIsCloudSave()) { + FtpsUtils ftpsUtils = SpringContextUtil.getBean(FtpsUtils.class); + ftpsUtils.moveFile(true, 10, path, savePath.getMediaPath() + path.replace(savePath.getMediaPathCache(), "")); + } return picResult; } @@ -278,6 +279,7 @@ public class HikCameraControlModuleImpl implements CameraControlModule { downloadtimer.schedule(new DownloadTask(result,downloadtimer,path,cameraId,savePath), 0, 5000); } + } class DownloadTask extends java.util.TimerTask { @@ -317,10 +319,11 @@ public class HikCameraControlModuleImpl implements CameraControlModule { PathUtil.deleteFile(path); File file = new File(ffmpegFile); file.renameTo(new File(path)); - - //上传到云服务器 - FtpsUtils ftpsUtils = SpringContextUtil.getBean(FtpsUtils.class); - ftpsUtils.moveFile(true,10, path,savePath.getMp4Path() + path.replace(savePath.getMp4PathCache(),"")); + if (savePath.getIsCloudSave()) { + //上传到云服务器 + FtpsUtils ftpsUtils = SpringContextUtil.getBean(FtpsUtils.class); + ftpsUtils.moveFile(true, 10, path, savePath.getMp4Path() + path.replace(savePath.getMp4PathCache(), "")); + } }else { log.debug("cameraId:{},progress:{}",cameraId,nPos.getValue()); } diff --git a/web/src/main/java/com/leaper/web/service/CameraService.java b/web/src/main/java/com/leaper/web/service/CameraService.java index 63060ca..c624b17 100644 --- a/web/src/main/java/com/leaper/web/service/CameraService.java +++ b/web/src/main/java/com/leaper/web/service/CameraService.java @@ -67,9 +67,8 @@ public class CameraService { public Integer add(Camera camera) { camera.setUser(configProperties.getCameraConfig().getCameraUser()); camera.setPassword(configProperties.getCameraConfig().getCameraPassword()); - camera.setPort(configProperties.getCameraConfig().getCameraPort()); camera.setUpdateTime(LocalDateTime.now()); - camera.setRtsp("rtsp://"+configProperties.getCameraConfig().getCameraUser()+":"+configProperties.getCameraConfig().getCameraPassword()+"@"+camera.getIp()+":554/cam/realmonitor?channel=1&subtype=0"); + camera.setRtsp("rtsp://"+configProperties.getCameraConfig().getCameraUser()+":"+configProperties.getCameraConfig().getCameraPassword()+"@"+camera.getIp()+":"+camera.getRtspPort()+"/h264/ch1/sub/avstream"); if(StringUtils.isEmpty(camera.getRtcServer())){ camera.setRtcServer("127.0.0.1"); } @@ -89,9 +88,8 @@ public class CameraService { if(StringUtils.isEmpty(camera.getRtcServer())){ camera.setRtcServer("127.0.0.1"); } - camera.setPort(configProperties.getCameraConfig().getCameraPort()); camera.setUser(configProperties.getCameraConfig().getCameraUser()); - camera.setRtsp("rtsp://"+configProperties.getCameraConfig().getCameraUser()+":"+configProperties.getCameraConfig().getCameraPassword()+"@"+camera.getIp()+":554/cam/realmonitor?channel=1&subtype=0"); + camera.setRtsp("rtsp://"+configProperties.getCameraConfig().getCameraUser()+":"+configProperties.getCameraConfig().getCameraPassword()+"@"+camera.getIp()+":"+camera.getRtspPort()+"/h264/ch1/sub/avstream"); try { cameraMapper.updateById(camera); } catch (DuplicateKeyException e) { diff --git a/web/src/main/java/com/leaper/web/service/FtpsUtils.java b/web/src/main/java/com/leaper/web/service/FtpsUtils.java index 734db37..35e50a4 100644 --- a/web/src/main/java/com/leaper/web/service/FtpsUtils.java +++ b/web/src/main/java/com/leaper/web/service/FtpsUtils.java @@ -76,6 +76,13 @@ public class FtpsUtils { } + /** + * 移动文件 + * @param flag 是否移动 + * @param count 尝试次数 + * @param srcFilePath 开始地址 + * @param targetFilePath 目标地址 + */ public void moveFile(boolean flag ,int count, String srcFilePath, String targetFilePath) { diff --git a/web/src/main/resources/application-prod.yml b/web/src/main/resources/application-prod.yml index 3cbfe3e..e6993ee 100644 --- a/web/src/main/resources/application-prod.yml +++ b/web/src/main/resources/application-prod.yml @@ -7,7 +7,7 @@ spring: maxWait: 60000 minEvictableIdleTimeMillis: 300000 minIdle: 15 - password: Leaper@123 + password: root poolPreparedStatements: true testOnBorrow: true testOnReturn: false diff --git a/web/src/main/resources/application-test.yml b/web/src/main/resources/application-test.yml index a55e493..1f7b752 100644 --- a/web/src/main/resources/application-test.yml +++ b/web/src/main/resources/application-test.yml @@ -51,8 +51,10 @@ cameraConfig: # ------------ # -----图片 mp4下载地址 savePath: + #是否云端保存 + isCloudSave: true saveDays: 1 -# 定期删除文件cron解析 + # 定期删除文件cron解析 deleteSaveCron: 0 0 0 2 * ? cloudIp: 121.37.95.190 cloudUser: root @@ -100,4 +102,8 @@ scanCodeMode: trayCodeTypes: - 14 # 照片 視頻保存多久 -deleteFileDays: 365 \ No newline at end of file +deleteFileDays: 365 + +mybatis-plus: + configuration: + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl \ No newline at end of file diff --git a/web/src/main/resources/application.yml b/web/src/main/resources/application.yml index 58bad61..43bf79b 100644 --- a/web/src/main/resources/application.yml +++ b/web/src/main/resources/application.yml @@ -34,4 +34,5 @@ zhehe: enable: true postToken: w89euijon2&UHBTY$%huni34ri logging: - config: classpath:logback-spring.xml \ No newline at end of file + config: classpath:logback-spring.xml +