| | |
| | | } |
| | | } |
| | | MediaFileMarkEntity mediaFileMarkEntity = this.fileUploadConvertToMarkEntity(file); |
| | | String url = "http://dev.jxpskj.com:9000/cloud-bucket" + file.getObjectKey(); |
| | | String url = "http://139.196.74.78: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(), |
| | |
| | | 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 endpoint = "http://139.196.74.78:9000"; |
| | | String accessKey = "sxkj"; |
| | | String secretKey = "sxkj2024"; |
| | | String bucketName = "cloud-bucket"; |
| | | String objectName = mediaFileMarkEntity.getObjectKey(); // 例如 "folder/file.txt" |
| | | uploadFile(endpoint, accessKey, secretKey, bucketName, objectName, file2); |
| | |
| | | if (file != null) { |
| | | builder.fileName(file.getName()) |
| | | .filePath(file.getPath()) |
| | | .examine(1) |
| | | .examine(0) |
| | | .fingerprint(file.getFingerprint()) |
| | | .objectKey(file.getObjectKey()) |
| | | .subFileType(file.getSubFileType()) |
| | |
| | | } |
| | | |
| | | |
| | | // 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 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(); |
| | | } |
| | | } |
| | | |
| | | |
| | | public void updateById(Integer id, MediaFileMarkEntity entity) { |
| | | entity.setIsadd(1); |
| | |
| | | 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()); |
| | | // } |
| | | // } |
| | | 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()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |