rain
2024-06-14 8d9a2d656e4ae007590c622e5f7c228adacdca49
src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java
@@ -2,10 +2,12 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dji.sample.common.model.Pagination;
import com.dji.sample.common.model.PaginationData;
import com.dji.sample.common.model.ResponseResult;
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;
@@ -16,8 +18,10 @@
import com.dji.sample.media.model.*;
import com.dji.sample.media.service.IFileService;
import com.dji.sample.media.util.ImgUtil;
import com.dji.sample.patches.dao.GetPatchesMapper;
import com.dji.sample.patches.model.entity.LotInfo;
import com.dji.sample.patches.utils.TimerUtil;
import com.dji.sample.territory.service.impl.TbFjServiceImpl;
import com.dji.sample.territory.utils.VideoZipUtil;
import com.dji.sample.territory.utils.WaterMarkUtil;
import com.drew.imaging.ImageProcessingException;
import io.minio.MinioClient;
@@ -52,8 +56,9 @@
    @Autowired
    private IMarkMapper markMapper;
    @Autowired
    private GetPatchesMapper patchesMapper;
    @Autowired
    private IDeviceDictionaryService deviceDictionaryService;
    @Autowired
    private OssServiceContext ossService;
@@ -84,37 +89,55 @@
        return mapper.insert(fileEntity);
    }
    public Integer saveMarkFile(String workspaceId, FileUploadDTO file) throws IOException, FontFormatException, ImageProcessingException {
        File file2 = null;
        MediaFileMarkEntity mediaFileMarkEntity = this.fileUploadConvertToMarkEntity(file);
        String url = "http://dev.jxpskj.com:9000/cloud-bucket" + file.getObjectKey();
        File file1 = TbFjServiceImpl.downloadFile(url);
        long timestamp = convertToTimestamp(file.getMetadata().getCreatedTime());
    public void saveMarkFile(String workspaceId, FileUploadDTO file) throws IOException, FontFormatException, ImageProcessingException {
        boolean endsWith = file.getObjectKey().endsWith(".mp4");
        if (!endsWith) {
            file2 = new File(WaterMarkUtil.addWatermark(file1, timestamp, file.getMetadata().getShootPosition().getLat(),
        if (endsWith) {
            MediaFileMarkEntity mediaFileMarkEntity = this.fileUploadConvertToMarkEntity(file);
            mediaFileMarkEntity.setWorkspaceId(workspaceId);
            mediaFileMarkEntity.setFileId(UUID.randomUUID().toString());
            markMapper.insert(mediaFileMarkEntity);
        } else {
            boolean contains = file.getName().contains("~");
            if (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);
            String url = "http://dev.jxpskj.com:9000/cloud-bucket" + file.getObjectKey();
            File file1 = TbFjServiceImpl.downloadFile(url);
            long timestamp = convertToTimestamp(file.getMetadata().getCreatedTime());
            File file2 = 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.setFileId(UUID.randomUUID().toString());
            mediaFileMarkEntity.setObjectKey("/mark" + file.getPath() + "/" + file.getName());
            mediaFileMarkEntity.setFileName("mark" + file.getName());
            mediaFileMarkEntity.setFilePath("mark" + file.getPath());
            String endpoint = "http://dev.jxpskj.com:9000";
            String accessKey = "pskj";
            String secretKey = "pskj@2021";
            String bucketName = "cloud-bucket";
            String objectName = mediaFileMarkEntity.getObjectKey(); // 例如 "folder/file.txt"
            uploadFile(endpoint, accessKey, secretKey, bucketName, objectName, file2);
            markMapper.insert(mediaFileMarkEntity);
        }
        Object data = ImgUtil.getInfo(file1);
        mediaFileMarkEntity.setDronedata(data);
        mediaFileMarkEntity.setWorkspaceId(workspaceId);
        mediaFileMarkEntity.setFileId(UUID.randomUUID().toString());
        mediaFileMarkEntity.setObjectKey("/mark" + file.getPath() + "/" + file.getName());
        mediaFileMarkEntity.setFileName("mark" + file.getName());
        mediaFileMarkEntity.setFilePath("mark" + file.getPath());
        String endpoint = "http://dev.jxpskj.com:9000";
        String accessKey = "pskj";
        String secretKey = "pskj@2021";
        String bucketName = "cloud-bucket";
        String objectName = mediaFileMarkEntity.getObjectKey(); // 例如 "folder/file.txt"
        uploadFile(endpoint, accessKey, secretKey, bucketName, objectName, file2);
        return markMapper.insert(mediaFileMarkEntity);
    }
    @Override
    public Object mediaInfo(String fileId) {
    public Object mediaInfo(String filename) {
        String name = "mark" + filename;
        MediaFileMarkEntity entity = markMapper.selectOne(new LambdaQueryWrapper<MediaFileMarkEntity>()
                .eq(MediaFileMarkEntity::getFileId, fileId));
                .eq(MediaFileMarkEntity::getFileName, name));
        return entity.getDronedata();
    }
@@ -133,18 +156,34 @@
                .eq(MediaFileEntity::getWorkspaceId, workspaceId).eq(MediaFileEntity::getJobId, jobId));
    }
    public List<MediaFileEntity> listByIsadd() {
        return mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>().eq(MediaFileEntity::getIsadd, 0)
                .like(MediaFileEntity::getFileName, "~"));
    public List<MediaFileEntity> listByIsadd(String dkbh, String workspaceId) {
        return mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>()
                .eq(MediaFileEntity::getWorkspaceId, workspaceId)
                .like(MediaFileEntity::getFileName, dkbh + "~"));
    }
    public int updateExamByFileId(String fileId) {
        // 创建并配置 LambdaUpdateWrapper
        LambdaUpdateWrapper<MediaFileEntity> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(MediaFileEntity::getFileId, fileId)
                .set(MediaFileEntity::getExamine, 0);
        // 执行更新操作并返回更新的行数
        return mapper.update(null, updateWrapper);
    public ResponseResult updateExamByFileId(String fileId) {
        int examineStatus = getExamByFileId(fileId);
        if (examineStatus == 1) {
            LambdaUpdateWrapper<MediaFileEntity> updateWrapper = new LambdaUpdateWrapper<>();
            updateWrapper.eq(MediaFileEntity::getFileId, fileId)
                    .set(MediaFileEntity::getExamine, 0);
            mapper.update(null, updateWrapper);
            return ResponseResult.success("审核未通过");
        } else if (examineStatus == 0) {
            LambdaUpdateWrapper<MediaFileEntity> updateWrapper = new LambdaUpdateWrapper<>();
            updateWrapper.eq(MediaFileEntity::getFileId, fileId)
                    .set(MediaFileEntity::getExamine, 1);
            mapper.update(null, updateWrapper);
            return ResponseResult.success("审核通过");
        }
        return ResponseResult.error("媒体文件不存在");
    }
    public int getExamByFileId(String fileId) {
        MediaFileEntity entity = mapper.selectOne(new LambdaQueryWrapper<MediaFileEntity>()
                .eq(MediaFileEntity::getFileId, fileId));
        return entity.getExamine();
    }
    @Override