|
@@ -25,10 +25,16 @@ 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 io.minio.ListObjectsArgs;
|
|
|
+import io.minio.MinioClient;
|
|
|
+import io.minio.RemoveObjectArgs;
|
|
|
+import io.minio.Result;
|
|
|
+import io.minio.messages.Item;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
@@ -38,6 +44,7 @@ import javax.annotation.Resource;
|
|
|
import java.io.*;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.ZonedDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
@@ -100,6 +107,15 @@ public class CameraUtil {
|
|
|
@Autowired
|
|
|
CameraLogDetailService cameraLogDetailService;
|
|
|
|
|
|
+ @Value("${minio.endpoint}")
|
|
|
+ private String endpoint;
|
|
|
+ @Value("${minio.accessKey}")
|
|
|
+ private String accessKey;
|
|
|
+ @Value("${minio.secretKey}")
|
|
|
+ private String secretKey;
|
|
|
+ @Value("${minio.bucketName}")
|
|
|
+ private String bucketName;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 历史回放
|
|
@@ -991,6 +1007,72 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public void removePrice(){
|
|
|
+ try {
|
|
|
+ // 创建MinioClient对象
|
|
|
+ MinioClient minioClient = MinioClient.builder()
|
|
|
+ .endpoint(endpoint)
|
|
|
+ .credentials(accessKey, secretKey)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ // 指定要删除文件的桶名和目录名
|
|
|
+ String bucketName = this.bucketName;
|
|
|
+ String prefix = "/camera_picture/normal/";
|
|
|
+
|
|
|
+ // 指定要删除的时间点(此处为当前时间之前的时间)
|
|
|
+ ZonedDateTime deleteTime = ZonedDateTime.now().minusDays(20); // 删除30天前的文件
|
|
|
+
|
|
|
+ // 递归删除指定目录下的所有文件和空目录
|
|
|
+ deleteObjectsAndEmptyDirectoriesRecursively(minioClient, bucketName, prefix, deleteTime);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("Error occurred: " + e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void deleteObjectsAndEmptyDirectoriesRecursively(MinioClient minioClient, String bucketName, String prefix, ZonedDateTime deleteTime) throws Exception{
|
|
|
+ log.info("----bucketName----"+bucketName);
|
|
|
+ log.info("----prefix----"+prefix);
|
|
|
+ log.info("----deleteTime----"+deleteTime);
|
|
|
+ Iterable<Result<Item>> results = minioClient.listObjects(ListObjectsArgs.builder()
|
|
|
+ .bucket(bucketName)
|
|
|
+ .prefix(prefix)
|
|
|
+ .recursive(true)
|
|
|
+ .build());
|
|
|
+
|
|
|
+ boolean hasFiles = false;
|
|
|
+ log.info("----results----"+results);
|
|
|
+ for (Result<Item> result : results) {
|
|
|
+ Item item = result.get();
|
|
|
+
|
|
|
+ // 如果是文件且在指定时间之前,则删除文件
|
|
|
+ log.info("----item.lastModified()----"+item.lastModified());
|
|
|
+ log.info("----NoDeleted----"+item.objectName());
|
|
|
+ if (!item.isDir() && item.lastModified().isBefore(deleteTime)) {
|
|
|
+ minioClient.removeObject(RemoveObjectArgs.builder()
|
|
|
+ .bucket(bucketName)
|
|
|
+ .object(item.objectName())
|
|
|
+ .build());
|
|
|
+ log.info("Deleted: " + item.objectName());
|
|
|
+ hasFiles = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果是目录,则递归删除目录下的文件和空目录
|
|
|
+ if (item.isDir()) {
|
|
|
+ deleteObjectsAndEmptyDirectoriesRecursively(minioClient, bucketName, item.objectName(), deleteTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果目录下没有文件且不是根目录,则删除该目录
|
|
|
+ if (!hasFiles && !prefix.isEmpty()) {
|
|
|
+ minioClient.removeObject(RemoveObjectArgs.builder()
|
|
|
+ .bucket(bucketName)
|
|
|
+ .object(prefix)
|
|
|
+ .build());
|
|
|
+ log.info("Deleted directory: " + prefix);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
// // 创建一个集合
|