rain
2024-08-17 608dea1f05bb2e33df4df050380fa49602b6c3ff
src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java
@@ -110,7 +110,22 @@
                .eq(MediaFileEntity::getFileId, fileId));
        return Optional.ofNullable(fileEntity);
    }
    public void saveMarkFile(String workspaceId, MediaFileEntity file,File file1) {
        try {
            MediaFileMarkEntity mediaFileMarkEntity= new MediaFileMarkEntity();
            mediaFileMarkEntity.setWorkspaceId(workspaceId);
            mediaFileMarkEntity.setIsadd(0);
            mediaFileMarkEntity.setIsOriginal(false);
            mediaFileMarkEntity.setFileId(UUID.randomUUID().toString());
            mediaFileMarkEntity.setObjectKey("/mark" + file.getFilePath()+ "/" + file.getFileName());
            mediaFileMarkEntity.setFileName("mark" + file.getFileName());
            mediaFileMarkEntity.setFilePath("mark" + file.getFilePath());
            uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), mediaFileMarkEntity.getObjectKey(), file1, "image/jpeg");
            markMapper.insert(mediaFileMarkEntity);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Override
    public Boolean checkExist(String workspaceId, String fingerprint) {
        return this.getMediaByFingerprint(workspaceId, fingerprint).isPresent();
@@ -120,38 +135,29 @@
    public Integer saveFile(String workspaceId, FileUploadDTO file) throws ImageProcessingException, IOException {
        MediaFileEntity fileEntity = this.fileUploadConvertToEntity(file);
        fileEntity.setWorkspaceId(workspaceId);
        fileEntity.setIsadd(0);
        fileEntity.setFileId(UUID.randomUUID().toString());
        String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey();
        File downloadedFile = TbFjServiceImpl.downloadFile(url);
        Object data = ImgUtil.getInfo(downloadedFile);
        fileEntity.setDroneData(data);
        //避免对视频处理引发报错
        if (file.getObjectKey().endsWith("jpeg")){
            fileEntity.setIsadd(0);
            String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey();
            File downloadedFile = TbFjServiceImpl.downloadFile(url);
            Object data = ImgUtil.getInfo(downloadedFile);
            fileEntity.setDroneData(data);
            updateStatue(file.getName());
            saveFiles(workspaceId,file,downloadedFile);
        }
        return mapper.insert(fileEntity);
    }
    public void saveFiles(String workspaceId, FileUploadDTO file) {
    public void saveFiles(String workspaceId, FileUploadDTO file,File mediaFile) {
        // 更新文件状态
        updateStatue(file.getName());
//        updateStatue(file.getName());
        try {
            // 下载文件
            boolean endsWithMp4 = file.getObjectKey().endsWith(".mp4");
            if (endsWithMp4) {
                // 处理视频文件
//            MediaFileZipEntity zipEntity = this.fileUploadConvertToZipEntity(file);
//            zipEntity.setWorkspaceId(workspaceId);
//            zipEntity.setFileId(UUID.randomUUID().toString());
//            zipMapper.insert(zipEntity);
                // 处理视频文件的其他逻辑(如果有)
            } else {
                // 处理图片文件
                String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey();
                File downloadedFile = TbFjServiceImpl.downloadFile(url);
                File nailFile = new File(ImgZipUtil.compressImage(downloadedFile, 50).toURI());
                File nailFile = new File(ImgZipUtil.compressImage(mediaFile, 50).toURI());
                MediaFileNailEntity nailEntity = this.fileUploadConvertToNailEntity(file);
                Object data = ImgUtil.getInfo(downloadedFile);
                nailEntity.setIsadd(0);
                Object data = ImgUtil.getInfo(mediaFile);
//                nailEntity.setIsadd(0);
                nailEntity.setIsOriginal(false);
                nailEntity.setDronedata(data);
                nailEntity.setWorkspaceId(workspaceId);
@@ -162,27 +168,27 @@
                nailEntity.setFileId(UUID.randomUUID().toString());
                // 上传图片文件
//            uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", file.getObjectKey(), downloadedFile, "image/jpeg");
                uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), nailName, nailFile, "image/jpeg");
//            uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", nailName, nailFile, "image/jpeg");
//            uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket",nailName, nailFile, "image/jpeg");
            uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), nailName, nailFile, "image/jpeg");
            uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", nailName, nailFile, "image/jpeg");
                nailMapper.insert(nailEntity);
                // 处理压缩后的图片文件(如果有)
//            File zipFile = new File(ImgZipUtil.compressImageAndGetFile(downloadedFile, 0.5f).toURI());
//            MediaFileZipEntity zipEntity = this.fileUploadConvertToZipEntity(file);
//            zipEntity.setIsOriginal(false);
//            zipEntity.setWorkspaceId(workspaceId);
//            zipEntity.setFileName("zip" + file.getName());
//            zipEntity.setObjectKey("/zip" + file.getPath() + "/" + file.getName());
//            zipEntity.setFilePath("zip" + file.getPath());
//            String zipName = zipEntity.getObjectKey();
//            zipEntity.setFileId(UUID.randomUUID().toString());
            File zipFile = new File(ImgZipUtil.compressImageAndGetFile(mediaFile, 0.5f).toURI());
            MediaFileZipEntity zipEntity = this.fileUploadConvertToZipEntity(file);
            zipEntity.setIsOriginal(false);
            zipEntity.setWorkspaceId(workspaceId);
            zipEntity.setFileName("zip" + file.getName());
            zipEntity.setObjectKey("/zip" + file.getPath() + "/" + file.getName());
            zipEntity.setFilePath("zip" + file.getPath());
            String zipName = zipEntity.getObjectKey();
            zipEntity.setFileId(UUID.randomUUID().toString());
                // 上传压缩文件
//            uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), zipName, zipFile, "image/jpeg");
//            uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", zipName, zipFile, "image/jpeg");
//            zipMapper.insert(zipEntity);
            }
            uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), zipName, zipFile, "image/jpeg");
            uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", zipName, zipFile, "image/jpeg");
            zipMapper.insert(zipEntity);
        } catch (IOException | ImageProcessingException e) {
            // 处理异常
            e.printStackTrace();