Przeglądaj źródła

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

gao.qiang 1 rok temu
rodzic
commit
d7d5868480

+ 4 - 0
business-service/src/main/java/com/ozs/service/entity/MsgAppPush.java

@@ -77,4 +77,8 @@ public class MsgAppPush extends BaseEntity implements Serializable {
      */
     private String remark;
 
+    /**
+     * app标识ID registration_id
+     */
+    private String registrationId;
 }

+ 1 - 1
business-service/src/main/java/com/ozs/service/mapper/UserRegistrationidMapper.java

@@ -18,5 +18,5 @@ public interface UserRegistrationidMapper extends BaseMapper<UserRegistrationid>
 
     int addRegistrationID(UserRegistrationid userRegistrationid);
 
-    List<String> selectRegistrationID(@Param("userIdList") List<String> userIdList);
+    List<UserRegistrationid> selectRegistrationID(@Param("userIdList") List<String> userIdList);
 }

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

@@ -12,5 +12,5 @@ import java.util.List;
 public interface UserRegistrationidService extends IService<UserRegistrationid> {
     Integer addRegistrationID(UserRegistrationid userRegistrationid);
 
-    List<String> selectRegistrationID(List<String> userIdList);
+    List<UserRegistrationid> selectRegistrationID(List<String> userIdList);
 }

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

@@ -43,7 +43,7 @@ public class UserRegistrationidServiceImpl extends ServiceImpl<UserRegistrationi
     }
 
     @Override
-    public List<String> selectRegistrationID(List<String> userIdList) {
+    public List<UserRegistrationid> selectRegistrationID(List<String> userIdList) {
         return userRegistrationidMapper.selectRegistrationID(userIdList);
     }
 }

+ 2 - 2
business-service/src/main/resources/mapper/service/UserRegistrationidMapper.xml

@@ -12,8 +12,8 @@
         where user_id = #{userId}
     </update>
 
-    <select id="selectRegistrationID" resultType="java.lang.String" parameterType="java.util.List">
-        select registration_id from user_registrationid where user_id in
+    <select id="selectRegistrationID" resultType="com.ozs.service.entity.UserRegistrationid" parameterType="java.util.List">
+        select * from user_registrationid where user_id in
         <foreach item="item" collection="userIdList" separator="," open="(" close=")" index="">
             #{item}
         </foreach>

+ 7 - 4
hazard-admin/src/main/java/com/ozs/web/controller/accountmanagment/BaseCameraManagementController.java

@@ -847,15 +847,18 @@ public class BaseCameraManagementController extends BaseController {
     @Log(title = "相机台账管理", businessType = BusinessType.OTHER)
     public AjaxResult getRecordByAlarmId(@RequestParam("alarmId") String alarmId) {
         Object cacheObject = redisCache.getCacheObject("STREAMING_ALARM_VIDEO:" + alarmId);
-        Map<String, Object> wait_merge_video_alarm_id = redisCache.getCacheMap("WAIT_MERGE_VIDEO_ALARM_ID");
-        log.info("待合成视频的报警信息集合:{}", wait_merge_video_alarm_id);
-        if (!wait_merge_video_alarm_id.keySet().contains(alarmId)) {
+        Map<String, Object> map = redisCache.getCacheMap("WAIT_MERGE_VIDEO_ALARM_ID");
+        log.info("待合成视频的报警信息集合:{}", map);
+        if (ObjectUtils.isEmpty(map)) {
+            return error("报警UUID:" + alarmId + ",是属于旧数据。请用新数据测试");
+        }
+        if (!map.keySet().contains(alarmId)) {
             return error("报警UUID:" + alarmId + ",是属于旧数据。请用新数据测试");
         }
         if (ObjectUtils.isEmpty(cacheObject)) {
             return error("报警UUID:" + alarmId + ",没有视频录像");
         }
-        return new AjaxResult(200, "ok", cacheObject);
+        return new AjaxResult(200, "ok", serverConfig.getUrl() + cacheObject);
     }
 
 }

+ 10 - 0
hazard-admin/src/main/java/com/ozs/web/controller/tool/TestController.java

@@ -65,6 +65,16 @@ public class TestController extends BaseController {
         return R.ok();
     }
 
+    @GetMapping("/deleteTs")
+    public R<String> deleteTs() {
+        try {
+            cameraUtil.deleteTsFile();
+        } catch (Exception e) {
+            return R.ok(e.getMessage().toString());
+        }
+        return R.ok();
+    }
+
     @ApiOperation("获取用户列表")
     @GetMapping("/list")
     public R<List<UserEntity>> userList() {

+ 11 - 11
hazard-admin/src/main/java/com/ozs/web/controller/websocket/WebSocketConteoller.java

@@ -6,10 +6,7 @@ import com.ozs.common.core.controller.BaseController;
 import com.ozs.common.core.domain.entity.SysUser;
 import com.ozs.common.utils.AppendUtils;
 import com.ozs.common.utils.StringUtils;
-import com.ozs.service.entity.BaseCameraManagement;
-import com.ozs.service.entity.MsgAlarm;
-import com.ozs.service.entity.MsgAppPush;
-import com.ozs.service.entity.MsgWebPush;
+import com.ozs.service.entity.*;
 import com.ozs.service.entity.vo.MsgAlarmResp;
 import com.ozs.service.service.*;
 import com.ozs.system.service.ISysUserService;
@@ -166,14 +163,16 @@ public class WebSocketConteoller extends BaseController {
             lwMsgAppPush.eq(MsgAppPush::getAlarmId, msgAlarm.getAlarmId());
         }
         List<MsgAppPush> msgAppPushList = msgAppPushService.list(lwMsgAppPush);
+        log.info("APPmsgAppPushList     size -----" + msgAppPushList.size());
         if (StringUtils.isEmpty(msgAppPushList) || msgAppPushList.size() == 0) {
-            List<String> alias = new ArrayList<>();
+            List<UserRegistrationid> alias = new ArrayList<>();
             if (!StringUtils.isEmpty(userIdList) || userIdList.size() > 0) {
                 alias = userRegistrationidService.selectRegistrationID(userIdList);
             }
-            List<String> listString = distinct(alias);
-            if (!StringUtils.isEmpty(listString) || listString.size() > 0) {
-                for (String userid : listString) {
+//            List<String> listString = distinct(alias);
+            if (!StringUtils.isEmpty(alias) || alias.size() > 0) {
+                for (UserRegistrationid userRegistrationid : alias) {
+                    log.info("APP  alias    -----" + userRegistrationid.getRegistrationId());
                     String pushId = UUID.randomUUID().toString();
                     msgAlarmResp.setPushId(UUID.randomUUID().toString());
                     String content = objStr(msgAlarmResp);
@@ -181,9 +180,9 @@ public class WebSocketConteoller extends BaseController {
                     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                     String formatDate = sdf.format(alarmTime != null ? alarmTime : new Date());
                     log.info("APPcontent-----" + content);
-                    log.info("APPuserid-----" + userid);
+                    log.info("APPuserid-----" + userRegistrationid.getUserId());
                     List<String> userList = new ArrayList<>();
-                    userList.add(userid);
+                    userList.add(userRegistrationid.getRegistrationId());
                     JPushUtil.sendToRegistrationId(
                             userList,
                             "报警通知!", cameraName != null ? cameraName : "",
@@ -196,7 +195,8 @@ public class WebSocketConteoller extends BaseController {
                     msgAppPush.setStatus(1);
                     msgAppPush.setPushId(pushId);
                     msgAppPush.setAlarmId(alarmId);
-                    msgAppPush.setReceiveBy(userid);
+                    msgAppPush.setReceiveBy(userRegistrationid.getUserId());
+                    msgAppPush.setRegistrationId(userRegistrationid.getRegistrationId());
                     msgAppPush.setCreateBy(userIdLogin);
                     msgAppPush.setCreateTime(new Date());
                     msgAppPush.setUpdateBy(userIdLogin);

+ 70 - 27
hazard-admin/src/main/java/com/ozs/web/core/util/CameraUtil.java

@@ -55,7 +55,9 @@ public class CameraUtil {
     private static String webUrl;
     private static String bakUrl;
     private static CmdCameraUtil cUtil;
+    private static RedisCache rc;
 
+    public final static String mvkey = "WAIT_MERGE_VIDEO_ALARM_ID";
     @Autowired
     private CaneraConfig caneraConfig;
 
@@ -410,17 +412,27 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
         }
 
         if (fileTs.size() > 0) {
+            Map<String, Object> mergeVideoTsFile = rc.getCacheMap("mergeVideoTsFile");
+            if (ObjectUtils.isEmpty(mergeVideoTsFile)) {
+                mergeVideoTsFile = new HashMap<>();
+            }
+            Map<Date, List<String>> objectObjectHashMap = new HashMap<>();
+            objectObjectHashMap.put(new Date(), fileTs);
+            mergeVideoTsFile.put(newfilePath, objectObjectHashMap);
+            rc.deleteObject("mergeVideoTsFile");
+            rc.setCacheMap("mergeVideoTsFile", mergeVideoTsFile);
+
             sm.append("-c copy " + newfilePath);
             log.info("合并命令:{}", sm.toString());
             cUtil.cmd(sm.toString());
         }
-        Thread.sleep(2000L);
-        for (String fileT : fileTs) {
-            File ft = new File(fileT);
-            if (ft.exists()) {
-                ft.delete();
-            }
-        }
+
+//        for (String fileT : fileTs) {
+//            File ft = new File(fileT);
+//            if (ft.exists()) {
+//                ft.delete();
+//            }
+//        }
     }
 
     public static List<Map<String, Object>> getRecordList(String channel, Date startTm, Date endTm) {
@@ -537,22 +549,6 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
         }
     }
 
-    public static void main(String[] args) throws InterruptedException, ParseException, IOException {
-//        CameraUtil cameraUtil = new CameraUtil();
-//        cameraUtil.closeRecording();
-        String s = "/opt/streams/record/flv/42010001541320001116/20230403_235506_000506-22e1523b-d170-11ed-8a42-fa163e4e1e9f.flv";
-        String substring = s.substring(0, s.lastIndexOf("."));
-        System.out.println(substring);
-//        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));
-    }
 
     public static File[] getCurFilesList(String filePath) {
         File path = new File(filePath);
@@ -684,6 +680,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
         bakUrl = caneraConfig.getBakUrl();
         recordUrl = caneraConfig.getRecordUrl();
         cUtil = cmdCameraUtil;
+        rc = redisCache;
     }
 
 
@@ -781,9 +778,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
     public void mergeVideo() {
         Date date = new Date();
         Calendar calendar = new GregorianCalendar();
-
-
-        Map<String, Object> alarmIdMap = redisCache.getCacheMap("WAIT_MERGE_VIDEO_ALARM_ID");
+        Map<String, Object> alarmIdMap = redisCache.getCacheMap(mvkey);
         log.info("WAIT_MERGE_VIDEO_ALARM_ID:{}", alarmIdMap);
         if (!ObjectUtils.isEmpty(alarmIdMap)) {
             Set<String> alarmIds = alarmIdMap.keySet();
@@ -801,6 +796,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
                         if (!StringUtils.isBlank(cameraChannelByAlarmId)) {
                             log.info("报警UUID:{},相机通道:{},开始时间:{},结束时间:{}", alarmId, cameraChannelByAlarmId, (Date) oTime, date);
                             String url = historyPlayListStr(cameraChannelByAlarmId, (Date) oTime, date);
+
                             redisCache.setCacheObject("STREAMING_ALARM_VIDEO:" + alarmId, url);
                             redisCache.expire("STREAMING_ALARM_VIDEO:" + alarmId, 365L, TimeUnit.DAYS);
                             alarmIdMap.remove(alarmId);
@@ -809,7 +805,54 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
                 }
             }
         }
-        redisCache.setCacheMap("WAIT_MERGE_VIDEO_ALARM_ID", alarmIdMap);
+        log.info("删除后的alarmIdMap:{}", alarmIdMap);
+        redisCache.deleteObject(mvkey);
+        redisCache.setCacheMap(mvkey, alarmIdMap);
+
+    }
 
+
+    public void deleteTsFile() {
+        Date date = new Date();
+        Set<String> keys = new HashSet<>();
+        Calendar calendar = new GregorianCalendar();
+        Map<String, Object> mergeVideoTsFile = redisCache.getCacheMap("mergeVideoTsFile");
+        if (!ObjectUtils.isEmpty(mergeVideoTsFile) && mergeVideoTsFile.size() > 0) {
+            mergeVideoTsFile.keySet().forEach(s -> {
+                Object o = mergeVideoTsFile.get(s);
+                if (!ObjectUtils.isEmpty(o)) {
+                    Map<Date, List<String>> m = (Map<Date, List<String>>) o;
+                    if (!ObjectUtils.isEmpty(m) && m.size() > 0) {
+                        m.keySet().forEach(md -> {
+                            Date fileTime = (Date) md;
+                            // 判断当前时间是否超过报警时间 20分钟
+                            calendar.setTime(fileTime);
+                            calendar.add(calendar.MINUTE, 10); //把日期往后增加一天,整数  往后推,负数往前移动
+                            fileTime = calendar.getTime(); //这个时间就是日期往后推一天的结果
+                            if (date.compareTo(fileTime) > 0) {
+                                List<String> list = m.get(md);
+                                for (String s1 : list) {
+                                    File ft = new File(s1);
+                                    if (ft.exists()) {
+                                        ft.delete();
+                                    }
+                                }
+                                //
+                                m.remove(md);
+                                keys.add(s);
+                            }
+                        });
+                    }
+                }
+            });
+            // 删除key
+            if (keys.size() > 0) {
+                for (String s : mergeVideoTsFile.keySet()) {
+                    mergeVideoTsFile.remove(s);
+                }
+            }
+        }
+        redisCache.deleteObject("mergeVideoTsFile");
+        redisCache.setCacheMap("mergeVideoTsFile", mergeVideoTsFile);
     }
 }

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

@@ -9,7 +9,7 @@ base:
   # 实例演示开关
   demoEnabled: true
   # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
-  profile: /data/service/hazard-admin/uploadPath
+  profile: /opt/streams
   #  profile: C:\base\uploadPath
   # 获取ip地址开关
   addressEnabled: true

+ 43 - 0
hazard-sdk/src/main/java/com/ozs/config/FastJson2JsonRedisSerializer.java

@@ -0,0 +1,43 @@
+package com.ozs.config;
+
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONReader;
+import com.alibaba.fastjson2.JSONWriter;
+import org.springframework.data.redis.serializer.RedisSerializer;
+import org.springframework.data.redis.serializer.SerializationException;
+
+import java.nio.charset.Charset;
+
+/**
+ * Redis使用FastJson序列化
+ *
+ * @author hx
+ */
+public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T> {
+    public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
+
+    private Class<T> clazz;
+
+    public FastJson2JsonRedisSerializer(Class<T> clazz) {
+        super();
+        this.clazz = clazz;
+    }
+
+    @Override
+    public byte[] serialize(T t) throws SerializationException {
+        if (t == null) {
+            return new byte[0];
+        }
+        return JSON.toJSONString(t, JSONWriter.Feature.WriteClassName).getBytes(DEFAULT_CHARSET);
+    }
+
+    @Override
+    public T deserialize(byte[] bytes) throws SerializationException {
+        if (bytes == null || bytes.length <= 0) {
+            return null;
+        }
+        String str = new String(bytes, DEFAULT_CHARSET);
+
+        return JSON.parseObject(str, clazz, JSONReader.Feature.SupportAutoType);
+    }
+}

+ 98 - 0
hazard-sdk/src/main/java/com/ozs/config/RedisConfig.java

@@ -0,0 +1,98 @@
+package com.ozs.config;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.PropertyAccessor;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.springframework.cache.CacheManager;
+import org.springframework.cache.annotation.CachingConfigurerSupport;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.cache.RedisCacheConfiguration;
+import org.springframework.data.redis.cache.RedisCacheManager;
+import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.script.DefaultRedisScript;
+import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
+import org.springframework.data.redis.serializer.RedisSerializationContext;
+import org.springframework.data.redis.serializer.RedisSerializer;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
+
+import java.time.Duration;
+
+/**
+ * redis配置
+ *
+ * @author hx
+ */
+@Configuration
+@EnableCaching
+public class RedisConfig extends CachingConfigurerSupport {
+    @Bean
+    @SuppressWarnings(value = {"unchecked", "rawtypes"})
+    public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
+        RedisTemplate<Object, Object> template = new RedisTemplate<>();
+        template.setConnectionFactory(connectionFactory);
+
+        FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class);
+
+        // 使用StringRedisSerializer来序列化和反序列化redis的key值
+        template.setKeySerializer(new StringRedisSerializer());
+        template.setValueSerializer(serializer);
+
+        // Hash的key也采用StringRedisSerializer的序列化方式
+        template.setHashKeySerializer(new StringRedisSerializer());
+        template.setHashValueSerializer(serializer);
+
+        template.afterPropertiesSet();
+        return template;
+    }
+
+    @Bean
+    public CacheManager cacheManager(RedisConnectionFactory factory) {
+        RedisSerializer<String> redisSerializer = new StringRedisSerializer();
+        Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new
+                Jackson2JsonRedisSerializer(Object.class);
+//解决查询缓存转换异常的问题
+        ObjectMapper om = new ObjectMapper();
+        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
+        om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
+        jackson2JsonRedisSerializer.setObjectMapper(om);
+// 配置序列化(解决乱码的问题),过期时间600秒
+        RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
+                .entryTtl(Duration.ofSeconds(600))
+                .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer))
+                .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer))
+                .disableCachingNullValues();
+        RedisCacheManager cacheManager = RedisCacheManager.builder(factory)
+                .cacheDefaults(config)
+                .build();
+        return cacheManager;
+    }
+
+    @Bean
+    public DefaultRedisScript<Long> limitScript() {
+        DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>();
+        redisScript.setScriptText(limitScriptText());
+        redisScript.setResultType(Long.class);
+        return redisScript;
+    }
+
+    /**
+     * 限流脚本
+     */
+    private String limitScriptText() {
+        return "local key = KEYS[1]\n" +
+                "local count = tonumber(ARGV[1])\n" +
+                "local time = tonumber(ARGV[2])\n" +
+                "local current = redis.call('get', key);\n" +
+                "if current and tonumber(current) > count then\n" +
+                "    return tonumber(current);\n" +
+                "end\n" +
+                "current = redis.call('incr', key)\n" +
+                "if tonumber(current) == 1 then\n" +
+                "    redis.call('expire', key, time)\n" +
+                "end\n" +
+                "return tonumber(current);";
+    }
+}

+ 6 - 2
hazard-sdk/src/main/java/com/ozs/controller/upload/GeoHazardMonitorTokenController.java

@@ -197,10 +197,14 @@ public class GeoHazardMonitorTokenController {
                 respMsgAlarmVo.setIsCancel(2);
                 respMsgAlarmVo.setCancelTime(null);
                 // 记录要合成报警视频的报警id
-                Map<String, Object> map = redisCache.getCacheMap("WAIT_MERGE_VIDEO_ALARM_ID");
+                Map<String, Object> map = redisCache.getCacheMap(RedisConstant.key);
+                if (ObjectUtils.isEmpty(map)) {
+                    map = new HashMap<>();
+                }
                 map.put(msgAlarm.getAlarmId(), msgAlarm.getAlarmTime());
                 log.info("map:{}", map);
-                redisCache.setCacheMap("WAIT_MERGE_VIDEO_ALARM_ID", map);
+                redisCache.deleteObject(RedisConstant.key);
+                redisCache.setCacheMap(RedisConstant.key, map);
             } else {
                 BeanUtils.copyProperties(reqMsgAlarmVo, msgAlarmVice);
                 String[] imageUrl = reqMsgAlarmVo.getImageUrls();

+ 6 - 0
hazard-sdk/src/main/java/com/ozs/controller/upload/RedisConstant.java

@@ -0,0 +1,6 @@
+package com.ozs.controller.upload;
+
+public class RedisConstant {
+
+    public final static String key = "WAIT_MERGE_VIDEO_ALARM_ID";
+}