Browse Source

飞行任务离线任务,srt文件,支持御2,御3格式

tags/v1.3.1
wanjing 1 year ago
parent
commit
c476e73c78
3 changed files with 103 additions and 3 deletions
  1. +5
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/upload/UploadFlightUrlService.java
  2. +81
    -2
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/utils/SrtDataUtil.java
  3. +17
    -0
      tuoheng-service/tuoheng-admin/src/test/java/com/tuoheng/admin/util/SrtDataUtilTest.java

+ 5
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/upload/UploadFlightUrlService.java View File

@@ -188,8 +188,12 @@ public class UploadFlightUrlService {
if (type == 1) {
//解析srt文件经纬度和时间戳
flightDataList = SrtDataUtil.getByM300(txtContent, inspectionId, tenantId);
} else if(type == 2){
flightDataList = SrtDataUtil.getByYu2(txtContent, inspectionId, tenantId);
} else if(type == 3){
flightDataList = SrtDataUtil.getByYu3e(txtContent, inspectionId, tenantId);
} else {
log.info("srt文件上传, type不等于1,异常");
log.info("srt文件上传, type不等于1,2,3,异常");
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
if (ObjectUtils.isEmpty(flightDataList)) {

+ 81
- 2
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/utils/SrtDataUtil.java View File

@@ -13,6 +13,7 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
* SRT文件经纬度解析工具
*
@@ -22,10 +23,84 @@ import java.util.regex.Pattern;
@Slf4j
public class SrtDataUtil {

/**
* 机型为御3E拍摄的SRT文件
*/
public static List<FlightData> getByYu3e(String srtMsg, String inspectionId, String tenantId) throws Exception {
List<FlightData> flightDataList = new ArrayList<>();
//将全部字符串按照每个font分割
List<String> msgList = new ArrayList<>();
Matcher msg = Pattern.compile(
Pattern.quote("HOME(")
+ "(.*?)"
+ Pattern.quote("ISO:")
).matcher(srtMsg);
while (msg.find()) {
String match = msg.group(1);
msgList.add(match);
}

//解析每组数据
for (String str : msgList) {
FlightData flightData = new FlightData();
flightData.setIsSrt(1);
flightData.setInspectionId(inspectionId);
flightData.setTenantId(tenantId);
//找出时间,格式为2023.02.27 15:32:19
Matcher time = Pattern.compile(Pattern.quote(") ")
+ "(.*?)"
+ Pattern.quote("GPS(")
).matcher(str);
if (time.find()) {
String match = time.group(1);
//截取时间,转为时间戳
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
Date date = simpleDateFormat.parse(match);
String timeStamp = String.valueOf(date.getTime());
flightData.setTimestamp(timeStamp);
} else {
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!");
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_TIME_IS_ERROR);
}

//找出经度
Matcher longitude = Pattern.compile(
Pattern.quote("GPS(")
+ "(.*?)"
+ Pattern.quote(",")
).matcher(str);
if (longitude.find()) {
String match = longitude.group(1);
flightData.setLng(match);
} else {
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!!");
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_LNG_IS_ERROR);
}
//找出数据 格式为 GPS(120.909168,32.596070,141.100000)
Matcher latitude = Pattern.compile(
Pattern.quote("GPS(")
+ "(.*?)"
+ Pattern.quote(")")
).matcher(str);
if (latitude.find()) {
String match = latitude.group(1);
//找出纬度
String lat = match.split(",")[1];
flightData.setLat(lat);
} else {
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!!!");
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_LAT_IS_ERROR);
}
flightDataList.add(flightData);
}
return flightDataList;
}


/**
* 机型为御二拍摄的SRT文件
*/
public static List<FlightData> getByYu2(String srtMsg, String inspectionId) throws Exception {
public static List<FlightData> getByYu2(String srtMsg, String inspectionId, String tenantId) throws Exception {
List<FlightData> flightDataList = new ArrayList<>();
//将全部字符串按照每个font分割
List<String> msgList = new ArrayList<>();
@@ -44,6 +119,7 @@ public class SrtDataUtil {
FlightData flightData = new FlightData();
flightData.setIsSrt(1);
flightData.setInspectionId(inspectionId);
flightData.setTenantId(tenantId);
//找出时间,格式为2021-08-24 09:33:15,848,518
Matcher time = Pattern.compile(Pattern.quote("ms")
+ "(.*?)"
@@ -59,6 +135,7 @@ public class SrtDataUtil {
String timeStamp = String.valueOf(date.getTime());
flightData.setTimestamp(timeStamp);
} else {
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!");
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_TIME_IS_ERROR);
}

@@ -72,6 +149,7 @@ public class SrtDataUtil {
String match = longitude.group(1);
flightData.setLng(match);
} else {
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!!");
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_LNG_IS_ERROR);
}
//找出纬度
@@ -84,6 +162,7 @@ public class SrtDataUtil {
String match = latitude.group(1);
flightData.setLat(match);
} else {
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!!!");
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_LAT_IS_ERROR);
}
flightDataList.add(flightData);
@@ -148,7 +227,7 @@ public class SrtDataUtil {
String match = longitude.group(1);
flightData.setLng(match);
} else {
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!!!");
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!!");
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_LNG_IS_ERROR);
}
//找出纬度

+ 17
- 0
tuoheng-service/tuoheng-admin/src/test/java/com/tuoheng/admin/util/SrtDataUtilTest.java View File

@@ -0,0 +1,17 @@
package com.tuoheng.admin.util;

import com.tuoheng.admin.entity.FlightData;
import com.tuoheng.admin.utils.SrtDataUtil;
import com.tuoheng.common.core.utils.FileUtils;

import java.util.List;

public class SrtDataUtilTest {

public static void main(String[] args) throws Exception {
String txtContent = FileUtils.txtToString("https://ta-tech-file.oss-cn-shanghai.aliyuncs.com/DJI_0826.SRT");
List<FlightData> byYu3e = SrtDataUtil.getByYu3e(txtContent, "1","1");
System.out.println(byYu3e);
}

}

Loading…
Cancel
Save