1.航线(kmz)业务增加,Minio文件路径字段。
2.增加方法从URL中提取文件路径部分。
| | |
| | | @Override |
| | | public Boolean deleteObject(String bucket, String objectKey) { |
| | | try { |
| | | // 检查文件是否存在 |
| | | client.statObject(StatObjectArgs.builder() |
| | | .bucket(bucket) |
| | | .object(objectKey) |
| | | .build()); |
| | | |
| | | // 文件存在,执行删除 |
| | | client.removeObject(RemoveObjectArgs.builder() |
| | | .bucket(bucket) |
| | | .object(objectKey) |
| | | .build()); |
| | | |
| | | log.info("成功删除文件: {}/{}", bucket, objectKey); |
| | | return true; |
| | | } catch (ErrorResponseException e) { |
| | | // 文件不存在的情况 |
| | | log.warn("文件不存在: {}/{}", bucket, objectKey); |
| | | client.removeObject(RemoveObjectArgs.builder().bucket(bucket).object(objectKey).build()); |
| | | } catch (MinioException | NoSuchAlgorithmException | IOException | InvalidKeyException e) { |
| | | log.error("Failed to delete file."); |
| | | e.printStackTrace(); |
| | | return false; |
| | | } catch (Exception e) { |
| | | log.error("删除文件失败: {}/{}", bucket, objectKey, e); |
| | | throw new RuntimeException("删除文件失败: " + e.getMessage(), e); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Excel(name = "文件大小") |
| | | private Double upFileSize; |
| | | |
| | | /** Minio文件路径 */ |
| | | @Excel(name = "Minio文件路径") |
| | | private String minioUpPath; |
| | | |
| | | } |
| | |
| | | import com.ard.route.service.IArdRouteInformationService; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import static com.ard.route.util.ToolUtils.extractFilePath; |
| | | import static com.ard.route.util.ToolUtils.getFileNameWithoutExtension; |
| | | |
| | | /** |
| | |
| | | // 删除航线(kmz)文件 |
| | | for (String id : ids) { |
| | | ArdRouteInformation information = ardRouteInformationMapper.selectArdRouteInformationById(id); |
| | | ossService.deleteObject("kmz", information.getUpPath()); |
| | | ossService.deleteObject("kmz", information.getMinioUpPath()); |
| | | } |
| | | return ardRouteInformationMapper.deleteArdRouteInformationByIds(ids); |
| | | } |
| | |
| | | ArdRouteInformation information = new ArdRouteInformation(); |
| | | information.setFileName(file.getOriginalFilename()); |
| | | information.setFileNameNew(getFileNameWithoutExtension(url)); |
| | | information.setMinioUpPath(extractFilePath(url)); |
| | | information.setUpPath(url); |
| | | information.setUpFileSize((double) file.getSize()); |
| | | insertArdRouteInformation(information); |
| | |
| | | import java.util.zip.ZipOutputStream; |
| | | |
| | | import static com.ard.route.util.RouteFileUtils.*; |
| | | import static com.ard.route.util.ToolUtils.extractFilePath; |
| | | import static com.ard.route.util.ToolUtils.getFileNameWithoutExtension; |
| | | |
| | | /** |
| | |
| | | ArdRouteInformation ardRouteInformation = new ArdRouteInformation(); |
| | | ardRouteInformation.setFileName(fileName); |
| | | ardRouteInformation.setFileNameNew(getFileNameWithoutExtension(kmzFilePath)); |
| | | ardRouteInformation.setMinioUpPath(extractFilePath(kmzFilePath)); |
| | | ardRouteInformation.setUpPath(kmzFilePath); |
| | | ardRouteInformation.setUpFileSize(fileSize); |
| | | ardRouteInformation.setCreateBy(SecurityUtils.getUsername()); |
| | |
| | | return fileNameWithExt; |
| | | } |
| | | |
| | | /** |
| | | * 从URL中提取文件路径部分 |
| | | * @param url 完整的URL字符串 |
| | | * @return 文件路径部分 |
| | | */ |
| | | public static String extractFilePath(String url) { |
| | | if (url == null || url.isEmpty()) { |
| | | return ""; |
| | | } |
| | | |
| | | // 找到最后一个 "kmz/" 的位置,加上4以包含 "kmz/" |
| | | int index = url.lastIndexOf("kmz/"); |
| | | if (index != -1) { |
| | | return url.substring(index + 4); // +4 跳过 "kmz/" |
| | | } |
| | | |
| | | // 如果没有找到 "kmz/",尝试其他方式 |
| | | return extractPathByDomain(url); |
| | | } |
| | | |
| | | /** |
| | | * 备选方法:通过域名后的第一个斜杠来提取 |
| | | */ |
| | | private static String extractPathByDomain(String url) { |
| | | // 移除协议头 |
| | | String withoutProtocol = url.replaceFirst("^https?://", ""); |
| | | // 找到第一个斜杠位置 |
| | | int slashIndex = withoutProtocol.indexOf("/"); |
| | | if (slashIndex != -1) { |
| | | return withoutProtocol.substring(slashIndex + 1); |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | } |
| | |
| | | <result property="fileName" column="file_name" /> |
| | | <result property="fileNameNew" column="file_name_new" /> |
| | | <result property="upPath" column="up_path" /> |
| | | <result property="minioUpPath" column="minio_up_path" /> |
| | | <result property="upFileSize" column="up_file_size" /> |
| | | <result property="createBy" column="create_by" /> |
| | | <result property="createTime" column="create_time" /> |
| | |
| | | file_name, |
| | | file_name_new, |
| | | up_path, |
| | | minio_up_path, |
| | | up_file_size, |
| | | create_by, |
| | | create_time, |
| | |
| | | <if test="fileName != null">file_name,</if> |
| | | <if test="fileNameNew != null">file_name_new,</if> |
| | | <if test="upPath != null">up_path,</if> |
| | | <if test="minioUpPath != null">minio_up_path,</if> |
| | | <if test="upFileSize != null">up_file_size,</if> |
| | | <if test="createBy != null">create_by,</if> |
| | | <if test="createTime != null">create_time,</if> |
| | |
| | | <if test="fileName != null">#{fileName},</if> |
| | | <if test="fileNameNew != null">#{fileNameNew},</if> |
| | | <if test="upPath != null">#{upPath},</if> |
| | | <if test="minioUpPath != null">#{minioUpPath},</if> |
| | | <if test="upFileSize != null">#{upFileSize},</if> |
| | | <if test="createBy != null">#{createBy},</if> |
| | | <if test="createTime != null">#{createTime},</if> |
| | |
| | | <if test="fileName != null">file_name = #{fileName},</if> |
| | | <if test="fileNameNew != null">file_name_new = #{fileNameNew},</if> |
| | | <if test="upPath != null">up_path = #{upPath},</if> |
| | | <if test="minioUpPath != null">minio_up_path = #{minioUpPath},</if> |
| | | <if test="upFileSize != null">up_file_size = #{upFileSize},</if> |
| | | <if test="createBy != null">create_by = #{createBy},</if> |
| | | <if test="createTime != null">create_time = #{createTime},</if> |