|
|
@@ -1,6 +1,8 @@
|
|
|
package com.dji.sample.map.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.CoordinateUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.dji.sample.map.dao.IFlightTaskMapper;
|
|
|
import com.dji.sample.map.dao.IFlightTrackMapper;
|
|
|
@@ -25,6 +27,7 @@ import org.springframework.util.StringUtils;
|
|
|
import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
@@ -332,6 +335,35 @@ public class FlightTrackTaskServiceImpl implements IFlightTrackTaskService {
|
|
|
return builder.build();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<FlightTaskEntity> getFlightTrack(String deviceSn, String worksapceId) {
|
|
|
+ List<FlightTaskEntity> result = new ArrayList<>();
|
|
|
+ LambdaQueryWrapper<FlightTaskEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(FlightTaskEntity ::getDeviceSn,deviceSn)
|
|
|
+ .eq(FlightTaskEntity ::getWorkspaceId,worksapceId);
|
|
|
+ result = mapper.selectList(wrapper);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public double getFlightKilometersByTaskId(Integer taskId) {
|
|
|
+ double result = 0;
|
|
|
+ List<FlightTrackEntity> trackResult = new ArrayList<>();
|
|
|
+ LambdaQueryWrapper<FlightTrackEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(FlightTrackEntity::getTaskId,taskId)
|
|
|
+ .orderByDesc(FlightTrackEntity::getCreateTime);
|
|
|
+ trackResult = trackMapper.selectList(wrapper);
|
|
|
+ List<CoordinateUtil.Coordinate> coordinates = new ArrayList<>();
|
|
|
+ for (int i = 0; i < trackResult.size(); i++) {
|
|
|
+ FlightTrackEntity flightTrackStart = trackResult.get(i);
|
|
|
+ coordinates.add(new CoordinateUtil.Coordinate(flightTrackStart.getLongitude(), flightTrackStart.getLatitude()));
|
|
|
+ }
|
|
|
+ if(coordinates.size() > 0) {
|
|
|
+ result = calculateTotalDistance(coordinates);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
private FlightTaskDTO entityToDto(FlightTaskEntity flightTaskEntity) {
|
|
|
FlightTaskDTO.FlightTaskDTOBuilder builder = FlightTaskDTO.builder();
|
|
|
if (flightTaskEntity != null) {
|
|
|
@@ -354,4 +386,29 @@ public class FlightTrackTaskServiceImpl implements IFlightTrackTaskService {
|
|
|
return builder.build();
|
|
|
}
|
|
|
|
|
|
+ private double calculateTotalDistance(List<CoordinateUtil.Coordinate> coordinates) {
|
|
|
+ double totalDistance = 0.0;
|
|
|
+
|
|
|
+ for (int i = 0; i < coordinates.size() - 1; i++) {
|
|
|
+ CoordinateUtil.Coordinate start = coordinates.get(i);
|
|
|
+ CoordinateUtil.Coordinate end = coordinates.get(i + 1);
|
|
|
+ double distance = calculateDistance(start, end);
|
|
|
+ totalDistance += distance;
|
|
|
+ }
|
|
|
+
|
|
|
+ return totalDistance;
|
|
|
+ }
|
|
|
+
|
|
|
+ private double calculateDistance(CoordinateUtil.Coordinate start, CoordinateUtil.Coordinate end) {
|
|
|
+ final int R = 6371; // 地球平均半径,单位为公里
|
|
|
+ double lat1 = Math.toRadians(start.getLat());
|
|
|
+ double lat2 = Math.toRadians(end.getLat());
|
|
|
+ double deltaLat = Math.toRadians(end.getLat() - start.getLat());
|
|
|
+ double deltaLon = Math.toRadians(end.getLng() - start.getLng());
|
|
|
+ double a = Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2)
|
|
|
+ + Math.cos(lat1) * Math.cos(lat2) * Math.sin(deltaLon / 2) * Math.sin(deltaLon / 2);
|
|
|
+ double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
|
+ return R * c;
|
|
|
+ }
|
|
|
+
|
|
|
}
|