Jelajahi Sumber

Merge branch 'master' of http://124.70.58.209:3000/ytrd-project-management/GeoHazardMonitor

gao.qiang 1 tahun lalu
induk
melakukan
5ec1d8e6c6

+ 0 - 1
business-service/src/main/java/com/ozs/service/entity/CameraLogDetail.java

@@ -73,7 +73,6 @@ public class CameraLogDetail implements Serializable {
     /**
      * 备注
      */
-    @Excel(name = "备注")
     private String remark;
 
     /**

+ 13 - 13
business-service/src/main/java/com/ozs/service/service/impl/CameraCaptureService.java

@@ -25,6 +25,7 @@ public class CameraCaptureService {
         HttpURLConnection connection = null;
         BufferedInputStream bis = null;
         BufferedOutputStream bos = null;
+        ByteArrayOutputStream byteArrayOutputStream = null;
         try {
             connection = (HttpURLConnection) url.openConnection();
             // http正文内,因此需要设为true
@@ -49,20 +50,19 @@ public class CameraCaptureService {
             connection.connect();
 
             // 返回流
-            System.out.println("responseCode=" + connection.getResponseCode());
+            System.out.println("responseCode=" + connection.getResponseCode()+"url"+url.toString());
             log.info("responseCode="+connection.getResponseCode());
             if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
                 InputStream input = connection.getInputStream();
                 bis = new BufferedInputStream(input);
-                minioUtils.minIoClientUpload(bis, fileName);
-                FileOutputStream output = new FileOutputStream(fileName);
-                bos = new BufferedOutputStream(output);
-                byte[] buffer = new byte[1024];
-                int size = 0;
-                while ((size = bis.read(buffer, 0, 1024)) != -1) {
-                    bos.write(buffer, 0, size);
+                byte [] bytes = new byte[102400];
+                int index = 0;
+                byteArrayOutputStream = new ByteArrayOutputStream();
+                while (-1 != (index = input.read(bytes,0,bytes.length))){
+                    byteArrayOutputStream.write(bytes,0,index);
                 }
-                bos.flush();
+                ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
+                minioUtils.minIoClientUpload(byteArrayInputStream, fileName);
             }
         } catch (Exception e) {
             //先关闭外层的缓冲流,再关闭内层的流,但是在关闭外层流的同时,
@@ -72,13 +72,13 @@ public class CameraCaptureService {
             if (bis != null) {
                 bis.close();
             }
-//            if (bos != null) {
-//                bos.close();
-//            }
             if (connection != null) {
                 connection.disconnect();
             }
-//            os.close();
+            if(byteArrayOutputStream != null){
+                byteArrayOutputStream.flush();
+                byteArrayOutputStream.close();
+            }
         }
     }
 }

+ 0 - 80
hazard-admin/src/main/java/com/ozs/web/controller/common/PictureController.java

@@ -1,80 +0,0 @@
-package com.ozs.web.controller.common;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.ozs.common.core.domain.AjaxResult;
-import com.ozs.common.utils.ApiTokenUtils;
-import com.ozs.common.utils.MinioUtils;
-import com.ozs.common.utils.uuid.IdUtils;
-import com.ozs.service.entity.BaseCameraManagement;
-import com.ozs.service.entity.MsgAlarm;
-import com.ozs.service.service.BaseCameraManagementService;
-import com.ozs.service.service.MsgAlarmService;
-import com.ozs.service.service.impl.CameraCaptureService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.util.ObjectUtils;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import javax.annotation.Resource;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.List;
-
-/**
- * @author wyy
- * @subject
- * @creat 2023/4/18
- */
-@RestController
-@RequestMapping("/getPicture")
-public class PictureController {
-    private static final Logger log = LoggerFactory.getLogger(PictureController.class);
-    @Resource
-    private ApiTokenUtils apiTokenUtils;
-    @Resource
-    BaseCameraManagementService baseCameraManagementService;
-    @Resource
-    MsgAlarmService msgAlarmService;
-    @Resource
-    CameraCaptureService cameraCaptureService;
-
-    /**
-     * 获取图片
-     *
-     * @param
-     * @return
-     */
-    @PostMapping("/api/snap")
-    public AjaxResult getPicture() throws IOException {
-        List<BaseCameraManagement> list = baseCameraManagementService.list();
-        list.forEach(l -> {
-            String uuid = IdUtils.fastSimpleUUID();
-            if(!ObjectUtils.isEmpty(l.getCameraCode()) &&!ObjectUtils.isEmpty(l.getChannel())){
-                QueryWrapper<MsgAlarm> queryWrapper = new QueryWrapper<MsgAlarm>();
-                queryWrapper.lambda().eq(MsgAlarm::getCameraCode,l.getCameraCode());
-                queryWrapper.lambda().eq(MsgAlarm::getIsLock,2);
-                List<MsgAlarm> msgAlarmList = msgAlarmService.list(queryWrapper);
-                try {
-                    System.out.println("http://124.70.58.209:18891/snap/"+l.getCameraCode()+"/"+l.getChannel());
-                    log.info("请求url"+"http://124.70.58.209:18891/snap/"+l.getCameraCode()+"/"+l.getChannel());
-                    URL url = new URL("http://124.70.58.209:18891/snap/"+l.getCameraCode()+"/"+l.getChannel());
-                    String fileName = "cameraPicture/"+l.getCameraCode()+"_"+uuid +".jpg";
-                    log.info("fileName="+fileName);
-                    cameraCaptureService.getCapture(url, fileName);
-                } catch (MalformedURLException e) {
-                    e.printStackTrace();
-                } catch (IOException e) {
-                    e.printStackTrace();
-                }
-            }
-        });
-        return AjaxResult.success(list);
-    }
-}

+ 71 - 0
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/ShotExecutors.java

@@ -0,0 +1,71 @@
+package com.ozs.web.controller.shotschedule;
+
+import com.ozs.system.service.ISysDictDataService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import java.util.UUID;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author wyy
+ * @subject
+ * @creat 2023/5/6
+ */
+@Configuration
+@EnableScheduling
+@EnableAsync
+@Slf4j
+public class ShotExecutors {
+
+   // private  static ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
+    @Autowired
+    private ISysDictDataService dictDataService;
+    @Autowired
+    private TaskNormalService taskNormalService; //定时任务-没有报警摄像头
+    @Autowired
+    private TaskAlarmService taskAlarmService;//定时任务-报警摄像头
+
+    /**
+     * 处理非预警摄像头截图
+     */
+    @Async
+    @Scheduled(fixedRate = 500)
+    public void handleNormalPicture() {
+        boolean shotSwitch = Boolean.parseBoolean(dictDataService.selectDictLabel("shot_switch", String.valueOf(0)));
+        try {
+            if (shotSwitch) {
+                taskNormalService.getNormalPicture();
+            }
+        } catch (Exception e) {
+            e.getMessage();
+            log.error(e.getMessage());
+        }
+    }
+
+    /**
+     * 处理预警摄像头截图
+     */
+    @Async
+    @Scheduled(fixedRate = 200)
+    public void handleAlarmPicture() {
+        boolean shotSwitch = Boolean.parseBoolean(dictDataService.selectDictLabel("shot_switch", String.valueOf(0)));
+        try {
+            if (shotSwitch) {
+                taskAlarmService.getAlarmPicture();
+            }
+        } catch (Exception e) {
+            e.getMessage();
+            log.error(e.getMessage());
+        }
+    }
+}

+ 79 - 0
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/TaskAlarmService.java

@@ -0,0 +1,79 @@
+package com.ozs.web.controller.shotschedule;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ozs.common.utils.uuid.IdUtils;
+import com.ozs.service.entity.BaseCameraManagement;
+import com.ozs.service.entity.MsgAlarm;
+import com.ozs.service.service.BaseCameraManagementService;
+import com.ozs.service.service.MsgAlarmService;
+import com.ozs.service.service.impl.CameraCaptureService;
+import com.ozs.system.service.ISysDictDataService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.ObjectUtils;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * @author wyy
+ * @subject
+ * @creat 2023/5/6
+ */
+@Slf4j
+@Service
+public class TaskAlarmService {
+    @Resource
+    BaseCameraManagementService baseCameraManagementService;
+    @Resource
+    MsgAlarmService msgAlarmService;
+    @Resource
+    CameraCaptureService cameraCaptureService;
+    @Autowired
+    private ISysDictDataService dictDataService;
+    private  static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+    @Value("${shot.urlAddress}")
+    private String urlAddress;
+
+
+    public void getAlarmPicture() {
+        QueryWrapper<MsgAlarm> queryWrapper = new QueryWrapper<MsgAlarm>();
+        queryWrapper.lambda().eq(MsgAlarm::getIsLock,2);
+        List<MsgAlarm> msgAlarmList = msgAlarmService.list(queryWrapper);
+        if(!CollectionUtils.isEmpty(msgAlarmList) && Objects.nonNull(msgAlarmList.get(0))){
+            msgAlarmList.forEach(l -> {
+                String uuid = IdUtils.fastSimpleUUID();
+                QueryWrapper<BaseCameraManagement> wrapper = new QueryWrapper<BaseCameraManagement>();
+                wrapper.lambda().eq(BaseCameraManagement::getCameraCode,l.getCameraCode());
+                BaseCameraManagement baseCameraManagement = baseCameraManagementService.getOne(wrapper);
+                if(!ObjectUtils.isEmpty(l.getCameraCode()) &&!ObjectUtils.isEmpty(baseCameraManagement)){
+                    try {
+                        System.out.println(urlAddress+l.getCameraCode()+"/"+baseCameraManagement.getChannel());
+                        log.info("请求url======"+urlAddress+l.getCameraCode()+"/"+baseCameraManagement.getChannel());
+                        URL url = new URL(urlAddress+l.getCameraCode()+"/"+baseCameraManagement.getChannel());
+                        String root = dictDataService.selectDictLabel("shot_address", String.valueOf(0));
+                        String dateString = format.format(new Date());
+                        String fileName = root + "/" + dateString + "/" + uuid + ".jpeg";
+                        //String fileName = root + "/" + dateString + "/alarm/"+ l.getCameraCode()+"_"+ uuid + ".jpeg";
+                        log.info("fileName======"+fileName);
+                        log.info("报警摄像头截图开始");
+                        cameraCaptureService.getCapture(url, fileName);
+                        log.info("报警摄像头截图结束");
+                    } catch (Throwable e) {
+                        e.printStackTrace();
+                        log.error(e.getMessage());
+                    }
+                }
+            });
+        }
+    }
+}

+ 82 - 0
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/TaskNormalService.java

@@ -0,0 +1,82 @@
+package com.ozs.web.controller.shotschedule;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ozs.common.utils.uuid.IdUtils;
+import com.ozs.service.entity.BaseCameraManagement;
+import com.ozs.service.entity.MsgAlarm;
+import com.ozs.service.service.BaseCameraManagementService;
+import com.ozs.service.service.MsgAlarmService;
+import com.ozs.service.service.impl.CameraCaptureService;
+import com.ozs.system.service.ISysDictDataService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.ObjectUtils;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * @author wyy
+ * @subject
+ * @creat 2023/5/6
+ */
+@Slf4j
+@Service
+public class TaskNormalService{
+    @Resource
+    BaseCameraManagementService baseCameraManagementService;
+    @Resource
+    MsgAlarmService msgAlarmService;
+    @Resource
+    CameraCaptureService cameraCaptureService;
+    @Autowired
+    private ISysDictDataService dictDataService;
+    private  static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+    @Value("${shot.urlAddress}")
+    private String urlAddress;
+
+
+    public void getNormalPicture() {
+        List<BaseCameraManagement> list = baseCameraManagementService.list();
+        QueryWrapper<MsgAlarm> queryWrapper = new QueryWrapper<MsgAlarm>();
+        queryWrapper.lambda().eq(MsgAlarm::getIsLock,2);
+        List<MsgAlarm> msgAlarmList = msgAlarmService.list(queryWrapper);
+        list.forEach(l -> {
+            if(!CollectionUtils.isEmpty(msgAlarmList) && Objects.nonNull(msgAlarmList.get(0))) {
+                boolean isCotain = msgAlarmList.stream().filter(m -> m.getCameraCode().equals(l.getCameraCode())).findAny().isPresent();
+                    if(isCotain){
+                        return;
+                    }
+            }
+            String uuid = IdUtils.fastSimpleUUID();
+            if (!ObjectUtils.isEmpty(l.getCameraCode()) && !ObjectUtils.isEmpty(l.getChannel())) {
+                try {
+                    System.out.println(urlAddress + l.getCameraCode() + "/" + l.getChannel());
+                    log.info("请求url======" + urlAddress + l.getCameraCode() + "/" + l.getChannel());
+                    URL url = new URL(urlAddress + l.getCameraCode() + "/" + l.getChannel());
+                    String root = dictDataService.selectDictLabel("shot_address", String.valueOf(0));
+                    String dateString = format.format(new Date());
+                    String fileName = root + "/" + dateString + "/" + uuid + ".jpeg";
+                    //String fileName = root + "/" + dateString + "/normal/"+ l.getCameraCode()+"_"+ uuid + ".jpeg";
+                    log.info("fileName======" + fileName);
+                    log.info("没有报警摄像头截图开始");
+                    cameraCaptureService.getCapture(url, fileName);
+                    log.info("没有报警摄像头截图结束");
+                } catch (MalformedURLException e) {
+                    e.printStackTrace();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        });
+    }
+}

+ 3 - 0
hazard-admin/src/main/resources/application.yml

@@ -168,3 +168,6 @@ mqtt:
   host: tcp://124.70.58.209:1883
   userName: guest
   passWord: guest
+
+shot:
+  urlAddress: http://124.70.58.209:18891/snap/