Jelajahi Sumber

Merge remote-tracking branch 'origin/prod' into prod

# Conflicts:
#	business-service/src/main/java/com/ozs/service/service/MsgAlarmService.java
#	business-service/src/main/java/com/ozs/service/service/impl/MsgAlarmServiceImpl.java
gao.qiang 10 bulan lalu
induk
melakukan
c0a5f0e1f3

+ 12 - 12
.idea/jarRepositories.xml

@@ -2,8 +2,8 @@
 <project version="4">
   <component name="RemoteRepositoriesConfiguration">
     <remote-repository>
-      <option name="id" value="public" />
-      <option name="name" value="aliyun nexus" />
+      <option name="id" value="central" />
+      <option name="name" value="Central Repository" />
       <option name="url" value="https://maven.aliyun.com/repository/public" />
     </remote-repository>
     <remote-repository>
@@ -11,6 +11,16 @@
       <option name="name" value="Central Repository" />
       <option name="url" value="https://repo.maven.apache.org/maven2" />
     </remote-repository>
+    <remote-repository>
+      <option name="id" value="public" />
+      <option name="name" value="aliyun nexus" />
+      <option name="url" value="https://maven.aliyun.com/repository/public" />
+    </remote-repository>
+    <remote-repository>
+      <option name="id" value="central" />
+      <option name="name" value="Maven Central repository" />
+      <option name="url" value="https://repo1.maven.org/maven2" />
+    </remote-repository>
     <remote-repository>
       <option name="id" value="central" />
       <option name="name" value="Central Repository" />
@@ -26,11 +36,6 @@
       <option name="name" value="Central Repository" />
       <option name="url" value="http://maven.aliyun.com/nexus/content/repositories/central/" />
     </remote-repository>
-    <remote-repository>
-      <option name="id" value="central" />
-      <option name="name" value="Maven Central repository" />
-      <option name="url" value="https://repo1.maven.org/maven2" />
-    </remote-repository>
     <remote-repository>
       <option name="id" value="custom_group" />
       <option name="name" value="Nexus Repository" />
@@ -41,10 +46,5 @@
       <option name="name" value="JBoss Community repository" />
       <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
     </remote-repository>
-    <remote-repository>
-      <option name="id" value="central" />
-      <option name="name" value="Central Repository" />
-      <option name="url" value="https://maven.aliyun.com/repository/public" />
-    </remote-repository>
   </component>
 </project>

+ 3 - 1
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.*;
@@ -18,7 +19,6 @@ import java.util.Map;
  * @since 2023-02-22
  */
 public interface MsgAlarmService extends IService<MsgAlarm> {
-    //web数据统计 报警数据详情
     IPage<AlarmStatisticVo> list(AlarmStatisticResVo alarmStatisticResVo);
 
     IPage listToPage(List list, int pageNum, int pageSize);
@@ -31,6 +31,7 @@ public interface MsgAlarmService extends IService<MsgAlarm> {
 
     //报警数据详情导出数据集合
     List<AlarmStatisticDto> exportExcel(AlarmStatisticResVo alarmStatisticResVo);
+
     /**
      * 通过相机编码查询未解除预警信息
      *
@@ -52,4 +53,5 @@ public interface MsgAlarmService extends IService<MsgAlarm> {
     List<MsgAlarm> queryAlarmInfoByAfterTenMinute();
 
     IPage<MsgAlarm> queryPageHome(MsgAlarmVo msgAlarmVo); 
+    List<BaseCameraManagement> getBaseCameraManagementsByLockedMsgAlarms(Integer isLock);
 }

+ 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) {

+ 15 - 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>
@@ -141,6 +144,18 @@ public class MsgAlarmServiceImpl extends ServiceImpl<MsgAlarmMapper, MsgAlarm> i
     }
 
     @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> cameraCodeList = lockedMsgAlarms.stream().map(MsgAlarm::getCameraCode).collect(Collectors.toList());
+        // 使用QueryWrapper和in方法根据cameraCode列表查询BaseCameraManagement数据
+        QueryWrapper<BaseCameraManagement> queryWrapper = new QueryWrapper<>();
+        queryWrapper.in("camera_code", cameraCodeList);
+        return baseCameraManagementMapper.selectList(queryWrapper);
     public IPage<MsgAlarm> queryPageHome(MsgAlarmVo msgAlarmVo) { 
         int pageNum = Integer.parseInt(msgAlarmVo.getPageNum().toString());
         int pageSize = Integer.parseInt(msgAlarmVo.getPageSize().toString());

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

@@ -46,8 +46,6 @@ public class ShotExecutors {
     /**
      * 处理非预警摄像头截图
      */
-    @Async
-    @Scheduled(fixedRate = 60000)
     public void handleNormalPicture() {
         List<SysDictData> dataList = DictUtils.getDictCache("shot_switch");
         if(CollectionUtils.isEmpty(dataList) || Objects.isNull(dataList.get(0))){
@@ -70,8 +68,6 @@ public class ShotExecutors {
     /**
      * 处理预警摄像头截图
      */
-    @Async
-    @Scheduled(fixedRate = 500)
     public void handleAlarmPicture() {
         List<SysDictData> dataList = DictUtils.getDictCache("shot_switch");
         if(CollectionUtils.isEmpty(dataList) || Objects.isNull(dataList.get(0))){

+ 90 - 0
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/ShotPictureExecutors.java

@@ -0,0 +1,90 @@
+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.util.CollectionUtils;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+/**
+ * @author wyy
+ * @subject
+ * @creat 2024/3/1
+ */
+@Configuration
+@EnableScheduling
+@EnableAsync
+@Slf4j
+public class ShotPictureExecutors {
+    private  static ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);
+    private  static ScheduledExecutorService alarmscheduledExecutorService = Executors.newScheduledThreadPool(5);
+    @Autowired
+    private ISysDictDataService dictDataService;
+    @Autowired
+    private ISysDictTypeService iSysDictTypeService;
+    @Autowired
+    private TaskService taskService; //任务
+
+    /**
+     * 处理非预警摄像头截图
+     */
+    @Async
+    @Scheduled(fixedRate = 60000)
+    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())) {
+                    scheduledExecutorService.submit(() -> {
+                        taskService.getNormalPicture();
+                    });
+                }
+            }
+        } catch (Exception e) {
+            e.getMessage();
+            log.error(e.getMessage());
+        }
+    }
+
+    /**
+     * 处理预警摄像头截图
+     */
+    @Async
+    @Scheduled(fixedRate = 500)
+    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);
+        }
+        try {
+            if(!CollectionUtils.isEmpty(dataList) && Objects.nonNull(dataList.get(0))){
+                if (Boolean.parseBoolean(dataList.get(0).getDictLabel())) {
+                    alarmscheduledExecutorService.submit(() -> {
+                        taskService.getAlarmPicture();
+                    });
+                }
+            }
+        } catch (Exception e) {
+            e.getMessage();
+            log.error(e.getMessage());
+        }
+    }
+}

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

@@ -0,0 +1,110 @@
+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.CompletableFuture;
+import java.util.stream.Collectors;
+
+/**
+ * @author wyy
+ * @subject
+ * @creat 2024/3/1
+ */
+@Slf4j
+@Service
+public class TaskService {
+    @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;
+    @Resource
+    MinioUtils minioUtils;
+
+    public void getNormalPicture() {
+        List<BaseCameraManagement> list = msgAlarmService.getBaseCameraManagementsByLockedMsgAlarms(1);
+        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);
+                        log.info("调用图片生成服务开始");
+                        cameraCaptureService.getCapture(url,fileName);
+                        log.info("调用图片生成服务结束");
+                    } catch (MalformedURLException e) {
+                        e.printStackTrace();
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    }
+                }
+            });
+        }
+    }
+
+    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);
+                        log.info("报警摄像头截图开始");
+                        cameraCaptureService.getCapture(url,fileName);
+                        log.info("报警摄像头截图结束");
+                    } catch (Throwable e) {
+                        e.printStackTrace();
+                        log.error(e.getMessage());
+                    }
+                }
+            });
+        }
+    }
+
+}