Browse Source

媒体文件排序优化

S0025136190 1 year ago
parent
commit
8b48633981

+ 8 - 5
Backend/sample/src/main/java/com/dji/sample/common/util/PicExifUtil.java

@@ -114,9 +114,12 @@ public class PicExifUtil {
                 if(exifIFD0Directory != null) {
                     builder.imageWidth(exifSubIFDDirectory.getInteger(ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH));
                     builder.imageHeight(exifSubIFDDirectory.getInteger(ExifSubIFDDirectory.TAG_EXIF_IMAGE_HEIGHT));
+                    //拍摄时间
+                    builder.createTime(exifSubIFDDirectory.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL).getTime());
                 } else {
                     log.info("============图片未获取到宽高 ");
                 }
+
             }
             //媒体类型
             FileTypeDirectory fileTypeDirectory = metadata.getFirstDirectoryOfType(FileTypeDirectory.class);
@@ -137,9 +140,9 @@ public class PicExifUtil {
         return null;
     }
 
-//    public static void main(String[] args) throws FileNotFoundException {
-//        String filePath = "C:\\Users\\86139\\Desktop\\DJI_20241024142543_0008_V.jpeg";
-//        File file = new File(filePath);
-//        getPicExif(new FileInputStream(file),false);
-//    }
+    public static void main(String[] args) throws FileNotFoundException {
+        String filePath = "C:\\Users\\86139\\Desktop\\DJI_20241024142543_0008_V.jpeg";
+        File file = new File(filePath);
+        getPicExif(new FileInputStream(file),false);
+    }
 }

+ 4 - 1
Backend/sample/src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java

@@ -247,6 +247,9 @@ public class FileServiceImpl implements IFileService {
                         if(exif.getSubFileType() == MediaSubFileTypeEnum.PANORAMA.getType()) {
                             fileEntity.setSubFileType(MediaSubFileTypeEnum.PANORAMA.getType());
                         }
+                        if(exif.getCreateTime() != null) {
+                            fileEntity.setPictureTime(exif.getCreateTime());
+                        }
 
                         mapper.update(fileEntity,
                                 new LambdaUpdateWrapper<MediaFileEntity>().eq(MediaFileEntity::getFileId, fileEntity.getFileId()));
@@ -347,7 +350,7 @@ public class FileServiceImpl implements IFileService {
                                 wrapper -> wrapper.like( MediaFileEntity::getFileName, param.getSearchInfo())
                                         .or().like( MediaFileEntity::getPayload, param.getSearchInfo())
                         )
-                        .orderByDesc(MediaFileEntity::getId));
+                        .orderByDesc(MediaFileEntity::getPictureTime));
         List<MediaFileDTO> records = pageData.getRecords()
                 .stream()
                 .map(this::entityConvertToDto)