Ver código fonte

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

# Conflicts:
#	business-service/src/main/java/com/ozs/service/service/impl/CameraCaptureService.java
#	hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/ShotPictureExecutors.java
orgycat 7 meses atrás
pai
commit
7390dcb1da

+ 4 - 1
business-service/src/main/java/com/ozs/service/service/impl/MsgAlarmServiceImpl.java

@@ -15,6 +15,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ozs.service.service.RedisService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
 import java.util.*;
 import java.util.stream.Collectors;
@@ -157,6 +158,7 @@ public class MsgAlarmServiceImpl extends ServiceImpl<MsgAlarmMapper, MsgAlarm> i
     @Override
     public void getNormalBaseCameraManagementsCache(String setType) {
         Set<BaseCameraVO> alarmSet = redisService.getSetMembers(Constants.ALARM_SET);
+        if(!CollectionUtils.isEmpty(alarmSet)) {
         Set<String> cameraCodeSet = alarmSet.stream()
                 .map(BaseCameraVO::getCameraCode)
                 .collect(Collectors.toSet());
@@ -166,12 +168,13 @@ public class MsgAlarmServiceImpl extends ServiceImpl<MsgAlarmMapper, MsgAlarm> i
             queryWrapper.notIn("camera_code", cameraCodeSet);
             Set<BaseCameraManagement> set = baseCameraManagementMapper.selectList(queryWrapper).stream().collect(Collectors.toSet());
             set.forEach(item -> {
-                BaseCameraVO  baseCameraVO=new BaseCameraVO();
+                BaseCameraVO baseCameraVO = new BaseCameraVO();
                 baseCameraVO.setCameraCode(item.getCameraCode());
                 baseCameraVO.setChannel(item.getChannel());
                 redisService.addToSet(Constants.NORMAL_SET, baseCameraVO);
             });
         }
+        }
     }
 
     @Override

+ 10 - 23
hazard-admin/src/main/java/com/ozs/web/controller/shotschedule/TaskService.java

@@ -48,22 +48,13 @@ public class TaskService {
 
     public void getNormalPicture() {
         String address = storeAddress;
-        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);
-        }
         List<SysDictData> addressDataList = DictUtils.getDictCache("shot_address");
         if(CollectionUtils.isEmpty(addressDataList) || Objects.isNull(addressDataList.get(0))){
             addressDataList = iSysDictTypeService.selectDictDataByType("shot_address");
             DictUtils.setDictCache("shot_address",addressDataList);
         }
-        if(!CollectionUtils.isEmpty(dataList) && Objects.nonNull(dataList.get(0))){
-            if (Boolean.parseBoolean(dataList.get(0).getDictLabel())) {
-                if(!CollectionUtils.isEmpty(addressDataList) && Objects.nonNull(addressDataList.get(0))){
-                    address = addressDataList.get(0).getDictLabel();
-                }
-            }
+        if(!CollectionUtils.isEmpty(addressDataList) && Objects.nonNull(addressDataList.get(0))){
+            address = addressDataList.get(0).getDictLabel();
         }
         boolean isHasKeyNormal = redisService.hasKey(Constants.NORMAL_SET);
         if(!isHasKeyNormal){
@@ -71,6 +62,9 @@ public class TaskService {
         }
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
         Set<BaseCameraVO> normalSet = redisService.getSetMembers(Constants.NORMAL_SET);
+        if (log.isDebugEnabled()) {
+            log.debug("正常摄像机数量:"+normalSet.size());
+        }
         if (!CollectionUtils.isEmpty(normalSet)) {
             String finalAddress = address;
             normalSet.forEach(item -> {
@@ -101,22 +95,13 @@ public class TaskService {
 
     public void getAlarmPicture() {
         String address = storeAddress;
-        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);
-        }
         List<SysDictData> addressDataList = DictUtils.getDictCache("shot_address");
         if(CollectionUtils.isEmpty(addressDataList) || Objects.isNull(addressDataList.get(0))){
             addressDataList = iSysDictTypeService.selectDictDataByType("shot_address");
             DictUtils.setDictCache("shot_address",addressDataList);
         }
-        if(!CollectionUtils.isEmpty(dataList) && Objects.nonNull(dataList.get(0))){
-            if (Boolean.parseBoolean(dataList.get(0).getDictLabel())) {
-                if(!CollectionUtils.isEmpty(addressDataList) && Objects.nonNull(addressDataList.get(0))){
-                    address = addressDataList.get(0).getDictLabel();
-                }
-            }
+        if(!CollectionUtils.isEmpty(addressDataList) && Objects.nonNull(addressDataList.get(0))){
+            address = addressDataList.get(0).getDictLabel();
         }
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
         boolean isHasKeyAlarm = redisService.hasKey(Constants.ALARM_SET);
@@ -124,6 +109,9 @@ public class TaskService {
             msgAlarmService.initializationCameraCache();
         }
         Set<BaseCameraVO> alarmSet = redisService.getSetMembers(Constants.ALARM_SET);
+        if (log.isDebugEnabled()) {
+            log.debug("报警摄像机数量:"+alarmSet.size());
+        }
         if(!CollectionUtils.isEmpty(alarmSet)){
             String finalAddress = address;
             alarmSet.forEach(item -> {
@@ -152,5 +140,4 @@ public class TaskService {
             });
         }
     }
-
 }

+ 4 - 1
hazard-admin/src/main/java/com/ozs/web/controller/system/SysDictDataController.java

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ozs.common.core.domain.vo.SysDictDataVo;
+import com.ozs.common.core.redis.RedisCache;
 import com.ozs.common.utils.DictUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -43,6 +44,8 @@ public class SysDictDataController extends BaseController {
 
     @Autowired
     private ISysDictTypeService dictTypeService;
+    @Autowired
+    RedisCache redisCache;
 
 //    @PreAuthorize("@ss.hasPermi('system:dict:list')")
 //    @GetMapping("/list")
@@ -149,7 +152,7 @@ public class SysDictDataController extends BaseController {
     {
         dict.setUpdateBy(getUsername());
         if(StringUtils.equals(dict.getDictType(),"shot_switch")){
-            DictUtils.removeDictCache("shot_switch");
+            redisCache.setCacheObject("shot_switch",dict.getStatus());
         }
         return toAjax(dictDataService.updateDictData(dict));
     }

+ 90 - 62
hazard-admin/src/main/java/com/ozs/web/core/util/CameraUtil.java

@@ -1,6 +1,39 @@
 package com.ozs.web.core.util;
 
 
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.stereotype.Component;
+import org.springframework.util.ObjectUtils;
+
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
@@ -13,13 +46,13 @@ import com.ozs.common.core.redis.RedisCache;
 import com.ozs.common.exception.base.BaseException;
 import com.ozs.common.utils.DateUtils;
 import com.ozs.common.utils.http.HttpUtils;
+import com.ozs.common.utils.uuid.IdUtils;
 import com.ozs.framework.config.ServerConfig;
 import com.ozs.service.entity.BaseCameraManagement;
 import com.ozs.service.entity.BaseDeviceDynamicManagement;
 import com.ozs.service.entity.CameraLogDetail;
 import com.ozs.service.entity.MqLog;
 import com.ozs.service.entity.MsgAlarm;
-import com.ozs.service.entity.MsgWebPush;
 import com.ozs.service.service.BaseCameraManagementService;
 import com.ozs.service.service.BaseDeviceDynamicManagementService;
 import com.ozs.service.service.CameraLogDetailService;
@@ -27,24 +60,9 @@ import com.ozs.service.service.MqLogService;
 import com.ozs.service.service.MsgAlarmService;
 import com.ozs.system.mapper.SysDictDataMapper;
 import com.ozs.web.core.config.CaneraConfig;
+
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.stereotype.Component;
-import org.springframework.util.ObjectUtils;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.Resource;
-import java.io.*;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.*;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
 
 /**
  * 相机工具
@@ -205,13 +223,12 @@ public class CameraUtil {
             try {
                 return historyPlay(list, ph, flay);
             } catch (Exception e) {
-                log.error(e.getMessage());
-                e.printStackTrace();
+                log.error("e", e);
+                throw new BaseException("视频处理失败");
             }
         } else {
             throw new BaseException("当前相机无视频录像");
         }
-        return null;
     }
 
 
@@ -414,50 +431,61 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
         }
         cUtil.cmd("chomd -R 777 " + file.getParentFile().getPath());
         log.info("newfilePath:{}", newfilePath);
-        StringBuffer sm = new StringBuffer(ffmpegPath + " -i \"concat:");
-        List<String> fileTs = new ArrayList<>();
-        for (int t = 0; t < fromVideoFileList.size(); t++) {
-            File ft = new File(fromVideoFileList.get(t));
-            if (ft.exists()) {
-                log.info("file:{}", fromVideoFileList.get(t));
-                String substring = fromVideoFileList.get(t).substring(0, fromVideoFileList.get(t).lastIndexOf("."));
-                int x;//定义两变量
-                Random ne = new Random();//实例化一个random的对象ne
-                x = ne.nextInt(9999 - 1000 + 1) + 1000;//为变量赋随机值1000-9999
-                substring = substring + x;//定义两变量
-
-                String cmdstr = ffmpegPath + " -i " + fromVideoFileList.get(t) + " -c:v copy " + substring + ".ts";
-                log.info("转换命令:{}", cmdstr);
-                cUtil.cmd(cmdstr);
-                fileTs.add(substring + ".ts");
-                if (t != fromVideoFileList.size() - 1) {
-                    sm.append(substring + ".ts|");
-                } else {
-                    sm.append(substring + ".ts\" ");
-                }
-            }
+       
+        StringBuilder argFileTxt = new StringBuilder();
+        fromVideoFileList.forEach(filePath -> {
+        	File videoFile = new File(filePath);
+        	if (!videoFile.exists()) {
+        		return;
+        	}
+        	log.info("file:{}", filePath);
+
+        	argFileTxt.append("file '").append(filePath).append("'").append(System.lineSeparator());
+        });
+        
+//        if (!flay) {
+//        	List<String> validFileList = new ArrayList<>();
+//        	validFileList.add(newfilePath);
+//        	putDeleteCache(validFileList);
+//        }
+        
+        if (argFileTxt.length() == 0) {
+        	return;
         }
-
-        if (fileTs.size() > 0) {
-            Map<String, Object> mergeVideoTsFile = rc.getCacheMap(tsFilekey);
-            if (ObjectUtils.isEmpty(mergeVideoTsFile)) {
-                mergeVideoTsFile = new HashMap<>();
-            }
-            if (!flay) {
-                // 如果没有解除,把生成的文件放入要删除的定时任务 redis key 中
-                fileTs.add(newfilePath);
-            }
-            mergeVideoTsFile.put(new Date().getTime() + "", fileTs);
-            rc.deleteObject(tsFilekey);
-            if (mergeVideoTsFile.size() > 0) {
-                rc.setCacheMap(tsFilekey, mergeVideoTsFile);
-            }
-
-            sm.append("-c copy " + newfilePath);
-            log.info("合并命令:{}", sm.toString());
-            cUtil.cmd(sm.toString());
+        
+        String argFileName = IdUtils.fastSimpleUUID() + "_tmp.txt";
+        File argFile = new File(file.getParentFile(), argFileName);
+        try (
+    		OutputStreamWriter bos = new OutputStreamWriter(new FileOutputStream(argFile), StandardCharsets.UTF_8);
+        ) {
+        	bos.write(argFileTxt.toString());
+        	bos.flush();
         }
-
+        
+        StringBuilder cmd = new StringBuilder(ffmpegPath);
+        cmd.append(" -f concat -safe 0 -y -i ")
+        		.append(argFile.getAbsolutePath())
+	        	.append(" -c copy ")
+	        	.append(newfilePath);
+        
+        log.info("合并命令:{}", cmd);
+        
+        cUtil.cmd(cmd.toString());
+        
+        argFile.delete();
+    }
+    
+    private static void putDeleteCache(List<String> pathList) {
+    	if (ObjectUtils.isEmpty(pathList)) {
+    		return;
+    	}
+        Map<String, Object> mergeVideoTsFile = rc.getCacheMap(tsFilekey);
+        if (ObjectUtils.isEmpty(mergeVideoTsFile)) {
+            mergeVideoTsFile = new HashMap<>();
+        }
+        mergeVideoTsFile.put(new Date().getTime() + "", pathList);
+        rc.deleteObject(tsFilekey);
+        rc.setCacheMap(tsFilekey, mergeVideoTsFile);
     }
 
     public static List<Map<String, Object>> getRecordList(String channel, Date startTm, Date endTm) {

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

@@ -16,7 +16,7 @@ base:
   # 验证码类型 math 数组计算 char 字符验证
   captchaType: math
   # 摄像头配置
-  ffmpegPath: /usr/local/ffmpeg/bin/ffmpeg
+  ffmpegPath: /usr/local/bin/ffmpeg
   filePath: /opt/streams/record/flv/
   webUrl: http://124.70.58.209:9080
   bakUrl: http://124.70.58.209:18891