|
|
@@ -1,13 +1,11 @@
|
|
|
package com.dji.sample.media.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.io.IoUtil;
|
|
|
import cn.hutool.core.util.ZipUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.dji.sample.common.util.CoordinateUtil;
|
|
|
-import com.dji.sample.common.util.PicExifUtil;
|
|
|
-import com.dji.sample.common.util.ThumbnailatorUtil;
|
|
|
-import com.dji.sample.common.util.UserRequest;
|
|
|
+import com.dji.sample.common.util.*;
|
|
|
import com.dji.sample.component.oss.model.OssConfiguration;
|
|
|
import com.dji.sample.component.oss.service.impl.OssServiceContext;
|
|
|
import com.dji.sample.manage.model.dto.DeviceDictionaryDTO;
|
|
|
@@ -49,6 +47,7 @@ import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.Executor;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -85,6 +84,9 @@ public class FileServiceImpl implements IFileService {
|
|
|
@Autowired
|
|
|
private IGroupService groupService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private Executor threadPool;
|
|
|
+
|
|
|
private static final String IMAGE = "image";
|
|
|
private static final String VIDEO = "video";
|
|
|
private static final String TAIL = "_100x100";
|
|
|
@@ -168,13 +170,61 @@ public class FileServiceImpl implements IFileService {
|
|
|
|
|
|
@Override
|
|
|
public Integer saveFile(String workspaceId, MediaUploadCallbackRequest file) {
|
|
|
+ //保存基本信息
|
|
|
MediaFileEntity fileEntity = this.fileUploadConvertToEntity(workspaceId,file);
|
|
|
fileEntity.setWorkspaceId(workspaceId);
|
|
|
fileEntity.setFileId(UUID.randomUUID().toString());
|
|
|
int result = mapper.insert(fileEntity);
|
|
|
+ //更新exif信息
|
|
|
+ updateExifInfo(fileEntity,workspaceId,file);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ private void updateExifInfo(MediaFileEntity fileEntity, String workspaceId, MediaUploadCallbackRequest file) {
|
|
|
+ //生成缩略图
|
|
|
+ threadPool.execute(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ String objectKey = file.getObjectKey();
|
|
|
+
|
|
|
+ //生成缩略图
|
|
|
+ String tObjectKey = getThumbnailObjectKey(file.getName());
|
|
|
+ putThumbnailImage(tObjectKey, objectKey, true);
|
|
|
+
|
|
|
+ //获取图片信息
|
|
|
+ MediaExifDTO exif = PicExifUtil.getPicExif(objectKey);
|
|
|
+
|
|
|
+ if (file != null) {
|
|
|
+ fileEntity.setImageWidth(exif.getImageWidth());
|
|
|
+ fileEntity.setImageHeight(exif.getImageHeight());
|
|
|
+ fileEntity.setXResolution(exif.getXResolution());
|
|
|
+ fileEntity.setYResolution(exif.getYResolution());
|
|
|
+ fileEntity.setLatitude(BigDecimal.valueOf(CoordinateUtil.checkValidVal(exif.getLatitude())).setScale(14, RoundingMode.DOWN));
|
|
|
+ fileEntity.setLongitude(BigDecimal.valueOf(CoordinateUtil.checkValidVal(exif.getLongitude())).setScale(14, RoundingMode.DOWN));
|
|
|
+ fileEntity.setLongitudeRef(exif.getLongitudeRef());
|
|
|
+ fileEntity.setLatitudeRef(exif.getLatitudeRef());
|
|
|
+ fileEntity.setMediaType(exif.getPictureType());
|
|
|
+ fileEntity.setPictureType(exif.getPictureType());
|
|
|
+ fileEntity.setDurationSeconds(exif.getDurationSeconds());
|
|
|
+
|
|
|
+ mapper.update(fileEntity,
|
|
|
+ new LambdaUpdateWrapper<MediaFileEntity>().eq(MediaFileEntity::getFileId, fileEntity.getFileId()));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private InputStream copyInputStream(InputStream input) {
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
+ IoUtil.copy(input,output);
|
|
|
+ return new ByteArrayInputStream(output.toByteArray());
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<MediaFileDTO> getAllFilesByWorkspaceId(String workspaceId) {
|
|
|
return mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>()
|
|
|
@@ -293,7 +343,8 @@ public class FileServiceImpl implements IFileService {
|
|
|
private MediaFileEntity fileUploadConvertToEntity(String workspaceId, MediaUploadCallbackRequest file) {
|
|
|
//通过path 获取航线名称,文件夹名称
|
|
|
String waylineName = getWaylineName(file.getPath());
|
|
|
- String dirName = getDirName(waylineName, file.getPath());
|
|
|
+// String dirName = getDirName(waylineName, file.getPath());
|
|
|
+ String dirName = file.getPath();
|
|
|
MediaDirDTO dirDto = null;
|
|
|
synchronized(dirName.intern()) {
|
|
|
dirDto = mediaDirService.getMediaDirByName(workspaceId, dirName, null);
|
|
|
@@ -313,51 +364,48 @@ public class FileServiceImpl implements IFileService {
|
|
|
}
|
|
|
dirDto = mediaDirService.createDir(dirBuilder.build());
|
|
|
}
|
|
|
- }
|
|
|
- //生成缩略图
|
|
|
- String tObjectKey = getThumbnailObjectKey(file.getName());
|
|
|
- putThumbnailImage(tObjectKey,file.getObjectKey(),true);
|
|
|
|
|
|
- MediaFileEntity.MediaFileEntityBuilder builder = MediaFileEntity.builder();
|
|
|
|
|
|
- if (file != null) {
|
|
|
- //获取图片信息
|
|
|
- MediaExifDTO exif = PicExifUtil.getPicExif(file.getObjectKey());
|
|
|
-
|
|
|
- //经纬度转换
|
|
|
- //AMap aMap = CoordinateUtil.transform(file.getMetadata().getShootPosition().getLng(),file.getMetadata().getShootPosition().getLat());
|
|
|
- //AMap aMap = CoordinateUtil.transform(exif.getLongitude(),exif.getLatitude());
|
|
|
- builder.fileName(file.getName())
|
|
|
- .filePath(file.getPath())
|
|
|
- .fingerprint(file.getFingerprint())
|
|
|
- .objectKey(file.getObjectKey())
|
|
|
- .subFileType(Optional.ofNullable(file.getSubFileType()).map(MediaSubFileTypeEnum::getType).orElse(null))
|
|
|
- .isOriginal(file.getExt().getOriginal())
|
|
|
- .jobId(file.getExt().getFileGroupId())
|
|
|
- .drone(file.getExt().getSn())
|
|
|
- .tinnyFingerprint(file.getExt().getTinnyFingerprint())
|
|
|
- .payload(getDeviceNameByModelKey(file.getExt().getPayloadModelKey()))
|
|
|
- .dirId(dirDto.getId())
|
|
|
- .waylineName(waylineName)
|
|
|
- .imageWidth(exif.getImageWidth())
|
|
|
- .imageHeight(exif.getImageHeight())
|
|
|
- .xResolution(exif.getXResolution())
|
|
|
- .yResolution(exif.getYResolution())
|
|
|
- .latitude(BigDecimal.valueOf(CoordinateUtil.checkValidVal(exif.getLatitude())).setScale(14, RoundingMode.DOWN))
|
|
|
- .longitude( BigDecimal.valueOf(CoordinateUtil.checkValidVal(exif.getLongitude())).setScale(14, RoundingMode.DOWN))
|
|
|
- .absoluteAltitude(BigDecimal.valueOf(CoordinateUtil.checkValidVal(file.getMetadata().getAbsoluteAltitude())).setScale(6, RoundingMode.DOWN))
|
|
|
- .relativeAltitude(BigDecimal.valueOf(CoordinateUtil.checkValidVal(file.getMetadata().getRelativeAltitude())).setScale(6, RoundingMode.DOWN))
|
|
|
- .size(ossService.getObjectSize(OssConfiguration.bucket, file.getObjectKey()))
|
|
|
- .pictureTime(file.getMetadata().getCreatedTime() != null ? file.getMetadata().getCreatedTime().atZone(ZoneId.of("UTC+0")).toInstant().toEpochMilli() : null)
|
|
|
- .longitudeRef(exif.getLongitudeRef())
|
|
|
- .latitudeRef(exif.getLatitudeRef())
|
|
|
- .mediaType(exif.getPictureType())
|
|
|
- .pictureType(exif.getPictureType())
|
|
|
- .durationSeconds(exif.getDurationSeconds())
|
|
|
- .taskName(dirDto.getDirName())//先取远程计划任务名称,没有就取文件夹名称
|
|
|
- ;
|
|
|
+ MediaFileEntity.MediaFileEntityBuilder builder = MediaFileEntity.builder();
|
|
|
+
|
|
|
+ if (file != null) {
|
|
|
+
|
|
|
+
|
|
|
+ //经纬度转换
|
|
|
+ //AMap aMap = CoordinateUtil.transform(file.getMetadata().getShootPosition().getLng(),file.getMetadata().getShootPosition().getLat());
|
|
|
+ //AMap aMap = CoordinateUtil.transform(exif.getLongitude(),exif.getLatitude());
|
|
|
+ builder.fileName(file.getName())
|
|
|
+ .filePath(file.getPath())
|
|
|
+ .fingerprint(file.getFingerprint())
|
|
|
+ .objectKey(file.getObjectKey())
|
|
|
+ .subFileType(Optional.ofNullable(file.getSubFileType()).map(MediaSubFileTypeEnum::getType).orElse(null))
|
|
|
+ .isOriginal(file.getExt().getOriginal())
|
|
|
+ .jobId(file.getExt().getFileGroupId())
|
|
|
+ .drone(file.getExt().getSn())
|
|
|
+ .tinnyFingerprint(file.getExt().getTinnyFingerprint())
|
|
|
+ .payload(getDeviceNameByModelKey(file.getExt().getPayloadModelKey()))
|
|
|
+ .dirId(dirDto.getId())
|
|
|
+ .waylineName(waylineName)
|
|
|
+// .imageWidth(exif.getImageWidth())
|
|
|
+// .imageHeight(exif.getImageHeight())
|
|
|
+// .xResolution(exif.getXResolution())
|
|
|
+// .yResolution(exif.getYResolution())
|
|
|
+// .latitude(BigDecimal.valueOf(CoordinateUtil.checkValidVal(exif.getLatitude())).setScale(14, RoundingMode.DOWN))
|
|
|
+// .longitude(BigDecimal.valueOf(CoordinateUtil.checkValidVal(exif.getLongitude())).setScale(14, RoundingMode.DOWN))
|
|
|
+ .absoluteAltitude(BigDecimal.valueOf(CoordinateUtil.checkValidVal(file.getMetadata().getAbsoluteAltitude())).setScale(6, RoundingMode.DOWN))
|
|
|
+ .relativeAltitude(BigDecimal.valueOf(CoordinateUtil.checkValidVal(file.getMetadata().getRelativeAltitude())).setScale(6, RoundingMode.DOWN))
|
|
|
+ .size(ossService.getObjectSize(OssConfiguration.bucket, file.getObjectKey()))
|
|
|
+ .pictureTime(file.getMetadata().getCreatedTime() != null ? file.getMetadata().getCreatedTime().atZone(ZoneId.of("UTC+0")).toInstant().toEpochMilli() : null)
|
|
|
+// .longitudeRef(exif.getLongitudeRef())
|
|
|
+// .latitudeRef(exif.getLatitudeRef())
|
|
|
+// .mediaType(exif.getPictureType())
|
|
|
+// .pictureType(exif.getPictureType())
|
|
|
+// .durationSeconds(exif.getDurationSeconds())
|
|
|
+ .taskName(dirDto.getDirName())//先取远程计划任务名称,没有就取文件夹名称
|
|
|
+ ;
|
|
|
+ }
|
|
|
+ return builder.build();
|
|
|
}
|
|
|
- return builder.build();
|
|
|
}
|
|
|
|
|
|
private String getDeviceNameByModelKey(DeviceEnum modelKey) {
|
|
|
@@ -459,21 +507,17 @@ public class FileServiceImpl implements IFileService {
|
|
|
String originFileName = entity.getFileName();
|
|
|
//缩略图路径
|
|
|
String tObjectKey = getThumbnailObjectKey(originFileName);
|
|
|
-// if(!putThumbnailImage(tObjectKey,entity.getObjectKey(),false)) {
|
|
|
-// return null;
|
|
|
-// }
|
|
|
return ossService.getObjectUrl(OssConfiguration.bucket, tObjectKey).toString();
|
|
|
|
|
|
}
|
|
|
|
|
|
private boolean putThumbnailImage(String tObjectKey, String originObjectKey,boolean toCreate) {
|
|
|
- if(originObjectKey.endsWith(PicExifUtil.MP4)) {
|
|
|
- System.out.println(originObjectKey);
|
|
|
- }
|
|
|
//生成缩略图
|
|
|
if(!ossService.objectExists(OssConfiguration.bucket,tObjectKey)) {
|
|
|
if(toCreate) {
|
|
|
- BufferedImage bufferedImage = ThumbnailatorUtil.getThumbnail(originObjectKey, 100, 100);
|
|
|
+ System.out.println("======生成缩略图开始======:" + originObjectKey);
|
|
|
+ URL url = ossService.getObjectUrl(OssConfiguration.bucket, originObjectKey);
|
|
|
+ BufferedImage bufferedImage = ThumbnailatorUtil.getThumbnail(originObjectKey, url,100, 100);
|
|
|
if (bufferedImage != null) {
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
try {
|
|
|
@@ -483,6 +527,7 @@ public class FileServiceImpl implements IFileService {
|
|
|
}
|
|
|
ossService.putObject(OssConfiguration.bucket, tObjectKey, new ByteArrayInputStream(outputStream.toByteArray()));
|
|
|
}
|
|
|
+ System.out.println("======生成缩略图结束======:" + originObjectKey);
|
|
|
} else {
|
|
|
return false;
|
|
|
}
|