| | |
| | | package com.dji.sample.media.service.impl; |
| | | |
| | | 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.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; |
| | |
| | | @Autowired |
| | | private IWaylineFileService waylineFileService; |
| | | |
| | | private ObjectMapper objectMapper = new ObjectMapper(); |
| | | |
| | | |
| | | private Optional<MediaFileEntity> getMediaByFingerprint(String workspaceId, String fingerprint) { |
| | | MediaFileEntity fileEntity = mapper.selectOne(new LambdaQueryWrapper<MediaFileEntity>() |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId) |
| | |
| | | MediaFileEntity fileEntity = this.fileUploadConvertToEntity(file); |
| | | fileEntity.setWorkspaceId(workspaceId); |
| | | fileEntity.setFileId(UUID.randomUUID().toString()); |
| | | updateInvestigate(file.getExt().getFlightId()); |
| | | return mapper.insert(fileEntity); |
| | | } |
| | | |
| | |
| | | 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); |
| | |
| | | Object data = ImgUtil.getInfo(file1); |
| | | mediaFileMarkEntity.setDronedata(data); |
| | | mediaFileMarkEntity.setWorkspaceId(workspaceId); |
| | | mediaFileMarkEntity.setIsadd(0); |
| | | mediaFileMarkEntity.setFileId(UUID.randomUUID().toString()); |
| | | mediaFileMarkEntity.setObjectKey("/mark" + file.getPath() + "/" + file.getName()); |
| | | mediaFileMarkEntity.setFileName("mark" + file.getName()); |
| | |
| | | markMapper.insert(mediaFileMarkEntity); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Object mediaInfo(String filename) { |
| | |
| | | |
| | | } |
| | | |
| | | public void updateInvestigate(String jobId){ |
| | | String waylineId=waylineJobService.getWaylineId(jobId); |
| | | String patchesId=waylineFileService.getPatchesId(waylineId); |
| | | if (patchesId==null){ |
| | | return; |
| | | } |
| | | List<Long> ids = Arrays.stream(patchesId.split(",")) |
| | | .map(Long::parseLong) |
| | | .collect(Collectors.toList()); |
| | | LambdaUpdateWrapper<LotInfo> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | updateWrapper.in(LotInfo::getId, ids) |
| | | .set(LotInfo::getInvestigate, 1) |
| | | .set(LotInfo::getIsPlan,1); |
| | | patchesMapper.update(null, updateWrapper); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<MediaFileEntity> listMediaFileEntity(String workspaceId, String jobId) { |
| | |
| | | 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 |
| | |
| | | // 获取时间戳(毫秒级别) |
| | | 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) |
| | | // .eq(MediaFileMarkEntity::getIsadd, 0) |
| | | ); |
| | | |
| | | // 筛选出name字段不包含'~'的数据 |
| | | List<MediaFileEntity> filteredFiles = mediaFiles.stream() |
| | | .filter(file -> !file.getFileName().contains("~")) |
| | | .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); |
| | | });} |
| | | if (closestFileOpt.isEmpty()) { |
| | | throw new RuntimeException("当前图片无法绑定图斑"); |
| | | } |
| | | // 提取并替换name字段 |
| | | closestFileOpt.ifPresent(closestFile -> { |
| | | String closestName = closestFile.getFileName(); |
| | | int startIndex = closestName.indexOf("V"); |
| | | if (closestName.contains("W")) { |
| | | startIndex = closestName.indexOf("W"); |
| | | } |
| | | if (closestName.contains("Z")) { |
| | | startIndex = closestName.indexOf("Z"); |
| | | } |
| | | int endIndex = closestName.indexOf(".", startIndex); |
| | | String replacement = closestName.substring(startIndex, endIndex); |
| | | int currentStartIndex = currentName.indexOf("V"); |
| | | if (currentName.contains("W")) { |
| | | currentStartIndex = closestName.indexOf("W"); |
| | | } |
| | | if (currentName.contains("Z")) { |
| | | currentStartIndex = closestName.indexOf("Z"); |
| | | } |
| | | int currentEndIndex = currentName.indexOf(".", currentStartIndex); |
| | | 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) |
| | | // .eq(MediaFileMarkEntity::getIsadd, 0) |
| | | ); |
| | | |
| | | |
| | | // 筛选出name字段不包含'~'的数据 |
| | | List<MediaFileMarkEntity> filteredFiles = mediaFiles.stream() |
| | | .filter(file -> !file.getFileName().contains("~")) |
| | | .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); |
| | | }); |
| | | } |
| | | if (closestFileOpt.isEmpty()) { |
| | | throw new RuntimeException("没有符合时间的对象"); |
| | | } |
| | | // 提取并替换name字段 |
| | | closestFileOpt.ifPresent(closestFile -> { |
| | | String closestName = closestFile.getFileName(); |
| | | int startIndex = closestName.indexOf("V"); |
| | | if (closestName.contains("W")) { |
| | | startIndex = closestName.indexOf("W"); |
| | | } |
| | | if (closestName.contains("Z")) { |
| | | startIndex = closestName.indexOf("Z"); |
| | | } |
| | | int endIndex = closestName.indexOf(".", startIndex); |
| | | String replacement = closestName.substring(startIndex, endIndex); |
| | | int currentStartIndex = currentName.indexOf("V"); |
| | | if (currentName.contains("W")) { |
| | | currentStartIndex = closestName.indexOf("W"); |
| | | } |
| | | if (currentName.contains("Z")) { |
| | | currentStartIndex = closestName.indexOf("Z"); |
| | | } |
| | | int currentEndIndex = currentName.indexOf(".", currentStartIndex); |
| | | String newName = currentName.substring(0, currentStartIndex) |
| | | + replacement |
| | | + currentName.substring(currentEndIndex); |
| | | currentFile.setFileName(newName); |
| | | updateById(currentFile.getId(), currentFile); |
| | | }); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | 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()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |