| | |
| | | package com.ard.route.util; |
| | | |
| | | import com.ard.route.domain.djuav.UavRouteReq; |
| | | import java.io.*; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | |
| | |
| | | * 工具类 |
| | | */ |
| | | public class ToolUtils { |
| | | |
| | | public static Boolean isLocal = false; |
| | | |
| | | public static String localFilePath = "KmzFile/kmz/"; |
| | | |
| | | public static String kmzPath = "kmz"; |
| | | |
| | |
| | | return ""; |
| | | } |
| | | |
| | | // 对象序列化为字节数组 |
| | | public static byte[] serialize(Object obj) throws IOException { |
| | | if (obj == null) { |
| | | return null; |
| | | } |
| | | try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | ObjectOutputStream oos = new ObjectOutputStream(baos)) { |
| | | oos.writeObject(obj); |
| | | return baos.toByteArray(); |
| | | } |
| | | } |
| | | |
| | | // 字节数组反序列化为对象 |
| | | public static Object deserialize(byte[] data) throws IOException, ClassNotFoundException { |
| | | try (ByteArrayInputStream bais = new ByteArrayInputStream(data); |
| | | ObjectInputStream ois = new ObjectInputStream(bais)) { |
| | | return ois.readObject(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 截取字符串 |
| | | * 参数: https://xxx.xxx.xxx.xxx:xxx/kmz/2025/11/08/文件名_20251108152249A001.kmz |
| | | */ |
| | | public static String subStringMinioName(String url) { |
| | | return new File(url).getName(); |
| | | } |
| | | |
| | | /** |
| | | * 截取字符串 |
| | | * minio里面文件夹路径名称 |
| | | */ |
| | | public static String subStringMinioUrlName(String url) { |
| | | int kmzIndex = url.indexOf("/kmz/"); |
| | | return url.substring(kmzIndex + 5); // +5 是为了跳过 "/kmz/" |
| | | } |
| | | |
| | | /** |
| | | * 截取字符串 |
| | | * 参数: "0-89-0" |
| | | */ |
| | | public static Integer subStringDroneType(String str) { |
| | | String[] parts = str.split("-"); |
| | | return Integer.valueOf(parts[1]); |
| | | } |
| | | |
| | | /** |
| | | * 截取字符串 |
| | | * 获取经纬度高度 |
| | | */ |
| | | public static Double getDoublePoint(String str,String type) { |
| | | if (str == null || str.isEmpty()) { |
| | | return null; |
| | | } |
| | | String[] parts = str.split(","); |
| | | if ("lon".equals(type)) { |
| | | return Double.parseDouble(parts[0].trim()); |
| | | } |
| | | if ("lat".equals(type)){ |
| | | return Double.parseDouble(parts[1].trim()); |
| | | } |
| | | if ("alt".equals(type)){ |
| | | return Double.parseDouble(parts[2].trim()); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 获取航线类型方法 |
| | | */ |
| | | public static String templateTypeData(UavRouteReq uavRouteReq) { |
| | | if ("waypoint".equals(uavRouteReq.getTemplateType())){ |
| | | return "0"; |
| | | } |
| | | return "1"; |
| | | } |
| | | |
| | | /** |
| | | * 获取无人机类型方法 |
| | | */ |
| | | public static String droneTypeData(UavRouteReq uavRouteReq) { |
| | | return "0-" + uavRouteReq.getDroneType() + "-0"; |
| | | } |
| | | |
| | | } |