| | |
| | | package com.dji.sample.media.service.impl; |
| | | |
| | | import com.aliyun.oss.OSS; |
| | | import com.aliyun.oss.OSSClientBuilder; |
| | | import com.aliyun.oss.model.PutObjectRequest; |
| | | import com.aliyun.oss.model.PutObjectResult; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | 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; |
| | |
| | | import com.dji.sample.manage.service.IDeviceDictionaryService; |
| | | import com.dji.sample.media.dao.IFileMapper; |
| | | import com.dji.sample.media.dao.IMarkMapper; |
| | | import com.dji.sample.media.dao.INailMapper; |
| | | import com.dji.sample.media.model.*; |
| | | import com.dji.sample.media.service.IFileService; |
| | | import com.dji.sample.media.util.ImgUtil; |
| | | import com.dji.sample.media.util.MinioFileDownloader; |
| | | import com.dji.sample.patches.dao.GetPatchesMapper; |
| | | import com.dji.sample.patches.model.entity.LotInfo; |
| | | import com.dji.sample.patches.utils.DistrictCodeUtils; |
| | | import com.dji.sample.patches.utils.TimerUtil; |
| | | import com.dji.sample.territory.pojo.TerritoryConfigPojo; |
| | | import com.dji.sample.territory.service.impl.TbFjServiceImpl; |
| | | import com.dji.sample.territory.utils.ImgZipUtil; |
| | | import com.dji.sample.territory.utils.WaterMarkUtil; |
| | | import com.dji.sample.wayline.service.IWaylineFileService; |
| | | import com.dji.sample.wayline.service.IWaylineJobService; |
| | | import com.drew.imaging.ImageProcessingException; |
| | | import com.fasterxml.jackson.databind.JsonNode; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import io.minio.MinioClient; |
| | | import io.minio.PutObjectArgs; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.awt.*; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.net.URL; |
| | | import java.time.Instant; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.util.Arrays; |
| | | import java.util.*; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.UUID; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.dji.sample.media.util.ImageDownloaderAndCompressor.*; |
| | | |
| | | /** |
| | | * @author sean |
| | |
| | | @Autowired |
| | | private IMarkMapper markMapper; |
| | | @Autowired |
| | | private INailMapper nailMapper; |
| | | @Autowired |
| | | private GetPatchesMapper patchesMapper; |
| | | @Autowired |
| | | private IDeviceDictionaryService deviceDictionaryService; |
| | | |
| | | @Autowired |
| | | private OssServiceContext ossService; |
| | | @Autowired |
| | | private TerritoryConfigPojo territoryConfigPojo; |
| | | @Autowired |
| | | private IWaylineJobService waylineJobService; |
| | | @Autowired |
| | | private IWaylineFileService waylineFileService; |
| | | @Autowired |
| | | private MinioPojo pojo; |
| | | |
| | | private ObjectMapper objectMapper = new ObjectMapper(); |
| | | |
| | | |
| | | private Optional<MediaFileEntity> getMediaByFingerprint(String workspaceId, String fingerprint) { |
| | | MediaFileEntity fileEntity = mapper.selectOne(new LambdaQueryWrapper<MediaFileEntity>() |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Integer saveFile(String workspaceId, FileUploadDTO file) { |
| | | public Integer saveFile(String workspaceId, FileUploadDTO file) throws IOException, ImageProcessingException { |
| | | MediaFileEntity fileEntity = this.fileUploadConvertToEntity(file); |
| | | fileEntity.setWorkspaceId(workspaceId); |
| | | fileEntity.setFileId(UUID.randomUUID().toString()); |
| | | return mapper.insert(fileEntity); |
| | | int count = mapper.insert(fileEntity); |
| | | String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey(); |
| | | if (file.getObjectKey().endsWith(".jpeg")) { |
| | | File file1 = TbFjServiceImpl.downloadFile(url); |
| | | Object data = ImgUtil.getInfo(file1); |
| | | fileEntity.setDroneData(data); |
| | | saveNailFile(workspaceId, file, file1,data); |
| | | count = mapper.insert(fileEntity); |
| | | file1.delete(); |
| | | } |
| | | if (file.getObjectKey().endsWith(".mp4")) { |
| | | saveNailFile(workspaceId, file, null,null); |
| | | } |
| | | return count; |
| | | } |
| | | public Integer saveMarkFile(String workspaceId, FileUploadDTO file) throws IOException, FontFormatException { |
| | | MediaFileMarkEntity mediaFileMarkEntity =this.fileUploadConvertToMarkEntity(file); |
| | | String url = "http://dev.jxpskj.com:9000/cloud-bucket" + file.getObjectKey(); |
| | | File file1=TbFjServiceImpl.downloadFile(url); |
| | | File file2= new File(WaterMarkUtil.addWatermark(file1, Long.valueOf(file.getMetadata().getCreatedTime().toString()),file.getMetadata().getPhotoedPosition().getLat(), |
| | | file.getMetadata().getPhotoedPosition().getLng(),file.getMetadata().getGimbalYawDegree()).toURI()); |
| | | mediaFileMarkEntity.setObjectKey(file.getPath()); |
| | | 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()); |
| | | uploadFile(String.valueOf(file2), mediaFileMarkEntity.getObjectKey()); |
| | | return markMapper.insert(mediaFileMarkEntity); |
| | | |
| | | public void saveNailFile(String workspaceId, FileUploadDTO file, File file1,Object data) throws IOException { |
| | | updateStatue(file.getName()); |
| | | boolean endsWith = file.getObjectKey().endsWith(".mp4"); |
| | | if (endsWith) { |
| | | MediaFileNailEntity nailEntity = this.fileUploadConvertToNailEntity((file)); |
| | | nailEntity.setWorkspaceId(workspaceId); |
| | | nailEntity.setFileId(UUID.randomUUID().toString()); |
| | | nailMapper.insert(nailEntity); |
| | | } else { |
| | | File nailFile = new File(ImgZipUtil.compressImage(file1, 50).toURI()); |
| | | MediaFileNailEntity nailEntity = this.fileUploadConvertToNailEntity(file); |
| | | nailEntity.setIsOriginal(false); |
| | | nailEntity.setDronedata(data); |
| | | nailEntity.setWorkspaceId(workspaceId); |
| | | nailEntity.setFileName("nail" + file.getName()); |
| | | nailEntity.setObjectKey("/nail" + file.getPath() + "/" + file.getName()); |
| | | nailEntity.setFilePath("nail" + file.getPath()); |
| | | String nailName = nailEntity.getObjectKey(); |
| | | nailEntity.setFileId(UUID.randomUUID().toString()); |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | 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; |
| | | List<MediaFileEntity> entitys = mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>() |
| | | .eq(MediaFileEntity::getFileName, name)); |
| | | if (entitys != null && !entitys.isEmpty()) { |
| | | for (MediaFileEntity entity : entitys) { |
| | | if (entity.getDroneData() != null) { |
| | | return entity.getDroneData(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!filename.contains("mark")) { |
| | | name = "mark" + filename; |
| | | } |
| | | List<MediaFileMarkEntity> entity = markMapper.selectList(new LambdaQueryWrapper<MediaFileMarkEntity>() |
| | | .eq(MediaFileMarkEntity::getFileName, name)); |
| | | if (entity != null && !entity.isEmpty()) { |
| | | for (MediaFileMarkEntity markEntity : entity) { |
| | | if (markEntity.getDronedata() != null) { |
| | | return markEntity.getDronedata(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return "null"; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<MediaFileDTO> getAllFilesByWorkspaceId(String workspaceId) { |
| | | return mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>() |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId)) |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId)) |
| | | .stream() |
| | | .map(this::entityConvertToDto) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | @Override |
| | | public PaginationData<MediaFileEntity> mediaQuery(Integer page, Integer pageSize, Long updateStart, Long updateEnd, Long photoStart, Long photoEnd, String jobName, String workspaceId, String type) { |
| | | // 创建查询条件对象 |
| | | LambdaQueryWrapper<MediaFileEntity> queryWrapper = new LambdaQueryWrapper<>(); |
| | | |
| | | // 添加查询条件 |
| | | queryWrapper.eq(MediaFileEntity::getWorkspaceId, workspaceId); |
| | | |
| | | if (updateStart != null && updateEnd != null) { |
| | | queryWrapper.between(MediaFileEntity::getCreateTime, updateStart, updateEnd); |
| | | } |
| | | |
| | | if (photoStart != null && photoEnd != null) { |
| | | queryWrapper.apply("JSON_UNQUOTE(JSON_EXTRACT(metadata, '$.createdTime')) BETWEEN {0} AND {1}", photoStart, photoEnd); |
| | | } |
| | | |
| | | if (jobName != null && !jobName.isEmpty()) { |
| | | List<String> jobIds = waylineJobService.getJobIds(jobName); |
| | | if (jobIds.isEmpty()) { |
| | | return new PaginationData<>(Collections.emptyList(), new Pagination(new Page<>(page, pageSize))); |
| | | } |
| | | queryWrapper.in(MediaFileEntity::getJobId, jobIds); |
| | | } |
| | | |
| | | if (type != null && !type.isEmpty()) { |
| | | if ("图片".equals(type)) { |
| | | queryWrapper.likeLeft(MediaFileEntity::getFileName, ".jpeg"); |
| | | } else if ("视频".equals(type)) { |
| | | queryWrapper.likeLeft(MediaFileEntity::getFileName, ".mp4"); |
| | | } |
| | | } |
| | | |
| | | queryWrapper.last("ORDER BY JSON_EXTRACT(metadata, '$.createdTime') DESC"); |
| | | |
| | | // 执行查询获取所有结果 |
| | | List<MediaFileEntity> allResults = mapper.selectList(queryWrapper); |
| | | |
| | | // 处理结果去重并设置任务名称 |
| | | Map<String, MediaFileEntity> uniqueFileMap = new LinkedHashMap<>(); |
| | | List<MediaFileEntity> uniqueResults = allResults.stream() |
| | | .peek(mediaFile -> { |
| | | String taskNameResult = waylineJobService.getName(mediaFile.getJobId()); |
| | | mediaFile.setJobName(taskNameResult); |
| | | }) |
| | | .filter(mediaFile -> uniqueFileMap.putIfAbsent(mediaFile.getFileName(), mediaFile) == null) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 计算分页信息 |
| | | int total = uniqueResults.size(); |
| | | int start = (page - 1) * pageSize; |
| | | int end = Math.min(start + pageSize, total); |
| | | |
| | | // 获取当前页的结果 |
| | | List<MediaFileEntity> pageResults = uniqueResults.subList(start, end); |
| | | |
| | | // 创建临时的 Page 对象 |
| | | Page<MediaFileEntity> resultPage = new Page<>(page, pageSize); |
| | | resultPage.setRecords(pageResults); |
| | | resultPage.setTotal(total); |
| | | |
| | | // 返回分页数据 |
| | | return new PaginationData<>(pageResults, new Pagination(resultPage)); |
| | | } |
| | | |
| | | @Override |
| | | public PaginationData<MediaFileNailEntity> mediaNailQuery(Integer page, Integer pageSize, Long updateStart, Long updateEnd, Long photoStart, Long photoEnd, String jobName, String workspaceId, String type) { |
| | | // 创建查询条件对象 |
| | | LambdaQueryWrapper<MediaFileNailEntity> queryWrapper = new LambdaQueryWrapper<>(); |
| | | |
| | | // 添加查询条件 |
| | | queryWrapper.eq(MediaFileNailEntity::getWorkspaceId, workspaceId); |
| | | |
| | | if (updateStart != null && updateEnd != null) { |
| | | queryWrapper.between(MediaFileNailEntity::getCreateTime, updateStart, updateEnd); |
| | | } |
| | | |
| | | if (photoStart != null && photoEnd != null) { |
| | | queryWrapper.apply("JSON_UNQUOTE(JSON_EXTRACT(metadata, '$.createdTime')) BETWEEN {0} AND {1}", photoStart, photoEnd); |
| | | } |
| | | |
| | | if (jobName != null && !jobName.isEmpty()) { |
| | | List<String> jobIds = waylineJobService.getJobIds(jobName); |
| | | if (jobIds.isEmpty()) { |
| | | return new PaginationData<>(Collections.emptyList(), new Pagination(new Page<>(page, pageSize))); |
| | | } |
| | | queryWrapper.in(MediaFileNailEntity::getJobId, jobIds); |
| | | } |
| | | |
| | | if (type != null && !type.isEmpty()) { |
| | | if ("图片".equals(type)) { |
| | | queryWrapper.likeLeft(MediaFileNailEntity::getFileName, ".jpeg"); |
| | | } else if ("视频".equals(type)) { |
| | | queryWrapper.likeLeft(MediaFileNailEntity::getFileName, ".mp4"); |
| | | } |
| | | } |
| | | |
| | | queryWrapper.last("ORDER BY JSON_EXTRACT(metadata, '$.createdTime') DESC"); |
| | | |
| | | // 执行查询获取所有结果 |
| | | List<MediaFileNailEntity> allResults = nailMapper.selectList(queryWrapper); |
| | | |
| | | // 处理结果去重并设置任务名称 |
| | | Map<String, MediaFileNailEntity> uniqueFileMap = new LinkedHashMap<>(); |
| | | List<MediaFileNailEntity> uniqueResults = allResults.stream() |
| | | .peek(mediaFile -> { |
| | | String taskNameResult = waylineJobService.getName(mediaFile.getJobId()); |
| | | mediaFile.setJobName(taskNameResult); |
| | | }) |
| | | .filter(mediaFile -> uniqueFileMap.putIfAbsent(mediaFile.getFileName(), mediaFile) == null) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 计算分页信息 |
| | | int total = uniqueResults.size(); |
| | | int start = (page - 1) * pageSize; |
| | | int end = Math.min(start + pageSize, total); |
| | | |
| | | // 获取当前页的结果 |
| | | List<MediaFileNailEntity> pageResults = uniqueResults.subList(start, end); |
| | | |
| | | // 创建临时的 Page 对象 |
| | | Page<MediaFileNailEntity> resultPage = new Page<>(page, pageSize); |
| | | resultPage.setRecords(pageResults); |
| | | resultPage.setTotal(total); |
| | | |
| | | // 返回分页数据 |
| | | return new PaginationData<>(pageResults, new Pagination(resultPage)); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<MediaFileEntity> listMediaFileEntity(String workspaceId, String jobId) { |
| | | return mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>() |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId).eq(MediaFileEntity::getJobId,jobId)); |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId).eq(MediaFileEntity::getJobId, jobId)); |
| | | } |
| | | |
| | | public List<MediaFileEntity> listByIsadd(String dkbh, String workspaceId) { |
| | | return mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>() |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId) |
| | | .like(MediaFileEntity::getFileName, dkbh + "~")); |
| | | } |
| | | |
| | | 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(); |
| | | } |
| | | |
| | | public String getDkbhName(String name) { |
| | | int startIndex = name.indexOf("点") + 1; |
| | | int endIndex = name.indexOf("."); |
| | | return name.substring(startIndex, endIndex); |
| | | } |
| | | |
| | | @Override |
| | |
| | | // .eq(MediaFileEntity::getWorkspaceId, workspaceId) |
| | | // .orderByDesc(MediaFileEntity::getId)); |
| | | Page<MediaFileEntity> pageData = mapper.selectPage(new Page<MediaFileEntity>(page, pageSize), new LambdaQueryWrapper<MediaFileEntity>() |
| | | .eq(MediaFileEntity::getWorkspaceId,workspaceId) |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId) |
| | | .orderByDesc(MediaFileEntity::getCreateTime)); |
| | | |
| | | List<MediaFileEntity> records = pageData.getRecords() |
| | | .stream() |
| | | .peek(mediaFile -> { |
| | | // 获取任务名称并设置到fileId |
| | | String taskNameResult = waylineJobService.getName(mediaFile.getJobId()); |
| | | mediaFile.setJobName(taskNameResult); |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | return new PaginationData<MediaFileEntity>(records, new Pagination(pageData)); |
| | | } |
| | | |
| | | public int deleteMedia(String workspaceId, String fileId) { |
| | | int count=mapper.delete(new LambdaUpdateWrapper<MediaFileEntity>().eq(MediaFileEntity::getFileId, fileId) |
| | | public int deleteMedia(String workspaceId, String fileId) { |
| | | int count = mapper.delete(new LambdaUpdateWrapper<MediaFileEntity>().eq(MediaFileEntity::getFileId, fileId) |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId)); |
| | | return count; |
| | | return count; |
| | | } |
| | | |
| | | @Override |
| | | public URL getObjectUrl(String workspaceId, String fileId) { |
| | | Optional<MediaFileEntity> mediaFileOpt = getMediaByFileId(workspaceId, fileId); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ResponseResult downloadImages(List<String> jobIds) { |
| | | try { |
| | | String bucketPath = "/data/software/minio-data/cloud-bucket/"; |
| | | // List<String> prefixes = getUniqueFilePaths(jobIds); |
| | | MinioFileDownloader downloader = new MinioFileDownloader(bucketPath); |
| | | // 下载并压缩文件到本地目录 |
| | | String localSaveDir = "/data/software/minio-data/zip-bucket/"; // 修改为你想保存的本地目录 |
| | | downloader.downloadAndZipFolders(jobIds, localSaveDir); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return ResponseResult.error("下载失败" + e.getMessage()); |
| | | } |
| | | return ResponseResult.success("下载成功"); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getUniqueFilePaths(List<String> jobIds) { |
| | | return mapper.selectList( |
| | | new LambdaQueryWrapper<MediaFileEntity>() |
| | | .in(MediaFileEntity::getJobId, jobIds)) |
| | | .stream() |
| | | .map(MediaFileEntity::getFilePath) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | @Override |
| | | public List<MediaFileDTO> getFilesByWorkspaceAndJobId(String workspaceId, String jobId) { |
| | | return mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>() |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId) |
| | | .eq(MediaFileEntity::getJobId, jobId)) |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId) |
| | | .eq(MediaFileEntity::getJobId, jobId)) |
| | | .stream() |
| | | .map(this::entityConvertToDto).collect(Collectors.toList()); |
| | | } |
| | |
| | | params.setWorkspaceId(mediaFileEntity.getWorkspaceId());*/ |
| | | boolean update1 = new LambdaUpdateChainWrapper<>(mapper).eq(MediaFileEntity::getFileId, mediaFileEntity.getFileId()) |
| | | .set(MediaFileEntity::getFileName, mediaFileEntity.getFileName()) |
| | | .set(MediaFileEntity::getCollectStatus,mediaFileEntity.getCollectStatus()) |
| | | .set(MediaFileEntity::getUserId,mediaFileEntity.getUserId()) |
| | | .set(MediaFileEntity::getCollectStatus, mediaFileEntity.getCollectStatus()) |
| | | .set(MediaFileEntity::getUserId, mediaFileEntity.getUserId()) |
| | | .update(); |
| | | // int update = mapper.update(mediaFileEntity, Wrappers.update(params)); |
| | | return update1; |
| | |
| | | |
| | | /** |
| | | * Convert the received file object into a database entity object. |
| | | * |
| | | * @param file |
| | | * @return |
| | | */ |
| | |
| | | if (file != null) { |
| | | builder.fileName(file.getName()) |
| | | .filePath(file.getPath()) |
| | | .isadd(0) |
| | | .examine(0) |
| | | .fingerprint(file.getFingerprint()) |
| | | .objectKey(file.getObjectKey()) |
| | | .subFileType(file.getSubFileType()) |
| | |
| | | } |
| | | return builder.build(); |
| | | } |
| | | |
| | | private MediaFileMarkEntity fileUploadConvertToMarkEntity(FileUploadDTO file) { |
| | | MediaFileMarkEntity.MediaFileMarkEntityBuilder builder = MediaFileMarkEntity.builder(); |
| | | |
| | | if (file != null) { |
| | | builder.fileName(file.getName()) |
| | | .filePath(file.getPath()) |
| | | .isadd(0) |
| | | .fingerprint(file.getFingerprint()) |
| | | .objectKey(file.getObjectKey()) |
| | | .subFileType(file.getSubFileType()) |
| | | .isOriginal(file.getExt().getIsOriginal()) |
| | | .jobId(file.getExt().getFlightId()) |
| | | .drone(file.getExt().getSn()).metadata(file.getMetadata()) |
| | | .tinnyFingerprint(file.getExt().getTinnyFingerprint()); |
| | | |
| | | // domain-type-subType |
| | | int[] payloadModel = Arrays.stream(file.getExt().getPayloadModelKey().split("-")) |
| | | .map(Integer::valueOf) |
| | | .mapToInt(Integer::intValue) |
| | | .toArray(); |
| | | Optional<DeviceDictionaryDTO> payloadDict = deviceDictionaryService |
| | | .getOneDictionaryInfoByTypeSubType(DeviceDomainEnum.PAYLOAD.getVal(), payloadModel[1], payloadModel[2]); |
| | | payloadDict.ifPresent(payload -> builder.payload(payload.getDeviceName())); |
| | | } |
| | | return builder.build(); |
| | | } |
| | | |
| | | private MediaFileNailEntity fileUploadConvertToNailEntity(FileUploadDTO file) { |
| | | MediaFileNailEntity.MediaFileNailEntityBuilder builder = MediaFileNailEntity.builder(); |
| | | |
| | | if (file != null) { |
| | | builder.fileName(file.getName()) |
| | | .fingerprint(file.getFingerprint()) |
| | | .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()); |
| | |
| | | |
| | | /** |
| | | * Convert database entity objects into file data transfer object. |
| | | * |
| | | * @param entity |
| | | * @return |
| | | */ |
| | |
| | | |
| | | return builder.build(); |
| | | } |
| | | public void uploadFile(String filePath, String key) { |
| | | OSS ossClient = new OSSClientBuilder().build(OssConfiguration.endpoint, OssConfiguration.accessKey, OssConfiguration.secretKey); |
| | | |
| | | public static void uploadFile(String endpoint, String accessKey, String secretKey, String bucketName, String objectName, File file, String type) { |
| | | try { |
| | | File file = new File(filePath); |
| | | PutObjectRequest putObjectRequest = new PutObjectRequest(OssConfiguration.bucket, key, file); |
| | | PutObjectResult putObjectResult = ossClient.putObject(putObjectRequest); |
| | | // 创建MinIO客户端实例 |
| | | MinioClient minioClient = MinioClient.builder() |
| | | .endpoint(endpoint) |
| | | .credentials(accessKey, secretKey) |
| | | .build(); |
| | | // 上传文件 |
| | | FileInputStream fileInputStream = new FileInputStream(file); |
| | | minioClient.putObject( |
| | | PutObjectArgs.builder() |
| | | .bucket(bucketName) |
| | | .object(objectName) |
| | | .stream(fileInputStream, file.length(), -1) |
| | | .contentType(type) |
| | | .build() |
| | | ); |
| | | fileInputStream.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | ossClient.shutdown(); |
| | | throw new RuntimeException("上传文件至服务器失败" + e); |
| | | } |
| | | } |
| | | |
| | | public static long convertToTimestamp(Date date) { |
| | | // 获取时间戳(毫秒级别) |
| | | return date.getTime(); |
| | | } |
| | | |
| | | public List<MediaFileEntity> getSameJobId(String jobId) { |
| | | return mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>() |
| | | .eq(MediaFileEntity::getJobId, jobId)); |
| | | } |
| | | |
| | | |
| | | public void updateMediaFileNames(String jobId) { |
| | | // 查询符合条件的数据 |
| | | List<MediaFileEntity> mediaFiles = mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>() |
| | | .eq(MediaFileEntity::getJobId, jobId)); |
| | | boolean allContainTilde = mediaFiles.stream().allMatch(file -> file.getFileName().contains("~")); |
| | | boolean noneContainTilde = mediaFiles.stream().noneMatch(file -> file.getFileName().contains("~")); |
| | | |
| | | // 如果所有 fileName 都包含 '~' 或者都不包含 '~',将 is_add 字段改为 1 |
| | | if (allContainTilde || noneContainTilde) { |
| | | return; |
| | | } |
| | | |
| | | // 筛选出name字段不包含'~'的数据 |
| | | List<MediaFileEntity> filteredFiles = mediaFiles.stream() |
| | | .filter(file -> !file.getFileName().contains("~")) |
| | | .collect(Collectors.toList()); |
| | | for (MediaFileEntity currentFile : filteredFiles) { |
| | | String currentName = currentFile.getFileName(); |
| | | Map<String, Object> currentMetadata = JSON.parseObject(JSON.toJSONString(currentFile.getMetadata()), Map.class); |
| | | Long currentCreatedTime = (Long) currentMetadata.get("createdTime"); |
| | | // 找到metadata中的createdTime小于当前数据的createdTime且最接近的那条数据 |
| | | Optional<MediaFileEntity> closestFileOpt = mediaFiles.stream() |
| | | .filter(file -> { |
| | | Map<String, Object> metadata = JSON.parseObject(JSON.toJSONString(file.getMetadata()), Map.class); |
| | | Long createdTime = (Long) metadata.get("createdTime"); |
| | | String filename = file.getFileName(); |
| | | return createdTime < currentCreatedTime && filename.contains("~"); |
| | | }) |
| | | .min((file1, file2) -> { |
| | | Map<String, Object> metadata1 = JSON.parseObject(JSON.toJSONString(file1.getMetadata()), Map.class); |
| | | Map<String, Object> metadata2 = JSON.parseObject(JSON.toJSONString(file2.getMetadata()), Map.class); |
| | | Long time1 = (Long) metadata1.get("createdTime"); |
| | | Long time2 = (Long) metadata2.get("createdTime"); |
| | | return Long.compare(currentCreatedTime - time1, currentCreatedTime - time2); |
| | | }); |
| | | if (closestFileOpt.isEmpty()) { |
| | | // 找不到小于的文件,尝试找大于且最接近的文件 |
| | | closestFileOpt = mediaFiles.stream() |
| | | .filter(file -> { |
| | | Map<String, Object> metadata = JSON.parseObject(JSON.toJSONString(file.getMetadata()), Map.class); |
| | | Long createdTime = (Long) metadata.get("createdTime"); |
| | | String filename = file.getFileName(); |
| | | return createdTime > currentCreatedTime && filename.contains("~"); |
| | | }) |
| | | .min((file1, file2) -> { |
| | | Map<String, Object> metadata1 = JSON.parseObject(JSON.toJSONString(file1.getMetadata()), Map.class); |
| | | Map<String, Object> metadata2 = JSON.parseObject(JSON.toJSONString(file2.getMetadata()), Map.class); |
| | | Long time1 = (Long) metadata1.get("createdTime"); |
| | | Long time2 = (Long) metadata2.get("createdTime"); |
| | | return Long.compare(time1 - currentCreatedTime, time2 - currentCreatedTime); |
| | | }); |
| | | } |
| | | // 提取并替换name字段 |
| | | closestFileOpt.ifPresent(closestFile -> { |
| | | String closestName = closestFile.getFileName(); |
| | | int startIndex = closestName.indexOf("V"); |
| | | if (startIndex == -1) startIndex = closestName.indexOf("W"); |
| | | if (startIndex == -1) startIndex = closestName.indexOf("Z"); |
| | | if (startIndex == -1) startIndex = closestName.indexOf("T"); |
| | | if (startIndex == -1) { |
| | | return; |
| | | } |
| | | int endIndex = closestName.indexOf(".", startIndex); |
| | | if (endIndex == -1) { |
| | | return; |
| | | } |
| | | String replacement = closestName.substring(startIndex, endIndex); |
| | | int currentStartIndex = currentName.indexOf("V"); |
| | | if (currentStartIndex == -1) currentStartIndex = currentName.indexOf("W"); |
| | | if (currentStartIndex == -1) currentStartIndex = currentName.indexOf("Z"); |
| | | if (currentStartIndex == -1) currentStartIndex = currentName.indexOf("T"); |
| | | if (currentStartIndex == -1) { |
| | | return; |
| | | } |
| | | int currentEndIndex = currentName.indexOf(".", currentStartIndex); |
| | | if (currentEndIndex == -1) { |
| | | return; |
| | | } |
| | | String newName = currentName.substring(0, currentStartIndex) |
| | | + replacement |
| | | + currentName.substring(currentEndIndex); |
| | | currentFile.setFileName(newName); |
| | | updateMediaById(currentFile.getId(), currentFile); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void updateMarkMediaFileNames(String jobId) { |
| | | try { |
| | | // 查询符合条件的数据 |
| | | List<MediaFileMarkEntity> mediaFiles = markMapper.selectList(new LambdaQueryWrapper<MediaFileMarkEntity>() |
| | | .eq(MediaFileMarkEntity::getJobId, jobId)); |
| | | |
| | | // 判断所有 fileName 是否都包含 '~' 或者都不包含 '~' |
| | | boolean allContainTilde = mediaFiles.stream().allMatch(file -> file.getFileName().contains("~")); |
| | | boolean noneContainTilde = mediaFiles.stream().noneMatch(file -> file.getFileName().contains("~")); |
| | | |
| | | // 如果所有 fileName 都包含 '~' 或者都不包含 '~',将 is_add 字段改为 1 |
| | | if (allContainTilde || noneContainTilde) { |
| | | mediaFiles.forEach(file -> { |
| | | file.setIsadd(1); |
| | | updateById(file.getId(), file); |
| | | }); |
| | | return; |
| | | } |
| | | |
| | | // 筛选出name字段不包含'~'的数据 |
| | | List<MediaFileMarkEntity> filteredFiles = mediaFiles.stream() |
| | | .filter(file -> !file.getFileName().contains("~")) |
| | | .collect(Collectors.toList()); |
| | | |
| | | for (MediaFileMarkEntity currentFile : filteredFiles) { |
| | | String currentName = currentFile.getFileName(); |
| | | Map<String, Object> currentMetadata = JSON.parseObject(JSON.toJSONString(currentFile.getMetadata()), Map.class); |
| | | Long currentCreatedTime = (Long) currentMetadata.get("createdTime"); |
| | | |
| | | // 找到metadata中的createdTime小于当前数据的createdTime且最接近的那条数据 |
| | | Optional<MediaFileMarkEntity> closestFileOpt = mediaFiles.stream() |
| | | .filter(file -> { |
| | | Map<String, Object> metadata = JSON.parseObject(JSON.toJSONString(file.getMetadata()), Map.class); |
| | | Long createdTime = (Long) metadata.get("createdTime"); |
| | | String filename = file.getFileName(); |
| | | return createdTime < currentCreatedTime && filename.contains("~"); |
| | | }) |
| | | .min((file1, file2) -> { |
| | | Map<String, Object> metadata1 = JSON.parseObject(JSON.toJSONString(file1.getMetadata()), Map.class); |
| | | Map<String, Object> metadata2 = JSON.parseObject(JSON.toJSONString(file2.getMetadata()), Map.class); |
| | | Long time1 = (Long) metadata1.get("createdTime"); |
| | | Long time2 = (Long) metadata2.get("createdTime"); |
| | | return Long.compare(currentCreatedTime - time1, currentCreatedTime - time2); |
| | | }); |
| | | |
| | | if (closestFileOpt.isEmpty()) { |
| | | // 找不到小于的文件,尝试找大于且最接近的文件 |
| | | closestFileOpt = mediaFiles.stream() |
| | | .filter(file -> { |
| | | Map<String, Object> metadata = JSON.parseObject(JSON.toJSONString(file.getMetadata()), Map.class); |
| | | Long createdTime = (Long) metadata.get("createdTime"); |
| | | String filename = file.getFileName(); |
| | | return createdTime > currentCreatedTime && filename.contains("~"); |
| | | }) |
| | | .min((file1, file2) -> { |
| | | Map<String, Object> metadata1 = JSON.parseObject(JSON.toJSONString(file1.getMetadata()), Map.class); |
| | | Map<String, Object> metadata2 = JSON.parseObject(JSON.toJSONString(file2.getMetadata()), Map.class); |
| | | Long time1 = (Long) metadata1.get("createdTime"); |
| | | Long time2 = (Long) metadata2.get("createdTime"); |
| | | return Long.compare(time1 - currentCreatedTime, time2 - currentCreatedTime); |
| | | }); |
| | | } |
| | | |
| | | // 提取并替换name字段 |
| | | closestFileOpt.ifPresent(closestFile -> { |
| | | String closestName = closestFile.getFileName(); |
| | | int startIndex = closestName.indexOf("V"); |
| | | if (startIndex == -1) startIndex = closestName.indexOf("W"); |
| | | if (startIndex == -1) startIndex = closestName.indexOf("Z"); |
| | | if (startIndex == -1) startIndex = closestName.indexOf("T"); |
| | | if (startIndex == -1) { |
| | | return; |
| | | } |
| | | int endIndex = closestName.indexOf(".", startIndex); |
| | | if (endIndex == -1) { |
| | | return; |
| | | } |
| | | String replacement = closestName.substring(startIndex, endIndex); |
| | | |
| | | int currentStartIndex = currentName.indexOf("V"); |
| | | if (currentStartIndex == -1) currentStartIndex = currentName.indexOf("W"); |
| | | if (currentStartIndex == -1) currentStartIndex = currentName.indexOf("Z"); |
| | | if (currentStartIndex == -1) currentStartIndex = currentName.indexOf("T"); |
| | | if (currentStartIndex == -1) { |
| | | return; |
| | | } |
| | | int currentEndIndex = currentName.indexOf(".", currentStartIndex); |
| | | if (currentEndIndex == -1) { |
| | | return; |
| | | } |
| | | String newName = currentName.substring(0, currentStartIndex) |
| | | + replacement |
| | | + currentName.substring(currentEndIndex); |
| | | currentFile.setFileName(newName); |
| | | updateById(currentFile.getId(), currentFile); |
| | | }); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public PaginationData<MediaFileEntity> getJobId(int pageNum, int pageSize, String workspaceId) { |
| | | List<MediaFileEntity> allRecords = new ArrayList<>(); |
| | | int currentPageNum = 1; // 从第一页开始获取记录 |
| | | |
| | | // 用于存储去重后的记录 |
| | | Map<String, MediaFileEntity> uniqueFilesMap = new HashMap<>(); |
| | | |
| | | while (true) { |
| | | // 分页查询 |
| | | Page<MediaFileEntity> page = new Page<>(currentPageNum, pageSize); |
| | | Page<MediaFileEntity> resultPage = mapper.selectPage(page, new LambdaQueryWrapper<MediaFileEntity>() |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId)); |
| | | |
| | | List<MediaFileEntity> result = resultPage.getRecords(); |
| | | |
| | | // 检查是否还有更多记录 |
| | | if (result.isEmpty()) { |
| | | break; // 没有更多记录了,停止请求 |
| | | } |
| | | |
| | | // 根据 fileName 字段进行去重并设置 JobName |
| | | result.stream() |
| | | .peek(mediaFile -> { |
| | | String taskNameResult = waylineJobService.getName(mediaFile.getJobId()); |
| | | mediaFile.setJobName(taskNameResult); |
| | | }) |
| | | .forEach(mediaFile -> uniqueFilesMap.putIfAbsent(mediaFile.getFileName(), mediaFile)); |
| | | |
| | | // 增加当前页数以获取更多记录 |
| | | currentPageNum++; |
| | | } |
| | | |
| | | // 获取去重后的实际总数 |
| | | List<MediaFileEntity> uniqueFiles = new ArrayList<>(uniqueFilesMap.values()); |
| | | int uniqueTotal = uniqueFiles.size(); |
| | | |
| | | // 计算当前页的起始和结束索引 |
| | | int fromIndex = Math.min((pageNum - 1) * pageSize, uniqueTotal); |
| | | int toIndex = Math.min(fromIndex + pageSize, uniqueTotal); |
| | | |
| | | // 获取当前页的数据 |
| | | List<MediaFileEntity> pagedUniqueFiles = uniqueFiles.subList(fromIndex, toIndex); |
| | | |
| | | // 创建新的分页对象,使用去重后的总数 |
| | | Page<MediaFileEntity> uniquePage = new Page<>(pageNum, pageSize, uniqueTotal); |
| | | |
| | | // 使用新的分页对象构造 Pagination |
| | | Pagination pagination = new Pagination(uniquePage); |
| | | |
| | | return new PaginationData<>(pagedUniqueFiles, pagination); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public PaginationData<MediaFileEntity> getPhotoByJobId(int pageNum, int pageSize, String workspaceId, String jobId) { |
| | | |
| | | // 分页查询 |
| | | Page<MediaFileEntity> page = new Page<>(pageNum, pageSize); |
| | | Page<MediaFileEntity> resultPage = mapper.selectPage(page, new LambdaQueryWrapper<MediaFileEntity>() |
| | | .eq(MediaFileEntity::getJobId, jobId) |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId)); |
| | | |
| | | List<MediaFileEntity> result = resultPage.getRecords(); |
| | | |
| | | // 根据 fileName 字段进行去重 |
| | | Map<String, MediaFileEntity> uniqueFilesMap = result.stream() |
| | | .collect(Collectors.toMap( |
| | | MediaFileEntity::getFileName, |
| | | entity -> entity, |
| | | (existing, replacement) -> existing // 如果有重复的,保留已有的 |
| | | )); |
| | | |
| | | List<MediaFileEntity> uniqueFiles = new ArrayList<>(uniqueFilesMap.values()); |
| | | |
| | | // 使用去重后的列表重新计算总数 |
| | | int uniqueTotal = uniqueFiles.size(); |
| | | |
| | | // 创建新的分页对象,使用去重后的总数 |
| | | Page<MediaFileEntity> uniquePage = new Page<>(pageNum, pageSize, uniqueTotal); |
| | | |
| | | // 截取当前页的数据 |
| | | int fromIndex = Math.min((pageNum - 1) * pageSize, uniqueTotal); |
| | | int toIndex = Math.min(fromIndex + pageSize, uniqueTotal); |
| | | List<MediaFileEntity> pagedUniqueFiles = uniqueFiles.subList(fromIndex, toIndex); |
| | | |
| | | // 使用新的分页对象构造 Pagination |
| | | Pagination pagination = new Pagination(uniquePage); |
| | | |
| | | return new PaginationData<>(pagedUniqueFiles, pagination); |
| | | } |
| | | |
| | | |
| | | public List<MediaFileEntity> getMedia(String jobId) { |
| | | return mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>() |
| | | .eq(MediaFileEntity::getJobId, jobId) |
| | | .groupBy(MediaFileEntity::getFileName)); // 使用groupBy去重 |
| | | } |
| | | |
| | | public void updateById(Integer id, MediaFileMarkEntity entity) { |
| | | entity.setIsadd(1); |
| | | UpdateWrapper<MediaFileMarkEntity> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.eq("id", id); |
| | | markMapper.update(entity, updateWrapper); |
| | | } |
| | | |
| | | public void updateMediaById(Integer id, MediaFileEntity entity) { |
| | | UpdateWrapper<MediaFileEntity> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.eq("id", id); |
| | | mapper.update(entity, updateWrapper); |
| | | } |
| | | |
| | | public void getNoaddFile() { |
| | | List<MediaFileMarkEntity> markEntities = markMapper.selectList(new LambdaQueryWrapper<MediaFileMarkEntity>().eq(MediaFileMarkEntity::getIsadd, 0)); |
| | | for (MediaFileMarkEntity mark : markEntities) { |
| | | updateMarkMediaFileNames(mark.getJobId()); |
| | | updateMediaFileNames(mark.getJobId()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |