1.航线(kmz)业务增加,Minio文件路径字段。
2.增加方法从URL中提取文件路径部分。
6 files modified
74 ■■■■■ changed files
ard-oss/src/main/java/com/ard/oss/service/impl/MinIOServiceImpl.java 25 ●●●●● patch | view | raw | blame | history
ard-route/src/main/java/com/ard/route/domain/route/ArdRouteInformation.java 4 ●●●●● patch | view | raw | blame | history
ard-route/src/main/java/com/ard/route/service/impl/ArdRouteInformationServiceImpl.java 4 ●●●●● patch | view | raw | blame | history
ard-route/src/main/java/com/ard/route/service/impl/UavRouteServiceImpl.java 2 ●●●●● patch | view | raw | blame | history
ard-route/src/main/java/com/ard/route/util/ToolUtils.java 34 ●●●●● patch | view | raw | blame | history
ard-route/src/main/resources/mapper/ArdRouteInformationMapper.xml 5 ●●●●● patch | view | raw | blame | history
ard-oss/src/main/java/com/ard/oss/service/impl/MinIOServiceImpl.java
@@ -127,28 +127,13 @@
    @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
ard-route/src/main/java/com/ard/route/domain/route/ArdRouteInformation.java
@@ -34,4 +34,8 @@
    @Excel(name = "文件大小")
    private Double upFileSize;
    /** Minio文件路径 */
    @Excel(name = "Minio文件路径")
    private String minioUpPath;
}
ard-route/src/main/java/com/ard/route/service/impl/ArdRouteInformationServiceImpl.java
@@ -13,6 +13,7 @@
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;
/**
@@ -88,7 +89,7 @@
        // 删除航线(kmz)文件
        for (String id : ids) {
            ArdRouteInformation information = ardRouteInformationMapper.selectArdRouteInformationById(id);
            ossService.deleteObject("kmz", information.getUpPath());
            ossService.deleteObject("kmz", information.getMinioUpPath());
        }
        return ardRouteInformationMapper.deleteArdRouteInformationByIds(ids);
    }
@@ -117,6 +118,7 @@
            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);
ard-route/src/main/java/com/ard/route/service/impl/UavRouteServiceImpl.java
@@ -38,6 +38,7 @@
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;
/**
@@ -210,6 +211,7 @@
                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());
ard-route/src/main/java/com/ard/route/util/ToolUtils.java
@@ -40,4 +40,38 @@
        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 "";
    }
}
ard-route/src/main/resources/mapper/ArdRouteInformationMapper.xml
@@ -9,6 +9,7 @@
        <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"    />
@@ -21,6 +22,7 @@
               file_name,
               file_name_new,
               up_path,
               minio_up_path,
               up_file_size,
               create_by,
               create_time,
@@ -50,6 +52,7 @@
            <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>
@@ -61,6 +64,7 @@
            <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>
@@ -75,6 +79,7 @@
            <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>