瀏覽代碼

1、新增alarms预警封面逻辑(1、每次都向中心端请求最新的图片然后上传(当前采用);2、将预警图片封装在镜像内,进行初始化上传);
2、新增minioClient2客户端@Bean(“minioClient2”).

pc147123 3 月之前
父節點
當前提交
e7ec7296e1

+ 4 - 0
pom.xml

@@ -27,6 +27,10 @@
         <beanutils.version>1.9.4</beanutils.version>
     </properties>
     <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
+        </dependency>
 
         <dependency>
             <groupId>commons-beanutils</groupId>

+ 7 - 0
src/main/java/com/example/unusualsounds/UnusualSoundsApplication.java

@@ -1,5 +1,6 @@
 package com.example.unusualsounds;
 
+import com.example.unusualsounds.framework.minio.MinioUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -17,6 +18,9 @@ public class UnusualSoundsApplication {
     @Autowired
     private RestTemplateBuilder builder;
 
+    @Autowired
+    private MinioUtil minioUtil;
+
     @Bean
     public RestTemplate restTemplate() {
         return builder.build();
@@ -24,5 +28,8 @@ public class UnusualSoundsApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(UnusualSoundsApplication.class, args);
+
+
+
     }
 }

+ 51 - 0
src/main/java/com/example/unusualsounds/common/init/InitImg.java

@@ -0,0 +1,51 @@
+//package com.example.unusualsounds.common.init;
+//
+//
+//import com.example.unusualsounds.common.utils.FileToMultipartFile;
+//import com.example.unusualsounds.framework.minio.MinioUtil;
+//import lombok.extern.slf4j.Slf4j;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.beans.factory.annotation.Value;
+//import org.springframework.boot.CommandLineRunner;
+//import org.springframework.stereotype.Component;
+//
+//import java.io.File;
+//
+///**
+// *
+// *
+// */
+//@Component
+//@Slf4j
+//public class InitImg implements CommandLineRunner {
+//    @Value(" ${Alarms.imageUrl}")
+//    private String imageUrl;
+//    @Autowired
+//    private MinioUtil minioUtil;
+//
+//    @Value("${Alarms.dir}")
+//    private String alarmsDir;
+//
+//    //边端图片封面
+//    @Value("${minio.source-dir}")
+//    private String alarmsUrl;
+//
+//    @Override
+//    public void run(String... args) throws Exception {
+//        String str = imageUrl;
+//        String fileName = str.trim().replaceFirst("^s3://[^/]+/", "");
+//        log.info("检查文件{}",fileName);
+//        boolean b = minioUtil.checkFileIsExist(fileName);
+//
+//        if(!b){
+//            File file = new File(alarmsDir);
+//            FileToMultipartFile fileToMultipartFile = new FileToMultipartFile(file);
+//            String url = minioUtil.uploadImageUrl(fileToMultipartFile, alarmsUrl,"image/jpeg");
+//            log.info("当前minio没有封面,重新上传后的url:{}",url);
+//        }else {
+//            log.info("当前minio已有封面");
+//        }
+//
+//
+//    }
+//}

+ 20 - 2
src/main/java/com/example/unusualsounds/framework/minio/MinioConfig.java

@@ -20,7 +20,15 @@ import java.util.concurrent.TimeUnit;
 @ConfigurationProperties(prefix = "minio")
 @Slf4j
 public class MinioConfig {
+    //从环境变量中获取
+    @Value("${Center-minio.endpoint}")
+    private String centerMinioEndpoint;
 
+    @Value("${Center-minio.ak}")
+    private String centerMinioAk;
+
+    @Value("${Center-minio.sk}")
+    private String centerMinioSk;
 
     private String endpoint;
     private String ak;
@@ -53,8 +61,8 @@ public class MinioConfig {
     }
 
 
-    @Bean
-    public MinioClient minioClient() {
+    @Bean("minioClient1")
+    public MinioClient minioClient1() {
 
         return MinioClient.builder()
                 .endpoint(endpoint)
@@ -63,4 +71,14 @@ public class MinioConfig {
                 .build();
     }
 
+    @Bean("minioClient2")
+    public MinioClient minioClient2() {
+
+        return  MinioClient.builder()
+                .endpoint(centerMinioEndpoint)
+                .credentials(centerMinioAk, centerMinioSk)
+                .build();
+    }
+
+
 }

+ 81 - 5
src/main/java/com/example/unusualsounds/framework/minio/MinioUtil.java

@@ -3,10 +3,10 @@ package com.example.unusualsounds.framework.minio;
 import com.example.unusualsounds.common.utils.DateUtils;
 import com.example.unusualsounds.common.utils.UUID;
 import io.minio.*;
+import io.minio.errors.MinioException;
 import io.minio.http.Method;
 import io.minio.messages.Bucket;
 import io.minio.messages.Item;
-import jakarta.annotation.Resource;
 import jakarta.servlet.ServletOutputStream;
 import jakarta.servlet.http.HttpServletResponse;
 import lombok.extern.slf4j.Slf4j;
@@ -14,11 +14,15 @@ import okhttp3.ConnectionPool;
 import okhttp3.OkHttpClient;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Component;
 import org.springframework.util.FastByteArrayOutputStream;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
 import java.io.InputStream;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -29,14 +33,15 @@ public class MinioUtil {
     @Autowired
     private MinioConfig prop;
 
-    @Resource
-    private MinioClient minioClient;
 
+    private MinioClient minioClient;
     private final OkHttpClient okHttpClient;
 
     @Autowired
-    public MinioUtil(OkHttpClient okHttpClient) { // 构造器注入
+    public MinioUtil(OkHttpClient okHttpClient,
+                     @Qualifier("minioClient1")MinioClient minioClient) { // 构造器注入
         this.okHttpClient = okHttpClient;
+        this.minioClient = minioClient;
         log.info("MinioUtil 中的OkHttpClient实例哈希值: {}", okHttpClient.hashCode());
     }
 
@@ -123,7 +128,7 @@ public class MinioUtil {
         } catch (Exception e) {
             log.warn("MinIO客户端连接异常{}", e.getMessage());
             log.info("重新初始化····");
-            minioClient = prop.minioClient();
+            minioClient = prop.minioClient1();
         }
 
         String originalFilename = file.getOriginalFilename();
@@ -254,4 +259,75 @@ public class MinioUtil {
             return false;
         }
     }
+
+    /**
+     * 检查文件是否存在
+     * @param fileName
+     * @return
+     */
+    public boolean checkFileIsExist(String fileName){
+        try {
+            minioClient.statObject(StatObjectArgs.builder().bucket(prop.getBucket()).object(fileName).build());
+            return true;
+        } catch (MinioException e) {
+            return false;
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        } catch (NoSuchAlgorithmException e) {
+            throw new RuntimeException(e);
+        } catch (InvalidKeyException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * 上传文件,使用源文件名
+     * ---
+     * 该方法以约定死contentType,仅限于上传图片类型
+     *
+     * @return
+     */
+    public String uploadImageUrl(MultipartFile file, String path,String contentType){
+
+        ConnectionPool pool = okHttpClient.connectionPool();
+        log.info("上传前连接池状态:空闲连接数={}, 活跃连接数={}",
+                pool.idleConnectionCount(),
+                pool.connectionCount());
+        String originalFilename = file.getOriginalFilename();
+        if (StringUtils.isBlank(originalFilename)) {
+            throw new RuntimeException("文件名为空");
+        }
+        String objectName = path + originalFilename;
+
+        try (InputStream inputStream = file.getInputStream()) {
+            PutObjectArgs objectArgs = PutObjectArgs.builder()
+                    .bucket(prop.getBucket())
+                    .object(objectName)
+                    .stream(inputStream, file.getSize(), -1)
+                    .contentType(contentType)
+                    .build();
+
+            minioClient.putObject(objectArgs);
+            log.info("上传成功后接池状态:空闲连接数={}, 活跃连接数={}",
+                    pool.idleConnectionCount(),
+                    pool.connectionCount());
+
+            return prop.getEndpoint() + "/" + prop.getBucket() + "/" + objectName;
+
+        } catch (Exception e) {
+            log.info("上传失败连接池状态:空闲连接数={}, 活跃连接数={}",
+                    pool.idleConnectionCount(),
+                    pool.connectionCount());
+            log.error("文件上传失败: {}", e.getMessage(), e);
+            return null;
+        }
+
+    }
+
+
+
+
+
+
+
 }

+ 25 - 1
src/main/java/com/example/unusualsounds/project/device/controller/SensorsController.java

@@ -13,14 +13,26 @@ import com.example.unusualsounds.project.device.service.impl.DeviceVoiceServiceI
 import com.example.unusualsounds.project.device.service.impl.DevicesSoundSensorsServiceImpl;
 import com.example.unusualsounds.project.vox.entity.DevicesSoundSensorsList;
 import com.example.unusualsounds.web.entity.AjaxResult;
+import io.minio.GetObjectArgs;
+import io.minio.MinioClient;
+import io.minio.errors.*;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.FileAlreadyExistsException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
@@ -36,6 +48,7 @@ public class SensorsController {
     @Value("${minio.source-dir}")
     private String printDir;
 
+
     @Autowired
     private MinioUtil minioUtil;
 
@@ -188,8 +201,19 @@ public class SensorsController {
         ajaxResult.put("msg", "文件上传成功");
         ajaxResult.put("fileUUID", upload);
         return ajaxResult;
-
     }
 
 
+//    @Operation(summary = "检查文件是否存在")
+//    @PostMapping("/checkPrint")
+//    public AjaxResult checkPrint(@RequestParam("fileName") String fileName) {
+//        AjaxResult ajaxResult = new AjaxResult();
+//
+//        boolean b = minioUtil.checkFileIsExist(fileName);
+//        ajaxResult.put("code", HttpStatus.SUCCESS);
+//        ajaxResult.put("status", b);
+//        return ajaxResult;
+//    }
+
+
 }

+ 7 - 0
src/main/java/com/example/unusualsounds/project/device/entity/DevicesSoundSensors.java

@@ -7,6 +7,10 @@ import com.baomidou.mybatisplus.annotation.TableName;
 import java.io.Serializable;
 import java.util.Date;
 
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
@@ -19,10 +23,13 @@ import lombok.NoArgsConstructor;
 @Data
 @AllArgsConstructor
 @NoArgsConstructor
+@Entity
 public class DevicesSoundSensors implements Serializable {
     /**
      * 自增id
      */
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
     @TableId(value = "id", type = IdType.AUTO)
     private Long id;
 

+ 1 - 1
src/main/java/com/example/unusualsounds/project/vox/controller/CheckVoxController.java

@@ -15,6 +15,7 @@ import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 
 
@@ -41,7 +42,6 @@ public class CheckVoxController {
     @Autowired
     private VoiceTicketLogsServiceImpl voiceTicketLogsServiceImpl;
 
-
     @Operation(summary = "算法启停接口")
     @PostMapping("/start_stop")
     public AjaxResult startStopVox(@RequestBody Device device) throws InterruptedException {

+ 7 - 0
src/main/java/com/example/unusualsounds/project/vox/entity/VoiceTicketLogs.java

@@ -7,6 +7,10 @@ import com.baomidou.mybatisplus.annotation.TableName;
 import java.io.Serializable;
 import java.util.Date;
 
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
@@ -19,10 +23,13 @@ import lombok.NoArgsConstructor;
 @Data
 @AllArgsConstructor
 @NoArgsConstructor
+@Entity
 public class VoiceTicketLogs implements Serializable {
     /**
      * 自增id
      */
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
     @TableId(value = "id", type = IdType.AUTO)
     private Long id;
 

+ 10 - 0
src/main/java/com/example/unusualsounds/project/vox/service/AlarmsService.java

@@ -13,5 +13,15 @@ import java.util.HashMap;
 public interface AlarmsService extends IService<Alarms> {
 
 
+    /**
+     * 保存预警结果
+     * @param resultAnalysis
+     * @return
+     */
     boolean saveResultAnalysis(HashMap<String, String> resultAnalysis);
+
+    /**
+     * 测试封面
+     */
+    void testAlarms();
 }

+ 128 - 5
src/main/java/com/example/unusualsounds/project/vox/service/impl/AlarmsServiceImpl.java

@@ -2,15 +2,32 @@ package com.example.unusualsounds.project.vox.service.impl;
 
 import com.alibaba.fastjson2.JSON;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.example.unusualsounds.common.utils.FileToMultipartFile;
 import com.example.unusualsounds.common.utils.RedisUtils;
 import com.example.unusualsounds.common.utils.UUID;
+import com.example.unusualsounds.framework.minio.MinioUtil;
 import com.example.unusualsounds.project.vox.entity.Alarms;
 import com.example.unusualsounds.project.vox.service.AlarmsService;
 import com.example.unusualsounds.project.vox.mapper.AlarmsMapper;
+import io.minio.GetObjectArgs;
+import io.minio.MinioClient;
+import io.minio.errors.*;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.FileAlreadyExistsException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
 import java.util.Date;
 import java.util.HashMap;
 
@@ -20,6 +37,7 @@ import java.util.HashMap;
 * @createDate 2025-02-18 14:45:58
 */
 @Service
+@Slf4j
 public class AlarmsServiceImpl extends ServiceImpl<AlarmsMapper, Alarms>
     implements AlarmsService{
 
@@ -30,12 +48,37 @@ public class AlarmsServiceImpl extends ServiceImpl<AlarmsMapper, Alarms>
     @Autowired
     private EdgeOrganizationServiceImpl edgeOrganizationServiceImpl;
 
-    @Value("${Alarms.imageUrl}")
+    @Value(" ${CENTER_CODE}")
+    private String centerCode;
+
+    @Value(" ${Alarms.imageUrl}")
     private String imageUrl;
 
-    @Value("${Alarms.thumbnailUrl}")
-    private String thumbnailUrl;
+    @Value(" ${EDGE_CODE}")
+    private String edgeCode;
+
+
+    @Value("${Center-minio.bucket}")
+    private String centerMinioBucket;
+
+    @Value("${Center-minio.imagePath}")
+    private String centerMinioImagePath;
+
+    @Value("${Alarms.dir}")
+    private String alarmsDir;
+
+    //边端图片封面
+    @Value("${minio.source-dir}")
+    private String alarmsUrl;
 
+    @Autowired
+    private MinioUtil minioUtil;
+
+    private MinioClient minioClient;
+
+    public AlarmsServiceImpl(@Qualifier("minioClient2") MinioClient minioClient){
+        this.minioClient = minioClient;
+    }
 
 
     @Override
@@ -67,15 +110,95 @@ public class AlarmsServiceImpl extends ServiceImpl<AlarmsMapper, Alarms>
         alarms.setUuid(alarmUUID);
         alarms.setCreatedAt(new Date());
         alarms.setUpdatedAt(new Date());
-        alarms.setImageUrl(imageUrl);
-        alarms.setThumbnailUrl(thumbnailUrl);
 
+//        alarms.setImageUrl(imageUrl);
+//        alarms.setThumbnailUrl(imageUrl);
+
+        // todo 每次上传文件都从中心端minio进行下载上传的方式
+        if(!StringUtils.equals(centerCode.trim(),edgeCode.trim())){
+            //边缘端
+            String string = this.downLoadCenterImg();
+            if(!"error".equals(string)){
+                this.upAlarmsImg(string);
+            }
+        }
+        alarms.setImageUrl(imageUrl.trim());
+        alarms.setThumbnailUrl(imageUrl.trim());
 
         boolean save = this.save(alarms);
         boolean reportSave = alarmReportsService.saveAlarmReport(alarms);
         return reportSave;
 
     }
+
+    @Override
+    public void testAlarms() {
+        String string = this.downLoadCenterImg();
+        System.out.println("下载的文件地址:"+string);
+        String s = this.upAlarmsImg(string);
+        System.out.println("上传的文件地址:"+s);
+    }
+
+
+    /**
+     * 上传最新的封面图片
+     * 然后返回s3开头的url
+     * @param alarmsImgDir
+     * @return
+     */
+    public String upAlarmsImg(String alarmsImgDir){
+        File file = new File(alarmsImgDir);
+        FileToMultipartFile fileToMultipartFile = new FileToMultipartFile(file);
+        String path = alarmsUrl+"print/";
+        String url = minioUtil.uploadImageUrl(fileToMultipartFile, path,"image/jpeg");
+
+        String tmpStr = "s3://";
+        String replaced = url.replaceFirst("https?://[^/]+", "s3:/");
+        return replaced;
+    }
+
+
+
+    /**
+     * 从中心端下载固定路径下的封面图片
+     * ,然后上传到当前边端站,每次预警都重新下载并上传
+     * @return
+     */
+    public String downLoadCenterImg() {
+        try {
+            // 使用minioClient2
+            String bucketName = centerMinioBucket;
+            String objectName = centerMinioImagePath;
+
+            Path destPath = Paths.get(alarmsDir);
+            // 如果文件已存在,则删除它
+            try {
+                if (Files.exists(destPath)) {
+                    Files.delete(destPath); // 删除已有文件
+                    log.warn("文件存在,删除{}", alarmsDir);
+                }
+            }catch (FileAlreadyExistsException e){
+                log.error("文件删除失败:{}",e.getMessage());
+            }
+            // 获取对象输入流
+            InputStream stream = minioClient.getObject(
+                    GetObjectArgs.builder()
+                            .bucket(bucketName)
+                            .object(objectName)
+                            .build());
+
+            // 将输入流写入到文件
+            Files.copy(stream, Paths.get(alarmsDir));
+            log.info("当前minio:{}",minioClient);
+            log.info("文件下载成功");
+            return alarmsDir;
+        } catch (InvalidKeyException | ErrorResponseException | InsufficientDataException | InternalException |
+                 InvalidResponseException | NoSuchAlgorithmException | ServerException | XmlParserException |
+                 IllegalArgumentException | IOException e) {
+            e.printStackTrace();
+            return "error";
+        }
+    }
 }
 
 

+ 33 - 6
src/main/resources/application-dev.yml

@@ -2,9 +2,21 @@
 server:
   port: 19801
 
+#knife4j配置
 knife4j:
-  #关闭生产环境屏蔽
+  #开启生产环境屏蔽
   production: false
+  #启用增强设置
+  enable: true
+  #启用登录认证
+  basic:
+    enable: true
+    username: admin
+    password: 123456
+  setting:
+    language: zh_cn
+    enable-version: true
+    enable-swagger-models: true
 
 
 minio:
@@ -14,9 +26,14 @@ minio:
   sk: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
   bucket: windmill
   dir: store/abnormal-sound/
-  source-dir: store/abnormal-sound/source/
+  source-dir: store/abnormal-sound/source/print/
 
 spring:
+  jpa:
+    database-platform: org.hibernate.dialect.MySQL57Dialect
+    hibernate:
+      ddl-auto: update
+    show-sql: true
   datasource:
     dynamic:
       primary: master
@@ -27,6 +44,7 @@ spring:
           url: jdbc:mysql://10.68.208.94:8639/iip_api_service?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true
           username: root
           password: fbLfJZ1sFMAw
+
     druid:
       initial-size: 5
       min-idle: 5
@@ -91,10 +109,10 @@ OkHttp:
   #当前分片时间是5分钟,保活取两倍+1
   KeepLive: 2
 
-#alarms配置
 Alarms:
-  imageUrl: s3://windmill/store/abnormal-sound/source/2025-03-21/aafdfd09-0f41-4942-9414-10061f8f674e.jpeg
-  thumbnailUrl: s3://windmill/store/abnormal-sound/source/2025-03-21/d4a6fa31-0404-486e-997d-9fd9a89f87bd.jpg
+  #预警封面图片
+  imageUrl: s3://windmill/store/abnormal-sound/source/print/202504301407.jpeg
+  dir: D:\tmp\data\vox\alarmImg\202504301407.jpeg
 
 voice:
   commandStr: "D:\\file\\ffmpeg\\ffmpeg.exe"
@@ -102,6 +120,15 @@ voice:
   commandCopy: "-c"
   commandA: "-c:a"
   commandAC: "aac"
-  commandSegmentTime: "100"
+  commandSegmentTime: "300"
+
+Center-minio:
+  #中心
+  endpoint: http://10.68.204.52:8077
+  ak: AKIAIOSFODNN7EXAMPLE
+  sk: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
+  bucket: windmill
+  imagePath: store/abnormal-sound/source/print/202504301407.jpeg
+
 
 

+ 30 - 4
src/main/resources/application-edge.yml

@@ -2,9 +2,21 @@
 server:
   port: 19801
 
+#knife4j配置
 knife4j:
   #开启生产环境屏蔽
   production: true
+  #启用增强设置
+  enable: true
+  #启用登录认证
+  basic:
+    enable: true
+    username: admin
+    password: 123456
+  setting:
+    language: zh_cn
+    enable-version: true
+    enable-swagger-models: true
 
 
 minio:
@@ -16,6 +28,11 @@ minio:
   source-dir: store/abnormal-sound/source/
 
 spring:
+  jpa:
+    database-platform: org.hibernate.dialect.MySQL57Dialect
+    hibernate:
+      ddl-auto: update
+    show-sql: true
   datasource:
     dynamic:
       primary: master
@@ -89,14 +106,23 @@ OkHttp:
   #当前分片时间是5分钟,保活取两倍+1
   KeepLive: 13
 
-#alarms配置
 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
+  #预警封面图片minio地址
+  imageUrl: s3://windmill/store/abnormal-sound/source/print/202504301407.jpeg
+  dir: /tmp/alarmImg/202504301407.jpeg
+
 voice:
   commandStr: "ffmpeg"
   commandProbeStr: "ffprobe"
   commandCopy: "-c:v"
   commandA: "-c:a"
   commandAC: "aac"
-  commandSegmentTime: "300"
+
+Center-minio:
+  #中心
+  endpoint: http://spi-lysffx.chnenergy.com.cn:9000
+  ak: AKIAIOSFODNN7EXAMPLE
+  sk: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
+  bucket: windmill
+  imagePath: store/abnormal-sound/source/print/202504301407.jpeg
+

+ 60 - 13
src/main/resources/application-prod.yml

@@ -1,30 +1,51 @@
-# 应用服务 WEB 访问端口 一见中心侧
+#正式环境下的模板
 server:
   port: 19801
 
+#knife4j配置
 knife4j:
   #开启生产环境屏蔽
   production: true
-
+  #启用增强设置
+  enable: true
+  #启用登录认证
+  basic:
+    enable: true
+    username: admin
+    password: 123456
+  setting:
+    language: zh_cn
+    enable-version: true
+    enable-swagger-models: true
 
 minio:
-  #  中心测
+  #中心      
   endpoint: http://minio-idaas.middleware.svc.cluster.local:9000
+  #边端
+  #endpoint: http://minio-idaas:9000
   ak: AKIAIOSFODNN7EXAMPLE
   sk: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
   bucket: windmill
   dir: store/abnormal-sound/
-  source-dir: store/abnormal-sound/source/
+  source-dir: store/abnormal-sound/source/print/
+
 
 spring:
+  jpa:
+    database-platform: org.hibernate.dialect.MySQL57Dialect
+    hibernate:
+      ddl-auto: update
+    show-sql: true
   datasource:
     dynamic:
       primary: master
       datasource:
-        #中心测
         master:
           type: com.alibaba.druid.pool.DruidDataSource
           driver-class-name: com.mysql.cj.jdbc.Driver
+          #边端
+          # url: jdbc:mysql://mysql:8436/iip_api_service?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true
+          #中心
           url: jdbc:mysql://xdbmysql57-leader.middleware.svc.cluster.local:8436/iip_api_service?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true
           username: root
           password: fbLfJZ1sFMAw
@@ -46,7 +67,10 @@ spring:
       max-request-size: 100MB
   data:
     redis:
+      #中心
       host: redis-single-master.middleware.svc.cluster.local
+      #边端
+      #host: redis-single-master
       port: 6379
       password: 12fbLfJZ1a3F
       database: 0
@@ -58,10 +82,22 @@ spring:
           max-wait: -1ms
           max-active: 1000
 
+
+logging:
+  level:
+    root: info
+    com.example.unusualsounds: debug
+    org:
+      hibernate:
+        sql: debug
+        type:
+          descriptor:
+            sql:
+              BasicBinder: trace
 #异音算法接口
 vox:
   #vox服务地址
-#  post-analysis-url: http://vox-model-service.vox-services.svc.cluster.local:8899/audio
+  #  post-analysis-url: http://vox-model-service.vox-services.svc.cluster.local:8899/audio
   post-analysis-url: http://vox-model-service:8899/audio
   #视频流切片保存地址
   video-dir: /tmp/
@@ -72,7 +108,11 @@ yijian-interface:
   center:
     ak: a440a816330a4e558ec33d50aaad379d
     sk: d9068f8ff3604a45a83b81c987de673a
+    #中心
     endpoint: http://10.170.69.123:8412
+    #边端
+    #endpoint: http://apisix-gateway:80
+
   #接口地址前缀配置
   uri-path-prefix: /api/spi
   #设备信息接口地址 GET /v1/devices/{deviceID}
@@ -85,21 +125,28 @@ yijian-interface:
 Camera:
   num: 60
 
-#minio线程池
 OkHttp:
-  num: 30
-  #当前分片时间是5分钟,保活取两倍+1
+  num: 80
   KeepLive: 13
 
-#alarms配置
 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
+  #预警封面图片
+  imageUrl: s3://windmill/store/abnormal-sound/source/print/202504301407.jpeg
+  dir: /tmp/alarmImg/202504301407.jpeg
+
+#ffmpeg commond
 voice:
   commandStr: "ffmpeg"
   commandProbeStr: "ffprobe"
   commandCopy: "-c:v"
   commandA: "-c:a"
   commandAC: "aac"
-  commandSegmentTime: "300"
+  #  commandSegmentTime: "300"
 
+Center-minio:
+  #中心
+  endpoint: http://spi-lysffx.chnenergy.com.cn:9000
+  ak: AKIAIOSFODNN7EXAMPLE
+  sk: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
+  bucket: windmill
+  imagePath: store/abnormal-sound/source/print/202504301407.jpeg

+ 28 - 4
src/main/resources/application-test.yml

@@ -2,10 +2,21 @@
 server:
   port: 19801
 
+#knife4j配置
 knife4j:
   #开启生产环境屏蔽
   production: true
-
+  #启用增强设置
+  enable: true
+  #启用登录认证
+  basic:
+    enable: true
+    username: admin
+    password: 123456
+  setting:
+    language: zh_cn
+    enable-version: true
+    enable-swagger-models: true
 
 minio:
   #  中心测
@@ -17,6 +28,11 @@ minio:
   source-dir: store/abnormal-sound/source/
 
 spring:
+  jpa:
+    database-platform: org.hibernate.dialect.MySQL57Dialect
+    hibernate:
+      ddl-auto: update
+    show-sql: true
   datasource:
     dynamic:
       primary: master
@@ -28,6 +44,7 @@ spring:
           url: jdbc:mysql://xdbmysql57-leader.middleware.svc.cluster.local:8436/iip_api_service?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true
           username: root
           password: fbLfJZ1sFMAw
+
     druid:
       initial-size: 5
       min-idle: 5
@@ -92,8 +109,9 @@ OkHttp:
 
 #alarms配置
 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
+  #预警封面图片
+  imageUrl: s3://windmill/store/abnormal-sound/source/print/202504301407.jpeg
+  dir: /tmp/alarmImg/202504301407.jpeg
 
 voice:
   commandStr: "ffmpeg"
@@ -103,4 +121,10 @@ voice:
   commandAC: "aac"
   commandSegmentTime: "300"
 
-
+Center-minio:
+  #中心
+  endpoint: http://spi-lysffx.chnenergy.com.cn:9000
+  ak: AKIAIOSFODNN7EXAMPLE
+  sk: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
+  bucket: windmill
+  imagePath: store/abnormal-sound/source/print/202504301407.jpeg

+ 13 - 15
src/main/resources/application.yml

@@ -1,4 +1,10 @@
 spring:
+  jpa:
+    database-platform: org.hibernate.dialect.MySQL57Dialect
+    hibernate:
+      ddl-auto: update
+    show-sql: true
+
   profiles:
     active: dev
 #    active: edge
@@ -29,25 +35,17 @@ mybatis-plus:
   config-location: classpath:mybatis/mybatis-config.xml
 
 
-#knife4j配置
-knife4j:
-  #启用增强设置
-  enable: true
-  #启用登录认证
-  basic:
-    enable: true
-    username: admin
-    password: 123456
-  setting:
-    language: zh_cn
-    enable-version: true
-    enable-swagger-models: true
-
-
 logging:
   level:
     root: info
     com.example.unusualsounds: debug
+    org:
+      hibernate:
+        sql: debug
+        type:
+          descriptor:
+            sql:
+              BasicBinder: trace
 
 
 

+ 16 - 4
src/test/java/com/example/unusualsounds/UnusualSoundsApplicationTests.java

@@ -273,7 +273,6 @@ class UnusualSoundsApplicationTests {
 
 
         String dirfile = "D:\\file\\ffmpeg\\voiceTest.mp4";
-
         File file = new File(dirfile);
         FileToMultipartFile fileToMultipartFile = new FileToMultipartFile(file);
 
@@ -305,7 +304,8 @@ class UnusualSoundsApplicationTests {
 
     }
 
-
+    @Value(" ${Alarms.imageUrl}")
+    private String imageUrl;
 
     @Test
     public void testJSonMap(){
@@ -325,8 +325,20 @@ class UnusualSoundsApplicationTests {
 //        String str = JSONObject.toJSONString(strings);
 //        System.out.println("str:"+str);
 
-        String str =null;
-        System.out.println("str:"+str !=null);
+
+
+//        String url = "http://10.68.208.94:8077/windmill/store/abnormal-sound/source/print/3629003b6644.jpeg";
+//        String tmpStr = "s3://";
+//        String replaced = url.replaceFirst("https?://[^/]+", "s3:/");
+//        System.out.println("replaced:"+replaced);
+//
+//        String imageUrl = "s3://windmill/store/abnormal-sound/source/print/202504301407.jpeg";
+//        String fileName = imageUrl.replaceFirst("^s3://[^/]+/", "");
+//        System.out.println("fileName:"+fileName);
+
+        String str = imageUrl;
+        System.out.println("str:"+imageUrl.trim());
+        System.out.println("str:"+str);
 
     }