Ver código fonte

1、完成调整redis缓存数据的存活时间由永久改为6小时。
2、完成minioClient 被拒绝时进行重新初始化操作。
3、调整并检查上传一段音频文件时 alarms预警 的deviceUuid缺少问题。
4、进行调整插入、修改、删除异音设备逻辑(当前为中心端只插入当前库,当前为边端,先插入中心端,然后再根据插入结果进行插入边端)。
5、调整getSensorList接口的ip字段获取。
6、调整获取设备的StreamUrl字段逻辑。
7、添加当前为中心端时上传文件仍然调用算法解析逻辑,

pc147123 3 meses atrás
pai
commit
943d767961

+ 0 - 61
src/main/java/com/example/unusualsounds/common/utils/WebUtils.java

@@ -96,65 +96,4 @@ public class WebUtils {
 
         return obj;
     }
-
-//    public static ResponseObj sendPostDelRequest(String url, Map<String, Object> headerMap, Map<String, Object> paraMap, List<String> ids, int requestTimeoutSeconds) {
-//        return sendPostDelRequest(url, null, null, ids, requestTimeoutSeconds, String.class);
-//    }
-//
-//    public static <T> ResponseObj<T> sendPostDelRequest(String url, Map<String, Object> headerMap, Map<String, Object> paraMap, List<String> ids, int requestTimeoutSeconds, Class<T> responseBodyType) {
-//
-//        SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
-//        clientHttpRequestFactory.setConnectTimeout(requestTimeoutSeconds * 1000);
-//        clientHttpRequestFactory.setReadTimeout(requestTimeoutSeconds * 1000);
-//        RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory);
-//        HttpHeaders headers = new HttpHeaders();
-//        headers.setContentType(MediaType.APPLICATION_JSON);
-//        String paramUrl;
-//        if (headerMap != null && !headerMap.isEmpty()) {
-//            Iterator var9 = headerMap.keySet().iterator();
-//
-//            while (var9.hasNext()) {
-//                paramUrl = (String) var9.next();
-//                headers.add(paramUrl, String.valueOf(headerMap.get(paramUrl)));
-//            }
-//        }
-//
-////        HttpEntity<Map<String, Object>> request = new HttpEntity(dataMap, headers);
-//        HttpEntity<List<String>> request = new HttpEntity<>(ids, headers);
-//        paramUrl = url;
-//        ResponseEntity<T> response = null;
-//
-//        try {
-//            if (paraMap != null) {
-//                boolean findParam = false;
-//
-//                for (Iterator var13 = paraMap.keySet().iterator(); var13.hasNext(); findParam = true) {
-//                    String param = (String) var13.next();
-//                    if (!findParam) {
-//                        paramUrl = paramUrl + "?";
-//                    } else {
-//                        paramUrl = paramUrl + "&";
-//                    }
-//
-//                    paramUrl = paramUrl + param + "={" + param + "}";
-//                }
-//
-//                response = restTemplate.postForEntity(paramUrl, request, responseBodyType, paraMap);
-//            } else {
-//                response = restTemplate.postForEntity(paramUrl, request, responseBodyType, new Object[0]);
-//            }
-//        } catch (Exception var15) {
-//            log.info("Exception var15:{}", var15);
-//        } catch (Throwable var16) {
-//            log.info("Throwable var16:{}", var16);
-//        }
-//
-//        ResponseObj<T> obj = new ResponseObj();
-//        if (response != null) {
-//            obj.setStatusCodeValue(response.getStatusCodeValue());
-//            obj.setBody(response.getBody());
-//        }
-//
-//        return obj;
-//    }
 }

+ 6 - 0
src/main/java/com/example/unusualsounds/project/device/entity/vo/RegisterSoundSensors.java

@@ -83,4 +83,10 @@ public class RegisterSoundSensors {
 
     @Schema(description = "判别当前是中心端还是边缘端")
     private String soundSensorIp;
+
+    /**
+     * 文件地址
+     */
+    @Schema(description = "文件地址")
+    private String StreamUrl;
 }

+ 14 - 18
src/main/java/com/example/unusualsounds/project/device/service/impl/DevicesSoundSensorsServiceImpl.java

@@ -114,10 +114,15 @@ public class DevicesSoundSensorsServiceImpl extends ServiceImpl<DevicesSoundSens
 
         if ("file".equals(soundSensors.getSoundSensorType())) {
             System.out.println("获取:" + soundSensors.getSoundFileUUid().toString());
-            Object o = RedisUtils.get(soundSensors.getSoundFileUUid());
 
-            devicesSoundSensors.setStreamUrl(o.toString());
-            devicesSoundSensors.setSrcUrl(o.toString());
+            if(!soundSensors.getStreamUrl().isEmpty()&&soundSensors.getStreamUrl()!=null){
+                devicesSoundSensors.setStreamUrl(soundSensors.getStreamUrl());
+                devicesSoundSensors.setSrcUrl(soundSensors.getStreamUrl());
+            }else {
+                Object o = RedisUtils.get(soundSensors.getSoundFileUUid());
+                devicesSoundSensors.setStreamUrl(o.toString());
+                devicesSoundSensors.setSrcUrl(o.toString());
+            }
             devicesSoundSensors.setStatus("online");
             devicesSoundSensors.setVideoType("file");
             devicesSoundSensors.setFileUuid(soundSensors.getSoundFileUUid());
@@ -154,10 +159,11 @@ public class DevicesSoundSensorsServiceImpl extends ServiceImpl<DevicesSoundSens
             }
             int insert = baseMapper.insert(devicesSoundSensors);
             RedisUtils.delete(soundSensors.getSoundFileUUid());
+            //当前为中心端时不能直接返回,如果插入成功则通知算法
             if (insert > 0) {
-                return true;
+                isFlag = true;
             } else {
-                return false;
+                isFlag = false;
             }
         } else {
             //当前为边端,先插入中心再插入本地
@@ -177,7 +183,7 @@ public class DevicesSoundSensorsServiceImpl extends ServiceImpl<DevicesSoundSens
 
 
         //对文件进行立刻通知算法解析(如果是文件类型,通知算法解析)
-        if ("file".equals(soundSensors.getSoundSensorType())) {
+        if ("file".equals(soundSensors.getSoundSensorType()) && isFlag) {
             log.info("对文件进行立刻通知算法解析(如果是文件类型,通知算法解析) start");
 //            QueryWrapper<Skills> skillsQueryWrapper = new QueryWrapper<>();
 //            skillsQueryWrapper.eq("uuid",soundSensors.getSkillUuid()).last("limit 1");
@@ -312,17 +318,7 @@ public class DevicesSoundSensorsServiceImpl extends ServiceImpl<DevicesSoundSens
         // todo ghjghj
         queryWrapper.orderByDesc("id");
         IPage<DevicesSoundSensors> page = baseMapper.selectPage(sensorsPage, queryWrapper);
-//        if (!StringUtils.equals(centerCode.trim(), edgeCode.trim())) {
-//            log.info("当前列表为边缘端");
-//            DevicesSoundSensorsList devicesSoundSensorsList = DevicesSoundSensorsList.builder()
-//                    .edgeName(edgeCode.trim()).soundSensors(page).build();
-//            return devicesSoundSensorsList;
-//        }else {
-//            log.info("当前列表为中心端");
-//            DevicesSoundSensorsList devicesSoundSensorsList = DevicesSoundSensorsList.builder()
-//                    .edgeName(centerCode.trim()).soundSensors(page).build();
-//            return devicesSoundSensorsList;
-//        }
+
         DevicesSoundSensorsList devicesSoundSensorsList = DevicesSoundSensorsList.builder()
                 .edgeName(checkServiceCode()).soundSensors(page).build();
         return devicesSoundSensorsList;
@@ -437,7 +433,7 @@ public class DevicesSoundSensorsServiceImpl extends ServiceImpl<DevicesSoundSens
     public Boolean insertSensors(String url, DevicesSoundSensors devicesSoundSensors, RegisterSoundSensors soundSensors, String soundFileUUid) {
 
         try {
-            // todo ghjghj
+
             Boolean aBoolean = VoiceAnalysisUtils.postCenterSensorsUp(url, soundSensors);
             if (!aBoolean) {
                 throw new RuntimeException("插入中心端异常");

+ 6 - 0
src/main/resources/application-edge.yml

@@ -93,3 +93,9 @@ OkHttp:
 Alarms:
   imageUrl: s3://windmill/store/abnormal-sound/source/2025-03-20/aafdfd09-0f41-4942-9414-10061f8f674e.jpeg
   thumbnailUrl: s3://windmill/store/abnormal-sound/source/2025-03-20/d4a6fa31-0404-486e-997d-9fd9a89f87bd.jpg
+voice:
+  commandStr: "ffmpeg"
+  commandProbeStr: "ffprobe"
+  commandCopy: "-c:v"
+  commandA: "-c:a"
+  commandAC: "aac"

+ 3 - 1
src/main/resources/application.yml

@@ -1,6 +1,8 @@
 spring:
   profiles:
-    active: dev
+#    active: dev
+    active: edge
+#    active: prod
 
 springdoc:
   swagger-ui:

+ 5 - 3
src/test/java/com/example/unusualsounds/UnusualSoundsApplicationTests.java

@@ -321,10 +321,12 @@ class UnusualSoundsApplicationTests {
 //                }
 //        );
 
-        List<String> strings = Arrays.asList("123", "abc", "qqa");
-        String str = JSONObject.toJSONString(strings);
-        System.out.println("str:"+str);
+//        List<String> strings = Arrays.asList("123", "abc", "qqa");
+//        String str = JSONObject.toJSONString(strings);
+//        System.out.println("str:"+str);
 
+        String str =null;
+        System.out.println("str:"+str !=null);
 
     }