rain
2024-07-23 636b54a1e782c2662d6163269093da7d5368664e
更新媒体文件存入,将源文件、水印文件、缩略图分离
7 files modified
157 ■■■■■ changed files
src/main/java/com/dji/sample/media/service/IFileService.java 9 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java 79 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/media/service/impl/MediaServiceImpl.java 5 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/media/util/ImgUtil.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/service/impl/GetPatchesServiceImpl.java 9 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/territory/service/impl/TbFjServiceImpl.java 42 ●●●●● patch | view | raw | blame | history
src/main/resources/application-dev.yml 8 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/media/service/IFileService.java
@@ -38,15 +38,6 @@
     */
    Integer saveFile(String workspaceId, FileUploadDTO file) throws IOException, ImageProcessingException;
    /**
     * 存储水印图片
     * @param workspaceId
     * @param file
     * @throws IOException
     * @throws FontFormatException
     * @throws ImageProcessingException
     */
    void saveMarkFile(String workspaceId, FileUploadDTO file) throws IOException, FontFormatException, ImageProcessingException;
    void updateMarkMediaFileNames(String jobId);
    PaginationData<MediaFileEntity> getJobId( int pageNum, int pageSize,String workspaceId);
    PaginationData<MediaFileEntity> getPhotoByJobId(int page,int pageSize ,String workspaceId,String jobId);
src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java
@@ -116,16 +116,25 @@
        MediaFileEntity fileEntity = this.fileUploadConvertToEntity(file);
        fileEntity.setWorkspaceId(workspaceId);
        fileEntity.setFileId(UUID.randomUUID().toString());
        if (!file.getObjectKey().endsWith(".mp4")){
        int count=mapper.insert(fileEntity);
        String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey();
        updateStatue(file.getName());
        if (!file.getObjectKey().endsWith(".mp4")){
        File file1 = TbFjServiceImpl.downloadFile(url);
        saveNailFile(workspaceId,file,file1);
        Object data = ImgUtil.getInfo(file1);
        fileEntity.setDroneData(data);
        file1.delete();
        }
        return mapper.insert(fileEntity);
        else {
            File file1 = TbFjServiceImpl.downloadFile(url);
            saveNailFile(workspaceId,file,file1);
            file1.delete();
        }
        return count;
    }
    public void saveMarkFile(String workspaceId, FileUploadDTO file) throws IOException {
    public void saveNailFile(String workspaceId,FileUploadDTO file,File file1) throws IOException {
        boolean endsWith = file.getObjectKey().endsWith(".mp4");
        if (endsWith) {
            MediaFileNailEntity nailEntity = this.fileUploadConvertToNailEntity((file));
@@ -133,12 +142,6 @@
            nailEntity.setFileId(UUID.randomUUID().toString());
            nailMapper.insert(nailEntity);
        } else {
            String endpoint = pojo.getEndpoint();
            String accessKey = pojo.getAccessKey();
            String secretKey = pojo.getSecretKey();
            String bucketName = pojo.getBucket();
            String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey();
            File file1 = TbFjServiceImpl.downloadFile(url);
            File nailFile = new File(ImgZipUtil.compressImage(file1, 50).toURI());
            MediaFileNailEntity nailEntity = this.fileUploadConvertToNailEntity(file);
            nailEntity.setIsOriginal(false);
@@ -148,42 +151,24 @@
            nailEntity.setFilePath("nail" + file.getPath());
            String nailName = nailEntity.getObjectKey();
            nailEntity.setFileId(UUID.randomUUID().toString());
            uploadFile(endpoint, accessKey, secretKey, bucketName, nailName, nailFile, "image/jpeg");
            uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), nailName, nailFile, "image/jpeg");
            nailMapper.insert(nailEntity);
            try {
                if (file.getName().contains("~")) {
                    String name = TimerUtil.getDkbh(file.getName());
                    List<LotInfo> lotInfos = patchesMapper.selectList(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getDkbh, name));
                    if (!lotInfos.isEmpty()) {
                        LambdaUpdateWrapper<LotInfo> updateWrapper = new LambdaUpdateWrapper<>();
                        updateWrapper.eq(LotInfo::getDkbh, name)
                                .eq(LotInfo::getInvestigate, 0)
                                .set(LotInfo::getInvestigate, 1);
                        patchesMapper.update(null, updateWrapper);
                    }
                }
                MediaFileMarkEntity mediaFileMarkEntity = this.fileUploadConvertToMarkEntity(file);
                long timestamp = convertToTimestamp(file.getMetadata().getCreatedTime());
                File markFile = new File(WaterMarkUtil.addWatermark(file1, timestamp, file.getMetadata().getShootPosition().getLat(),
                        file.getMetadata().getShootPosition().getLng(), file.getMetadata().getGimbalYawDegree()).toURI());
                Object data = ImgUtil.getInfo(file1);
                mediaFileMarkEntity.setDronedata(data);
                mediaFileMarkEntity.setWorkspaceId(workspaceId);
                mediaFileMarkEntity.setIsadd(0);
                mediaFileMarkEntity.setIsOriginal(false);
                mediaFileMarkEntity.setFileId(UUID.randomUUID().toString());
                mediaFileMarkEntity.setObjectKey("/mark" + file.getPath() + "/" + file.getName());
                mediaFileMarkEntity.setFileName("mark" + file.getName());
                mediaFileMarkEntity.setFilePath("mark" + file.getPath());
                String objectName = mediaFileMarkEntity.getObjectKey(); // 例如 "folder/file.txt"
                uploadFile(endpoint, accessKey, secretKey, bucketName, objectName, markFile, "image/jpeg");
                markMapper.insert(mediaFileMarkEntity);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public void updateStatue(String filename) {
        if (filename.contains("~")) {
            String name = TimerUtil.getDkbh(filename);
            List<LotInfo> lotInfos = patchesMapper.selectList(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getDkbh, name));
            if (!lotInfos.isEmpty()) {
                LambdaUpdateWrapper<LotInfo> updateWrapper = new LambdaUpdateWrapper<>();
                updateWrapper.eq(LotInfo::getDkbh, name)
                        .eq(LotInfo::getInvestigate, 0)
                        .set(LotInfo::getInvestigate, 1);
                patchesMapper.update(null, updateWrapper);
            }
        }
    }
    @Override
    public Object mediaInfo(String filename) {
        String name = filename;
@@ -436,16 +421,11 @@
    public ResponseResult downloadImages(List<String> jobIds) {
        try {
            String bucketPath = "/data/software/minio-data/cloud-bucket/";
            List<String> prefixes = getUniqueFilePaths(jobIds);
            // List<String> prefixes = getUniqueFilePaths(jobIds);
            MinioFileDownloader downloader = new MinioFileDownloader(bucketPath);
            // 下载并压缩文件到本地目录
            String localSaveDir = "/data/software/minio-data/zip-bucket/"; // 修改为你想保存的本地目录
            downloader.downloadAndZipFolders(prefixes, localSaveDir);
            System.out.println("压缩文件已保存到:" + localSaveDir);
            downloader.downloadAndZipFolders(jobIds, localSaveDir);
        }  catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.error("下载失败"+e.getMessage());
@@ -524,6 +504,7 @@
        if (file != null) {
            builder.fileName(file.getName())
                    .filePath(file.getPath())
                    .fingerprint(file.getFingerprint())
                    .objectKey(file.getObjectKey())
                    .subFileType(file.getSubFileType())
@@ -553,6 +534,7 @@
                    .objectKey(file.getObjectKey())
                    .subFileType(file.getSubFileType())
                    .isOriginal(file.getExt().getIsOriginal())
                    .filePath(file.getPath())
                    .jobId(file.getExt().getFlightId())
                    .drone(file.getExt().getSn()).metadata(file.getMetadata())
                    .tinnyFingerprint(file.getExt().getTinnyFingerprint());
@@ -598,7 +580,6 @@
        return builder.build();
    }
    public static void uploadFile(String endpoint, String accessKey, String secretKey, String bucketName, String objectName, File file, String type) {
        try {
            // 创建MinIO客户端实例
src/main/java/com/dji/sample/media/service/impl/MediaServiceImpl.java
@@ -226,10 +226,7 @@
        // set path
        String objectKey = callback.getFile().getObjectKey();
        callback.getFile().setPath(objectKey.substring(objectKey.indexOf("/") + 1, objectKey.lastIndexOf("/")));
        int count =fileService.saveFile(job.getWorkspaceId(), callback.getFile());
        fileService.saveMarkFile(job.getWorkspaceId(), callback.getFile());
        return count > 0;
        return fileService.saveFile(job.getWorkspaceId(), callback.getFile()) > 0;
    }
    /**
src/main/java/com/dji/sample/media/util/ImgUtil.java
@@ -112,9 +112,4 @@
        return newJsonObject;
    }
    public static void main(String[] args) throws ImageProcessingException, IOException {
        File file1 = TbFjServiceImpl.downloadFile("http://dev.jxpskj.com:9000/cloud-bucket/05708dc5-4273-4b12-ad54-e05c89d6c3d4/DJI_202406031131_010_05708dc5-4273-4b12-ad54-e05c89d6c3d4/DJI_20240603113305_0001_W_航点1.jpeg");
        System.out.println(getInfo(file1));
    }
}
src/main/java/com/dji/sample/patches/service/impl/GetPatchesServiceImpl.java
@@ -100,7 +100,8 @@
        if (statue == 1) {
            List<MediaFileMarkEntity> allResults = markMapper.selectList(
                    new LambdaQueryWrapper<MediaFileMarkEntity>().like(MediaFileMarkEntity::getFileName, "%" + dkbh + "~" + "%"));
                    new LambdaQueryWrapper<MediaFileMarkEntity>()
                            .like(MediaFileMarkEntity::getFileName, "%" + dkbh + "~" + "%"));
            // 去重处理
            Map<String, MediaFileMarkEntity> uniqueFileMap = new LinkedHashMap<>();
@@ -125,7 +126,8 @@
            return new PaginationData<>(pageResults, new Pagination(resultPage));
        } else {
            List<MediaFileEntity> allResults = fileMapper.selectList(
                    new LambdaQueryWrapper<MediaFileEntity>().like(MediaFileEntity::getFileName, "%" + dkbh + "~" + "%"));
                    new LambdaQueryWrapper<MediaFileEntity>()
                            .like(MediaFileEntity::getFileName, "%" + dkbh + "~" + "%"));
            // 去重处理
            Map<String, MediaFileEntity> uniqueFileMap = new LinkedHashMap<>();
@@ -155,7 +157,8 @@
    public List<MediaFileEntity> listPohto(String dkbh, String workspaceId) {
        return fileMapper.selectList(new LambdaQueryWrapper<MediaFileEntity>().like(MediaFileEntity::getFileName, "%" + dkbh + "%")
                .eq(MediaFileEntity::getWorkspaceId, workspaceId));
                .eq(MediaFileEntity::getWorkspaceId, workspaceId)
                .eq(MediaFileEntity::getExamine,1));
    }
    public LotInfo getLotinfo(String dkbh, String workspaceId) {
        return mapper.selectOne(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getDkbh, dkbh)
src/main/java/com/dji/sample/territory/service/impl/TbFjServiceImpl.java
@@ -3,7 +3,8 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.dji.sample.media.model.MediaFileEntity;
import com.dji.sample.media.dao.IMarkMapper;
import com.dji.sample.media.model.*;
import com.dji.sample.media.util.ImgUtil;
import com.dji.sample.patches.config.pojo.PatchesConfigPojo;
import com.dji.sample.patches.model.entity.LotInfo;
@@ -12,38 +13,27 @@
import com.dji.sample.territory.pojo.TerritoryConfigPojo;
import com.dji.sample.territory.service.ITbFJService;
import com.dji.sample.territory.utils.*;
import com.dji.sample.territory.utils.jym.SM2SignVO;
import com.dji.sample.territory.utils.jym.SM2SignVerUtils;
import com.dji.sample.territory.utils.jym.Util;
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.imageio.ImageIO;
import javax.xml.crypto.Data;
import java.awt.image.BufferedImage;
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import static com.dji.sample.territory.utils.CoordinateSystemUtil.*;
import static com.dji.sample.territory.utils.SM2SignUtil.getSM2PrivateKey;
import static com.dji.sample.territory.utils.SM2SignUtil.signWithSM2;
import static com.dji.sample.territory.utils.SM3.addJym;
import static com.dji.sample.media.service.impl.FileServiceImpl.uploadFile;
import static com.dji.sample.territory.utils.SM3.sm3;
@Service
@@ -55,7 +45,10 @@
    private PatchesConfigPojo patchesConfigPojo;
    @Autowired
    private TerritoryConfigPojo territoryConfigPojo;
    @Autowired
    private MinioPojo pojo;
    @Autowired
    private IMarkMapper markMapper;
    /**
     * 按照地块编号所对应的信息和音视频文件存入sqlite数据库
     *
@@ -111,6 +104,9 @@
        JSONObject shootPosition = jsonObject.getJSONObject("shootPosition");
        Double lat = shootPosition.getDouble("lat");
        Double lng = shootPosition.getDouble("lng");
        PositionDTO position=new PositionDTO();
        position.setLat(lat);
        position.setLng(lng);
//        double[] coordinates = extractCoordinates(pointWGStoCGCS(lng, lat));
//        double x = Double.parseDouble(((formatCoordinate(coordinates[1]))));
//        double y = Double.parseDouble(((formatCoordinate(coordinates[0]))));
@@ -149,6 +145,7 @@
            byte[] bytesArray = Files.readAllBytes(file1.toPath());
            fjhxz= sm3(bytesArray);
            FJ = fileToByteArray(file1);
            saveMarkFile(lotInfo.getWorkspaceId(),mediaFile,file1);
        } else {
            file1 = VideoZipUtil.compressVideo(file, 800000, 128000, 1280, 720);
            FJ = fileToByteArray(file1);
@@ -186,6 +183,7 @@
//        else {
////            throw new IllegalArgumentException("未匹配到相关地块");
//        }
        file.delete();
        return builder.build();
    }
@@ -231,6 +229,22 @@
        fis.close();
        return data;
    }
    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();
        }
    }
    public static String convertTimestampToDateTime(long timestamp) {
        // 将时间戳转换为 Instant 对象
src/main/resources/application-dev.yml
@@ -85,10 +85,10 @@
oss:
  enable: true
  provider: minio
  endpoint: http://dev.jxpskj.com:9000
  external-endpoint: http://dev.jxpskj.com:9000
  access-key: pskj
  secret-key: pskj@2021
  endpoint: http://139.196.74.78:9000
  external-endpoint: http://139.196.74.78:9000
  access-key: sxkj
  secret-key: sxkj2024
  bucket: cloud-bucket
  expire: 3600
  region: us-east-1