Bladeren bron

截图定时修改

wyyay 10 maanden geleden
bovenliggende
commit
cee59a52d6

+ 5 - 0
business-service/src/main/java/com/ozs/service/service/MsgAlarmService.java

@@ -1,6 +1,7 @@
 package com.ozs.service.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.ozs.service.entity.BaseCameraManagement;
 import com.ozs.service.entity.MsgAlarm;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ozs.service.entity.vo.*;
@@ -52,4 +53,8 @@ public interface MsgAlarmService extends IService<MsgAlarm> {
     List<MsgAlarm> queryAlarmInfoByAfterTenMinute();
 
     IPage<MsgAlarm> queryPageHome(MsgAlarmVo msgAlarmVo);
+
+    List<BaseCameraManagement> getBaseCameraManagementsByLockedMsgAlarms(Integer isLock);
+
+    List<BaseCameraManagement> getBaseCameraManagements();
 }

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

@@ -62,6 +62,7 @@ public class CameraCaptureService {
                     byteArrayOutputStream.write(bytes,0,index);
                 }
                 ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
+                log.info("getCapture======" + fileName);
                 minioUtils.minIoClientUpload(byteArrayInputStream, fileName);
             }
         } catch (Exception e) {

+ 35 - 0
business-service/src/main/java/com/ozs/service/service/impl/MsgAlarmServiceImpl.java

@@ -1,11 +1,13 @@
 package com.ozs.service.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.pagehelper.PageHelper;
 import com.ozs.common.utils.AppendUtils;
 import com.ozs.common.utils.StringUtils;
+import com.ozs.service.entity.BaseCameraManagement;
 import com.ozs.service.entity.BaseUser;
 import com.ozs.service.entity.MsgAlarm;
 import com.ozs.service.entity.vo.*;
@@ -20,6 +22,7 @@ import org.springframework.util.CollectionUtils;
 import org.springframework.util.ObjectUtils;
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -152,4 +155,36 @@ public class MsgAlarmServiceImpl extends ServiceImpl<MsgAlarmMapper, MsgAlarm> i
         pageR.setTotal(page.getTotal());
         return pageR;
     }
+
+    @Override
+    public List<BaseCameraManagement> getBaseCameraManagementsByLockedMsgAlarms(Integer isLock) {
+        // 查询MsgAlarm中isLock=的数据
+        List<MsgAlarm> lockedMsgAlarms = msgAlarmMapper.selectList(new QueryWrapper<MsgAlarm>().eq("is_lock", isLock));
+        if (lockedMsgAlarms.isEmpty()) {
+            return Collections.emptyList();
+        }
+        // 提取cameraCode列表
+        List<String> cameraCodeListR = lockedMsgAlarms.stream().map(MsgAlarm::getCameraCode).collect(Collectors.toList());
+        List<String> cameraCodeList = new ArrayList<>(new TreeSet<>(cameraCodeListR));
+        // 使用QueryWrapper和in方法根据cameraCode列表查询BaseCameraManagement数据
+        QueryWrapper<BaseCameraManagement> queryWrapper = new QueryWrapper<>();
+        queryWrapper.in("camera_code", cameraCodeList);
+        List<BaseCameraManagement> list = baseCameraManagementMapper.selectList(queryWrapper);
+        return list;
+    }
+
+    @Override
+    public List<BaseCameraManagement> getBaseCameraManagements() {
+        List<MsgAlarm> lockedMsgAlarms = msgAlarmMapper.selectList(new QueryWrapper<MsgAlarm>().eq("is_lock", 2));
+        if (lockedMsgAlarms.isEmpty()) {
+            return Collections.emptyList();
+        }
+        List<String> cameraCodeListR = lockedMsgAlarms.stream().map(MsgAlarm::getCameraCode).collect(Collectors.toList());
+        List<String> cameraCodeList = new ArrayList<>(new TreeSet<>(cameraCodeListR));
+        // 使用QueryWrapper和in方法根据cameraCode列表查询BaseCameraManagement数据
+        QueryWrapper<BaseCameraManagement> queryWrapper = new QueryWrapper<>();
+        queryWrapper.notIn("camera_code", cameraCodeList);
+        List<BaseCameraManagement> list = baseCameraManagementMapper.selectList(queryWrapper);
+        return list;
+    }
 }

+ 7 - 16
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/ShotExecutors.java

@@ -11,44 +11,36 @@ 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 org.springframework.util.CollectionUtils;
 
-import javax.annotation.PostConstruct;
 import java.util.List;
 import java.util.Objects;
-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
+ * @creat 2024/3/1
  */
 @Configuration
 @EnableScheduling
 @EnableAsync
 @Slf4j
-public class ShotExecutors {
-
-   // private  static ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
+public class ShotPictureExecutors {
     @Autowired
     private ISysDictDataService dictDataService;
     @Autowired
     private ISysDictTypeService iSysDictTypeService;
     @Autowired
-    private TaskNormalService taskNormalService; //定时任务-没有报警摄像头
-    @Autowired
-    private TaskAlarmService taskAlarmService;//定时任务-报警摄像头
+    private TaskService taskService; //任务
 
     /**
      * 处理非预警摄像头截图
      */
     @Async
     @Scheduled(fixedRate = 60000)
-    public void handleNormalPicture() {
+    public synchronized void handleNormalPicture() {
         List<SysDictData> dataList = DictUtils.getDictCache("shot_switch");
         if(CollectionUtils.isEmpty(dataList) || Objects.isNull(dataList.get(0))){
             dataList = iSysDictTypeService.selectDictDataByType("shot_switch");
@@ -58,7 +50,7 @@ public class ShotExecutors {
         try {
             if(!CollectionUtils.isEmpty(dataList) && Objects.nonNull(dataList.get(0))){
                 if (Boolean.parseBoolean(dataList.get(0).getDictLabel())) {
-                    taskNormalService.getNormalPicture();
+                        taskService.getNormalPicture();
                 }
             }
         } catch (Exception e) {
@@ -72,17 +64,16 @@ public class ShotExecutors {
      */
     @Async
     @Scheduled(fixedRate = 500)
-    public void handleAlarmPicture() {
+    public synchronized void handleAlarmPicture() {
         List<SysDictData> dataList = DictUtils.getDictCache("shot_switch");
         if(CollectionUtils.isEmpty(dataList) || Objects.isNull(dataList.get(0))){
             dataList = iSysDictTypeService.selectDictDataByType("shot_switch");
             DictUtils.setDictCache("shot_switch",dataList);
         }
-        //boolean shotSwitch = Boolean.parseBoolean(dictDataService.selectDictLabel("shot_switch", String.valueOf(0)));
         try {
             if(!CollectionUtils.isEmpty(dataList) && Objects.nonNull(dataList.get(0))){
                 if (Boolean.parseBoolean(dataList.get(0).getDictLabel())) {
-                    taskAlarmService.getAlarmPicture();
+                    taskService.getAlarmPicture();
                 }
             }
         } catch (Exception e) {

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

@@ -1,79 +0,0 @@
-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());
-                    }
-                }
-            });
-        }
-    }
-}

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

@@ -1,82 +0,0 @@
-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();
-                }
-            }
-        });
-    }
-}

+ 127 - 0
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/TaskService.java

@@ -0,0 +1,127 @@
+package com.ozs.web.controller.shotschedule;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+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 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.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.ObjectUtils;
+
+import javax.annotation.Resource;
+import java.io.ByteArrayInputStream;
+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;
+import java.util.concurrent.*;
+import java.util.stream.Collectors;
+
+/**
+ * @author wyy
+ * @subject
+ * @creat 2024/3/1
+ */
+@Slf4j
+@Service
+public class TaskService {
+    private  static ExecutorService executorService = Executors.newFixedThreadPool(5);
+    private  static ExecutorService alarmExecutorService = Executors.newFixedThreadPool(5);
+    @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 = msgAlarmService.getBaseCameraManagements();
+        if (!CollectionUtils.isEmpty(list) && Objects.nonNull(list.get(0))) {
+            list.forEach(l -> {
+                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 + "/" + "normal" + "/" + dateString + "/" + uuid + ".jpeg";
+                        log.info("fileName======" + fileName);
+                        executorService.submit(new Runnable() {
+                            @Override
+                            public void run() {
+                                log.info("调用图片生成服务开始");
+                                try {
+                                    cameraCaptureService.getCapture(url, fileName);
+                                } catch (IOException e) {
+                                    e.printStackTrace();
+                                }
+                                log.info("调用图片生成服务结束");
+                            }
+                        });
+                    } catch (Throwable e) {
+                        e.printStackTrace();
+                        log.error(e.getMessage());
+                    }
+                }
+            });
+        }
+    }
+
+    public void getAlarmPicture() {
+        List<BaseCameraManagement> msgAlarmList = msgAlarmService.getBaseCameraManagementsByLockedMsgAlarms(2);
+        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 + "/" + "alarm" + "/" + dateString + "/" + uuid + ".jpeg";
+                        log.info("fileName======"+fileName);
+                        alarmExecutorService.submit(new Runnable() {
+                            @Override
+                            public void run() {
+                                log.info("报警摄像头截图开始");
+                                try {
+                                    cameraCaptureService.getCapture(url, fileName);
+                                } catch (IOException e) {
+                                    e.printStackTrace();
+                                }
+                                log.info("报警摄像头截图结束");
+                            }
+                        });
+                    } catch (Throwable e) {
+                        e.printStackTrace();
+                        log.error(e.getMessage());
+                    }
+                }
+            });
+        }
+    }
+
+}

+ 1 - 1
hazard-admin/src/main/resources/application.yml

@@ -164,4 +164,4 @@ mqtt:
   passWord: guest
 
 shot:
-  urlAddress: http://124.70.58.209:9081/snap/
+  urlAddress: http://124.70.58.209:9080/snap/