Sfoglia il codice sorgente

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

wyyay 2 anni fa
parent
commit
c8120e6fb0

+ 2 - 2
.idea/compiler.xml

@@ -7,10 +7,10 @@
         <sourceOutputDir name="target/generated-sources/annotations" />
         <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
         <outputRelativeToContentRoot value="true" />
-        <module name="base-admin" />
-        <module name="hazard-admin" />
         <module name="hazard-sdk" />
         <module name="business-service" />
+        <module name="hazard-admin" />
+        <module name="base-admin" />
       </profile>
     </annotationProcessing>
     <bytecodeTargetLevel>

+ 12 - 12
.idea/jarRepositories.xml

@@ -1,16 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="RemoteRepositoriesConfiguration">
-    <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>
-    <remote-repository>
-      <option name="id" value="central" />
-      <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" />
@@ -18,8 +8,8 @@
     </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" />
+      <option name="name" value="Central Repository" />
+      <option name="url" value="https://repo.maven.apache.org/maven2" />
     </remote-repository>
     <remote-repository>
       <option name="id" value="central" />
@@ -36,6 +26,11 @@
       <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" />
@@ -46,5 +41,10 @@
       <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>

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

@@ -187,5 +187,5 @@ public class MsgAlarm extends BaseEntity implements Serializable {
      * 推送消息ID
      */
     @TableField(exist = false)
-    private Long msgId;
+    private String msgId;
 }

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

@@ -76,6 +76,7 @@ public class MsgWebPushServiceImpl extends ServiceImpl<MsgWebPushMapper, MsgWebP
                 String mile = AppendUtils.stringAppend(baseCameraManagement.getInstallMile());
                 msgAlarmResp.setAlarmMile(mile);
                 msgAlarmResp.setInstallLongitude(baseCameraManagement.getInstallLongitude() + "," + baseCameraManagement.getInstallLatitude());
+                msgAlarmResp.setPushId(msgAlarm.getMsgId());
                 msgAlarmRespList.add(msgAlarmResp);
             }
         }

+ 1 - 1
business-service/src/main/resources/mapper/service/MsgWebPushMapper.xml

@@ -10,7 +10,7 @@
     </select>
 
     <select id="webAlarm" parameterType="java.lang.String" resultType="com.ozs.service.entity.MsgAlarm">
-        select b.*
+        select b.*, a.push_id as msgId
         from msg_web_push AS a
         join msg_alarm AS b on a.alarm_id = b.alarm_id
         where a.status = 1

+ 31 - 51
hazard-admin/src/main/java/com/ozs/web/controller/tool/TestController.java

@@ -31,10 +31,13 @@ import io.swagger.annotations.ApiOperation;
  */
 @Api("用户信息管理")
 @RestController
-@RequestMapping("/test/user")
-public class TestController extends BaseController
-{
+@RequestMapping("/test")
+public class TestController extends BaseController {
+
+
+
     private final static Map<Integer, UserEntity> users = new LinkedHashMap<Integer, UserEntity>();
+
     {
         users.put(1, new UserEntity(1, "admin", "admin123", "15888888888"));
         users.put(2, new UserEntity(2, "ry", "admin123", "15666666666"));
@@ -42,8 +45,7 @@ public class TestController extends BaseController
 
     @ApiOperation("获取用户列表")
     @GetMapping("/list")
-    public R<List<UserEntity>> userList()
-    {
+    public R<List<UserEntity>> userList() {
         List<UserEntity> userList = new ArrayList<UserEntity>(users.values());
         return R.ok(userList);
     }
@@ -51,30 +53,24 @@ public class TestController extends BaseController
     @ApiOperation("获取用户详细")
     @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
     @GetMapping("/{userId}")
-    public R<UserEntity> getUser(@PathVariable Integer userId)
-    {
-        if (!users.isEmpty() && users.containsKey(userId))
-        {
+    public R<UserEntity> getUser(@PathVariable Integer userId) {
+        if (!users.isEmpty() && users.containsKey(userId)) {
             return R.ok(users.get(userId));
-        }
-        else
-        {
+        } else {
             return R.fail("用户不存在");
         }
     }
 
     @ApiOperation("新增用户")
     @ApiImplicitParams({
-        @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Integer", dataTypeClass = Integer.class),
-        @ApiImplicitParam(name = "username", value = "用户名称", dataType = "String", dataTypeClass = String.class),
-        @ApiImplicitParam(name = "password", value = "用户密码", dataType = "String", dataTypeClass = String.class),
-        @ApiImplicitParam(name = "mobile", value = "用户手机", dataType = "String", dataTypeClass = String.class)
+            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Integer", dataTypeClass = Integer.class),
+            @ApiImplicitParam(name = "username", value = "用户名称", dataType = "String", dataTypeClass = String.class),
+            @ApiImplicitParam(name = "password", value = "用户密码", dataType = "String", dataTypeClass = String.class),
+            @ApiImplicitParam(name = "mobile", value = "用户手机", dataType = "String", dataTypeClass = String.class)
     })
     @PostMapping("/save")
-    public R<String> save(UserEntity user)
-    {
-        if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
-        {
+    public R<String> save(UserEntity user) {
+        if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId())) {
             return R.fail("用户ID不能为空");
         }
         users.put(user.getUserId(), user);
@@ -83,14 +79,11 @@ public class TestController extends BaseController
 
     @ApiOperation("更新用户")
     @PutMapping("/update")
-    public R<String> update(@RequestBody UserEntity user)
-    {
-        if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
-        {
+    public R<String> update(@RequestBody UserEntity user) {
+        if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId())) {
             return R.fail("用户ID不能为空");
         }
-        if (users.isEmpty() || !users.containsKey(user.getUserId()))
-        {
+        if (users.isEmpty() || !users.containsKey(user.getUserId())) {
             return R.fail("用户不存在");
         }
         users.remove(user.getUserId());
@@ -101,23 +94,18 @@ public class TestController extends BaseController
     @ApiOperation("删除用户信息")
     @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
     @DeleteMapping("/{userId}")
-    public R<String> delete(@PathVariable Integer userId)
-    {
-        if (!users.isEmpty() && users.containsKey(userId))
-        {
+    public R<String> delete(@PathVariable Integer userId) {
+        if (!users.isEmpty() && users.containsKey(userId)) {
             users.remove(userId);
             return R.ok();
-        }
-        else
-        {
+        } else {
             return R.fail("用户不存在");
         }
     }
 }
 
 @ApiModel(value = "UserEntity", description = "用户实体")
-class UserEntity
-{
+class UserEntity {
     @ApiModelProperty("用户ID")
     private Integer userId;
 
@@ -130,46 +118,38 @@ class UserEntity
     @ApiModelProperty("用户手机")
     private String mobile;
 
-    public UserEntity()
-    {
+    public UserEntity() {
 
     }
 
-    public UserEntity(Integer userId, String username, String password, String mobile)
-    {
+    public UserEntity(Integer userId, String username, String password, String mobile) {
         this.userId = userId;
         this.username = username;
         this.password = password;
         this.mobile = mobile;
     }
 
-    public Integer getUserId()
-    {
+    public Integer getUserId() {
         return userId;
     }
 
-    public void setUserId(Integer userId)
-    {
+    public void setUserId(Integer userId) {
         this.userId = userId;
     }
 
-    public String getUsername()
-    {
+    public String getUsername() {
         return username;
     }
 
-    public void setUsername(String username)
-    {
+    public void setUsername(String username) {
         this.username = username;
     }
 
-    public String getPassword()
-    {
+    public String getPassword() {
         return password;
     }
 
-    public void setPassword(String password)
-    {
+    public void setPassword(String password) {
         this.password = password;
     }
 

+ 101 - 31
hazard-admin/src/main/java/com/ozs/web/core/util/CameraUtil.java

@@ -28,6 +28,9 @@ 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.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
@@ -46,9 +49,14 @@ public class CameraUtil {
     private static String transcribeFilePath;
     private static String webUrl;
     private static String bakUrl;
+    private static CmdCameraUtil cUtil;
 
     @Autowired
     private CaneraConfig caneraConfig;
+
+    @Autowired
+    private CmdCameraUtil cmdCameraUtil;
+
     @Autowired
     private SysDictDataMapper dictDataMapper;
     @Resource
@@ -63,7 +71,7 @@ public class CameraUtil {
      * @return
      * @throws IOException
      */
-    public static String historyPlay(List<String> fromVideoFileList, String ph) {
+    public static String historyPlay(List<String> fromVideoFileList, String ph, String uuid) {
         // 视频服务映射路径
         String NewfilePath = BaseConfig.getProfile() + "/" + ph;
         log.info("NewfilePath:{}", NewfilePath);
@@ -71,14 +79,29 @@ public class CameraUtil {
         if (ObjectUtils.isEmpty(fromVideoFileList) || fromVideoFileList.size() <= 0) {
             throw new BaseException("当前相机无视频录像");
         }
-        new Thread(() -> {
-            try {
-                myConvetor(fromVideoFileList, NewfilePath);
-            } catch (IOException e) {
-                log.error(e.getMessage());
-                e.printStackTrace();
+        ExecutorService executor = Executors.newFixedThreadPool(10);
+
+        executor.submit(new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    Map<String, String> map = myConvetor(fromVideoFileList, NewfilePath, uuid);
+                    if (!ObjectUtils.isEmpty(map)) {
+                        cUtil.cmd(map.get("cmd"));
+                        //删除生成的ts文件
+                        File file1 = new File(map.get("path"));
+                        if (file1.exists()) {
+                            file1.delete();
+                        }
+                    }
+                } catch (IOException e) {
+                    log.error(e.getMessage());
+                    e.printStackTrace();
+                }
             }
-        }).start();
+        });
+        executor.shutdown();
+
         return Constants.RESOURCE_PREFIX + "/" + ph;
     }
 
@@ -94,6 +117,12 @@ public class CameraUtil {
             return bakUrl + "/hdl/" + channel + "/" + cameraCode + ".flv";
         }
         return webUrl + "/hdl/" + channel + "/" + cameraCode + ".flv";
+
+
+//        if (!flay) {
+//            return bakUrl + "/ws/" + channel + "/" + cameraCode + ".flv";
+//        }
+//        return webUrl + "/ws/" + channel + "/" + cameraCode + ".flv";
     }
 
     public static String getPlayFlv(String cameraCode, String channel) {
@@ -132,12 +161,13 @@ public class CameraUtil {
      */
     public static String historyPlayListStr(String channel, Date startTm, Date endTm) {
         List<String> list = filterPlayList(channel, startTm, endTm, filePath);
+        String uuid = UUID.randomUUID().toString();
         String ph = "flv/" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, new Date())
                 + "/" + channel + "/"
-                + UUID.randomUUID().toString() + ".flv";
+                + uuid + ".flv";
         if (!ObjectUtils.isEmpty(list)) {
             try {
-                return historyPlay(list, ph);
+                return historyPlay(list, ph, uuid);
             } catch (Exception e) {
                 log.error(e.getMessage());
                 e.printStackTrace();
@@ -187,9 +217,13 @@ public class CameraUtil {
                     String substring1 = substring.substring(0, substring.indexOf("-"));
                     String[] s2 = substring1.split("_");
                     if (!ObjectUtils.isEmpty(s2)) {
+
                         String s3 = s2[0] + s2[1];
                         String s4 = s2[0] + s2[2];
                         Date sdate = DateUtils.dateTime(DateUtils.YYYYMMDDHHMMSS, s3);
+                        if (s2[1].startsWith("23") && s2[2].startsWith("00")) {
+                            sdate = DateUtils.addDays(sdate, -1);
+                        }
                         Date edate = DateUtils.dateTime(DateUtils.YYYYMMDDHHMMSS, s4);
                         /*     sdate  |startTm|  edate     |endTm| */
                         if (startTm.compareTo(sdate) >= 0
@@ -232,14 +266,14 @@ public class CameraUtil {
      * @param newfilePath       生产新的视频文件路径
      * @throws IOException
      */
-    public static void myConvetor(List<String> fromVideoFileList,
-                                  String newfilePath) throws IOException {
+    public static Map<String, String> myConvetor(List<String> fromVideoFileList,
+                                                 String newfilePath,
+                                                 String uuid) throws IOException {
         /*
         * for f in *.flv; do echo "file '$f'" >> mylist.txt; done
             ffmpeg -f concat -i mylist.txt -c copy output.flv
         * */
 
-        List<String> rspList = new ArrayList<String>();
         File file = new File(newfilePath);
         boolean flay = false;
         if (!file.getParentFile().exists()) {
@@ -251,18 +285,24 @@ public class CameraUtil {
 
 
         StringBuffer sm = new StringBuffer("for f in ");
+        String pathStr = null;
         for (int t = 0; t < fromVideoFileList.size(); t++) {
             File ft = new File(fromVideoFileList.get(t));
             if (ft.exists()) {
                 if (t != fromVideoFileList.size() - 1) {
-                    sm.append(fromVideoFileList.get(t) + " ");
+//                    sm.append(fromVideoFileList.get(t) + " ");
+                    sm.append(fromVideoFileList.get(t).substring(fromVideoFileList.get(t).lastIndexOf("/") + 1, fromVideoFileList.get(t).length()) + " ");
                 } else {
-                    sm.append(fromVideoFileList.get(t));
+//                    sm.append(fromVideoFileList.get(t));
+                    sm.append(fromVideoFileList.get(t).substring(fromVideoFileList.get(t).lastIndexOf("/") + 1, fromVideoFileList.get(t).length()));
+                    pathStr = fromVideoFileList.get(t).substring(0, fromVideoFileList.get(t).lastIndexOf("/"));
                 }
             }
         }
-        String substring = newfilePath.substring(0, newfilePath.lastIndexOf("."));
-        substring = substring + ".txt";
+//        String substring = newfilePath.substring(0, newfilePath.lastIndexOf("."));
+//        substring = substring + ".txt";
+
+        String substring = uuid + ".txt";
         log.info("临时转化的文件:{}", substring);
 
 
@@ -274,39 +314,47 @@ public class CameraUtil {
         PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(proc.getOutputStream())), true);
 
         try {
-            String commit1 = ffmpegPath + " -f concat -safe 0 -i " + substring + " -c copy " + newfilePath;
+            String commit1 = ffmpegPath + " -f concat -safe 0 -i " + pathStr + "/" + substring + " -c copy " + newfilePath;
+
+            log.info("合并视频命令:{}", commit1);
             List<String> commands = new ArrayList<>();
             if (flay) {
                 commands.add("chomd -R 777 " + file.getParentFile().getPath());
             }
+            //
+            commands.add("cd " + pathStr);
             // 合并成一个临时文件
             commands.add(commit);
+
             // 临时文件转化为 flv
-            commands.add(commit1);
+//            commands.add(commit1);
+            log.info("录像视频命令:{}", commands);
             for (String line : commands) {
+                log.info("命令:{}", line);
                 out.println(line);
             }
             out.println("exit");// 这个命令必须执行,否则in流不结束。
+            log.info("命令:{}", "exit");
             String rspLine = "";
             while ((rspLine = in.readLine()) != null) {
-                System.out.println(rspLine);
-                rspList.add(rspLine);
-            }
-            int i = proc.waitFor();
-            log.info("执行结果:{}", i);
-            //删除生成的ts文件
-            File file1 = new File(substring);
-            if (file1.exists()) {
-                file1.delete();
+                log.info("*****:{}", rspLine);
             }
+            proc.waitFor();
+            Map<String, String> map = new HashMap<>();
+            map.put("cmd", commit1);
+            map.put("path", pathStr + "/" + substring);
+            return map;
+
+
         } catch (InterruptedException e) {
+            log.error(e.getMessage());
             e.printStackTrace();
         } finally {
             in.close();
             out.close();
             proc.destroy();
         }
-        log.info("返回结果:{}", rspList);
+        return null;
     }
 
 
@@ -318,6 +366,7 @@ public class CameraUtil {
         transcribeFilePath = caneraConfig.getTranscribeFilePath();
         webUrl = caneraConfig.getWebUrl();
         bakUrl = caneraConfig.getBakUrl();
+        cUtil = cmdCameraUtil;
     }
 
     /**
@@ -345,6 +394,7 @@ public class CameraUtil {
 
             // 删除
             commands.add(commit);
+            log.info("删除昨天的录像视频命令:{}", commands);
             for (String line : commands) {
                 out.println(line);
             }
@@ -522,8 +572,28 @@ public class CameraUtil {
         return listFiles;
     }
 
+    public static void execute(String command) {
+        try {
+            ProcessBuilder process = new ProcessBuilder(command);
+            process.inheritIO().start().waitFor();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
     public static void main(String[] args) throws InterruptedException, ParseException, IOException {
-        CameraUtil cameraUtil = new CameraUtil();
-        cameraUtil.closeRecording();
+//        CameraUtil cameraUtil = new CameraUtil();
+//        cameraUtil.closeRecording();
+//        String s = "/opt/streams/record/flv/42010001541320001116/20230403_235506_000506-22e1523b-d170-11ed-8a42-fa163e4e1e9f.flv";
+//        String fileStr = s.substring(s.lastIndexOf("/") + 1, s.length());
+//        String pathStr = s.substring(0, s.lastIndexOf("/"));
+//        System.out.println(fileStr);
+//        System.out.println(pathStr);
+
+        String s = "20230403235512";
+        Date sdate = DateUtils.dateTime(DateUtils.YYYYMMDDHHMMSS, s);
+        sdate = DateUtils.addDays(sdate, -1);
+        System.out.println(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, sdate));
     }
 }

+ 80 - 0
hazard-admin/src/main/java/com/ozs/web/core/util/CmdCameraUtil.java

@@ -0,0 +1,80 @@
+package com.ozs.web.core.util;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+@Slf4j
+@Component
+public class CmdCameraUtil {
+
+
+    public void cmd(String cmd) {
+        long l = System.currentTimeMillis();
+        Process exec = null;
+        try {
+            exec = Runtime.getRuntime().exec(new String[]{"sh", "-c", cmd});
+            long l1 = System.currentTimeMillis();
+            log.info("cmd-time:{}", l1 - l);
+        } catch (IOException e) {
+            log.error(e.getMessage());
+            e.printStackTrace();
+        }
+        try {
+            printProcessMsg(exec);
+        } catch (IOException e) {
+            log.error(e.getMessage());
+            e.printStackTrace();
+        }
+        try {
+            int i = exec.waitFor();
+        } catch (InterruptedException e) {
+            log.error(e.getMessage());
+            e.printStackTrace();
+        }
+    }
+
+
+    /**
+     * 处理process输出流和错误流,防止进程阻塞,在process.waitFor();前调用
+     *
+     * @param exec
+     * @throws IOException
+     */
+    private void printProcessMsg(Process exec) throws IOException {
+        //防止ffmpeg进程塞满缓存造成死锁
+        InputStream error = exec.getErrorStream();
+        InputStream is = exec.getInputStream();
+
+        StringBuffer result = new StringBuffer();
+        String line = null;
+        try {
+            BufferedReader br = new BufferedReader(new InputStreamReader(error, "GBK"));
+            BufferedReader br2 = new BufferedReader(new InputStreamReader(is, "GBK"));
+
+            while ((line = br.readLine()) != null) {
+                result.append(line + "\n");
+            }
+            log.info("FFMPEG视频合成进程错误信息:" + result.toString());
+
+            result = new StringBuffer();
+            line = null;
+
+            while ((line = br2.readLine()) != null) {
+                result.append(line + "\n");
+            }
+            log.info("FFMPEG视频合成进程输出内容为:" + result.toString());
+        } catch (IOException e2) {
+            e2.printStackTrace();
+        } finally {
+            error.close();
+            is.close();
+        }
+
+    }
+
+}