} catch (IOException e) { | } catch (IOException e) { | ||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||
ThumbnailUtil.cenerateCompression(filePathName,filePathName,300,0.8); | |||||
ThumbnailUtil.cenerateCompression(filePathName, filePathName, 300, 0.8); | |||||
return file; | return file; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
public static String txtToString(String fileUrl) throws Exception { | public static String txtToString(String fileUrl) throws Exception { | ||||
StringBuilder sb = new StringBuilder(); | StringBuilder sb = new StringBuilder(); | ||||
int HttpResult; // 服务器返回的状态 | int HttpResult; // 服务器返回的状态 | ||||
try { | try { | ||||
URL url =new URL(fileUrl); // 创建URL | |||||
URL url = new URL(fileUrl); // 创建URL | |||||
URLConnection urlconn = url.openConnection(); // 试图连接并取得返回状态码 | URLConnection urlconn = url.openConnection(); // 试图连接并取得返回状态码 | ||||
urlconn.connect(); | urlconn.connect(); | ||||
HttpURLConnection httpconn =(HttpURLConnection)urlconn; | |||||
HttpURLConnection httpconn = (HttpURLConnection) urlconn; | |||||
HttpResult = httpconn.getResponseCode(); | HttpResult = httpconn.getResponseCode(); | ||||
if(HttpResult != HttpURLConnection.HTTP_OK) { | |||||
if (HttpResult != HttpURLConnection.HTTP_OK) { | |||||
throw new RuntimeException("无法连接"); | throw new RuntimeException("无法连接"); | ||||
} else { | } else { | ||||
InputStreamReader isReader = new InputStreamReader(urlconn.getInputStream(),"UTF-8"); | |||||
InputStreamReader isReader = new InputStreamReader(urlconn.getInputStream(), "UTF-8"); | |||||
BufferedReader reader = new BufferedReader(isReader); | BufferedReader reader = new BufferedReader(isReader); | ||||
String line; // 用来保存每行读取的内容 | String line; // 用来保存每行读取的内容 | ||||
line = reader.readLine(); // 读取第一行 | line = reader.readLine(); // 读取第一行 | ||||
line = reader.readLine(); // 读取下一行 | line = reader.readLine(); // 读取下一行 | ||||
} | } | ||||
} | } | ||||
} | |||||
catch (FileNotFoundException e) { | |||||
} catch (FileNotFoundException e) { | |||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | |||||
catch (IOException e) { | |||||
} catch (IOException e) { | |||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||
return sb.toString(); | return sb.toString(); | ||||
} | } | ||||
inspectionUpdate.setTenantId(inspection.getTenantId()); | inspectionUpdate.setTenantId(inspection.getTenantId()); | ||||
// 如果任务处于分析完成,响应前端,任务已完成,不能上传视频 | // 如果任务处于分析完成,响应前端,任务已完成,不能上传视频 | ||||
updateSrtUrl(request.getSrtUrl(), inspection.getId(), request.getType(), inspection.getTenantId()); | |||||
this.updateSrtUrl(request.getSrtUrl(), inspection.getId(), request.getType(), inspection.getTenantId()); | |||||
// 上传离线视频,更新任务状态为分析中 | // 上传离线视频,更新任务状态为分析中 | ||||
inspectionUpdate.setSrtName(request.getSrtUrl().substring(request.getSrtUrl().lastIndexOf("/") + 1)); | inspectionUpdate.setSrtName(request.getSrtUrl().substring(request.getSrtUrl().lastIndexOf("/") + 1)); | ||||
inspectionMapper.updateByPrimaryKeySelective(inspectionUpdate); | inspectionMapper.updateByPrimaryKeySelective(inspectionUpdate); | ||||
} | } | ||||
/** | |||||
* 长传视频 | |||||
* | |||||
* @param fileUrl | |||||
* @param inspectionId | |||||
* @param type | |||||
* @param tenantId | |||||
*/ | |||||
private void updateSrtUrl(String fileUrl, String inspectionId, Integer type, String tenantId) { | private void updateSrtUrl(String fileUrl, String inspectionId, Integer type, String tenantId) { | ||||
log.info("进入srt文件上传方法, fileUrl:{}, inspectionId:{}, type:{}, tenantId:{}", fileUrl, inspectionId, type, tenantId); | |||||
List<FlightData> flightDataList = new ArrayList<>(); | List<FlightData> flightDataList = new ArrayList<>(); | ||||
try { | try { | ||||
String txtContent = FileUtils.txtToString(fileUrl); | String txtContent = FileUtils.txtToString(fileUrl); | ||||
//type为1时,机型为M300 | //type为1时,机型为M300 | ||||
if (type == 1) { | if (type == 1) { | ||||
//解析srt文件经纬度和时间戳 | //解析srt文件经纬度和时间戳 | ||||
flightDataList = SrtDataUtil.getByM300(txtContent, inspectionId, tenantId); | flightDataList = SrtDataUtil.getByM300(txtContent, inspectionId, tenantId); | ||||
} else { | } else { | ||||
log.info("srt文件上传, type不等于1,异常"); | |||||
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL); | throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL); | ||||
} | } | ||||
if (ObjectUtils.isEmpty(flightDataList)) { | if (ObjectUtils.isEmpty(flightDataList)) { | ||||
log.info("srt文件上传, 上传文件数据错误,请检查文件!"); | |||||
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_IS_ERROR); | throw new ServiceException(ServiceExceptionEnum.FILE_DATA_IS_ERROR); | ||||
} | } | ||||
flightDataMapper.delete(new LambdaQueryWrapper<FlightData>() | flightDataMapper.delete(new LambdaQueryWrapper<FlightData>() |
* 机型为M300拍摄的SRT文件 | * 机型为M300拍摄的SRT文件 | ||||
*/ | */ | ||||
public static List<FlightData> getByM300(String srtMsg, String inspectionId, String tenantId) throws Exception { | public static List<FlightData> getByM300(String srtMsg, String inspectionId, String tenantId) throws Exception { | ||||
log.info("获取机型为M300拍摄的SRT文件数据"); | |||||
List<FlightData> flightDataList = new ArrayList<>(); | List<FlightData> flightDataList = new ArrayList<>(); | ||||
//将全部字符串按照每个font分割 | //将全部字符串按照每个font分割 | ||||
List<String> msgList = new ArrayList<>(); | List<String> msgList = new ArrayList<>(); | ||||
try { | try { | ||||
date = simpleDateFormat.parse(match); | date = simpleDateFormat.parse(match); | ||||
} catch (ParseException e) { | } catch (ParseException e) { | ||||
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!"); | |||||
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_TIME_IS_ERROR); | throw new ServiceException(ServiceExceptionEnum.FILE_DATA_TIME_IS_ERROR); | ||||
} | } | ||||
String timeStamp = String.valueOf(date.getTime()); | String timeStamp = String.valueOf(date.getTime()); | ||||
flightData.setTimestamp(timeStamp); | flightData.setTimestamp(timeStamp); | ||||
} else { | } else { | ||||
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!!"); | |||||
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_TIME_IS_ERROR); | throw new ServiceException(ServiceExceptionEnum.FILE_DATA_TIME_IS_ERROR); | ||||
} | } | ||||
String match = longitude.group(1); | String match = longitude.group(1); | ||||
flightData.setLng(match); | flightData.setLng(match); | ||||
} else { | } else { | ||||
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!!!"); | |||||
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_LNG_IS_ERROR); | throw new ServiceException(ServiceExceptionEnum.FILE_DATA_LNG_IS_ERROR); | ||||
} | } | ||||
//找出纬度 | //找出纬度 | ||||
String match = latitude.group(1); | String match = latitude.group(1); | ||||
flightData.setLat(match); | flightData.setLat(match); | ||||
} else { | } else { | ||||
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!!!!"); | |||||
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_LAT_IS_ERROR); | throw new ServiceException(ServiceExceptionEnum.FILE_DATA_LAT_IS_ERROR); | ||||
} | } | ||||
flightDataList.add(flightData); | flightDataList.add(flightData); |