Browse Source

截图修改

wyyay 10 months ago
parent
commit
6de7009708

+ 4 - 2
business-service/src/main/java/com/ozs/service/service/MsgAlarmService.java

@@ -52,7 +52,9 @@ public interface MsgAlarmService extends IService<MsgAlarm> {
 
     List<MsgAlarm> queryAlarmInfoByAfterTenMinute();
 
-    IPage<MsgAlarm> queryPageHome(MsgAlarmVo msgAlarmVo); 
-    
+    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

@@ -9,6 +9,7 @@ import javax.annotation.Resource;
 import java.io.*;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.util.Date;
 
 /**
  * @author wyy

+ 19 - 2
business-service/src/main/java/com/ozs/service/service/impl/MsgAlarmServiceImpl.java

@@ -164,10 +164,27 @@ public class MsgAlarmServiceImpl extends ServiceImpl<MsgAlarmMapper, MsgAlarm> i
             return Collections.emptyList();
         }
         // 提取cameraCode列表
-        List<String> cameraCodeList = lockedMsgAlarms.stream().map(MsgAlarm::getCameraCode).collect(Collectors.toList());
+        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);
-        return baseCameraManagementMapper.selectList(queryWrapper);
+        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;
     }
 }

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

@@ -1,89 +0,0 @@
-package com.ozs.web.controller.shotschedule;
-
-import com.ozs.common.core.domain.entity.SysDictData;
-import com.ozs.common.utils.DictUtils;
-import com.ozs.system.service.ISysDictDataService;
-import com.ozs.system.service.ISysDictTypeService;
-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 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
- */
-@Configuration
-@EnableScheduling
-@EnableAsync
-@Slf4j
-public class ShotExecutors {
-
-   // private  static ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
-    @Autowired
-    private ISysDictDataService dictDataService;
-    @Autowired
-    private ISysDictTypeService iSysDictTypeService;
-    @Autowired
-    private TaskNormalService taskNormalService; //定时任务-没有报警摄像头
-    @Autowired
-    private TaskAlarmService taskAlarmService;//定时任务-报警摄像头
-
-    /**
-     * 处理非预警摄像头截图
-     */
-    public void handleNormalPicture() {
-        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())) {
-                    taskNormalService.getNormalPicture();
-                }
-            }
-        } catch (Exception e) {
-            e.getMessage();
-            log.error(e.getMessage());
-        }
-    }
-
-    /**
-     * 处理预警摄像头截图
-     */
-    public 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();
-                }
-            }
-        } catch (Exception e) {
-            e.getMessage();
-            log.error(e.getMessage());
-        }
-    }
-}

+ 4 - 12
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/ShotPictureExecutors.java

@@ -15,8 +15,6 @@ import org.springframework.util.CollectionUtils;
 
 import java.util.List;
 import java.util.Objects;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
 
 /**
  * @author wyy
@@ -28,8 +26,6 @@ import java.util.concurrent.ScheduledExecutorService;
 @EnableAsync
 @Slf4j
 public class ShotPictureExecutors {
-    private  static ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);
-    private  static ScheduledExecutorService alarmscheduledExecutorService = Executors.newScheduledThreadPool(5);
     @Autowired
     private ISysDictDataService dictDataService;
     @Autowired
@@ -42,7 +38,7 @@ public class ShotPictureExecutors {
      */
     @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");
@@ -52,9 +48,7 @@ public class ShotPictureExecutors {
         try {
             if(!CollectionUtils.isEmpty(dataList) && Objects.nonNull(dataList.get(0))){
                 if (Boolean.parseBoolean(dataList.get(0).getDictLabel())) {
-                    scheduledExecutorService.submit(() -> {
-                        taskService.getNormalPicture();
-                    });
+                    taskService.getNormalPicture();
                 }
             }
         } catch (Exception e) {
@@ -68,7 +62,7 @@ public class ShotPictureExecutors {
      */
     @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");
@@ -77,9 +71,7 @@ public class ShotPictureExecutors {
         try {
             if(!CollectionUtils.isEmpty(dataList) && Objects.nonNull(dataList.get(0))){
                 if (Boolean.parseBoolean(dataList.get(0).getDictLabel())) {
-                    alarmscheduledExecutorService.submit(() -> {
-                        taskService.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();
-                }
-            }
-        });
-    }
-}

+ 45 - 14
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/TaskService.java

@@ -26,7 +26,7 @@ import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
 import java.util.Objects;
-import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.*;
 import java.util.stream.Collectors;
 
 /**
@@ -37,6 +37,8 @@ import java.util.stream.Collectors;
 @Slf4j
 @Service
 public class TaskService {
+    private  static ExecutorService executorService = Executors.newFixedThreadPool(50);
+    private  static ExecutorService alarmExecutorService = Executors.newFixedThreadPool(10);
     @Resource
     BaseCameraManagementService baseCameraManagementService;
     @Resource
@@ -48,11 +50,9 @@ public class TaskService {
     private  static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
     @Value("${shot.urlAddress}")
     private String urlAddress;
-    @Resource
-    MinioUtils minioUtils;
 
     public void getNormalPicture() {
-        List<BaseCameraManagement> list = msgAlarmService.getBaseCameraManagementsByLockedMsgAlarms(1);
+        List<BaseCameraManagement> list = msgAlarmService.getBaseCameraManagements();
         if (!CollectionUtils.isEmpty(list) && Objects.nonNull(list.get(0))) {
             list.forEach(l -> {
                 String uuid = IdUtils.fastSimpleUUID();
@@ -65,16 +65,31 @@ public class TaskService {
                         String dateString = format.format(new Date());
                         String fileName = root + "/" + "normal" + "/" + dateString + "/" + uuid + ".jpeg";
                         log.info("fileName======" + fileName);
-                        log.info("调用图片生成服务开始");
-                        cameraCaptureService.getCapture(url,fileName);
-                        log.info("调用图片生成服务结束");
-                    } catch (MalformedURLException e) {
-                        e.printStackTrace();
-                    } catch (IOException e) {
+                        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());
                     }
                 }
             });
+            try {
+                if(executorService.awaitTermination(60,TimeUnit.SECONDS)){
+                    executorService.shutdown();
+                }
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
         }
     }
 
@@ -93,17 +108,33 @@ public class TaskService {
                         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";
+                        String fileName = root + "/" + "alarm" + "/" + dateString + "/" + uuid + ".jpeg";
                         log.info("fileName======"+fileName);
-                        log.info("报警摄像头截图开始");
-                        cameraCaptureService.getCapture(url,fileName);
-                        log.info("报警摄像头截图结束");
+                        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());
                     }
                 }
             });
+            try {
+                if(alarmExecutorService.awaitTermination(30,TimeUnit.SECONDS)){
+                    executorService.shutdown();
+                }
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
         }
     }