|
@@ -12,6 +12,7 @@ import java.io.PrintWriter;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.ZonedDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
@@ -28,8 +29,14 @@ import java.util.stream.Collectors;
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
+import io.minio.ListObjectsArgs;
|
|
|
+import io.minio.MinioClient;
|
|
|
+import io.minio.RemoveObjectArgs;
|
|
|
+import io.minio.Result;
|
|
|
+import io.minio.messages.Item;
|
|
|
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;
|
|
@@ -120,6 +127,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;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 历史回放
|
|
@@ -1018,6 +1034,71 @@ 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 = "/data/tools/minio/data/picbucket/camera_picture/";
|
|
|
+
|
|
|
+ // 指定要删除的时间点(此处为当前时间之前的时间)
|
|
|
+ ZonedDateTime deleteTime = ZonedDateTime.now().minusDays(30); // 删除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());
|
|
|
+ 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) {
|
|
|
|
|
|
// // 创建一个集合
|